Skip to content

Commit 69ae946

Browse files
committed
add compatibility tests using good example code off the net
The test script will fetch the ESP-IDF framework to have all necessary include files, and will then fetch two sources of example code (ulptool and binutil-esp32_ulp's own test examples). The examples are fetched rather than duplicated into this repo, to avoid potential licensing and attribution issues.
1 parent 2f6ee78 commit 69ae946

File tree

2 files changed

+127
-1
lines changed

2 files changed

+127
-1
lines changed

Diff for: .github/workflows/run_tests.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,13 @@ jobs:
7070
export PATH=$PATH:${{ steps.build_micropython.outputs.bin_dir }}
7171
export PATH=$PATH:${{ steps.build_binutils.outputs.bin_dir }}
7272
cd tests
73-
ln -s ../binutils-esp32ulp # already cloned earlier. reuse.
7473
./01_compat_tests.sh
74+
75+
- name: Run compat tests with RTC macros
76+
id: compat_rtc_tests
77+
run: |
78+
export PATH=$PATH:${{ steps.build_micropython.outputs.bin_dir }}
79+
export PATH=$PATH:${{ steps.build_binutils.outputs.bin_dir }}
80+
cd tests
81+
ln -s ../binutils-esp32ulp # already cloned earlier. reuse.
82+
./02_compat_rtc_tests.sh

Diff for: tests/02_compat_rtc_tests.sh

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/bash
2+
3+
# export PYTHONPATH=.:$PYTHONPATH
4+
5+
set -e
6+
7+
make_log_dir() {
8+
mkdir -p log
9+
}
10+
11+
fetch_esp_idf() {
12+
[ -d esp-idf ] && return
13+
14+
echo "Fetching esp-idf"
15+
log_file=log/fetch-esp-idf.log
16+
git clone --depth 1 \
17+
https://github.com/espressif/esp-idf.git 1>$log_file 2>&1
18+
}
19+
20+
fetch_ulptool_examples() {
21+
[ -d ulptool ] && return
22+
23+
echo "Fetching ulptool examples"
24+
log_file=log/fetch-ulptool.log
25+
git clone --depth 1 \
26+
https://github.com/duff2013/ulptool 1>$log_file 2>&1
27+
}
28+
29+
fetch_binutils_esp32ulp_examples() {
30+
[ -d binutils-esp32ulp ] && return
31+
32+
echo "Fetching binutils-esp32ulp examples"
33+
log_file=log/fetch-binutils.log
34+
git clone --depth 1 \
35+
https://github.com/espressif/binutils-esp32ulp.git 1>$log_file 2>&1
36+
}
37+
38+
build_defines_db() {
39+
local defines_db=defines.db
40+
41+
if [ "$1" = "-r" ] && [ -s "${defines_db}" ]; then
42+
# reuse existing defines.db
43+
return
44+
fi
45+
46+
echo "Building defines DB from include files"
47+
log_file=log/build_defines_db.log
48+
rm -f "${defines_db}"
49+
micropython -m esp32_ulp.parse_to_db \
50+
esp-idf/components/soc/esp32/include/soc/*.h \
51+
esp-idf/components/esp_common/include/*.h 1>$log_file
52+
}
53+
54+
make_log_dir
55+
fetch_esp_idf
56+
fetch_ulptool_examples
57+
fetch_binutils_esp32ulp_examples
58+
build_defines_db $1
59+
60+
for src_file in ulptool/src/ulp_examples/*/*.s binutils-esp32ulp/gas/testsuite/gas/esp32ulp/esp32/*.s; do
61+
62+
src_name="${src_file%.s}"
63+
64+
echo "Testing $src_file"
65+
66+
test_name="${src_name##*/}"
67+
68+
# for now, skip files that contain known bugs in esp32_ulp (essentially a todo list of what to fix)
69+
for I in rtcio esp32ulp_all esp32ulp_globals esp32ulp_jumpr esp32ulp_ranges test_reg; do
70+
if [ "${test_name}" = "$I" ]; then
71+
# these are old bugs, and not related to the RTC macro handling functionality
72+
# they will still be great to fix over time
73+
echo -e "\tSkipping... known bugs in esp32_ulp"
74+
continue 2
75+
fi
76+
done
77+
78+
# for now, skip files that contain unsupported things (macros)
79+
for I in i2c i2c_dev stack i2c_wr test1 test_jumpr test_macro; do
80+
if [ "${test_name}" = "$I" ]; then
81+
echo -e "\tSkipping... not yet supported"
82+
continue 2
83+
fi
84+
done
85+
86+
echo -e "\tBuilding using py-esp32-ulp"
87+
ulp_file="${src_name}.ulp"
88+
log_file="${src_name}.log"
89+
micropython -m esp32_ulp $src_file 1>$log_file # generates $ulp_file
90+
91+
pre_file="${src_name}.pre"
92+
obj_file="${src_name}.o"
93+
elf_file="${src_name}.elf"
94+
bin_file="${src_name}.bin"
95+
96+
echo -e "\tBuilding using binutils"
97+
gcc -I esp-idf/components/soc/esp32/include -I esp-idf/components/esp_common/include \
98+
-x assembler-with-cpp \
99+
-E -o ${pre_file} $src_file
100+
esp32ulp-elf-as -o $obj_file ${pre_file}
101+
esp32ulp-elf-ld -T esp32.ulp.ld -o $elf_file $obj_file
102+
esp32ulp-elf-objcopy -O binary $elf_file $bin_file
103+
104+
if ! diff $ulp_file $bin_file 1>/dev/null; then
105+
echo -e "\tBuild outputs differ!"
106+
echo ""
107+
echo "Compatibility test failed for $src_file"
108+
echo "py-esp32-ulp log:"
109+
cat $log_file
110+
echo "py-esp32-ulp output:"
111+
xxd $ulp_file
112+
echo "binutils output:"
113+
xxd $bin_file
114+
exit 1
115+
else
116+
echo -e "\tBuild outputs match"
117+
fi
118+
done

0 commit comments

Comments
 (0)