| 44 | class CoreTest : public testing::TestWithParam<std::string> {}; |
| 45 | |
| 46 | TEST_P(CoreTest, TestSuites) { |
| 47 | const auto [Proposal, Conf, UnitName] = T.resolve(GetParam()); |
| 48 | const auto &ConfRef = Conf; |
| 49 | |
| 50 | // Define context structure |
| 51 | struct TestContext { |
| 52 | WasmEdge::VM::VM VM; |
| 53 | WasmEdge::SpecTestModule SpecTestMod; |
| 54 | TestContext(const WasmEdge::Configure &C) : VM(C) { |
| 55 | VM.registerModule(SpecTestMod); |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | T.onInit = [&ConfRef](SpecTest::ContextHandle Parent, |
| 60 | const std::vector<std::pair<std::string, std::string>> |
| 61 | &SharedModules) -> SpecTest::ContextHandle { |
| 62 | // Always create VM with own Store to avoid module name conflicts |
| 63 | // from built-in host modules being re-registered in a shared Store. |
| 64 | auto *Ctx = new TestContext(ConfRef); |
| 65 | if (Parent != nullptr && !SharedModules.empty()) { |
| 66 | auto *P = static_cast<TestContext *>(Parent); |
| 67 | for (const auto &[ParentName, AliasName] : SharedModules) { |
| 68 | const auto *ModInst = P->VM.getStoreManager().findModule(ParentName); |
| 69 | if (ModInst != nullptr) { |
| 70 | // Register the shared module under the alias name so that |
| 71 | // the thread's wasm modules can import it by the expected name. |
| 72 | Ctx->VM.registerModule(AliasName, *ModInst); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | return Ctx; |
| 77 | }; |
| 78 | |
| 79 | T.onFini = [](SpecTest::ContextHandle Ctx) { |
| 80 | delete static_cast<TestContext *>(Ctx); |
| 81 | }; |
| 82 | |
| 83 | T.onModule = [](SpecTest::ContextHandle Ctx, const std::string &ModName, |
| 84 | const std::string &FileName) -> Expect<void> { |
| 85 | auto &VM = static_cast<TestContext *>(Ctx)->VM; |
| 86 | if (!ModName.empty()) { |
| 87 | // registerModule only supports core wasm modules. If it fails (e.g. |
| 88 | // because the file is a component), fall back to |
| 89 | // load/validate/instantiate. |
| 90 | if (auto Res = VM.registerModule(ModName, FileName); Res) { |
| 91 | return {}; |
| 92 | } |
| 93 | } |
| 94 | if (T.SkipComponentValidation) { |
| 95 | // For component-model tests where validation is not yet supported, |
| 96 | // skip validation by force-setting the stage as validated. |
| 97 | return VM.loadWasm(FileName) |
| 98 | .and_then([&VM]() { return VM.forceValidateForComponent(); }) |
| 99 | .and_then([&VM]() { return VM.instantiate(); }); |
| 100 | } else { |
| 101 | return VM.loadWasm(FileName) |
| 102 | .and_then([&VM]() { return VM.validate(); }) |
| 103 | .and_then([&VM]() { return VM.instantiate(); }); |
nothing calls this directly
no test coverage detected