timers/timer_create0{2, 3, 4}: Ported to new library
PATCH 1/1 timers/timer_create0{2, 3, 4}: Ported to new library
Merged timer_create0{2,3} into one test, cleaned up and ported the tests to the new library. Also added several missing clocks and made sure that optional clocks are really tested if they are available.
---
Notes:
This is the first step in order to port all the timer tests to the new library. The common_timers.h currently defines a CLEANUP macro which is used by the tests that are still using the old library. The new tests will display an unused-function warning when compiled. This will be removed once the last timer test is ported over.
m4/ltp-time.m4 | 2 +- runtest/timers | 1 - testcases/kernel/timers/include/common_timers.h | 38 +++- testcases/kernel/timers/include/timer_blacklist.h | 40 ++++ testcases/kernel/timers/timer_create/.gitignore | 1 - .../kernel/timers/timer_create/timer_create02.c | 232 +++++++-------------- .../kernel/timers/timer_create/timer_create03.c | 156 -------------- .../kernel/timers/timer_create/timer_create04.c | 226 ++++++-------------- 8 files changed, 217 insertions(+), 479 deletions(-) create mode 100644 testcases/kernel/timers/include/timer_blacklist.h delete mode 100644 testcases/kernel/timers/timer_create/timer_create03.c
m4/ltp-time.m4 +1 -1
@@ -26,7 +26,7 @@ dnl dnl ---------------------------- dnl AC_DEFUN([LTP_CHECK_TIME],[ - AC_CHECK_DECLS([CLOCK_MONOTONIC_RAW, CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_COARSE],,,[ + AC_CHECK_DECLS([CLOCK_MONOTONIC_RAW, CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_COARSE, CLOCK_BOOTTIME, CLOCK_REALTIME_ALARM, CLOCK_BOOTTIME_ALARM, CLOCK_TAI],,,[ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif
runtest/timers +0 -1
@@ -1,6 +1,5 @@ #DESCRIPTION:Posix Timer Tests timer_create02 timer_create02 -timer_create03 timer_create03 timer_create04 timer_create04 timer_delete02 timer_delete02 timer_delete03 timer_delete03
testcases/kernel/timers/include/common_timers.h +31 -7
@@ -6,8 +6,8 @@#ifndef __COMMON_TIMERS_H__#define __COMMON_TIMERS_H__ -#define CLEANUP cleanup +#include "config.h" #include "lapi/syscalls.h"
@@ -19,15 +19,27 @@ clock_t clock_list[] = {CLOCK_MONOTONIC ,CLOCK_PROCESS_CPUTIME_ID ,CLOCK_THREAD_CPUTIME_ID , -#if HAVE_CLOCK_MONOTONIC_RAW +#if HAVE_DECL_CLOCK_MONOTONIC_RAWCLOCK_MONOTONIC_RAW , #endif -#if HAVE_CLOCK_REALTIME_COARSE +#if HAVE_DECL_CLOCK_REALTIME_COARSECLOCK_REALTIME_COARSE , #endif -#if HAVE_CLOCK_MONOTONIC_COARSE +#if HAVE_DECL_CLOCK_MONOTONIC_COARSECLOCK_MONOTONIC_COARSE , #endif +#if HAVE_DECL_CLOCK_BOOTTIME +CLOCK_BOOTTIME , +#endif +#if HAVE_DECL_CLOCK_REALTIME_ALARM +CLOCK_REALTIME_ALARM , +#endif +#if HAVE_DECL_CLOCK_BOOTTIME_ALARM +CLOCK_BOOTTIME_ALARM , +#endif +#if HAVE_DECL_CLOCK_TAI + CLOCK_TAI, +#endif };/* CLOCKS_DEFINED is the number of clock sources defined for sure */ #define CLOCKS_DEFINED (sizeof(clock_list) / sizeof(*clock_list))
@@ -45,14 +57,26 @@ const char *get_clock_str(const int clock_id)CLOCK_TO_STR (CLOCK_MONOTONIC );CLOCK_TO_STR (CLOCK_PROCESS_CPUTIME_ID );CLOCK_TO_STR (CLOCK_THREAD_CPUTIME_ID ); -#if HAVE_CLOCK_MONOTONIC_RAW +#if HAVE_DECL_CLOCK_MONOTONIC_RAW CLOCK_TO_STR (CLOCK_MONOTONIC_RAW );#endif -#if HAVE_CLOCK_REALTIME_COARSE +#if HAVE_DECL_CLOCK_REALTIME_COARSE CLOCK_TO_STR (CLOCK_REALTIME_COARSE );#endif -#if HAVE_CLOCK_MONOTONIC_COARSE +#if HAVE_DECL_CLOCK_MONOTONIC_COARSE CLOCK_TO_STR (CLOCK_MONOTONIC_COARSE ); +#endif +#if HAVE_DECL_CLOCK_BOOTTIME +CLOCK_TO_STR (CLOCK_BOOTTIME ); +#endif +#if HAVE_DECL_CLOCK_REALTIME_ALARM +CLOCK_TO_STR (CLOCK_REALTIME_ALARM ); +#endif +#if HAVE_DECL_CLOCK_BOOTTIME_ALARM +CLOCK_TO_STR (CLOCK_BOOTTIME_ALARM ); +#endif +#if HAVE_DECL_CLOCK_TAI +CLOCK_TO_STR (CLOCK_TAI );#endif default :return "CLOCK_!?!?!?" ;
testcases/kernel/timers/include/timer_blacklist.h new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) SUSE LLC, 2019. All Rights Reserved. +* +* Author: Christian Amann <[email protected]> +*/ +/* +* Provides support to skip (possibly) unsupported clocks for testing +*/ + +#ifndef TIMER_BLACKLIST_H +#define TIMER_BLACKLIST_H + +#define BLACKLIST_SIZE ARRAY_SIZE(blacklist_clocks) + +static kernel_timer_t blacklist_clocks[] = { +#if HAVE_DECL_CLOCK_MONOTONIC_RAW + CLOCK_MONOTONIC_RAW, +#endif +#if HAVE_DECL_CLOCK_MONOTONIC_COARSE + CLOCK_MONOTONIC_COARSE, +#endif +#if HAVE_DECL_CLOCK_REALTIME_COARSE + CLOCK_REALTIME_COARSE, +#endif +}; + +static int skip_clock (kernel_timer_t clock) +{ +unsigned int i; + +for (i =0 ; i <BLACKLIST_SIZE ; ++i) { +if (clock == blacklist_clocks[i]) +return 1 ; + } +return 0 ; +} + + +#endif /* TIMER_BLACKLIST_H */
testcases/kernel/timers/timer_create/.gitignore +0 -1
@@ -1,3 +1,2 @@ /timer_create02 -/timer_create03 /timer_create04
testcases/kernel/timers/timer_create/timer_create02.c +80 -152
257 lines not on this page · raw message
testcases/kernel/timers/timer_create/timer_create03.c deleted +0 -156
156 lines not on this page · raw message
testcases/kernel/timers/timer_create/timer_create04.c +65 -161
252 lines not on this page · raw message
Signature · 1 line
2.16.4
PATCH 1/1 timers/timer_create0{2, 3, 4}: Ported to new library
Hi!
Quoted 115 lines
Merged timer_create0{2,3} into one test, cleaned up and ported the tests to the new library. Also added several missing clocks and made sure that optional clocks are really tested if they are available.
Signed-off-by Christian Amann <[email protected]>---
Notes:
This is the first step in order to port all the timer tests to the new library. Thecommon_timers.hcurrently defines a CLEANUP macro which is used by the tests that are still using the old library. The new tests will display an unused-function warning when compiled. This will be removed once the last timer test is ported over.m4/ltp-time.m4 | 2 +- runtest/timers | 1 - testcases/kernel/timers/include/common_timers.h | 38 +++- testcases/kernel/timers/include/timer_blacklist.h | 40 ++++ testcases/kernel/timers/timer_create/.gitignore | 1 - .../kernel/timers/timer_create/timer_create02.c | 232 +++++++-------------- .../kernel/timers/timer_create/timer_create03.c | 156 -------------- .../kernel/timers/timer_create/timer_create04.c | 226 ++++++-------------- 8 files changed, 217 insertions(+), 479 deletions(-) create mode 100644 testcases/kernel/timers/include/timer_blacklist.h delete mode 100644 testcases/kernel/timers/timer_create/timer_create03.cm4/ltp-time.m4 +1
-1@@ -26,7 +26,7 @@ dnl dnl ---------------------------- dnl AC_DEFUN([LTP_CHECK_TIME],[ - AC_CHECK_DECLS([CLOCK_MONOTONIC_RAW, CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_COARSE],,,[ + AC_CHECK_DECLS([CLOCK_MONOTONIC_RAW, CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_COARSE, CLOCK_BOOTTIME, CLOCK_REALTIME_ALARM, CLOCK_BOOTTIME_ALARM, CLOCK_TAI],,,[ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endifruntest/timers +0
-1@@ -1,6 +1,5 @@ #DESCRIPTION:Posix Timer Tests timer_create02 timer_create02 -timer_create03 timer_create03 timer_create04 timer_create04 timer_delete02 timer_delete02 timer_delete03 timer_delete03testcases/kernel/timers/include/common_timers.h +24
-7@@ -6,8 +6,8 @@#ifndef __COMMON_TIMERS_H__#define __COMMON_TIMERS_H__ -#define CLEANUP cleanup +#include "config.h" #include "lapi/syscalls.h" @@ -19,15 +19,27 @@ clock_t clock_list[] = {CLOCK_MONOTONIC ,CLOCK_PROCESS_CPUTIME_ID ,CLOCK_THREAD_CPUTIME_ID , -#if HAVE_CLOCK_MONOTONIC_RAW +#if HAVE_DECL_CLOCK_MONOTONIC_RAWCLOCK_MONOTONIC_RAW , #endif -#if HAVE_CLOCK_REALTIME_COARSE +#if HAVE_DECL_CLOCK_REALTIME_COARSECLOCK_REALTIME_COARSE , #endif -#if HAVE_CLOCK_MONOTONIC_COARSE +#if HAVE_DECL_CLOCK_MONOTONIC_COARSECLOCK_MONOTONIC_COARSE , #endif +#if HAVE_DECL_CLOCK_BOOTTIME +CLOCK_BOOTTIME , +#endif +#if HAVE_DECL_CLOCK_REALTIME_ALARM +CLOCK_REALTIME_ALARM , +#endif +#if HAVE_DECL_CLOCK_BOOTTIME_ALARM +CLOCK_BOOTTIME_ALARM , +#endif +#if HAVE_DECL_CLOCK_TAI + CLOCK_TAI, +#endif };/* CLOCKS_DEFINED is the number of clock sources defined for sure */ #define CLOCKS_DEFINED (sizeof(clock_list) / sizeof(*clock_list))@@ -45,14 +57,26 @@ const char *get_clock_str(const int clock_id)CLOCK_TO_STR (CLOCK_MONOTONIC );CLOCK_TO_STR (CLOCK_PROCESS_CPUTIME_ID );CLOCK_TO_STR (CLOCK_THREAD_CPUTIME_ID ); -#if HAVE_CLOCK_MONOTONIC_RAW +#if HAVE_DECL_CLOCK_MONOTONIC_RAW CLOCK_TO_STR (CLOCK_MONOTONIC_RAW );#endif -#if HAVE_CLOCK_REALTIME_COARSE +#if HAVE_DECL_CLOCK_REALTIME_COARSE CLOCK_TO_STR (CLOCK_REALTIME_COARSE );#endif -#if HAVE_CLOCK_MONOTONIC_COARSE +#if HAVE_DECL_CLOCK_MONOTONIC_COARSE CLOCK_TO_STR (CLOCK_MONOTONIC_COARSE ); +#endif +#if HAVE_DECL_CLOCK_BOOTTIME +CLOCK_TO_STR (CLOCK_BOOTTIME ); +#endif +#if HAVE_DECL_CLOCK_REALTIME_ALARM
testcases/kernel/timers/include/common_timers.h const char *get_clock_str(const int clock_id) · line 82
Quoted 10 lines
testcases/kernel/timers/include/common_timers.h +7
-0+CLOCK_TO_STR (CLOCK_REALTIME_ALARM ); +#endif +#if HAVE_DECL_CLOCK_BOOTTIME_ALARM +CLOCK_TO_STR (CLOCK_BOOTTIME_ALARM ); +#endif +#if HAVE_DECL_CLOCK_TAI +CLOCK_TO_STR (CLOCK_TAI );#endif default :return "CLOCK_!?!?!?" ;
Can we change this for a fallback defitions and runtime detection?
In the clock_gettime01.c test we decided that subset of clocks should be always present and working and that the newer ones can exit with EINVAL which means that they are not supported on currenlty running kernel.
Quoted 282 lines
testcases/kernel/timers/include/timer_blacklist.h new file +40
-0@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) SUSE LLC, 2019. All Rights Reserved. +* +* Author: Christian Amann <[email protected]> +*/ +/* +* Provides support to skip (possibly) unsupported clocks for testing +*/ + +#ifndef TIMER_BLACKLIST_H +#define TIMER_BLACKLIST_H + +#define BLACKLIST_SIZE ARRAY_SIZE(blacklist_clocks) + +static kernel_timer_t blacklist_clocks[] = { +#if HAVE_DECL_CLOCK_MONOTONIC_RAW + CLOCK_MONOTONIC_RAW, +#endif +#if HAVE_DECL_CLOCK_MONOTONIC_COARSE + CLOCK_MONOTONIC_COARSE, +#endif +#if HAVE_DECL_CLOCK_REALTIME_COARSE + CLOCK_REALTIME_COARSE, +#endif +}; + +static int skip_clock (kernel_timer_t clock) +{ +unsigned int i; + +for (i =0 ; i <BLACKLIST_SIZE ; ++i) { +if (clock == blacklist_clocks[i]) +return 1 ; + } +return 0 ; +} + + +#endif /* TIMER_BLACKLIST_H */ testcases/kernel/timers/timer_create/.gitignore +0
-1@@ -1,3 +1,2 @@ /timer_create02 -/timer_create03 /timer_create04testcases/kernel/timers/timer_create/timer_create02.c +68
-134@@ -1,177 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) Wipro Technologies Ltd, 2003. All Rights Reserved. * -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +* Author: Aniruddha Marathe <[email protected]> * +* Ported to new library: +* 07/2019 Christian Amann <[email protected]> */ -/************************************************************************** -* -* TEST IDENTIFIER : timer_create02 -* -* EXECUTED BY : anyone -* -* TEST TITLE : Basic test for timer_create(2) -* -* TEST CASE TOTAL : 3 -* -* AUTHOR : Aniruddha Marathe <[email protected]> -* -* SIGNALS -* Uses SIGUSR1 to pause before test if option set. -* (See the parse_opts(3) man page). -* -* DESCRIPTION -* This is a Phase I test for the timer_create(2) system call. -* It is intended to provide a limited exposure of the system call. -* -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call with different notification types for -* clock ID CLOCK_REALTIME -* Check return code, if system call failed (return=-1) -* Log the errno and Issue a FAIL message. -* Otherwise, Issue a PASS message. -* -* Cleanup: -* Print errno log and/or timing stats if options given +/* * -* USAGE: <for command-line> -* timer_create02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p] -* where: -* -c n : Run n copies simultaneously. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -p : Pause for SIGUSR1 before starting -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. +* Basic test for timer_create(2): * -*RESTRICTIONS: -* None -*****************************************************************************/ +* Creates a timer for each available clock using the +* following notification types: +* 1) SIGEV_NONE +* 2) SIGEV_SIGNAL +* 3) SIGEV_THREAD +* 4) SIGEV_THREAD_ID +* 5) NULL +*/ -#include <stdlib.h> -#include <errno.h> -#include <time.h> #include <signal.h> - -#include "test.h" +#include <time.h> +#include "tst_test.h" +#include "tst_safe_macros.h" #include "common_timers.h" - -void setup (void ); -void setup_test (int option); - -char *TCID ="timer_create02" ;/* Test program identifier. */ -int TST_TOTAL =3 ;/* Total number of test cases. */ -static struct sigevent evp, *evp_ptr; - -int main (int ac,char **av) +#include "timer_blacklist.h" + +static struct sigevent evp; + +static struct notif_type { +int sigev_signo; +int sigev_notify; +char *message; +struct sigevent *sevp; +} types[] = { + {SIGALRM ,SIGEV_NONE ,"SIGEV_NONE" , &evp}, + {SIGALRM ,SIGEV_SIGNAL ,"SIGEV_SIGNAL" , &evp}, + {SIGALRM ,SIGEV_THREAD ,"SIGEV_THREAD" , &evp}, + {SIGALRM ,SIGEV_THREAD_ID ,"SIGEV_THREAD_ID" , &evp}, + {0 ,0 ,"NULL" ,NULL }, +}; + +static void run (unsigned int n) { -int lc, i, j; -kernel_timer_t created_timer_id;/* holds the returned timer_id */ -char *message[3 ] = { -"SIGEV_SIGNAL" , -"NULL" , -"SIGEV_NONE" - }; -const char *mrstr ="MONOTONIC_RAW" ; - -tst_parse_opts (ac, av,NULL ,NULL ); +unsigned int i, errors; +struct notif_type *nt = &types[n]; +kernel_timer_t created_timer_id; -setup (); +tst_res (TINFO ,"Testing notification type: %s" , nt->message); -for (lc =0 ;TEST_LOOPING (lc); lc++) { +memset (&evp,0 ,sizeof (evp)); - tst_count =0 ; + errors =0 ; +for (i =0 ; i <CLOCKS_DEFINED ; ++i) { +clock_t clock = clock_list[i]; -for (i =0 ; i <TST_TOTAL ; i++) { +if (skip_clock (clock)) +continue ; -setup_test (i); + evp.sigev_value = (union sigval )0 ; + evp.sigev_signo = nt->sigev_signo; + evp.sigev_notify = nt->sigev_notify; -for (j =0 ; j <CLOCKS_DEFINED ; ++j) { +if (strstr (get_clock_str (clock),"CPUTIME_ID" )) { +/* (PROCESS_CPUTIME_ID & +* THREAD_CPUTIME_ID) +* is not supported on kernel versions +* lower than 2.6.12 +*/ +if ((tst_kvercmp (2 ,6 ,12 )) <0 ) +continue ; + } +if (!strcmp (get_clock_str (clock),"MONOTONIC_RAW" )) +continue ; -if (strstr (get_clock_str (clock_list[j]), -"CPUTIME_ID" )) { -/* (PROCESS_CPUTIME_ID & -* THREAD_CPUTIME_ID) -* is not supported on kernel versions -* lower than 2.6.12 -*/ -if ((tst_kvercmp (2 ,6 ,12 )) <0 ) { -continue ; - } - } -if (strstr (get_clock_str (clock_list[j]), mrstr)) -continue ; +if (!strcmp (nt->message,"SIGEV_THREAD_ID" )) + evp._sigev_un._tid =getpid (); -TEST (ltp_syscall (__NR_timer_create, - clock_list[j], evp_ptr, - &created_timer_id)); +TEST (tst_syscall (__NR_timer_create, + clock, nt->sevp, + &created_timer_id)); -tst_resm ((TEST_RETURN ==0 ? -TPASS : -TFAIL |TTERRNO ), -"%s %s with notification type = %s" , -get_clock_str (clock_list[j]), - (TEST_RETURN ==0 ? -"passed" :"failed" ), message[i]); - } +if (TST_RET !=0 ) { +tst_res (TFAIL |TTERRNO , +"Clock %s failed" ,get_clock_str (clock)); + errors++; } - } -cleanup (); -tst_exit (); -} - -/* setup_test() - sets up individual test */ -void setup_test (int option) -{ -switch (option) { -case 0 : - evp.sigev_value = (union sigval )0 ; - evp.sigev_signo =SIGALRM ; - evp.sigev_notify =SIGEV_SIGNAL ; - evp_ptr = &evp; -break ; -case 1 : - evp_ptr =NULL ; -break ; -case 2 : - evp.sigev_value = (union sigval )0 ; - evp.sigev_signo =SIGALRM ;/* any will do */ - evp.sigev_notify =SIGEV_NONE ;
testcases/kernel/timers/timer_create/timer_create02.c line 97
Quoted 10 lines
testcases/kernel/timers/timer_create/timer_create02.c +7
-2- evp_ptr = &evp; -break ; +TEST (tst_syscall (__NR_timer_delete, created_timer_id)); +if (TST_RET !=0 ) { +tst_res (TINFO ,"Failed to delete timer %s" , +get_clock_str (clock)); + } } +if (!errors) +tst_res (TPASS ,"All clocks passed!" );
Can we instead print PASS/FAIL for each type of clock?
Also this is a big rewrite so the patch would be easier to read with the -B parameter passed to git format-patch.
Signature · 2 lines
Cyril Hrubis [email protected]