timers/timer_create0{2, 3, 4}: Ported to new library
PATCH v2 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 missing clocks and made sure that optional clocks are tested if they are not available and fail at runtime.
---
Notes:
Please ignore the compiler warning about an unused cleanup function. This will be removed once the whole set of testcases is ported over to the new LTP-library.
include/lapi/posix_clocks.h | 4 + runtest/timers | 1 - testcases/kernel/timers/include/common_timers.h | 45 ++-- testcases/kernel/timers/timer_create/.gitignore | 1 - .../kernel/timers/timer_create/timer_create02.c | 286 ++++++++------------- .../kernel/timers/timer_create/timer_create03.c | 156 ----------- .../kernel/timers/timer_create/timer_create04.c | 285 +++++++------------- 7 files changed, 236 insertions(+), 542 deletions(-) rewrite testcases/kernel/timers/timer_create/timer_create02.c (95%) delete mode 100644 testcases/kernel/timers/timer_create/timer_create03.c
rewrite testcases/kernel/timers/timer_create/timer_create04.c (94%)
include/lapi/posix_clocks.h +4 -0
@@ -35,4 +35,8 @@# define CLOCK_BOOTTIME_ALARM 9#endif +#ifndef CLOCK_TAI +#define CLOCK_TAI 11 +#endif +#endif /* POSIX_CLOCKS_H__ */
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 +25 -20
78 lines not on this page · raw message
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 +109 -177
286 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 +98 -187
285 lines not on this page · raw message
Signature · 1 line
2.16.4
PATCH v2 1/1 timers/timer_create0{2, 3, 4}: Ported to new library
Hi!
Quoted 19 lines
testcases/kernel/timers/timer_create/timer_create02.c +19
-0+// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) Wipro Technologies Ltd, 2003. All Rights Reserved. +* +* Author: Aniruddha Marathe <[email protected]> +* +* Ported to new library: +* 07/2019 Christian Amann <[email protected]> +*/ +/* +* +* Basic test for timer_create(2): +* +* 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
testcases/kernel/timers/timer_create/timer_create02.c line 29
Quoted 10 lines
testcases/kernel/timers/timer_create/timer_create02.c +10
-0+* 5) NULL +*/ + +#include <signal.h> +#include <time.h> +#include "tst_test.h" +#include "tst_safe_macros.h" +#include "common_timers.h" + +static struct sigevent evp;
I guess that there is no reason for evp to be global variable now.
Quoted 21 lines
testcases/kernel/timers/timer_create/timer_create02.c +21
-0+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) +{ +unsigned int i; +struct notif_type *nt = &types[n]; +kernel_timer_t created_timer_id; + +tst_res (TINFO ,"Testing notification type: %s" , nt->message); +
testcases/kernel/timers/timer_create/timer_create02.c line 61
Quoted 10 lines
testcases/kernel/timers/timer_create/timer_create02.c +10
-0+memset (&evp,0 ,sizeof (evp)); + +for (i =0 ; i <CLOCKS_DEFINED ; ++i) { +clock_t clock = clock_list[i]; + + evp.sigev_value = (union sigval )0 ; + evp.sigev_signo = nt->sigev_signo; + evp.sigev_notify = nt->sigev_notify; + +if (strstr (get_clock_str (clock),"CPUTIME_ID" )) {
Maybe even here we can go for explicit:
clock == CLOCK_PROCESS_CPUTIME_ID || clock == CLOCK_THREAD_CPUTIME_ID
testcases/kernel/timers/timer_create/timer_create02.c line 71
Quoted 10 lines
testcases/kernel/timers/timer_create/timer_create02.c +10
-0+/* (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 ;
Why not just clock == CLOCK_MONOTONIC_RAW ?
testcases/kernel/timers/timer_create/timer_create02.c line 74
Quoted 2 lines
testcases/kernel/timers/timer_create/timer_create02.c +2
-0+if (!strcmp (nt->message,"SIGEV_THREAD_ID" )) + evp._sigev_un._tid =getpid ();
Here as well, why not just nt->sigev_notify == SIGEV_THREAD_ID ?
testcases/kernel/timers/timer_create/timer_create02.c line 85
Quoted 10 lines
testcases/kernel/timers/timer_create/timer_create02.c +10
-0+TEST (tst_syscall (__NR_timer_create, + clock, nt->sevp, + &created_timer_id)); + +if (TST_RET !=0 ) { +if (allowed_to_fail (clock) &&TST_ERR ==EINVAL ) { +tst_res (TPASS , +"%s unsupported, failed as expected: %s" , +get_clock_str (clock), +tst_strerrno (TST_ERR ));
^
You can use TTERRNO flag here instead.
Quoted 4 lines
testcases/kernel/timers/timer_create/timer_create02.c +4
-0+ }else { +tst_res (TFAIL |TTERRNO , +"Failed to create timer for %s" , +get_clock_str (clock));
testcases/kernel/timers/timer_create/timer_create02.c line 99
Quoted 10 lines
testcases/kernel/timers/timer_create/timer_create02.c +10
-0+ } +continue ; + } + +tst_res (TPASS ,"Timer successfully created for %s" , +get_clock_str (clock)); + +TEST (tst_syscall (__NR_timer_delete, created_timer_id)); +if (TST_RET !=0 ) { + tst_res(TINFO, "Failed to delete timer %s",
^
Really TINFO I would go for TFAIL|TTERRNO here
Quoted 10 lines
testcases/kernel/timers/timer_create/timer_create02.c +10
-0+ get_clock_str(clock)); + } + } +} + +static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (types), + .needs_root =1 , +};
...
Quoted 49 lines
testcases/kernel/timers/timer_create/timer_create04.c +49
-0+// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) Wipro Technologies Ltd, 2003. All Rights Reserved. +* +* Author: Aniruddha Marathe <[email protected]> +* +* Ported to new library: +* 07/2019 Christian Amann <[email protected]> +*/ +/* +* Basic error handling test for timer_create(2): +* +* Passes invalid parameters when calling the syscall and checks +* if it fails with EFAULT: +* 1) Pass an invalid pointer for the sigevent structure parameter +* 2) Pass an invalid pointer for the timer ID parameter +*/ + +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <time.h> +#include <signal.h> +#include "tst_test.h" +#include "common_timers.h" + +static struct sigevent sig_ev; +static kernel_timer_t timer_id; + +static struct testcase { +struct sigevent *ev_ptr; +kernel_timer_t *kt_ptr; +int error; +char *description; +} tcases[] = { + {NULL , &timer_id,EFAULT ,"invalid sigevent struct" }, + {&sig_ev,NULL ,EFAULT ,"invalid timer ID" }, +}; + +static int have_recent_kernel (void ) +{ +return tst_kvercmp (2 ,6 ,12 ) >=0 ; +} + +static void run (unsigned int n) +{ +unsigned int i; +struct testcase *tc = &tcases[n]; +
testcases/kernel/timers/timer_create/timer_create04.c line 59
Quoted 10 lines
testcases/kernel/timers/timer_create/timer_create04.c +10
-0+tst_res (TINFO ,"Testing for %s." , tc->description); + +for (i =0 ; i <CLOCKS_DEFINED ; ++i) { +clock_t clock = clock_list[i]; + +/* PROCESS_CPUTIME_ID & THREAD_CPUTIME_ID are not supported on +* kernel versions lower than 2.6.12 +*/ +if (strstr (get_clock_str (clock),"CPUTIME_ID" ) && + !have_recent_kernel ())
^
Well recent is kind of relative word, I wouldn't call 2.6.12 recent yet it works fine here.
What about we called the function have_cputime_timers() or something similar?
I guess that we can also put it in the common header and use it in the previous test as well.
testcases/kernel/timers/timer_create/timer_create04.c line 66
Quoted 7 lines
testcases/kernel/timers/timer_create/timer_create04.c +7
-0+ tc->error =EINVAL ; + +TEST (tst_syscall (__NR_timer_create, clock_list[n], tc->ev_ptr, + tc->kt_ptr)); + +if (TST_RET !=-1 ||TST_ERR != tc->error) { +if (allowed_to_fail (clock) &&TST_ERR ==EINVAL ) {
^
Maybe this should be called "possibly_unsupported()" or something similar.
testcases/kernel/timers/timer_create/timer_create04.c line 70
Quoted 4 lines
testcases/kernel/timers/timer_create/timer_create04.c +4
-0+tst_res (TPASS , +"%s unsupported, failes as expected: %s" , +get_clock_str (clock), +tst_strerrno (TST_ERR ));
TTERRNO here as well
Quoted 34 lines
testcases/kernel/timers/timer_create/timer_create04.c +28
-0+ }else { +tst_res (TFAIL |TTERRNO , +"%s didn't fail as expected (%s) - Got" , +get_clock_str (clock), +tst_strerrno (tc->error)); + } +continue ; + } +tst_res (TPASS ,"Timer creation for %s failed as expected: %s" , +get_clock_str (clock),tst_strerrno (tc->error)); + } +} + +static void setup (void ) +{ + tcases[0 ].ev_ptr =tst_get_bad_addr (NULL ); + tcases[1 ].kt_ptr =tst_get_bad_addr (NULL ); + + sig_ev.sigev_value = (union sigval )0 ; + sig_ev.sigev_signo =SIGALRM ; + sig_ev.sigev_notify =SIGEV_NONE ; +} + +static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, +};Signature · 5 lines
2.16.4 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]