1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * 5f08c3bdfSopenharmony_ci * 1) kill() fails with errno set to EINVAL if given an invalid signal. 6f08c3bdfSopenharmony_ci * 2) kill() fails with errno set to ESRCH if given a non-existent pid. 7f08c3bdfSopenharmony_ci * 3) kill() fails with errno set to ESRCH if the given pid is INT_MIN. 8f08c3bdfSopenharmony_ci * 9f08c3bdfSopenharmony_ci * HISTORY 10f08c3bdfSopenharmony_ci * 07/2001 Ported by Wayne Boyer 11f08c3bdfSopenharmony_ci */ 12f08c3bdfSopenharmony_ci 13f08c3bdfSopenharmony_ci#include <sys/types.h> 14f08c3bdfSopenharmony_ci#include <signal.h> 15f08c3bdfSopenharmony_ci#include <unistd.h> 16f08c3bdfSopenharmony_ci#include "tst_test.h" 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_cistatic pid_t real_pid, fake_pid, int_min_pid; 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_cistatic struct tcase { 21f08c3bdfSopenharmony_ci int test_sig; 22f08c3bdfSopenharmony_ci int exp_errno; 23f08c3bdfSopenharmony_ci pid_t *pid; 24f08c3bdfSopenharmony_ci} tcases[] = { 25f08c3bdfSopenharmony_ci {2000, EINVAL, &real_pid}, 26f08c3bdfSopenharmony_ci {SIGKILL, ESRCH, &fake_pid}, 27f08c3bdfSopenharmony_ci {SIGKILL, ESRCH, &int_min_pid} 28f08c3bdfSopenharmony_ci}; 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_cistatic void verify_kill(unsigned int n) 31f08c3bdfSopenharmony_ci{ 32f08c3bdfSopenharmony_ci struct tcase *tc = &tcases[n]; 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci TEST(kill(*tc->pid, tc->test_sig)); 35f08c3bdfSopenharmony_ci if (TST_RET != -1) { 36f08c3bdfSopenharmony_ci tst_res(TFAIL, "kill should fail but not, return %ld", TST_RET); 37f08c3bdfSopenharmony_ci return; 38f08c3bdfSopenharmony_ci } 39f08c3bdfSopenharmony_ci 40f08c3bdfSopenharmony_ci if (tc->exp_errno == TST_ERR) 41f08c3bdfSopenharmony_ci tst_res(TPASS | TTERRNO, "kill failed as expected"); 42f08c3bdfSopenharmony_ci else 43f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "kill expected %s but got", 44f08c3bdfSopenharmony_ci tst_strerrno(tc->exp_errno)); 45f08c3bdfSopenharmony_ci} 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_cistatic void setup(void) 48f08c3bdfSopenharmony_ci{ 49f08c3bdfSopenharmony_ci real_pid = getpid(); 50f08c3bdfSopenharmony_ci fake_pid = tst_get_unused_pid(); 51f08c3bdfSopenharmony_ci int_min_pid = INT_MIN; 52f08c3bdfSopenharmony_ci} 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_cistatic struct tst_test test = { 55f08c3bdfSopenharmony_ci .test = verify_kill, 56f08c3bdfSopenharmony_ci .tcnt = ARRAY_SIZE(tcases), 57f08c3bdfSopenharmony_ci .setup = setup, 58f08c3bdfSopenharmony_ci}; 59