add in some contributed O_APPEND test helper programs.
authorfsgqa <fsgqa>
Wed, 4 Sep 2002 07:00:33 +0000 (07:00 +0000)
committerfsgqa <fsgqa>
Wed, 4 Sep 2002 07:00:33 +0000 (07:00 +0000)
src/Makefile
src/append_reader.c [new file with mode: 0644]
src/append_writer.c [new file with mode: 0644]

index e3c31baaa7dfb736e95e78e2707dbc0adf89d861..23fcf10d21be3da13e88ebca1c29ef7016e78eba 100644 (file)
@@ -36,7 +36,7 @@ include $(TOPDIR)/include/builddefs
 TARGETS = alloc acl_get bstat devzero dirstress fault feature \
          fsstress fill fill2 getpagesize holes ioctl loggen lstat64 \
          nametest permname randholes runas truncfile usemem \
-         fstest mmapcat
+         fstest mmapcat append_reader append_writer
 ifeq ($(HAVE_DB), true)
 TARGETS += dbtest
 endif
diff --git a/src/append_reader.c b/src/append_reader.c
new file mode 100644 (file)
index 0000000..6b9e4f6
--- /dev/null
@@ -0,0 +1,44 @@
+/* Simple test program for checking O_APPEND writes (see append_writer.c)
+ *
+ * Contributed by hatakeyama@bsd.tnes.nec.co.jp
+ */
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/param.h>
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+       char *file;
+       int fd, i, rc, d;
+
+       if (argc < 2)
+               exit(1);
+
+       file = argv[1];
+
+       if ((fd = open(file, O_RDONLY, 0600)) == -1) {
+               perror("couldn't open");
+               exit(1);
+       }
+
+       for (i = 0; ;i ++) {
+               if ((rc = read(fd, &d, sizeof(d))) != sizeof(i)) {
+                       if (rc == 0)
+                               exit(0);
+                       perror("couldn't read");
+                       exit(1);
+               }
+
+               if (d != i) {
+                       fprintf(stderr, "bad data, offset = %u", i * 4);
+                       exit(1);
+               }
+       }
+
+       exit(0);
+}
+
diff --git a/src/append_writer.c b/src/append_writer.c
new file mode 100644 (file)
index 0000000..acf093c
--- /dev/null
@@ -0,0 +1,34 @@
+/* Simple test program for O_APPEND writes (checked by append_reader.c)
+ * 
+ * Contributed by hatakeyama@bsd.tnes.nec.co.jp
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/param.h>
+
+int main(int argc, char **argv)
+{
+       char file[MAXPATHLEN];
+       int fd, i;
+
+       sprintf(file, "testfile.%d", getpid());
+
+       if ((fd = open(file, O_CREAT | O_RDWR | O_APPEND, 0600)) == -1) {
+               perror("couldn't open");
+               exit(1);
+       }
+
+       for (i = 0; ;i ++) {
+               if (write(fd, &i, sizeof(i)) != sizeof(i)) {
+                       perror("couldn't write");
+                       exit(1);
+               }
+       }
+
+       exit(0);
+}
+