Gaudi Framework, version v21r7

Home   Generated: 22 Jan 2010

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     # If the use specifies a directory where to collect all the results
00029     # (e.g. because running from a read-only location) we must use it
00030     if "QMTESTRESULTSDIR" in os.environ:
00031         opts.output = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTSDIR"]))
00032         opts.output = os.path.join(opts.output,
00033                                    "%s.%s.qmr" % (opts.package, os.environ.get("CMTCONFIG", "noConfig")))
00034     
00035     # Do we have user options? 
00036     opts.have_user_options = len(argv)
00037     # Scan the user options (if any) to look for options we must intercept
00038     while argv:
00039         o = argv.pop(0)
00040         if o in ['-o','--output']:
00041             # make the path absolute 
00042             opts.output = os.path.realpath(argv.pop(0))
00043             opts.have_user_options -= 2
00044         elif o in ["--no-output"]:
00045             opts.output = None
00046             opts.have_user_options -= 1
00047         elif o in ["--dry-run"]:
00048             opts.dry_run = True
00049             opts.have_user_options -= 1
00050         else:
00051             opts.qmtest_args.append(o)
00052     # Add the option for the output to the qmtest_args
00053     if opts.output:
00054         opts.qmtest_args = ["-o", opts.output] + opts.qmtest_args
00055     else:
00056         opts.qmtest_args.insert(0, "--no-output")
00057     return opts
00058 
00059 def main(argv = None):
00060     opts = parseOptions(argv)
00061     
00062     print "==========> Running tests for package %s" % opts.package
00063     
00064     # create the destination directory if necessary
00065     if opts.output:
00066         results_dest_dir = os.path.realpath(os.path.join(opts.qmtest_dir, os.path.dirname(opts.output)))
00067         if not os.path.exists(results_dest_dir):
00068             print "==========> Creating '%s'" % results_dest_dir
00069             os.makedirs(results_dest_dir, 0755)
00070     
00071     print "==========> Entering '%s'" % opts.qmtest_dir
00072     os.chdir(opts.qmtest_dir)
00073 
00074     if not os.path.isdir("QMTest"):
00075         # The QMTest database is not initialized
00076         print "==========> Initializing QMTest database"
00077         os.system("qmtest create-tdb")
00078 
00079     # prepare the qmtest command
00080     cmd = "qmtest run %s" % (" ".join(opts.qmtest_args))
00081     
00082     # check if we have a test suite called as the package
00083     if not opts.have_user_options and os.path.exists("%s.qms" % opts.package.lower()):
00084         cmd += " %s" % opts.package.lower()
00085     
00086     if opts.dry_run:
00087         print "==========> Would run '%s'"%cmd
00088     else:
00089         print "==========> Running '%s'"%cmd
00090         os.system(cmd)
00091 
00092 # Note: the return code of qmtest is not propagated to avoid that
00093 #       CMT stops if we have a non-PASS tests (e.g. UNTESTED).
00094 if __name__ == '__main__':
00095     main()

Generated at Fri Jan 22 20:27:58 2010 for Gaudi Framework, version v21r7 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004