Coverage Report

Created: 2026-06-30 06:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/WasmEdge/lib/vm/plugin_modules.cpp
Line
Count
Source
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright The WasmEdge Authors
3
4
#include "plugin_modules.h"
5
6
#include "common/spdlog.h"
7
#include "plugin/plugin.h"
8
9
#include "host/mock/wasi_crypto_module.h"
10
#include "host/mock/wasi_logging_module.h"
11
#include "host/mock/wasi_nn_module.h"
12
#include "host/mock/wasmedge_image_module.h"
13
#include "host/mock/wasmedge_process_module.h"
14
#include "host/mock/wasmedge_stablediffusion_module.h"
15
#include "host/mock/wasmedge_tensorflow_module.h"
16
#include "host/mock/wasmedge_tensorflowlite_module.h"
17
18
#include <algorithm>
19
#include <array>
20
21
namespace WasmEdge {
22
namespace VM {
23
24
namespace {
25
26
using namespace std::literals::string_view_literals;
27
28
using ModuleFactory = std::unique_ptr<Runtime::Instance::ModuleInstance> (*)();
29
30
template <typename T>
31
0
std::unique_ptr<Runtime::Instance::ModuleInstance> createMock() {
32
0
  return std::make_unique<T>();
33
0
}
Unexecuted instantiation: plugin_modules.cpp:std::__1::unique_ptr<WasmEdge::Runtime::Instance::ModuleInstance, std::__1::default_delete<WasmEdge::Runtime::Instance::ModuleInstance> > WasmEdge::VM::(anonymous namespace)::createMock<WasmEdge::Host::WasiNNModuleMock>()
Unexecuted instantiation: plugin_modules.cpp:std::__1::unique_ptr<WasmEdge::Runtime::Instance::ModuleInstance, std::__1::default_delete<WasmEdge::Runtime::Instance::ModuleInstance> > WasmEdge::VM::(anonymous namespace)::createMock<WasmEdge::Host::WasiCryptoCommonModuleMock>()
Unexecuted instantiation: plugin_modules.cpp:std::__1::unique_ptr<WasmEdge::Runtime::Instance::ModuleInstance, std::__1::default_delete<WasmEdge::Runtime::Instance::ModuleInstance> > WasmEdge::VM::(anonymous namespace)::createMock<WasmEdge::Host::WasiCryptoAsymmetricCommonModuleMock>()
Unexecuted instantiation: plugin_modules.cpp:std::__1::unique_ptr<WasmEdge::Runtime::Instance::ModuleInstance, std::__1::default_delete<WasmEdge::Runtime::Instance::ModuleInstance> > WasmEdge::VM::(anonymous namespace)::createMock<WasmEdge::Host::WasiCryptoKxModuleMock>()
Unexecuted instantiation: plugin_modules.cpp:std::__1::unique_ptr<WasmEdge::Runtime::Instance::ModuleInstance, std::__1::default_delete<WasmEdge::Runtime::Instance::ModuleInstance> > WasmEdge::VM::(anonymous namespace)::createMock<WasmEdge::Host::WasiCryptoSignaturesModuleMock>()
Unexecuted instantiation: plugin_modules.cpp:std::__1::unique_ptr<WasmEdge::Runtime::Instance::ModuleInstance, std::__1::default_delete<WasmEdge::Runtime::Instance::ModuleInstance> > WasmEdge::VM::(anonymous namespace)::createMock<WasmEdge::Host::WasiCryptoSymmetricModuleMock>()
Unexecuted instantiation: plugin_modules.cpp:std::__1::unique_ptr<WasmEdge::Runtime::Instance::ModuleInstance, std::__1::default_delete<WasmEdge::Runtime::Instance::ModuleInstance> > WasmEdge::VM::(anonymous namespace)::createMock<WasmEdge::Host::WasmEdgeProcessModuleMock>()
Unexecuted instantiation: plugin_modules.cpp:std::__1::unique_ptr<WasmEdge::Runtime::Instance::ModuleInstance, std::__1::default_delete<WasmEdge::Runtime::Instance::ModuleInstance> > WasmEdge::VM::(anonymous namespace)::createMock<WasmEdge::Host::WasiLoggingModuleMock>()
Unexecuted instantiation: plugin_modules.cpp:std::__1::unique_ptr<WasmEdge::Runtime::Instance::ModuleInstance, std::__1::default_delete<WasmEdge::Runtime::Instance::ModuleInstance> > WasmEdge::VM::(anonymous namespace)::createMock<WasmEdge::Host::WasmEdgeTensorflowModuleMock>()
Unexecuted instantiation: plugin_modules.cpp:std::__1::unique_ptr<WasmEdge::Runtime::Instance::ModuleInstance, std::__1::default_delete<WasmEdge::Runtime::Instance::ModuleInstance> > WasmEdge::VM::(anonymous namespace)::createMock<WasmEdge::Host::WasmEdgeTensorflowLiteModuleMock>()
Unexecuted instantiation: plugin_modules.cpp:std::__1::unique_ptr<WasmEdge::Runtime::Instance::ModuleInstance, std::__1::default_delete<WasmEdge::Runtime::Instance::ModuleInstance> > WasmEdge::VM::(anonymous namespace)::createMock<WasmEdge::Host::WasmEdgeImageModuleMock>()
Unexecuted instantiation: plugin_modules.cpp:std::__1::unique_ptr<WasmEdge::Runtime::Instance::ModuleInstance, std::__1::default_delete<WasmEdge::Runtime::Instance::ModuleInstance> > WasmEdge::VM::(anonymous namespace)::createMock<WasmEdge::Host::WasmEdgeStableDiffusionModuleMock>()
34
35
struct OfficialPluginEntry {
36
  std::string_view PluginName;
37
  std::string_view ModuleName;
38
  ModuleFactory MockFactory;
39
};
40
41
/// One row per official plugin module. Both the load order of the mock-or-real
42
/// instances and the official plugin name check derive from this table.
43
constexpr std::array<OfficialPluginEntry, 12> OfficialPluginTable{{
44
    {"wasi_nn"sv, "wasi_nn"sv, createMock<Host::WasiNNModuleMock>},
45
    {"wasi_crypto"sv, "wasi_crypto_common"sv,
46
     createMock<Host::WasiCryptoCommonModuleMock>},
47
    {"wasi_crypto"sv, "wasi_crypto_asymmetric_common"sv,
48
     createMock<Host::WasiCryptoAsymmetricCommonModuleMock>},
49
    {"wasi_crypto"sv, "wasi_crypto_kx"sv,
50
     createMock<Host::WasiCryptoKxModuleMock>},
51
    {"wasi_crypto"sv, "wasi_crypto_signatures"sv,
52
     createMock<Host::WasiCryptoSignaturesModuleMock>},
53
    {"wasi_crypto"sv, "wasi_crypto_symmetric"sv,
54
     createMock<Host::WasiCryptoSymmetricModuleMock>},
55
    {"wasmedge_process"sv, "wasmedge_process"sv,
56
     createMock<Host::WasmEdgeProcessModuleMock>},
57
    {"wasi_logging"sv, "wasi:logging/logging"sv,
58
     createMock<Host::WasiLoggingModuleMock>},
59
    {"wasmedge_tensorflow"sv, "wasmedge_tensorflow"sv,
60
     createMock<Host::WasmEdgeTensorflowModuleMock>},
61
    {"wasmedge_tensorflowlite"sv, "wasmedge_tensorflowlite"sv,
62
     createMock<Host::WasmEdgeTensorflowLiteModuleMock>},
63
    {"wasmedge_image"sv, "wasmedge_image"sv,
64
     createMock<Host::WasmEdgeImageModuleMock>},
65
    {"wasmedge_stablediffusion"sv, "wasmedge_stablediffusion"sv,
66
     createMock<Host::WasmEdgeStableDiffusionModuleMock>},
67
}};
68
69
std::unique_ptr<Runtime::Instance::ModuleInstance>
70
0
createPluginModule(const OfficialPluginEntry &Entry) {
71
0
  if (const auto *Plugin = Plugin::Plugin::find(Entry.PluginName)) {
72
0
    if (const auto *Module = Plugin->findModule(Entry.ModuleName)) {
73
0
      return Module->create();
74
0
    }
75
0
  }
76
0
  spdlog::debug("Plugin: {} , module name: {} not found. Mock instead."sv,
77
0
                Entry.PluginName, Entry.ModuleName);
78
0
  return Entry.MockFactory();
79
0
}
80
81
} // namespace
82
83
std::vector<std::unique_ptr<Runtime::Instance::ModuleInstance>>
84
0
loadOfficialPluginModules() {
85
0
  std::vector<std::unique_ptr<Runtime::Instance::ModuleInstance>> Modules;
86
0
  Modules.reserve(OfficialPluginTable.size());
87
0
  for (const auto &Entry : OfficialPluginTable) {
88
0
    Modules.push_back(createPluginModule(Entry));
89
0
  }
90
0
  return Modules;
91
0
}
92
93
0
bool isOfficialPlugin(std::string_view PName) {
94
0
  return std::any_of(OfficialPluginTable.begin(), OfficialPluginTable.end(),
95
0
                     [PName](const OfficialPluginEntry &Entry) {
96
0
                       return Entry.PluginName == PName;
97
0
                     });
98
0
}
99
100
} // namespace VM
101
} // namespace WasmEdge