robbiew | ac9784e | 2003-01-03 17:17:46 +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 | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
Cyril Hrubis | f6f4b7f | 2014-02-26 17:45:31 +0100 | [diff] [blame] | 17 | |
| 18 | /* |
| 19 | * Checks that swapon() succeds with swapfile. |
| 20 | */ |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 21 | |
| 22 | #include <unistd.h> |
yaberauneya | 77772ef | 2009-10-17 06:53:58 +0000 | [diff] [blame] | 23 | #include <errno.h> |
| 24 | #include <stdlib.h> |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 25 | #include "test.h" |
yaberauneya | 89911a1 | 2009-11-26 14:11:35 +0000 | [diff] [blame] | 26 | #include "linux_syscall_numbers.h" |
Cyril Hrubis | 0f0e348 | 2014-02-27 16:08:04 +0100 | [diff] [blame] | 27 | #include "tst_fs_type.h" |
Stanislav Kholmanskikh | 4bdda04 | 2013-08-14 10:01:47 +0400 | [diff] [blame] | 28 | #include "libswapon.h" |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 29 | |
Cyril Hrubis | f6f4b7f | 2014-02-26 17:45:31 +0100 | [diff] [blame] | 30 | static void setup(void); |
| 31 | static void cleanup(void); |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 32 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 33 | char *TCID = "swapon01"; |
| 34 | int TST_TOTAL = 1; |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 35 | |
Cyril Hrubis | b16efb8 | 2014-03-06 14:49:17 +0100 | [diff] [blame] | 36 | static long fs_type; |
| 37 | |
Cyril Hrubis | a432c4d | 2014-03-06 14:28:30 +0100 | [diff] [blame] | 38 | static void verify_swapon(void) |
| 39 | { |
| 40 | TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0)); |
| 41 | |
| 42 | if (TEST_RETURN == -1) { |
Cyril Hrubis | b16efb8 | 2014-03-06 14:49:17 +0100 | [diff] [blame] | 43 | if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) { |
| 44 | tst_brkm(TCONF, cleanup, |
| 45 | "Swapfile on BTRFS not implemeted"); |
| 46 | return; |
| 47 | } |
Cyril Hrubis | a432c4d | 2014-03-06 14:28:30 +0100 | [diff] [blame] | 48 | 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_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 60 | int main(int ac, char **av) |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 61 | { |
| 62 | |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 63 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 64 | const char *msg; |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 65 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 66 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 62383b8 | 2010-11-22 12:02:14 -0800 | [diff] [blame] | 67 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 68 | |
robbiew | 6b01d68 | 2003-04-28 20:27:26 +0000 | [diff] [blame] | 69 | setup(); |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 70 | |
robbiew | 6b01d68 | 2003-04-28 20:27:26 +0000 | [diff] [blame] | 71 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 72 | tst_count = 0; |
Cyril Hrubis | a432c4d | 2014-03-06 14:28:30 +0100 | [diff] [blame] | 73 | verify_swapon(); |
Cyril Hrubis | f6f4b7f | 2014-02-26 17:45:31 +0100 | [diff] [blame] | 74 | } |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 75 | |
robbiew | 6b01d68 | 2003-04-28 20:27:26 +0000 | [diff] [blame] | 76 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 77 | tst_exit(); |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Cyril Hrubis | f6f4b7f | 2014-02-26 17:45:31 +0100 | [diff] [blame] | 80 | static void setup(void) |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 81 | { |
robbiew | 6b01d68 | 2003-04-28 20:27:26 +0000 | [diff] [blame] | 82 | tst_sig(FORK, DEF_HANDLER, cleanup); |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 83 | |
Cyril Hrubis | f6f4b7f | 2014-02-26 17:45:31 +0100 | [diff] [blame] | 84 | tst_require_root(NULL); |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 85 | |
robbiew | 6b01d68 | 2003-04-28 20:27:26 +0000 | [diff] [blame] | 86 | TEST_PAUSE; |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 87 | |
robbiew | 6b01d68 | 2003-04-28 20:27:26 +0000 | [diff] [blame] | 88 | tst_tmpdir(); |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 89 | |
Cyril Hrubis | b16efb8 | 2014-03-06 14:49:17 +0100 | [diff] [blame] | 90 | switch ((fs_type = tst_fs_type(cleanup, "."))) { |
Cyril Hrubis | 0f0e348 | 2014-02-27 16:08:04 +0100 | [diff] [blame] | 91 | case TST_NFS_MAGIC: |
| 92 | case TST_TMPFS_MAGIC: |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 93 | tst_brkm(TCONF, cleanup, |
Cyril Hrubis | 0f0e348 | 2014-02-27 16:08:04 +0100 | [diff] [blame] | 94 | "Cannot do swapon on a file on %s filesystem", |
Cyril Hrubis | b16efb8 | 2014-03-06 14:49:17 +0100 | [diff] [blame] | 95 | tst_fs_type_name(fs_type)); |
Cyril Hrubis | 0f0e348 | 2014-02-27 16:08:04 +0100 | [diff] [blame] | 96 | break; |
robbiew | 143090a | 2005-01-17 22:10:09 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Stanislav Kholmanskikh | 4bdda04 | 2013-08-14 10:01:47 +0400 | [diff] [blame] | 99 | make_swapfile(cleanup, "swapfile01"); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 100 | } |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 101 | |
Cyril Hrubis | f6f4b7f | 2014-02-26 17:45:31 +0100 | [diff] [blame] | 102 | static void cleanup(void) |
robbiew | ac9784e | 2003-01-03 17:17:46 +0000 | [diff] [blame] | 103 | { |
robbiew | 6b01d68 | 2003-04-28 20:27:26 +0000 | [diff] [blame] | 104 | tst_rmdir(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 105 | } |