Debian Codegraph @

ao-bringup/test-chaoskey

raw
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=`sudo dmesg -t | awk '/usb.*Product:/ { ck = index($0, "ChaosKey"); }
16 /usb.*SerialNumber:/ { if (ck) print $4; }' | tail -1`
17
18 case "$snum" in
19 "")
20 serial=""
21 ;;
22 *)
23 serial="--serial $snum"
24 ;;
25 esac
26 ;;
27 *)
28 echo "Usage: $0 [serial]"
29 exit 1
30 ;;
31 esac
32
33 echo -e '\e[34mTesting ChaosKey' $snum '\e[39m'
34
35 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"
36
37 PASS=0
38 FAIL=0
39 WEAK=0
40 chaosread $serial --infinite --bytes | for test in $tests done; do
41 case $test in
42 *:*:*)
43 dnum=`echo $test | sed 's/:.*$//'`
44 tnum=`echo $test | sed 's/^[^:]*://'`
45 tnum=`echo $test | sed 's/^[^:]*://' | sed 's/:.*$//'`
46 nnum=`echo $test | sed 's/^.*://'`
47 opts="-d $dnum -t $tnum -n $nnum"
48 ;;
49 *:*)
50 dnum=`echo $test | sed 's/:.*$//'`
51 tnum=`echo $test | sed 's/^.*://'`
52 opts="-d $dnum -t $tnum"
53 ;;
54 *)
55 dnum=$test
56 opts="-d $dnum"
57 ;;
58 esac
59 case $dnum in
60 done)
61 echo DONE
62 ;;
63 *)
64 echo TEST $dnum
65 dieharder -g 200 $opts
66 ;;
67 esac
68 done | while read result; do
69 case "$result" in
70 TEST*)
71 testnum=`echo $result | sed 's/TEST //'`
72 ;;
73 *PASSED*)
74 PASS=`expr $PASS + 1`
75 ;;
76 *WEAK*)
77 WEAK=`expr $WEAK + 1`
78 ;;
79 *FAILED*)
80 echo test $testnum failed
81 FAIL=`expr $FAIL + 1`
82 ;;
83 DONE)
84 echo pass $PASS weak $WEAK fail $FAIL
85 case $PASS:$FAIL in
86 [1-9]*:0)
87 echo -e '\e[32m'ChaosKey $snum is ready to ship'\e[39m'
88 exit 0
89 ;;
90 *)
91 echo -e '\e[31m'ChaosKey $snum failed'\e[39m'
92 exit 1
93 ;;
94 esac
95 ;;
96 esac
97 done