|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +test_disassembling_a_file() { |
| 6 | + local verbose |
| 7 | + if [ "$1" == verbose ]; then |
| 8 | + verbose=-v |
| 9 | + echo -e "Testing disassembling a file in VERBOSE mode" |
| 10 | + else |
| 11 | + echo -e "Testing disassembling a file in NORMAL mode" |
| 12 | + fi |
| 13 | + |
| 14 | + testname=all_opcodes |
| 15 | + fixture=fixtures/${testname}.S |
| 16 | + echo -e "\tBuilding $fixture using micropython-esp32-ulp" |
| 17 | + |
| 18 | + log_file="${testname}.log" |
| 19 | + ulp_file="fixtures/${testname}.ulp" |
| 20 | + micropython -m esp32_ulp $fixture 1>$log_file # generates $ulp_file |
| 21 | + |
| 22 | + lst_file="${testname}.lst" |
| 23 | + lst_file_fixture=fixtures/${testname}${verbose}.lst |
| 24 | + echo -e "\tDisassembling $ulp_file using micropython-esp32-ulp disassembler" |
| 25 | + micropython tools/disassemble.py $verbose $ulp_file > $lst_file |
| 26 | + |
| 27 | + if ! diff $lst_file_fixture $lst_file 1>/dev/null; then |
| 28 | + echo -e "\tDisassembled output differs from expected output!" |
| 29 | + echo "" |
| 30 | + echo "Disassembly test failed for $fixture" |
| 31 | + echo "micropython-esp32-ulp log:" |
| 32 | + cat $log_file |
| 33 | + echo "Diff of disassembly: expected vs actual" |
| 34 | + diff -u $lst_file_fixture $lst_file |
| 35 | + fi |
| 36 | +} |
| 37 | + |
| 38 | +test_disassembling_a_manual_sequence() { |
| 39 | + local verbose |
| 40 | + if [ "$1" == verbose ]; then |
| 41 | + verbose=-v |
| 42 | + echo -e "Testing disassembling a manual byte sequence in VERBOSE mode" |
| 43 | + else |
| 44 | + echo -e "Testing disassembling a manual byte sequence in NORMAL mode" |
| 45 | + fi |
| 46 | + |
| 47 | + sequence="e1af 8c72 0100 0068 2705 cc19 0005 681d 0000 00a0 0000 0074" |
| 48 | + |
| 49 | + lst_file="manual_bytes.lst" |
| 50 | + lst_file_fixture=fixtures/manual_bytes${verbose}.lst |
| 51 | + echo -e "\tDisassembling manual byte sequence using micropython-esp32-ulp disassembler" |
| 52 | + micropython tools/disassemble.py -m $sequence > $lst_file |
| 53 | + |
| 54 | + if ! diff $lst_file_fixture $lst_file 1>/dev/null; then |
| 55 | + echo -e "\tDisassembled output differs from expected output!" |
| 56 | + echo "" |
| 57 | + echo "Disassembly test failed for manual byte sequence" |
| 58 | + echo "Diff of disassembly: expected vs actual" |
| 59 | + diff -u $lst_file_fixture $lst_file |
| 60 | + fi |
| 61 | +} |
| 62 | + |
| 63 | +test_disassembling_a_file |
| 64 | +test_disassembling_a_file verbose |
| 65 | + |
| 66 | +test_disassembling_a_manual_sequence |
| 67 | +test_disassembling_a_manual_sequence verbose |
0 commit comments