ao-bringup: Add colors to chaoskey test result reporting
[fw/altos] / ao-bringup / test-chaoskey
1 #!/bin/bash
2 snum="unknown"
3 case "$#" in
4     1)
5         case "$1" in
6             "-?"|"--help")
7                 echo "Usage: $0 [serial]"
8                 exit 0
9                 ;;
10         esac
11         snum="$1"
12         serial="--serial $1"
13         ;;
14     0)
15         snum=`dmesg | grep 'on chaoskey' | tail -1 | sed 's/.*chaoskey \([0-9a-f][0-9a-f]*\) on chaoskey.*/\1/'`
16         case "$snum" in
17             "")
18                 serial=""
19                 ;;
20             *)
21                 serial="--serial $snum"
22                 ;;
23         esac
24         ;;
25     *)
26         echo "Usage: $0 [serial]"
27         exit 1
28         ;;
29 esac
30
31 echo -e '\e[34mTesting ChaosKey' $snum '\e[39m'
32
33 tests="0:100 1:100 2:100 3:100 12:10 13:100 15:10000 16:250 202:1000 203:100 204:500 206:20 207:1000:32 209:1000"
34
35 PASS=0
36 FAIL=0
37 WEAK=0
38 ../ao-tools/ao-chaosread/ao-chaosread $serial --infinite --bytes | for test in $tests done; do
39     case $test in
40         *:*:*)
41             dnum=`echo $test | sed 's/:.*$//'`
42             tnum=`echo $test | sed 's/^[^:]*://'`
43             tnum=`echo $test | sed 's/^[^:]*://' | sed 's/:.*$//'`
44             nnum=`echo $test | sed 's/^.*://'`
45             opts="-d $dnum -t $tnum -n $nnum"
46             ;;
47         *:*)
48             dnum=`echo $test | sed 's/:.*$//'`
49             tnum=`echo $test | sed 's/^.*://'`
50             opts="-d $dnum -t $tnum"
51             ;;
52         *)
53             dnum=$test
54             opts="-d $dnum"
55             ;;
56     esac
57     case $dnum in
58     done)
59         echo DONE
60         ;;
61     *)
62         echo TEST $dnum
63         dieharder -g 200 $opts
64         ;;
65     esac
66 done | while read result; do
67     case "$result" in
68         TEST*)
69             testnum=`echo $result | sed 's/TEST //'`
70             ;;
71         *PASSED*)
72             PASS=`expr $PASS + 1`
73             ;;
74         *WEAK*)
75             WEAK=`expr $WEAK + 1`
76             ;;
77         *FAILED*)
78             echo test $testnum failed
79             FAIL=`expr $FAIL + 1`
80             ;;
81         DONE)
82             echo pass $PASS weak $WEAK fail $FAIL
83             case $PASS:$FAIL in
84                 [1-9]*:0)
85                     echo -e '\e[32m'ChaosKey $snum is ready to ship'\e[39m'
86                     exit 0
87                     ;;
88                 *)
89                     echo -e '\e[31m'ChaosKey $snum failed'\e[39m'
90                     exit 1
91                     ;;
92             esac
93             ;;
94     esac
95 done