Whamcloud - gitweb
Small open/close test to help narrow down our LOV bug
authorpschwan <pschwan>
Fri, 6 Sep 2002 03:33:07 +0000 (03:33 +0000)
committerpschwan <pschwan>
Fri, 6 Sep 2002 03:33:07 +0000 (03:33 +0000)
lustre/tests/openclose.c [new file with mode: 0644]

diff --git a/lustre/tests/openclose.c b/lustre/tests/openclose.c
new file mode 100644 (file)
index 0000000..9077e3d
--- /dev/null
@@ -0,0 +1,53 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+
+int main(int argc, char *argv[])
+{
+        char *filename;
+        unsigned long count, i;
+        int fd;
+
+        if (argc != 3) {
+                fprintf(stderr, "usage: %s <filename> <iterations>\n", argv[0]);
+                exit(1);
+        }
+
+        filename = argv[1];
+        count = strtoul(argv[2], NULL, 0);
+
+        fd = open(filename, O_RDWR|O_CREAT, 0644);
+        if (fd < 0) {
+                fprintf(stderr, "open(%s, O_CREAT): %s\n", filename,
+                        strerror(errno));
+                exit(1);
+        }
+        if (close(fd) < 0) {
+                fprintf(stderr, "close(): %s\n", strerror(errno));
+                exit(1);
+        }
+
+        for (i = 0; i < count; i++) {
+                fd = open(filename, O_RDONLY);
+                if (fd < 0) {
+                        fprintf(stderr, "open(%s, O_RDONLY): %s\n", filename,
+                                strerror(errno));
+                        exit(1);
+                }
+                if (close(fd) < 0) {
+                        fprintf(stderr, "close(): %s\n", strerror(errno));
+                        exit(1);
+                }
+        }
+        if (unlink(filename) < 0) {
+                fprintf(stderr, "unlink(%s): %s\n", filename, strerror(errno));
+                exit(1);
+        }
+        printf("Done.\n");
+        return 0;
+}