MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / processCommands

Method processCommands

test/spec/spectest.cpp:743–1237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

741}
742
743void SpecTest::processCommands(ContextHandle Ctx, std::string_view Proposal,
744 std::string_view UnitName, void *CmdArrayPtr) {
745 simdjson::dom::array CmdArray =
746 *static_cast<simdjson::dom::array *>(CmdArrayPtr);
747 const bool IsComponent = (Proposal == "component-model"sv);
748
749 std::map<std::string, std::string> Alias;
750 std::map<std::string, SpecTest::WasmUnit> ASTMap;
751 std::string LastModName;
752 std::map<std::string, std::thread> ThreadMap;
753
754 // Helper function to get module name.
755 auto GetModuleName = [&](const simdjson::dom::object &Action) -> std::string {
756 std::string_view ModName;
757 if (!Action["module"].get(ModName)) {
758 if (auto It = Alias.find(std::string(ModName)); It != Alias.end()) {
759 // If module name is aliased, use the aliased name.
760 return It->second;
761 }
762 return std::string(ModName);
763 }
764 return LastModName;
765 };
766
767 // Helper function to check the result of invocation.
768 auto Invoke = [&](const simdjson::dom::object &Action,
769 const simdjson::dom::array &Expected, uint64_t LineNumber) {
770 if (IsComponent) {
771 // TODO: Component model invocation not yet supported.
772 return;
773 }
774 const auto ModName = GetModuleName(Action);
775 const std::string_view Field = Action["field"];
776 simdjson::dom::array Args = Action["args"];
777 const auto Params = parseValueList(Args);
778 const auto Returns = parseExpectedList(Expected);
779
780 // Invoke function of named module. Named modules are registered in Store
781 // Manager. Anonymous modules are instantiated in the VM.
782 if (auto Res = onInvoke(Ctx, ModName, std::string(Field), Params.first,
783 Params.second)) {
784 // Check value.
785 EXPECT_TRUE(compares(Returns, *Res));
786 } else {
787 EXPECT_NE(LineNumber, LineNumber);
788 }
789 };
790
791 // Helper function to check one of the matched results of invocation.
792 auto InvokeEither = [&](const simdjson::dom::object &Action,
793 const simdjson::dom::array &Eithers,
794 uint64_t LineNumber) {
795 if (IsComponent) {
796 // TODO: Component model invocation not yet supported.
797 return;
798 }
799 const auto ModName = GetModuleName(Action);
800 const std::string_view Field = Action["field"];

Callers

nothing calls this directly

Calls 15

parseValueListFunction · 0.85
parseExpectedListFunction · 0.85
parseEithersListFunction · 0.85
checkComponentSupportedFunction · 0.85
resolveRegisterFunction · 0.85
resolveCommandFunction · 0.85
to_stringFunction · 0.85
getErrCodePhaseMethod · 0.80
getEnumMethod · 0.80
eraseMethod · 0.80
getMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected