Skip to content

Commit b55008b

Browse files
committed
testing/esp: add preloaded stub bins test
1 parent aaba62c commit b55008b

File tree

4 files changed

+57
-31
lines changed

4 files changed

+57
-31
lines changed

.gitlab/ci/build-test-app.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ build_test_app_esp32c6:
255255
CHIP_NAME: "esp32c6"
256256
TOOLCHAIN_PREFIX: "riscv32-esp"
257257
BUILD_TEST_APP_DIR: "build_test_app_esp32c6"
258-
TEST_APP_CONFIGS: "single_core single_core_4MB svtrace_single apptrace_gcov_single single_core_amazon_freertos"
258+
TEST_APP_CONFIGS: "single_core single_core_4MB svtrace_single apptrace_gcov_single single_core_amazon_freertos single_core_preloaded_stub"
259259
extends: .build_idf_master_test_app_template
260260

261261
build_test_app_esp32c61:
@@ -271,7 +271,7 @@ build_test_app_esp32h2:
271271
CHIP_NAME: "esp32h2"
272272
TOOLCHAIN_PREFIX: "riscv32-esp"
273273
BUILD_TEST_APP_DIR: "build_test_app_esp32h2"
274-
TEST_APP_CONFIGS: "single_core single_core_4MB svtrace_single apptrace_gcov_single single_core_amazon_freertos"
274+
TEST_APP_CONFIGS: "single_core single_core_4MB svtrace_single apptrace_gcov_single single_core_amazon_freertos single_core_preloaded_stub"
275275
extends: .build_idf_master_test_app_template
276276

277277
build_test_app_esp32p4:
@@ -350,7 +350,7 @@ build_test_app_esp32c6_idf5.4.x:
350350
CHIP_NAME: "esp32c6"
351351
TOOLCHAIN_PREFIX: "riscv32-esp"
352352
BUILD_TEST_APP_DIR: "build_test_app_esp32c6_idf5.4.x"
353-
TEST_APP_CONFIGS: "single_core single_core_4MB svtrace_single apptrace_gcov_single single_core_amazon_freertos"
353+
TEST_APP_CONFIGS: "single_core single_core_4MB svtrace_single apptrace_gcov_single single_core_amazon_freertos single_core_preloaded_stub"
354354
extends: .build_idf54x_test_app_template
355355

356356
build_test_app_esp32c61_idf5.4.x:
@@ -366,7 +366,7 @@ build_test_app_esp32h2_idf5.4.x:
366366
CHIP_NAME: "esp32h2"
367367
TOOLCHAIN_PREFIX: "riscv32-esp"
368368
BUILD_TEST_APP_DIR: "build_test_app_esp32h2_idf5.4.x"
369-
TEST_APP_CONFIGS: "single_core single_core_4MB svtrace_single apptrace_gcov_single single_core_amazon_freertos"
369+
TEST_APP_CONFIGS: "single_core single_core_4MB svtrace_single apptrace_gcov_single single_core_amazon_freertos single_core_preloaded_stub"
370370
extends: .build_idf54x_test_app_template
371371

372372
build_test_app_esp32p4_idf5.4.x:

src/target/espressif/esp_algorithm.c

+2
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ int esp_algorithm_check_preloaded_image(struct target *target, struct esp_algori
390390
|| idf_key != ESP_STUB_FLASHER_IDF_KEY)
391391
return ERROR_FAIL;
392392

393+
LOG_TARGET_INFO(target, "Stub flasher will be running from preloaded image (%" PRIX32 ")", idf_key);
394+
393395
/* code and data is already loaded and we know code is at the beginning of iram_org.
394396
data is at the begginning of dram_org
395397
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_FREERTOS_UNICORE=y
2+
CONFIG_ESP_DEBUG_INCLUDE_OCD_STUB_BINS=y

testing/esp/test_flasher.py

+49-27
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,26 @@ def test_cache_handling(self):
123123
for i in range(5):
124124
self.run_to_bp_and_check(dbg.TARGET_STOP_REASON_BP, 'gpio_set_level', ['gpio_set_level'], outmost_func_name='cache_handling_task')
125125

126+
def test_stub_logs(self):
127+
"""
128+
This test checks if stub logs are enabled successfully.
129+
"""
130+
expected_strings = ["STUB_D: cmd 4:FLASH_MAP_GET",
131+
"STUB_D: stub_flash_get_size: ENTER",
132+
"STUB_I: Found app image: magic 0xe9"]
133+
134+
self.gdb.monitor_run("esp stub_log on", 5)
135+
self.gdb.monitor_run("flash probe 0", 5)
136+
self.gdb.monitor_run("esp stub_log off", 5)
137+
138+
log_path = get_logger().handlers[1].baseFilename # 0:StreamHandler 1:FileHandler
139+
target_output = ''
140+
with open(log_path, 'r') as file:
141+
target_output = file.read()
142+
143+
for expected_str in expected_strings:
144+
self.assertIn(expected_str, target_output, f"Expected string '{expected_str}' not found in output")
145+
126146
def program_esp_bins(self, actions):
127147
# Temp Folder where everything will be contained
128148
tmp = tempfile.mkdtemp(prefix="esp")
@@ -229,30 +249,6 @@ def generate_flasher_args_json():
229249
}
230250

231251

232-
class StubTestsImpl:
233-
234-
def test_stub_logs(self):
235-
"""
236-
This test checks if stub logs are enabled successfully.
237-
"""
238-
expected_strings = ["STUB_D: cmd 4:FLASH_MAP_GET",
239-
"STUB_D: stub_flash_get_size: ENTER"]
240-
241-
self.gdb.monitor_run("esp stub_log on", 5)
242-
self.gdb.monitor_run("flash probe 0", 5)
243-
self.gdb.monitor_run("esp stub_log off", 5)
244-
245-
log_path = get_logger().handlers[1].baseFilename # 0:StreamHandler 1:FileHandler
246-
found_line_count = 0
247-
with open(log_path) as file:
248-
for line in file:
249-
for s in expected_strings:
250-
if s in line:
251-
found_line_count += 1
252-
# We expect at least len(expected_strings) for one core.
253-
self.assertTrue(found_line_count >= len(expected_strings))
254-
255-
256252
########################################################################
257253
# TESTS DEFINITION WITH SPECIAL TESTS #
258254
########################################################################
@@ -285,6 +281,32 @@ def setUp(self):
285281
DebuggerGenericTestAppTestsSingleEncrypted.setUp(self)
286282
FlasherTestsImpl.setUp(self)
287283

288-
class StubTestsSingle(DebuggerGenericTestAppTestsSingle, StubTestsImpl):
289-
def setUp(self):
290-
DebuggerGenericTestAppTestsSingle.setUp(self)
284+
@idf_ver_min('latest')
285+
@only_for_chip(['esp32c6', 'esp32h2'])
286+
class FlasherTestsPreloadedStubSingle(DebuggerGenericTestAppTestsSingle):
287+
288+
def __init__(self, methodName='runTest'):
289+
super(FlasherTestsPreloadedStubSingle, self).__init__(methodName)
290+
self.test_app_cfg.bin_dir = os.path.join('output', 'single_core_preloaded_stub')
291+
self.test_app_cfg.build_dir = os.path.join('builds', 'single_core_preloaded_stub')
292+
293+
def test_preloaded_stub_binary(self):
294+
"""
295+
This test checks if stub codes already loaded to the targets and functioning as expected
296+
"""
297+
expected_strings = ["Stub flasher will be running from preloaded image (5C3A9F5A)",
298+
"Flash mapping 0:",
299+
"Flash mapping 1:"]
300+
301+
target_output = ''
302+
def _target_stream_handler(type, stream, payload):
303+
nonlocal target_output
304+
target_output += payload
305+
self.gdb.stream_handler_add('target', _target_stream_handler)
306+
307+
self.gdb.monitor_run("esp stub_log off", 5)
308+
self.gdb.monitor_run("flash probe 0", 5)
309+
self.gdb.stream_handler_remove('target', _target_stream_handler)
310+
311+
for expected_str in expected_strings:
312+
self.assertIn(expected_str, target_output, f"Expected string '{expected_str}' not found in output")

0 commit comments

Comments
 (0)