1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4 */
5
6 /*\
7 * [Description]
8 *
9 * Check that swapoff() succeeds.
10 */
11
12 #include <unistd.h>
13 #include <errno.h>
14 #include <stdlib.h>
15
16 #include "tst_test.h"
17 #include "lapi/syscalls.h"
18 #include "libswap.h"
19
20 #define MNTPOINT "mntpoint"
21 #define TEST_FILE MNTPOINT"/testswap"
22 #define SWAP_FILE MNTPOINT"/swapfile"
23
verify_swapoff(void)24 static void verify_swapoff(void)
25 {
26 if (tst_syscall(__NR_swapon, SWAP_FILE, 0) != 0) {
27 tst_res(TFAIL | TERRNO, "Failed to turn on the swap file"
28 ", skipping test iteration");
29 return;
30 }
31
32 TEST(tst_syscall(__NR_swapoff, SWAP_FILE));
33
34 if (TST_RET == -1) {
35 tst_res(TFAIL | TTERRNO, "Failed to turn off swapfile,"
36 " system reboot after execution of LTP "
37 "test suite is recommended.");
38 } else {
39 tst_res(TPASS, "Succeeded to turn off swapfile");
40 }
41 }
42
setup(void)43 static void setup(void)
44 {
45 is_swap_supported(TEST_FILE);
46 SAFE_MAKE_SWAPFILE_BLKS(SWAP_FILE, 65536);
47 }
48
49 static struct tst_test test = {
50 .mntpoint = MNTPOINT,
51 .mount_device = 1,
52 .dev_min_size = 350,
53 .all_filesystems = 1,
54 .needs_root = 1,
55 .test_all = verify_swapoff,
56 .setup = setup
57 };
58