tests: ztest: remove old API tests

Remove tests for old API.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2023-05-28 08:25:32 +00:00
commit cd9adf2ce2
19 changed files with 0 additions and 442 deletions

View file

@ -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})

View file

@ -1 +0,0 @@
CONFIG_ZTEST=y

View file

@ -1,21 +0,0 @@
/*
* Copyright 2021 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/ztest.h>
/**
* @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));

View file

@ -1,5 +0,0 @@
tests:
testing.ztest.automain:
tags: test_framework
integration_platforms:
- native_posix

View file

@ -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)

View file

@ -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__ */

View file

@ -1 +0,0 @@
CONFIG_ZTEST=y

View file

@ -1,2 +0,0 @@
CONFIG_ZTEST=y
CONFIG_ZTEST_TC_UTIL_USER_OVERRIDE=y

View file

@ -1,33 +0,0 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/ztest.h>
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);
}

View file

@ -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

View file

@ -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})

View file

@ -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 <stdbool.h>
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_ */

View file

@ -1 +0,0 @@
CONFIG_ZTEST=y

View file

@ -1,198 +0,0 @@
/*
* Copyright 2021 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <zephyr/ztest.h>
#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);
}

View file

@ -1,14 +0,0 @@
/*
* Copyright 2021 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/ztest.h>
#include "common.h"
static void test_stub(void)
{
}
ztest_register_test_suite(run_null_predicate_once, NULL, ztest_unit_test(test_stub));

View file

@ -1,21 +0,0 @@
/*
* Copyright 2021 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/ztest.h>
#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));

View file

@ -1,21 +0,0 @@
/*
* Copyright 2021 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/ztest.h>
#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));

View file

@ -1,21 +0,0 @@
/*
* Copyright 2021 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/ztest.h>
#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));

View file

@ -1,5 +0,0 @@
tests:
testing.ztest.register:
tags: test_framework
integration_platforms:
- native_posix