Skip to content

Conversation

@pugong2019
Copy link

Add enhanced test coverage for wasm-c-api functionality:

  • Add wasm_extern_type testing with null input validation
  • Add wasm_memory internal API tests with WebAssembly module integration
  • Extend CMakeLists.txt to include new test files

Add enhanced test coverage for wasm-c-api functionality:
- Add wasm_extern_type testing with null input validation
- Add wasm_memory internal API tests with WebAssembly module integration
- Extend CMakeLists.txt to include new test files

Signed-off-by: Gong, Pu <[email protected]>
@lum1n0us lum1n0us added the ai-assistant It is created by an AI assistant or with the help of an AI assistant. label Oct 27, 2025
Copy link
Collaborator

@lum1n0us lum1n0us left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests/unit/wasm-c-api/enhanced_gen_wasm_c_api_test.cc is better than tests/unit/wasm-c-api/enhanced_gen_wasm_memory_new_internal_test.cc.

ASSERT_NE(nullptr, engine);
store = wasm_store_new(engine);
ASSERT_NE(nullptr, store);
runtime = std::make_unique<WAMRRuntimeRAII<512 * 1024>>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not call both wasm_engine_new() and wasm_runtime_full_init()(via WAMRRuntimeRAII). In this case, WAMRRuntimeRAII should not be involved.


// Cleanup
wasm_func_delete(func);
wasm_functype_delete(functype);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to cleanup externtype.

The own in its declaration WASM_API_EXTERN own wasm_externtype_t* wasm_extern_type(const wasm_extern_t*); indicates an ownership transfer.


// Cleanup
wasm_func_delete(func);
wasm_functype_delete(functype);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to cleanup externtype.

The own in its declaration WASM_API_EXTERN own wasm_externtype_t* wasm_extern_type(const wasm_extern_t*); indicates an ownership transfer.


// Cleanup
wasm_global_delete(global);
wasm_globaltype_delete(globaltype);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to cleanup externtype.

The own in its declaration WASM_API_EXTERN own wasm_externtype_t* wasm_extern_type(const wasm_extern_t*); indicates an ownership transfer.

// The fact that we can get exports means the instance was created
// successfully which means wasm_memory_new_internal was called and
// succeeded
ASSERT_GE(exports.size, 0u);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be 0.

}

// Create multiple instances to exercise memory creation paths
for (int i = 0; i < 3; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 3 times.


// Test Case 12: Test error handling paths in memory creation
TEST_F(WasmMemoryNewInternalTest,
ErrorHandlingPaths_MemoryCreation_HandlesFailuresGracefully)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to a previous one.


// Test Case 13: Test comprehensive parameter validation
TEST_F(WasmMemoryNewInternalTest,
ParameterValidation_ComprehensiveTest_CoversAllPaths)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case appears to be a simple combination of previous ones.

@lum1n0us
Copy link
Collaborator

tests/unit/wasm-c-api/enhanced_gen_wasm_c_api_test.cc

PASS: 11. NEED MODIFICATION: 1. DROP: 1.

Case Check Description
wasm_extern_type_NullInput_ReturnsNull PASS
wasm_extern_type_FunctionExtern_ReturnsCorrectExternType PASS
wasm_extern_type_FunctionExternWithParams_ReturnsCorrectExternType PASS
wasm_extern_type_GlobalExtern_ReturnsCorrectExternType PASS
wasm_extern_type_ConstGlobalExtern_ReturnsCorrectExternType PASS
wasm_extern_type_MemoryExtern_ReturnsCorrectExternType PASS
wasm_extern_type_MemoryExternWithDifferentLimits_ReturnsCorrectExternType PASS
wasm_extern_type_TableExtern_ReturnsCorrectExternType PASS
wasm_extern_type_TableExternWithFuncRef_ReturnsCorrectExternType PASS
wasm_extern_type_InvalidKind_ReturnsNullAndLogsWarning NEED MODIFICATION WRONG implementation
wasm_extern_type_AllExternKinds_ReturnCorrectTypes DROP DUPE
wasm_extern_type_MultipleCalls_ReturnConsistentResults PASS
wasm_extern_type_ConstExtern_HandlesCorrectly PASS

tests/unit/wasm-c-api/enhanced_gen_wasm_memory_new_internal_test.cc

PASS: 4. NEED MODIFICATION: 3. DROP: 6.

Case Check Description
ModuleWithMemory_InstantiationCreatesMemory_SucceedsCorrectly PASS
ModuleWithoutMemory_InstantiationHandlesCorrectly_SucceedsGracefully PASS
NullStore_MemoryCreation_HandlesGracefully DROP DUPE
ValidParameters_MemoryCreation_SucceedsCorrectly DROP DUPE
BoundaryConditions_MemoryCreation_HandlesCorrectly DROP DUPE
MultipleMemoryCreation_IndependentObjects_CreatedCorrectly PASS
MemoryOperations_SizeAndGrow_WorkCorrectly NEED MODIFICATION WRONG implementation
InvalidMemoryType_CreationHandlesGracefully PASS
ResourceLifecycle_ProperCleanup_NoMemoryLeaks NEED MODIFICATION WRONG implementation
MemoryTypeValidation_VariousLimits_HandlesCorrectly DROP DUPE
ModuleInstantiation_MemoryCreationPaths_CoverInternalFunction NEED MODIFICATION WRONG STUB
ErrorHandlingPaths_MemoryCreation_HandlesFailuresGracefully DROP DUPE
ParameterValidation_ComprehensiveTest_CoversAllPaths DROP DUPE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assistant It is created by an AI assistant or with the help of an AI assistant.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants