From 199be6b84faeff7ef03032c857766d4a023fbbb4 Mon Sep 17 00:00:00 2001 From: Cyril Bur Date: Tue, 23 Jun 2015 13:22:09 +1000 Subject: libflash/blocklevel: Extend the block level to be able to do ecc At the moment ECC reads and writes are still being handled by the low level core of libflash. ECC should be none of libflashes concern, it is primarily a hardware access backend. It makes sense for blocklevel to take care of ECC but currently it has no way of knowing. With some simple modifications (which are rudimentary at the moment and will need a performance improvement) blocklevel can handle ECC, and with a little more effort this can be extended to provide read and write protection in blocklevel. Reviewed-By: Alistair Popple Signed-off-by: Cyril Bur Signed-off-by: Stewart Smith --- libc/include/errno.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libc') 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 -- cgit v1.1 From 82d60cae3f53317dc7a3e84de00656bdd03a504a Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Wed, 24 Jun 2015 13:20:19 +1000 Subject: add tests for libc memchr Signed-off-by: Stewart Smith --- libc/test/run-memops-test.c | 6 ++++++ libc/test/run-memops.c | 7 +++++++ 2 files changed, 13 insertions(+) (limited to 'libc') 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 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 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; } -- cgit v1.1 From b8677f6a97a978e11017736a280bc948bb1a85fe Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Wed, 24 Jun 2015 13:23:12 +1000 Subject: add tests for libc memcmp Signed-off-by: Stewart Smith --- libc/test/run-memops-test.c | 6 ++++++ libc/test/run-memops.c | 4 ++++ 2 files changed, 10 insertions(+) (limited to 'libc') diff --git a/libc/test/run-memops-test.c b/libc/test/run-memops-test.c index 7212d76..c848a1d 100644 --- a/libc/test/run-memops-test.c +++ b/libc/test/run-memops-test.c @@ -45,6 +45,7 @@ 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_memset(char* buf, int c, size_t s) { @@ -63,3 +64,8 @@ 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)); +} diff --git a/libc/test/run-memops.c b/libc/test/run-memops.c index cc107f7..ded21ae 100644 --- a/libc/test/run-memops.c +++ b/libc/test/run-memops.c @@ -23,6 +23,7 @@ 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 main(void) { @@ -45,6 +46,9 @@ int main(void) 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)); free(buf); return 0; -- cgit v1.1 From 147bcfbba9e9eaec215b5ad40e6bfb3fd57361dd Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Wed, 24 Jun 2015 13:28:21 +1000 Subject: add tests for libc strcmp Signed-off-by: Stewart Smith --- libc/test/run-memops-test.c | 6 ++++++ libc/test/run-memops.c | 4 ++++ 2 files changed, 10 insertions(+) (limited to 'libc') diff --git a/libc/test/run-memops-test.c b/libc/test/run-memops-test.c index c848a1d..41c624f 100644 --- a/libc/test/run-memops-test.c +++ b/libc/test/run-memops-test.c @@ -46,6 +46,7 @@ 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_memset(char* buf, int c, size_t s) { @@ -69,3 +70,8 @@ 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)); +} diff --git a/libc/test/run-memops.c b/libc/test/run-memops.c index ded21ae..259c4ff 100644 --- a/libc/test/run-memops.c +++ b/libc/test/run-memops.c @@ -24,6 +24,7 @@ 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 main(void) { @@ -49,6 +50,9 @@ int main(void) 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)); free(buf); return 0; -- cgit v1.1 From a4385471decc41f4aa7ff39328b7aec1de4e9dc9 Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Wed, 24 Jun 2015 13:34:26 +1000 Subject: add tests for libc strcasecmp Signed-off-by: Stewart Smith --- libc/test/run-memops-test.c | 12 ++++++++++++ libc/test/run-memops.c | 15 +++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'libc') diff --git a/libc/test/run-memops-test.c b/libc/test/run-memops-test.c index 41c624f..e6fc7d0 100644 --- a/libc/test/run-memops-test.c +++ b/libc/test/run-memops-test.c @@ -47,6 +47,8 @@ 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_memset(char* buf, int c, size_t s) { @@ -75,3 +77,13 @@ 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)); +} diff --git a/libc/test/run-memops.c b/libc/test/run-memops.c index 259c4ff..50b2cab 100644 --- a/libc/test/run-memops.c +++ b/libc/test/run-memops.c @@ -25,6 +25,8 @@ 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 main(void) { @@ -53,7 +55,20 @@ int main(void) 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)); + + free(buf); + return 0; } -- cgit v1.1 From 9c7f0d09eb4850b1828720846b07433b745ba526 Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Wed, 24 Jun 2015 13:41:04 +1000 Subject: add tests for libc strncasecmp Signed-off-by: Stewart Smith --- libc/test/run-memops-test.c | 6 ++++++ libc/test/run-memops.c | 11 +++++++++++ 2 files changed, 17 insertions(+) (limited to 'libc') diff --git a/libc/test/run-memops-test.c b/libc/test/run-memops-test.c index e6fc7d0..a4179eb 100644 --- a/libc/test/run-memops-test.c +++ b/libc/test/run-memops-test.c @@ -49,6 +49,7 @@ 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_memset(char* buf, int c, size_t s) { @@ -87,3 +88,8 @@ 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)); +} diff --git a/libc/test/run-memops.c b/libc/test/run-memops.c index 50b2cab..21f6ab6 100644 --- a/libc/test/run-memops.c +++ b/libc/test/run-memops.c @@ -27,6 +27,7 @@ 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 main(void) { @@ -66,6 +67,16 @@ int main(void) 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); -- cgit v1.1 From 513e6b8a88df7b6f62e379886987041fa626ed34 Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Wed, 24 Jun 2015 13:59:42 +1000 Subject: add tests for libc memmove Signed-off-by: Stewart Smith --- libc/test/run-memops-test.c | 8 ++++++++ libc/test/run-memops.c | 21 +++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'libc') 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; } -- cgit v1.1 From 3cafe0e80b6f57115bc059e26f11c5d613112984 Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Wed, 24 Jun 2015 15:02:49 +1000 Subject: add tests for libc isdigit, isprint, isspace, isxdigit Signed-off-by: Stewart Smith --- libc/test/run-ctype-test.c | 24 ++++++++++++++++ libc/test/run-ctype.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) (limited to 'libc') diff --git a/libc/test/run-ctype-test.c b/libc/test/run-ctype-test.c index 5ba76f1..999292b 100644 --- a/libc/test/run-ctype-test.c +++ b/libc/test/run-ctype-test.c @@ -31,3 +31,27 @@ #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_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); +} diff --git a/libc/test/run-ctype.c b/libc/test/run-ctype.c index 15ec9bd..eac04ec 100644 --- a/libc/test/run-ctype.c +++ b/libc/test/run-ctype.c @@ -20,8 +20,77 @@ #include #include #include +#include +#include + +int skiboot_isdigit(int ch); +int skiboot_isprint(int ch); +int skiboot_isspace(int ch); +int skiboot_isxdigit(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); + } + return 0; } -- cgit v1.1 From 5e8158245446028d86edf3a166217eda4a78ba47 Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Wed, 24 Jun 2015 15:06:20 +1000 Subject: add tests for libc tolower() and toupper() Signed-off-by: Stewart Smith --- libc/test/run-ctype-test.c | 12 ++++++++++++ libc/test/run-ctype.c | 10 ++++++++++ 2 files changed, 22 insertions(+) (limited to 'libc') diff --git a/libc/test/run-ctype-test.c b/libc/test/run-ctype-test.c index 999292b..bbe91d3 100644 --- a/libc/test/run-ctype-test.c +++ b/libc/test/run-ctype-test.c @@ -35,6 +35,8 @@ 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) { @@ -55,3 +57,13 @@ 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 eac04ec..3851a5d 100644 --- a/libc/test/run-ctype.c +++ b/libc/test/run-ctype.c @@ -27,6 +27,8 @@ 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) { @@ -92,5 +94,13 @@ int main(void) 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; } -- cgit v1.1