Skip to content

Commit ff30bf0

Browse files
committed
tests/esp: Add support for string test IDs
1 parent 9ffee12 commit ff30bf0

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

testing/esp/debug_backend_tests.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ def __init__(self, bin_dir='', build_dir='', src_dir='', app_name='',
240240
# App binary offeset in flash
241241
self.pt_off = ESP32_PT_FLASH_OFF
242242
# name of test app variable which selects sub-test to run
243+
# used for number-based tests selection
243244
self.test_select_var = None
245+
# name of test app variable which holds sub-test string ID (name) to run
246+
# used for string-based tests selection
247+
self.test_id_var = None
244248
# Program's entry point ("app_main" is IDF's default)
245249
self.entry_point = entry_point
246250
# File containing commands to execute at startup
@@ -500,6 +504,7 @@ def setUp(self):
500504
self.stop_exec()
501505
self.prepare_app_for_debugging(self.test_app_cfg.app_off)
502506
# ready to select and start test (should be done in test method)
507+
self.select_sub_test(self.id())
503508

504509
def tearDown(self):
505510
self.clear_bps()
@@ -544,10 +549,14 @@ def clear_wps(self):
544549
self.gdb.delete_bp(wpn)
545550
self.wps = {}
546551

547-
def select_sub_test(self, sub_test_num):
552+
def select_sub_test(self, sub_test_id):
548553
""" Selects sub test in app running on target
549554
"""
550-
self.gdb.data_eval_expr('%s=%d' % (self.test_app_cfg.test_select_var, sub_test_num))
555+
if type(sub_test_id) is str:
556+
self.gdb.data_eval_expr('%s=%d' % (self.test_app_cfg.test_select_var, -1))
557+
self.gdb.data_eval_expr('%s=\\"%s\\"' % (self.test_app_cfg.test_id_var, sub_test_id))
558+
else:
559+
self.gdb.data_eval_expr('%s=%d' % (self.test_app_cfg.test_select_var, sub_test_id))
551560

552561

553562
def run_to_bp(self, exp_rsn, func_name, tmo=20):
@@ -627,6 +636,7 @@ def __init__(self, methodName):
627636
self.test_app_cfg.bld_path = os.path.join('bootloader', 'bootloader.bin')
628637
self.test_app_cfg.pt_path = os.path.join('partition_table', 'partition-table.bin')
629638
self.test_app_cfg.test_select_var = 's_run_test'
639+
self.test_app_cfg.test_id_var = 's_run_test_str'
630640

631641

632642
class DebuggerGenericTestAppTestsDual(DebuggerGenericTestAppTests):

testing/esp/test_apps/gen_ut_app/main/gen_ut_app.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
#include <stdio.h>
1010
#include <string.h>
11+
#include <fnmatch.h>
1112
#include "freertos/FreeRTOS.h"
1213
#include "freertos/task.h"
1314
#include "gen_ut_app.h"
@@ -25,6 +26,7 @@ const static char *TAG = "ut_app";
2526

2627
// test app algorithm selector
2728
volatile static int s_run_test = CONFIG_GEN_UT_APP_RUNTEST;
29+
volatile static char s_run_test_str[256];
2830
// vars for WP tests
2931
volatile static int s_count1 = 0;
3032
volatile static int s_count2 = 100;
@@ -346,10 +348,23 @@ static void step_over_inst_changing_intlevel(void* arg)
346348
}
347349
#endif
348350

351+
// match test string ID with pattern. See fnmatch for wildcard format description.
352+
bool test_id_match(const char *pattern, const char *id)
353+
{
354+
if (esp_ptr_internal(id) && esp_ptr_byte_accessible(id)) {
355+
return fnmatch(pattern, id, 0) == 0;
356+
}
357+
return false;
358+
}
349359

350360
void app_main()
351361
{
352-
ESP_LOGI(TAG, "Run test %d\n", s_run_test);
362+
if (s_run_test == -1) {
363+
ESP_LOGI(TAG, "Run test '%s'\n", s_run_test_str);
364+
s_run_test = (int)s_run_test_str;
365+
} else {
366+
ESP_LOGI(TAG, "Run test %d\n", s_run_test);
367+
}
353368
if (s_run_test == 100){
354369
static struct timer_task_arg task_arg = { .tim_grp = TEST_TIMER_GROUP_1, .tim_id = TEST_TIMER_0, .tim_period = 500000UL, .isr_func = test_timer_isr};
355370
xTaskCreate(&blink_task, "blink_task", 4096, &task_arg, 5, NULL);
@@ -386,12 +401,22 @@ void app_main()
386401
break;
387402
}
388403
}
389-
if (res == UT_UNSUPPORTED) {
390-
ESP_LOGE(TAG, "Invalid test id (%d)!", s_run_test);
391-
} else if (res != UT_OK) {
392-
ESP_LOGE(TAG, "Test %d failed (%d)!", s_run_test, res);
404+
if (s_run_test != -1) {
405+
if (res == UT_UNSUPPORTED) {
406+
ESP_LOGE(TAG, "Invalid test id (%d)!", s_run_test);
407+
} else if (res != UT_OK) {
408+
ESP_LOGE(TAG, "Test %d failed (%d)!", s_run_test, res);
409+
} else {
410+
ESP_LOGI(TAG, "Test %d completed!", s_run_test);
411+
}
393412
} else {
394-
ESP_LOGI(TAG, "Test %d completed!", s_run_test);
413+
if (res == UT_UNSUPPORTED) {
414+
ESP_LOGE(TAG, "Invalid test id (%s)!", s_run_test_str);
415+
} else if (res != UT_OK) {
416+
ESP_LOGE(TAG, "Test '%s' failed (%d)!", s_run_test_str, res);
417+
} else {
418+
ESP_LOGI(TAG, "Test '%s' completed!", s_run_test_str);
419+
}
395420
}
396421
// wait forever
397422
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);

testing/esp/test_apps/gen_ut_app/main/gen_ut_app.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#ifndef GEN_UT_APP_H
2222
#define GEN_UT_APP_H
2323

24+
#include <stdbool.h>
2425
#include "ut_idf_ver.h"
2526
#include "sdkconfig.h"
2627

@@ -56,6 +57,15 @@ typedef ut_result_t (*test_func_t)(int test_num);
5657
*/
5758
#define BLINK_GPIO CONFIG_BLINK_GPIO
5859

60+
#define TEST_ID_PATTERN(_name_) _name_##_id_pattern
61+
#define TEST_ID_MATCH(_exp_, _id_) test_id_match(_exp_, (const char *)_id_)
62+
#define TEST_ENTRY(_name_) _name_##_task
63+
#define TEST_DECL(_name_, _exp_) \
64+
static const char _name_##_id_pattern[] = _exp_; \
65+
static void _name_##_task(void *pvParameter)
66+
67+
bool test_id_match(const char *exp, const char *id);
68+
5969
#endif
6070

6171
#endif //GEN_UT_APP_H

testing/esp/test_apps/gen_ut_app/main/special_tests.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ ut_result_t special_test_do(int test_num)
253253
break;
254254
}
255255
#if CONFIG_IDF_TARGET_ARCH_RISCV
256+
/* we have two different tests for Xtensa and RISCV with the same ID. See above.
257+
TODO: switch to string test IDs like 'test_bp.DebuggerBreakpointTestsDual.test_bp_add_remove_run', 'test_bp.DebuggerBreakpointTests*.test_bp_add_remove_run' */
256258
case 804:
257259
{
258260
xTaskCreatePinnedToCore(&target_wp_reconf_task, "target_wp_reconf_task", 2048, NULL, 5, NULL, portNUM_PROCESSORS-1);

0 commit comments

Comments
 (0)