Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / workunits / fs / test_o_trunc.c
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6 #include <string.h>
7 #include <stdlib.h>
8
9 int main(int argc, char *argv[])
10 {
11         char obuf[32], ibuf[1024];
12         int n, max = 0;
13         
14         if (argc > 2)
15                 max = atoi(argv[2]);
16         if (!max)
17                 max = 600;
18         
19         memset(obuf, 0xff, sizeof(obuf));
20         
21         for (n = 1; n <= max; ++n) {
22                 int fd, ret;
23                 fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0644);
24                 printf("%d/%d: open fd = %d\n", n, max, fd);
25                 
26                 ret = write(fd, obuf, sizeof(obuf));
27                 printf("write ret = %d\n", ret);
28                 
29                 sleep(1);
30                 
31                 ret = write(fd, obuf, sizeof(obuf));
32                 printf("write ret = %d\n", ret);
33                 
34                 ret = pread(fd, ibuf, sizeof(ibuf), 0);
35                 printf("pread ret = %d\n", ret);
36                 
37                 if (memcmp(obuf, ibuf, sizeof(obuf))) {
38                         printf("mismatch\n");
39                         close(fd);
40                         break;
41                 }
42                 close(fd);
43         }
44         return 0;
45 }