From 17cfcde9bde524c3203885aac969981c40fac724 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Sat, 14 Nov 2009 06:39:46 -0600 Subject: [PATCH 8/8] testsuite: Add --log option to write daemon log into file --- testsuite | 23 ++++++++++++++--------- 1 files changed, 14 insertions(+), 9 deletions(-) diff --git a/testsuite b/testsuite index 3b43e22..14f239e 100755 --- a/testsuite +++ b/testsuite @@ -42,6 +42,7 @@ import shutil import dbus import signal import stat +import optparse test_ram_dev1 = '/dev/ram8' test_ram_dev2 = '/dev/ram9' @@ -67,7 +68,7 @@ class DKDisksTestCase(unittest.TestCase): manager_props = None @classmethod - def init(klass): + def init(klass, logfile=None): '''start daemon and set up test environment''' assert os.geteuid() == 0, 'need to be root for running this' @@ -108,7 +109,10 @@ class DKDisksTestCase(unittest.TestCase): print 'daemon path:', daemon_path # start daemon - klass.daemon_log = tempfile.TemporaryFile() + if logfile: + klass.daemon_log = open(logfile, 'w') + else: + klass.daemon_log = tempfile.TemporaryFile() klass.daemon = subprocess.Popen([daemon_path, '--replace'], stdout=klass.daemon_log, stderr=subprocess.STDOUT) assert klass.daemon.pid, 'daemon failed to start' @@ -133,10 +137,6 @@ class DKDisksTestCase(unittest.TestCase): os.wait() klass.daemon = None - #print '----- daemon log ----' - #klass.daemon_log.seek(0) - #print klass.daemon_log.read() - @classmethod def sync(klass): '''Wait until pending events finished processing.''' @@ -1197,11 +1197,16 @@ class GlobalOps(DKDisksTestCase): # ---------------------------------------------------------------------------- if __name__ == '__main__': - DKDisksTestCase.init() - if len(sys.argv) == 1: + optparser = optparse.OptionParser('%prog [options] [test class] [test name] [...]') + optparser.add_option('-l', '--log-file', dest='logfile', + help='write daemon log to a file') + (opts, args) = optparser.parse_args() + + DKDisksTestCase.init(logfile=opts.logfile) + if len(args) == 0: tests = unittest.TestLoader().loadTestsFromName('__main__') else: - tests = unittest.TestLoader().loadTestsFromNames(sys.argv[1:], + tests = unittest.TestLoader().loadTestsFromNames(args, __import__('__main__')) unittest.TextTestRunner(verbosity=2).run(tests) -- 1.6.5