From cd9adf2ce2df787719435b37f03b3fbc29e6b328 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Sun, 28 May 2023 08:25:32 +0000 Subject: [PATCH] tests: ztest: remove old API tests Remove tests for old API. Signed-off-by: Anas Nashif --- tests/ztest/automain/CMakeLists.txt | 9 - tests/ztest/automain/prj.conf | 1 - tests/ztest/automain/src/test_feature.c | 21 -- tests/ztest/automain/testcase.yaml | 5 - tests/ztest/custom_output/CMakeLists.txt | 9 - .../include/tc_util_user_override.h | 37 ---- tests/ztest/custom_output/prj.conf | 1 - .../custom_output/prj_customized_output.conf | 2 - tests/ztest/custom_output/src/main.c | 33 --- tests/ztest/custom_output/testcase.yaml | 10 - tests/ztest/register/CMakeLists.txt | 10 - tests/ztest/register/include/common.h | 23 -- tests/ztest/register/prj.conf | 1 - tests/ztest/register/src/main.c | 198 ------------------ .../ztest/register/src/test_null_predicate.c | 14 -- tests/ztest/register/src/test_step_0.c | 21 -- tests/ztest/register/src/test_step_1.c | 21 -- tests/ztest/register/src/test_step_all.c | 21 -- tests/ztest/register/testcase.yaml | 5 - 19 files changed, 442 deletions(-) delete mode 100644 tests/ztest/automain/CMakeLists.txt delete mode 100644 tests/ztest/automain/prj.conf delete mode 100644 tests/ztest/automain/src/test_feature.c delete mode 100644 tests/ztest/automain/testcase.yaml delete mode 100644 tests/ztest/custom_output/CMakeLists.txt delete mode 100644 tests/ztest/custom_output/include/tc_util_user_override.h delete mode 100644 tests/ztest/custom_output/prj.conf delete mode 100644 tests/ztest/custom_output/prj_customized_output.conf delete mode 100644 tests/ztest/custom_output/src/main.c delete mode 100644 tests/ztest/custom_output/testcase.yaml delete mode 100644 tests/ztest/register/CMakeLists.txt delete mode 100644 tests/ztest/register/include/common.h delete mode 100644 tests/ztest/register/prj.conf delete mode 100644 tests/ztest/register/src/main.c delete mode 100644 tests/ztest/register/src/test_null_predicate.c delete mode 100644 tests/ztest/register/src/test_step_0.c delete mode 100644 tests/ztest/register/src/test_step_1.c delete mode 100644 tests/ztest/register/src/test_step_all.c delete mode 100644 tests/ztest/register/testcase.yaml diff --git a/tests/ztest/automain/CMakeLists.txt b/tests/ztest/automain/CMakeLists.txt deleted file mode 100644 index f6939588854..00000000000 --- a/tests/ztest/automain/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright 2021 Google LLC -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(automain) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources}) diff --git a/tests/ztest/automain/prj.conf b/tests/ztest/automain/prj.conf deleted file mode 100644 index 9467c292689..00000000000 --- a/tests/ztest/automain/prj.conf +++ /dev/null @@ -1 +0,0 @@ -CONFIG_ZTEST=y diff --git a/tests/ztest/automain/src/test_feature.c b/tests/ztest/automain/src/test_feature.c deleted file mode 100644 index 9e091cf5cdd..00000000000 --- a/tests/ztest/automain/src/test_feature.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/** - * @brief A stub unit test. - * - * This is a mock unit test that is expected to run. Note that it is not added directly to a test - * suite and run via ztest_run_test_suite(). It is instead registered below using - * ztest_register_test_suite and will be run by the automatically generated test_main() function. - */ -static void test_stub(void) -{ -} - -ztest_register_test_suite(test_suite, NULL, - ztest_unit_test(test_stub)); diff --git a/tests/ztest/automain/testcase.yaml b/tests/ztest/automain/testcase.yaml deleted file mode 100644 index d9fbee9144f..00000000000 --- a/tests/ztest/automain/testcase.yaml +++ /dev/null @@ -1,5 +0,0 @@ -tests: - testing.ztest.automain: - tags: test_framework - integration_platforms: - - native_posix diff --git a/tests/ztest/custom_output/CMakeLists.txt b/tests/ztest/custom_output/CMakeLists.txt deleted file mode 100644 index 2802f30450c..00000000000 --- a/tests/ztest/custom_output/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(integration) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources}) -zephyr_include_directories(include) diff --git a/tests/ztest/custom_output/include/tc_util_user_override.h b/tests/ztest/custom_output/include/tc_util_user_override.h deleted file mode 100644 index 83dc2d694e5..00000000000 --- a/tests/ztest/custom_output/include/tc_util_user_override.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2019 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef __TC_UTIL_USER_OVERRIDE_H__ -#define __TC_UTIL_USER_OVERRIDE_H__ - -/* This header provides a sample user override of various tc_util.h defines. */ - -/* Example: Reduce vertical line verbosity by - * redefining the separator to nothing. - */ -#define PRINT_LINE - -/* Example: Prepend test cases with a counter. */ -#define TC_START(original) do { \ - static int count; \ - printk("%d: Test [%s]", ++count, original); \ -} while (0) - -/* Example: Change result string output formats. */ -#define TC_PASS_STR "Customized PASS" -#define TC_FAIL_STR "Customized FAIL" -#define TC_SKIP_STR "Customized SKIP" - -/* Example: Also count the number of pass/fail/skips and display it. */ -#define Z_TC_END_RESULT(result, s) do { \ - static int result_keeper[3] = {0}; \ - result_keeper[result]++; \ - printk(" reported %s - %s in 0 seconds(No time counted) no. %d\n", \ - TC_RESULT_TO_STR(result), s,\ - result_keeper[result]); \ -} while (0) - -#endif /* __TC_UTIL_USER_OVERRIDE_H__ */ diff --git a/tests/ztest/custom_output/prj.conf b/tests/ztest/custom_output/prj.conf deleted file mode 100644 index 9467c292689..00000000000 --- a/tests/ztest/custom_output/prj.conf +++ /dev/null @@ -1 +0,0 @@ -CONFIG_ZTEST=y diff --git a/tests/ztest/custom_output/prj_customized_output.conf b/tests/ztest/custom_output/prj_customized_output.conf deleted file mode 100644 index 290d9378c56..00000000000 --- a/tests/ztest/custom_output/prj_customized_output.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_ZTEST_TC_UTIL_USER_OVERRIDE=y diff --git a/tests/ztest/custom_output/src/main.c b/tests/ztest/custom_output/src/main.c deleted file mode 100644 index d7092f63d3d..00000000000 --- a/tests/ztest/custom_output/src/main.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -static void test_assert_pass(void) -{ - ztest_test_pass(); -} - -static void test_assert_skip(void) -{ - ztest_test_skip(); -} - -/* - * Same tests called several times to show custom handling of output. - */ -void test_main(void) -{ - ztest_test_suite(framework_tests, - ztest_unit_test(test_assert_pass), - ztest_unit_test(test_assert_pass), - ztest_unit_test(test_assert_pass), - ztest_unit_test(test_assert_skip), - ztest_unit_test(test_assert_skip) - ); - - ztest_run_test_suite(framework_tests); -} diff --git a/tests/ztest/custom_output/testcase.yaml b/tests/ztest/custom_output/testcase.yaml deleted file mode 100644 index 182edc60391..00000000000 --- a/tests/ztest/custom_output/testcase.yaml +++ /dev/null @@ -1,10 +0,0 @@ -tests: - testing.ztest.regular_output: - tags: test_framework - integration_platforms: - - native_posix - testing.ztest.customized_output: - extra_args: CONF_FILE=prj_customized_output.conf - tags: test_framework - integration_platforms: - - native_posix diff --git a/tests/ztest/register/CMakeLists.txt b/tests/ztest/register/CMakeLists.txt deleted file mode 100644 index a06945233f8..00000000000 --- a/tests/ztest/register/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright 2021 Google LLC -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(register) - -FILE(GLOB app_sources src/*.c) -target_include_directories(app PRIVATE include) -target_sources(app PRIVATE ${app_sources}) diff --git a/tests/ztest/register/include/common.h b/tests/ztest/register/include/common.h deleted file mode 100644 index c518a5af5bc..00000000000 --- a/tests/ztest/register/include/common.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef TESTS_ZTEST_REGISTER_INCLUDE_COMMON_H_ -#define TESTS_ZTEST_REGISTER_INCLUDE_COMMON_H_ - -#include - -enum phase { - PHASE_VERIFY, - PHASE_NULL_PREDICATE_0, - PHASE_NULL_PREDICATE_1, - PHASE_STEPS_0, - PHASE_STEPS_1, -}; -struct global_test_state { - enum phase phase; -}; - -#endif /* TESTS_ZTEST_REGISTER_INCLUDE_COMMON_H_ */ diff --git a/tests/ztest/register/prj.conf b/tests/ztest/register/prj.conf deleted file mode 100644 index 9467c292689..00000000000 --- a/tests/ztest/register/prj.conf +++ /dev/null @@ -1 +0,0 @@ -CONFIG_ZTEST=y diff --git a/tests/ztest/register/src/main.c b/tests/ztest/register/src/main.c deleted file mode 100644 index 8bdabaccca7..00000000000 --- a/tests/ztest/register/src/main.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include "common.h" - -#define num_registered_suites (_ztest_suite_node_list_end - _ztest_suite_node_list_start) - -/** The current state of the test application. */ -static struct global_test_state global_state; - -/** - * Copies of the test entry's snapshot, used to test assertions. There's no good way to get the - * number of registered test suites at compile time so this is set to an arbitrary large size that - * should be enough even if the number of tests grows. There's a runtime check for this in - * test_verify_execution. - */ -static struct ztest_suite_stats stats_snapshot[128]; - -/** The results of a single execution */ -struct execution_results { - /** The test phase that was run */ - enum phase test_phase; - /** The number of tests that ran */ - int test_run_count; -} execution_results; - -/** - * Helper function used to find a test entry by name. - * - * @param name The name of the test entry. - * @return Pointer to the struct unit_test_node or NULL if not found. - */ -static struct ztest_suite_node *find_test_node(const char *name) -{ - struct ztest_suite_node *ptr; - - for (ptr = _ztest_suite_node_list_start; ptr != _ztest_suite_node_list_end; ++ptr) { - if (strcmp(ptr->name, name) == 0) { - return ptr; - } - } - - return NULL; -} - -/** - * @brief Find a snapshot in the stats_snapshot array - * - * Lookup a test case by name and find the matching ztest_suite_stats. - * - * @param name The name of the test entry. - * @return Pointer to the stats snapshot. - */ -static struct ztest_suite_stats *find_snapshot(const char *name) -{ - int index = find_test_node(name) - _ztest_suite_node_list_start; - - return stats_snapshot + index; -} - -/** - * Reset the global state between phases. This function can be thought of similarly to making a - * change affecting the state of the application being tested. - * - * @param phase The new phase of the application. - */ -static void reset_state(enum phase phase) -{ - execution_results.test_phase = phase; - execution_results.test_run_count = 0; - global_state.phase = phase; - - for (int i = 0; i < num_registered_suites; ++i) { - stats_snapshot[i] = *_ztest_suite_node_list_start[i].stats; - } -} - -/** - * Create a snapshot of the tests' stats. This function should be called after each run in order - * to assert on only the changes in the stats. - */ -static void take_stats_snapshot(void) -{ - for (int i = 0; i < num_registered_suites; ++i) { - struct ztest_suite_stats *snapshot = stats_snapshot + i; - struct ztest_suite_stats *current = _ztest_suite_node_list_start[i].stats; - - snapshot->run_count = current->run_count - snapshot->run_count; - snapshot->skip_count = current->skip_count - snapshot->skip_count; - snapshot->fail_count = current->fail_count - snapshot->fail_count; - } -} - -static void test_verify_execution(void) -{ - const struct ztest_suite_stats *stats; - - zassert_true(ARRAY_SIZE(stats_snapshot) >= num_registered_suites, - "Not enough stats snapshots, please allocate more."); - switch (execution_results.test_phase) { - case PHASE_NULL_PREDICATE_0: - /* Verify that only remove_first_node suite was run and removed. */ - stats = find_snapshot("run_null_predicate_once"); - zassert_equal(1, execution_results.test_run_count); - zassert_equal(1, stats->run_count); - zassert_equal(0, stats->skip_count); - zassert_equal(0, stats->fail_count); - break; - case PHASE_NULL_PREDICATE_1: - /* Verify that only remove_first_two_nodes_* were run. */ - zassert_equal(0, execution_results.test_run_count); - stats = find_snapshot("run_null_predicate_once"); - zassert_equal(0, stats->run_count); - zassert_equal(1, stats->skip_count); - zassert_equal(0, stats->fail_count); - break; - case PHASE_STEPS_0: - /* Verify that steps_0 and steps_all suites were run. */ - zassert_equal(2, execution_results.test_run_count); - stats = find_snapshot("test_step_0"); - zassert_equal(1, stats->run_count); - zassert_equal(0, stats->skip_count); - zassert_equal(0, stats->fail_count); - stats = find_snapshot("test_step_1"); - zassert_equal(0, stats->run_count); - zassert_equal(1, stats->skip_count); - zassert_equal(0, stats->fail_count); - stats = find_snapshot("test_step_all"); - zassert_equal(1, stats->run_count); - zassert_equal(0, stats->skip_count); - zassert_equal(0, stats->fail_count); - break; - case PHASE_STEPS_1: - /* Verify that steps_1 and steps_all suites were run. */ - zassert_equal(2, execution_results.test_run_count); - stats = find_snapshot("test_step_0"); - zassert_equal(0, stats->run_count); - zassert_equal(1, stats->skip_count); - zassert_equal(0, stats->fail_count); - stats = find_snapshot("test_step_1"); - zassert_equal(1, stats->run_count); - zassert_equal(0, stats->skip_count); - zassert_equal(0, stats->fail_count); - stats = find_snapshot("test_step_all"); - zassert_equal(1, stats->run_count); - zassert_equal(0, stats->skip_count); - zassert_equal(0, stats->fail_count); - break; - default: - ztest_test_fail(); - } -} - -static bool verify_predicate(const void *state) -{ - const struct global_test_state *s = state; - - return s->phase == PHASE_VERIFY; -} - -ztest_register_test_suite(verify, verify_predicate, - ztest_unit_test(test_verify_execution)); - -void test_main(void) -{ - /* Make sure that when predicate is set to NULL, the test is run. */ - reset_state(PHASE_NULL_PREDICATE_0); - execution_results.test_run_count = ztest_run_registered_test_suites(&global_state); - take_stats_snapshot(); - global_state.phase = PHASE_VERIFY; - ztest_run_registered_test_suites(&global_state); - - /* Try running the tests again, nothing should run. */ - reset_state(PHASE_NULL_PREDICATE_1); - execution_results.test_run_count = ztest_run_registered_test_suites(&global_state); - take_stats_snapshot(); - global_state.phase = PHASE_VERIFY; - ztest_run_registered_test_suites(&global_state); - - /* Run filter tests for step 0. */ - reset_state(PHASE_STEPS_0); - execution_results.test_run_count = ztest_run_registered_test_suites(&global_state); - global_state.phase = PHASE_VERIFY; - take_stats_snapshot(); - ztest_run_registered_test_suites(&global_state); - - /* Run filter tests for step 1. */ - reset_state(PHASE_STEPS_1); - execution_results.test_run_count = ztest_run_registered_test_suites(&global_state); - global_state.phase = PHASE_VERIFY; - take_stats_snapshot(); - ztest_run_registered_test_suites(&global_state); -} diff --git a/tests/ztest/register/src/test_null_predicate.c b/tests/ztest/register/src/test_null_predicate.c deleted file mode 100644 index f3639ba8b14..00000000000 --- a/tests/ztest/register/src/test_null_predicate.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "common.h" - -static void test_stub(void) -{ -} - -ztest_register_test_suite(run_null_predicate_once, NULL, ztest_unit_test(test_stub)); diff --git a/tests/ztest/register/src/test_step_0.c b/tests/ztest/register/src/test_step_0.c deleted file mode 100644 index 22d372e8ee3..00000000000 --- a/tests/ztest/register/src/test_step_0.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "common.h" - -static void test_step_0(void) -{ -} - -static bool predicate(const void *state) -{ - const struct global_test_state *s = state; - - return s->phase == PHASE_STEPS_0; -} - -ztest_register_test_suite(test_step_0, predicate, ztest_unit_test(test_step_0)); diff --git a/tests/ztest/register/src/test_step_1.c b/tests/ztest/register/src/test_step_1.c deleted file mode 100644 index 2bb63aa2cf4..00000000000 --- a/tests/ztest/register/src/test_step_1.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "common.h" - -static void test_step_1(void) -{ -} - -static bool predicate(const void *state) -{ - const struct global_test_state *s = state; - - return s->phase == PHASE_STEPS_1; -} - -ztest_register_test_suite(test_step_1, predicate, ztest_unit_test(test_step_1)); diff --git a/tests/ztest/register/src/test_step_all.c b/tests/ztest/register/src/test_step_all.c deleted file mode 100644 index 9af5a5df5da..00000000000 --- a/tests/ztest/register/src/test_step_all.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "common.h" - -static void test_step_all(void) -{ -} - -static bool predicate(const void *state) -{ - const struct global_test_state *s = state; - - return s->phase == PHASE_STEPS_0 || s->phase == PHASE_STEPS_1; -} - -ztest_register_test_suite(test_step_all, predicate, ztest_unit_test(test_step_all)); diff --git a/tests/ztest/register/testcase.yaml b/tests/ztest/register/testcase.yaml deleted file mode 100644 index e9a0744f027..00000000000 --- a/tests/ztest/register/testcase.yaml +++ /dev/null @@ -1,5 +0,0 @@ -tests: - testing.ztest.register: - tags: test_framework - integration_platforms: - - native_posix