Whamcloud - gitweb
LU-10038 test: improve error reporting in sanity test_133g()
[fs/lustre-release.git] / lustre / tests / badarea_io.c
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6
7 #undef perror
8 #define perror(str) ((void)0)
9
10 int main(int argc, char **argv)
11 {
12         int rc;
13         int fd = open(argv[1], O_WRONLY);
14
15         if (fd == -1) {
16                 perror(argv[1]);
17                 goto read;
18         }
19
20         /* We need rc because Sles11 compiler warns against unchecked
21          * return value of read and write */
22         rc = write(fd, (void *)0x4096000, 5);
23         if (rc != 5)
24                 perror("write badarea (Should have failed)");
25
26         rc = write(fd, &fd, 0);
27         if (rc != 0)
28                 perror("write zero bytes");
29
30         rc = write(fd, &fd, 1);
31         if (rc != 1)
32                 perror("write one byte");
33
34         rc = write(fd, &fd, 2UL*1024*1024);
35         if (rc != 2UL*1024*1024)
36                 perror("write 2M");
37
38         rc = write(fd, &fd, 2UL*1024*1024*1024);
39         if (rc != 2UL*1024*1024*1024)
40                 perror("write 2G");
41
42         rc = write(fd, &fd, -2);
43         if (rc != -2)
44                 perror("write -2");
45
46         close(fd);
47
48 read:
49         fd = open(argv[1], O_RDONLY);
50         if (fd == -1)
51                 return 0;
52         rc = read(fd, (void *)0x4096000, 5);
53         perror("read");
54
55         close(fd);
56
57         /* Tame the compiler spooked about rc assigned, but not used */
58         if (!rc)
59                 return -1; /* Not really important. */
60
61         return 0;
62 }