From 6a2a7521c8eba299d67d56f62c37277b22f5237e Mon Sep 17 00:00:00 2001 From: "radim.karnis" Date: Wed, 21 Jun 2023 13:13:24 +0200 Subject: [PATCH] ci(esp_idf_monitor): Extend test_app for ROM ELF address decoding --- .../main/Kconfig.projbuild | 7 +++ .../system/monitor_addr_lookup/main/main.c | 14 +++++- .../pytest_monitor_addr_lookup.py | 47 +++++++++++++------ .../sdkconfig.ci.addr_lookup_in_ROM | 1 + .../sdkconfig.ci.addr_lookup_in_app | 1 + 5 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 tools/test_apps/system/monitor_addr_lookup/main/Kconfig.projbuild create mode 100644 tools/test_apps/system/monitor_addr_lookup/sdkconfig.ci.addr_lookup_in_ROM create mode 100644 tools/test_apps/system/monitor_addr_lookup/sdkconfig.ci.addr_lookup_in_app diff --git a/tools/test_apps/system/monitor_addr_lookup/main/Kconfig.projbuild b/tools/test_apps/system/monitor_addr_lookup/main/Kconfig.projbuild new file mode 100644 index 0000000000..c46107f602 --- /dev/null +++ b/tools/test_apps/system/monitor_addr_lookup/main/Kconfig.projbuild @@ -0,0 +1,7 @@ +config TEST_ADDR_LOOKUP_IN_APP + bool "TEST_ADDR_LOOKUP_IN_APP" + default n + +config TEST_ADDR_LOOKUP_IN_ROM + bool "TEST_ADDR_LOOKUP_IN_ROM" + default n diff --git a/tools/test_apps/system/monitor_addr_lookup/main/main.c b/tools/test_apps/system/monitor_addr_lookup/main/main.c index 16c042a228..1c14e060e3 100644 --- a/tools/test_apps/system/monitor_addr_lookup/main/main.c +++ b/tools/test_apps/system/monitor_addr_lookup/main/main.c @@ -8,6 +8,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" +#if CONFIG_TEST_ADDR_LOOKUP_IN_APP static volatile bool s_initialization_done = false; static void initialize(void) @@ -23,9 +24,13 @@ static int get_random_number(void) } return rand(); } +#endif // CONFIG_TEST_ADDR_LOOKUP_IN_APP void app_main(void) { + printf("app_main is running from 0x%x\n", (int) app_main); + +#if CONFIG_TEST_ADDR_LOOKUP_IN_APP volatile int number = get_random_number(); int *n = malloc(sizeof(int)); @@ -33,10 +38,17 @@ void app_main(void) *n = number; - printf("app_main is running from 0x%x\n", (int) app_main); printf("Initializer function at 0x%x\n", (int) initialize); printf("Got %d stored at 0x%x and 0x%x from a function from 0x%x\n", *n, (int) n, (int) (&number), (int) get_random_number); printf("This is the end of the report\n"); free(n); +#endif // CONFIG_TEST_ADDR_LOOKUP_IN_APP + +#if CONFIG_TEST_ADDR_LOOKUP_IN_ROM + printf("Crashing now!\n"); + + esp_rom_install_channel_putc(1, (void (*)(char)) abort); + esp_rom_printf("a"); +#endif // CONFIG_TEST_ADDR_LOOKUP_IN_ROM } diff --git a/tools/test_apps/system/monitor_addr_lookup/pytest_monitor_addr_lookup.py b/tools/test_apps/system/monitor_addr_lookup/pytest_monitor_addr_lookup.py index a7e70b8b6b..0d35149d02 100644 --- a/tools/test_apps/system/monitor_addr_lookup/pytest_monitor_addr_lookup.py +++ b/tools/test_apps/system/monitor_addr_lookup/pytest_monitor_addr_lookup.py @@ -11,6 +11,10 @@ from pytest_embedded import Dut @pytest.mark.generic @pytest.mark.supported_targets +@pytest.mark.parametrize('config', [ + 'addr_lookup_in_app', + 'addr_lookup_in_ROM', +], indirect=True) def test_monitor_addr_lookup(config: str, dut: Dut) -> None: # The port needs to be closed because esp_idf_monitor will connect to it dut.serial.stop_redirect_thread() @@ -22,22 +26,35 @@ def test_monitor_addr_lookup(config: str, dut: Dut) -> None: with open(monitor_log_path, 'w') as log, pexpect.spawn(monitor_cmd, logfile=log, timeout=5, encoding='utf-8', codec_errors='ignore') as p: p.expect_exact('main_task: Calling app_main()') - ADDRESS = '0x[a-f0-9]{8}' + ADDRESS = r'0x[a-f0-9]{8}' + FUNC_NAME = r'[a-zA-Z_][\w]*' - p.expect(re.compile(r'app_main is running from ({})'.format(ADDRESS))) - a = p.match.group(1) - p.expect_exact('{}: app_main at'.format(a)) + p.expect(re.compile(rf'app_main is running from ({ADDRESS})')) + addr = p.match.group(1) + p.expect_exact(f'{addr}: app_main at') - p.expect(re.compile(r'Initializer function at ({})'.format(ADDRESS))) - a = p.match.group(1) - p.expect_exact('{}: initialize at'.format(a)) + if config == 'addr_lookup_in_app': + p.expect(re.compile(rf'Initializer function at ({ADDRESS})')) + addr = p.match.group(1) + p.expect_exact(f'{addr}: initialize at') - p.expect(re.compile(r'Got \d+ stored at ({}) and ({}) from a function from ({})'.format(ADDRESS, ADDRESS, ADDRESS))) - var1 = p.match.group(1) - var2 = p.match.group(2) - func = p.match.group(3) - match_index = p.expect([str(var1), str(var2), pexpect.TIMEOUT]) - assert match_index == 2 # should be TIMEOUT because addr2line should not match addresses of variables - p.expect_exact('{}: get_random_number at'.format(func)) + p.expect(re.compile(rf'Got \d+ stored at ({ADDRESS}) and ({ADDRESS}) from a function from ({ADDRESS})')) + var1 = p.match.group(1) + var2 = p.match.group(2) + func = p.match.group(3) + match_index = p.expect([str(var1), str(var2), pexpect.TIMEOUT]) + assert match_index == 2 # should be TIMEOUT because addr2line should not match addresses of variables + p.expect_exact(f'{func}: get_random_number at') - p.expect_exact('This is the end of the report') + p.expect_exact('This is the end of the report') + + elif config == 'addr_lookup_in_ROM': + p.expect_exact('Crashing now!') + + p.expect(re.compile(rf'abort\(\) was called at PC ({ADDRESS}) on core 0')) + addr = p.match.group(1) + p.expect_exact(f'abort() was called at PC {addr} on core 0') + + p.expect(re.compile(rf'({ADDRESS}): ({FUNC_NAME}) in ROM')) + addr, func = p.match.group(1), p.match.group(2) + p.expect_exact(f'{addr}: {func} in ROM') diff --git a/tools/test_apps/system/monitor_addr_lookup/sdkconfig.ci.addr_lookup_in_ROM b/tools/test_apps/system/monitor_addr_lookup/sdkconfig.ci.addr_lookup_in_ROM new file mode 100644 index 0000000000..282db80b75 --- /dev/null +++ b/tools/test_apps/system/monitor_addr_lookup/sdkconfig.ci.addr_lookup_in_ROM @@ -0,0 +1 @@ +CONFIG_TEST_ADDR_LOOKUP_IN_ROM=y diff --git a/tools/test_apps/system/monitor_addr_lookup/sdkconfig.ci.addr_lookup_in_app b/tools/test_apps/system/monitor_addr_lookup/sdkconfig.ci.addr_lookup_in_app new file mode 100644 index 0000000000..d56aeebea5 --- /dev/null +++ b/tools/test_apps/system/monitor_addr_lookup/sdkconfig.ci.addr_lookup_in_app @@ -0,0 +1 @@ +CONFIG_TEST_ADDR_LOOKUP_IN_APP=y