1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * Copyright (C) 2017 Cyril Hrubis <chrubis@suse.cz> 5f08c3bdfSopenharmony_ci * Copyright (c) Linux Test Project, 2002-2022 6f08c3bdfSopenharmony_ci * Ported to LTP: Wayne Boyer 7f08c3bdfSopenharmony_ci */ 8f08c3bdfSopenharmony_ci 9f08c3bdfSopenharmony_ci/*\ 10f08c3bdfSopenharmony_ci * [Description] 11f08c3bdfSopenharmony_ci * 12f08c3bdfSopenharmony_ci * Verify that any pending alarm() is canceled when seconds is zero. 13f08c3bdfSopenharmony_ci */ 14f08c3bdfSopenharmony_ci 15f08c3bdfSopenharmony_ci#include "tst_test.h" 16f08c3bdfSopenharmony_ci 17f08c3bdfSopenharmony_cistatic volatile int alarms_received; 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_cistatic void sigproc(int sig) 20f08c3bdfSopenharmony_ci{ 21f08c3bdfSopenharmony_ci if (sig == SIGALRM) 22f08c3bdfSopenharmony_ci alarms_received++; 23f08c3bdfSopenharmony_ci} 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_cistatic void setup(void) 26f08c3bdfSopenharmony_ci{ 27f08c3bdfSopenharmony_ci SAFE_SIGNAL(SIGALRM, sigproc); 28f08c3bdfSopenharmony_ci} 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_cistatic void verify_alarm(void) 31f08c3bdfSopenharmony_ci{ 32f08c3bdfSopenharmony_ci TST_EXP_PASS_SILENT(alarm(2)); 33f08c3bdfSopenharmony_ci sleep(1); 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_ci TST_EXP_VAL(alarm(0), 1); 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_ci /* Wait for signal SIGALRM */ 38f08c3bdfSopenharmony_ci sleep(2); 39f08c3bdfSopenharmony_ci 40f08c3bdfSopenharmony_ci TST_EXP_EQ_LU(alarms_received, 0); 41f08c3bdfSopenharmony_ci} 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_cistatic struct tst_test test = { 44f08c3bdfSopenharmony_ci .setup = setup, 45f08c3bdfSopenharmony_ci .test_all = verify_alarm, 46f08c3bdfSopenharmony_ci}; 47