• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
verify_swapoff(void)20 static void verify_swapoff(void)
21 {
22 	if (tst_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
23 		tst_res(TFAIL | TERRNO, "Failed to turn on the swap file"
24 			 ", skipping test iteration");
25 		return;
26 	}
27 
28 	TEST(tst_syscall(__NR_swapoff, "./swapfile01"));
29 
30 	if (TST_RET == -1) {
31 		tst_res(TFAIL | TTERRNO, "Failed to turn off swapfile,"
32 			" system reboot after execution of LTP "
33 			"test suite is recommended.");
34 	} else {
35 		tst_res(TPASS, "Succeeded to turn off swapfile");
36 	}
37 }
38 
setup(void)39 static void setup(void)
40 {
41 	is_swap_supported("./tstswap");
42 
43 	if (!tst_fs_has_free(".", 64, TST_MB))
44 		tst_brk(TBROK,
45 			"Insufficient disk space to create swap file");
46 
47 	if (tst_fill_file("swapfile01", 0x00, 1024, 65536))
48 		tst_brk(TBROK, "Failed to create file for swap");
49 
50 	if (system("mkswap swapfile01 > tmpfile 2>&1") != 0)
51 		tst_brk(TBROK, "Failed to make swapfile");
52 }
53 
54 static struct tst_test test = {
55 	.needs_root = 1,
56 	.needs_tmpdir = 1,
57 	.test_all = verify_swapoff,
58 	.setup = setup
59 };
60