hwsim tests: Allow run-tests.py to start tracing

In order to get tracing per test, allow run-tests.py to start
and stop tracing per test case. This is implemented using a
python 'with' context so it starts/stops automatically at the
right spots.

Instead of starting global tracing, also use it from run-all.sh
and put the trace files into the log dir.

Note that this only works right if you use a separate log dir
for all test runs as the trace files aren't timestamped.

Signed-hostap: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2013-10-30 21:05:24 +01:00 committed by Jouni Malinen
parent 0648c3b8f5
commit 435e37df7c
2 changed files with 88 additions and 67 deletions

View file

@ -44,9 +44,11 @@ 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"
shift shift
else else
unset TRACE unset TRACE
unset TRACE_ARGS
fi fi
if ! ./start.sh $CONCURRENT $VALGRIND $TRACE; then if ! ./start.sh $CONCURRENT $VALGRIND $TRACE; then
@ -55,14 +57,7 @@ if ! ./start.sh $CONCURRENT $VALGRIND $TRACE; then
fi fi
DATE=`ls -1tr $LOGDIR | tail -1 | cut -f1 -d-` DATE=`ls -1tr $LOGDIR | tail -1 | cut -f1 -d-`
rm $LOGDIR/last-debug 2>/dev/null rm $LOGDIR/last-debug 2>/dev/null
RUNTESTS="./run-tests.py -l $LOGDIR/$DATE-run $DB -e $LOGDIR/$DATE-failed -r $LOGDIR/results.txt $CONCURRENT_TESTS $@" ./run-tests.py $TRACE_ARGS -l $LOGDIR/$DATE-run $DB -e $LOGDIR/$DATE-failed -r $LOGDIR/results.txt $CONCURRENT_TESTS $@ || errors=1
if [ "$TRACE" != "" ] ; then
sudo trace-cmd record -o $LOGDIR/$DATE-trace.dat -e mac80211 -e cfg80211 su $USER -c $RUNTESTS || errors=1
else
$RUNTESTS || errors=1
fi
cat $LOGDIR/$DATE-run >> $LOGDIR/last-debug cat $LOGDIR/$DATE-run >> $LOGDIR/last-debug
./stop-wifi.sh ./stop-wifi.sh

View file

@ -12,6 +12,7 @@ import sys
import time import time
from datetime import datetime from datetime import datetime
import argparse import argparse
import subprocess
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -47,6 +48,28 @@ def report(conn, build, commit, run, test, result, diff):
print "sqlite: " + str(e) print "sqlite: " + str(e)
print "sql: %r" % (params, ) print "sql: %r" % (params, )
class Tracer(object):
def __init__(self, tracedir, testname):
self._tracedir = tracedir
self._testname = testname
def __enter__(self):
if not self._tracedir:
return
output = os.path.join(self._tracedir, '%s.dat' % (self._testname, ))
self._trace_cmd = subprocess.Popen(['sudo', 'trace-cmd', 'record', '-o', output, '-e', 'mac80211', '-e', 'cfg80211', 'sh', '-c', 'echo STARTED ; read l'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=open('/dev/null', 'w'),
cwd=self._tracedir)
l = self._trace_cmd.stdout.read(7)
while not 'STARTED' in l:
l += self._trace_cmd.stdout.read(1)
def __exit__(self, type, value, traceback):
if not self._tracedir:
return
self._trace_cmd.stdin.write('DONE\n')
self._trace_cmd.wait()
def main(): def main():
tests = [] tests = []
test_modules = [] test_modules = []
@ -86,6 +109,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',
help='tracing directory - will get a trace file per test')
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='+')
@ -165,70 +190,71 @@ def main():
if args.testmodules: if args.testmodules:
if not t.__module__ in args.testmodules: if not t.__module__ in args.testmodules:
continue continue
reset_devs(dev, apdev) with Tracer(args.tracedir, t.__name__):
logger.info("START " + t.__name__) reset_devs(dev, apdev)
if log_to_file: logger.info("START " + t.__name__)
print "START " + t.__name__
sys.stdout.flush()
if t.__doc__:
logger.info("Test: " + t.__doc__)
start = datetime.now()
for d in dev:
try:
d.request("NOTE TEST-START " + t.__name__)
except Exception, e:
logger.info("Failed to issue TEST-START before " + t.__name__ + " for " + d.ifname)
logger.info(e)
print "FAIL " + t.__name__ + " - could not start test"
if conn:
conn.close()
conn = None
sys.exit(1)
try:
if t.func_code.co_argcount > 1:
res = t(dev, apdev)
else:
res = t(dev)
end = datetime.now()
diff = end - start
if res == "skip":
skipped.append(t.__name__)
result = "SKIP"
else:
passed.append(t.__name__)
result = "PASS"
report(conn, args.build, args.commit, run, t.__name__, result, diff)
result = result + " " + t.__name__ + " "
result = result + str(diff.total_seconds()) + " " + str(end)
logger.info(result)
if log_to_file or print_res:
print result
sys.stdout.flush()
if results_file:
f = open(results_file, 'a')
f.write(result + "\n")
f.close()
except Exception, e:
end = datetime.now()
diff = end - start
logger.info(e)
failed.append(t.__name__)
report(conn, args.build, args.commit, run, t.__name__, "FAIL", diff)
result = "FAIL " + t.__name__ + " " + str(diff.total_seconds()) + " " + str(end)
logger.info(result)
if log_to_file: if log_to_file:
print result print "START " + t.__name__
sys.stdout.flush() sys.stdout.flush()
if results_file: if t.__doc__:
f = open(results_file, 'a') logger.info("Test: " + t.__doc__)
f.write(result + "\n") start = datetime.now()
f.close() for d in dev:
for d in dev: try:
d.request("NOTE TEST-START " + t.__name__)
except Exception, e:
logger.info("Failed to issue TEST-START before " + t.__name__ + " for " + d.ifname)
logger.info(e)
print "FAIL " + t.__name__ + " - could not start test"
if conn:
conn.close()
conn = None
sys.exit(1)
try: try:
d.request("NOTE TEST-STOP " + t.__name__) if t.func_code.co_argcount > 1:
res = t(dev, apdev)
else:
res = t(dev)
end = datetime.now()
diff = end - start
if res == "skip":
skipped.append(t.__name__)
result = "SKIP"
else:
passed.append(t.__name__)
result = "PASS"
report(conn, args.build, args.commit, run, t.__name__, result, diff)
result = result + " " + t.__name__ + " "
result = result + str(diff.total_seconds()) + " " + str(end)
logger.info(result)
if log_to_file or print_res:
print result
sys.stdout.flush()
if results_file:
f = open(results_file, 'a')
f.write(result + "\n")
f.close()
except Exception, e: except Exception, e:
logger.info("Failed to issue TEST-STOP after " + t.__name__ + " for " + d.ifname) end = datetime.now()
diff = end - start
logger.info(e) logger.info(e)
failed.append(t.__name__)
report(conn, args.build, args.commit, run, t.__name__, "FAIL", diff)
result = "FAIL " + t.__name__ + " " + str(diff.total_seconds()) + " " + str(end)
logger.info(result)
if log_to_file:
print result
sys.stdout.flush()
if results_file:
f = open(results_file, 'a')
f.write(result + "\n")
f.close()
for d in dev:
try:
d.request("NOTE TEST-STOP " + t.__name__)
except Exception, e:
logger.info("Failed to issue TEST-STOP after " + t.__name__ + " for " + d.ifname)
logger.info(e)
if not args.tests: if not args.tests:
reset_devs(dev, apdev) reset_devs(dev, apdev)