-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_stub.go
More file actions
84 lines (69 loc) · 2.01 KB
/
main_stub.go
File metadata and controls
84 lines (69 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//go:build !integration
// +build !integration
package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
)
// collectWasmFiles returns all .wasm files in the given directory
func collectWasmFiles(dirPath string) ([]string, error) {
var files []string
entries, err := os.ReadDir(dirPath)
if err != nil {
return nil, fmt.Errorf("failed to read directory: %w", err)
}
for _, entry := range entries {
if entry.IsDir() {
continue
}
if filepath.Ext(entry.Name()) == ".wasm" {
fullPath := filepath.Join(dirPath, entry.Name())
files = append(files, fullPath)
}
}
return files, nil
}
// runFuzzerWithRuntime processes all WASM files using the provided runtime
func runFuzzerWithRuntime(dirPath string, runtime WasmRuntime) (FuzzingReport, error) {
report := FuzzingReport{
Results: make([]ExecutionResult, 0),
FailureCounts: make(map[FailureStage]int),
}
// Initialize failure counts
report.FailureCounts[StageLoad] = 0
report.FailureCounts[StageValidate] = 0
report.FailureCounts[StageInstantiate] = 0
report.FailureCounts[StageExecute] = 0
// Collect all WASM files
files, err := collectWasmFiles(dirPath)
if err != nil {
return report, err
}
report.TotalFiles = len(files)
// Process each file sequentially (no concurrency)
for _, filePath := range files {
result := processWasmFileWithRuntime(filePath, runtime)
report.Results = append(report.Results, result)
if result.Success {
report.Passed++
} else {
report.Failed++
report.FailureCounts[result.FailureStage]++
}
}
return report, nil
}
// outputJSON writes the report as formatted JSON to stdout
func outputJSON(report FuzzingReport) error {
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
return encoder.Encode(report)
}
func main() {
// Stub main for non-integration builds
// When running tests, we use processWasmFileWithRuntime with mocks
fmt.Println("Build with -tags=integration to run the full WasmEdge fuzzer")
fmt.Println("Run 'go test' to run the fault injection tests")
}