timers/timer_create0{2, 3, 4}: Ported to new library
PATCH v3 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.
--- include/lapi/posix_clocks.h | 4 + runtest/timers | 1 - testcases/kernel/timers/include/common_timers.h | 49 ++-- testcases/kernel/timers/timer_create/.gitignore | 1 - .../kernel/timers/timer_create/timer_create02.c | 284 ++++++++------------- .../kernel/timers/timer_create/timer_create03.c | 156 ----------- .../kernel/timers/timer_create/timer_create04.c | 281 +++++++------------- 7 files changed, 234 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 +29 -20
81 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 +107 -177
284 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 +94 -187
281 lines not on this page · raw message
Signature · 1 line
2.16.4
PATCH v3 1/1 timers/timer_create0{2, 3, 4}: Ported to new library
Hi!
Quoted 1 line
-#define CLEANUP cleanup
Removing this line breaks the compilation for the timer_delete() tests, it should be removed once these are rewritten, (yes there is a CLEANUP() function defined in the old library headers which, after this define becomes cleanup(), it's a mess we have to get rid off but let's do that step by a step).
HINT: Do make clean && make in the timers directory after applying this
patch.
Quoted 73 lines
testcases/kernel/timers/timer_create/timer_create04.c +73
-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 void run (unsigned int n) +{ +unsigned int i; +struct testcase *tc = &tcases[n]; + +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 (clock ==CLOCK_PROCESS_CPUTIME_ID || + clock ==CLOCK_THREAD_CPUTIME_ID ) { +if (!have_cputime_timers ()) + 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 (possibly_unsupported (clock) &&TST_ERR ==EINVAL ) { +tst_res (TPASS |TTERRNO , +"%s unsupported, failed as expected" , +get_clock_str (clock)); + }else { +tst_res (TFAIL |TTERRNO , +"%s didn't fail as expected (%s) - Got" , +get_clock_str (clock), +tst_strerrno (tc->error)); + } +continue ;
testcases/kernel/timers/timer_create/timer_create04.c line 83
Quoted 10 lines
testcases/kernel/timers/timer_create/timer_create04.c +10
-0+ } +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 );
Can we rather do:
for (i = 0; i < ARRAY_SIZE(tcases); i++) {
if (!tcases[i].ev_ptr)
tcases[i].ev_ptr = tst_get_bad_addr();
if (!tcases[i].kt_ptr)
tcases[i].kt_ptr = tst_get_bad_addr();
}That way we do not depend on the order of the structure.
Also we should probably move these tests to the syscalls/timer_create/ directory and add them to the syscalls runtest file. But let's do that in a separate patch. We may also rename them to 01 and 02 in that patch.
And this test misses EINVAL tests for:
* wrong timer id
(we do have MAX_CLOCKS constant in lapi/posix_clocks.h for that)
* wrong content of the sigevent structure
But given that the original test was missing these we may as well do that in a follow up patch as well.
Signature · 2 lines
Cyril Hrubis [email protected]