Skip to content

Commit 82a2a16

Browse files
keith-zephyrnashif
authored andcommitted
ztest: Fix formatting
Run clang-format on some ztest files. Signed-off-by: Keith Short <[email protected]>
1 parent d8bc125 commit 82a2a16

File tree

3 files changed

+90
-101
lines changed

3 files changed

+90
-101
lines changed

subsys/testsuite/ztest/include/zephyr/ztest_assert.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ static inline bool z_zexpect(bool cond, const char *default_msg, const char *fil
172172
#define _zassert_base(cond, default_msg, msg, ...) \
173173
do { \
174174
bool _msg = (msg != NULL); \
175-
bool _ret = z_zassert(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,\
176-
__LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
175+
bool _ret = \
176+
z_zassert(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__, \
177+
__LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
177178
(void)_msg; \
178179
if (!_ret) { \
179180
/* If kernel but without multithreading return. */ \
@@ -209,8 +210,9 @@ static inline bool z_zexpect(bool cond, const char *default_msg, const char *fil
209210
#define _zassume_base(cond, default_msg, msg, ...) \
210211
do { \
211212
bool _msg = (msg != NULL); \
212-
bool _ret = z_zassume(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,\
213-
__LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
213+
bool _ret = \
214+
z_zassume(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__, \
215+
__LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
214216
(void)_msg; \
215217
if (!_ret) { \
216218
/* If kernel but without multithreading return. */ \
@@ -396,7 +398,7 @@ static inline bool z_zexpect(bool cond, const char *default_msg, const char *fil
396398
* @param s2 The second string
397399
* @param ... Optional message and variables to print if the expectation fails
398400
*/
399-
#define zassert_str_equal(s1, s2, ...) \
401+
#define zassert_str_equal(s1, s2, ...) \
400402
zassert(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__)
401403

402404
/**
@@ -574,7 +576,7 @@ static inline bool z_zexpect(bool cond, const char *default_msg, const char *fil
574576
* @param s2 The second string
575577
* @param ... Optional message and variables to print if the expectation fails
576578
*/
577-
#define zassume_str_equal(s1, s2, ...) \
579+
#define zassume_str_equal(s1, s2, ...) \
578580
zassume(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__)
579581

580582
/**
@@ -719,7 +721,7 @@ static inline bool z_zexpect(bool cond, const char *default_msg, const char *fil
719721
* @param s2 The second string
720722
* @param ... Optional message and variables to print if the expectation fails
721723
*/
722-
#define zexpect_str_equal(s1, s2, ...) \
724+
#define zexpect_str_equal(s1, s2, ...) \
723725
zexpect(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__)
724726

725727
/**

subsys/testsuite/ztest/src/ztest.c

Lines changed: 59 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ static int cleanup_test(struct ztest_unit_test *test)
107107
#ifdef KERNEL
108108

109109
#if defined(CONFIG_SMP) && (CONFIG_MP_MAX_NUM_CPUS > 1)
110-
#define MAX_NUM_CPUHOLD (CONFIG_MP_MAX_NUM_CPUS - 1)
110+
#define MAX_NUM_CPUHOLD (CONFIG_MP_MAX_NUM_CPUS - 1)
111111
#define CPUHOLD_STACK_SZ (512 + CONFIG_TEST_EXTRA_STACK_SIZE)
112112

113113
struct cpuhold_pool_item {
114-
struct k_thread thread;
115-
bool used;
114+
struct k_thread thread;
115+
bool used;
116116
};
117117

118118
static struct cpuhold_pool_item cpuhold_pool_items[MAX_NUM_CPUHOLD + 1];
@@ -184,10 +184,8 @@ static void cpu_hold(void *arg1, void *arg2, void *arg3)
184184
cpuhold_spawned = false;
185185

186186
cpuhold_pool_items[i].used = true;
187-
k_thread_create(&cpuhold_pool_items[i].thread,
188-
cpuhold_stacks[i], CPUHOLD_STACK_SZ,
189-
cpu_hold, k_current_get(),
190-
(void *)(uintptr_t)idx, NULL,
187+
k_thread_create(&cpuhold_pool_items[i].thread, cpuhold_stacks[i], CPUHOLD_STACK_SZ,
188+
cpu_hold, k_current_get(), (void *)(uintptr_t)idx, NULL,
191189
K_HIGHEST_THREAD_PRIO, 0, K_NO_WAIT);
192190

193191
/*
@@ -217,7 +215,6 @@ static void cpu_hold(void *arg1, void *arg2, void *arg3)
217215
k_thread_name_set(k_current_get(), tname);
218216
}
219217

220-
221218
uint32_t dt, start_ms = k_uptime_get_32();
222219
unsigned int key = arch_irq_lock();
223220

@@ -243,8 +240,7 @@ static void cpu_hold(void *arg1, void *arg2, void *arg3)
243240
* logic views it as one "job") and cause other test failures.
244241
*/
245242
dt = k_uptime_get_32() - start_ms;
246-
zassert_true(dt < CONFIG_ZTEST_CPU_HOLD_TIME_MS,
247-
"1cpu test took too long (%d ms)", dt);
243+
zassert_true(dt < CONFIG_ZTEST_CPU_HOLD_TIME_MS, "1cpu test took too long (%d ms)", dt);
248244
arch_irq_unlock(key);
249245
}
250246
#endif /* CONFIG_SMP && (CONFIG_MP_MAX_NUM_CPUS > 1) */
@@ -268,10 +264,9 @@ void z_impl_z_test_1cpu_start(void)
268264
__ASSERT_NO_MSG(j != -1);
269265

270266
cpuhold_pool_items[j].used = true;
271-
k_thread_create(&cpuhold_pool_items[j].thread,
272-
cpuhold_stacks[j], CPUHOLD_STACK_SZ,
273-
cpu_hold, NULL, (void *)(uintptr_t)i, NULL,
274-
K_HIGHEST_THREAD_PRIO, 0, K_NO_WAIT);
267+
k_thread_create(&cpuhold_pool_items[j].thread, cpuhold_stacks[j], CPUHOLD_STACK_SZ,
268+
cpu_hold, NULL, (void *)(uintptr_t)i, NULL, K_HIGHEST_THREAD_PRIO,
269+
0, K_NO_WAIT);
275270
k_sem_take(&cpuhold_sem, K_FOREVER);
276271
}
277272
#endif
@@ -292,10 +287,16 @@ void z_impl_z_test_1cpu_stop(void)
292287
}
293288

294289
#ifdef CONFIG_USERSPACE
295-
void z_vrfy_z_test_1cpu_start(void) { z_impl_z_test_1cpu_start(); }
290+
void z_vrfy_z_test_1cpu_start(void)
291+
{
292+
z_impl_z_test_1cpu_start();
293+
}
296294
#include <zephyr/syscalls/z_test_1cpu_start_mrsh.c>
297295

298-
void z_vrfy_z_test_1cpu_stop(void) { z_impl_z_test_1cpu_stop(); }
296+
void z_vrfy_z_test_1cpu_stop(void)
297+
{
298+
z_impl_z_test_1cpu_stop();
299+
}
299300
#include <zephyr/syscalls/z_test_1cpu_stop_mrsh.c>
300301
#endif /* CONFIG_USERSPACE */
301302
#endif
@@ -671,10 +672,8 @@ static int run_test(struct ztest_suite_node *suite, struct ztest_unit_test *test
671672
if (IS_ENABLED(CONFIG_MULTITHREADING)) {
672673
get_start_time_cyc();
673674
k_thread_create(&ztest_thread, ztest_thread_stack,
674-
K_THREAD_STACK_SIZEOF(ztest_thread_stack),
675-
test_cb, suite, test, data,
676-
CONFIG_ZTEST_THREAD_PRIORITY,
677-
K_INHERIT_PERMS, K_FOREVER);
675+
K_THREAD_STACK_SIZEOF(ztest_thread_stack), test_cb, suite, test,
676+
data, CONFIG_ZTEST_THREAD_PRIORITY, K_INHERIT_PERMS, K_FOREVER);
678677

679678
k_thread_access_grant(&ztest_thread, suite, test, suite->stats);
680679
if (test->name != NULL) {
@@ -765,8 +764,8 @@ struct ztest_unit_test *z_ztest_get_next_test(const char *suite, struct ztest_un
765764
}
766765

767766
#if CONFIG_ZTEST_SHUFFLE
768-
static void z_ztest_shuffle(bool shuffle, void *dest[], intptr_t start,
769-
size_t num_items, size_t element_size)
767+
static void z_ztest_shuffle(bool shuffle, void *dest[], intptr_t start, size_t num_items,
768+
size_t element_size)
770769
{
771770
/* Initialize dest array */
772771
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,
789788
}
790789
#endif
791790

792-
static int z_ztest_run_test_suite_ptr(struct ztest_suite_node *suite,
793-
bool shuffle, int suite_iter, int case_iter)
791+
static int z_ztest_run_test_suite_ptr(struct ztest_suite_node *suite, bool shuffle, int suite_iter,
792+
int case_iter)
794793
{
795794
struct ztest_unit_test *test = NULL;
796795
void *data = NULL;
@@ -836,8 +835,8 @@ static int z_ztest_run_test_suite_ptr(struct ztest_suite_node *suite,
836835

837836
memset(tests_to_run, 0, ZTEST_TEST_COUNT * sizeof(struct ztest_unit_test *));
838837
z_ztest_shuffle(shuffle, (void **)tests_to_run,
839-
(intptr_t)_ztest_unit_test_list_start,
840-
ZTEST_TEST_COUNT, sizeof(struct ztest_unit_test));
838+
(intptr_t)_ztest_unit_test_list_start, ZTEST_TEST_COUNT,
839+
sizeof(struct ztest_unit_test));
841840
for (size_t j = 0; j < ZTEST_TEST_COUNT; ++j) {
842841
test = tests_to_run[j];
843842
/* 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,
902901

903902
int z_ztest_run_test_suite(const char *name, bool shuffle, int suite_iter, int case_iter)
904903
{
905-
return z_ztest_run_test_suite_ptr(ztest_find_test_suite(name),
906-
shuffle, suite_iter, case_iter);
904+
return z_ztest_run_test_suite_ptr(ztest_find_test_suite(name), shuffle, suite_iter,
905+
case_iter);
907906
}
908907

909908
#ifdef CONFIG_USERSPACE
@@ -979,12 +978,10 @@ static void __ztest_show_suite_summary_oneline(struct ztest_suite_node *suite)
979978
}
980979

981980
TC_SUMMARY_PRINT("SUITE %s - %3d.%02d%% [%s]: pass = %d, fail = %d, "
982-
"skip = %d, total = %d duration = %u.%03u seconds\n",
983-
TC_RESULT_TO_STR(suite_result),
984-
passrate_major, passrate_minor,
985-
suite->name, distinct_pass, distinct_fail,
986-
distinct_skip, distinct_total,
987-
suite_duration_worst_ms / 1000, suite_duration_worst_ms % 1000);
981+
"skip = %d, total = %d duration = %u.%03u seconds\n",
982+
TC_RESULT_TO_STR(suite_result), passrate_major, passrate_minor,
983+
suite->name, distinct_pass, distinct_fail, distinct_skip, distinct_total,
984+
suite_duration_worst_ms / 1000, suite_duration_worst_ms % 1000);
988985
flush_log();
989986
}
990987

@@ -1010,20 +1007,18 @@ static void __ztest_show_suite_summary_verbose(struct ztest_suite_node *suite)
10101007
}
10111008

10121009
if (tc_result == TC_FLAKY) {
1013-
TC_SUMMARY_PRINT(" - %s - [%s.%s] - (Failed %d of %d attempts)"
1014-
" - duration = %u.%03u seconds\n",
1015-
TC_RESULT_TO_STR(tc_result),
1016-
test->test_suite_name, test->name,
1017-
test->stats->run_count - test->stats->pass_count,
1018-
test->stats->run_count,
1019-
test->stats->duration_worst_ms / 1000,
1020-
test->stats->duration_worst_ms % 1000);
1010+
TC_SUMMARY_PRINT(
1011+
" - %s - [%s.%s] - (Failed %d of %d attempts)"
1012+
" - duration = %u.%03u seconds\n",
1013+
TC_RESULT_TO_STR(tc_result), test->test_suite_name, test->name,
1014+
test->stats->run_count - test->stats->pass_count,
1015+
test->stats->run_count, test->stats->duration_worst_ms / 1000,
1016+
test->stats->duration_worst_ms % 1000);
10211017
} else {
10221018
TC_SUMMARY_PRINT(" - %s - [%s.%s] duration = %u.%03u seconds\n",
1023-
TC_RESULT_TO_STR(tc_result),
1024-
test->test_suite_name, test->name,
1025-
test->stats->duration_worst_ms / 1000,
1026-
test->stats->duration_worst_ms % 1000);
1019+
TC_RESULT_TO_STR(tc_result), test->test_suite_name,
1020+
test->name, test->stats->duration_worst_ms / 1000,
1021+
test->stats->duration_worst_ms % 1000);
10271022
}
10281023

10291024
if (flush_frequency % 3 == 0) {
@@ -1057,8 +1052,8 @@ static void __ztest_show_suite_summary(void)
10571052
flush_log();
10581053
}
10591054

1060-
static int __ztest_run_test_suite(struct ztest_suite_node *ptr,
1061-
const void *state, bool shuffle, int suite_iter, int case_iter)
1055+
static int __ztest_run_test_suite(struct ztest_suite_node *ptr, const void *state, bool shuffle,
1056+
int suite_iter, int case_iter)
10621057
{
10631058
struct ztest_suite_stats *stats = ptr->stats;
10641059
int count = 0;
@@ -1100,26 +1095,26 @@ int z_impl_ztest_run_test_suites(const void *state, bool shuffle, int suite_iter
11001095
__ztest_init_unit_test_result_for_suite(suites_to_run[i]);
11011096
}
11021097
for (size_t i = 0; i < ZTEST_SUITE_COUNT; ++i) {
1103-
count += __ztest_run_test_suite(suites_to_run[i],
1104-
state, shuffle, suite_iter, case_iter);
1098+
count += __ztest_run_test_suite(suites_to_run[i], state, shuffle, suite_iter,
1099+
case_iter);
11051100
/* Stop running tests if we have a critical error or if we have a failure and
11061101
* FAIL_FAST was set
11071102
*/
11081103
if (test_status == ZTEST_STATUS_CRITICAL_ERROR ||
1109-
(test_status == ZTEST_STATUS_HAS_FAILURE && FAIL_FAST)) {
1104+
(test_status == ZTEST_STATUS_HAS_FAILURE && FAIL_FAST)) {
11101105
break;
11111106
}
11121107
}
11131108
#else
11141109
for (struct ztest_suite_node *ptr = _ztest_suite_node_list_start;
1115-
ptr < _ztest_suite_node_list_end; ++ptr) {
1110+
ptr < _ztest_suite_node_list_end; ++ptr) {
11161111
__ztest_init_unit_test_result_for_suite(ptr);
11171112
count += __ztest_run_test_suite(ptr, state, shuffle, suite_iter, case_iter);
11181113
/* Stop running tests if we have a critical error or if we have a failure and
11191114
* FAIL_FAST was set
11201115
*/
11211116
if (test_status == ZTEST_STATUS_CRITICAL_ERROR ||
1122-
(test_status == ZTEST_STATUS_HAS_FAILURE && FAIL_FAST)) {
1117+
(test_status == ZTEST_STATUS_HAS_FAILURE && FAIL_FAST)) {
11231118
break;
11241119
}
11251120
}
@@ -1274,8 +1269,8 @@ static int cmd_shuffle(const struct shell *sh, size_t argc, char **argv)
12741269
struct getopt_state *state;
12751270
int opt;
12761271
static struct option long_options[] = {{"suite_iter", required_argument, 0, 's'},
1277-
{"case_iter", required_argument, 0, 'c'},
1278-
{0, 0, 0, 0}};
1272+
{"case_iter", required_argument, 0, 'c'},
1273+
{0, 0, 0, 0}};
12791274
int opt_index = 0;
12801275
int val;
12811276
int opt_num = 0;
@@ -1290,7 +1285,7 @@ static int cmd_shuffle(const struct shell *sh, size_t argc, char **argv)
12901285
val = atoi(state->optarg);
12911286
if (val < 1) {
12921287
shell_fprintf(sh, SHELL_ERROR,
1293-
"Invalid number of suite interations\n");
1288+
"Invalid number of suite interations\n");
12941289
return -ENOEXEC;
12951290
}
12961291
suite_iter = val;
@@ -1300,15 +1295,15 @@ static int cmd_shuffle(const struct shell *sh, size_t argc, char **argv)
13001295
val = atoi(state->optarg);
13011296
if (val < 1) {
13021297
shell_fprintf(sh, SHELL_ERROR,
1303-
"Invalid number of case interations\n");
1298+
"Invalid number of case interations\n");
13041299
return -ENOEXEC;
13051300
}
13061301
case_iter = val;
13071302
opt_num++;
13081303
break;
13091304
default:
1310-
shell_fprintf(sh, SHELL_ERROR,
1311-
"Invalid option or option usage: %s\n", argv[opt_index + 1]);
1305+
shell_fprintf(sh, SHELL_ERROR, "Invalid option or option usage: %s\n",
1306+
argv[opt_index + 1]);
13121307
return -ENOEXEC;
13131308
}
13141309
}
@@ -1327,11 +1322,11 @@ static int cmd_run_suite(const struct shell *sh, size_t argc, char **argv)
13271322
ztest_set_test_args(argv[1]);
13281323

13291324
for (struct ztest_suite_node *ptr = _ztest_suite_node_list_start;
1330-
ptr < _ztest_suite_node_list_end; ++ptr) {
1325+
ptr < _ztest_suite_node_list_end; ++ptr) {
13311326
__ztest_init_unit_test_result_for_suite(ptr);
13321327
count += __ztest_run_test_suite(ptr, NULL, shuffle, 1, 1);
13331328
if (test_status == ZTEST_STATUS_CRITICAL_ERROR ||
1334-
(test_status == ZTEST_STATUS_HAS_FAILURE && FAIL_FAST)) {
1329+
(test_status == ZTEST_STATUS_HAS_FAILURE && FAIL_FAST)) {
13351330
break;
13361331
}
13371332
}
@@ -1357,8 +1352,7 @@ static const struct ztest_suite_node *suite_lookup(size_t idx, const char *prefi
13571352

13581353
while (suite < suite_end) {
13591354
if ((suite->name != NULL) && (strlen(suite->name) != 0) &&
1360-
((prefix == NULL) ||
1361-
(strncmp(prefix, suite->name, strlen(prefix)) == 0))) {
1355+
((prefix == NULL) || (strncmp(prefix, suite->name, strlen(prefix)) == 0))) {
13621356
if (match_idx == idx) {
13631357
return suite;
13641358
}
@@ -1380,6 +1374,7 @@ static void testsuite_list_get(size_t idx, struct shell_static_entry *entry)
13801374
entry->subcmd = NULL;
13811375
}
13821376

1377+
/* clang-format off */
13831378
SHELL_STATIC_SUBCMD_SET_CREATE(
13841379
sub_ztest_cmds,
13851380
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)
13961391
SHELL_CMD_ARG(run-testcase, NULL, "Run testcase", cmd_run_suite, 2, 0),
13971392
SHELL_SUBCMD_SET_END /* Array terminated. */
13981393
);
1394+
/* clang-format on */
13991395

14001396
SHELL_CMD_REGISTER(ztest, &sub_ztest_cmds, "Ztest commands", NULL);
14011397
#endif /* CONFIG_ZTEST_SHELL */

0 commit comments

Comments
 (0)