summaryrefslogtreecommitdiffstats
path: root/assembler/selftest.sh
blob: 99dbf1733affa60a10ddb0a81f2d88eaa8c6306c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash

ASM="b43-asm"
DASM="b43-dasm"
SUM="sha1sum"
TMPDIR="/tmp"


if [ $# -ne 1 ]; then
	echo "b43-(d)asm trivial selftest"
	echo "This selftest will take the binary input file, disassemble"
	echo "it, assemble it and compare the two binaries."
	echo
	echo "Usage: $0 /path/to/binary"
	exit 1
fi
infile="$1"

if ! [ -r "$infile" ]; then
	echo "Can not read input binary $infile"
	exit 1
fi

rnd="$RANDOM"
asmfile="$TMPDIR/b43-asm-selftest-$rnd.asm"
outfile="$TMPDIR/b43-asm-selftest-$rnd.bin"

function cleanup
{
	rm -f "$asmfile"
	rm -f "$outfile"
}
cleanup


$DASM "$infile" "$asmfile"
err=$?
if [ $err -ne 0 ]; then
	echo "Disassembling FAILED: $err"
	cleanup
	exit 1
fi
$ASM "$asmfile" "$outfile"
err=$?
if [ $err -ne 0 ]; then
	echo "Assembling FAILED: $err"
	cleanup
	exit 1
fi

orig_sum="$($SUM "$infile" | cut -f1 -d ' ')"
err=$?
if [ $err -ne 0 ] || [ -z "$orig_sum" ]; then
	echo "Checksumming of input file failed: $err"
	cleanup
	exit 1
fi
out_sum="$($SUM "$outfile" | cut -f1 -d ' ')"
err=$?
if [ $err -ne 0 ] || [ -z "$out_sum" ]; then
	echo "Checksumming of reassembled file failed: $err"
	cleanup
	exit 1
fi
cleanup

echo "Input file checksum:    $orig_sum"
echo "Re-assembled checksum:  $out_sum"
echo

if [ "$orig_sum" != "$out_sum" ]; then
	echo "FAILURE: Checksums don't match!"
	exit 1
fi
echo "Checksums match"

exit 0
bues.ch cgit interface