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