1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001,2005 4f08c3bdfSopenharmony_ci * Ported to LTP: Wayne Boyer 5f08c3bdfSopenharmony_ci * 06/2005 Test for alarm cleanup by Amos Waterland 6f08c3bdfSopenharmony_ci * 7f08c3bdfSopenharmony_ci * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz> 8f08c3bdfSopenharmony_ci * Copyright (c) Linux Test Project, 2006-2022 9f08c3bdfSopenharmony_ci */ 10f08c3bdfSopenharmony_ci 11f08c3bdfSopenharmony_ci/*\ 12f08c3bdfSopenharmony_ci * [Description] 13f08c3bdfSopenharmony_ci * 14f08c3bdfSopenharmony_ci * The return value of the alarm system call should be equal to the 15f08c3bdfSopenharmony_ci * amount previously remaining in the alarm clock. 16f08c3bdfSopenharmony_ci * A SIGALRM signal should be received after the specified amount of 17f08c3bdfSopenharmony_ci * time has elapsed. 18f08c3bdfSopenharmony_ci */ 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_ci#include "tst_test.h" 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_cistatic volatile int alarms_fired; 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_cistatic void run(void) 25f08c3bdfSopenharmony_ci{ 26f08c3bdfSopenharmony_ci alarms_fired = 0; 27f08c3bdfSopenharmony_ci 28f08c3bdfSopenharmony_ci TST_EXP_PASS(alarm(10)); 29f08c3bdfSopenharmony_ci sleep(1); 30f08c3bdfSopenharmony_ci TST_EXP_VAL(alarm(1), 9); 31f08c3bdfSopenharmony_ci sleep(2); 32f08c3bdfSopenharmony_ci TST_EXP_EQ_LU(alarms_fired, 1); 33f08c3bdfSopenharmony_ci} 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_cistatic void sighandler(int sig) 36f08c3bdfSopenharmony_ci{ 37f08c3bdfSopenharmony_ci if (sig == SIGALRM) 38f08c3bdfSopenharmony_ci alarms_fired++; 39f08c3bdfSopenharmony_ci} 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_cistatic void setup(void) 42f08c3bdfSopenharmony_ci{ 43f08c3bdfSopenharmony_ci SAFE_SIGNAL(SIGALRM, sighandler); 44f08c3bdfSopenharmony_ci} 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_cistatic struct tst_test test = { 47f08c3bdfSopenharmony_ci .test_all = run, 48f08c3bdfSopenharmony_ci .setup = setup, 49f08c3bdfSopenharmony_ci}; 50