@@ -24,6 +24,28 @@ 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+ }
48+
2749 func testValueGeneration( ) throws {
2850 let runner = try GetJavaScriptExecutorOrSkipTest ( )
2951
@@ -142,7 +164,7 @@ class LiveTests: XCTestCase {
142164 // The closure can use the ProgramBuilder to emit a program of a specific
143165 // shape that is then executed with the given runner. We then check that
144166 // 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 ] ) {
167+ static func runLiveTest( iterations n: Int = 250 , withRunner runner: JavaScriptExecutor , timeoutInSeconds : Int = 5 , body: ( ProgramBuilder ) -> Void ) throws -> ( failureRate: Double , failureMessages: [ String : Int ] ) {
146168 let liveTestConfig = Configuration ( logLevel: . error, enableInspection: true )
147169
148170 // We have to use the proper JavaScriptEnvironment here.
@@ -178,7 +200,7 @@ class LiveTests: XCTestCase {
178200 }
179201
180202 DispatchQueue . concurrentPerform ( iterations: n) { i in
181- let result = executeAndParseResults ( program: programs [ i] , runner: runner)
203+ let result = executeAndParseResults ( program: programs [ i] , runner: runner, timeoutInSeconds : timeoutInSeconds )
182204 results [ i] = result
183205 }
184206
@@ -214,10 +236,11 @@ class LiveTests: XCTestCase {
214236 }
215237 }
216238
217- static func executeAndParseResults( program: ( program: Program , jsProgram: String ) , runner: JavaScriptExecutor ) -> ExecutionResult {
239+ static func executeAndParseResults( program: ( program: Program , jsProgram: String ) , runner: JavaScriptExecutor , timeoutInSeconds : Int ) -> ExecutionResult {
218240
219241 do {
220- let result = try runner. executeScript ( program. jsProgram, withTimeout: 5 * Seconds)
242+ let result = try runner. executeScript ( program. jsProgram,
243+ withTimeout: Double ( timeoutInSeconds) * Seconds)
221244 if result. isFailure {
222245 var signature : String ? = nil
223246
0 commit comments