From 0b1fb6c5d76838e68538699eecc70121212383eb Mon Sep 17 00:00:00 2001 From: hwwang Date: Wed, 17 Jul 2024 16:54:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E4=B8=80=E9=83=A8=E5=88=86logbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/Makefile | 1 + runtime/include/map.h | 15 +++++------ runtime/src/current_sandbox.c | 9 ++++--- runtime/src/memlogging.c | 1 + runtime/tests/fibonacciadd/main | Bin 0 -> 18648 bytes runtime/tests/fibonacciadd/main.c | 42 ++++++++++++++++-------------- runtime/tests/fibonacciadd/test | Bin 16248 -> 0 bytes 7 files changed, 36 insertions(+), 32 deletions(-) create mode 100755 runtime/tests/fibonacciadd/main delete mode 100755 runtime/tests/fibonacciadd/test diff --git a/runtime/Makefile b/runtime/Makefile index c589752..63b95c3 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -150,6 +150,7 @@ fetch: @git config --global --add safe.directory /sledge/runtime/tests/speechtotext/thirdparty/sphinxbase @git config --global --add safe.directory /sledge/runtime/thirdparty/http-parser @git config --global --add safe.directory /sledge/runtime/thirdparty/jsmn + @git config --global --add safe.directory /sledge/runtime/thirdparty/hashmap @git config --global --add safe.directory /sledge/runtime/tests/C-Image-Manip @git submodule update --init --recursive diff --git a/runtime/include/map.h b/runtime/include/map.h index 61574b3..89fa83a 100644 --- a/runtime/include/map.h +++ b/runtime/include/map.h @@ -16,7 +16,7 @@ struct map_node { struct map_node *next; - void *key; + char *key; void *value; uint32_t key_len; uint32_t value_len; @@ -44,13 +44,12 @@ map_init(struct hashmap *restrict map) /* See https://en.wikipedia.org/wiki/Jenkins_hash_function */ static inline uint32_t -jenkins_hash(void *key, uint32_t key_len) +jenkins_hash(char *key, uint32_t key_len) { uint32_t i = 0; uint32_t hash = 0; - unsigned char *data = (unsigned char *)key; while (i != key_len) { - hash += data[i++]; + hash += key[i++]; hash += hash << 10; hash ^= hash >> 6; } @@ -61,7 +60,7 @@ jenkins_hash(void *key, uint32_t key_len) } static inline void * -map_get(struct hashmap *map, void *key, uint32_t key_len, uint32_t *ret_value_len) +map_get(struct hashmap *map, char *key, uint32_t key_len, uint32_t *ret_value_len) { void *value = NULL; @@ -86,7 +85,7 @@ DONE: } static inline bool -map_set(struct hashmap *map, void *key, uint32_t key_len, void *value, uint32_t value_len, bool manage_mvalue) +map_set(struct hashmap *map, char *key, uint32_t key_len, void *value, uint32_t value_len, bool manage_mvalue) { bool did_set = false; @@ -127,7 +126,7 @@ DONE: * @returns boolean if node was deleted or not */ static inline bool -map_delete(struct hashmap *map, void *key, uint32_t key_len) +map_delete(struct hashmap *map, char *key, uint32_t key_len) { bool did_delete = false; @@ -164,7 +163,7 @@ DONE: } static inline void -map_upsert(struct hashmap *map, void *key, uint32_t key_len, void *value, uint32_t value_len) +map_upsert(struct hashmap *map, char *key, uint32_t key_len, void *value, uint32_t value_len) { uint32_t hash = MAP_HASH(key, key_len); struct map_bucket *bucket = &map->buckets[hash % MAP_BUCKET_COUNT]; diff --git a/runtime/src/current_sandbox.c b/runtime/src/current_sandbox.c index ab30eb2..df7de09 100644 --- a/runtime/src/current_sandbox.c +++ b/runtime/src/current_sandbox.c @@ -245,7 +245,7 @@ current_sandbox_start(void) map_set(sandbox_req_map, cur_request_id, strlen(cur_request_id), sandbox_request, sizeof(struct sandbox_request *), false); }else { - uint32_t rest_pre_count =*requet_id; + uint32_t rest_pre_count = *requet_id; assert(rest_pre_count >= 1); struct sandbox_request *sandbox_request = map_get(sandbox_req_map, cur_request_id, strlen(cur_request_id), &ret_value_len); @@ -263,18 +263,19 @@ current_sandbox_start(void) uint64_t enqueue_timestamp = __getcycles(); const char *previous_output = sandbox_request->previous_function_output ? sandbox_request->previous_function_output : ""; - int new_output_length = strlen(previous_output) + output_length + 1; + ssize_t new_output_length = sandbox_request->output_length + output_length + 2; char *new_output = (char *)malloc(new_output_length); if (!new_output) { fprintf(stderr, "Failed to allocate memory for the new output: %s\n", strerror(errno)); free(pre_func_output); goto err; } - snprintf(new_output, new_output_length, "%s+%s", previous_output, pre_func_output); + snprintf(new_output, new_output_length, "%s&%s", previous_output, pre_func_output); free(sandbox_request->previous_function_output); + sandbox_request->previous_function_output = NULL; sandbox_request->previous_function_output = new_output; free(pre_func_output); - sandbox_request->output_length +=output_length; + sandbox_request->output_length = new_output_length; rest_pre_count --; if (rest_pre_count != 0) diff --git a/runtime/src/memlogging.c b/runtime/src/memlogging.c index 2c3e7b7..45da59d 100644 --- a/runtime/src/memlogging.c +++ b/runtime/src/memlogging.c @@ -93,6 +93,7 @@ mem_log(char const * fmt, ...) } else { /* Write Success */ log_obj.offset += n; +// dump_log_to_file(log_obj); } } diff --git a/runtime/tests/fibonacciadd/main b/runtime/tests/fibonacciadd/main new file mode 100755 index 0000000000000000000000000000000000000000..a5f9aeb3650d02c02b7352271ff881b9bf103f9d GIT binary patch literal 18648 zcmeHPdu$xXd7r)Gk|*(XBt?mo8f)c>)Q1e!trOaE6}e3fIVfzU4GJN!0upvpDQ#LM zseS!@v-2JARwU8}{VTlzcE9<4-)r{U+1uIKo%>SHo?Sjo6I}e_K0#c#!9~JKaB8cn zfP}>+QHy<>SS~8TS4hm2hg|}xTdw*_X+YtAP_k>G$}IFZTv#yW77``9ISU718gwR2Wmh2{!-Gs7Z zdPBuy%7;nKr)`tUr*!-&d1QdNA}K-e)%W%_ifUl zc9RY1P$7TZMTn<*EjH3|^YH{~E=Kg7_}ha-=PK(VXq-j(A~0hXydT(X`m5%^>1Sg$ zeQNJ)IQ7Tb@YjGF*u3R1fZ6ot&w<}L2mW2)1~zZm4S;NJD|UJ)n@l_XVkn-?X0pPv zY$pseftcbAJ4m&|X9Tb}9F34U!a+!`IiM zWD?y`7e^GfK=Ku0MDe-B$$8X^pH}=|oO~YL)+e3^PlbOM`S-|BC-*7!yT|x7bw3J( zrI}!y`K#*wMAroMH7?hR@Z#%est9LaWOJhkuVE*kw~BDO{)I7uD8k7Xm&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i_^sG%=v#Hy!y;Dy$Rd;B71(0d8!>C3hTMt4A1yS5K!Oc`22jq|Lej3-=QvxfmkVJ=+yiPl}}O zDVm)_G1LY7Nz@y$aev_ZAI(Q_-$AudE^KkDw#PZgWkveAo6UapeXa)0co!EBEB+hZ CSch@| literal 0 HcmV?d00001 diff --git a/runtime/tests/fibonacciadd/main.c b/runtime/tests/fibonacciadd/main.c index 94dc880..98f3ae2 100644 --- a/runtime/tests/fibonacciadd/main.c +++ b/runtime/tests/fibonacciadd/main.c @@ -1,8 +1,9 @@ +#include #include -#include #include -#include +#include +// 假设的 Fibonacci 函数实现 unsigned long int fib(unsigned long int n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); @@ -17,28 +18,29 @@ int main() { perror("Error reading input"); return 1; } - buffer[bytes_read] = '\0'; // Null-terminate the string + buffer[bytes_read] = '\0'; - // Variables to store the two numbers unsigned long int num1, num2; - // Split the input into two parts based on newline and parse them - char *line = strtok(buffer, "+"); - if (line != NULL && sscanf(line, "%lu", &num1) == 1) { - line = strtok(NULL, "\n"); - if (line != NULL && sscanf(line, "%lu", &num2) == 1) { - // Calculate Fibonacci numbers and their sum - unsigned long int fib1 = fib(num1); - unsigned long int fib2 = fib(num2); - unsigned long int sum = fib1 + fib2; - - printf("Fibonacci(%lu) + Fibonacci(%lu) = %lu + %lu = %lu\n", num1, num2, fib1, fib2, sum); - } else { - printf("Invalid input. Please enter two numbers on separate lines.\n"); - return 1; - } + char *line = strtok(buffer, "&"); + char *second_part = strtok(NULL, "\0"); // Assume the rest of the string is the second number + + if (line && sscanf(line, "%lu", &num1) == 1 && + second_part && sscanf(second_part, "%lu", &num2) == 1) { + // Calculate Fibonacci numbers and their sum + unsigned long int fib1 = fib(num1); + unsigned long int fib2 = fib(num2); + unsigned long int sum = fib1 + fib2; + + // Prepare output string + char output[1024]; + int len = snprintf(output, sizeof(output), "Fibonacci(%lu) + Fibonacci(%lu) = %lu + %lu = %lu\n", num1, num2, fib1, fib2, sum); + + // Write to stdout + write(1, output, len); } else { - printf("Invalid input. Please enter two numbers on separate lines.\n"); + const char *error_msg = "Invalid input. Please enter two numbers separated by .\n"; + write(1, error_msg, strlen(error_msg)); return 1; } diff --git a/runtime/tests/fibonacciadd/test b/runtime/tests/fibonacciadd/test deleted file mode 100755 index 45f4126ef91840384cf42771784544a0df7894f0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16248 zcmeHOeQX@X6`!-?#6S`|#34>7WSf#S5c%?DLQ-&Z`8a1ylVB33v{GTSzFXT{?!&#? zOKb$e-~`1rmP{#ysQYiP;#y_xsc zd#k(BqW)1;JJQ~7-tT?P?AzJ9+1r`B|Mt`=!BwV`}S; z-2%dlAxCKxRRc=qc&KY2J=z!dKmYp0znk&kH}Y@Y_SC}-r&ivuYXRC|ztIP6uwXnM zA}C{hCLCy^@^KH;6o+`)I+;eSRIUNVrDc>41E-bYv7K`EvnuePs=zO)z<(cj4US;h z2}HSe@tn)?S61Mk2VR3CSa5tT4w5MM7M#53wQ{*^P8desF%!2NiJseyF4InlypwaX zw~L%*CP4{9B!Lz=$4HxY2AD*jX>{2cGiBdliQb%@ak_xD^V!7u^+rCQFf&~Oy>J|@ z6ggGi5;o-RW$G zI$|i(vW7T%A~2$+!BGvh8bTan5nww3`M#NN+i;0%M2ffuDNhr7NiHn3FT&9|K=KbB z_zGN_Dsex^Sor&nzi0TOjnelS^JDZoQyY_Rf_aw5Hz*#jJB~#zXMH^06I_Zuo_-3X z>b#G?gpC0weLUV*Tn-bDG5DTF-4i|@?^iBIe7yXfA;nQ2ukKf+81wOb&Zv3O$3ud> za>~bF?6F}b%s`ldFau!*!VH8N2s7}XXW-9uSH7nYo~zY|Yks>z2>sxgQ{|r02VbZ? zE`zz(ejaFdNeVve7R3bG_n>Ct71wpUMx~4svx#3%$v7dKcz#O83Dm@sQ!-ARCcZf( zle!eyT)X^{2L> z)3@nEujqrXo^S7nuNqtRl0MSX0H^KFdk{?j(iN>+bO1UH2^?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