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" |
| 24 | #include "usctest.h" |
| 25 | #include <errno.h> |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 26 | #include <stdlib.h> |
yaberauneya | 77772ef | 2009-10-17 06:53:58 +0000 | [diff] [blame] | 27 | #include "config.h" |
yaberauneya | a2a05e3 | 2009-11-26 14:19:32 +0000 | [diff] [blame] | 28 | #include "linux_syscall_numbers.h" |
Cyril Hrubis | 0f0e348 | 2014-02-27 16:08:04 +0100 | [diff] [blame] | 29 | #include "tst_fs_type.h" |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 30 | |
Cyril Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 31 | static void setup(void); |
| 32 | static void cleanup(void); |
Cyril Hrubis | dfda9f8 | 2014-03-06 13:37:21 +0100 | [diff] [blame^] | 33 | static void verify_swapoff(void); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 34 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 35 | char *TCID = "swapoff01"; |
| 36 | int TST_TOTAL = 1; |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 37 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 38 | int main(int ac, char **av) |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 39 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 40 | int lc; |
| 41 | char *msg; |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 42 | |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 43 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 44 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 45 | |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 46 | setup(); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 47 | |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 48 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 49 | tst_count = 0; |
Cyril Hrubis | dfda9f8 | 2014-03-06 13:37:21 +0100 | [diff] [blame^] | 50 | verify_swapoff(); |
Cyril Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 51 | } |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 52 | |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 53 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 54 | tst_exit(); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Cyril Hrubis | dfda9f8 | 2014-03-06 13:37:21 +0100 | [diff] [blame^] | 57 | static 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 Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 76 | static void setup(void) |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 77 | { |
Cyril Hrubis | 0f0e348 | 2014-02-27 16:08:04 +0100 | [diff] [blame] | 78 | long type; |
| 79 | |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 80 | tst_sig(FORK, DEF_HANDLER, cleanup); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 81 | |
Cyril Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 82 | tst_require_root(NULL); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 83 | |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 84 | TEST_PAUSE; |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 85 | |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 86 | tst_tmpdir(); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 87 | |
Cyril Hrubis | 0f0e348 | 2014-02-27 16:08:04 +0100 | [diff] [blame] | 88 | switch ((type = tst_fs_type(cleanup, "."))) { |
| 89 | case TST_NFS_MAGIC: |
| 90 | case TST_TMPFS_MAGIC: |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 91 | tst_brkm(TCONF, cleanup, |
Cyril Hrubis | 0f0e348 | 2014-02-27 16:08:04 +0100 | [diff] [blame] | 92 | "Cannot do swapoff on a file on %s filesystem", |
| 93 | tst_fs_type_name(type)); |
| 94 | break; |
robbiew | 143090a | 2005-01-17 22:10:09 +0000 | [diff] [blame] | 95 | } |
| 96 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 97 | if (!tst_cwd_has_free(65536)) { |
| 98 | tst_brkm(TBROK, cleanup, |
| 99 | "Insufficient disk space to create swap file"); |
robbiew | 143090a | 2005-01-17 22:10:09 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Cyril Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 102 | if (tst_fill_file("swapfile01", 0x00, 1024, 65536)) |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 103 | tst_brkm(TBROK, cleanup, "Failed to create file for swap"); |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 104 | |
Cyril Hrubis | dfda9f8 | 2014-03-06 13:37:21 +0100 | [diff] [blame^] | 105 | if (system("mkswap swapfile01 > tmpfile 2>&1") != 0) |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 106 | tst_brkm(TBROK, cleanup, "Failed to make swapfile"); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 107 | } |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 108 | |
Cyril Hrubis | 591ddcb | 2014-02-26 18:06:19 +0100 | [diff] [blame] | 109 | static void cleanup(void) |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 110 | { |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 111 | TEST_CLEANUP; |
robbiew | 0abc81f | 2003-01-02 16:45:29 +0000 | [diff] [blame] | 112 | |
robbiew | adc1c01 | 2003-04-29 17:06:59 +0000 | [diff] [blame] | 113 | tst_rmdir(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 114 | } |