1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/ztest.h>
8 
9 #ifdef CONFIG_SOC_FOLDER_TEST_STRING
10 #define STRING_OUTPUT CONFIG_SOC_FOLDER_TEST_STRING
11 #else
12 #error "Invalid test configuration"
13 #endif
14 
15 #ifndef CONFIG_TEST_TYPE
16 #error "Invalid test configuration"
17 #endif
18 
19 #ifdef CONFIG_SOC_FOLDER_TEST_INCLUDE_BOARD
20 #define INCLUDED_BOARD 1
21 #else
22 #define INCLUDED_BOARD 0
23 #endif
24 
25 #ifdef CONFIG_SOC_FOLDER_TEST_INCLUDE_BOARD_SUFFIX
26 #define INCLUDED_BOARD_SUFFIX 1
27 #else
28 #define INCLUDED_BOARD_SUFFIX 0
29 #endif
30 
31 #ifdef CONFIG_SOC_FOLDER_TEST_INCLUDE_BOARD_QUALIFIERS
32 #define INCLUDED_BOARD_QUALIFIERS 1
33 #else
34 #define INCLUDED_BOARD_QUALIFIERS 0
35 #endif
36 
37 #ifdef CONFIG_SOC_FOLDER_TEST_INCLUDE_BOARD_OTHER
38 #define INCLUDED_BOARD_OTHER 1
39 #else
40 #define INCLUDED_BOARD_OTHER 0
41 #endif
42 
43 #ifdef CONFIG_SOC_FOLDER_TEST_INCLUDE_SOC
44 #define INCLUDED_SOC 1
45 #else
46 #define INCLUDED_SOC 0
47 #endif
48 
49 #ifdef CONFIG_SOC_FOLDER_TEST_INCLUDE_SOC_SUFFIX
50 #define INCLUDED_SOC_SUFFIX 1
51 #else
52 #define INCLUDED_SOC_SUFFIX 0
53 #endif
54 
55 #ifdef CONFIG_SOC_FOLDER_TEST_INCLUDE_SOC_OTHER
56 #define INCLUDED_SOC_OTHER 1
57 #else
58 #define INCLUDED_SOC_OTHER 0
59 #endif
60 
61 #if CONFIG_TEST_TYPE == 0
62 /* Default test */
ZTEST(soc_folder_kconfig,test_default)63 ZTEST(soc_folder_kconfig, test_default)
64 {
65 	zassert_false(INCLUDED_BOARD_SUFFIX, "Did not expect board suffix config to be present");
66 
67 #ifdef CONFIG_BOARD_NATIVE_SIM_NATIVE_64
68 	zassert_false(INCLUDED_BOARD, "Did not expect board config to be present");
69 	zassert_true(INCLUDED_BOARD_QUALIFIERS, "Expected board qualifier config to be present");
70 	zassert_mem_equal(STRING_OUTPUT, "five", strlen("five"), "Expected string to match");
71 #else
72 	zassert_true(INCLUDED_BOARD, "Expected board config to be present");
73 	zassert_false(INCLUDED_BOARD_QUALIFIERS,
74 		      "Did not expect board qualifier config to be present");
75 	zassert_mem_equal(STRING_OUTPUT, "two", strlen("two"), "Expected string to match");
76 #endif
77 
78 	zassert_false(INCLUDED_BOARD_OTHER, "Did not expect board other config to be present");
79 	zassert_true(INCLUDED_SOC, "Expect soc config to be present");
80 	zassert_false(INCLUDED_SOC_SUFFIX, "Did not expect soc suffix config to be present");
81 	zassert_false(INCLUDED_SOC_OTHER, "Did not expect soc other config to be present");
82 }
83 #elif CONFIG_TEST_TYPE == 1
84 /* File suffix test */
ZTEST(soc_folder_kconfig,test_suffix)85 ZTEST(soc_folder_kconfig, test_suffix)
86 {
87 	zassert_true(INCLUDED_BOARD_SUFFIX, "Expected board suffix config to be present");
88 
89 	zassert_false(INCLUDED_BOARD, "Did not expect board config to be present");
90 	zassert_false(INCLUDED_BOARD_QUALIFIERS,
91 		      "Did not expect board qualifier config to be present");
92 	zassert_mem_equal(STRING_OUTPUT, "four", strlen("four"), "Expected string to match");
93 	zassert_false(INCLUDED_BOARD_OTHER, "Did not expect board other config to be present");
94 	zassert_false(INCLUDED_SOC, "Did not expect soc config to be present");
95 	zassert_true(INCLUDED_SOC_SUFFIX, "Expected soc suffix config to be present");
96 	zassert_false(INCLUDED_SOC_OTHER, "Did not expect soc other config to be present");
97 }
98 #elif CONFIG_TEST_TYPE == 2
99 /* Conf file test */
ZTEST(soc_folder_kconfig,test_conf)100 ZTEST(soc_folder_kconfig, test_conf)
101 {
102 	zassert_false(INCLUDED_BOARD_SUFFIX, "Did not expect board suffix config to be present");
103 
104 #ifdef CONFIG_BOARD_NATIVE_SIM_NATIVE_64
105 	zassert_false(INCLUDED_BOARD, "Did not expect board config to be present");
106 	zassert_true(INCLUDED_BOARD_QUALIFIERS,
107 		     "Expected board qualifier config to be present");
108 #else
109 	zassert_true(INCLUDED_BOARD, "Expected board config to be present");
110 	zassert_false(INCLUDED_BOARD_QUALIFIERS,
111 		     "Did not expect board qualifier config to be present");
112 #endif
113 
114 	zassert_mem_equal(STRING_OUTPUT, "three", strlen("three"), "Expected string to match");
115 
116 	zassert_true(INCLUDED_BOARD_OTHER, "Expected board other config to be present");
117 	zassert_true(INCLUDED_SOC, "Expected soc config to be present");
118 	zassert_false(INCLUDED_SOC_SUFFIX, "Did not expect soc suffix config to be present");
119 	zassert_false(INCLUDED_SOC_OTHER, "Did not expect soc other config to be present");
120 }
121 #elif CONFIG_TEST_TYPE == 3
122 /* File suffix and conf file test */
ZTEST(soc_folder_kconfig,test_suffix_conf)123 ZTEST(soc_folder_kconfig, test_suffix_conf)
124 {
125 	zassert_true(INCLUDED_BOARD_SUFFIX, "Expected board suffix config to be present");
126 	zassert_false(INCLUDED_BOARD, "Did not expect board config to be present");
127 	zassert_false(INCLUDED_BOARD_QUALIFIERS,
128 		      "Did not expect board qualifier config to be present");
129 	zassert_mem_equal(STRING_OUTPUT, "three", strlen("three"), "Expected string to match");
130 	zassert_true(INCLUDED_BOARD_OTHER, "Expected board other config to be present");
131 	zassert_false(INCLUDED_SOC, "Did not expect soc config to be present");
132 	zassert_true(INCLUDED_SOC_SUFFIX, "Expected soc suffix config to be present");
133 	zassert_false(INCLUDED_SOC_OTHER, "Did not expect soc other config to be present");
134 }
135 #else
136 #error "Invalid test type"
137 #endif
138 
139 ZTEST_SUITE(soc_folder_kconfig, NULL, NULL, NULL, NULL, NULL);
140