1 /*
2  * Copyright (c) 2018 Oticon A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include <zephyr/kernel.h>
7 #include "bs_types.h"
8 #include "bs_tracing.h"
9 #include "time_machine.h"
10 #include "bstests.h"
11 
12 /*
13  * This is just a demo of the test framework facilities
14  */
15 
16 extern enum bst_result_t bst_result;
17 
test_empty_init(void)18 static void test_empty_init(void)
19 {
20 	bst_ticker_set_next_tick_absolute(500e3);
21 	bst_result = In_progress;
22 }
23 
test_empty_tick(bs_time_t HW_device_time)24 static void test_empty_tick(bs_time_t HW_device_time)
25 {
26 
27 	bst_result = Failed;
28 	bs_trace_error_line("test: empty demo test finished "
29 			    "(failed as it should be)\n");
30 
31 }
32 
test_empty_thread(void * p1,void * p2,void * p3)33 static void test_empty_thread(void *p1, void *p2, void *p3)
34 {
35 	int i = 0;
36 
37 	while (1) {
38 		printk("A silly demo thread. Iteration %i\n", i++);
39 		k_sleep(K_MSEC(100));
40 	}
41 }
42 
43 static K_THREAD_STACK_DEFINE(stack_te,
44 			     CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE);
45 static struct k_thread test_thread_thread;
46 
test_main(void)47 static void test_main(void)
48 {
49 
50 	bs_trace_raw_time(3, "Empty test main called\n");
51 
52 	k_thread_create(&test_thread_thread, stack_te,
53 			CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE,
54 			test_empty_thread, NULL, NULL, NULL,
55 			0, 0, K_NO_WAIT);
56 }
57 
58 static const struct bst_test_instance test_def[] = {
59 	{
60 		.test_id = "empty",
61 		.test_descr = "demo empty test (it just fails after 500ms)",
62 		.test_post_init_f = test_empty_init,
63 		.test_tick_f = test_empty_tick,
64 		.test_main_f = test_main
65 	},
66 	BSTEST_END_MARKER
67 };
68 
test_empty_install(struct bst_test_list * tests)69 struct bst_test_list *test_empty_install(struct bst_test_list *tests)
70 {
71 	return bst_add_tests(tests, test_def);
72 }
73