1#!/usr/bin/env bash
2
3
4memory_test () {
5    pushd $IDF_PATH/examples/get-started/hello_world \
6    && echo -e "\n***\nBuilding project for $1..." &>> $IDF_PATH/tools/test_idf_size/output \
7    && idf.py set-target $1 \
8    && idf.py build \
9    && echo -e "\n***\nRunning mem_test.py for $1..." &>> $IDF_PATH/tools/test_idf_size/output \
10    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json build/hello_world.map > size_output.json \
11    && python $IDF_PATH/components/esptool_py/esptool/esptool.py --chip $1 image_info build/hello_world.bin > esptool_output \
12    && python -m coverage run -a $IDF_PATH/tools/test_idf_size/mem_test.py size_output.json esptool_output &>> $IDF_PATH/tools/test_idf_size/output \
13    && popd
14}
15
16json_test() {
17    echo -e "\n***\nProducing JSON output for $1..." &>> output \
18    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json app_$1.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
19    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json --archives app_$1.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
20    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json --files app_$1.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
21    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json --archive_details libdriver.a app_$1.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output
22}
23
24{ python -m coverage debug sys \
25    && python -m coverage erase &> output \
26    && memory_test esp32 \
27    && memory_test esp32s2 \
28    && memory_test esp32s3 \
29    && memory_test esp32c3 \
30    && echo -e "\n***\nRunning idf_size.py..." &>> output \
31    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map &>> output \
32    && echo -e "\n***\nRunning idf_size.py on bootloader..." &>> output \
33    && python -m coverage run -a $IDF_PATH/tools/idf_size.py bootloader.map &>> output \
34    && echo -e "\n***\nRunning idf_size.py with overflow..." &>> output \
35    && python -m coverage run -a $IDF_PATH/tools/idf_size.py overflow.map &>> output \
36    && echo -e "\n***\nRunning idf_size.py --archives..." &>> output \
37    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --archives app.map &>> output \
38    && echo -e "\n***\nRunning idf_size.py --files..." &>> output \
39    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --files app.map &>> output \
40    && echo -e "\n***\nRunning idf_size.py --archive_details..." &>> output \
41    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --archive_details libdriver.a app.map &>> output \
42    && echo -e "\n***\nRunning idf_size.py diff with bootloader..." &>> output \
43    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --diff bootloader.map &>> output \
44    && echo -e "\n***\nRunning idf_size.py diff with itself..." &>> output \
45    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --diff app.map &>> output \
46    && echo -e "\n***\nRunning idf_size.py diff with another app..." &>> output \
47    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --diff app2.map &>> output \
48    && echo -e "\n***\nRunning idf_size.py diff with app in reverse order..." &>> output \
49    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app2.map --diff app.map &>> output \
50    && echo -e "\n***\nRunning idf_size.py diff --archives with bootloader..." &>> output \
51    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --archives --diff bootloader.map &>> output \
52    && echo -e "\n***\nRunning idf_size.py diff --archives with itself..." &>> output \
53    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --archives --diff app.map &>> output \
54    && echo -e "\n***\nRunning idf_size.py diff --archives with another app..." &>> output \
55    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --archives --diff app2.map &>> output \
56    && echo -e "\n***\nRunning idf_size.py diff --archives with app in reverse order..." &>> output \
57    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app2.map --archives --diff app.map &>> output \
58    && echo -e "\n***\nRunning idf_size.py diff --files with bootloader..." &>> output \
59    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --files --diff bootloader.map &>> output \
60    && echo -e "\n***\nRunning idf_size.py diff --files with itself..." &>> output \
61    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --files --diff app.map &>> output \
62    && echo -e "\n***\nRunning idf_size.py diff --files with another app..." &>> output \
63    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --files --diff app2.map &>> output \
64    && echo -e "\n***\nRunning idf_size.py diff --files with app in reverse order..." &>> output \
65    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app2.map --files --diff app.map &>> output \
66    && echo -e "\n***\nRunning idf_size.py diff --archive_details with bootloader..." &>> output \
67    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --archive_details libdriver.a --diff bootloader.map &>> output \
68    && echo -e "\n***\nRunning idf_size.py diff --archive_details with bootloader..." &>> output \
69    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --archive_details libc.a --diff bootloader.map &>> output \
70    && echo -e "\n***\nRunning idf_size.py diff --archive_details with itself..." &>> output \
71    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --archive_details libdriver.a --diff app.map &>> output \
72    && echo -e "\n***\nRunning idf_size.py diff --archive_details with another app..." &>> output \
73    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --archive_details libdriver.a --diff app2.map &>> output \
74    && echo -e "\n***\nRunning idf_size.py diff --archive_details with app in reverse order..." &>> output \
75    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app2.map --archive_details libdriver.a --diff app.map &>> output \
76    && echo -e "\n***\nRunning idf_size.py diff --archive_details with another app..." &>> output \
77    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --archive_details libfreertos.a --diff app2.map &>> output \
78    && echo -e "\n***\nRunning idf_size.py for esp32s2..." &>> output \
79    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32s2 app_esp32s2.map &>> output \
80    && echo -e "\n***\nRunning idf_size.py for esp32s2 with overflow..." &>> output \
81    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32s2 overflow_esp32s2.map &>> output \
82    && echo -e "\n***\nRunning idf_size.py for esp32s2 (target autodetected)..." &>> output \
83    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app_esp32s2.map &>> output \
84    && echo -e "\n***\nRunning idf_size.py on bootloader for esp32s2..." &>> output \
85    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32s2 bootloader_esp32s2.map &>> output \
86    && echo -e "\n***\nRunning idf_size.py on bootloader for esp32s2 (target autodetected)..." &>> output \
87    && python -m coverage run -a $IDF_PATH/tools/idf_size.py bootloader_esp32s2.map &>> output \
88    && echo -e "\n***\nRunning idf_size.py --archives for esp32s2..." &>> output \
89    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32s2 --archives app_esp32s2.map &>> output \
90    && echo -e "\n***\nRunning idf_size.py --files for esp32s2..." &>> output \
91    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32s2 --files app_esp32s2.map &>> output \
92    && echo -e "\n***\nRunning idf_size.py --archive_details for esp32s2..." &>> output \
93    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32s2 --archive_details libdriver.a app_esp32s2.map &>> output \
94    && echo -e "\n***\nRunning idf_size.py diff with another app (different target)..." &>> output \
95    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app.map --diff app_esp32s2.map &>> output \
96    && echo -e "\n***\nRunning idf_size.py for esp32h2..." &>> output \
97    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32h2 app_esp32h2.map &>> output \
98    && echo -e "\n***\nRunning idf_size.py for esp32h2 (target autodetected)..." &>> output \
99    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app_esp32h2.map &>> output \
100    && echo -e "\n***\nRunning idf_size.py --archives for esp32h2..." &>> output \
101    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32h2 --archives app_esp32h2.map &>> output \
102    && echo -e "\n***\nRunning idf_size.py --files for esp32h2..." &>> output \
103    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32h2 --files app_esp32h2.map &>> output \
104    && echo -e "\n***\nRunning idf_size.py --archive_details for esp32h2..." &>> output \
105    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32h2 --archive_details libdriver.a app_esp32h2.map &>> output \
106    && echo -e "\n***\nRunning idf_size.py for esp32c3..." &>> output \
107    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32c3 app_esp32c3.map &>> output \
108    && echo -e "\n***\nRunning idf_size.py for esp32c3 with overflow..." &>> output \
109    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32c3 overflow_esp32c3.map &>> output \
110    && echo -e "\n***\nRunning idf_size.py for esp32c3 (target autodetected)..." &>> output \
111    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app_esp32c3.map &>> output \
112    && echo -e "\n***\nRunning idf_size.py --archives for esp32c3..." &>> output \
113    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32c3 --archives app_esp32c3.map &>> output \
114    && echo -e "\n***\nRunning idf_size.py --files for esp32c3..." &>> output \
115    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32c3 --files app_esp32c3.map &>> output \
116    && echo -e "\n***\nRunning idf_size.py --archive_details for esp32c3..." &>> output \
117    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32c3 --archive_details libdriver.a app_esp32c3.map &>> output \
118    && echo -e "\n***\nRunning idf_size.py for esp32s3..." &>> output \
119    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32s3 app_esp32s3.map &>> output \
120    && echo -e "\n***\nRunning idf_size.py for esp32s3 with overflow..." &>> output \
121    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32s3 overflow_esp32s3.map &>> output \
122    && echo -e "\n***\nRunning idf_size.py for esp32s3 (target autodetected)..." &>> output \
123    && python -m coverage run -a $IDF_PATH/tools/idf_size.py app_esp32s3.map &>> output \
124    && echo -e "\n***\nRunning idf_size.py --archives for esp32s3..." &>> output \
125    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32s3 --archives app_esp32s3.map &>> output \
126    && echo -e "\n***\nRunning idf_size.py --files for esp32s3..." &>> output \
127    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32s3 --files app_esp32s3.map &>> output \
128    && echo -e "\n***\nRunning idf_size.py --archive_details for esp32s3..." &>> output \
129    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --target esp32s3 --archive_details libdriver.a app_esp32s3.map &>> output \
130    && echo -e "\n***\nProducing JSON output..." &>> output \
131    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json app.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
132    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json --archives app.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
133    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json --files app.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
134    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json --archive_details libdriver.a app.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
135    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json app.map --diff app2.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
136    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json --archives app.map --diff app2.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
137    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json --files app.map --diff app2.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
138    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json --archive_details libdriver.a app.map --diff app2.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
139    && json_test esp32s2 \
140    && json_test esp32c3 \
141    && json_test esp32h2 \
142    && json_test esp32s3 \
143    && echo -e "\n***\nProducing JSON file output..." &>> output \
144    && python -m coverage run -a $IDF_PATH/tools/idf_size.py --json --output-file output.json app.map &>> output \
145    && echo -e "\n***\nProducing text file output..." &>> output \
146    && python -m coverage run -a $IDF_PATH/tools/idf_size.py -o output.txt app.map &>> output \
147    && echo -e "\n***\nRunning idf_size_tests.py..." &>> output \
148    && python -m coverage run -a $IDF_PATH/tools/test_idf_size/test_idf_size.py &>> output \
149    && echo -e "\n\nComparing expected output..." \
150    && diff -Z output expected_output \
151    && echo -e "\n\nComparing expected json output..." \
152    && diff -Z output.json expected_output.json \
153    && echo -e "\n\nComparing expected text output..." \
154    && diff -Z output.txt expected_output.txt \
155    && python -m coverage report \
156; } || { echo 'The test for idf_size has failed. Please examine the artifacts.' ; exit 1; }
157
158# Note: "diff -Z is used because some versions of Python print trailing whitespace for JSON pretty-printing, and some don't
159