From bd0dbbe7676320fc9e73b5ecc7f64ab53552ca67 Mon Sep 17 00:00:00 2001 From: Guillaume Souchere Date: Wed, 10 Apr 2024 11:23:07 +0200 Subject: [PATCH] test(heap): Extend task tracking test with task handle check Add a test to make sure that the task handles returned in the task tracking information are valid task handles. To verify that, feed the task name returned by pcTaskGetName() using the task handle under test to xTaskGetHandle() and make sure the task handle returned matches the one under test. --- .../test_apps/heap_tests/main/test_task_tracking.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/components/heap/test_apps/heap_tests/main/test_task_tracking.c b/components/heap/test_apps/heap_tests/main/test_task_tracking.c index 99215969dc..96a370528d 100644 --- a/components/heap/test_apps/heap_tests/main/test_task_tracking.c +++ b/components/heap/test_apps/heap_tests/main/test_task_tracking.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -49,6 +49,16 @@ static void check_heap_task_info(TaskHandle_t taskHdl) // heap_caps_get_per_task_info includes the size of the block owner (4 bytes) TEST_ASSERT(heap_info.totals[i].size[0] == ALLOC_BYTES + 4); } + + // test that if not 0, the task handle corresponds to an actual task. + // this test is to make sure no rubbish is stored as a task handle. + if (heap_info.totals[i].task != 0) { + // feeding the task name returned by pcTaskGetName() to xTaskGetHandle(). + // xTaskGetHandle would return the task handler used as parameter in + // pcTaskGetName if the task handle is valid. Otherwise, it will return + // NULL or just crash if the pointer to the task name is complete nonsense. + TEST_ASSERT_EQUAL(heap_info.totals[i].task, xTaskGetHandle(pcTaskGetName(heap_info.totals[i].task))); + } } TEST_ASSERT_TRUE(task_found); }