1ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew/* 2ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. 3ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew * 4ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew * This program is free software; you can redistribute it and/or modify it 5ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew * under the terms of version 2 of the GNU General Public License as 6ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew * published by the Free Software Foundation. 7ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew * 8ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew * This program is distributed in the hope that it would be useful, but 9ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew * WITHOUT ANY WARRANTY; without even the implied warranty of 10ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew * 12ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew * You should have received a copy of the GNU General Public License along 13fed9641096e27f79a0f2d9adfe9839dd8d11dc0fWanlong Gao * with this program; if not, write the Free Software Foundation, Inc., 14fed9641096e27f79a0f2d9adfe9839dd8d11dc0fWanlong Gao * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 15ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew * 16ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew */ 17f6f4b7f7de8b83c5a0f4f1d647a19b0ba7a5d835Cyril Hrubis 18f6f4b7f7de8b83c5a0f4f1d647a19b0ba7a5d835Cyril Hrubis /* 19f6f4b7f7de8b83c5a0f4f1d647a19b0ba7a5d835Cyril Hrubis * Checks that swapon() succeds with swapfile. 20f6f4b7f7de8b83c5a0f4f1d647a19b0ba7a5d835Cyril Hrubis */ 21ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew 22ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew#include <unistd.h> 2377772ef57f3c92243d1df2064fdb2b321e40227dyaberauneya#include <errno.h> 2477772ef57f3c92243d1df2064fdb2b321e40227dyaberauneya#include <stdlib.h> 25ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew#include "test.h" 2689911a1fbdf83d83b13218a88432b4c59b01fdf1yaberauneya#include "linux_syscall_numbers.h" 274bdda040bc045dd8d921d54d3b54db5dabeb9958Stanislav Kholmanskikh#include "libswapon.h" 28ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew 29f6f4b7f7de8b83c5a0f4f1d647a19b0ba7a5d835Cyril Hrubisstatic void setup(void); 30f6f4b7f7de8b83c5a0f4f1d647a19b0ba7a5d835Cyril Hrubisstatic void cleanup(void); 31ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew 32fdce7d5e2a219d201a2b0e3bab6b61b01ec1d716Cyril Hrubischar *TCID = "swapon01"; 33fdce7d5e2a219d201a2b0e3bab6b61b01ec1d716Cyril Hrubisint TST_TOTAL = 1; 34ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew 35b16efb8afc1a8409db3f4cd5fe0bd092f1fe8317Cyril Hrubisstatic long fs_type; 36b16efb8afc1a8409db3f4cd5fe0bd092f1fe8317Cyril Hrubis 37a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubisstatic void verify_swapon(void) 38a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis{ 39a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0)); 40a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis 41a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis if (TEST_RETURN == -1) { 42b16efb8afc1a8409db3f4cd5fe0bd092f1fe8317Cyril Hrubis if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) { 43b16efb8afc1a8409db3f4cd5fe0bd092f1fe8317Cyril Hrubis tst_brkm(TCONF, cleanup, 44b16efb8afc1a8409db3f4cd5fe0bd092f1fe8317Cyril Hrubis "Swapfile on BTRFS not implemeted"); 45b16efb8afc1a8409db3f4cd5fe0bd092f1fe8317Cyril Hrubis return; 46b16efb8afc1a8409db3f4cd5fe0bd092f1fe8317Cyril Hrubis } 47a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile"); 48a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis } else { 49a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis tst_resm(TPASS, "Succeeded to turn on swapfile"); 50a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis /*we need to turn this swap file off for -i option */ 51a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis if (ltp_syscall(__NR_swapoff, "./swapfile01") != 0) { 52a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis tst_brkm(TBROK, cleanup, "Failed to turn off swapfile," 53a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis " system reboot after execution of LTP " 54a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis "test suite is recommended."); 55a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis } 56a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis } 57a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis} 58a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis 5956207cec7732e09c216c751c0b5f88a242bacae6subrata_modakint main(int ac, char **av) 60ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew{ 61ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew 6289af32a63ce8a780ea39337339e14caae244b5a4Cyril Hrubis int lc; 636b01d689606d971217ccb961f3c44db8c2024d08robbiew 64d6d11d08678aac1ed2c370ea8e42e5f45aea07beCyril Hrubis tst_parse_opts(ac, av, NULL, NULL); 656b01d689606d971217ccb961f3c44db8c2024d08robbiew 666b01d689606d971217ccb961f3c44db8c2024d08robbiew setup(); 676b01d689606d971217ccb961f3c44db8c2024d08robbiew 686b01d689606d971217ccb961f3c44db8c2024d08robbiew for (lc = 0; TEST_LOOPING(lc); lc++) { 69d59a659cd639ca2780b00049d102acd2a783d585Caspar Zhang tst_count = 0; 70a432c4d8a2ef65d31d15acc676c3473816d4af1aCyril Hrubis verify_swapon(); 71f6f4b7f7de8b83c5a0f4f1d647a19b0ba7a5d835Cyril Hrubis } 726b01d689606d971217ccb961f3c44db8c2024d08robbiew 736b01d689606d971217ccb961f3c44db8c2024d08robbiew cleanup(); 741e6f5a673655551de5734ff31ef48cd63b604e6dGarrett Cooper tst_exit(); 75ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew} 76ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew 77f6f4b7f7de8b83c5a0f4f1d647a19b0ba7a5d835Cyril Hrubisstatic void setup(void) 78ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew{ 796b01d689606d971217ccb961f3c44db8c2024d08robbiew tst_sig(FORK, DEF_HANDLER, cleanup); 80ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew 81d1e794d62b1bf619df8390535e4c2a58899b1145Cyril Hrubis tst_require_root(); 82ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew 836b01d689606d971217ccb961f3c44db8c2024d08robbiew TEST_PAUSE; 84ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew 856b01d689606d971217ccb961f3c44db8c2024d08robbiew tst_tmpdir(); 86ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew 87b16efb8afc1a8409db3f4cd5fe0bd092f1fe8317Cyril Hrubis switch ((fs_type = tst_fs_type(cleanup, "."))) { 880f0e3487c46947c6eee21cce1c77aa7e2e3b302aCyril Hrubis case TST_NFS_MAGIC: 890f0e3487c46947c6eee21cce1c77aa7e2e3b302aCyril Hrubis case TST_TMPFS_MAGIC: 9056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak tst_brkm(TCONF, cleanup, 910f0e3487c46947c6eee21cce1c77aa7e2e3b302aCyril Hrubis "Cannot do swapon on a file on %s filesystem", 92b16efb8afc1a8409db3f4cd5fe0bd092f1fe8317Cyril Hrubis tst_fs_type_name(fs_type)); 930f0e3487c46947c6eee21cce1c77aa7e2e3b302aCyril Hrubis break; 94143090a9f7b93c011573dc044a58b2eea48e07e5robbiew } 95143090a9f7b93c011573dc044a58b2eea48e07e5robbiew 964bdda040bc045dd8d921d54d3b54db5dabeb9958Stanislav Kholmanskikh make_swapfile(cleanup, "swapfile01"); 972c28215423293e443469a07ae7011135d058b671Garrett Cooper} 98ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew 99f6f4b7f7de8b83c5a0f4f1d647a19b0ba7a5d835Cyril Hrubisstatic void cleanup(void) 100ac9784e4b6099dba38e356f4dde08a8d91846a48robbiew{ 1016b01d689606d971217ccb961f3c44db8c2024d08robbiew tst_rmdir(); 102ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman} 103