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