alarm02: simplify using TST_EXP_* macros
PATCH 1/5 alarm02: simplify using TST_EXP_* macros
- copyright update
- description comment reword and turn into docparse format
- remove duplicated includes
- use TST_EXP_PASS and TST_EXP_VAL macros
--- testcases/kernel/syscalls/alarm/alarm02.c | 51 +++++++---------------- 1 file changed, 15 insertions(+), 36 deletions(-)
testcases/kernel/syscalls/alarm/alarm02.c +15 -36
@@ -1,17 +1,17 @@// SPDX-License-Identifier: GPL-2.0-or-later -/* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. +/* +* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. * Author: Billy Jean Horne -* -* Test Description: -* 1) alarm() return UINT_MAX if seconds is UINT_MAX. -* 2) alarm() return UINT_MAX/2 if seconds is UINT_MAX/2. -* 3) alarm() return UINT_MAX/4 if seconds is UINT_MAX/4. +* Copyright (c) Linux Test Project, 2009-2022 */ -#include <unistd.h> -#include <errno.h> -#include <sys/signal.h> -#include <limits.h> +/*\ +* [Description] +* +* Verify that alarm() returns: +* - zero when there was no previously scheduled alarm. +* - number of seconds remaining until any previously scheduled alarm. +*/ #include "tst_test.h"
@@ -29,37 +29,16 @@ static struct tcase {static void verify_alarm (unsigned int n) {struct tcase *tc = &tcases[n]; -unsigned int ret; - alarms_received =0 ; - ret =alarm (tc->sec); -if (ret !=0 ) { -tst_res (TFAIL , -"alarm(%u) returned %ld, when 0 was " , - tc->sec,TST_RET ); -return ; - } +TST_EXP_PASS (alarm (tc->sec),"alarm(%u)" , tc->sec); -TEST (alarm (0 )); -if (alarms_received ==1 ) { -tst_res (TFAIL , -"alarm(%u) signal was received for value %s" , - tc->sec, tc->str); -return ; - } +TST_EXP_VAL (alarm (0 ), tc->sec); -if (tc->sec !=TST_RET ) { +if (alarms_received ==1 )tst_res (TFAIL , -"alarm(%u) returned %ld as unexpected" , - tc->sec,TST_RET ); -return ; - } - -tst_res (TPASS , -"alarm(%u) returned %ld as expected " -"for value %s" , - tc->sec,TST_RET , tc->str); +"alarm(%u) delivered SIGALRM for seconds value %s" , + tc->sec, tc->str); }static void sighandler (int sig)
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/5 alarm03: cleanup and simplify
- copyright udpate
- description comment reword and turn into docparse format
- remove duplicated headers
- use TST_EXP_* macros
--- testcases/kernel/syscalls/alarm/alarm03.c | 41 ++++++----------------- 1 file changed, 10 insertions(+), 31 deletions(-)
testcases/kernel/syscalls/alarm/alarm03.c +10 -31
@@ -2,53 +2,32 @@/* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. * Author: Richard Logan +* Copyright (c) Linux Test Project, 2009-2022 +*/ + +/*\ +* [Description] * -* Test Description: -* The process does a fork: -* 1) By the value returned by child's alarm(0), check whether child -* process cleared the previously specified alarm request or not. -* 2) By the value returned by parent's alarm(0), check whether parent -* process cleared the previously specified alarm request or not. +* Verify that alarms created by alarm() are not inherited by children +* created via fork. */ -#include <errno.h> -#include <signal.h> #include <stdlib.h> -#include <unistd.h> -#include "tst_test.h" static void verify_alarm (void ) {pid_t pid; -TEST (alarm (100 )); +TST_EXP_PASS_SILENT (alarm (100 )); pid =SAFE_FORK ();if (pid ==0 ) { -TEST (alarm (0 )); -if (TST_RET !=0 ) { -tst_res (TFAIL , -"alarm(100), fork, alarm(0) child's " -"alarm returned %ld" ,TST_RET ); - }else { -tst_res (TPASS , -"alarm(100), fork, alarm(0) child's " -"alarm returned %ld" ,TST_RET ); - } +TST_EXP_PASS (alarm (0 ),"alarm(0) in child process" );exit (0 ); } -TEST (alarm (0 )); -if (TST_RET !=100 ) { -tst_res (TFAIL , -"alarm(100), fork, alarm(0) parent's " -"alarm returned %ld" ,TST_RET ); - }else { -tst_res (TPASS , -"alarm(100), fork, alarm(0) parent's " -"alarm returned %ld" ,TST_RET ); - } +TST_EXP_VAL (alarm (0 ),100 ,"alarm(0) in parent process" ); }static struct tst_test test = {
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/5 alarm05: use TST_EXP_* macros
In reply to Avinesh Kumar- turn comment into docparse format
- make check fix: un-initialize static var
- simplify test using TST_EXP_* macros
--- testcases/kernel/syscalls/alarm/alarm05.c | 30 ++++++----------------- 1 file changed, 7 insertions(+), 23 deletions(-)
testcases/kernel/syscalls/alarm/alarm05.c +7 -23
@@ -7,8 +7,9 @@* Copyright (c) 2018 Cyril Hrubis <[email protected]> */ -/* -* Test Description: +/*\ +* [Description] +* * The return value of the alarm system call should be equal to the * amount previously remaining in the alarm clock. * A SIGALRM signal should be received after the specified amount of
@@ -17,34 +18,17 @@#include "tst_test.h" -static volatile int alarms_fired =0 ; +static volatile int alarms_fired;static void run (void ) { -unsigned int ret; - alarms_fired =0 ; - ret =alarm (10 ); -if (ret) -tst_res (TFAIL ,"alarm() returned non-zero" ); -else -tst_res (TPASS ,"alarm() returned zero" ); - +TST_EXP_PASS (alarm (10 ));sleep (1 ); - - ret =alarm (1 ); -if (ret ==9 ) -tst_res (TPASS ,"alarm() returned remainder correctly" ); -else -tst_res (TFAIL ,"alarm() returned wrong remained %u" , ret); - +TST_EXP_VAL (alarm (1 ),9 );sleep (2 ); - -if (alarms_fired ==1 ) -tst_res (TPASS ,"alarm handler fired once" ); -else -tst_res (TFAIL ,"alarm handler filred %u times" , alarms_fired); +TST_EXP_EQ_LU (alarms_fired,1 ); }static void sighandler (int sig)
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/5 alarm06: cleanup and simplify
In reply to Avinesh Kumar- turn description comment into docparse and reword
- remove duplicated headers
- make check fix: un-initialize static var
- test using TST_EXP_* macros
--- testcases/kernel/syscalls/alarm/alarm06.c | 34 +++++------------------ 1 file changed, 7 insertions(+), 27 deletions(-)
testcases/kernel/syscalls/alarm/alarm06.c +7 -27
@@ -5,25 +5,15 @@* Ported to LTP: Wayne Boyer */ -/* -* Check the functionality of the Alarm system call when the time input -* parameter is zero. +/*\ +* [Description] * -* Expected Result: -* The previously specified alarm request should be cancelled and the -* SIGALRM should not be received. +* Verify that any pending alarm() is canceled when seconds is zero. */ -#include <stdio.h> -#include <unistd.h> -#include <sys/types.h> -#include <errno.h> -#include <string.h> -#include <signal.h> -#include "tst_test.h" -static volatile int alarms_received =0 ; +static volatile int alarms_received;static void sigproc (int sig) {
@@ -38,25 +28,15 @@ static void setup(void)static void verify_alarm (void ) { -int ret; - -alarm (2 ); +TST_EXP_PASS_SILENT (alarm (2 ));sleep (1 ); - ret =alarm (0 ); +TST_EXP_VAL (alarm (0 ),1 );/* Wait for signal SIGALRM */ sleep (2 ); -if (alarms_received) -tst_res (TFAIL ,"Received %i alarms" , alarms_received); -else -tst_res (TPASS ,"Received 0 alarms" ); - -if (ret ==1 ) -tst_res (TPASS ,"alarm(0) returned 1" ); -else -tst_res (TFAIL ,"alarm(0) returned %i, expected 1" , ret); +TST_EXP_EQ_LU (alarms_received,0 ); }static struct tst_test test = {
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 5/5 alarm07: cleanup and simplify
In reply to Avinesh Kumar- copyright update
- description comment into docparse format and reword
- remove duplicated headers
- make check fix: un-initialize static var
- use TST_EXP_* macros
--- testcases/kernel/syscalls/alarm/alarm07.c | 31 +++++++++-------------- 1 file changed, 12 insertions(+), 19 deletions(-)
testcases/kernel/syscalls/alarm/alarm07.c +12 -19
@@ -2,45 +2,38 @@/* * Copyright (c) International Business Machines Corp., 2001 * Author: Wayne Boyer +* Copyright (c) Linux Test Project, 2009-2022 +*/ + +/*\ +* [Description] * -* Test Description: -* By the SIGALRM signal, check whether the previously specified alarm request -* was cleared in the child process or not. +* Verify that SIGALRM signal scheduled by alarm() in the parent process +* is not delivered to the child process. */ -#include <unistd.h> #include <stdlib.h> -#include <errno.h> -#include <signal.h> -#include "tst_test.h" -static volatile int alarm_cnt =0 ; +static volatile int alarm_cnt;static void verify_alarm (void ) {pid_t pid; + alarm_cnt =0 ; -TEST (alarm (1 )); +TST_EXP_PASS_SILENT (alarm (1 )); pid =SAFE_FORK ();sleep (3 );if (pid ==0 ) { -if (alarm_cnt ==0 ) { -tst_res (TPASS ,"alarm() request cleared in child" ); - }else { -tst_res (TFAIL ,"alarm() request not cleared in " -"child; alarms received:%d" , alarm_cnt); - } +TST_EXP_EQ_LU (alarm_cnt,0 );exit (0 ); } -if (alarm_cnt !=1 ) -tst_res (TFAIL ,"Sigalarms in parent %i, expected 1" , alarm_cnt); -else -tst_res (TPASS ,"Got 1 sigalarm in parent" ); +TST_EXP_EQ_LU (alarm_cnt,1 ); } static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 5/5] alarm07: cleanup and simplify
Hi Avinesh,
thanks, patchset merged!
testcases/kernel/syscalls/alarm/alarm07.c line 5
Quoted 6 lines
+++
b/testcases/kernel/syscalls/alarm/alarm07.ctestcases/kernel/syscalls/alarm/alarm07.c +1
-0@@ -2,45 +2,38 @@/* * Copyright (c) International Business Machines Corp., 2001 * Author: Wayne Boyer +* Copyright (c) Linux Test Project, 2009-2022
FYI this was 2002 (fixed).
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp