Skip to content

Commit 2641d66

Browse files
committed
Add integration tests for disassembler
Test both disassembling a file (assembled from source for the test), and disassembling a byte sequence provided on the command line. Source code to be assembled and expected disassembler listings are provided in the tests/fixtures directory.
1 parent 10a5051 commit 2641d66

File tree

7 files changed

+558
-0
lines changed

7 files changed

+558
-0
lines changed

Diff for: .github/workflows/run_tests.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,10 @@ jobs:
9191
export PATH=$PATH:${{ steps.fetch_binutils.outputs.bin_dir }}
9292
cd tests
9393
./02_compat_rtc_tests.sh
94+
95+
- name: Run disassembler tests
96+
id: disassembler_tests
97+
run: |
98+
export PATH=$PATH:${{ steps.build_micropython.outputs.bin_dir }}
99+
cd tests
100+
./03_disassembler_tests.sh

Diff for: tests/03_disassembler_tests.sh

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)