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 * Checks that swapon() succeds with swapfile. 10f08c3bdfSopenharmony_ci */ 11f08c3bdfSopenharmony_ci 12f08c3bdfSopenharmony_ci#include <unistd.h> 13f08c3bdfSopenharmony_ci#include <errno.h> 14f08c3bdfSopenharmony_ci#include <stdlib.h> 15f08c3bdfSopenharmony_ci#include "tst_test.h" 16f08c3bdfSopenharmony_ci#include "lapi/syscalls.h" 17f08c3bdfSopenharmony_ci#include "libswap.h" 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_cistatic void verify_swapon(void) 20f08c3bdfSopenharmony_ci{ 21f08c3bdfSopenharmony_ci TEST(tst_syscall(__NR_swapon, "./swapfile01", 0)); 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_ci if (TST_RET == -1) { 24f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "Failed to turn on swapfile"); 25f08c3bdfSopenharmony_ci } else { 26f08c3bdfSopenharmony_ci tst_res(TPASS, "Succeeded to turn on swapfile"); 27f08c3bdfSopenharmony_ci /*we need to turn this swap file off for -i option */ 28f08c3bdfSopenharmony_ci if (tst_syscall(__NR_swapoff, "./swapfile01") != 0) { 29f08c3bdfSopenharmony_ci tst_brk(TBROK | TERRNO, "Failed to turn off swapfile," 30f08c3bdfSopenharmony_ci " system reboot after execution of LTP " 31f08c3bdfSopenharmony_ci "test suite is recommended."); 32f08c3bdfSopenharmony_ci } 33f08c3bdfSopenharmony_ci } 34f08c3bdfSopenharmony_ci} 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_cistatic void setup(void) 37f08c3bdfSopenharmony_ci{ 38f08c3bdfSopenharmony_ci is_swap_supported("./tstswap"); 39f08c3bdfSopenharmony_ci make_swapfile("swapfile01", 0); 40f08c3bdfSopenharmony_ci} 41f08c3bdfSopenharmony_ci 42f08c3bdfSopenharmony_cistatic struct tst_test test = { 43f08c3bdfSopenharmony_ci .needs_tmpdir = 1, 44f08c3bdfSopenharmony_ci .test_all = verify_swapon, 45f08c3bdfSopenharmony_ci .setup = setup 46f08c3bdfSopenharmony_ci}; 47