Print this page
11814 test-runner exit code should reflect test results

@@ -12,11 +12,11 @@
 #
 
 #
 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
 # Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
-# Copyright 2018 Joyent, Inc.
+# Copyright 2019 Joyent, Inc.
 #
 
 import ConfigParser
 import os
 import logging

@@ -37,10 +37,12 @@
 BASEDIR = '/var/tmp/test_results'
 KILL = '/usr/bin/kill'
 TRUE = '/usr/bin/true'
 SUDO = '/usr/bin/sudo'
 
+retcode = 0
+
 # Custom class to reopen the log file in case it is forcibly closed by a test.
 class WatchedFileHandlerClosed(WatchedFileHandler):
     """Watch files, including closed files.
     Similar to (and inherits from) logging.handler.WatchedFileHandler,
     except that IOErrors are handled by reopening the stream and retrying.

@@ -82,26 +84,30 @@
         """
         Finalize the results of this Cmd.
         Report SKIP for return codes 3,4 (NOTINUSE, UNSUPPORTED)
         as defined in ../stf/include/stf.shlib
         """
+        global retcode
+
         Result.total += 1
         m, s = divmod(time() - self.starttime, 60)
         self.runtime = '%02d:%02d' % (m, s)
         self.returncode = proc.returncode
         if killed:
             self.result = 'KILLED'
             Result.runresults['KILLED'] += 1
+            retcode = 2;
         elif self.returncode is 0:
             self.result = 'PASS'
             Result.runresults['PASS'] += 1
         elif self.returncode is 3 or self.returncode is 4:
             self.result = 'SKIP'
             Result.runresults['SKIP'] += 1
         elif self.returncode is not 0:
             self.result = 'FAIL'
             Result.runresults['FAIL'] += 1
+            retcode = 1;
 
 
 class Output(object):
     """
     This class is a slightly modified version of the 'Stream' class found

@@ -888,10 +894,10 @@
         fail('Unknown command specified')
 
     testrun.complete_outputdirs()
     testrun.run(options)
     testrun.summary()
-    exit(0)
+    exit(retcode)
 
 
 if __name__ == '__main__':
     main()