Skip to content

Commit

Permalink
[FIX] test-context.c imports contains now the expected mul import…
Browse files Browse the repository at this point in the history
… too
  • Loading branch information
YaronWittenstein committed Aug 1, 2019
1 parent 3f4ffb0 commit f64eee8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/runtime-c-api/tests/test-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ void inc_counter(wasmer_instance_context_t *ctx) {
data->value = data->value + data->amount;
}

void mul_counter(wasmer_instance_context_t *ctx) {
counter_data* data = (counter_data*)wasmer_instance_context_data_get(ctx);
data->value = data->value * data->amount;
}

int32_t get_counter(wasmer_instance_context_t *ctx) {
counter_data* data = (counter_data*)wasmer_instance_context_data_get(ctx);
return data->value;
Expand Down Expand Up @@ -90,21 +95,27 @@ int main()
wasmer_import_func_t *inc_func = wasmer_import_func_new((void (*)(void *)) inc_counter, inc_params_sig, 0, inc_returns_sig, 0);
wasmer_import_t inc_import = create_import("env", "inc", inc_func);

wasmer_value_tag mul_params_sig[] = {};
wasmer_value_tag mul_returns_sig[] = {};
wasmer_import_func_t *mul_func = wasmer_import_func_new((void (*)(void *)) mul_counter, mul_params_sig, 0, mul_returns_sig, 0);
wasmer_import_t mul_import = create_import("env", "mul", mul_func);

wasmer_value_tag get_params_sig[] = {};
wasmer_value_tag get_returns_sig[] = {WASM_I32};
wasmer_import_func_t *get_func = wasmer_import_func_new((void (*)(void *)) get_counter, get_params_sig, 0, get_returns_sig, 1);
wasmer_import_t get_import = create_import("env", "get", get_func);

wasmer_import_t imports[] = {inc_import, get_import};
wasmer_import_t imports[] = {inc_import, mul_import, get_import};

// Read the wasm file
wasm_file_t wasm_file = read_wasm_file("assets/inc.wasm");

// Instantiate instance
printf("Instantiating\n");
wasmer_instance_t *instance = NULL;
wasmer_result_t compile_result = wasmer_instantiate(&instance, wasm_file.bytes, wasm_file.bytes_len, imports, 2);
printf("Compile result: %d\n", compile_result);
wasmer_result_t instantiate_res = wasmer_instantiate(&instance, wasm_file.bytes, wasm_file.bytes_len, imports, 3);
printf("Compile result: %d\n", instantiate_res);
assert(instantiate_res == WASMER_OK);

// Init counter
counter_data *counter = init_counter(2, 5);
Expand Down
1 change: 1 addition & 0 deletions lib/runtime-c-api/tests/test-module-import-instantiate.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ int main()
wasmer_instance_t *instance = NULL;
wasmer_result_t instantiate_res = wasmer_module_import_instantiate(&instance, module, import_object);
printf("Compile result: %d\n", instantiate_res);
assert(instantiate_res == WASMER_OK);

// Init counter
counter_data *counter = init_counter(2, 5);
Expand Down

0 comments on commit f64eee8

Please sign in to comment.