diff options
author | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-06-24 13:20:19 +1000 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-06-24 13:20:19 +1000 |
commit | 82d60cae3f53317dc7a3e84de00656bdd03a504a (patch) | |
tree | 12b8dbec0fef411ca7cb6e747022c8e65ee3956f | |
parent | 114b3a23cfb21b18fb98888e1c97e7046efc2f8b (diff) | |
download | skiboot-82d60cae3f53317dc7a3e84de00656bdd03a504a.zip skiboot-82d60cae3f53317dc7a3e84de00656bdd03a504a.tar.gz skiboot-82d60cae3f53317dc7a3e84de00656bdd03a504a.tar.bz2 |
add tests for libc memchr
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r-- | libc/test/run-memops-test.c | 6 | ||||
-rw-r--r-- | libc/test/run-memops.c | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/libc/test/run-memops-test.c b/libc/test/run-memops-test.c index 429cfdc..7212d76 100644 --- a/libc/test/run-memops-test.c +++ b/libc/test/run-memops-test.c @@ -44,6 +44,7 @@ #include <stdlib.h> int test_memset(char* buf, int c, size_t s); +int test_memchr(const void *ptr, int c, size_t n, void* expected); int test_memset(char* buf, int c, size_t s) { @@ -57,3 +58,8 @@ int test_memset(char* buf, int c, size_t s) return r; } + +int test_memchr(const void *ptr, int c, size_t n, void* expected) +{ + return(expected == memchr(ptr, c, n)); +} diff --git a/libc/test/run-memops.c b/libc/test/run-memops.c index 80822df..cc107f7 100644 --- a/libc/test/run-memops.c +++ b/libc/test/run-memops.c @@ -22,6 +22,7 @@ #include <stdio.h> int test_memset(char* buf, int c, size_t s); +int test_memchr(const void *ptr, int c, size_t n, void* expected); int main(void) { @@ -40,5 +41,11 @@ int main(void) assert(test_memset(buf, 0, 1024) == 0); free(buf); + buf = malloc(20); + strncpy(buf, "Hello World!", 20); + assert(test_memchr(buf, 'o', strlen(buf), buf+4)); + assert(test_memchr(buf, 'a', strlen(buf), NULL)); + free(buf); + return 0; } |