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

Function main

test/component/fuzzing/fuzz_component.cpp:13–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include <variant>
12
13int main(int Argc, char *Argv[]) {
14 if (Argc != 2) {
15 std::cerr << "Usage: " << Argv[0] << " <wasm-file>" << std::endl;
16 return EXIT_FAILURE;
17 }
18
19 std::filesystem::path WasmPath(Argv[1]);
20
21 WasmEdge::Configure Conf;
22 Conf.addProposal(WasmEdge::Proposal::Component);
23
24 WasmEdge::Loader::Loader Loader(Conf);
25 auto ParseResult = Loader.parseWasmUnit(WasmPath);
26 if (!ParseResult) {
27 std::cerr << "Parse failed: " << WasmPath << std::endl;
28 return EXIT_FAILURE;
29 }
30
31 auto &Unit = *ParseResult;
32 if (auto *Comp =
33 std::get_if<std::unique_ptr<WasmEdge::AST::Component::Component>>(
34 &Unit)) {
35 WasmEdge::Validator::Validator Validator(Conf);
36 auto ValidResult = Validator.validate(**Comp);
37 if (!ValidResult) {
38 std::cerr << "Validation failed: " << WasmPath << std::endl;
39 return EXIT_FAILURE;
40 }
41 } else if (auto *Mod =
42 std::get_if<std::unique_ptr<WasmEdge::AST::Module>>(&Unit)) {
43 WasmEdge::Validator::Validator Validator(Conf);
44 auto ValidResult = Validator.validate(**Mod);
45 if (!ValidResult) {
46 std::cerr << "Validation failed: " << WasmPath << std::endl;
47 return EXIT_FAILURE;
48 }
49 }
50
51 return EXIT_SUCCESS;
52}

Callers

nothing calls this directly

Calls 3

addProposalMethod · 0.80
parseWasmUnitMethod · 0.80
validateMethod · 0.45

Tested by

no test coverage detected