@@ -10,10 +10,16 @@ import { supplyDefaultFunction } from "../utils/index.js";
10
10
import { parseImportFunctionInfo } from "../utils/wasmparser.js" ;
11
11
import { ExecutionRecorder } from "./executionRecorder.js" ;
12
12
import { CoverageRecorder } from "./covRecorder.js" ;
13
+ import assert from "node:assert" ;
13
14
14
15
const readFile = promises . readFile ;
15
16
16
- async function nodeExecutor ( wasm : string , outFolder : string , imports ?: Imports ) : Promise < ExecutionRecorder > {
17
+ async function nodeExecutor (
18
+ wasm : string ,
19
+ outFolder : string ,
20
+ matchedTestNames ?: string [ ] ,
21
+ imports ?: Imports
22
+ ) : Promise < ExecutionRecorder > {
17
23
const wasi = new WASI ( {
18
24
args : [ "node" , basename ( wasm ) ] ,
19
25
env : process . env ,
@@ -46,12 +52,23 @@ async function nodeExecutor(wasm: string, outFolder: string, imports?: Imports):
46
52
try {
47
53
wasi . start ( ins ) ;
48
54
const execTestFunction = ins . exports [ "executeTestFunction" ] ;
49
- if ( typeof execTestFunction === "function" ) {
50
- for ( const fncs of executionRecorder . registerFunctions ) {
51
- const functions = fncs [ 1 ] ;
52
- ( execTestFunction as ( a : number ) => void ) ( functions ) ;
55
+ assert ( typeof execTestFunction === "function" ) ;
56
+ if ( matchedTestNames === undefined ) {
57
+ // means execute all testFunctions
58
+ for ( const functionInfo of executionRecorder . registerFunctions ) {
59
+ const functionIndex = functionInfo [ 1 ] ;
60
+ ( execTestFunction as ( a : number ) => void ) ( functionIndex ) ;
53
61
mockInstrumentFunc [ "mockFunctionStatus.clear" ] ( ) ;
54
62
}
63
+ } else {
64
+ for ( const functionInfo of executionRecorder . registerFunctions ) {
65
+ const [ testName , functionIndex ] = functionInfo ;
66
+ if ( matchedTestNames . includes ( testName ) ) {
67
+ console . log ( testName ) ;
68
+ ( execTestFunction as ( a : number ) => void ) ( functionIndex ) ;
69
+ mockInstrumentFunc [ "mockFunctionStatus.clear" ] ( ) ;
70
+ }
71
+ }
55
72
}
56
73
} catch ( error ) {
57
74
if ( error instanceof Error ) {
@@ -66,14 +83,15 @@ async function nodeExecutor(wasm: string, outFolder: string, imports?: Imports):
66
83
export async function execWasmBinarys (
67
84
outFolder : string ,
68
85
instrumentResult : InstrumentResult [ ] ,
86
+ matchedTestNames ?: string [ ] ,
69
87
imports ?: Imports
70
88
) : Promise < AssertResult > {
71
89
const assertRes = new AssertResult ( ) ;
72
90
ensureDirSync ( outFolder ) ;
73
91
await Promise . all < void > (
74
92
instrumentResult . map ( async ( res ) : Promise < void > => {
75
93
const { instrumentedWasm, expectInfo } = res ;
76
- const recorder : ExecutionRecorder = await nodeExecutor ( instrumentedWasm , outFolder , imports ) ;
94
+ const recorder : ExecutionRecorder = await nodeExecutor ( instrumentedWasm , outFolder , matchedTestNames , imports ) ;
77
95
await assertRes . merge ( recorder , expectInfo ) ;
78
96
} )
79
97
) ;
0 commit comments