2015-01-19 18:03:23 +01:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, https://www.qubes-os.org/
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2014-2015 Wojtek Porczyk <woju@invisiblethingslab.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
2015-01-05 14:41:59 +01:00
|
|
|
|
2015-10-17 00:10:15 +02:00
|
|
|
import argparse
|
2017-08-28 14:31:43 +02:00
|
|
|
import code
|
2015-01-07 16:46:59 +01:00
|
|
|
import curses
|
2017-01-18 22:16:46 +01:00
|
|
|
import itertools
|
2015-10-17 00:10:15 +02:00
|
|
|
import logging
|
|
|
|
import logging.handlers
|
|
|
|
import os
|
2015-01-20 15:18:08 +01:00
|
|
|
import socket
|
2015-10-17 00:10:15 +02:00
|
|
|
import subprocess
|
2015-01-05 14:41:59 +01:00
|
|
|
import sys
|
|
|
|
import unittest
|
2015-10-17 00:10:15 +02:00
|
|
|
import unittest.signals
|
2015-01-05 14:41:59 +01:00
|
|
|
|
2015-01-20 15:18:08 +01:00
|
|
|
import qubes.tests
|
2017-06-05 16:14:30 +02:00
|
|
|
import qubes.api.admin
|
2015-01-20 15:18:08 +01:00
|
|
|
|
2015-10-17 00:10:15 +02:00
|
|
|
class CursesColor(dict):
|
2017-01-18 22:16:46 +01:00
|
|
|
colors = (
|
|
|
|
'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white')
|
|
|
|
attrs = {
|
|
|
|
'bold': 'bold', 'normal': 'sgr0'}
|
2015-01-07 16:46:59 +01:00
|
|
|
def __init__(self):
|
2015-10-17 00:10:15 +02:00
|
|
|
super(CursesColor, self).__init__()
|
2017-01-18 22:16:46 +01:00
|
|
|
self.has_colors = False
|
2015-01-07 16:46:59 +01:00
|
|
|
try:
|
|
|
|
curses.setupterm()
|
2017-01-18 22:16:46 +01:00
|
|
|
self.has_colors = True
|
2015-01-07 16:46:59 +01:00
|
|
|
except curses.error:
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def __missing__(self, key):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=unused-argument,no-self-use
|
2017-01-18 22:16:46 +01:00
|
|
|
if not self.has_colors:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
try:
|
|
|
|
value = curses.tigetstr(self.attrs[key])
|
|
|
|
except KeyError:
|
|
|
|
try:
|
|
|
|
value = curses.tparm(
|
|
|
|
curses.tigetstr('setaf'), self.colors.index(key))
|
|
|
|
except ValueError:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
value = value.decode()
|
|
|
|
self[key] = value
|
|
|
|
return value
|
2015-01-07 16:46:59 +01:00
|
|
|
|
|
|
|
|
2015-10-17 00:10:15 +02:00
|
|
|
class QubesTestResult(unittest.TestResult):
|
2015-01-07 16:46:59 +01:00
|
|
|
'''A test result class that can print colourful text results to a stream.
|
|
|
|
|
|
|
|
Used by TextTestRunner. This is a lightly rewritten unittest.TextTestResult.
|
|
|
|
'''
|
|
|
|
|
|
|
|
separator1 = unittest.TextTestResult.separator1
|
|
|
|
separator2 = unittest.TextTestResult.separator2
|
|
|
|
|
|
|
|
def __init__(self, stream, descriptions, verbosity):
|
2015-10-17 00:10:15 +02:00
|
|
|
super(QubesTestResult, self).__init__(stream, descriptions, verbosity)
|
2015-01-07 16:46:59 +01:00
|
|
|
self.stream = stream
|
2015-01-19 19:02:28 +01:00
|
|
|
self.showAll = verbosity > 1 # pylint: disable=invalid-name
|
2015-01-07 16:46:59 +01:00
|
|
|
self.dots = verbosity == 1
|
|
|
|
self.descriptions = descriptions
|
|
|
|
|
2015-10-17 00:10:15 +02:00
|
|
|
self.color = CursesColor()
|
2015-01-20 15:18:08 +01:00
|
|
|
self.hostname = socket.gethostname()
|
2015-01-07 16:46:59 +01:00
|
|
|
|
2015-10-17 00:10:15 +02:00
|
|
|
self.log = logging.getLogger('qubes.tests')
|
|
|
|
|
|
|
|
|
2015-01-07 16:46:59 +01:00
|
|
|
def _fmtexc(self, err):
|
2015-01-20 14:41:19 +01:00
|
|
|
if str(err[1]):
|
2015-01-13 22:35:10 +01:00
|
|
|
return '{color[bold]}{}:{color[normal]} {!s}'.format(
|
|
|
|
err[0].__name__, err[1], color=self.color)
|
2015-01-07 16:46:59 +01:00
|
|
|
else:
|
2015-01-13 22:35:10 +01:00
|
|
|
return '{color[bold]}{}{color[normal]}'.format(
|
|
|
|
err[0].__name__, color=self.color)
|
2015-01-07 16:46:59 +01:00
|
|
|
|
2015-12-29 19:54:15 +01:00
|
|
|
def get_log(self, test):
|
|
|
|
try:
|
|
|
|
return test.log
|
|
|
|
except AttributeError:
|
|
|
|
return self.log
|
|
|
|
|
2015-01-19 19:02:28 +01:00
|
|
|
def getDescription(self, test): # pylint: disable=invalid-name
|
2015-01-07 16:46:59 +01:00
|
|
|
teststr = str(test).split('/')
|
2015-01-20 15:18:08 +01:00
|
|
|
for i in range(-2, 0):
|
2015-01-23 18:37:40 +01:00
|
|
|
try:
|
|
|
|
fullname = teststr[i].split('_', 2)
|
|
|
|
except IndexError:
|
|
|
|
continue
|
2015-01-20 15:18:08 +01:00
|
|
|
fullname[-1] = '{color[bold]}{}{color[normal]}'.format(
|
|
|
|
fullname[-1], color=self.color)
|
|
|
|
teststr[i] = '_'.join(fullname)
|
2015-01-07 16:46:59 +01:00
|
|
|
teststr = '/'.join(teststr)
|
|
|
|
|
|
|
|
doc_first_line = test.shortDescription()
|
|
|
|
if self.descriptions and doc_first_line:
|
|
|
|
return '\n'.join((teststr, ' {}'.format(
|
2015-01-13 22:35:10 +01:00
|
|
|
doc_first_line, color=self.color)))
|
2015-01-07 16:46:59 +01:00
|
|
|
else:
|
|
|
|
return teststr
|
|
|
|
|
2015-01-19 19:02:28 +01:00
|
|
|
def startTest(self, test): # pylint: disable=invalid-name
|
2015-10-17 00:10:15 +02:00
|
|
|
super(QubesTestResult, self).startTest(test)
|
2015-12-29 19:54:15 +01:00
|
|
|
self.get_log(test).critical('started')
|
2015-01-07 16:46:59 +01:00
|
|
|
if self.showAll:
|
2015-01-20 15:18:08 +01:00
|
|
|
if not qubes.tests.in_git:
|
|
|
|
self.stream.write('{}: '.format(self.hostname))
|
2015-01-07 16:46:59 +01:00
|
|
|
self.stream.write(self.getDescription(test))
|
|
|
|
self.stream.write(' ... ')
|
|
|
|
self.stream.flush()
|
|
|
|
|
2015-01-19 19:02:28 +01:00
|
|
|
def addSuccess(self, test): # pylint: disable=invalid-name
|
2015-10-17 00:10:15 +02:00
|
|
|
super(QubesTestResult, self).addSuccess(test)
|
2015-12-29 19:54:15 +01:00
|
|
|
self.get_log(test).warning('ok')
|
2015-01-07 16:46:59 +01:00
|
|
|
if self.showAll:
|
2015-01-13 22:35:10 +01:00
|
|
|
self.stream.writeln('{color[green]}ok{color[normal]}'.format(
|
|
|
|
color=self.color))
|
2015-01-07 16:46:59 +01:00
|
|
|
elif self.dots:
|
|
|
|
self.stream.write('.')
|
|
|
|
self.stream.flush()
|
|
|
|
|
2015-01-19 19:02:28 +01:00
|
|
|
def addError(self, test, err): # pylint: disable=invalid-name
|
2015-10-17 00:10:15 +02:00
|
|
|
super(QubesTestResult, self).addError(test, err)
|
2015-12-29 19:54:15 +01:00
|
|
|
self.get_log(test).critical(
|
|
|
|
'ERROR ({err[0].__name__}: {err[1]!r})'.format(err=err))
|
2015-01-07 16:46:59 +01:00
|
|
|
if self.showAll:
|
2015-01-13 22:35:10 +01:00
|
|
|
self.stream.writeln(
|
|
|
|
'{color[red]}{color[bold]}ERROR{color[normal]} ({})'.format(
|
|
|
|
self._fmtexc(err), color=self.color))
|
2015-01-07 16:46:59 +01:00
|
|
|
elif self.dots:
|
2015-01-13 22:35:10 +01:00
|
|
|
self.stream.write(
|
|
|
|
'{color[red]}{color[bold]}E{color[normal]}'.format(
|
|
|
|
color=self.color))
|
2015-01-07 16:46:59 +01:00
|
|
|
self.stream.flush()
|
|
|
|
|
2015-01-19 19:02:28 +01:00
|
|
|
def addFailure(self, test, err): # pylint: disable=invalid-name
|
2015-10-17 00:10:15 +02:00
|
|
|
super(QubesTestResult, self).addFailure(test, err)
|
2015-12-29 19:54:15 +01:00
|
|
|
self.get_log(test).error(
|
|
|
|
'FAIL ({err[0].__name__}: {err[1]!r})'.format(err=err))
|
2015-01-07 16:46:59 +01:00
|
|
|
if self.showAll:
|
2015-01-13 22:35:10 +01:00
|
|
|
self.stream.writeln('{color[red]}FAIL{color[normal]}'.format(
|
|
|
|
color=self.color))
|
2015-01-07 16:46:59 +01:00
|
|
|
elif self.dots:
|
2015-01-13 22:35:10 +01:00
|
|
|
self.stream.write('{color[red]}F{color[normal]}'.format(
|
|
|
|
color=self.color))
|
2015-01-07 16:46:59 +01:00
|
|
|
self.stream.flush()
|
|
|
|
|
2015-01-19 19:02:28 +01:00
|
|
|
def addSkip(self, test, reason): # pylint: disable=invalid-name
|
2015-10-17 00:10:15 +02:00
|
|
|
super(QubesTestResult, self).addSkip(test, reason)
|
2015-12-29 19:54:15 +01:00
|
|
|
self.get_log(test).warning('skipped ({})'.format(reason))
|
2015-01-07 16:46:59 +01:00
|
|
|
if self.showAll:
|
2015-01-13 22:35:10 +01:00
|
|
|
self.stream.writeln(
|
|
|
|
'{color[cyan]}skipped{color[normal]} ({})'.format(
|
|
|
|
reason, color=self.color))
|
2015-01-07 16:46:59 +01:00
|
|
|
elif self.dots:
|
2015-01-13 22:35:10 +01:00
|
|
|
self.stream.write('{color[cyan]}s{color[normal]}'.format(
|
|
|
|
color=self.color))
|
2015-01-07 16:46:59 +01:00
|
|
|
self.stream.flush()
|
|
|
|
|
2015-01-19 19:02:28 +01:00
|
|
|
def addExpectedFailure(self, test, err): # pylint: disable=invalid-name
|
2015-10-17 00:10:15 +02:00
|
|
|
super(QubesTestResult, self).addExpectedFailure(test, err)
|
2015-12-29 19:54:15 +01:00
|
|
|
self.get_log(test).warning('expected failure')
|
2015-01-07 16:46:59 +01:00
|
|
|
if self.showAll:
|
2015-01-13 22:35:10 +01:00
|
|
|
self.stream.writeln(
|
|
|
|
'{color[yellow]}expected failure{color[normal]}'.format(
|
|
|
|
color=self.color))
|
2015-01-07 16:46:59 +01:00
|
|
|
elif self.dots:
|
2015-01-13 22:35:10 +01:00
|
|
|
self.stream.write('{color[yellow]}x{color[normal]}'.format(
|
|
|
|
color=self.color))
|
2015-01-07 16:46:59 +01:00
|
|
|
self.stream.flush()
|
|
|
|
|
2015-01-19 19:02:28 +01:00
|
|
|
def addUnexpectedSuccess(self, test): # pylint: disable=invalid-name
|
2015-10-17 00:10:15 +02:00
|
|
|
super(QubesTestResult, self).addUnexpectedSuccess(test)
|
2015-12-29 19:54:15 +01:00
|
|
|
self.get_log(test).error('unexpected success')
|
2015-01-07 16:46:59 +01:00
|
|
|
if self.showAll:
|
|
|
|
self.stream.writeln(
|
2015-01-19 17:06:30 +01:00
|
|
|
'{color[yellow]}{color[bold]}unexpected success'
|
|
|
|
'{color[normal]}'.format(color=self.color))
|
2015-01-07 16:46:59 +01:00
|
|
|
elif self.dots:
|
2015-01-13 22:35:10 +01:00
|
|
|
self.stream.write(
|
|
|
|
'{color[yellow]}{color[bold]}u{color[normal]}'.format(
|
|
|
|
color=self.color))
|
2015-01-07 16:46:59 +01:00
|
|
|
self.stream.flush()
|
|
|
|
|
2015-01-19 19:02:28 +01:00
|
|
|
def printErrors(self): # pylint: disable=invalid-name
|
2015-01-07 16:46:59 +01:00
|
|
|
if self.dots or self.showAll:
|
|
|
|
self.stream.writeln()
|
|
|
|
self.printErrorList(
|
2015-01-13 22:35:10 +01:00
|
|
|
'{color[red]}{color[bold]}ERROR{color[normal]}'.format(
|
|
|
|
color=self.color),
|
|
|
|
self.errors)
|
2015-01-07 16:46:59 +01:00
|
|
|
self.printErrorList(
|
2016-10-14 17:20:14 +02:00
|
|
|
'{color[red]}FAIL{color[normal]}'.format(
|
|
|
|
color=self.color),
|
2015-01-13 22:35:10 +01:00
|
|
|
self.failures)
|
2016-10-14 17:20:14 +02:00
|
|
|
self.printErrorList(
|
|
|
|
'{color[yellow]}EXPECTED{color[normal]}'.format(
|
|
|
|
color=self.color),
|
|
|
|
self.expectedFailures)
|
2015-01-07 16:46:59 +01:00
|
|
|
|
2015-01-19 19:02:28 +01:00
|
|
|
def printErrorList(self, flavour, errors): # pylint: disable=invalid-name
|
2015-01-07 16:46:59 +01:00
|
|
|
for test, err in errors:
|
|
|
|
self.stream.writeln(self.separator1)
|
2015-01-19 17:06:30 +01:00
|
|
|
self.stream.writeln('%s: %s' % (flavour, self.getDescription(test)))
|
2015-01-07 16:46:59 +01:00
|
|
|
self.stream.writeln(self.separator2)
|
|
|
|
self.stream.writeln('%s' % err)
|
|
|
|
|
|
|
|
|
|
|
|
def demo(verbosity=2):
|
2015-01-20 14:41:19 +01:00
|
|
|
class TC_00_Demo(qubes.tests.QubesTestCase):
|
2015-01-07 16:46:59 +01:00
|
|
|
'''Demo class'''
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=no-self-use
|
2015-01-07 16:46:59 +01:00
|
|
|
def test_0_success(self):
|
|
|
|
'''Demo test (success)'''
|
|
|
|
pass
|
|
|
|
def test_1_error(self):
|
|
|
|
'''Demo test (error)'''
|
|
|
|
raise Exception()
|
|
|
|
def test_2_failure(self):
|
|
|
|
'''Demo test (failure)'''
|
|
|
|
self.fail('boo')
|
|
|
|
def test_3_skip(self):
|
|
|
|
'''Demo test (skipped by call to self.skipTest())'''
|
|
|
|
self.skipTest('skip')
|
|
|
|
@unittest.skip(None)
|
|
|
|
def test_4_skip_decorator(self):
|
|
|
|
'''Demo test (skipped by decorator)'''
|
|
|
|
pass
|
|
|
|
@unittest.expectedFailure
|
|
|
|
def test_5_expected_failure(self):
|
|
|
|
'''Demo test (expected failure)'''
|
|
|
|
self.fail()
|
|
|
|
@unittest.expectedFailure
|
|
|
|
def test_6_unexpected_success(self):
|
|
|
|
'''Demo test (unexpected success)'''
|
|
|
|
pass
|
|
|
|
|
2015-01-20 14:41:19 +01:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TC_00_Demo)
|
2015-01-07 16:46:59 +01:00
|
|
|
runner = unittest.TextTestRunner(stream=sys.stdout, verbosity=verbosity)
|
2015-10-17 00:10:15 +02:00
|
|
|
runner.resultclass = QubesTestResult
|
2015-01-07 16:46:59 +01:00
|
|
|
return runner.run(suite).wasSuccessful()
|
|
|
|
|
|
|
|
|
2015-10-17 00:10:15 +02:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
epilog='''When running only specific tests, write their names like in log,
|
|
|
|
in format: MODULE+"/"+CLASS+"/"+FUNCTION. MODULE should omit initial
|
|
|
|
"qubes.tests.". Example: basic/TC_00_Basic/test_000_create''')
|
|
|
|
|
|
|
|
parser.add_argument('--verbose', '-v',
|
|
|
|
action='count',
|
|
|
|
help='increase console verbosity level')
|
|
|
|
parser.add_argument('--quiet', '-q',
|
|
|
|
action='count',
|
|
|
|
help='decrease console verbosity level')
|
|
|
|
|
|
|
|
parser.add_argument('--list', '-l',
|
|
|
|
action='store_true', dest='list',
|
|
|
|
help='list all available tests and exit')
|
|
|
|
|
|
|
|
parser.add_argument('--failfast', '-f',
|
|
|
|
action='store_true', dest='failfast',
|
|
|
|
help='stop on the first fail, error or unexpected success')
|
|
|
|
parser.add_argument('--no-failfast',
|
|
|
|
action='store_false', dest='failfast',
|
|
|
|
help='disable --failfast')
|
|
|
|
|
|
|
|
# pylint: disable=protected-access
|
2017-01-18 22:16:46 +01:00
|
|
|
try:
|
|
|
|
name_to_level = logging._nameToLevel
|
|
|
|
except AttributeError:
|
|
|
|
name_to_level = logging._levelNames
|
2015-10-17 00:10:15 +02:00
|
|
|
parser.add_argument('--loglevel', '-L', metavar='LEVEL',
|
|
|
|
action='store', choices=tuple(k
|
2017-01-18 22:16:46 +01:00
|
|
|
for k in sorted(name_to_level.keys(),
|
|
|
|
key=lambda x: name_to_level[x])
|
|
|
|
if isinstance(k, str)),
|
2015-10-17 00:10:15 +02:00
|
|
|
help='logging level for file and syslog forwarding '
|
|
|
|
'(one of: %(choices)s; default: %(default)s)')
|
2017-01-18 22:16:46 +01:00
|
|
|
del name_to_level
|
2015-10-17 00:10:15 +02:00
|
|
|
# pylint: enable=protected-access
|
|
|
|
|
|
|
|
parser.add_argument('--logfile', '-o', metavar='FILE',
|
|
|
|
action='store',
|
|
|
|
help='if set, test run will be also logged to file')
|
|
|
|
|
|
|
|
parser.add_argument('--syslog',
|
|
|
|
action='store_true', dest='syslog',
|
|
|
|
help='reenable logging to syslog')
|
|
|
|
parser.add_argument('--no-syslog',
|
|
|
|
action='store_false', dest='syslog',
|
|
|
|
help='disable logging to syslog')
|
|
|
|
|
|
|
|
parser.add_argument('--kmsg', '--very-brave-or-very-stupid',
|
|
|
|
action='store_true', dest='kmsg',
|
|
|
|
help='log most important things to kernel ring-buffer')
|
|
|
|
parser.add_argument('--no-kmsg', '--i-am-smarter-than-kay-sievers',
|
|
|
|
action='store_false', dest='kmsg',
|
|
|
|
help='do not abuse kernel ring-buffer')
|
|
|
|
|
2017-06-05 16:14:30 +02:00
|
|
|
parser.add_argument('--allow-running-along-qubesd',
|
|
|
|
action='store_true', default=False,
|
|
|
|
help='allow running in parallel with qubesd;'
|
|
|
|
' this is DANGEROUS and WILL RESULT IN INCONSISTENT SYSTEM STATE')
|
|
|
|
|
2017-08-28 14:31:43 +02:00
|
|
|
parser.add_argument('--break-to-repl',
|
|
|
|
action='store_true', default=False,
|
|
|
|
help='break to REPL after tests')
|
|
|
|
|
2015-10-17 00:10:15 +02:00
|
|
|
parser.add_argument('names', metavar='TESTNAME',
|
|
|
|
action='store', nargs='*',
|
|
|
|
help='list of tests to run named like in description '
|
|
|
|
'(default: run all tests)')
|
|
|
|
|
|
|
|
parser.set_defaults(
|
|
|
|
failfast=False,
|
|
|
|
loglevel='DEBUG',
|
|
|
|
logfile=None,
|
|
|
|
syslog=True,
|
|
|
|
kmsg=False,
|
|
|
|
verbose=2,
|
|
|
|
quiet=0)
|
|
|
|
|
|
|
|
|
|
|
|
def list_test_cases(suite):
|
|
|
|
for test in suite:
|
|
|
|
if isinstance(test, unittest.TestSuite):
|
|
|
|
#yield from
|
|
|
|
for i in list_test_cases(test):
|
|
|
|
yield i
|
|
|
|
else:
|
|
|
|
yield test
|
|
|
|
|
|
|
|
|
2017-08-28 14:31:43 +02:00
|
|
|
def main(args=None):
|
|
|
|
args = parser.parse_args(args)
|
2015-10-17 00:10:15 +02:00
|
|
|
|
2015-01-05 14:41:59 +01:00
|
|
|
suite = unittest.TestSuite()
|
|
|
|
loader = unittest.TestLoader()
|
|
|
|
|
2015-10-17 00:10:15 +02:00
|
|
|
if args.names:
|
|
|
|
alltests = loader.loadTestsFromName('qubes.tests')
|
|
|
|
for name in args.names:
|
|
|
|
suite.addTests(
|
|
|
|
[test for test in list_test_cases(alltests)
|
2016-05-02 00:19:18 +02:00
|
|
|
if str(test).startswith(name)])
|
2015-10-17 00:10:15 +02:00
|
|
|
else:
|
|
|
|
suite.addTests(loader.loadTestsFromName('qubes.tests'))
|
|
|
|
|
|
|
|
if args.list:
|
|
|
|
for test in list_test_cases(suite):
|
|
|
|
print(str(test)) # pylint: disable=superfluous-parens
|
|
|
|
return True
|
|
|
|
|
|
|
|
logging.root.setLevel(args.loglevel)
|
|
|
|
|
|
|
|
if args.logfile is not None:
|
|
|
|
ha_file = logging.FileHandler(
|
|
|
|
os.path.join(os.environ['HOME'], args.logfile))
|
|
|
|
ha_file.setFormatter(
|
|
|
|
logging.Formatter('%(asctime)s %(name)s[%(process)d]: %(message)s'))
|
|
|
|
logging.root.addHandler(ha_file)
|
|
|
|
|
|
|
|
if args.syslog:
|
|
|
|
ha_syslog = logging.handlers.SysLogHandler('/dev/log')
|
|
|
|
ha_syslog.setFormatter(
|
|
|
|
logging.Formatter('%(name)s[%(process)d]: %(message)s'))
|
|
|
|
logging.root.addHandler(ha_syslog)
|
|
|
|
|
|
|
|
if args.kmsg:
|
|
|
|
try:
|
|
|
|
subprocess.check_call(('sudo', 'chmod', '666', '/dev/kmsg'))
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
parser.error('could not chmod /dev/kmsg')
|
|
|
|
else:
|
|
|
|
ha_kmsg = logging.FileHandler('/dev/kmsg', 'w')
|
|
|
|
ha_kmsg.setFormatter(
|
|
|
|
logging.Formatter('%(name)s[%(process)d]: %(message)s'))
|
|
|
|
ha_kmsg.setLevel(logging.CRITICAL)
|
|
|
|
logging.root.addHandler(ha_kmsg)
|
|
|
|
|
2017-06-05 16:14:30 +02:00
|
|
|
if not args.allow_running_along_qubesd \
|
2017-06-06 15:49:19 +02:00
|
|
|
and os.path.exists(qubes.api.admin.QubesAdminAPI.SOCKNAME):
|
2017-06-05 16:14:30 +02:00
|
|
|
parser.error('refusing to run until qubesd is disabled')
|
|
|
|
|
2015-10-17 00:10:15 +02:00
|
|
|
runner = unittest.TextTestRunner(stream=sys.stdout,
|
|
|
|
verbosity=(args.verbose-args.quiet),
|
|
|
|
failfast=args.failfast)
|
|
|
|
unittest.signals.installHandler()
|
2017-08-31 20:22:05 +02:00
|
|
|
runner.resultclass = QubesTestResult
|
2017-08-28 14:31:43 +02:00
|
|
|
result = runner.run(suite)
|
|
|
|
|
|
|
|
if args.break_to_repl:
|
|
|
|
code.interact(local=locals())
|
|
|
|
|
|
|
|
return result.wasSuccessful()
|
2015-01-05 14:41:59 +01:00
|
|
|
|
2015-10-17 00:10:15 +02:00
|
|
|
|
2015-01-05 14:41:59 +01:00
|
|
|
if __name__ == '__main__':
|
2015-01-07 16:46:59 +01:00
|
|
|
sys.exit(not main())
|