Cleanup; the test driver is now way more robust.
authorDavid Given <dg@cowlark.com>
Wed, 16 Nov 2016 19:50:14 +0000 (20:50 +0100)
committerDavid Given <dg@cowlark.com>
Wed, 16 Nov 2016 19:50:14 +0000 (20:50 +0100)
plat/qemuppc/tests/lib/test.c
plat/qemuppc/tests/testdriver.sh

index 9da7e81..02d9877 100644 (file)
@@ -1,5 +1,7 @@
 #include "test.h"
 
+/* No CRT in this file (this includes stdio and stdlib!). */
+
 void finished(void)
 {
     static const char s[] = "@@FINISHED\n";
@@ -9,7 +11,7 @@ void finished(void)
 void writehex(uint32_t code)
 {
     char buf[8];
-    char* p = &buf[8];
+    char* p = &buf[sizeof(buf)];
 
     do
     {
@@ -18,7 +20,7 @@ void writehex(uint32_t code)
     }
     while (code > 0);
 
-    write(1, p, buf+8-p);
+    write(1, p, buf + sizeof(buf) - p);
 }
 
 void fail(uint32_t code)
index 84abdab..8cce48d 100755 (executable)
@@ -3,25 +3,18 @@ qemu=$1
 img=$2
 timeout=$3
 
-pipe=/tmp/testdriver.$$.pipe
+pipe=/tmp/$$.testdriver.pipe
 mknod $pipe p
-trap "rm $pipe" EXIT
+trap "rm -f $pipe" EXIT
 
-timeout $timeout $qemu -nographic -kernel $img >$pipe 2>&1 &
-pid=$!
+result=/tmp/$$.testdriver.result
+trap "rm -f $result" EXIT
 
-status=0
-while read line < $pipe; do
-    case "$line" in
-        *@@FAIL*)
-            echo $line
-            status=1
-            ;;
+pidfile=/tmp/$$.testdriver.pid
+trap "rm -f $pidfile" EXIT
 
-        *@@FINISHED*)
-            kill $pid
-            ;;
-    esac
-done
+($qemu -nographic -kernel $img 2>&1 & echo $! > $pidfile ) | tee $result | \
+    grep -l @@FINISHED | (read dummy && kill $(cat $pidfile))
 
-exit $status
+grep @@FAIL $result && cat $result && exit 1
+exit 0
\ No newline at end of file