Skip to content

Commit 1772dc2

Browse files
Jordan Yatescarlescufi
authored andcommitted
tests: devicetree: api: new STRING_TOKEN macros
Add tests for the new `STRING_TOKEN` macros. Signed-off-by: Jordan Yates <[email protected]>
1 parent f2b8a99 commit 1772dc2

File tree

1 file changed

+72
-14
lines changed
  • tests/lib/devicetree/api/src

1 file changed

+72
-14
lines changed

tests/lib/devicetree/api/src/main.c

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,40 +2220,98 @@ static void test_string_token(void)
22202220
token_zero,
22212221
token_one,
22222222
token_two,
2223-
token_max,
22242223
token_no_inst,
22252224
};
2225+
enum {
2226+
TOKEN_ZERO = token_no_inst + 1,
2227+
TOKEN_ONE,
2228+
TOKEN_TWO,
2229+
TOKEN_NO_INST,
2230+
};
22262231
int i;
22272232

2228-
/* Test DT_INST_STRING_TOKEN_OR when property is found */
2233+
/* Test DT_INST_STRING_TOKEN */
2234+
#define STRING_TOKEN_TEST_INST_EXPANSION(inst) \
2235+
DT_INST_STRING_TOKEN(inst, val),
22292236
int array_inst[] = {
2230-
#define STRING_TOKEN_TEST_INST_EXPANSION(inst) \
2231-
DT_INST_STRING_TOKEN_OR(inst, val, token_no_inst),
2232-
DT_INST_FOREACH_STATUS_OKAY(STRING_TOKEN_TEST_INST_EXPANSION)
2237+
DT_INST_FOREACH_STATUS_OKAY(STRING_TOKEN_TEST_INST_EXPANSION)
22332238
};
22342239

22352240
for (i = 0; i < ARRAY_SIZE(array_inst); i++) {
2236-
zassert_true(array_inst[i] != token_no_inst, "");
2241+
zassert_between_inclusive(array_inst[i], token_zero, token_two, "");
2242+
}
2243+
2244+
/* Test DT_INST_STRING_UPPER_TOKEN */
2245+
#define STRING_UPPER_TOKEN_TEST_INST_EXPANSION(inst) \
2246+
DT_INST_STRING_UPPER_TOKEN(inst, val),
2247+
int array_inst_upper[] = {
2248+
DT_INST_FOREACH_STATUS_OKAY(STRING_UPPER_TOKEN_TEST_INST_EXPANSION)
2249+
};
2250+
2251+
for (i = 0; i < ARRAY_SIZE(array_inst_upper); i++) {
2252+
zassert_between_inclusive(array_inst_upper[i], TOKEN_ZERO, TOKEN_TWO, "");
2253+
}
2254+
2255+
/* Test DT_INST_STRING_TOKEN_OR when property is found */
2256+
#define STRING_TOKEN_OR_TEST_INST_EXPANSION(inst) \
2257+
DT_INST_STRING_TOKEN_OR(inst, val, token_no_inst),
2258+
int array_inst_or[] = {
2259+
DT_INST_FOREACH_STATUS_OKAY(STRING_TOKEN_OR_TEST_INST_EXPANSION)
2260+
};
2261+
2262+
for (i = 0; i < ARRAY_SIZE(array_inst_or); i++) {
2263+
zassert_between_inclusive(array_inst_or[i], token_zero, token_two, "");
2264+
}
2265+
2266+
/* Test DT_INST_STRING_UPPER_TOKEN_OR when property is found */
2267+
#define STRING_UPPER_TOKEN_OR_TEST_INST_EXPANSION(inst) \
2268+
DT_INST_STRING_UPPER_TOKEN_OR(inst, val, TOKEN_NO_INST),
2269+
int array_inst_upper_or[] = {
2270+
DT_INST_FOREACH_STATUS_OKAY(STRING_UPPER_TOKEN_OR_TEST_INST_EXPANSION)
2271+
};
2272+
2273+
for (i = 0; i < ARRAY_SIZE(array_inst_upper_or); i++) {
2274+
zassert_between_inclusive(array_inst_upper_or[i], TOKEN_ZERO, TOKEN_TWO, "");
22372275
}
22382276

22392277
/* Test DT_STRING_TOKEN_OR when property is found */
22402278
zassert_equal(DT_STRING_TOKEN_OR(DT_NODELABEL(test_string_token_0),
2241-
val, token_one), token_zero, "");
2279+
val, token_one), token_zero, "");
22422280
zassert_equal(DT_STRING_TOKEN_OR(DT_NODELABEL(test_string_token_1),
2243-
val, token_two), token_one, "");
2281+
val, token_two), token_one, "");
22442282

22452283
/* Test DT_STRING_TOKEN_OR is not found */
22462284
zassert_equal(DT_STRING_TOKEN_OR(DT_NODELABEL(test_string_token_1),
2247-
no_inst, token_zero), token_zero, "");
2285+
no_inst, token_zero), token_zero, "");
2286+
2287+
/* Test DT_STRING_UPPER_TOKEN_OR when property is found */
2288+
zassert_equal(DT_STRING_UPPER_TOKEN_OR(DT_NODELABEL(test_string_token_0),
2289+
val, TOKEN_ONE), TOKEN_ZERO, "");
2290+
zassert_equal(DT_STRING_UPPER_TOKEN_OR(DT_NODELABEL(test_string_token_1),
2291+
val, TOKEN_TWO), TOKEN_ONE, "");
2292+
2293+
/* Test DT_STRING_UPPER_TOKEN_OR is not found */
2294+
zassert_equal(DT_STRING_UPPER_TOKEN_OR(DT_NODELABEL(test_string_token_1),
2295+
no_inst, TOKEN_ZERO), TOKEN_ZERO, "");
22482296

22492297
/* Test DT_INST_STRING_TOKEN_OR when property is not found */
2250-
int array_no_inst[] = {
2251-
#define STRING_TOKEN_TEST_NO_INST_EXPANSION(inst) \
2298+
#define STRING_TOKEN_TEST_NO_INST_EXPANSION(inst) \
22522299
DT_INST_STRING_TOKEN_OR(inst, no_inst, token_no_inst),
2253-
DT_INST_FOREACH_STATUS_OKAY(STRING_TOKEN_TEST_NO_INST_EXPANSION)
2300+
int array_no_inst_or[] = {
2301+
DT_INST_FOREACH_STATUS_OKAY(STRING_TOKEN_TEST_NO_INST_EXPANSION)
2302+
};
2303+
for (i = 0; i < ARRAY_SIZE(array_no_inst_or); i++) {
2304+
zassert_equal(array_no_inst_or[i], token_no_inst, "");
2305+
}
2306+
2307+
/* Test DT_INST_STRING_UPPER_TOKEN_OR when property is not found */
2308+
#define STRING_UPPER_TOKEN_TEST_NO_INST_EXPANSION(inst) \
2309+
DT_INST_STRING_UPPER_TOKEN_OR(inst, no_inst, TOKEN_NO_INST),
2310+
int array_no_inst_upper_or[] = {
2311+
DT_INST_FOREACH_STATUS_OKAY(STRING_UPPER_TOKEN_TEST_NO_INST_EXPANSION)
22542312
};
2255-
for (i = 0; i < ARRAY_SIZE(array_no_inst); i++) {
2256-
zassert_true(array_no_inst[i] == token_no_inst, "");
2313+
for (i = 0; i < ARRAY_SIZE(array_no_inst_upper_or); i++) {
2314+
zassert_equal(array_no_inst_upper_or[i], TOKEN_NO_INST, "");
22572315
}
22582316
}
22592317

0 commit comments

Comments
 (0)