blob: 0d7320f58135b715130e450a9c4f62f1ce482504 [file] [log] [blame]
robbiew0abc81f2003-01-02 16:45:29 +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.
robbiew0abc81f2003-01-02 16:45:29 +000015 *
16 */
Cyril Hrubis591ddcb2014-02-26 18:06:19 +010017
18/*
19 * Check that swapoff() succeeds.
20 */
robbiew0abc81f2003-01-02 16:45:29 +000021
22#include <unistd.h>
23#include "test.h"
24#include "usctest.h"
25#include <errno.h>
robbiew0abc81f2003-01-02 16:45:29 +000026#include <stdlib.h>
yaberauneya77772ef2009-10-17 06:53:58 +000027#include "config.h"
yaberauneyaa2a05e32009-11-26 14:19:32 +000028#include "linux_syscall_numbers.h"
Cyril Hrubis0f0e3482014-02-27 16:08:04 +010029#include "tst_fs_type.h"
robbiew0abc81f2003-01-02 16:45:29 +000030
Cyril Hrubis591ddcb2014-02-26 18:06:19 +010031static void setup(void);
32static void cleanup(void);
Cyril Hrubisdfda9f82014-03-06 13:37:21 +010033static void verify_swapoff(void);
robbiew0abc81f2003-01-02 16:45:29 +000034
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020035char *TCID = "swapoff01";
36int TST_TOTAL = 1;
robbiew0abc81f2003-01-02 16:45:29 +000037
subrata_modak56207ce2009-03-23 13:35:39 +000038int main(int ac, char **av)
robbiew0abc81f2003-01-02 16:45:29 +000039{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020040 int lc;
41 char *msg;
robbiew0abc81f2003-01-02 16:45:29 +000042
Garrett Coopera9e49f12010-12-16 10:54:03 -080043 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080044 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew0abc81f2003-01-02 16:45:29 +000045
robbiewadc1c012003-04-29 17:06:59 +000046 setup();
robbiew0abc81f2003-01-02 16:45:29 +000047
robbiewadc1c012003-04-29 17:06:59 +000048 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080049 tst_count = 0;
Cyril Hrubisdfda9f82014-03-06 13:37:21 +010050 verify_swapoff();
Cyril Hrubis591ddcb2014-02-26 18:06:19 +010051 }
robbiew0abc81f2003-01-02 16:45:29 +000052
robbiewadc1c012003-04-29 17:06:59 +000053 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080054 tst_exit();
robbiew0abc81f2003-01-02 16:45:29 +000055}
56
Cyril Hrubisdfda9f82014-03-06 13:37:21 +010057static void verify_swapoff(void)
58{
59 if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
60 tst_resm(TWARN, "Failed to turn on the swap file"
61 ", skipping test iteration");
62 return;
63 }
64
65 TEST(ltp_syscall(__NR_swapoff, "./swapfile01"));
66
67 if (TEST_RETURN == -1) {
68 tst_resm(TFAIL | TTERRNO, "Failed to turn off swapfile,"
69 " system reboot after execution of LTP "
70 "test suite is recommended.");
71 } else {
72 tst_resm(TPASS, "Succeeded to turn off swapfile");
73 }
74}
75
Cyril Hrubis591ddcb2014-02-26 18:06:19 +010076static void setup(void)
robbiew0abc81f2003-01-02 16:45:29 +000077{
Cyril Hrubis0f0e3482014-02-27 16:08:04 +010078 long type;
79
robbiewadc1c012003-04-29 17:06:59 +000080 tst_sig(FORK, DEF_HANDLER, cleanup);
robbiew0abc81f2003-01-02 16:45:29 +000081
Cyril Hrubis591ddcb2014-02-26 18:06:19 +010082 tst_require_root(NULL);
robbiew0abc81f2003-01-02 16:45:29 +000083
robbiewadc1c012003-04-29 17:06:59 +000084 TEST_PAUSE;
robbiew0abc81f2003-01-02 16:45:29 +000085
robbiewadc1c012003-04-29 17:06:59 +000086 tst_tmpdir();
robbiew0abc81f2003-01-02 16:45:29 +000087
Cyril Hrubis0f0e3482014-02-27 16:08:04 +010088 switch ((type = tst_fs_type(cleanup, "."))) {
89 case TST_NFS_MAGIC:
90 case TST_TMPFS_MAGIC:
subrata_modak56207ce2009-03-23 13:35:39 +000091 tst_brkm(TCONF, cleanup,
Cyril Hrubis0f0e3482014-02-27 16:08:04 +010092 "Cannot do swapoff on a file on %s filesystem",
93 tst_fs_type_name(type));
94 break;
robbiew143090a2005-01-17 22:10:09 +000095 }
96
subrata_modak56207ce2009-03-23 13:35:39 +000097 if (!tst_cwd_has_free(65536)) {
98 tst_brkm(TBROK, cleanup,
99 "Insufficient disk space to create swap file");
robbiew143090a2005-01-17 22:10:09 +0000100 }
101
Cyril Hrubis591ddcb2014-02-26 18:06:19 +0100102 if (tst_fill_file("swapfile01", 0x00, 1024, 65536))
robbiewadc1c012003-04-29 17:06:59 +0000103 tst_brkm(TBROK, cleanup, "Failed to create file for swap");
robbiew0abc81f2003-01-02 16:45:29 +0000104
Cyril Hrubisdfda9f82014-03-06 13:37:21 +0100105 if (system("mkswap swapfile01 > tmpfile 2>&1") != 0)
robbiewadc1c012003-04-29 17:06:59 +0000106 tst_brkm(TBROK, cleanup, "Failed to make swapfile");
Garrett Cooper2c282152010-12-16 00:55:50 -0800107}
robbiew0abc81f2003-01-02 16:45:29 +0000108
Cyril Hrubis591ddcb2014-02-26 18:06:19 +0100109static void cleanup(void)
robbiew0abc81f2003-01-02 16:45:29 +0000110{
robbiewadc1c012003-04-29 17:06:59 +0000111 TEST_CLEANUP;
robbiew0abc81f2003-01-02 16:45:29 +0000112
robbiewadc1c012003-04-29 17:06:59 +0000113 tst_rmdir();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700114}