aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorStewart Smith <stewart@linux.vnet.ibm.com>2015-06-24 13:59:42 +1000
committerStewart Smith <stewart@linux.vnet.ibm.com>2015-06-24 13:59:42 +1000
commit513e6b8a88df7b6f62e379886987041fa626ed34 (patch)
treea45381eebf4fd5fa1baf795cd29cfad2c9f497df /libc
parent9c7f0d09eb4850b1828720846b07433b745ba526 (diff)
downloadskiboot-513e6b8a88df7b6f62e379886987041fa626ed34.zip
skiboot-513e6b8a88df7b6f62e379886987041fa626ed34.tar.gz
skiboot-513e6b8a88df7b6f62e379886987041fa626ed34.tar.bz2
add tests for libc memmove
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libc')
-rw-r--r--libc/test/run-memops-test.c8
-rw-r--r--libc/test/run-memops.c21
2 files changed, 27 insertions, 2 deletions
diff --git a/libc/test/run-memops-test.c b/libc/test/run-memops-test.c
index a4179eb..cb2d7f8 100644
--- a/libc/test/run-memops-test.c
+++ b/libc/test/run-memops-test.c
@@ -50,6 +50,7 @@ int test_strcmp(const void *ptr1, const void *ptr2, int expected);
int test_strchr(const char *s, int c, char *expected);
int test_strcasecmp(const char *s1, const char *s2, int expected);
int test_strncasecmp(const char *s1, const char *s2, size_t n, int expected);
+int test_memmove(void *dest, const void *src, size_t n, const void *r, const void *expected, size_t expected_n);
int test_memset(char* buf, int c, size_t s)
{
@@ -93,3 +94,10 @@ int test_strncasecmp(const char *s1, const char *s2, size_t n, int expected)
{
return(expected == strncasecmp(s1, s2, n));
}
+
+int test_memmove(void *dest, const void *src, size_t n, const void *r, const void *expected, size_t expected_n)
+{
+ if (memmove(dest, src, n) != dest)
+ return -1;
+ return(memcmp(r, expected, expected_n) == 0);
+}
diff --git a/libc/test/run-memops.c b/libc/test/run-memops.c
index 21f6ab6..5c425f2 100644
--- a/libc/test/run-memops.c
+++ b/libc/test/run-memops.c
@@ -28,10 +28,12 @@ int test_strcmp(const void *ptr1, const void *ptr2, int expected);
int test_strchr(const char *s, int c, char *expected);
int test_strcasecmp(const char *s1, const char *s2, int expected);
int test_strncasecmp(const char *s1, const char *s2, size_t n, int expected);
+int test_memmove(void *dest, const void *src, size_t n, const void *r, const void *expected, size_t expected_n);
int main(void)
{
- char* buf;
+ char *buf;
+ char *buf2;
buf = malloc(100);
assert(test_memset(buf, 0x42, 100) == 0);
@@ -77,9 +79,24 @@ int main(void)
assert(test_strncasecmp(buf, "HeLLo WOrlc!", 2, 0));
assert(test_strncasecmp(buf, "HeLLp WOrlc!", 5, -1));
-
free(buf);
+ buf = malloc(20);
+ buf2 = malloc(20);
+ strncpy(buf, "Hello", 20);
+ strncpy(buf2, " World!", 20);
+
+ assert(test_memmove(buf + 5, buf2, strlen(buf2), buf,
+ "Hello World!", strlen("Hello World!")));
+
+ strncpy(buf, "HHello World!", 20);
+ assert(test_memmove(buf, buf+1, strlen("Hello World!"), buf, "Hello World!", strlen("Hello World!")));
+
+ strncpy(buf, "0123456789", 20);
+ assert(test_memmove(buf+1, buf , strlen("0123456789"), buf, "00123456789", strlen("00123456789")));
+
+ free(buf);
+ free(buf2);
return 0;
}