add parent nodes

tree
hwwang 8 months ago
parent 793c12c9b9
commit cc7b810fd0

@ -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
}
]
}
]
}

@ -0,0 +1,88 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
}

@ -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单元测试")

@ -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

@ -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
}
Loading…
Cancel
Save