ztest: Fix formatting
Run clang-format on some ztest files. Signed-off-by: Keith Short <keithshort@google.com>
This commit is contained in:
parent
d8bc125469
commit
82a2a16649
3 changed files with 90 additions and 101 deletions
|
@ -172,7 +172,8 @@ static inline bool z_zexpect(bool cond, const char *default_msg, const char *fil
|
|||
#define _zassert_base(cond, default_msg, msg, ...) \
|
||||
do { \
|
||||
bool _msg = (msg != NULL); \
|
||||
bool _ret = z_zassert(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,\
|
||||
bool _ret = \
|
||||
z_zassert(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__, \
|
||||
__LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
|
||||
(void)_msg; \
|
||||
if (!_ret) { \
|
||||
|
@ -209,7 +210,8 @@ static inline bool z_zexpect(bool cond, const char *default_msg, const char *fil
|
|||
#define _zassume_base(cond, default_msg, msg, ...) \
|
||||
do { \
|
||||
bool _msg = (msg != NULL); \
|
||||
bool _ret = z_zassume(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,\
|
||||
bool _ret = \
|
||||
z_zassume(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__, \
|
||||
__LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
|
||||
(void)_msg; \
|
||||
if (!_ret) { \
|
||||
|
|
|
@ -184,10 +184,8 @@ static void cpu_hold(void *arg1, void *arg2, void *arg3)
|
|||
cpuhold_spawned = false;
|
||||
|
||||
cpuhold_pool_items[i].used = true;
|
||||
k_thread_create(&cpuhold_pool_items[i].thread,
|
||||
cpuhold_stacks[i], CPUHOLD_STACK_SZ,
|
||||
cpu_hold, k_current_get(),
|
||||
(void *)(uintptr_t)idx, NULL,
|
||||
k_thread_create(&cpuhold_pool_items[i].thread, cpuhold_stacks[i], CPUHOLD_STACK_SZ,
|
||||
cpu_hold, k_current_get(), (void *)(uintptr_t)idx, NULL,
|
||||
K_HIGHEST_THREAD_PRIO, 0, K_NO_WAIT);
|
||||
|
||||
/*
|
||||
|
@ -217,7 +215,6 @@ static void cpu_hold(void *arg1, void *arg2, void *arg3)
|
|||
k_thread_name_set(k_current_get(), tname);
|
||||
}
|
||||
|
||||
|
||||
uint32_t dt, start_ms = k_uptime_get_32();
|
||||
unsigned int key = arch_irq_lock();
|
||||
|
||||
|
@ -243,8 +240,7 @@ static void cpu_hold(void *arg1, void *arg2, void *arg3)
|
|||
* logic views it as one "job") and cause other test failures.
|
||||
*/
|
||||
dt = k_uptime_get_32() - start_ms;
|
||||
zassert_true(dt < CONFIG_ZTEST_CPU_HOLD_TIME_MS,
|
||||
"1cpu test took too long (%d ms)", dt);
|
||||
zassert_true(dt < CONFIG_ZTEST_CPU_HOLD_TIME_MS, "1cpu test took too long (%d ms)", dt);
|
||||
arch_irq_unlock(key);
|
||||
}
|
||||
#endif /* CONFIG_SMP && (CONFIG_MP_MAX_NUM_CPUS > 1) */
|
||||
|
@ -268,10 +264,9 @@ void z_impl_z_test_1cpu_start(void)
|
|||
__ASSERT_NO_MSG(j != -1);
|
||||
|
||||
cpuhold_pool_items[j].used = true;
|
||||
k_thread_create(&cpuhold_pool_items[j].thread,
|
||||
cpuhold_stacks[j], CPUHOLD_STACK_SZ,
|
||||
cpu_hold, NULL, (void *)(uintptr_t)i, NULL,
|
||||
K_HIGHEST_THREAD_PRIO, 0, K_NO_WAIT);
|
||||
k_thread_create(&cpuhold_pool_items[j].thread, cpuhold_stacks[j], CPUHOLD_STACK_SZ,
|
||||
cpu_hold, NULL, (void *)(uintptr_t)i, NULL, K_HIGHEST_THREAD_PRIO,
|
||||
0, K_NO_WAIT);
|
||||
k_sem_take(&cpuhold_sem, K_FOREVER);
|
||||
}
|
||||
#endif
|
||||
|
@ -292,10 +287,16 @@ void z_impl_z_test_1cpu_stop(void)
|
|||
}
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
void z_vrfy_z_test_1cpu_start(void) { z_impl_z_test_1cpu_start(); }
|
||||
void z_vrfy_z_test_1cpu_start(void)
|
||||
{
|
||||
z_impl_z_test_1cpu_start();
|
||||
}
|
||||
#include <zephyr/syscalls/z_test_1cpu_start_mrsh.c>
|
||||
|
||||
void z_vrfy_z_test_1cpu_stop(void) { z_impl_z_test_1cpu_stop(); }
|
||||
void z_vrfy_z_test_1cpu_stop(void)
|
||||
{
|
||||
z_impl_z_test_1cpu_stop();
|
||||
}
|
||||
#include <zephyr/syscalls/z_test_1cpu_stop_mrsh.c>
|
||||
#endif /* CONFIG_USERSPACE */
|
||||
#endif
|
||||
|
@ -671,10 +672,8 @@ static int run_test(struct ztest_suite_node *suite, struct ztest_unit_test *test
|
|||
if (IS_ENABLED(CONFIG_MULTITHREADING)) {
|
||||
get_start_time_cyc();
|
||||
k_thread_create(&ztest_thread, ztest_thread_stack,
|
||||
K_THREAD_STACK_SIZEOF(ztest_thread_stack),
|
||||
test_cb, suite, test, data,
|
||||
CONFIG_ZTEST_THREAD_PRIORITY,
|
||||
K_INHERIT_PERMS, K_FOREVER);
|
||||
K_THREAD_STACK_SIZEOF(ztest_thread_stack), test_cb, suite, test,
|
||||
data, CONFIG_ZTEST_THREAD_PRIORITY, K_INHERIT_PERMS, K_FOREVER);
|
||||
|
||||
k_thread_access_grant(&ztest_thread, suite, test, suite->stats);
|
||||
if (test->name != NULL) {
|
||||
|
@ -765,8 +764,8 @@ struct ztest_unit_test *z_ztest_get_next_test(const char *suite, struct ztest_un
|
|||
}
|
||||
|
||||
#if CONFIG_ZTEST_SHUFFLE
|
||||
static void z_ztest_shuffle(bool shuffle, void *dest[], intptr_t start,
|
||||
size_t num_items, size_t element_size)
|
||||
static void z_ztest_shuffle(bool shuffle, void *dest[], intptr_t start, size_t num_items,
|
||||
size_t element_size)
|
||||
{
|
||||
/* Initialize dest array */
|
||||
for (size_t i = 0; i < num_items; ++i) {
|
||||
|
@ -789,8 +788,8 @@ static void z_ztest_shuffle(bool shuffle, void *dest[], intptr_t start,
|
|||
}
|
||||
#endif
|
||||
|
||||
static int z_ztest_run_test_suite_ptr(struct ztest_suite_node *suite,
|
||||
bool shuffle, int suite_iter, int case_iter)
|
||||
static int z_ztest_run_test_suite_ptr(struct ztest_suite_node *suite, bool shuffle, int suite_iter,
|
||||
int case_iter)
|
||||
{
|
||||
struct ztest_unit_test *test = NULL;
|
||||
void *data = NULL;
|
||||
|
@ -836,8 +835,8 @@ static int z_ztest_run_test_suite_ptr(struct ztest_suite_node *suite,
|
|||
|
||||
memset(tests_to_run, 0, ZTEST_TEST_COUNT * sizeof(struct ztest_unit_test *));
|
||||
z_ztest_shuffle(shuffle, (void **)tests_to_run,
|
||||
(intptr_t)_ztest_unit_test_list_start,
|
||||
ZTEST_TEST_COUNT, sizeof(struct ztest_unit_test));
|
||||
(intptr_t)_ztest_unit_test_list_start, ZTEST_TEST_COUNT,
|
||||
sizeof(struct ztest_unit_test));
|
||||
for (size_t j = 0; j < ZTEST_TEST_COUNT; ++j) {
|
||||
test = tests_to_run[j];
|
||||
/* Make sure that the test belongs to this suite */
|
||||
|
@ -902,8 +901,8 @@ static int z_ztest_run_test_suite_ptr(struct ztest_suite_node *suite,
|
|||
|
||||
int z_ztest_run_test_suite(const char *name, bool shuffle, int suite_iter, int case_iter)
|
||||
{
|
||||
return z_ztest_run_test_suite_ptr(ztest_find_test_suite(name),
|
||||
shuffle, suite_iter, case_iter);
|
||||
return z_ztest_run_test_suite_ptr(ztest_find_test_suite(name), shuffle, suite_iter,
|
||||
case_iter);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
|
@ -980,10 +979,8 @@ static void __ztest_show_suite_summary_oneline(struct ztest_suite_node *suite)
|
|||
|
||||
TC_SUMMARY_PRINT("SUITE %s - %3d.%02d%% [%s]: pass = %d, fail = %d, "
|
||||
"skip = %d, total = %d duration = %u.%03u seconds\n",
|
||||
TC_RESULT_TO_STR(suite_result),
|
||||
passrate_major, passrate_minor,
|
||||
suite->name, distinct_pass, distinct_fail,
|
||||
distinct_skip, distinct_total,
|
||||
TC_RESULT_TO_STR(suite_result), passrate_major, passrate_minor,
|
||||
suite->name, distinct_pass, distinct_fail, distinct_skip, distinct_total,
|
||||
suite_duration_worst_ms / 1000, suite_duration_worst_ms % 1000);
|
||||
flush_log();
|
||||
}
|
||||
|
@ -1010,19 +1007,17 @@ static void __ztest_show_suite_summary_verbose(struct ztest_suite_node *suite)
|
|||
}
|
||||
|
||||
if (tc_result == TC_FLAKY) {
|
||||
TC_SUMMARY_PRINT(" - %s - [%s.%s] - (Failed %d of %d attempts)"
|
||||
TC_SUMMARY_PRINT(
|
||||
" - %s - [%s.%s] - (Failed %d of %d attempts)"
|
||||
" - duration = %u.%03u seconds\n",
|
||||
TC_RESULT_TO_STR(tc_result),
|
||||
test->test_suite_name, test->name,
|
||||
TC_RESULT_TO_STR(tc_result), test->test_suite_name, test->name,
|
||||
test->stats->run_count - test->stats->pass_count,
|
||||
test->stats->run_count,
|
||||
test->stats->duration_worst_ms / 1000,
|
||||
test->stats->run_count, test->stats->duration_worst_ms / 1000,
|
||||
test->stats->duration_worst_ms % 1000);
|
||||
} else {
|
||||
TC_SUMMARY_PRINT(" - %s - [%s.%s] duration = %u.%03u seconds\n",
|
||||
TC_RESULT_TO_STR(tc_result),
|
||||
test->test_suite_name, test->name,
|
||||
test->stats->duration_worst_ms / 1000,
|
||||
TC_RESULT_TO_STR(tc_result), test->test_suite_name,
|
||||
test->name, test->stats->duration_worst_ms / 1000,
|
||||
test->stats->duration_worst_ms % 1000);
|
||||
}
|
||||
|
||||
|
@ -1057,8 +1052,8 @@ static void __ztest_show_suite_summary(void)
|
|||
flush_log();
|
||||
}
|
||||
|
||||
static int __ztest_run_test_suite(struct ztest_suite_node *ptr,
|
||||
const void *state, bool shuffle, int suite_iter, int case_iter)
|
||||
static int __ztest_run_test_suite(struct ztest_suite_node *ptr, const void *state, bool shuffle,
|
||||
int suite_iter, int case_iter)
|
||||
{
|
||||
struct ztest_suite_stats *stats = ptr->stats;
|
||||
int count = 0;
|
||||
|
@ -1100,8 +1095,8 @@ int z_impl_ztest_run_test_suites(const void *state, bool shuffle, int suite_iter
|
|||
__ztest_init_unit_test_result_for_suite(suites_to_run[i]);
|
||||
}
|
||||
for (size_t i = 0; i < ZTEST_SUITE_COUNT; ++i) {
|
||||
count += __ztest_run_test_suite(suites_to_run[i],
|
||||
state, shuffle, suite_iter, case_iter);
|
||||
count += __ztest_run_test_suite(suites_to_run[i], state, shuffle, suite_iter,
|
||||
case_iter);
|
||||
/* Stop running tests if we have a critical error or if we have a failure and
|
||||
* FAIL_FAST was set
|
||||
*/
|
||||
|
@ -1307,8 +1302,8 @@ static int cmd_shuffle(const struct shell *sh, size_t argc, char **argv)
|
|||
opt_num++;
|
||||
break;
|
||||
default:
|
||||
shell_fprintf(sh, SHELL_ERROR,
|
||||
"Invalid option or option usage: %s\n", argv[opt_index + 1]);
|
||||
shell_fprintf(sh, SHELL_ERROR, "Invalid option or option usage: %s\n",
|
||||
argv[opt_index + 1]);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
}
|
||||
|
@ -1357,8 +1352,7 @@ static const struct ztest_suite_node *suite_lookup(size_t idx, const char *prefi
|
|||
|
||||
while (suite < suite_end) {
|
||||
if ((suite->name != NULL) && (strlen(suite->name) != 0) &&
|
||||
((prefix == NULL) ||
|
||||
(strncmp(prefix, suite->name, strlen(prefix)) == 0))) {
|
||||
((prefix == NULL) || (strncmp(prefix, suite->name, strlen(prefix)) == 0))) {
|
||||
if (match_idx == idx) {
|
||||
return suite;
|
||||
}
|
||||
|
@ -1380,6 +1374,7 @@ static void testsuite_list_get(size_t idx, struct shell_static_entry *entry)
|
|||
entry->subcmd = NULL;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(
|
||||
sub_ztest_cmds,
|
||||
SHELL_CMD_ARG(run-all, NULL, "Run all tests", cmd_runall, 0, 0),
|
||||
|
@ -1396,6 +1391,7 @@ static void testsuite_list_get(size_t idx, struct shell_static_entry *entry)
|
|||
SHELL_CMD_ARG(run-testcase, NULL, "Run testcase", cmd_run_suite, 2, 0),
|
||||
SHELL_SUBCMD_SET_END /* Array terminated. */
|
||||
);
|
||||
/* clang-format on */
|
||||
|
||||
SHELL_CMD_REGISTER(ztest, &sub_ztest_cmds, "Ztest commands", NULL);
|
||||
#endif /* CONFIG_ZTEST_SHELL */
|
||||
|
|
|
@ -77,8 +77,7 @@ int snprintk(char *str, size_t size, const char *fmt, ...)
|
|||
* been fixed to void* or similar GH-2825
|
||||
*/
|
||||
#define BITS_PER_UL (8 * sizeof(unsigned long))
|
||||
#define DEFINE_BITFIELD(name, bits) \
|
||||
unsigned long(name)[DIV_ROUND_UP(bits, BITS_PER_UL)]
|
||||
#define DEFINE_BITFIELD(name, bits) unsigned long(name)[DIV_ROUND_UP(bits, BITS_PER_UL)]
|
||||
|
||||
static inline int sys_bitfield_find_first_clear(const unsigned long *bitmap,
|
||||
const unsigned int bits)
|
||||
|
@ -100,8 +99,8 @@ static inline int sys_bitfield_find_first_clear(const unsigned long *bitmap,
|
|||
/* First bit is free */
|
||||
return cnt * BITS_PER_UL;
|
||||
} else {
|
||||
const unsigned int bit = (cnt * BITS_PER_UL) +
|
||||
__builtin_ffsl(neg_bitmap) - 1;
|
||||
const unsigned int bit =
|
||||
(cnt * BITS_PER_UL) + __builtin_ffsl(neg_bitmap) - 1;
|
||||
/* Ensure first free bit is within total bits count */
|
||||
if (bit < bits) {
|
||||
return bit;
|
||||
|
@ -124,8 +123,8 @@ static void free_parameter(struct parameter *param)
|
|||
return;
|
||||
}
|
||||
__ASSERT(allocation_index < CONFIG_ZTEST_PARAMETER_COUNT,
|
||||
"param %p given to free is not in the static buffer %p:%u",
|
||||
param, params, CONFIG_ZTEST_PARAMETER_COUNT);
|
||||
"param %p given to free is not in the static buffer %p:%u", param, params,
|
||||
CONFIG_ZTEST_PARAMETER_COUNT);
|
||||
sys_bitfield_clear_bit((mem_addr_t)params_allocation, allocation_index);
|
||||
}
|
||||
|
||||
|
@ -134,8 +133,8 @@ static struct parameter *alloc_parameter(void)
|
|||
int allocation_index;
|
||||
struct parameter *param;
|
||||
|
||||
allocation_index = sys_bitfield_find_first_clear(
|
||||
params_allocation, CONFIG_ZTEST_PARAMETER_COUNT);
|
||||
allocation_index =
|
||||
sys_bitfield_find_first_clear(params_allocation, CONFIG_ZTEST_PARAMETER_COUNT);
|
||||
if (allocation_index == -1) {
|
||||
printk("No more mock parameters available for allocation\n");
|
||||
ztest_test_fail();
|
||||
|
@ -152,8 +151,8 @@ void z_init_mock(void)
|
|||
|
||||
#endif
|
||||
|
||||
static struct parameter *find_and_delete_value(struct parameter *param,
|
||||
const char *fn, const char *name)
|
||||
static struct parameter *find_and_delete_value(struct parameter *param, const char *fn,
|
||||
const char *name)
|
||||
{
|
||||
struct parameter *value;
|
||||
|
||||
|
@ -172,8 +171,7 @@ static struct parameter *find_and_delete_value(struct parameter *param,
|
|||
return value;
|
||||
}
|
||||
|
||||
static void insert_value(struct parameter *param, const char *fn,
|
||||
const char *name, uintptr_t val)
|
||||
static void insert_value(struct parameter *param, const char *fn, const char *name, uintptr_t val)
|
||||
{
|
||||
struct parameter *value;
|
||||
|
||||
|
@ -192,16 +190,15 @@ static void insert_value(struct parameter *param, const char *fn,
|
|||
param->next = value;
|
||||
}
|
||||
|
||||
static struct parameter parameter_list = { NULL, "", "", 0 };
|
||||
static struct parameter return_value_list = { NULL, "", "", 0 };
|
||||
static struct parameter parameter_list = {NULL, "", "", 0};
|
||||
static struct parameter return_value_list = {NULL, "", "", 0};
|
||||
|
||||
void z_ztest_expect_value(const char *fn, const char *name, uintptr_t val)
|
||||
{
|
||||
insert_value(¶meter_list, fn, name, val);
|
||||
}
|
||||
|
||||
void z_ztest_check_expected_value(const char *fn, const char *name,
|
||||
uintptr_t val)
|
||||
void z_ztest_check_expected_value(const char *fn, const char *name, uintptr_t val)
|
||||
{
|
||||
struct parameter *param;
|
||||
uintptr_t expected;
|
||||
|
@ -219,8 +216,8 @@ void z_ztest_check_expected_value(const char *fn, const char *name,
|
|||
/* We need to cast these values since the toolchain doesn't
|
||||
* provide inttypes.h
|
||||
*/
|
||||
PRINT("%s:%s received wrong value: Got %lu, expected %lu\n", fn,
|
||||
name, (unsigned long)val, (unsigned long)expected);
|
||||
PRINT("%s:%s received wrong value: Got %lu, expected %lu\n", fn, name,
|
||||
(unsigned long)val, (unsigned long)expected);
|
||||
ztest_test_fail();
|
||||
}
|
||||
}
|
||||
|
@ -230,8 +227,7 @@ void z_ztest_expect_data(const char *fn, const char *name, void *val)
|
|||
insert_value(¶meter_list, fn, name, (uintptr_t)val);
|
||||
}
|
||||
|
||||
void z_ztest_check_expected_data(const char *fn, const char *name, void *data,
|
||||
uint32_t length)
|
||||
void z_ztest_check_expected_data(const char *fn, const char *name, void *data, uint32_t length)
|
||||
{
|
||||
struct parameter *param;
|
||||
void *expected;
|
||||
|
@ -254,8 +250,7 @@ void z_ztest_check_expected_data(const char *fn, const char *name, void *data,
|
|||
PRINT("%s:%s received data while expected null pointer\n", fn, name);
|
||||
ztest_test_fail();
|
||||
} else if (data == NULL && expected != NULL) {
|
||||
PRINT("%s:%s received null pointer while expected data\n", fn,
|
||||
name);
|
||||
PRINT("%s:%s received null pointer while expected data\n", fn, name);
|
||||
ztest_test_fail();
|
||||
} else if (data != NULL) {
|
||||
if (memcmp(data, expected, length) != 0) {
|
||||
|
@ -270,8 +265,7 @@ void z_ztest_return_data(const char *fn, const char *name, void *val)
|
|||
insert_value(¶meter_list, fn, name, (uintptr_t)val);
|
||||
}
|
||||
|
||||
void z_ztest_copy_return_data(const char *fn, const char *name, void *data,
|
||||
uint32_t length)
|
||||
void z_ztest_copy_return_data(const char *fn, const char *name, void *data, uint32_t length)
|
||||
{
|
||||
struct parameter *param;
|
||||
void *return_data;
|
||||
|
@ -302,8 +296,7 @@ void z_ztest_returns_value(const char *fn, uintptr_t value)
|
|||
uintptr_t z_ztest_get_return_value(const char *fn)
|
||||
{
|
||||
uintptr_t value;
|
||||
struct parameter *param =
|
||||
find_and_delete_value(&return_value_list, fn, "");
|
||||
struct parameter *param = find_and_delete_value(&return_value_list, fn, "");
|
||||
|
||||
if (!param) {
|
||||
PRINT("Failed to find return value for function %s\n", fn);
|
||||
|
@ -332,14 +325,12 @@ int z_cleanup_mock(void)
|
|||
int fail = 0;
|
||||
|
||||
if (parameter_list.next) {
|
||||
PRINT("Parameter not used by mock: %s:%s\n",
|
||||
parameter_list.next->fn,
|
||||
PRINT("Parameter not used by mock: %s:%s\n", parameter_list.next->fn,
|
||||
parameter_list.next->name);
|
||||
fail = 1;
|
||||
}
|
||||
if (return_value_list.next) {
|
||||
PRINT("Return value no used by mock: %s\n",
|
||||
return_value_list.next->fn);
|
||||
PRINT("Return value no used by mock: %s\n", return_value_list.next->fn);
|
||||
fail = 2;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue