From cc7b810fd09e490310f01a31a1822e1060ed067d Mon Sep 17 00:00:00 2001 From: hwwang Date: Fri, 7 Jun 2024 17:22:35 +0800 Subject: [PATCH] add parent nodes --- .vscode/launch.json | 24 +---- graph.c | 88 +++++++++++++++++++ runtime/Utest_py/ctest.py | 43 +++++++++ runtime/src/module.c | 29 ++++-- runtime/tests/generate_json.sh | 0 runtime/tests/generate_json_2d.sh | 0 runtime/tests/generate_json_p80.sh | 0 runtime/tests/generate_json_single.sh | 0 runtime/tests/set_bash.sh | 0 runtime/tests/set_cpu.sh | 0 runtime/tests/start-edf-broadcast.sh | 0 runtime/tests/start-edf-triaged.sh | 0 runtime/tests/start-edf.sh | 0 runtime/tests/start-srsf-broadcast.sh | 0 runtime/tests/start-srsf-p80.sh | 0 runtime/tests/start-srsf.sh | 0 runtime/tests/start.sh | 0 runtime/tests/start_monitor.sh | 0 runtime/tests/start_test.sh | 0 runtime/tests/start_test2.sh | 0 runtime/tests/start_test_compare2.sh | 0 runtime/tests/start_test_full.sh | 0 runtime/tests/stop_monitor.sh | 0 .../test_multiple_image_processing4.json | 45 ++++++++++ 24 files changed, 200 insertions(+), 29 deletions(-) create mode 100644 graph.c create mode 100644 runtime/Utest_py/ctest.py mode change 100644 => 100755 runtime/tests/generate_json.sh mode change 100644 => 100755 runtime/tests/generate_json_2d.sh mode change 100644 => 100755 runtime/tests/generate_json_p80.sh mode change 100644 => 100755 runtime/tests/generate_json_single.sh mode change 100644 => 100755 runtime/tests/set_bash.sh mode change 100644 => 100755 runtime/tests/set_cpu.sh mode change 100644 => 100755 runtime/tests/start-edf-broadcast.sh mode change 100644 => 100755 runtime/tests/start-edf-triaged.sh mode change 100644 => 100755 runtime/tests/start-edf.sh mode change 100644 => 100755 runtime/tests/start-srsf-broadcast.sh mode change 100644 => 100755 runtime/tests/start-srsf-p80.sh mode change 100644 => 100755 runtime/tests/start-srsf.sh mode change 100644 => 100755 runtime/tests/start.sh mode change 100644 => 100755 runtime/tests/start_monitor.sh mode change 100644 => 100755 runtime/tests/start_test.sh mode change 100644 => 100755 runtime/tests/start_test2.sh mode change 100644 => 100755 runtime/tests/start_test_compare2.sh mode change 100644 => 100755 runtime/tests/start_test_full.sh mode change 100644 => 100755 runtime/tests/stop_monitor.sh create mode 100644 runtime/tests/test_multiple_image_processing4.json diff --git a/.vscode/launch.json b/.vscode/launch.json index 77a7602..b77d4b3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -37,13 +37,16 @@ "request": "launch", "program": "${workspaceFolder}/runtime/bin/sledgert", "args": [ - "${workspaceFolder}/runtime/experiments/preemption/spec.json" + "${workspaceFolder}/runtime/tests/test_multiple_image_processing4.json" ], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", + "sourceFileMap": { + "/sledge/runtime": "${workspaceFolder}/runtime" + }, "envFile": "${workspaceFolder}/.env", "setupCommands": [ { @@ -52,25 +55,6 @@ "ignoreFailures": true } ] - }, - { - "name": "C/C++ Runner: Debug Session", - "type": "cppdbg", - "request": "launch", - "args": [], - "stopAtEntry": false, - "externalConsole": false, - "cwd": "/home/hai/sledge-serverless-framework/runtime/src", - "program": "/home/hai/sledge-serverless-framework/runtime/src/build/Debug/outDebug", - "MIMode": "gdb", - "miDebuggerPath": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] } ] } diff --git a/graph.c b/graph.c new file mode 100644 index 0000000..80fd095 --- /dev/null +++ b/graph.c @@ -0,0 +1,88 @@ +#include +#include +#include + +#define TABLE_SIZE 100 + +typedef struct Node { + int key; + char value[256]; + struct Node* next; +} Node; + +typedef struct Edge { + Node* from; + Node* to; + double cost; + struct Edge* next; +} Edge; + +typedef struct Graph { + Node* nodes[TABLE_SIZE]; + Edge* edges[TABLE_SIZE]; +} Graph; + +unsigned int hash(int key) { + return key % TABLE_SIZE; +} + +void insertNode(Graph* g, int key, const char* value) { + unsigned int index = hash(key); + Node* new_node = (Node*) malloc(sizeof(Node)); + if (new_node) { + new_node->key = key; + strcpy(new_node->value, value); + new_node->next = g->nodes[index]; + g->nodes[index] = new_node; + } +} + +Node* findNode(Graph* g, int key) { + unsigned int index = hash(key); + Node* node = g->nodes[index]; + while (node) { + if (node->key == key) + return node; + node = node->next; + } + return NULL; +} + +void insertEdge(Graph* g, int fromKey, int toKey, double cost) { + Node* fromNode = findNode(g, fromKey); + Node* toNode = findNode(g, toKey); + if (fromNode && toNode) { + unsigned int index = hash(fromKey); + Edge* new_edge = (Edge*) malloc(sizeof(Edge)); + if (new_edge) { + new_edge->from = fromNode; + new_edge->to = toNode; + new_edge->cost = cost; + new_edge->next = g->edges[index]; + g->edges[index] = new_edge; + } + } +} + +void initGraph(Graph* g) { + for (int i = 0; i < TABLE_SIZE; i++) { + g->nodes[i] = NULL; + g->edges[i] = NULL; + } +} + +int main() { + Graph g; + initGraph(&g); + + insertNode(&g, 1, "Node 1"); + insertNode(&g, 2, "Node 2"); + insertEdge(&g, 1, 2, 0.5); + + Node* n = findNode(&g, 1); + if (n) { + printf("Found node: %s\n", n->value); + } + + return 0; +} diff --git a/runtime/Utest_py/ctest.py b/runtime/Utest_py/ctest.py new file mode 100644 index 0000000..8c88eff --- /dev/null +++ b/runtime/Utest_py/ctest.py @@ -0,0 +1,43 @@ +import unittest,importlib,BeautifulReport,cffi + +def load(): + src = open("add.c").read() + inc = open("add.h").read() + + builder = cffi.FFI() + + builder.cdef(inc) + builder.set_source("addLib",src) + builder.compile() + + md = importlib.import_module("addLib") + + return md.lib + +md = load() + +class AddTestCase(unittest.TestCase): + + def test_case1(self): + ''' + 第1个case + :return: + ''' + self.assertEqual(md.addition(1,2),1+2) + print('md.addition(1,2),1+2') + + def test_case2(self): + ''' + 第2个case + :return: + ''' + self.assertEqual(md.addition(1,5),1+2) + + print('md.addition(1,5),1+2') + +sut = unittest.TestSuite() +sut.addTest(unittest(AddTestCase)) +run = BeautifulReport.BeautifulReport(sut) + +run.report(filename="test.html",description="add单元测试") + diff --git a/runtime/src/module.c b/runtime/src/module.c index 4544c77..af08fd7 100644 --- a/runtime/src/module.c +++ b/runtime/src/module.c @@ -609,9 +609,6 @@ module_new_from_json(char *file_name) { module->is_parent = false; } - module->left_module = NULL; - module->right_module = NULL; - nodes[i] = module; // if (tail_module != NULL) { tail_module->next_module = module; } // tail_module = module; // tail_module->next_module = NULL; @@ -622,7 +619,10 @@ module_new_from_json(char *file_name) // } module_set_http_info(module, request_count, request_headers, request_content_type, - response_count, reponse_headers, response_content_type); + response_count, reponse_headers, response_content_type); + module->left_module = NULL; + module->right_module = NULL; + nodes[module_count] = module; module_count++; } @@ -631,11 +631,22 @@ module_new_from_json(char *file_name) } if (module_count == 0) panic("%s contained no active modules\n", file_name); - for (int i = 0; i < module_count; i++) { - int left_index = 2 * i + 1; - int right_index = 2 * i + 2; - if (left_index < module_count) nodes[i]->left_module = nodes[left_index]; - if (right_index < module_count) nodes[i]->right_module = nodes[right_index]; + for (int i = 0; i < module_count; i++) + { + int left_index = 2 * i + 1; + int right_index = 2 * i + 2; + assert(nodes[left_index]); + assert(nodes[right_index]); + if (left_index < module_count) + { + nodes[i]->left_module = nodes[left_index]; + nodes[left_index]->parent_nodes = nodes[i]; + } + if (right_index < module_count) + { + nodes[i]->right_module = nodes[right_index]; + nodes[right_index]->parent_nodes = nodes[i]; + } } free(nodes); #ifdef LOG_MODULE_LOADING diff --git a/runtime/tests/generate_json.sh b/runtime/tests/generate_json.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/generate_json_2d.sh b/runtime/tests/generate_json_2d.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/generate_json_p80.sh b/runtime/tests/generate_json_p80.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/generate_json_single.sh b/runtime/tests/generate_json_single.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/set_bash.sh b/runtime/tests/set_bash.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/set_cpu.sh b/runtime/tests/set_cpu.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/start-edf-broadcast.sh b/runtime/tests/start-edf-broadcast.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/start-edf-triaged.sh b/runtime/tests/start-edf-triaged.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/start-edf.sh b/runtime/tests/start-edf.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/start-srsf-broadcast.sh b/runtime/tests/start-srsf-broadcast.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/start-srsf-p80.sh b/runtime/tests/start-srsf-p80.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/start-srsf.sh b/runtime/tests/start-srsf.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/start.sh b/runtime/tests/start.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/start_monitor.sh b/runtime/tests/start_monitor.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/start_test.sh b/runtime/tests/start_test.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/start_test2.sh b/runtime/tests/start_test2.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/start_test_compare2.sh b/runtime/tests/start_test_compare2.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/start_test_full.sh b/runtime/tests/start_test_full.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/stop_monitor.sh b/runtime/tests/stop_monitor.sh old mode 100644 new mode 100755 diff --git a/runtime/tests/test_multiple_image_processing4.json b/runtime/tests/test_multiple_image_processing4.json new file mode 100644 index 0000000..be059db --- /dev/null +++ b/runtime/tests/test_multiple_image_processing4.json @@ -0,0 +1,45 @@ +{ + "active": true, + "name": "resize1", + "path": "resize_wasm.so", + "port": 10000, + "relative-deadline-us": 78574, + "argsize": 1, + "http-req-headers": [], + "http-req-content-type": "image/jpeg", + "http-req-size": 1024000, + "http-resp-headers": [], + "http-resp-size": 1024000, + "http-resp-content-type": "image/png" +}, + +{ + "active": true, + "name": "png2bmp1", + "path": "C-Image-Manip_wasm.so", + "port": 10001, + "relative-deadline-us": 78574, + "argsize": 1, + "http-req-headers": [], + "http-req-content-type": "image/png", + "http-req-size": 4096000, + "http-resp-headers": [], + "http-resp-size": 4096000, + "http-resp-content-type": "image/bmp" +}, + +{ + "active": true, + "name": "cifar10_1", + "path": "cifar10_wasm.so", + "port": 10002, + "relative-deadline-us": 78574, + "argsize": 1, + "http-req-headers": [], + "http-req-content-type": "image/bmp", + "http-req-size": 4096000, + "http-resp-headers": [], + "http-resp-size": 1024, + "http-resp-content-type": "text/plain", + "tail-module": true +}