assembler: Some r15 fixes
[b43-tools.git] / assembler / selftest.sh
1 #!/bin/bash
2
3 ASM="b43-asm"
4 DASM="b43-dasm"
5 SUM="sha1sum"
6 TMPDIR="/tmp"
7
8
9 if [ $# -ne 1 ]; then
10         echo "b43-(d)asm trivial selftest"
11         echo "This selftest will take the binary input file, disassemble"
12         echo "it, assemble it and compare the two binaries."
13         echo
14         echo "Usage: $0 /path/to/binary"
15         exit 1
16 fi
17 infile="$1"
18
19 if ! [ -r "$infile" ]; then
20         echo "Can not read input binary $infile"
21         exit 1
22 fi
23
24 rnd="$RANDOM"
25 asmfile="$TMPDIR/b43-asm-selftest-$rnd.asm"
26 outfile="$TMPDIR/b43-asm-selftest-$rnd.bin"
27
28 function cleanup
29 {
30         rm -f "$asmfile"
31         rm -f "$outfile"
32 }
33 cleanup
34
35
36 $DASM "$infile" "$asmfile"
37 err=$?
38 if [ $err -ne 0 ]; then
39         echo "Disassembling FAILED: $err"
40         cleanup
41         exit 1
42 fi
43 $ASM "$asmfile" "$outfile"
44 err=$?
45 if [ $err -ne 0 ]; then
46         echo "Assembling FAILED: $err"
47         cleanup
48         exit 1
49 fi
50
51 orig_sum="$($SUM "$infile" | cut -f1 -d ' ')"
52 err=$?
53 if [ $err -ne 0 ] || [ -z "$orig_sum" ]; then
54         echo "Checksumming of input file failed: $err"
55         cleanup
56         exit 1
57 fi
58 out_sum="$($SUM "$outfile" | cut -f1 -d ' ')"
59 err=$?
60 if [ $err -ne 0 ] || [ -z "$out_sum" ]; then
61         echo "Checksumming of reassembled file failed: $err"
62         cleanup
63         exit 1
64 fi
65 cleanup
66
67 echo "Input file checksum:    $orig_sum"
68 echo "Re-assembled checksum:  $out_sum"
69 echo
70
71 if [ "$orig_sum" != "$out_sum" ]; then
72         echo "FAILURE: Checksums don't match!"
73         exit 1
74 fi
75 echo "Checksums match"
76
77 exit 0