hwsim tests: Pass --logdir to run-tests.py

Instead of passing the log directory for each option
(-l, -r, -e, and -T) pass it once and make the other
options just take the filename (optionally, even).

This will also make it easier to extend later.

Signed-hostap: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2013-10-30 22:37:15 +01:00 committed by Jouni Malinen
parent 958bf1ba39
commit 0141fa5244
2 changed files with 27 additions and 11 deletions

View file

@ -49,7 +49,7 @@ fi
if [ "x$1" = "xtrace" ] ; then if [ "x$1" = "xtrace" ] ; then
TRACE=trace TRACE=trace
SUFFIX=$SUFFIX-trace SUFFIX=$SUFFIX-trace
TRACE_ARGS="-T $LOGDIR" TRACE_ARGS="-T"
shift shift
else else
unset TRACE unset TRACE
@ -66,7 +66,7 @@ fi
if ! [ -z "$LOGBASEDIR" ] ; then if ! [ -z "$LOGBASEDIR" ] ; then
rm $LOGBASEDIR/last-debug 2>/dev/null rm $LOGBASEDIR/last-debug 2>/dev/null
fi fi
./run-tests.py $TRACE_ARGS -l $LOGDIR/run $DB -e $LOGDIR/failed -r $LOGDIR/results.txt $CONCURRENT_TESTS $@ || errors=1 ./run-tests.py --logdir "$LOGDIR" $TRACE_ARGS -l run $DB -e failed -r results.txt $CONCURRENT_TESTS $@ || errors=1
if ! [ -z "$LOGBASEDIR" ] ; then if ! [ -z "$LOGBASEDIR" ] ; then
cat $LOGDIR/run >> $LOGBASEDIR/last-debug cat $LOGDIR/run >> $LOGBASEDIR/last-debug

View file

@ -89,6 +89,9 @@ def main():
print_res = False print_res = False
parser = argparse.ArgumentParser(description='hwsim test runner') parser = argparse.ArgumentParser(description='hwsim test runner')
parser.add_argument('--logdir', metavar='<directory>', default='logs',
help='log output directory for all other options, ' +
'must be given if other log options are used')
group = parser.add_mutually_exclusive_group() group = parser.add_mutually_exclusive_group()
group.add_argument('-d', const=logging.DEBUG, action='store_const', group.add_argument('-d', const=logging.DEBUG, action='store_const',
dest='loglevel', default=logging.INFO, dest='loglevel', default=logging.INFO,
@ -96,12 +99,15 @@ def main():
group.add_argument('-q', const=logging.WARNING, action='store_const', group.add_argument('-q', const=logging.WARNING, action='store_const',
dest='loglevel', help="be quiet") dest='loglevel', help="be quiet")
group.add_argument('-l', metavar='<filename>', dest='logfile', group.add_argument('-l', metavar='<filename>', dest='logfile',
help='debug log filename') help='debug log filename (in log directory)')
parser.add_argument('-e', metavar="<filename>", dest='errorfile', parser.add_argument('-e', metavar="<filename>", dest='errorfile',
help='error filename') nargs='?', const="failed",
help='error filename (in log directory)')
parser.add_argument('-r', metavar="<filename>", dest='resultsfile', parser.add_argument('-r', metavar="<filename>", dest='resultsfile',
help='results filename') nargs='?', const="results.txt",
help='results filename (in log directory)')
parser.add_argument('-S', metavar='<sqlite3 db>', dest='database', parser.add_argument('-S', metavar='<sqlite3 db>', dest='database',
help='database to write results to') help='database to write results to')
parser.add_argument('--commit', metavar='<commit id>', parser.add_argument('--commit', metavar='<commit id>',
@ -109,8 +115,8 @@ def main():
parser.add_argument('-b', metavar='<build>', dest='build', help='build ID') parser.add_argument('-b', metavar='<build>', dest='build', help='build ID')
parser.add_argument('-L', action='store_true', dest='update_tests_db', parser.add_argument('-L', action='store_true', dest='update_tests_db',
help='List tests (and update descriptions in DB)') help='List tests (and update descriptions in DB)')
parser.add_argument('-T', metavar='<dir>', dest='tracedir', parser.add_argument('-T', action='store_true', dest='tracing',
help='tracing directory - will get a trace file per test') help='collect tracing per test case (in log directory)')
parser.add_argument('-f', dest='testmodules', metavar='<test module>', parser.add_argument('-f', dest='testmodules', metavar='<test module>',
help='execute only tests from these test modules', help='execute only tests from these test modules',
type=str, choices=[[]] + test_modules, nargs='+') type=str, choices=[[]] + test_modules, nargs='+')
@ -124,8 +130,14 @@ def main():
print 'Invalid arguments - both test module and tests given' print 'Invalid arguments - both test module and tests given'
sys.exit(2) sys.exit(2)
if (args.logfile or args.errorfile or
args.resultsfile or args.tracing):
if not args.logdir:
print 'Need --logdir for the given options'
sys.exit(2)
if args.logfile: if args.logfile:
logging.basicConfig(filename=args.logfile, logging.basicConfig(filename=os.path.join(args.logdir, args.logfile),
level=logging.DEBUG) level=logging.DEBUG)
log_to_file = True log_to_file = True
else: else:
@ -134,8 +146,12 @@ def main():
if args.loglevel == logging.WARNING: if args.loglevel == logging.WARNING:
print_res = True print_res = True
error_file = args.errorfile error_file = args.errorfile and os.path.join(args.logdir, args.errorfile)
results_file = args.resultsfile results_file = args.resultsfile and os.path.join(args.logdir, args.resultsfile)
tracedir = None
if args.tracing:
tracedir = args.logdir
if args.database: if args.database:
import sqlite3 import sqlite3
@ -190,7 +206,7 @@ def main():
if args.testmodules: if args.testmodules:
if not t.__module__ in args.testmodules: if not t.__module__ in args.testmodules:
continue continue
with Tracer(args.tracedir, t.__name__): with Tracer(tracedir, t.__name__):
reset_devs(dev, apdev) reset_devs(dev, apdev)
logger.info("START " + t.__name__) logger.info("START " + t.__name__)
if log_to_file: if log_to_file: