From bf8c01d44d0849f40a5a212679315c6f5d84d690 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 13 Aug 2022 18:53:22 +0200 Subject: user/tests: basic memset test --- src/user/app/tests/libc/string.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src') 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 +#include #include 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); } -- cgit v1.2.3