diff options
author | dzwdz | 2022-08-13 18:53:22 +0200 |
---|---|---|
committer | dzwdz | 2022-08-13 18:53:22 +0200 |
commit | bf8c01d44d0849f40a5a212679315c6f5d84d690 (patch) | |
tree | 7ce6562837c69bb7cf0d82add6c202fa431bc61c /src/user/app/tests/libc/string.c | |
parent | 822ff022ba9caf03c26bd9260d1db3869018211b (diff) |
user/tests: basic memset test
Diffstat (limited to 'src/user/app/tests/libc/string.c')
-rw-r--r-- | src/user/app/tests/libc/string.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/user/app/tests/libc/string.c b/src/user/app/tests/libc/string.c index 82aff98..53fe1c0 100644 --- a/src/user/app/tests/libc/string.c +++ b/src/user/app/tests/libc/string.c @@ -1,4 +1,6 @@ #include "../tests.h" +#include <stdbool.h> +#include <stdlib.h> #include <string.h> static void test_memcmp(void) { @@ -19,6 +21,23 @@ static void test_memcmp(void) { test(0 < memcmp("654", "555", 3)); } +static bool memall(const unsigned char *s, unsigned char c, size_t n) { + for (size_t i = 0; i < n; i++) + if (s[i] != c) return false; + return true; +} + +static void test_memset(void) { + const size_t buflen = 4096; + void *buf = malloc(buflen); + test(buf); + for (int i = 0; i < 257; i++) { + memset(buf, i, buflen); + test(memall(buf, i & 0xff, buflen)); + } + free(buf); +} + static void test_strcmp(void) { test(0 == strcmp("string", "string")); test(0 > strcmp("str", "string")); @@ -48,6 +67,7 @@ static void test_strtol(void) { void r_libc_string(void) { run_test(test_memcmp); + run_test(test_memset); run_test(test_strcmp); run_test(test_strtol); } |