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
TRACE=trace
SUFFIX=$SUFFIX-trace
TRACE_ARGS="-T $LOGDIR"
shift
else
unset TRACE
unset TRACE_ARGS
fi
if ! ./start.sh $CONCURRENT $VALGRIND $TRACE; then
@ -55,14 +57,7 @@ if ! ./start.sh $CONCURRENT $VALGRIND $TRACE; then
fi
DATE=`ls -1tr $LOGDIR | tail -1 | cut -f1 -d-`
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 $@"
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
./run-tests.py $TRACE_ARGS -l $LOGDIR/$DATE-run $DB -e $LOGDIR/$DATE-failed -r $LOGDIR/results.txt $CONCURRENT_TESTS $@ || errors=1
cat $LOGDIR/$DATE-run >> $LOGDIR/last-debug
./stop-wifi.sh

View file

@ -12,6 +12,7 @@ import sys
import time
from datetime import datetime
import argparse
import subprocess
import logging
logger = logging.getLogger(__name__)
@ -47,6 +48,28 @@ def report(conn, build, commit, run, test, result, diff):
print "sqlite: " + str(e)
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():
tests = []
test_modules = []
@ -86,6 +109,8 @@ def main():
parser.add_argument('-b', metavar='<build>', dest='build', help='build ID')
parser.add_argument('-L', action='store_true', dest='update_tests_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>',
help='execute only tests from these test modules',
type=str, choices=[[]] + test_modules, nargs='+')
@ -165,6 +190,7 @@ def main():
if args.testmodules:
if not t.__module__ in args.testmodules:
continue
with Tracer(args.tracedir, t.__name__):
reset_devs(dev, apdev)
logger.info("START " + t.__name__)
if log_to_file: