initial code repo
[stor4nfv.git] / src / ceph / src / test / test_cfuse_cache_invalidate.cc
diff --git a/src/ceph/src/test/test_cfuse_cache_invalidate.cc b/src/ceph/src/test/test_cfuse_cache_invalidate.cc
new file mode 100644 (file)
index 0000000..1389e5d
--- /dev/null
@@ -0,0 +1,53 @@
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <assert.h>
+
+#define REGION 1048576
+int main(int argc, char *argv[]) {
+
+  pid_t p = fork();
+  char buf[REGION];
+  memset(buf, 0, sizeof(buf));
+
+  if (p != 0) {
+    int done = 0;
+    int fd = open(argv[1], O_RDWR|O_CREAT, 0644);
+    if (fd < 0) {
+      perror(argv[1]);
+      return 1;
+    }
+
+    int i = 0;
+    while(!done) {
+      printf("writing %d\n", i++);
+      assert(pwrite(fd, buf, REGION, 0) == REGION);
+      int status;
+      int ret = waitpid(p, &status, WNOHANG);
+      assert(ret >= 0);
+      if (ret > 0) {
+       done = 1;
+      }
+    }
+    close(fd);
+  } else {
+    sleep(1);
+    int fd = open(argv[2], O_RDONLY, 0644);
+    if (fd < 0) {
+      perror(argv[2]);
+      return 1;
+    }
+
+    printf("reading\n");
+    assert(pread(fd, buf, REGION, 0) == REGION);
+    close(fd);
+  }
+
+  return 0;
+}