diff options
author | H. Peter Anvin <hpa@zytor.com> | 2012-05-08 17:40:30 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2012-05-08 17:48:07 -0700 |
commit | 8254a21514d5dfbcec248da334441264570e801b (patch) | |
tree | a746273fa1918c87b307e8586fee093b0c0d4181 | |
parent | 9469b751d78544ec4ec4522de7a8f6c98c01b035 (diff) | |
download | klibc-8254a21514d5dfbcec248da334441264570e801b.tar.gz |
[klibc] Simple stdio test
Very simple test for basic stdio functionality.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r-- | usr/klibc/tests/Kbuild | 1 | ||||
-rw-r--r-- | usr/klibc/tests/stdio.c | 70 |
2 files changed, 71 insertions, 0 deletions
diff --git a/usr/klibc/tests/Kbuild b/usr/klibc/tests/Kbuild index b7978d47b734a..22b2078f03d1b 100644 --- a/usr/klibc/tests/Kbuild +++ b/usr/klibc/tests/Kbuild @@ -39,6 +39,7 @@ sig-nodefer.shared-y := sig-nodefer.o socket.shared-y := socket.o stat.shared-y := stat.o statfs.shared-y := statfs.o +stdio.shared-y := stdio.o strlcpycat.shared-y := strlcpycat.o strtoimax.shared-y := strtoimax.o strtotime.shared-y := strtotime.o diff --git a/usr/klibc/tests/stdio.c b/usr/klibc/tests/stdio.c new file mode 100644 index 0000000000000..895c7306b7a88 --- /dev/null +++ b/usr/klibc/tests/stdio.c @@ -0,0 +1,70 @@ +#include <stdio.h> +#include <stddef.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <sys/mman.h> +#include <arpa/inet.h> +#include <inttypes.h> + +#define TEST_WORDS (1024*1024) + +int main(void) +{ + FILE *f; + int i, n; + uint32_t *buf1, *buf2, *p; + + printf("Hello, World!\nHello again"); + printf(" - and some more - "); + printf("and some more\n"); + + buf1 = mmap(NULL, 2*4*TEST_WORDS, PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, 0, 0); + if (buf1 == MAP_FAILED) { + perror("mmap"); + return 1; + } + + buf2 = buf1 + TEST_WORDS; + + p = buf1; + for (i = 0; i < TEST_WORDS; i++) + *p++ = htonl(i); + + f = fopen("test.out", "w+b"); + if (!f) { + perror("fopen"); + return 1; + } + + for (i = 2; i < TEST_WORDS; i += (i >> 1)) { + n = fwrite(buf1, 4, i, f); + if (n != i) { + perror("fwrite"); + return 1; + } + } + + fprintf(f, "Writing to the file...\n"); + fprintf(f, "Writing to the file "); + fprintf(f, "some more\n"); + + fseek(f, 0, SEEK_SET); + + for (i = 2; i < TEST_WORDS; i += (i >> 1)) { + n = fread(buf2, 4, i, f); + if (n != i) { + perror("fread"); + return 1; + } + + if (memcmp(buf1, buf2, i*4)) { + fprintf(stderr, "memory mismatch error, i = %d\n", i); + return 1; + } + } + + fclose(f); + return 0; +} |