robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 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 |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 13 | * with this program; if not, write the Free Software Foundation, Inc., |
| 14 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
Cyril Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 17 | |
| 18 | /* |
| 19 | * Check that swapoff() succeeds. |
| 20 | */ |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 21 | |
| 22 | #include <unistd.h> |
| 23 | #include "test.h" |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 24 | #include <errno.h> |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 25 | #include <stdlib.h> |
yaberauneya | 77772ef | 2009-10-17 06:53:58 +0000 | [diff] [blame] | 26 | #include "config.h" |
yaberauneya | a2a05e3 | 2009-11-26 14:19:32 +0000 | [diff] [blame] | 27 | #include "linux_syscall_numbers.h" |
Cyril Hrubis | 0f0e348 | 2014-02-27 16:08:04 +0100 | [diff] [blame] | 28 | #include "tst_fs_type.h" |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 29 | |
Cyril Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 30 | static void setup(void); |
| 31 | static void cleanup(void); |
Cyril Hrubis | dfda9f8 | 2014-03-06 13:37:21 +0100 | [diff] [blame] | 32 | static void verify_swapoff(void); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 33 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 34 | char *TCID = "swapoff01"; |
| 35 | int TST_TOTAL = 1; |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 36 | |
Cyril Hrubis | 72c0a1b | 2014-03-06 13:40:25 +0100 | [diff] [blame] | 37 | static long fs_type; |
| 38 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 39 | int main(int ac, char **av) |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 40 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 41 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 42 | const char *msg; |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 43 | |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 44 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 45 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 46 | |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 47 | setup(); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 48 | |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 49 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 50 | tst_count = 0; |
Cyril Hrubis | dfda9f8 | 2014-03-06 13:37:21 +0100 | [diff] [blame] | 51 | verify_swapoff(); |
Cyril Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 52 | } |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 53 | |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 54 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 55 | tst_exit(); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Cyril Hrubis | dfda9f8 | 2014-03-06 13:37:21 +0100 | [diff] [blame] | 58 | static void verify_swapoff(void) |
| 59 | { |
| 60 | if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) { |
Cyril Hrubis | 72c0a1b | 2014-03-06 13:40:25 +0100 | [diff] [blame] | 61 | if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) { |
| 62 | tst_brkm(TCONF, cleanup, |
| 63 | "Swapfiles on BTRFS are not implemented"); |
| 64 | } |
| 65 | |
| 66 | tst_resm(TBROK, "Failed to turn on the swap file" |
Cyril Hrubis | dfda9f8 | 2014-03-06 13:37:21 +0100 | [diff] [blame] | 67 | ", skipping test iteration"); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | TEST(ltp_syscall(__NR_swapoff, "./swapfile01")); |
| 72 | |
| 73 | if (TEST_RETURN == -1) { |
| 74 | tst_resm(TFAIL | TTERRNO, "Failed to turn off swapfile," |
| 75 | " system reboot after execution of LTP " |
| 76 | "test suite is recommended."); |
| 77 | } else { |
| 78 | tst_resm(TPASS, "Succeeded to turn off swapfile"); |
| 79 | } |
| 80 | } |
| 81 | |
Cyril Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 82 | static void setup(void) |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 83 | { |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 84 | tst_sig(FORK, DEF_HANDLER, cleanup); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 85 | |
Cyril Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 86 | tst_require_root(NULL); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 87 | |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 88 | TEST_PAUSE; |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 89 | |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 90 | tst_tmpdir(); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 91 | |
Cyril Hrubis | 72c0a1b | 2014-03-06 13:40:25 +0100 | [diff] [blame] | 92 | switch ((fs_type = tst_fs_type(cleanup, "."))) { |
Cyril Hrubis | 0f0e348 | 2014-02-27 16:08:04 +0100 | [diff] [blame] | 93 | case TST_NFS_MAGIC: |
| 94 | case TST_TMPFS_MAGIC: |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 95 | tst_brkm(TCONF, cleanup, |
Cyril Hrubis | 0f0e348 | 2014-02-27 16:08:04 +0100 | [diff] [blame] | 96 | "Cannot do swapoff on a file on %s filesystem", |
Cyril Hrubis | 72c0a1b | 2014-03-06 13:40:25 +0100 | [diff] [blame] | 97 | tst_fs_type_name(fs_type)); |
Cyril Hrubis | 0f0e348 | 2014-02-27 16:08:04 +0100 | [diff] [blame] | 98 | break; |
robbiew | 143090a | 2005-01-17 22:10:09 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Xiaoguang Wang | 4694167 | 2014-04-25 10:02:07 +0800 | [diff] [blame] | 101 | if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 102 | tst_brkm(TBROK, cleanup, |
| 103 | "Insufficient disk space to create swap file"); |
robbiew | 143090a | 2005-01-17 22:10:09 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Cyril Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 106 | if (tst_fill_file("swapfile01", 0x00, 1024, 65536)) |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 107 | tst_brkm(TBROK, cleanup, "Failed to create file for swap"); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 108 | |
Cyril Hrubis | dfda9f8 | 2014-03-06 13:37:21 +0100 | [diff] [blame] | 109 | if (system("mkswap swapfile01 > tmpfile 2>&1") != 0) |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 110 | tst_brkm(TBROK, cleanup, "Failed to make swapfile"); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 111 | } |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 112 | |
Cyril Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 113 | static void cleanup(void) |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 114 | { |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 115 | tst_rmdir(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 116 | } |