From: Matthew Dillon Date: Fri, 13 Aug 2004 02:28:42 +0000 (+0000) Subject: add 'read1', a program that tests reading one byte at a time from a file. X-Git-Tag: v2.0.1~10536 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/830da3091c91a4b89b0ee33acb27138866df4e45 add 'read1', a program that tests reading one byte at a time from a file. --- diff --git a/test/sysperf/Makefile b/test/sysperf/Makefile index 14578fce1c..7cb3a87206 100644 --- a/test/sysperf/Makefile +++ b/test/sysperf/Makefile @@ -1,5 +1,5 @@ # -# $DragonFly: src/test/sysperf/Makefile,v 1.8 2004/04/29 16:14:53 dillon Exp $ +# $DragonFly: src/test/sysperf/Makefile,v 1.9 2004/08/13 02:28:42 dillon Exp $ # TARGETS=/tmp/sc1 /tmp/sc2 /tmp/sc3 /tmp/sc4 \ @@ -86,5 +86,8 @@ all: $(TARGETS) /tmp/mem2: memzero.c memzero.S blib.c $(CC) $(CFLAGS) memzero.c memzero.S blib.c -o /tmp/mem2 +/tmp/read1: read1.c blib.c + $(CC) $(CFLAGS) read1.c blib.c -o /tmp/read1 + clean: rm -f $(TARGETS) diff --git a/test/sysperf/read1.c b/test/sysperf/read1.c new file mode 100644 index 0000000000..8065fdcf44 --- /dev/null +++ b/test/sysperf/read1.c @@ -0,0 +1,92 @@ +/* + * read1.c + * + * Tests reading 1 byte at a time from a file. + * + * $DragonFly: src/test/sysperf/read1.c,v 1.1 2004/08/13 02:28:42 dillon Exp $ + */ + +#include "blib.h" +#include +#include +#include + +char Buf[8192]; + +int +main(int ac, char **av) +{ + int bytes; + int fd; + int i; + int j; + char c; + char *ptr; + const char *filename; + + if (ac == 1) { + fprintf(stderr, "%s filesize[k,m]\n", av[0]); + exit(1); + } + bytes = strtol(av[1], &ptr, 0); + if (*ptr == 'k' || *ptr == 'K') { + bytes *= 1024; + } else if (*ptr == 'm' || *ptr == 'M') { + bytes *= 1024 * 1024; + } else if (*ptr) { + fprintf(stderr, "Illegal numerical suffix: %s\n", ptr); + exit(1); + } + if (bytes <= 0) { + fprintf(stderr, "I can't handle %d sized buffers\n", bytes); + exit(1); + } + + filename = "read1.dat"; + fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666); + if (fd < 0) { + if (errno == EROFS) { + filename = "/tmp/read1.dat"; + fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666); + } + if (fd < 0) { + perror("open()"); + exit(1); + } + } + for (i = 0; i < bytes; i += sizeof(Buf)) { + int n = (bytes - i > sizeof(Buf)) ? sizeof(Buf) : bytes - i; + if (write(fd, Buf, n) != n) { + close(fd); + perror("write()"); + remove(filename); + exit(1); + } + } + fsync(fd); + fsync(fd); + sleep(1); + fsync(fd); + lseek(fd, 0L, 0); + sleep(1); + + start_timing(); + i = 0; + while (stop_timing(0, NULL) == 0) { + for (j = 0; j < 256 * 1024; ++j) { + if (read(fd, &c, 1) != 1) + lseek(fd, 0L, 0); + } + i += j; + } + lseek(fd, 0L, 0); + start_timing(); + for (j = 0; j < i; ++j) { + if (read(fd, &c, 1) != 1) + lseek(fd, 0L, 0); + } + stop_timing(j, "read 1char from file:"); + remove(filename); + return(0); +} +