Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / test_cfuse_cache_invalidate.cc
1
2 #include <stdio.h>
3 #include <errno.h>
4 #include <string.h>
5 #include <sys/types.h>
6 #include <sys/wait.h>
7 #include <sys/stat.h>
8 #include <fcntl.h>
9 #include <unistd.h>
10 #include <assert.h>
11
12 #define REGION 1048576
13 int main(int argc, char *argv[]) {
14
15   pid_t p = fork();
16   char buf[REGION];
17   memset(buf, 0, sizeof(buf));
18
19   if (p != 0) {
20     int done = 0;
21     int fd = open(argv[1], O_RDWR|O_CREAT, 0644);
22     if (fd < 0) {
23       perror(argv[1]);
24       return 1;
25     }
26
27     int i = 0;
28     while(!done) {
29       printf("writing %d\n", i++);
30       assert(pwrite(fd, buf, REGION, 0) == REGION);
31       int status;
32       int ret = waitpid(p, &status, WNOHANG);
33       assert(ret >= 0);
34       if (ret > 0) {
35         done = 1;
36       }
37     }
38     close(fd);
39   } else {
40     sleep(1);
41     int fd = open(argv[2], O_RDONLY, 0644);
42     if (fd < 0) {
43       perror(argv[2]);
44       return 1;
45     }
46
47     printf("reading\n");
48     assert(pread(fd, buf, REGION, 0) == REGION);
49     close(fd);
50   }
51
52   return 0;
53 }