Gaudi Framework, version v21r6

Home   Generated: 11 Nov 2009

run_qmtest.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Small wrapper script to simplify the execution of QMTest tests.
00004 #
00005 # @author: Marco Clemencic <marco.clemencic@cern.ch>
00006 # @date: 22/10/2007
00007 #
00008 import os, sys
00009 
00010 class Options(object):
00011     pass
00012 
00013 def parseOptions(argv = None):
00014     if argv is None:
00015         argv = sys.argv[1:]
00016     # Defaults
00017     opts = Options()
00018     opts.package = "Unknown"
00019     opts.qmtest_args = []
00020     opts.have_user_options = False
00021     opts.output = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTS"]))
00022     opts.qmtest_dir = os.path.normpath(os.path.expandvars(os.environ["QMTESTLOCALDIR"]))
00023     opts.dry_run = False
00024     # First argument is the package name:
00025     if argv:
00026         opts.package = argv.pop(0)
00027     
00028     # Do we have user options? 
00029     opts.have_user_options = len(argv)
00030     # Scan the user options (if any) to look for options we must intercept
00031     while argv:
00032         o = argv.pop(0)
00033         if o in ['-o','--output']:
00034             # make the path absolute 
00035             opts.output = os.path.realpath(argv.pop(0))
00036             opts.have_user_options -= 2
00037         elif o in ["--no-output"]:
00038             opts.output = None
00039             opts.have_user_options -= 1
00040         elif o in ["--dry-run"]:
00041             opts.dry_run = True
00042             opts.have_user_options -= 1
00043         else:
00044             opts.qmtest_args.append(o)
00045     # Add the option for the output to the qmtest_args
00046     if opts.output:
00047         opts.qmtest_args = ["-o", opts.output] + opts.qmtest_args
00048     else:
00049         opts.qmtest_args.insert(0, "--no-output")
00050     return opts
00051 
00052 def main(argv = None):
00053     opts = parseOptions(argv)
00054     
00055     print "==========> Running tests for package %s" % opts.package
00056     
00057     # create the destination directory if necessary
00058     if opts.output:
00059         results_dest_dir = os.path.realpath(os.path.join(opts.qmtest_dir, os.path.dirname(opts.output)))
00060         if not os.path.exists(results_dest_dir):
00061             print "==========> Creating '%s'" % results_dest_dir
00062             os.makedirs(results_dest_dir, 0755)
00063     
00064     print "==========> Entering '%s'" % opts.qmtest_dir
00065     os.chdir(opts.qmtest_dir)
00066 
00067     if not os.path.isdir("QMTest"):
00068         # The QMTest database is not initialized
00069         print "==========> Initializing QMTest database"
00070         os.system("qmtest create-tdb")
00071 
00072     # prepare the qmtest command
00073     cmd = "qmtest run %s" % (" ".join(opts.qmtest_args))
00074     
00075     # check if we have a test suite called as the package
00076     if not opts.have_user_options and os.path.exists("%s.qms" % opts.package.lower()):
00077         cmd += " %s" % opts.package.lower()
00078     
00079     if opts.dry_run:
00080         print "==========> Would run '%s'"%cmd
00081     else:
00082         print "==========> Running '%s'"%cmd
00083         os.system(cmd)
00084 
00085 # Note: the return code of qmtest is not propagated to avoid that
00086 #       CMT stops if we have a non-PASS tests (e.g. UNTESTED).
00087 if __name__ == '__main__':
00088     main()

Generated at Wed Nov 11 16:23:08 2009 for Gaudi Framework, version v21r6 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004