1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 
9 #include "bs_tracing.h"
10 #include "bstests.h"
11 #include "babblekit/testcase.h"
12 #include "testlib/log_utils.h"
13 
14 extern void entrypoint_dut(void);
15 extern void entrypoint_peer(void);
16 extern enum bst_result_t bst_result;
17 
18 unsigned long runtime_log_level = LOG_LEVEL_INF;
19 
test_args(int argc,char * argv[])20 static void test_args(int argc, char *argv[])
21 {
22 	size_t argn = 0;
23 	const char *arg = argv[argn];
24 
25 	if (strcmp(arg, "log_level") == 0) {
26 
27 		runtime_log_level = strtoul(argv[++argn], NULL, 10);
28 
29 		if (runtime_log_level >= LOG_LEVEL_NONE &&
30 			runtime_log_level <= LOG_LEVEL_DBG){
31 			TEST_PRINT("Runtime log level configuration: %d", runtime_log_level);
32 		} else {
33 			TEST_FAIL("Invalid arguments to set log level: %d", runtime_log_level);
34 		}
35 	} else {
36 		TEST_PRINT("Default runtime log level configuration: INFO");
37 	}
38 }
39 
test_end_cb(void)40 static void test_end_cb(void)
41 {
42 	/* This callback will fire right before the executable returns
43 	 *
44 	 * You can use it to print test or system state that would be of use for
45 	 * debugging why the test fails.
46 	 * Here we just print a dummy string for demonstration purposes.
47 	 *
48 	 * Can also be used to trigger a `k_oops` which will halt the image if
49 	 * running under a debugger, if `CONFIG_ARCH_POSIX_TRAP_ON_FATAL=y`.
50 	 */
51 	static const char demo_state[] = "My interesting state";
52 
53 	if (bst_result != Passed) {
54 		TEST_PRINT("Test has not passed. State: %s", demo_state);
55 	}
56 }
57 
58 static const struct bst_test_instance entrypoints[] = {
59 	{
60 		.test_id = "dut",
61 		.test_delete_f = test_end_cb,
62 		.test_main_f = entrypoint_dut,
63 		.test_args_f = test_args,
64 	},
65 	{
66 		.test_id = "peer",
67 		.test_delete_f = test_end_cb,
68 		.test_main_f = entrypoint_peer,
69 		.test_args_f = test_args,
70 	},
71 	BSTEST_END_MARKER,
72 };
73 
install(struct bst_test_list * tests)74 static struct bst_test_list *install(struct bst_test_list *tests)
75 {
76 	return bst_add_tests(tests, entrypoints);
77 };
78 
79 bst_test_install_t test_installers[] = {install, NULL};
80 
main(void)81 int main(void)
82 {
83 	bst_main();
84 
85 	return 0;
86 }
87