selftest.sh 1.5 KB

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