aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2015-07-01 14:04:44 +1000
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2015-07-01 14:04:44 +1000
commitdd72c49c4c7ec924952bd5073e364d8c1417ccfd (patch)
tree6bdd9024e534de5e61dbebdf99eb0233c7610917 /libc
parentf469c1f4df925f207fea4b727e5c0561af88bd9b (diff)
parent4153f5d6a76736f8ba9500880d8f0c1034bdd1b6 (diff)
downloadskiboot-dd72c49c4c7ec924952bd5073e364d8c1417ccfd.zip
skiboot-dd72c49c4c7ec924952bd5073e364d8c1417ccfd.tar.gz
skiboot-dd72c49c4c7ec924952bd5073e364d8c1417ccfd.tar.bz2
Merge remote-tracking branch 'github/master' into mergeback
Diffstat (limited to 'libc')
-rw-r--r--libc/include/errno.h2
-rw-r--r--libc/test/run-ctype-test.c36
-rw-r--r--libc/test/run-ctype.c79
-rw-r--r--libc/test/run-memops-test.c44
-rw-r--r--libc/test/run-memops.c60
5 files changed, 220 insertions, 1 deletions
diff --git a/libc/include/errno.h b/libc/include/errno.h
index d585934..c2bd987 100644
--- a/libc/include/errno.h
+++ b/libc/include/errno.h
@@ -21,6 +21,7 @@ extern int errno;
#define EPERM 1 /* not permitted */
#define ENOENT 2 /* file or directory not found */
#define EIO 5 /* input/output error */
+#define EBADF 9 /* Bad file number */
#define ENOMEM 12 /* not enough space */
#define EACCES 13 /* permission denied */
#define EFAULT 14 /* bad address */
@@ -30,5 +31,6 @@ extern int errno;
#define EINVAL 22 /* invalid argument */
#define EDOM 33 /* math argument out of domain of func */
#define ERANGE 34 /* math result not representable */
+#define ENOSYS 38 /* Function not implemented */
#endif
diff --git a/libc/test/run-ctype-test.c b/libc/test/run-ctype-test.c
index 5ba76f1..bbe91d3 100644
--- a/libc/test/run-ctype-test.c
+++ b/libc/test/run-ctype-test.c
@@ -31,3 +31,39 @@
#include "../ctype/tolower.c"
#include "../ctype/toupper.c"
+int skiboot_isdigit(int ch);
+int skiboot_isprint(int ch);
+int skiboot_isspace(int ch);
+int skiboot_isxdigit(int ch);
+int skiboot_tolower(int ch);
+int skiboot_toupper(int ch);
+
+int skiboot_isdigit(int ch)
+{
+ return isdigit(ch);
+}
+
+int skiboot_isprint(int ch)
+{
+ return isprint(ch);
+}
+
+int skiboot_isspace(int ch)
+{
+ return isspace(ch);
+}
+
+int skiboot_isxdigit(int ch)
+{
+ return isxdigit(ch);
+}
+
+int skiboot_tolower(int ch)
+{
+ return tolower(ch);
+}
+
+int skiboot_toupper(int ch)
+{
+ return toupper(ch);
+}
diff --git a/libc/test/run-ctype.c b/libc/test/run-ctype.c
index 15ec9bd..3851a5d 100644
--- a/libc/test/run-ctype.c
+++ b/libc/test/run-ctype.c
@@ -20,8 +20,87 @@
#include <assert.h>
#include <string.h>
#include <stdio.h>
+#include <assert.h>
+#include <ctype.h>
+
+int skiboot_isdigit(int ch);
+int skiboot_isprint(int ch);
+int skiboot_isspace(int ch);
+int skiboot_isxdigit(int ch);
+int skiboot_tolower(int ch);
+int skiboot_toupper(int ch);
int main(void)
{
+ int i;
+ int r1, r2;
+
+ for(i = '0'; i <= '9'; i++)
+ assert(skiboot_isdigit(i));
+ assert(skiboot_isdigit('a') == 0);
+ assert(skiboot_isdigit('Z') == 0);
+
+ for (i = 0; i < 257; i++) {
+ r1 = skiboot_isdigit(i);
+ r2 = isdigit(i);
+ if (r1)
+ assert(r2);
+ if (!r1)
+ assert(!r2);
+ }
+
+ for(i = '0'; i <= '9'; i++)
+ assert(skiboot_isprint(i));
+ assert(skiboot_isprint('\0') == 0);
+ assert(skiboot_isprint(4) == 0);
+
+ for (i = 0; i < 257; i++) {
+ r1 = skiboot_isprint(i);
+ r2 = isprint(i);
+ if (r1)
+ assert(r2);
+ if (!r1)
+ assert(!r2);
+ }
+
+ for(i = '0'; i <= '9'; i++)
+ assert(skiboot_isspace(i) == 0);
+ assert(skiboot_isspace('\f'));
+ assert(skiboot_isspace('\n'));
+ assert(skiboot_isspace(' '));
+
+ for (i = 0; i < 257; i++) {
+ r1 = skiboot_isspace(i);
+ r2 = isspace(i);
+ if (r1)
+ assert(r2);
+ if (!r1)
+ assert(!r2);
+ }
+
+ for(i = '0'; i <= '9'; i++)
+ assert(skiboot_isxdigit(i));
+ assert(skiboot_isxdigit('a'));
+ assert(skiboot_isxdigit('A'));
+ assert(skiboot_isxdigit('F'));
+ assert(skiboot_isxdigit('Z') == 0);
+
+ for (i = 0; i < 257; i++) {
+ r1 = skiboot_isxdigit(i);
+ r2 = isxdigit(i);
+ if (r1)
+ assert(r2);
+ if (!r1)
+ assert(!r2);
+ }
+
+ for (i = 0; i < 257; i++) {
+ assert(skiboot_tolower(i) == tolower(i));
+ }
+
+ for (i = 0; i < 257; i++) {
+ assert(skiboot_toupper(i) == toupper(i));
+ }
+
return 0;
}
diff --git a/libc/test/run-memops-test.c b/libc/test/run-memops-test.c
index 429cfdc..cb2d7f8 100644
--- a/libc/test/run-memops-test.c
+++ b/libc/test/run-memops-test.c
@@ -44,6 +44,13 @@
#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_memcmp(const void *ptr1, const void *ptr2, size_t n, int expected);
+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)
{
@@ -57,3 +64,40 @@ 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));
+}
+
+int test_memcmp(const void *ptr1, const void *ptr2, size_t n, int expected)
+{
+ return(expected == memcmp(ptr1, ptr2, n));
+}
+
+int test_strcmp(const void *ptr1, const void *ptr2, int expected)
+{
+ return(expected == strcmp(ptr1, ptr2));
+}
+
+int test_strchr(const char *s, int c, char *expected)
+{
+ return(expected == strchr(s, c));
+}
+
+int test_strcasecmp(const char *s1, const char *s2, int expected)
+{
+ return(expected == strcasecmp(s1, s2));
+}
+
+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 80822df..5c425f2 100644
--- a/libc/test/run-memops.c
+++ b/libc/test/run-memops.c
@@ -22,10 +22,18 @@
#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 test_memcmp(const void *ptr1, const void *ptr2, size_t n, int expected);
+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);
@@ -40,5 +48,55 @@ 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));
+
+ assert(test_memcmp(buf, "Hello World!", strlen(buf), 0));
+ assert(test_memcmp(buf, "Hfllow World", strlen(buf), -1));
+
+ assert(test_strcmp(buf, "Hello World!", 0));
+ assert(test_strcmp(buf, "Hfllow World", -1));
+
+ assert(test_strchr(buf, 'H', buf));
+ assert(test_strchr(buf, 'e', buf+1));
+ assert(test_strchr(buf, 'a', NULL));
+ assert(test_strchr(buf, '!', buf+11));
+
+ assert(test_strcasecmp(buf, "Hello World!", 0));
+ assert(test_strcasecmp(buf, "HELLO WORLD!", 0));
+ assert(test_strcasecmp(buf, "IELLO world!", -1));
+ assert(test_strcasecmp(buf, "HeLLo WOrlc!", 1));
+
+ assert(test_strncasecmp(buf, "Hello World!", strlen(buf), 0));
+ assert(test_strncasecmp(buf, "HELLO WORLD!", strlen(buf), 0));
+ assert(test_strncasecmp(buf, "IELLO world!", strlen(buf), -1));
+ assert(test_strncasecmp(buf, "HeLLo WOrlc!", strlen(buf), 1));
+
+ assert(test_strncasecmp(buf, "HeLLo WOrlc!", 0, 0));
+ assert(test_strncasecmp(buf, "HeLLo WOrlc!", 1, 0));
+ 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;
}