summaryrefslogtreecommitdiffstats
path: root/src/test/test_cfuse_cache_invalidate.cc
blob: 4b45cb39c7fe31b39a949d458a51ed8729e94ff1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#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 "include/ceph_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++);
      ceph_assert(pwrite(fd, buf, REGION, 0) == REGION);
      int status;
      int ret = waitpid(p, &status, WNOHANG);
      ceph_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");
    ceph_assert(pread(fd, buf, REGION, 0) == REGION);
    close(fd);
  }

  return 0;
}