@@ -2,7 +2,7 @@ import WasmKit
2
2
import XCTest
3
3
4
4
final class FuzzTranslatorRegressionTests : XCTestCase {
5
- func testRunAll( ) async throws {
5
+ func testRunAll( ) throws {
6
6
let sourceRoot = URL ( fileURLWithPath: #filePath)
7
7
. deletingLastPathComponent ( ) . deletingLastPathComponent ( ) . deletingLastPathComponent ( )
8
8
let failCasesDir =
@@ -12,34 +12,40 @@ final class FuzzTranslatorRegressionTests: XCTestCase {
12
12
for file in try FileManager . default. contentsOfDirectory ( atPath: failCasesDir. path) {
13
13
let path = failCasesDir. appendingPathComponent ( file) . path
14
14
print ( " Fuzz regression test: \( path. dropFirst ( sourceRoot. path. count + 1 ) ) " )
15
-
16
- let data = try Data ( contentsOf: URL ( fileURLWithPath: path) )
17
- do {
18
- let module = try WasmKit . parseWasm ( bytes: Array ( data) )
19
- let engine = Engine ( configuration: EngineConfiguration ( compilationMode: . eager) )
20
- let store = Store ( engine: engine)
21
- var imports = Imports ( )
22
- for importEntry in module. imports {
23
- let value : ExternalValueConvertible
24
- switch importEntry. descriptor {
25
- case . function( let typeIndex) :
26
- let type = module. types [ Int ( typeIndex) ]
27
- value = Function ( store: store, type: type) { _, _ in
28
- fatalError ( " unreachable " )
29
- }
30
- case . global( let globalType) :
31
- value = try Global ( store: store, type: globalType, value: . i32( 0 ) )
32
- case . memory( let memoryType) :
33
- value = try Memory ( store: store, type: memoryType)
34
- case . table( let tableType) :
35
- value = try Table ( store: store, type: tableType)
36
- }
37
- imports. define ( module: importEntry. module, name: importEntry. name, value. externalValue)
38
- }
39
- _ = try module. instantiate ( store: store, imports: imports)
40
- } catch {
41
- // Explicit errors are ok
42
- }
15
+ try checkFuzzCase ( path: path)
43
16
}
44
17
}
18
+
19
+ func checkFuzzCase( path: String ) throws {
20
+ let data = try Data ( contentsOf: URL ( fileURLWithPath: path) )
21
+ do {
22
+ let module = try WasmKit . parseWasm ( bytes: Array ( data) )
23
+ let engine = Engine ( configuration: EngineConfiguration ( compilationMode: . eager) )
24
+ let store = Store ( engine: engine)
25
+ var imports = Imports ( )
26
+ for importEntry in module. imports {
27
+ let value : ExternalValueConvertible
28
+ switch importEntry. descriptor {
29
+ case . function( let typeIndex) :
30
+ guard typeIndex < module. types. count else { return }
31
+ let type = module. types [ Int ( typeIndex) ]
32
+ value = Function ( store: store, type: type) { _, _ in
33
+ // Provide "start function" with empty results
34
+ if type. results. isEmpty { return [ ] }
35
+ fatalError ( " Unexpected function call " )
36
+ }
37
+ case . global( let globalType) :
38
+ value = try Global ( store: store, type: globalType, value: . i32( 0 ) )
39
+ case . memory( let memoryType) :
40
+ value = try Memory ( store: store, type: memoryType)
41
+ case . table( let tableType) :
42
+ value = try Table ( store: store, type: tableType)
43
+ }
44
+ imports. define ( module: importEntry. module, name: importEntry. name, value. externalValue)
45
+ }
46
+ _ = try module. instantiate ( store: store, imports: imports)
47
+ } catch {
48
+ // Explicit errors are ok
49
+ }
50
+ }
45
51
}
0 commit comments