forked from micropython/micropython-esp32-ulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_disassembler_tests.sh
executable file
·91 lines (76 loc) · 2.92 KB
/
03_disassembler_tests.sh
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
#
# This file is part of the micropython-esp32-ulp project,
# https://github.com/micropython/micropython-esp32-ulp
#
# SPDX-FileCopyrightText: 2018-2023, the micropython-esp32-ulp authors, see AUTHORS file.
# SPDX-License-Identifier: MIT
set -e
test_disassembling_a_file() {
local cpu=$1
local verbose
if [ "$2" == verbose ]; then
verbose=-v
echo -e "Testing disassembling a file in VERBOSE mode"
else
echo -e "Testing disassembling a file in NORMAL mode"
fi
testname=all_opcodes
fixture=fixtures/${testname}.${cpu}.S
echo -e "\tBuilding $fixture using micropython-esp32-ulp ($cpu)"
log_file="${testname}.log"
ulp_file="fixtures/${testname}.${cpu}.ulp"
micropython -m esp32_ulp -c $cpu $fixture 1>$log_file # generates $ulp_file
lst_file="${testname}.$cpu.lst"
lst_file_fixture=fixtures/${testname}${verbose}.$cpu.lst
echo -e "\tDisassembling $ulp_file using micropython-esp32-ulp disassembler ($cpu)"
micropython -m tools.disassemble -c $cpu $verbose $ulp_file > $lst_file
if ! diff $lst_file_fixture $lst_file 1>/dev/null; then
echo -e "\tDisassembled output differs from expected output!"
echo ""
echo "Disassembly test failed for $fixture"
echo "micropython-esp32-ulp log:"
cat $log_file
echo "Diff of disassembly: expected vs actual"
diff -u $lst_file_fixture $lst_file
fi
}
test_disassembling_a_manual_sequence() {
local cpu=$1
local verbose
if [ "$2" == verbose ]; then
verbose=-v
echo -e "Testing disassembling a manual byte sequence in VERBOSE mode"
else
echo -e "Testing disassembling a manual byte sequence in NORMAL mode"
fi
if [ "$cpu" == "esp32s2" ]; then
sequence="e1af 8c74 8101 0068 2705 cc19 0005 681d 0000 00a0 0000 0078"
else
sequence="e1af 8c72 0100 0068 2705 cc19 0005 681d 0000 00a0 0000 0074"
fi
lst_file="manual_bytes.$cpu.lst"
lst_file_fixture=fixtures/manual_bytes${verbose}.$cpu.lst
echo -e "\tDisassembling manual byte sequence using micropython-esp32-ulp disassembler ($cpu)"
micropython -m tools.disassemble -c $cpu $verbose -m $sequence> $lst_file
if ! diff $lst_file_fixture $lst_file 1>/dev/null; then
echo -e "\tDisassembled output differs from expected output!"
echo ""
echo "Disassembly test failed for manual byte sequence"
echo "Diff of disassembly: expected vs actual"
diff -u $lst_file_fixture $lst_file
fi
}
# esp32
echo "Testing for CPU: esp32"
test_disassembling_a_file esp32
test_disassembling_a_file esp32 verbose
test_disassembling_a_manual_sequence esp32
test_disassembling_a_manual_sequence esp32 verbose
echo ""
# esp32s2
echo "Testing for CPU: esp32s2"
test_disassembling_a_file esp32s2
test_disassembling_a_file esp32s2 verbose
test_disassembling_a_manual_sequence esp32s2
test_disassembling_a_manual_sequence esp32s2 verbose