reports/Builder__ReportRunner.st
author Claus Gittinger <cg@exept.de>
Thu, 28 Mar 2019 13:54:38 +0100
changeset 542 aa25a71be62a
parent 243 625f6907682a
permissions -rw-r--r--
#DOCUMENTATION by cg
class: stx_goodies_builder_quickSelfTest
class definition

class: stx_goodies_builder_quickSelfTest class
added:18 methods
     1 "{ Package: 'stx:goodies/builder/reports' }"
     2 
     3 "{ NameSpace: Builder }"
     4 
     5 StandaloneStartup subclass:#ReportRunner
     6 	instanceVariableNames:''
     7 	classVariableNames:''
     8 	poolDictionaries:''
     9 	category:'Builder-Reports'
    10 !
    11 
    12 ReportRunner class instanceVariableNames:'parser report debugging setup teardown ident'
    13 
    14 "
    15  The following class instance variables are inherited by this class:
    16 
    17 	StandaloneStartup - MutexHandle
    18 	Object - 
    19 "
    20 !
    21 
    22 
    23 !ReportRunner class methodsFor:'initialization'!
    24 
    25 initialize
    26 
    27     super initialize.
    28     debugging := Transcript notNil and:[Transcript isView].
    29     self setupSignalHandlers.
    30 
    31     "Created: / 06-11-2011 / 22:07:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    32     "Modified: / 28-06-2013 / 01:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    33 ! !
    34 
    35 !ReportRunner class methodsFor:'command line options'!
    36 
    37 cmdlineOptionIdent
    38 
    39     ^CmdLineOption new
    40         short: $i;
    41         long: 'ident';
    42         description: 'run/configuration identification';
    43         action:[:option |
    44             ident := option.
    45         ];
    46         yourself
    47 
    48     "Created: / 22-01-2014 / 10:00:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    49 !
    50 
    51 cmdlineOptionOutputDirectory
    52 
    53     ^CmdLineOption new
    54         short: $D;
    55         long: 'output-directory';
    56         description: 'Default report output directory';
    57         action:[:outputdir |
    58             Report outputDir: outputdir.
    59             self  verboseInfo:'Report dir: ' , Report outputDir asString.
    60         ];
    61         yourself
    62 
    63     "Created: / 06-11-2011 / 09:33:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    64     "Modified: / 22-01-2014 / 10:00:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    65 !
    66 
    67 cmdlineOptionReport
    68 
    69     ^CmdLineOption new
    70         short: $r;
    71         long: 'report';
    72         description: 'Report to run';
    73         action:[:option |
    74             report := Smalltalk at: option asSymbol.
    75             report isNil ifTrue:[
    76                 Stderr nextPutLine:('ERROR: Report class %1 does not exist (forgot to load package?)' bindWith: option).
    77                 "/Smalltalk exit: 1.
    78             ].
    79             report := report new.
    80             parser options addAll: (CmdLineOption optionsFor: report)
    81         ];
    82         yourself
    83 
    84     "Created: / 06-11-2011 / 09:45:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    85     "Modified: / 22-01-2014 / 10:00:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    86 !
    87 
    88 cmdlineOptionSetup
    89 
    90     ^CmdLineOption new
    91         short: $S;
    92         long: 'setup';
    93         description: 'Code executed before tests are loaded and executed';
    94         action:[:option |
    95             setup := option
    96         ];
    97         yourself
    98 
    99     "Created: / 15-05-2013 / 16:50:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   100     "Modified: / 24-01-2014 / 15:26:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   101 !
   102 
   103 cmdlineOptionTeardown
   104 
   105     ^CmdLineOption new
   106         short: $T;
   107         long: 'teardown';
   108         description: 'Code executed after all tests are executed';
   109         action:[:option |
   110             teardown := option
   111         ];
   112         yourself
   113 
   114     "Created: / 15-05-2013 / 16:50:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   115     "Modified: / 22-01-2014 / 10:01:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   116 ! !
   117 
   118 !ReportRunner class methodsFor:'debugging'!
   119 
   120 dumpProcess: aProcess
   121     Stderr cr; cr
   122 
   123     "Created: / 27-06-2013 / 23:41:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   124 !
   125 
   126 dumpProcess: aProcess on: aStream
   127     | ctx |
   128     aStream cr; cr.
   129     aStream nextPutAll: '== ['; nextPutAll: aProcess id printString; nextPutAll:'] '; nextPutAll: aProcess name; nextPutAll: ' =='; cr.
   130     aStream cr.
   131     aStream nextPutAll: '  State:   '; nextPutAll: aProcess state printString; cr.
   132     aStream nextPutAll: '  Group:   '; nextPutAll: aProcess processGroupId printString; cr.
   133     aStream nextPutAll: '  Creator: '; nextPutAll: aProcess processGroupId printString; cr.
   134     aStream nextPutAll: '  Stack:   '; cr; cr.
   135 
   136     aProcess == Processor activeProcess ifTrue:[ctx := thisContext] ifFalse:[ctx := aProcess suspendedContext].
   137     [ ctx notNil ] whileTrue:[
   138         aStream nextPutAll: '  '.
   139         ctx fullPrintOn: aStream.
   140         aStream cr.
   141         ctx := ctx sender.
   142     ].
   143     aStream cr.
   144 
   145     "
   146         self dumpProcess: Processor activeProcess on: Transcript.
   147     "
   148 
   149     "Created: / 28-06-2013 / 01:00:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   150     "Modified: / 06-06-2014 / 09:14:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   151 !
   152 
   153 dumpProcesses
   154     self dumpProcessesOn: Stderr
   155 
   156     "
   157     self dumpProcessesOn: Transcript.
   158     "
   159 
   160     "Created: / 27-06-2013 / 23:41:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   161     "Modified (comment): / 28-06-2013 / 01:06:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   162 !
   163 
   164 dumpProcessesOn: aStream
   165     Process allInstancesDo:[:process|
   166         process isDead ifFalse:[
   167             self dumpProcess: process on: aStream
   168         ]
   169     ]
   170 
   171     "Created: / 27-06-2013 / 23:42:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   172 ! !
   173 
   174 !ReportRunner class methodsFor:'defaults'!
   175 
   176 allowCoverageMeasurementOption
   177 
   178     ^false "CoverageReport will do that"
   179 
   180     "Created: / 13-01-2012 / 11:48:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   181 !
   182 
   183 allowDebugOption
   184 
   185     ^true
   186 
   187     "Created: / 21-07-2011 / 09:48:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   188 ! !
   189 
   190 !ReportRunner class methodsFor:'multiple applications support'!
   191 
   192 applicationRegistryPath
   193     "the key under which this application stores its process ID in the registry
   194      as a collection of path-components.
   195      i.e. if #('foo' 'bar' 'baz') is returned here, the current applications ID will be stored
   196      in HKEY_CURRENT_USER\Software\foo\bar\baz\CurrentID.
   197      (would also be used as a relative path for a temporary lock file under unix).
   198      Used to detect if another instance of this application is already running."
   199 
   200     ^ #('exept' 'smalltallx' 'hdreportrunner')
   201 
   202     "Modified: / 21-07-2011 / 09:43:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   203 !
   204 
   205 applicationUUID
   206     "answer an application-specific unique uuid.
   207      This is used as the name of some exclusive OS-resource, which is used to find out,
   208      if another instance of this application is already running.
   209      Under win32, a mutex is used; under unix, an exclusive file in the tempDir could be used."
   210 
   211     ^ '99f65c80-b375-11e0-86ad-0013e89c0459' asUUID
   212 
   213     "Modified: / 21-07-2011 / 09:44:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   214 ! !
   215 
   216 !ReportRunner class methodsFor:'startup'!
   217 
   218 handleSIGTERM
   219     self dumpProcesses.
   220     debugging ifFalse:[
   221         Smalltalk exit:127.
   222     ].
   223 
   224     "Created: / 27-06-2013 / 23:10:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   225     "Modified: / 28-06-2013 / 01:08:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   226 !
   227 
   228 handleSIGUSR2
   229     self dumpProcesses
   230 
   231     "Created: / 27-06-2013 / 23:10:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   232 !
   233 
   234 setupSignalHandlers
   235     "On UNIX, this sets up a custom signal handler on SIGUSR2 and SIGTERM that
   236      dumps stacks on all threads"
   237 
   238     | sigusr2 sigterm |
   239 
   240     OperatingSystem isUNIXlike ifTrue:[
   241 
   242 
   243         sigterm := Signal new.
   244         sigterm handlerBlock: [:ex | self handleSIGTERM].
   245         OperatingSystem operatingSystemSignal:OperatingSystem sigTERM install: sigterm.
   246         OperatingSystem enableSignal: OperatingSystem sigTERM.
   247 
   248         sigusr2 := Signal new.
   249         sigusr2 handlerBlock: [:ex | self handleSIGUSR2].
   250         OperatingSystem operatingSystemSignal:OperatingSystem sigUSR2 install: sigusr2.
   251         OperatingSystem enableSignal: OperatingSystem sigUSR2.
   252     ].
   253 
   254     "
   255     OperatingSystem sendSignal: OperatingSystem sigUSR2 to: OperatingSystem getProcessId
   256     "
   257 
   258     "Created: / 27-06-2013 / 20:57:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   259     "Modified: / 28-06-2013 / 01:11:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   260 !
   261 
   262 setupToolsForDebug
   263 
   264     super setupToolsForDebug.
   265     debugging := true.
   266 
   267     "Created: / 06-11-2011 / 22:06:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   268 !
   269 
   270 start
   271     Smalltalk silentLoading: true.
   272     ^ super start.
   273 
   274     "Created: / 22-01-2014 / 09:17:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   275 !
   276 
   277 usage
   278 
   279     Stderr nextPutAll:'usage: report-runner.';
   280            nextPutAll: (OperatingSystem isMSWINDOWSlike ifTrue:['bat'] ifFalse:['sh']);
   281            nextPutAll: ' [-D <dir>] -r <report> [-p <package1> [-p <package2> [...]]]'; cr.
   282 
   283     Stderr nextPutLine:'Common options:'; cr.
   284 
   285     Stderr nextPutLine:'  --help .................. output this message'.
   286 "/    Stderr nextPutLine:'  --verbose ............... verbose startup'.
   287 "/    Stderr nextPutLine:'  --noBanner .............. no splash screen'.
   288 "/    Stderr nextPutLine:'  --newAppInstance ........ start as its own application process (do not reuse'.
   289 "/    Stderr nextPutLine:'                            a running instance)'.
   290 "/    self allowScriptingOption ifTrue:[
   291 "/        Stderr nextPutLine:'  --scripting portNr ...enable scripting via port (or stdin/stdOut if 0)'.
   292 "/    ].
   293     self allowDebugOption ifTrue:[
   294         Stderr nextPutLine:'  --debug ................. enable Debugger'.
   295     ].
   296     "/                 '  ......................... '
   297     Stderr nextPutLine:'  -D <dir>'.
   298     Stderr nextPutLine:'  --output-directory=<dir>  directory where report files will go'.
   299     Stderr nextPutLine:'  -S <expr>'.
   300     Stderr nextPutLine:'  --setup=<expr> .......... smalltalk expression that is evaluated before'. 
   301     Stderr nextPutLine:'                            any report is run'.
   302     Stderr nextPutLine:'  -T <expr>'.
   303     Stderr nextPutLine:'  --teardown=<expr> ....... smalltalk expression that is evaluated before'. 
   304     Stderr nextPutLine:'                            after all reports finished'.
   305     Stderr nextPutLine:'  -i <ident>'.
   306     Stderr nextPutLine:'  --ident=<ident> ......... run/configuration identification string to'.
   307     Stderr nextPutLine:'                            use when creating output files'.
   308     Stderr nextPutLine:'  -r <report class>'.
   309     Stderr nextPutLine:'  --report=<report class> . report to run. available reports:'.
   310     Report available do:[:report|
   311         Stderr nextPutAll:'      '; nextPutLine: report name
   312     ].
   313     Stderr nextPutLine:'  -p <package>'.
   314     Stderr nextPutLine:'  --package=<package> ..... package to run report on'.
   315     Stderr nextPutLine:'                            May be specified multiple times.'.
   316 
   317     Report available do:[:cls|
   318         self usageForReportClass: cls.
   319     ].
   320 
   321 
   322     debugging ifFalse:[
   323         Smalltalk exit:1.
   324     ].
   325     "
   326     self usage
   327     "
   328 
   329     "Created: / 13-01-2012 / 11:48:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   330     "Modified: / 27-05-2014 / 17:02:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   331 !
   332 
   333 usageForReportClass: class
   334     | options |
   335 
   336     "/ '.........................' size  25
   337     options := CmdLineOption optionsFor: class new.
   338     options := options reject:[:option | 'pF' includes: option short  ].
   339     options notEmptyOrNil ifTrue:[
   340         Stderr cr.
   341         Stderr nextPutAll: class name; nextPutLine:' options:'; cr.
   342         options do:[:option |                
   343             | optlen |  
   344 
   345             option short notNil ifTrue:[ 
   346                 Stderr nextPutAll: '  '.
   347                 Stderr nextPut: $-; nextPut: option short; space.
   348                 optlen := 2.
   349                 option hasParam ifTrue:[ 
   350                     | paramName |
   351 
   352                     paramName := 'val'.
   353                     Stderr nextPut:$<; nextPutAll: paramName; nextPut:$>; space.
   354                     optlen := optlen + 3 + paramName size.
   355                 ].
   356             ].
   357             option long notNil ifTrue:[ 
   358                  option short notNil ifTrue:[ 
   359                     Stderr cr.
   360                 ].
   361                 Stderr nextPutAll: '  --'.
   362                 Stderr nextPutAll: option long.
   363                 optlen := option long size + 2.
   364                 option hasParam ifTrue:[ 
   365                     | paramName |
   366 
   367                     paramName := 'val'.
   368                     Stderr nextPut:$=; nextPut:$<; nextPutAll: paramName; nextPut:$>.
   369                     optlen := optlen + 3 + paramName size.
   370                 ].
   371                 Stderr space.
   372             ].
   373             Stderr next: (26 - 1"space" -2"--" - optlen) put: $..    
   374             Stderr space.
   375             option description notNil ifTrue:[
   376                 Stderr nextPutAll: option description
   377             ].
   378             Stderr cr.
   379         ]
   380     ]
   381 
   382     "
   383     ReportRunner usageForReportClass: TestReport.
   384     "
   385 
   386     "Created: / 27-05-2014 / 16:42:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   387     "Modified: / 16-06-2014 / 11:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   388 ! !
   389 
   390 !ReportRunner class methodsFor:'startup-to be redefined'!
   391 
   392 main:argv0
   393     "Process command line arguments"
   394 
   395     | argv |
   396 
   397     argv := argv0 asOrderedCollection.
   398     argv isEmpty ifTrue:[ 
   399         self usage.
   400     ].
   401     argv remove: '--abortOnSEGV' ifAbsent:[nil].
   402     parser := CmdLineParser new.
   403     CmdLineOptionError autoload.
   404 
   405     [
   406         parser parse: argv for: self.
   407     ] on:CmdLineOptionError do:[:ex|
   408         Stderr nextPutLine:'Error when processing options: ', ex description.
   409         debugging ifFalse:[
   410             ex suspendedContext fullPrintAllOn: Stderr.
   411             Stderr nextPutLine:'Exiting'.
   412             Smalltalk exit:1.
   413         ] ifTrue:[
   414             ex pass
   415         ]
   416     ].
   417 
   418     debugging ifFalse:[ 
   419         NoHandlerError emergencyHandler:(NoHandlerError abortingEmergencyHandler)
   420     ].
   421 
   422     [
   423         setup notNil ifTrue:[Compiler evaluate: setup].
   424         [
   425             report ident: ident.
   426             report run.
   427         ] ensure:[
   428             teardown notNil ifTrue:[Compiler evaluate: teardown].
   429         ].
   430         debugging ifFalse:[
   431             Smalltalk exit:0.
   432         ].
   433     ] on: Error do:[:ex|
   434         Stderr nextPutAll:'Error when running tests: '.
   435         Stderr nextPutAll:ex description; cr.
   436         ex suspendedContext printAllOn:Stderr.
   437 
   438 
   439         debugging ifFalse:[
   440             Smalltalk exit:1.
   441         ] ifTrue:[
   442             ex pass
   443         ]
   444     ]
   445 
   446     "Modified: / 27-05-2014 / 17:05:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   447 ! !
   448 
   449 !ReportRunner class methodsFor:'documentation'!
   450 
   451 version
   452     ^ '$Header$'
   453 !
   454 
   455 version_CVS
   456     ^ '$Header$'
   457 !
   458 
   459 version_SVN
   460     ^ '$Id$'
   461 ! !
   462 
   463 
   464 ReportRunner initialize!