diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/commonlib/bsd/Makefile.mk | 4 | ||||
-rw-r--r-- | tests/commonlib/bsd/string-test.c | 38 | ||||
-rw-r--r-- | tests/lib/string-test.c | 26 |
3 files changed, 42 insertions, 26 deletions
diff --git a/tests/commonlib/bsd/Makefile.mk b/tests/commonlib/bsd/Makefile.mk index 3de223e707..ee710bcdb9 100644 --- a/tests/commonlib/bsd/Makefile.mk +++ b/tests/commonlib/bsd/Makefile.mk @@ -3,6 +3,7 @@ tests-y += helpers-test tests-y += gcd-test tests-y += ipchksum-test +tests-y += string-test helpers-test-srcs += tests/commonlib/bsd/helpers-test.c @@ -11,3 +12,6 @@ gcd-test-srcs += src/commonlib/bsd/gcd.c ipchksum-test-srcs += tests/commonlib/bsd/ipchksum-test.c ipchksum-test-srcs += src/commonlib/bsd/ipchksum.c + +string-test-srcs += tests/commonlib/bsd/string-test.c +string-test-srcs += src/commonlib/bsd/string.c diff --git a/tests/commonlib/bsd/string-test.c b/tests/commonlib/bsd/string-test.c new file mode 100644 index 0000000000..d94b82e18c --- /dev/null +++ b/tests/commonlib/bsd/string-test.c @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <commonlib/bsd/string.h> +#include <tests/test.h> + +/* Used to test skip_atoi */ +struct str_with_u_val_t { + char *str; + uint32_t value; + uint32_t offset; +} str_with_u_val[] = { + {"42aa", 42, 2}, + {"a", 0, 0}, + {"0", 0, 1}, + {"4a2", 4, 1}, +}; + +static void test_skip_atoi(void **state) +{ + int i; + char *ptr, *copy; + + for (i = 0; i < ARRAY_SIZE(str_with_u_val); i++) { + ptr = str_with_u_val[i].str; + copy = ptr; + assert_true(str_with_u_val[i].value == skip_atoi(&ptr)); + assert_int_equal(str_with_u_val[i].offset, ptr - copy); + } +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_skip_atoi), + }; + + return cb_run_group_tests(tests, NULL, NULL); +} diff --git a/tests/lib/string-test.c b/tests/lib/string-test.c index 621a74ceff..17bb69ab56 100644 --- a/tests/lib/string-test.c +++ b/tests/lib/string-test.c @@ -43,18 +43,6 @@ struct str_with_l_val_t { {"\t\n\r\f\v-42", -42}, }; -/* Used to test skip_atoi */ -struct str_with_u_val_t { - char *str; - uint32_t value; - uint32_t offset; -} str_with_u_val[] = { - {"42aa", 42, 2}, - {"a", 0, 0}, - {"0", 0, 1}, - {"4a2", 4, 1}, -}; - static void test_strdup(void **state) { char str[] = "Hello coreboot\n"; @@ -204,19 +192,6 @@ static void test_strncmp(void **state) assert_int_equal(0, strncmp(str, str2, str2_len - 1)); } -static void test_skip_atoi(void **state) -{ - int i; - char *ptr, *copy; - - for (i = 0; i < ARRAY_SIZE(str_with_u_val); i++) { - ptr = str_with_u_val[i].str; - copy = ptr; - assert_true(str_with_u_val[i].value == skip_atoi(&ptr)); - assert_int_equal(str_with_u_val[i].offset, ptr - copy); - } -} - static void test_strspn(void **state) { char str[] = "4213401234"; @@ -260,7 +235,6 @@ int main(void) cmocka_unit_test(test_strcpy), cmocka_unit_test(test_strcmp), cmocka_unit_test(test_strncmp), - cmocka_unit_test(test_skip_atoi), cmocka_unit_test(test_strspn), cmocka_unit_test(test_strcspn), cmocka_unit_test(test_atol), |