diff options
Diffstat (limited to 'test/lib')
| -rw-r--r-- | test/lib/lmb.c | 12 | ||||
| -rw-r--r-- | test/lib/string.c | 24 |
2 files changed, 31 insertions, 5 deletions
diff --git a/test/lib/lmb.c b/test/lib/lmb.c index b6259bef442..168c66ae649 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -477,7 +477,7 @@ static int lib_test_lmb_at_0(struct unit_test_state *uts) 0, 0, 0, 0); /* check that this was an error by freeing b */ ret = lmb_free(b, 4, LMB_NONE); - ut_asserteq(ret, -1); + ut_asserteq(ret, -EFAULT); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, ram_size - 4, 0, 0, 0, 0); @@ -779,11 +779,19 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram) /* check that allocating outside memory fails */ if (ram_end != 0) { ret = lmb_alloc_addr(ram_end, 1, LMB_NONE); + ut_asserteq(ret, -EFAULT); + ret = lmb_alloc_addr(ram_end - 1, 2, LMB_NOMAP); + ut_asserteq(ret, -EINVAL); + ret = lmb_alloc_addr(ram_end - 1, 2, LMB_NOOVERWRITE); ut_asserteq(ret, -EINVAL); } if (ram != 0) { ret = lmb_alloc_addr(ram - 1, 1, LMB_NONE); - ut_asserteq(ret, -EINVAL); + ut_asserteq(ret, -EFAULT); + ret = lmb_alloc_addr(ram - 1, 2, LMB_NOMAP); + ut_asserteq(ret, -EEXIST); + ret = lmb_alloc_addr(ram - 1, 2, LMB_NOOVERWRITE); + ut_asserteq(ret, -EEXIST); } lmb_pop(&store); diff --git a/test/lib/string.c b/test/lib/string.c index db6f28dbfdf..d418a40c4d4 100644 --- a/test/lib/string.c +++ b/test/lib/string.c @@ -284,18 +284,36 @@ static int lib_strstr(struct unit_test_state *uts) { const char *s1 = "Itsy Bitsy Teenie Weenie"; const char *s2 = "eenie"; - const char *s3 = "easy"; + const char *s3 = "bits"; ut_asserteq_ptr(&s1[12], strstr(s1, s2)); ut_asserteq_ptr(&s1[13], strstr(&s1[3], &s2[1])); ut_assertnull(strstr(s1, s3)); - ut_asserteq_ptr(&s1[2], strstr(s1, &s3[2])); - ut_asserteq_ptr(&s1[8], strstr(&s1[5], &s3[2])); + ut_asserteq_ptr(&s1[1], strstr(s1, &s3[2])); + ut_asserteq_ptr(&s1[7], strstr(&s1[5], &s3[2])); return 0; } LIB_TEST(lib_strstr, 0); +/** lib_strcasestr() - unit test for strcasestr() */ +static int lib_strcasestr(struct unit_test_state *uts) +{ + const char *s1 = "Itsy Bitsy Teenie Weenie"; + const char *s2 = "eenie"; + const char *s3 = "bits"; + + ut_asserteq_ptr(&s1[12], strcasestr(s1, s2)); + ut_asserteq_ptr(&s1[13], strcasestr(&s1[3], &s2[1])); + ut_asserteq_ptr(&s1[5], strcasestr(s1, s3)); + ut_asserteq_ptr(&s1[1], strcasestr(s1, &s3[2])); + ut_asserteq_ptr(&s1[7], strcasestr(&s1[5], &s3[2])); + ut_assertnull(strcasestr(&s1[6], s3)); + + return 0; +} +LIB_TEST(lib_strcasestr, 0); + static int lib_strim(struct unit_test_state *uts) { char buf[BUFLEN], *p; |
