From 32248f11be315b257152db386ce398188d56c159 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Thu, 26 May 2022 10:48:10 -0400 Subject: [PATCH] fix: Correct upsert bug --- applications/Makefile | 12 +++++++++++- applications/wasm_apps | 2 +- runtime/include/map.h | 8 ++++---- runtime/src/sledge_abi.c | 1 - tests/scratch_storage/spec.json | 18 ++++++++++++++++++ 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/applications/Makefile b/applications/Makefile index 8cf3187..a779fc1 100644 --- a/applications/Makefile +++ b/applications/Makefile @@ -22,7 +22,11 @@ all: \ gocr.install \ gps_ekf.install \ license_plate_detection.install \ - resize_image.install + resize_image.install \ + scratch_storage_get.install \ + scratch_storage_set.install \ + scratch_storage_delete.install \ + scratch_storage_upsert.install \ .PHONY: clean clean: @@ -94,3 +98,9 @@ scratch_storage_get.install: ../runtime/bin/scratch_storage_get.wasm.so .PHONY: scratch_storage_set.install scratch_storage_set.install: ../runtime/bin/scratch_storage_set.wasm.so + +.PHONY: scratch_storage_delete.install +scratch_storage_delete.install: ../runtime/bin/scratch_storage_delete.wasm.so + +.PHONY: scratch_storage_upsert.install +scratch_storage_upsert.install: ../runtime/bin/scratch_storage_upsert.wasm.so diff --git a/applications/wasm_apps b/applications/wasm_apps index 54de4d2..cf8a8ba 160000 --- a/applications/wasm_apps +++ b/applications/wasm_apps @@ -1 +1 @@ -Subproject commit 54de4d27f9a6e1f20b65b7110612a658479e6133 +Subproject commit cf8a8bafb10c37f207ccba1405cac07cd70bae8f diff --git a/runtime/include/map.h b/runtime/include/map.h index 1a64ddd..0bad1db 100644 --- a/runtime/include/map.h +++ b/runtime/include/map.h @@ -153,9 +153,9 @@ map_upsert(struct map *map, uint8_t *key, uint32_t key_len, uint8_t *value, uint for (struct map_node *node = map->buckets[hash % MAP_BUCKET_COUNT]; node != NULL; node = node->next) { if (node->hash == hash) { node->value_len = value_len; - node->value = realloc(&node->value, value_len); + node->value = realloc(node->value, value_len); assert(node->value); - memcpy(&node->value, value, value_len); + memcpy(node->value, value, value_len); } goto DONE; } @@ -173,8 +173,8 @@ map_upsert(struct map *map, uint8_t *key, uint32_t key_len, uint8_t *value, uint assert(new_node->value); // Copy Key and Value - memcpy(&new_node->key, key, key_len); - memcpy(&new_node->value, value, value_len); + memcpy(new_node->key, key, key_len); + memcpy(new_node->value, value, value_len); map->buckets[hash % MAP_BUCKET_COUNT] = new_node; diff --git a/runtime/src/sledge_abi.c b/runtime/src/sledge_abi.c index b1c2146..6d1424a 100644 --- a/runtime/src/sledge_abi.c +++ b/runtime/src/sledge_abi.c @@ -1148,7 +1148,6 @@ DONE: * @param key_len * @param value_offset * @param value_len - * @returns 0 on success, 1 if already present, */ EXPORT void sledge_abi__scratch_storage_upsert(uint32_t key_offset, uint32_t key_len, uint32_t value_offset, uint32_t value_len) diff --git a/tests/scratch_storage/spec.json b/tests/scratch_storage/spec.json index 0047ea7..79ee5d1 100644 --- a/tests/scratch_storage/spec.json +++ b/tests/scratch_storage/spec.json @@ -20,6 +20,24 @@ "relative-deadline-us": 20000000, "http-resp-content-type": "text/plain", "http-resp-size": 1024 + }, + { + "route": "/delete", + "path": "scratch_storage_delete.wasm.so", + "expected-execution-us": 10000000, + "admissions-percentile": 70, + "relative-deadline-us": 20000000, + "http-resp-content-type": "text/plain", + "http-resp-size": 1024 + }, + { + "route": "/upsert", + "path": "scratch_storage_upsert.wasm.so", + "expected-execution-us": 10000000, + "admissions-percentile": 70, + "relative-deadline-us": 20000000, + "http-resp-content-type": "text/plain", + "http-resp-size": 1024 } ] }