1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) Linux Test Project, 2009-2021 4f08c3bdfSopenharmony_ci * Copyright (c) Crackerjack Project, 2007 5f08c3bdfSopenharmony_ci * Ported from Crackerjack to LTP by Manas Kumar Nayak maknayak@in.ibm.com> 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci/*\ 9f08c3bdfSopenharmony_ci * [Description] 10f08c3bdfSopenharmony_ci * 11f08c3bdfSopenharmony_ci * Basic tests for the tkill syscall. 12f08c3bdfSopenharmony_ci * 13f08c3bdfSopenharmony_ci * [Algorithm] 14f08c3bdfSopenharmony_ci * 15f08c3bdfSopenharmony_ci * Calls tkill and capture signal to verify success. 16f08c3bdfSopenharmony_ci */ 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_ci#include <signal.h> 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_ci#include "tst_test.h" 21f08c3bdfSopenharmony_ci#include "lapi/syscalls.h" 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_cistatic volatile sig_atomic_t sig_flag; 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_cistatic void sighandler(int sig) 26f08c3bdfSopenharmony_ci{ 27f08c3bdfSopenharmony_ci if (sig == SIGUSR1) 28f08c3bdfSopenharmony_ci sig_flag = 1; 29f08c3bdfSopenharmony_ci} 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_cistatic void setup(void) 32f08c3bdfSopenharmony_ci{ 33f08c3bdfSopenharmony_ci SAFE_SIGNAL(SIGUSR1, sighandler); 34f08c3bdfSopenharmony_ci} 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_cistatic void run(void) 37f08c3bdfSopenharmony_ci{ 38f08c3bdfSopenharmony_ci int tid; 39f08c3bdfSopenharmony_ci int timeout_ms = 1000; 40f08c3bdfSopenharmony_ci sig_flag = 0; 41f08c3bdfSopenharmony_ci 42f08c3bdfSopenharmony_ci tid = tst_syscall(__NR_gettid); 43f08c3bdfSopenharmony_ci TST_EXP_PASS(tst_syscall(__NR_tkill, tid, SIGUSR1)); 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_ci while (timeout_ms--) { 46f08c3bdfSopenharmony_ci if (sig_flag) 47f08c3bdfSopenharmony_ci break; 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_ci usleep(1000); 50f08c3bdfSopenharmony_ci } 51f08c3bdfSopenharmony_ci 52f08c3bdfSopenharmony_ci if (sig_flag) 53f08c3bdfSopenharmony_ci tst_res(TPASS, "signal captured"); 54f08c3bdfSopenharmony_ci else 55f08c3bdfSopenharmony_ci tst_res(TFAIL, "signal not captured"); 56f08c3bdfSopenharmony_ci} 57f08c3bdfSopenharmony_ci 58f08c3bdfSopenharmony_cistatic struct tst_test test = { 59f08c3bdfSopenharmony_ci .needs_tmpdir = 1, 60f08c3bdfSopenharmony_ci .setup = setup, 61f08c3bdfSopenharmony_ci .test_all = run, 62f08c3bdfSopenharmony_ci}; 63