1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) Crackerjack Project., 2007 4f08c3bdfSopenharmony_ci * Ported from Crackerjack to LTP by Manas Kumar Nayak maknayak@in.ibm.com> 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/*\ 8f08c3bdfSopenharmony_ci * [Description] 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * Basic tests for the tkill() errors. 11f08c3bdfSopenharmony_ci * 12f08c3bdfSopenharmony_ci * [Algorithm] 13f08c3bdfSopenharmony_ci * 14f08c3bdfSopenharmony_ci * - EINVAL on an invalid thread ID 15f08c3bdfSopenharmony_ci * - ESRCH when no process with the specified thread ID exists 16f08c3bdfSopenharmony_ci */ 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_ci#include <stdio.h> 19f08c3bdfSopenharmony_ci#include <stdlib.h> 20f08c3bdfSopenharmony_ci#include <errno.h> 21f08c3bdfSopenharmony_ci#include <unistd.h> 22f08c3bdfSopenharmony_ci#include <signal.h> 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_ci#include "tst_test.h" 25f08c3bdfSopenharmony_ci#include "lapi/syscalls.h" 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_cistatic pid_t unused_tid; 28f08c3bdfSopenharmony_cistatic pid_t inval_tid = -1; 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_cistruct test_case_t { 31f08c3bdfSopenharmony_ci int *tid; 32f08c3bdfSopenharmony_ci int exp_errno; 33f08c3bdfSopenharmony_ci} tc[] = { 34f08c3bdfSopenharmony_ci {&inval_tid, EINVAL}, 35f08c3bdfSopenharmony_ci {&unused_tid, ESRCH} 36f08c3bdfSopenharmony_ci}; 37f08c3bdfSopenharmony_ci 38f08c3bdfSopenharmony_cistatic void setup(void) 39f08c3bdfSopenharmony_ci{ 40f08c3bdfSopenharmony_ci unused_tid = tst_get_unused_pid(); 41f08c3bdfSopenharmony_ci} 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_cistatic void run(unsigned int i) 44f08c3bdfSopenharmony_ci{ 45f08c3bdfSopenharmony_ci TST_EXP_FAIL(tst_syscall(__NR_tkill, *(tc[i].tid), SIGUSR1), 46f08c3bdfSopenharmony_ci tc[i].exp_errno, "tst_syscall(__NR_tkill) expecting %s", 47f08c3bdfSopenharmony_ci tst_strerrno(tc[i].exp_errno)); 48f08c3bdfSopenharmony_ci} 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_cistatic struct tst_test test = { 51f08c3bdfSopenharmony_ci .tcnt = ARRAY_SIZE(tc), 52f08c3bdfSopenharmony_ci .needs_tmpdir = 1, 53f08c3bdfSopenharmony_ci .setup = setup, 54f08c3bdfSopenharmony_ci .test = run, 55f08c3bdfSopenharmony_ci}; 56