]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - test/str_ut.c
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2020 Google LLC
8 #include <test/suites.h>
12 /* This is large enough for any of the test strings */
13 #define TEST_STR_SIZE 200
15 static const char str1
[] = "I'm sorry I'm late.";
16 static const char str2
[] = "1099abNo, don't bother apologising.";
17 static const char str3
[] = "0xbI'm sorry you're alive.";
19 /* Declare a new str test */
20 #define STR_TEST(_name, _flags) UNIT_TEST(_name, _flags, str_test)
22 static int run_strtoul(struct unit_test_state
*uts
, const char *str
, int base
,
23 ulong expect_val
, int expect_endp_offset
)
28 val
= simple_strtoul(str
, &endp
, base
);
29 ut_asserteq(expect_val
, val
);
30 ut_asserteq(expect_endp_offset
, endp
- str
);
35 static int str_simple_strtoul(struct unit_test_state
*uts
)
37 /* Base 10 and base 16 */
38 ut_assertok(run_strtoul(uts
, str2
, 10, 1099, 4));
39 ut_assertok(run_strtoul(uts
, str2
, 16, 0x1099ab, 6));
42 ut_assertok(run_strtoul(uts
, str1
, 10, 0, 0));
45 ut_assertok(run_strtoul(uts
, str1
, 0, 0, 0));
46 ut_assertok(run_strtoul(uts
, str2
, 0, 1099, 4));
47 ut_assertok(run_strtoul(uts
, str3
, 0, 0xb, 3));
50 ut_assertok(run_strtoul(uts
, str1
, 2, 0, 0));
51 ut_assertok(run_strtoul(uts
, str2
, 2, 2, 2));
53 /* Check endp being NULL */
54 ut_asserteq(1099, simple_strtoul(str2
, NULL
, 0));
58 STR_TEST(str_simple_strtoul
, 0);
60 int do_ut_str(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *const argv
[])
62 struct unit_test
*tests
= ll_entry_start(struct unit_test
,
64 const int n_ents
= ll_entry_count(struct unit_test
, str_test
);
66 return cmd_ut_category("str", "str_", tests
, n_ents
, argc
, argv
);