Whamcloud - gitweb
LU-14264 tests: make PARALLEL available to all suites
[fs/lustre-release.git] / lustre / tests / badarea_io.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2014, Intel Corporation.
24  * Use is subject to license terms.
25  */
26 #include <stdio.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <unistd.h>
31
32 #undef perror
33 #define perror(str) ((void)0)
34
35 int main(int argc, char **argv)
36 {
37         int rc;
38         int fd;
39         void *volatile buf = (void *)0x4096000;
40         void *volatile fd_ptr;
41
42         fd = open(argv[1], O_WRONLY);
43         if (fd == -1) {
44                 perror(argv[1]);
45                 goto read;
46         }
47
48         /* We need rc because Sles11 compiler warns against unchecked
49          * return value of read and write */
50         rc = write(fd, buf, 5);
51         if (rc != 5)
52                 perror("write badarea (Should have failed)");
53
54         fd_ptr = (void *)&fd;
55         rc = write(fd, fd_ptr, 0);
56         if (rc != 0)
57                 perror("write zero bytes");
58
59         rc = write(fd, fd_ptr, 1);
60         if (rc != 1)
61                 perror("write one byte");
62
63         rc = write(fd, fd_ptr, 2UL*1024*1024);
64         if (rc != 2UL*1024*1024)
65                 perror("write 2M");
66
67         rc = write(fd, fd_ptr, 2UL*1024*1024*1024);
68         if (rc != 2UL*1024*1024*1024)
69                 perror("write 2G");
70
71         rc = write(fd, fd_ptr, -2);
72         if (rc != -2)
73                 perror("write -2");
74
75         close(fd);
76
77 read:
78         fd = open(argv[1], O_RDONLY);
79         if (fd == -1)
80                 return 0;
81         rc = read(fd, buf, 5);
82         perror("read");
83
84         close(fd);
85
86         /* Tame the compiler spooked about rc assigned, but not used */
87         if (!rc)
88                 return -1; /* Not really important. */
89
90         return 0;
91 }