blob: cda8ec254372679ceaf8423a0d7af07cc215abf6 [file] [log] [blame]
robbiewac9784e2003-01-03 17:17:46 +00001/*
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
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
robbiewac9784e2003-01-03 17:17:46 +000015 *
16 */
Cyril Hrubisf6f4b7f2014-02-26 17:45:31 +010017
18 /*
19 * Checks that swapon() succeds with swapfile.
20 */
robbiewac9784e2003-01-03 17:17:46 +000021
22#include <unistd.h>
yaberauneya77772ef2009-10-17 06:53:58 +000023#include <errno.h>
24#include <stdlib.h>
robbiewac9784e2003-01-03 17:17:46 +000025#include "test.h"
yaberauneya89911a12009-11-26 14:11:35 +000026#include "linux_syscall_numbers.h"
Cyril Hrubis0f0e3482014-02-27 16:08:04 +010027#include "tst_fs_type.h"
Stanislav Kholmanskikh4bdda042013-08-14 10:01:47 +040028#include "libswapon.h"
robbiewac9784e2003-01-03 17:17:46 +000029
Cyril Hrubisf6f4b7f2014-02-26 17:45:31 +010030static void setup(void);
31static void cleanup(void);
robbiewac9784e2003-01-03 17:17:46 +000032
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020033char *TCID = "swapon01";
34int TST_TOTAL = 1;
robbiewac9784e2003-01-03 17:17:46 +000035
Cyril Hrubisb16efb82014-03-06 14:49:17 +010036static long fs_type;
37
Cyril Hrubisa432c4d2014-03-06 14:28:30 +010038static void verify_swapon(void)
39{
40 TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0));
41
42 if (TEST_RETURN == -1) {
Cyril Hrubisb16efb82014-03-06 14:49:17 +010043 if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
44 tst_brkm(TCONF, cleanup,
45 "Swapfile on BTRFS not implemeted");
46 return;
47 }
Cyril Hrubisa432c4d2014-03-06 14:28:30 +010048 tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
49 } else {
50 tst_resm(TPASS, "Succeeded to turn on swapfile");
51 /*we need to turn this swap file off for -i option */
52 if (ltp_syscall(__NR_swapoff, "./swapfile01") != 0) {
53 tst_brkm(TBROK, cleanup, "Failed to turn off swapfile,"
54 " system reboot after execution of LTP "
55 "test suite is recommended.");
56 }
57 }
58}
59
subrata_modak56207ce2009-03-23 13:35:39 +000060int main(int ac, char **av)
robbiewac9784e2003-01-03 17:17:46 +000061{
62
Cyril Hrubis89af32a2012-10-24 16:39:11 +020063 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020064 const char *msg;
robbiewac9784e2003-01-03 17:17:46 +000065
Garrett Cooper45e285d2010-11-22 12:19:25 -080066 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper62383b82010-11-22 12:02:14 -080067 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiewac9784e2003-01-03 17:17:46 +000068
robbiew6b01d682003-04-28 20:27:26 +000069 setup();
robbiewac9784e2003-01-03 17:17:46 +000070
robbiew6b01d682003-04-28 20:27:26 +000071 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080072 tst_count = 0;
Cyril Hrubisa432c4d2014-03-06 14:28:30 +010073 verify_swapon();
Cyril Hrubisf6f4b7f2014-02-26 17:45:31 +010074 }
robbiewac9784e2003-01-03 17:17:46 +000075
robbiew6b01d682003-04-28 20:27:26 +000076 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080077 tst_exit();
robbiewac9784e2003-01-03 17:17:46 +000078}
79
Cyril Hrubisf6f4b7f2014-02-26 17:45:31 +010080static void setup(void)
robbiewac9784e2003-01-03 17:17:46 +000081{
robbiew6b01d682003-04-28 20:27:26 +000082 tst_sig(FORK, DEF_HANDLER, cleanup);
robbiewac9784e2003-01-03 17:17:46 +000083
Cyril Hrubisf6f4b7f2014-02-26 17:45:31 +010084 tst_require_root(NULL);
robbiewac9784e2003-01-03 17:17:46 +000085
robbiew6b01d682003-04-28 20:27:26 +000086 TEST_PAUSE;
robbiewac9784e2003-01-03 17:17:46 +000087
robbiew6b01d682003-04-28 20:27:26 +000088 tst_tmpdir();
robbiewac9784e2003-01-03 17:17:46 +000089
Cyril Hrubisb16efb82014-03-06 14:49:17 +010090 switch ((fs_type = tst_fs_type(cleanup, "."))) {
Cyril Hrubis0f0e3482014-02-27 16:08:04 +010091 case TST_NFS_MAGIC:
92 case TST_TMPFS_MAGIC:
subrata_modak56207ce2009-03-23 13:35:39 +000093 tst_brkm(TCONF, cleanup,
Cyril Hrubis0f0e3482014-02-27 16:08:04 +010094 "Cannot do swapon on a file on %s filesystem",
Cyril Hrubisb16efb82014-03-06 14:49:17 +010095 tst_fs_type_name(fs_type));
Cyril Hrubis0f0e3482014-02-27 16:08:04 +010096 break;
robbiew143090a2005-01-17 22:10:09 +000097 }
98
Stanislav Kholmanskikh4bdda042013-08-14 10:01:47 +040099 make_swapfile(cleanup, "swapfile01");
Garrett Cooper2c282152010-12-16 00:55:50 -0800100}
robbiewac9784e2003-01-03 17:17:46 +0000101
Cyril Hrubisf6f4b7f2014-02-26 17:45:31 +0100102static void cleanup(void)
robbiewac9784e2003-01-03 17:17:46 +0000103{
robbiew6b01d682003-04-28 20:27:26 +0000104 tst_rmdir();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700105}