RegressionTests__SnapshotRestartTests.st
branchjv
changeset 1568 4fc22e888376
parent 1567 e17701a073f9
child 1569 e4f47eb7a708
--- a/RegressionTests__SnapshotRestartTests.st	Thu Jan 05 23:36:28 2017 +0000
+++ b/RegressionTests__SnapshotRestartTests.st	Fri Jan 06 23:41:06 2017 +0000
@@ -17,37 +17,6 @@
 !
 
 
-!SnapshotRestartTests methodsFor:'asserting'!
-
-assertAllTestsPassed: logfile
-    | innerSuite expected logfileContents |
-
-    innerSuite := ToRunOnFreshAndRestartedSnapshotTests buildSuite.
-    expected := '%1 run, %1 passed, 0 skipped, 0 failed, 0 errors ### HERE ### ' bindWith: innerSuite tests size.
-    logfile readingFileDo:[:s |
-	[ s atEnd ] whileFalse:[
-	    | line |
-
-	    line := s nextLine.
-	    "/ Uss starts with because on Windows you get 0xD chars at the end, sigh
-	    (line startsWith: expected) ifTrue:[ ^ self ].
-	]
-    ].
-    "
-    logfile contents asString
-    "
-    logfile readingFileDo: [ :f |
-        "Read at most 5MB of the log to avoid reading gigabytes 
-         of output produced by a 'thundestorm'."
-        logfileContents := f next: (logfile fileSize min: (16 * 1024"16Kb")).
-	"/ logfileContents := 'Disabled'.
-    ].
-    self assert: false description: ('Not all inner tests passed: ' , logfileContents).
-
-    "Created: / 14-08-2013 / 20:06:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified (format): / 31-05-2016 / 17:00:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
 !SnapshotRestartTests methodsFor:'compilation'!
 
 make
@@ -58,6 +27,9 @@
 
 make: target
     | cmd |
+    pkgdir := Smalltalk getPackageDirectoryForPackage: #'stx:goodies/regression/testData/packages/snapshot_restart'.
+    self assert: pkgdir notNil.
+    self assert: pkgdir isDirectory.     
 
     OperatingSystem isMSWINDOWSlike ifTrue:[ 
         STCCompilerInterface getCCDefine = '__BORLANDC__' ifTrue:[ 
@@ -98,58 +70,73 @@
 
     "Created: / 14-08-2013 / 18:26:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 05-11-2016 / 22:48:25 / jv"
-    "Modified: / 10-11-2016 / 00:23:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-01-2017 / 23:20:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!SnapshotRestartTests methodsFor:'private'!
+
+do: setupBlock onRestartDo: restartBlock
+    self assert: setupBlock byteCode notNil   description: 'setupBlock must have bytecode - stc-compiled blocks not supported'.
+    self assert: restartBlock byteCode notNil description: 'restartBlock must have bytecode - stc-compiled blocks not supported'.
+
+    setupBlock value.
+    Smalltalk addImageStartBlock:[
+        [ 
+            Stdout nextPutLine:'===> Restarted from snapshot'.
+            restartBlock value.
+            Smalltalk exit: EXIT_CODE_SUCCESS.
+        ] fork
+    ].
+    Stdout nextPutLine:'===> Saving snapshot to ', testSelector , '.img'.
+    ObjectMemory snapShotOn: testSelector , '.img'.
+    Smalltalk exit: EXIT_CODE_SUCCESS.
+
+    "Created: / 06-01-2017 / 22:14:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-01-2017 / 23:36:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+performTest
+    | tempDir imageFile |
+
+    [
+        tempDir := Filename newTemporary.
+        tempDir makeDirectory.
+        self spawnSelector:#performTestInternal inDirectory:tempDir.
+
+        imageFile := tempDir / (testSelector , '.img').
+        self assert: imageFile exists description: 'Image file does not exist - did test save it?'.
+        self spawnSmalltalk: { '--image' . imageFile pathName } inDirectory: tempDir
+    ] ensure:[
+        (tempDir notNil and:[ tempDir exists ]) ifTrue:[
+            [
+                tempDir recursiveRemove.
+            ] on:Error
+                    do:[:ex | 
+                OperatingSystem isMSWINDOWSlike ifFalse:[
+                    ex reject.
+                ].
+            ]
+        ].
+    ].       
+
+    "Created: / 06-01-2017 / 22:05:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+performTestInternal
+    super performTest.
+
+    "Created: / 06-01-2017 / 22:04:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !SnapshotRestartTests methodsFor:'running'!
 
-runTestsOnFreshImage
-    | script log logfile |
-
-    script := pkgdir / 'run-ToRunOnFreshAndRestartedSnapshotTests-tests.st'.
-    self assert: script exists.
-    log := FileStream newTemporaryIn: Filename currentDirectory nameTemplate: ('RegressionTests__SnapshotRestartTests-' , testSelector , '%1-%2.log').
-    logfile := log fileName.
-    [
-	OperatingSystem executeCommand: ('%1 --execute %2' bindWith: exe with: script asAbsoluteFilename pathName) outputTo: log errorTo: log inDirectory: tmpdir pathName.
-    ] ensure:[
-	log close.
-    ].
-
-    self assertAllTestsPassed: logfile.
-
-    "Created: / 14-08-2013 / 20:06:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 13-09-2013 / 12:54:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-runTestsOnRestartedImage
-    |  log logfile |
-
-    log := FileStream newTemporaryIn: Filename currentDirectory nameTemplate: ('RegressionTests__SnapshotRestartTests-' , testSelector , '%1-%2.log').
-    logfile := log fileName.
-    [
-	OperatingSystem executeCommand: ('%1 -i %2' bindWith: exe with: (tmpdir / 'restart.img') pathName ) outputTo: log errorTo: log inDirectory: tmpdir pathName
-    ] ensure:[
-	log close.
-    ].
-    self assertAllTestsPassed: logfile.
-
-    "Created: / 14-08-2013 / 20:10:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 13-09-2013 / 12:54:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
 setUp
     tmpdir := Filename newTemporaryDirectory.
-    pkgdir := Smalltalk getPackageDirectoryForPackage: #'stx:goodies/regression/testData/packages/snapshot_restart'.
-    self assert: pkgdir notNil.
-    self assert: pkgdir isDirectory.
-
     exe := OperatingSystem pathOfSTXExecutable.
-
     self make:'clobber'.
 
     "Created: / 14-08-2013 / 18:21:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 14-08-2013 / 20:17:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 06-01-2017 / 23:21:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 tearDown
@@ -161,24 +148,42 @@
 !SnapshotRestartTests methodsFor:'tests'!
 
 test_bc
+    "Test restart with bytecode-compiled package"
 
-    "Test restsrt with bytecode-compiled package"
+    | result |
 
-    self runTestsOnFreshImage.
-    self runTestsOnRestartedImage.
+    self do:[
+        result := ToRunOnFreshAndRestartedSnapshotTests buildSuite run.
+        self assert: result errorCount == 0.
+        self assert: result failureCount == 0.
+    ] onRestartDo:[ 
+        result := ToRunOnFreshAndRestartedSnapshotTests buildSuite run.
+        self assert: result errorCount == 0.
+        self assert: result failureCount == 0.
+    ].
 
     "Created: / 14-08-2013 / 19:58:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-01-2017 / 23:37:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 test_stc
+    "Test restart with bytecode-compiled package"
 
-    "Test restsrt with bytecode-compiled package"
+    | result |
 
-    self make.
-    self runTestsOnFreshImage.
-    self runTestsOnRestartedImage.
+    self do:[
+        self make.
+        result := ToRunOnFreshAndRestartedSnapshotTests buildSuite run.
+        self assert: result errorCount == 0.
+        self assert: result failureCount == 0.
+    ] onRestartDo:[ 
+        result := ToRunOnFreshAndRestartedSnapshotTests buildSuite run.
+        self assert: result errorCount == 0.
+        self assert: result failureCount == 0.
+    ].
 
     "Created: / 14-08-2013 / 20:26:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-01-2017 / 23:31:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !SnapshotRestartTests::ToRunOnFreshAndRestartedSnapshotTests methodsFor:'running'!