From 09c70d57811b20099b84509367dafc3723c2f4a0 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 21 Jun 2022 20:29:01 +0200 Subject: [PATCH] unity: expose some internal functions to allow iterating over tests --- components/unity/include/unity_test_runner.h | 6 +++ components/unity/unity_runner.c | 42 ++++++++++++-------- tools/ci/check_copyright_ignore.txt | 1 - 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/components/unity/include/unity_test_runner.h b/components/unity/include/unity_test_runner.h index 7587b6d249..b14e3c0f77 100644 --- a/components/unity/include/unity_test_runner.h +++ b/components/unity/include/unity_test_runner.h @@ -171,12 +171,18 @@ void unity_testcase_register(test_desc_t* desc); void unity_run_test_by_name(const char *name); +void unity_run_test_by_index(int test_index); + void unity_run_tests_by_tag(const char *tag, bool invert); void unity_run_all_tests(void); void unity_run_menu(void); +int unity_get_test_count(void); + +bool unity_get_test_info(int test_index, test_desc_t* out_info); + #include "sdkconfig.h" //to get IDF_TARGET_xxx #define CONFIG_IDF_TARGET_NA 0 diff --git a/components/unity/unity_runner.c b/components/unity/unity_runner.c index 3c07b250f6..c4cb7ecc55 100644 --- a/components/unity/unity_runner.c +++ b/components/unity/unity_runner.c @@ -1,16 +1,8 @@ -// Copyright 2016-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -143,7 +135,7 @@ static void unity_run_single_test(const test_desc_t *test) } } -static void unity_run_single_test_by_index(int index) +void unity_run_test_by_index(int index) { const test_desc_t *test; for (test = s_unity_tests_first; test != NULL && index != 0; test = test->next, --index) { @@ -159,7 +151,7 @@ static void unity_run_single_test_by_index_parse(const char *filter, int index_m int test_index = strtol(filter, NULL, 10); if (test_index >= 1 && test_index <= index_max) { UNITY_EXEC_TIME_START(); - unity_run_single_test_by_index(test_index - 1); + unity_run_test_by_index(test_index - 1); UNITY_EXEC_TIME_STOP(); UnityPrint("Test ran in "); UnityPrintNumberUnsigned(UNITY_EXEC_TIME_MS()); @@ -254,7 +246,7 @@ static int print_test_menu(void) return test_counter; } -static int get_test_count(void) +int unity_get_test_count(void) { int test_counter = 0; for (const test_desc_t *test = s_unity_tests_first; @@ -271,7 +263,7 @@ void unity_run_menu(void) UNITY_PRINT_EOL(); UnityPrint("Press ENTER to see the list of tests."); UNITY_PRINT_EOL(); - int test_count = get_test_count(); + int test_count = unity_get_test_count(); while (true) { char cmdline[256] = { 0 }; while (strlen(cmdline) == 0) { @@ -318,3 +310,19 @@ void unity_run_menu(void) UNITY_OUTPUT_FLUSH(); } } + +bool unity_get_test_info(int test_index, test_desc_t* out_info) +{ + if (test_index < 0) { + return false; + } + const test_desc_t *test; + for (test = s_unity_tests_first; test != NULL && test_index != 0; test = test->next, --test_index) { + ; + } + if (test == NULL) { + return false; + } + *out_info = *test; + return true; +} diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index b9236666e5..0b722b4e80 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1418,7 +1418,6 @@ components/ulp/test/esp32/test_ulp_as.c components/unity/include/priv/setjmp.h components/unity/include/unity_config.h components/unity/include/unity_fixture_extras.h -components/unity/unity_runner.c components/usb/test/hcd/test_hcd_ctrl.c components/vfs/include/esp_vfs_common.h components/vfs/include/esp_vfs_eventfd.h