1 /*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * You should have received a copy of the GNU General Public License along
13 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 */
17
18 /*
19 * Checks that swapon() succeds with swapfile.
20 */
21
22 #include <unistd.h>
23 #include <errno.h>
24 #include <stdlib.h>
25 #include "test.h"
26 #include "lapi/syscalls.h"
27 #include "libswapon.h"
28
29 static void setup(void);
30 static void cleanup(void);
31
32 char *TCID = "swapon01";
33 int TST_TOTAL = 1;
34
35 static long fs_type;
36
verify_swapon(void)37 static void verify_swapon(void)
38 {
39 TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0));
40
41 if (TEST_RETURN == -1) {
42 if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
43 tst_brkm(TCONF, cleanup,
44 "Swapfile on BTRFS not implemeted");
45 return;
46 }
47 tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
48 } else {
49 tst_resm(TPASS, "Succeeded to turn on swapfile");
50 /*we need to turn this swap file off for -i option */
51 if (ltp_syscall(__NR_swapoff, "./swapfile01") != 0) {
52 tst_brkm(TBROK, cleanup, "Failed to turn off swapfile,"
53 " system reboot after execution of LTP "
54 "test suite is recommended.");
55 }
56 }
57 }
58
main(int ac,char ** av)59 int main(int ac, char **av)
60 {
61
62 int lc;
63
64 tst_parse_opts(ac, av, NULL, NULL);
65
66 setup();
67
68 for (lc = 0; TEST_LOOPING(lc); lc++) {
69 tst_count = 0;
70 verify_swapon();
71 }
72
73 cleanup();
74 tst_exit();
75 }
76
setup(void)77 static void setup(void)
78 {
79 tst_sig(FORK, DEF_HANDLER, cleanup);
80
81 tst_require_root();
82
83 TEST_PAUSE;
84
85 tst_tmpdir();
86
87 switch ((fs_type = tst_fs_type(cleanup, "."))) {
88 case TST_NFS_MAGIC:
89 case TST_TMPFS_MAGIC:
90 tst_brkm(TCONF, cleanup,
91 "Cannot do swapon on a file on %s filesystem",
92 tst_fs_type_name(fs_type));
93 break;
94 }
95
96 make_swapfile(cleanup, "swapfile01");
97 }
98
cleanup(void)99 static void cleanup(void)
100 {
101 tst_rmdir();
102 }
103