1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4 * Copyright (c) Linux Test Project, 2003-2024
5 */
6
7 /*\
8 * [Description]
9 *
10 * Checks that swapon() succeds with swapfile.
11 */
12
13 #include <unistd.h>
14 #include <errno.h>
15 #include <stdlib.h>
16 #include "tst_test.h"
17 #include "lapi/syscalls.h"
18 #include "libswap.h"
19
20 #define SWAP_FILE "swapfile01"
21
verify_swapon(void)22 static void verify_swapon(void)
23 {
24 TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0));
25
26 if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
27 tst_brk(TBROK | TERRNO,
28 "Failed to turn off swapfile, system reboot recommended");
29 }
30 }
31
setup(void)32 static void setup(void)
33 {
34 is_swap_supported(SWAP_FILE);
35 make_swapfile(SWAP_FILE, 0);
36 }
37
38 static struct tst_test test = {
39 .needs_root = 1,
40 .needs_tmpdir = 1,
41 .test_all = verify_swapon,
42 .setup = setup
43 };
44