1 #!/usr/bin/python2.6
2
3 #
4 # This file and its contents are supplied under the terms of the
5 # Common Development and Distribution License ("CDDL"), version 1.0.
6 # You may only use this file in accordance with the terms of version
7 # 1.0 of the CDDL.
8 #
9 # A full copy of the text of the CDDL should have accompanied this
10 # source. A copy of the CDDL is also available via the Internet at
11 # http://www.illumos.org/license/CDDL.
12 #
13
14 #
15 # Copyright (c) 2012 by Delphix. All rights reserved.
16 #
17
18 import ConfigParser
19 import os
20 import logging
21 from datetime import datetime
22 from optparse import OptionParser
23 from pwd import getpwnam
24 from pwd import getpwuid
25 from select import select
26 from subprocess import PIPE
27 from subprocess import Popen
28 from sys import argv
29 from sys import exit
30 from threading import Timer
31 from time import time
32
33 BASEDIR = '/var/tmp/test_results'
34 KILL = '/usr/bin/kill'
35 TRUE = '/usr/bin/true'
217 command.
218 """
219 Result.total += 1
220 Result.runresults['SKIP'] += 1
221 self.result.stdout = self.result.stderr = []
222 self.result.starttime = time()
223 m, s = divmod(time() - self.result.starttime, 60)
224 self.result.runtime = '%02d:%02d' % (m, s)
225 self.result.result = 'SKIP'
226
227 def log(self, logger, options):
228 """
229 This function is responsible for writing all output. This includes
230 the console output, the logfile of all results (with timestamped
231 merged stdout and stderr), and for each test, the unmodified
232 stdout/stderr/merged in it's own file.
233 """
234 if logger is None:
235 return
236
237 user = ' (run as %s)' % self.user if len(self.user) else ''
238 msga = 'Test: %s%s ' % (self.pathname, user)
239 msgb = '[%s] [%s]' % (self.result.runtime, self.result.result)
240 pad = ' ' * (80 - (len(msga) + len(msgb)))
241
242 # If -q is specified, only print a line for tests that didn't pass.
243 # This means passing tests need to be logged as DEBUG, or the one
244 # line summary will only be printed in the logfile for failures.
245 if not options.quiet:
246 logger.info('%s%s%s' % (msga, pad, msgb))
247 elif self.result.result is not 'PASS':
248 logger.info('%s%s%s' % (msga, pad, msgb))
249 else:
250 logger.debug('%s%s%s' % (msga, pad, msgb))
251
252 lines = self.result.stdout + self.result.stderr
253 for dt, line in sorted(lines):
254 logger.debug('%s %s' % (dt.strftime("%H:%M:%S.%f ")[:11], line))
255
256 if len(self.result.stdout):
257 with open(os.path.join(self.outputdir, 'stdout'), 'w') as out:
|
1 #!/usr/bin/python2.6
2
3 #
4 # This file and its contents are supplied under the terms of the
5 # Common Development and Distribution License ("CDDL"), version 1.0.
6 # You may only use this file in accordance with the terms of version
7 # 1.0 of the CDDL.
8 #
9 # A full copy of the text of the CDDL should have accompanied this
10 # source. A copy of the CDDL is also available via the Internet at
11 # http://www.illumos.org/license/CDDL.
12 #
13
14 #
15 # Copyright (c) 2013 by Delphix. All rights reserved.
16 #
17
18 import ConfigParser
19 import os
20 import logging
21 from datetime import datetime
22 from optparse import OptionParser
23 from pwd import getpwnam
24 from pwd import getpwuid
25 from select import select
26 from subprocess import PIPE
27 from subprocess import Popen
28 from sys import argv
29 from sys import exit
30 from threading import Timer
31 from time import time
32
33 BASEDIR = '/var/tmp/test_results'
34 KILL = '/usr/bin/kill'
35 TRUE = '/usr/bin/true'
217 command.
218 """
219 Result.total += 1
220 Result.runresults['SKIP'] += 1
221 self.result.stdout = self.result.stderr = []
222 self.result.starttime = time()
223 m, s = divmod(time() - self.result.starttime, 60)
224 self.result.runtime = '%02d:%02d' % (m, s)
225 self.result.result = 'SKIP'
226
227 def log(self, logger, options):
228 """
229 This function is responsible for writing all output. This includes
230 the console output, the logfile of all results (with timestamped
231 merged stdout and stderr), and for each test, the unmodified
232 stdout/stderr/merged in it's own file.
233 """
234 if logger is None:
235 return
236
237 logname = getpwuid(os.getuid()).pw_name
238 user = ' (run as %s)' % (self.user if len(self.user) else logname)
239 msga = 'Test: %s%s ' % (self.pathname, user)
240 msgb = '[%s] [%s]' % (self.result.runtime, self.result.result)
241 pad = ' ' * (80 - (len(msga) + len(msgb)))
242
243 # If -q is specified, only print a line for tests that didn't pass.
244 # This means passing tests need to be logged as DEBUG, or the one
245 # line summary will only be printed in the logfile for failures.
246 if not options.quiet:
247 logger.info('%s%s%s' % (msga, pad, msgb))
248 elif self.result.result is not 'PASS':
249 logger.info('%s%s%s' % (msga, pad, msgb))
250 else:
251 logger.debug('%s%s%s' % (msga, pad, msgb))
252
253 lines = self.result.stdout + self.result.stderr
254 for dt, line in sorted(lines):
255 logger.debug('%s %s' % (dt.strftime("%H:%M:%S.%f ")[:11], line))
256
257 if len(self.result.stdout):
258 with open(os.path.join(self.outputdir, 'stdout'), 'w') as out:
|