[PATCH] hwsim tests: prefill database in VM tests

Johannes Berg johannes at sipsolutions.net
Thu Oct 31 11:05:11 EDT 2013


From: Johannes Berg <johannes.berg at intel.com>

In some cases, e.g. with the VM tests if the VM crashes, it
can be useful to know which tests should have run but didn't
(or didn't finish). In order to catch these more easily, add
an option to prefill the database with all tests at the very
beginning of the testing (in a new NOTRUN state) and use the
option in the VM tests.

Signed-hostap: Johannes Berg <johannes.berg at intel.com>
---
 tests/hwsim/run-all.sh   |  3 +++
 tests/hwsim/run-tests.py | 19 ++++++++++++++++---
 tests/hwsim/vm/inside.sh |  1 +
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/tests/hwsim/run-all.sh b/tests/hwsim/run-all.sh
index 84b5bae..3179446 100755
--- a/tests/hwsim/run-all.sh
+++ b/tests/hwsim/run-all.sh
@@ -19,6 +19,9 @@ else
     if [ -n "$BUILD" ]; then
 	DB="$DB -b $BUILD"
     fi
+    if [ "$PREFILL_DB" = "y" ] ; then
+        DB="$DB --prefill-tests"
+    fi
 fi
 
 if [ "x$1" = "xconcurrent-valgrind" ]; then
diff --git a/tests/hwsim/run-tests.py b/tests/hwsim/run-tests.py
index 429cbdb..aea9bfb 100755
--- a/tests/hwsim/run-tests.py
+++ b/tests/hwsim/run-tests.py
@@ -34,14 +34,16 @@ def reset_devs(dev, apdev):
     for ap in apdev:
         hapd.remove(ap['ifname'])
 
-def report(conn, build, commit, run, test, result, diff):
+def report(conn, prefill, build, commit, run, test, result, duration):
     if conn:
         if not build:
             build = ''
         if not commit:
             commit = ''
+        if prefill:
+            conn.execute('DELETE FROM results WHERE test=? AND run=?', (test, run))
         sql = "INSERT INTO results(test,result,run,time,duration,build,commitid) VALUES(?, ?, ?, ?, ?, ?, ?)"
-        params = (test, result, run, time.time(), diff.total_seconds(), build, commit)
+        params = (test, result, run, time.time(), duration, build, commit)
         try:
             conn.execute(sql, params)
             conn.commit()
@@ -107,6 +109,8 @@ def main():
 
     parser.add_argument('-S', metavar='<sqlite3 db>', dest='database',
                         help='database to write results to')
+    parser.add_argument('--prefill-tests', action='store_true', dest='prefill',
+                        help='prefill test database with NOTRUN before all tests')
     parser.add_argument('--commit', metavar='<commit id>',
                         help='commit ID, only for database')
     parser.add_argument('-b', metavar='<build>', dest='build', help='build ID')
@@ -207,6 +211,7 @@ def main():
     if args.dmesg:
         subprocess.call(['sudo', 'dmesg', '-c'], stdout=open('/dev/null', 'w'))
 
+    tests_to_run = []
     for t in tests:
         name = t.__name__.replace('test_', '', 1)
         if args.tests:
@@ -215,7 +220,15 @@ def main():
         if args.testmodules:
             if not t.__module__.replace('test_', '', 1) in args.testmodules:
                 continue
+        tests_to_run.append(t)
 
+    if conn and args.prefill:
+        for t in tests_to_run:
+            name = t.__name__.replace('test_', '', 1)
+            report(conn, False, args.build, args.commit, run, name, 'NOTRUN', 0)
+
+    for t in tests_to_run:
+        name = t.__name__.replace('test_', '', 1)
         if log_handler:
             log_handler.stream.close()
             logger.removeHandler(log_handler)
@@ -294,7 +307,7 @@ def main():
         else:
             failed.append(name)
 
-        report(conn, args.build, args.commit, run, name, result, diff)
+        report(conn, args.prefill, args.build, args.commit, run, name, result, diff.total_seconds())
         result = result + " " + name + " "
         result = result + str(diff.total_seconds()) + " " + str(end)
         logger.info(result)
diff --git a/tests/hwsim/vm/inside.sh b/tests/hwsim/vm/inside.sh
index cbef727..d14bf01 100755
--- a/tests/hwsim/vm/inside.sh
+++ b/tests/hwsim/vm/inside.sh
@@ -64,6 +64,7 @@ else
 	export USER=0
 	export LOGDIR=/tmp/logs
 	export DBFILE=$LOGDIR/results.db
+	export PREFILL_DB=y
 
 	cd $TESTDIR
 	./run-all.sh $ARGS >/dev/ttyS0 2>&1
-- 
1.8.4.rc3



More information about the HostAP mailing list