@@ -24,6 +24,29 @@ class LiveTests: XCTestCase {
2424 // Set to true to log failing programs
2525 static let VERBOSE = false
2626
27+ /// Meta-test ensuring that the test framework can successfully terminate an endless loop.
28+ func testEndlessLoopTermination( ) throws {
29+ let runner = try GetJavaScriptExecutorOrSkipTest ( )
30+
31+ let results = try Self . runLiveTest ( iterations: 1 , withRunner: runner, timeoutInSeconds: 1 ) { b in
32+ b. loadInt ( 123 ) // prefix
33+
34+ let module = b. buildWasmModule ( ) { module in
35+ module. addWasmFunction ( with: [ ] => [ ] ) { function, label, args in
36+ function. wasmBuildLoop ( with: [ ] => [ ] , args: [ ] ) { label, args in
37+ function. wasmBranch ( to: label)
38+ return [ ]
39+ }
40+ return [ ]
41+ }
42+ }
43+ b. callMethod ( module. getExportedMethod ( at: 0 ) , on: module. loadExports ( ) , withArgs: [ ] )
44+ }
45+ assert ( results. failureRate == 1 )
46+ assert ( results. failureMessages. count == 1 )
47+ print ( results. failureMessages)
48+ }
49+
2750 func testValueGeneration( ) throws {
2851 let runner = try GetJavaScriptExecutorOrSkipTest ( )
2952
@@ -142,7 +165,7 @@ class LiveTests: XCTestCase {
142165 // The closure can use the ProgramBuilder to emit a program of a specific
143166 // shape that is then executed with the given runner. We then check that
144167 // we stay below the maximum failure rate over the given number of iterations.
145- static func runLiveTest( iterations n: Int = 250 , withRunner runner: JavaScriptExecutor , body: ( ProgramBuilder ) -> Void ) throws -> ( failureRate: Double , failureMessages: [ String : Int ] ) {
168+ static func runLiveTest( iterations n: Int = 250 , withRunner runner: JavaScriptExecutor , timeoutInSeconds : Int = 5 , body: ( ProgramBuilder ) -> Void ) throws -> ( failureRate: Double , failureMessages: [ String : Int ] ) {
146169 let liveTestConfig = Configuration ( logLevel: . error, enableInspection: true )
147170
148171 // We have to use the proper JavaScriptEnvironment here.
@@ -178,7 +201,7 @@ class LiveTests: XCTestCase {
178201 }
179202
180203 DispatchQueue . concurrentPerform ( iterations: n) { i in
181- let result = executeAndParseResults ( program: programs [ i] , runner: runner)
204+ let result = executeAndParseResults ( program: programs [ i] , runner: runner, timeoutInSeconds : timeoutInSeconds )
182205 results [ i] = result
183206 }
184207
@@ -214,10 +237,11 @@ class LiveTests: XCTestCase {
214237 }
215238 }
216239
217- static func executeAndParseResults( program: ( program: Program , jsProgram: String ) , runner: JavaScriptExecutor ) -> ExecutionResult {
240+ static func executeAndParseResults( program: ( program: Program , jsProgram: String ) , runner: JavaScriptExecutor , timeoutInSeconds : Int ) -> ExecutionResult {
218241
219242 do {
220- let result = try runner. executeScript ( program. jsProgram, withTimeout: 5 * Seconds)
243+ let result = try runner. executeScript ( program. jsProgram,
244+ withTimeout: Double ( timeoutInSeconds) * Seconds)
221245 if result. isFailure {
222246 var signature : String ? = nil
223247
0 commit comments