Просмотр исходного кода

samples/multi-module: Examine module registration a bit (#1595)

YAMAMOTO Takashi 3 лет назад
Родитель
Сommit
9ba8c80850
1 измененных файлов с 28 добавлено и 0 удалено
  1. 28 0
      samples/multi-module/src/main.c

+ 28 - 0
samples/multi-module/src/main.c

@@ -66,6 +66,7 @@ main()
     uint8 *file_buf = NULL;
     uint32 file_buf_size = 0;
     wasm_module_t module = NULL;
+    wasm_module_t module1;
     wasm_module_inst_t module_inst = NULL;
 
     /* all malloc() only from the given buffer */
@@ -122,6 +123,33 @@ main()
         "call \"C5\", it will be failed since it is a export function, ===> ");
     wasm_application_execute_func(module_inst, "C5", 0, args);
 
+    /* examine module registration a bit */
+    module1 = wasm_runtime_find_module_registered("mC");
+    if (module1 != NULL) {
+        printf("unexpected module mC %p != NULL\n", module1);
+        goto UNLOAD_MODULE;
+    }
+    module1 = wasm_runtime_find_module_registered("mA");
+    if (module1 == NULL) {
+        printf("unexpected module mA\n");
+        goto UNLOAD_MODULE;
+    }
+    module1 = wasm_runtime_find_module_registered("mB");
+    if (module1 == NULL) {
+        printf("unexpected module mB\n");
+        goto UNLOAD_MODULE;
+    }
+    if (!wasm_runtime_register_module("mC", module, error_buf,
+                                      sizeof(error_buf))) {
+        printf("%s\n", error_buf);
+        goto UNLOAD_MODULE;
+    }
+    module1 = wasm_runtime_find_module_registered("mC");
+    if (module1 != module) {
+        printf("unexpected module mC %p != %p\n", module1, module);
+        goto UNLOAD_MODULE;
+    }
+
     ret = true;
 
     printf("- wasm_runtime_deinstantiate\n");