syscalls/clock_settime01.c: create syscall clock_settime test
PATCH 1/2 syscalls/clock_settime01.c: create syscall clock_settime test
clock_settime01 creates a new test, using new API, based on existing and older kernel/timers/clock_settime tests. It includes tests from files clock_settime02 and clock_settime03, which will be deleted in next commits.
--- runtest/syscalls | 2 + .../kernel/syscalls/clock_settime/.gitignore | 1 + .../kernel/syscalls/clock_settime/Makefile | 8 + .../syscalls/clock_settime/clock_settime01.c | 187 ++++++++++++++++++ 4 files changed, 198 insertions(+) create mode 100644 testcases/kernel/syscalls/clock_settime/.gitignore create mode 100644 testcases/kernel/syscalls/clock_settime/Makefile create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime01.c
runtest/syscalls +2 -0
@@ -79,6 +79,8 @@ clock_nanosleep01 clock_nanosleep01 clock_nanosleep02 clock_nanosleep02 clock_nanosleep2_01 clock_nanosleep2_01 +clock_settime01 clock_settime01 + clone01 clone01 clone02 clone02 clone03 clone03
testcases/kernel/syscalls/clock_settime/.gitignore new file +1 -0
@@ -0,0 +1 @@ +clock_settime01
testcases/kernel/syscalls/clock_settime/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# Copyright (c) 2018 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +187 -0
187 lines not on this page · raw message
Signature · 1 line
2.20.0.rc1
PATCH 2/2 timers/clock_settime: remove clock_settime tests
clock_settime01 creates a new test, using new API, based on existing and older kernel/timers/clock_settime tests. It includes tests from files clock_settime02 and clock_settime03.
This commit deletes timers/clock_settime/* tests.
--- runtest/timers | 2 - .../kernel/timers/clock_settime/.gitignore | 2 - .../kernel/timers/clock_settime/Makefile | 27 --- .../timers/clock_settime/clock_settime02.c | 128 ------------- .../timers/clock_settime/clock_settime03.c | 173 ------------------ 5 files changed, 332 deletions(-) delete mode 100644 testcases/kernel/timers/clock_settime/.gitignore delete mode 100644 testcases/kernel/timers/clock_settime/Makefile delete mode 100644 testcases/kernel/timers/clock_settime/clock_settime02.c delete mode 100644 testcases/kernel/timers/clock_settime/clock_settime03.c
runtest/timers +0 -2
@@ -1,8 +1,6 @@ #DESCRIPTION:Posix Timer Tests clock_gettime02 clock_gettime02 clock_gettime03 clock_gettime03 -clock_settime02 clock_settime02 -clock_settime03 clock_settime03 timer_create02 timer_create02 timer_create03 timer_create03 timer_create04 timer_create04
testcases/kernel/timers/clock_settime/.gitignore deleted +0 -2
@@ -1,2 +0,0 @@ -/clock_settime02 -/clock_settime03
testcases/kernel/timers/clock_settime/Makefile deleted +0 -27
@@ -1,27 +0,0 @@ -# -# Copyright (c) International Business Machines Corp., 2001 -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# - -top_srcdir ?= ../../../.. - -include $(top_srcdir)/include/mk/testcases.mk - -CPPFLAGS += -D_GNU_SOURCE -I$(abs_srcdir)/../include - -LDLIBS += -lpthread -lrt - -include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/timers/clock_settime/clock_settime02.c deleted +0 -128
128 lines not on this page · raw message
testcases/kernel/timers/clock_settime/clock_settime03.c deleted +0 -173
173 lines not on this page · raw message
Signature · 1 line
2.20.0.rc1
PATCH 1/2 syscalls/clock_settime01.c: create syscall clock_settime test
In reply to Rafael David TinocoHi!
Quoted 72 lines
--- runtest/syscalls | 2 + .../kernel/syscalls/clock_settime/.gitignore | 1 + .../kernel/syscalls/clock_settime/Makefile | 8 + .../syscalls/clock_settime/clock_settime01.c | 187 ++++++++++++++++++ 4 files changed, 198 insertions(+) create mode 100644 testcases/kernel/syscalls/clock_settime/.gitignore create mode 100644 testcases/kernel/syscalls/clock_settime/Makefile create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime01.cruntest/syscalls +2
-0@@ -79,6 +79,8 @@ clock_nanosleep01 clock_nanosleep01 clock_nanosleep02 clock_nanosleep02 clock_nanosleep2_01 clock_nanosleep2_01 +clock_settime01 clock_settime01 + clone01 clone01 clone02 clone02 clone03 clone03testcases/kernel/syscalls/clock_settime/.gitignore new file +1
-0@@ -0,0 +1 @@ +clock_settime01testcases/kernel/syscalls/clock_settime/Makefile new file +8
-0@@ -0,0 +1,8 @@ +# Copyright (c) 2018 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/syscalls/clock_settime/clock_settime01.c new file +22
-0@@ -0,0 +1,187 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2018 Linaro Limited. All rights reserved. +* Author: Rafael David Tinoco <[email protected]> +*/ + +/* +* Basic tests for clock_settime(2) on different clock types +*/ + +#include "config.h" +#include "tst_test.h" +#include "lapi/syscalls.h" + +#define NSEC_PER_SEC (1000000000L) +#define MAX_CLOCKS 16 + +static struct timespec clock_realtime_saved; + +struct test_case { +clockid_t type; +struct timespec newtime;
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 32
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +10
-0+int exp_ret; +int exp_err; +int replace; +}; + +struct test_case tc[] = { + {/* case 01: REALTIME */ + .type =CLOCK_REALTIME , + .exp_ret =0 , + },
What about we separate the only positive case to a separate test, then we can also do more a few more sanity checks there. I would probably go for sequence of something as:
* get the realtime time
* increasing it by some value in seconds
* set the realtime time
* get the realtime time
* check that the value is aprox the first value increased by the value
* decrease by the value
* set it again
* check it again
That would cover both cases of setting time forward and backward and at the end we would end up with the correct time as a bonus.
Quoted 70 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +70
-0+ { /* case 02: REALTIME: timespec NULL */ + .type = CLOCK_REALTIME, + .newtime.tv_sec = -2, + .exp_ret = -1, + .exp_err = EFAULT, + .replace = 1, + }, + { /* case 03: REALTIME: tv_sec = -1 */ + .type = CLOCK_REALTIME, + .newtime.tv_sec = -1, + .exp_ret = -1, + .exp_err = EINVAL, + .replace = 1, + }, + { /* case 04: REALTIME: tv_nsec = -1 */ + .type = CLOCK_REALTIME, + .newtime.tv_nsec = -1, + .exp_ret = -1, + .exp_err = EINVAL, + .replace = 1, + }, + { /* case 05: REALTIME: tv_nsec = 1s+1 */ + .type = CLOCK_REALTIME, + .newtime.tv_nsec = NSEC_PER_SEC + 1, + .exp_ret = -1, + .exp_err = EINVAL, + .replace = 1, + }, + { /* case 06: MONOTONIC */ + .type = CLOCK_MONOTONIC, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 07: MAXCLOCK */ + .type = MAX_CLOCKS, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 08: MAXCLOCK+1 */ + .type = MAX_CLOCKS + 1, + .exp_ret = -1, + .exp_err = EINVAL, + }, + /* Linux specific */ + { /* case 09: CLOCK_MONOTONIC_COARSE */ + .type = CLOCK_MONOTONIC_COARSE, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 10: CLOCK_MONOTONIC_RAW */ + .type = CLOCK_MONOTONIC_RAW, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 11: CLOCK_BOOTTIME */ + .type = CLOCK_BOOTTIME, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 12: CLOCK_PROCESS_CPUTIME_ID */ + .type = CLOCK_PROCESS_CPUTIME_ID, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 13: CLOCK_THREAD_CPUTIME_ID */ + .type = CLOCK_THREAD_CPUTIME_ID, + .exp_ret = -1, + .exp_err = EINVAL, + }, +};
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 112
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +10
-0+ +static int sys_clock_settime (clockid_t clk_id,struct timespec *tp) +{ +return tst_syscall (__NR_clock_settime, clk_id, tp); +} + +static int sys_clock_gettime (clockid_t clk_id,struct timespec *tp) +{ +return tst_syscall (__NR_clock_gettime, clk_id, tp); +}
Any reason why we avoid the clock_settime and clock_gettime libc functions here?
Quoted 49 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +49
-0+static void cleanup (void ) +{ +/* restore realtime clock */ + +if (sys_clock_settime (CLOCK_REALTIME , &clock_realtime_saved) <0 ) +tst_res (TBROK |TTERRNO ,"clock_settime(2): could not set " +"current time back" ); +} + +static void setup (void ) +{ +if (sys_clock_gettime (CLOCK_REALTIME , &clock_realtime_saved) <0 ) +tst_res (TBROK |TTERRNO ,"clock_gettime(2): could not get " +"current time" ); +} + +static void verify_clock_settime (unsigned int i) +{ +struct timespec spec, *specptr; + +if (tc[i].replace ==0 ) { + +/* add 1 sec to test clock */ + + specptr = &spec; + specptr->tv_sec = clock_realtime_saved.tv_sec +1 ; + specptr->tv_nsec = clock_realtime_saved.tv_nsec; + + }else { + +/* bad pointer case */ + +if (tc[i].newtime.tv_sec ==-2 ) + specptr =tst_get_bad_addr (cleanup); + +/* use given values */ + +else { + specptr = &spec; + specptr->tv_sec = tc[i].newtime.tv_sec; + specptr->tv_nsec = tc[i].newtime.tv_nsec; + } + } + +TEST (sys_clock_settime (tc[i].type, specptr)); + +if (tc[i].exp_ret ==TST_RET ) { + +if (TST_RET >=0 )
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 172
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +10
-0+tst_res (TPASS ,"clock_settime(2): worked as expected" ); + + else { +if (tc[i].exp_err ==TST_ERR ) +tst_res (TPASS ,"clock_settime(2): failed as " +"expected" ); +else +tst_res (TFAIL |TTERRNO ,"clock_settime(2): " +"failed with different error" ); + }
LKML coding style prefers curly braces around both blocks if they are around one of them, but that's a minor one.
Quoted 20 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +14
-0+return ; + } + +tst_res (TFAIL |TTERRNO ,"clock_settime(2): clock type %d failed" , + tc[i].type); +} + +static struct tst_test test = { + .setup = setup, + .test = verify_clock_settime, + .cleanup = cleanup, + .tcnt =ARRAY_SIZE (tc), + .needs_root =1 , +};Signature · 5 lines
2.20.0.rc1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 syscalls/clock_settime01.c: create syscall clock_settime test
Quoted 97 lines · Cyril Hrubis
Hi!
Quoted 72 lines
--- runtest/syscalls | 2 + .../kernel/syscalls/clock_settime/.gitignore | 1 + .../kernel/syscalls/clock_settime/Makefile | 8 + .../syscalls/clock_settime/clock_settime01.c | 187 ++++++++++++++++++ 4 files changed, 198 insertions(+) create mode 100644 testcases/kernel/syscalls/clock_settime/.gitignore create mode 100644 testcases/kernel/syscalls/clock_settime/Makefile create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime01.cruntest/syscalls +2
-0@@ -79,6 +79,8 @@ clock_nanosleep01 clock_nanosleep01 clock_nanosleep02 clock_nanosleep02 clock_nanosleep2_01 clock_nanosleep2_01 +clock_settime01 clock_settime01 + clone01 clone01 clone02 clone02 clone03 clone03testcases/kernel/syscalls/clock_settime/.gitignore new file +1
-0@@ -0,0 +1 @@ +clock_settime01testcases/kernel/syscalls/clock_settime/Makefile new file +8
-0@@ -0,0 +1,8 @@ +# Copyright (c) 2018 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/syscalls/clock_settime/clock_settime01.c new file +22
-0@@ -0,0 +1,187 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2018 Linaro Limited. All rights reserved. +* Author: Rafael David Tinoco <[email protected]> +*/ + +/* +* Basic tests for clock_settime(2) on different clock types +*/ + +#include "config.h" +#include "tst_test.h" +#include "lapi/syscalls.h" + +#define NSEC_PER_SEC (1000000000L) +#define MAX_CLOCKS 16 + +static struct timespec clock_realtime_saved; + +struct test_case { +clockid_t type; +struct timespec newtime;testcases/kernel/syscalls/clock_settime/clock_settime01.c line 32
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +10
-0+int exp_ret; +int exp_err; +int replace; +}; + +struct test_case tc[] = { + {/* case 01: REALTIME */ + .type =CLOCK_REALTIME , + .exp_ret =0 , + },What about we separate the only positive case to a separate test, then we can also do more a few more sanity checks there. I would probably go for sequence of something as:
* get the realtime time
* increasing it by some value in seconds
* set the realtime time
* get the realtime time
* check that the value is aprox the first value increased by the value
* decrease by the value
* set it again
* check it again
Quoted 3 lines
That would cover both cases of setting time forward and backward and at the end we would end up with the correct time as a bonus.
Alright. Will do.
Quoted 75 lines
Quoted 75 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +75
-0+ { /* case 02: REALTIME: timespec NULL */ + .type = CLOCK_REALTIME, + .newtime.tv_sec = -2, + .exp_ret = -1, + .exp_err = EFAULT, + .replace = 1, + }, + { /* case 03: REALTIME: tv_sec = -1 */ + .type = CLOCK_REALTIME, + .newtime.tv_sec = -1, + .exp_ret = -1, + .exp_err = EINVAL, + .replace = 1, + }, + { /* case 04: REALTIME: tv_nsec = -1 */ + .type = CLOCK_REALTIME, + .newtime.tv_nsec = -1, + .exp_ret = -1, + .exp_err = EINVAL, + .replace = 1, + }, + { /* case 05: REALTIME: tv_nsec = 1s+1 */ + .type = CLOCK_REALTIME, + .newtime.tv_nsec = NSEC_PER_SEC + 1, + .exp_ret = -1, + .exp_err = EINVAL, + .replace = 1, + }, + { /* case 06: MONOTONIC */ + .type = CLOCK_MONOTONIC, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 07: MAXCLOCK */ + .type = MAX_CLOCKS, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 08: MAXCLOCK+1 */ + .type = MAX_CLOCKS + 1, + .exp_ret = -1, + .exp_err = EINVAL, + }, + /* Linux specific */ + { /* case 09: CLOCK_MONOTONIC_COARSE */ + .type = CLOCK_MONOTONIC_COARSE, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 10: CLOCK_MONOTONIC_RAW */ + .type = CLOCK_MONOTONIC_RAW, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 11: CLOCK_BOOTTIME */ + .type = CLOCK_BOOTTIME, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 12: CLOCK_PROCESS_CPUTIME_ID */ + .type = CLOCK_PROCESS_CPUTIME_ID, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 13: CLOCK_THREAD_CPUTIME_ID */ + .type = CLOCK_THREAD_CPUTIME_ID, + .exp_ret = -1, + .exp_err = EINVAL, + }, +}; + +static int sys_clock_settime(clockid_t clk_id, struct timespec *tp) +{ + return tst_syscall(__NR_clock_settime, clk_id, tp); +}
Quoted 8 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 112
Quoted 5 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +5
-0+ +static int sys_clock_gettime (clockid_t clk_id,struct timespec *tp) +{ +return tst_syscall (__NR_clock_gettime, clk_id, tp); +}Any reason why we avoid the
clock_settimeandclock_gettimelibc functions here?
Nope. I guess I could use libc one.
Quoted 56 lines
Quoted 56 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +55
-0+static void cleanup (void ) +{ +/* restore realtime clock */ + +if (sys_clock_settime (CLOCK_REALTIME , &clock_realtime_saved) <0 ) +tst_res (TBROK |TTERRNO ,"clock_settime(2): could not set " +"current time back" ); +} + +static void setup (void ) +{ +if (sys_clock_gettime (CLOCK_REALTIME , &clock_realtime_saved) <0 ) +tst_res (TBROK |TTERRNO ,"clock_gettime(2): could not get " +"current time" ); +} + +static void verify_clock_settime (unsigned int i) +{ +struct timespec spec, *specptr; + +if (tc[i].replace ==0 ) { + +/* add 1 sec to test clock */ + + specptr = &spec; + specptr->tv_sec = clock_realtime_saved.tv_sec +1 ; + specptr->tv_nsec = clock_realtime_saved.tv_nsec; + + }else { + +/* bad pointer case */ + +if (tc[i].newtime.tv_sec ==-2 ) + specptr =tst_get_bad_addr (cleanup); + +/* use given values */ + +else { + specptr = &spec; + specptr->tv_sec = tc[i].newtime.tv_sec; + specptr->tv_nsec = tc[i].newtime.tv_nsec; + } + } + +TEST (sys_clock_settime (tc[i].type, specptr)); + +if (tc[i].exp_ret ==TST_RET ) { + +if (TST_RET >=0 ) +tst_res (TPASS ,"clock_settime(2): worked as expected" ); + +else { +if (tc[i].exp_err ==TST_ERR ) +tst_res (TPASS ,"clock_settime(2): failed as " +"expected" );
Quoted 8 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 172
Quoted 4 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +4
-0+else +tst_res (TFAIL |TTERRNO ,"clock_settime(2): " +"failed with different error" ); + }LKML coding style prefers curly braces around both blocks if they are around one of them, but that's a minor one.
Will fix.
Quoted 19 lines
Quoted 19 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +14
-0+return ; + } + +tst_res (TFAIL |TTERRNO ,"clock_settime(2): clock type %d failed" , + tc[i].type); +} + +static struct tst_test test = { + .setup = setup, + .test = verify_clock_settime, + .cleanup = cleanup, + .tcnt =ARRAY_SIZE (tc), + .needs_root =1 , +};Signature · 1 line
2.20.0.rc1
Quoted 3 lines
Quoted 2 lines
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Thanks for reviewing it.
Signature · 2 lines
Rafael D. Tinoco Linaro - Kernel Validation
PATCH v2 1/2 syscalls/clock_settime01.c: create syscall clock_settime
In reply to Cyril Hrubisclock_settime01 creates a new test, using new API, based on existing and older kernel/timers/clock_settime tests. It includes tests from files clock_settime02 and clock_settime03, which will be deleted in next commits.
--- runtest/syscalls | 3 + .../kernel/syscalls/clock_settime/.gitignore | 2 + .../kernel/syscalls/clock_settime/Makefile | 8 + .../syscalls/clock_settime/clock_settime01.c | 122 +++++++++++++ .../syscalls/clock_settime/clock_settime02.c | 171 ++++++++++++++++++ 5 files changed, 306 insertions(+) create mode 100644 testcases/kernel/syscalls/clock_settime/.gitignore create mode 100644 testcases/kernel/syscalls/clock_settime/Makefile create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime01.c create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime02.c
runtest/syscalls +3 -0
@@ -79,6 +79,9 @@ clock_nanosleep01 clock_nanosleep01 clock_nanosleep02 clock_nanosleep02 clock_nanosleep2_01 clock_nanosleep2_01 +clock_settime01 clock_settime01 +clock_settime02 clock_settime02 + clone01 clone01 clone02 clone02 clone03 clone03
testcases/kernel/syscalls/clock_settime/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +clock_settime01 +clock_settime02
testcases/kernel/syscalls/clock_settime/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# Copyright (c) 2018 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +122 -0
122 lines not on this page · raw message
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +171 -0
171 lines not on this page · raw message
Signature · 1 line
2.20.0.rc1
PATCH v2 1/2 syscalls/clock_settime01.c: create syscall clock_settime
Quoted 9 lines · Rafael David Tinoco
Fixes 343
clock_settime01creates a new test, using new API, based on existing and olderkernel/timers/clock_settimetests. It includes tests from filesclock_settime02andclock_settime03, which will be deleted in next commits.Signed-off-by Rafael David Tinoco <[email protected]>---
Cyril,
Please if you accept this patch, amend the description to:
"""clock_settime01 creates a new test, using new API, based on existing and older kernel/timers/clock_settime02 test. clock_settime02 creates another test based on older kernel/timers/clock_settime03 test. Both will be deleted in the next commits.
"""
I forgot to change description before sending v2. Sorry.
About the first test, best way to check good results is:
$ date ; time sudo $(find . -name clock_settime01) -I 10 2>&1 > /dev/null 2>&1 ; date
Thu Dec 6 17:09:24 -02 2018
real 0m10.032s
user 0m2.710s
sys 0m11.911s
Thu Dec 6 17:09:34 -02 2018
Using CLOCK_MONOTONIC_RAW we can make sure to restore a good time to CLOCK_REALTIME after the test has run (independently of how many seconds it took or iterations it had).
Signature · 2 lines
Rafael D. Tinoco Linaro - Kernel Validation
PATCH v2 2/2 timers/clock_settime: remove clock_settime tests
In reply to Rafael David Tinococlock_settime01 creates a new test, using new API, based on existing and older kernel/timers/clock_settime tests. It includes tests from files clock_settime02 and clock_settime03.
This commit deletes timers/clock_settime/* tests.
--- runtest/timers | 2 - .../kernel/timers/clock_settime/.gitignore | 2 - .../kernel/timers/clock_settime/Makefile | 27 --- .../timers/clock_settime/clock_settime02.c | 128 ------------- .../timers/clock_settime/clock_settime03.c | 173 ------------------ 5 files changed, 332 deletions(-) delete mode 100644 testcases/kernel/timers/clock_settime/.gitignore delete mode 100644 testcases/kernel/timers/clock_settime/Makefile delete mode 100644 testcases/kernel/timers/clock_settime/clock_settime02.c delete mode 100644 testcases/kernel/timers/clock_settime/clock_settime03.c
runtest/timers +0 -2
@@ -1,8 +1,6 @@ #DESCRIPTION:Posix Timer Tests clock_gettime02 clock_gettime02 clock_gettime03 clock_gettime03 -clock_settime02 clock_settime02 -clock_settime03 clock_settime03 timer_create02 timer_create02 timer_create03 timer_create03 timer_create04 timer_create04
testcases/kernel/timers/clock_settime/.gitignore deleted +0 -2
@@ -1,2 +0,0 @@ -/clock_settime02 -/clock_settime03
testcases/kernel/timers/clock_settime/Makefile deleted +0 -27
@@ -1,27 +0,0 @@ -# -# Copyright (c) International Business Machines Corp., 2001 -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# - -top_srcdir ?= ../../../.. - -include $(top_srcdir)/include/mk/testcases.mk - -CPPFLAGS += -D_GNU_SOURCE -I$(abs_srcdir)/../include - -LDLIBS += -lpthread -lrt - -include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/timers/clock_settime/clock_settime02.c deleted +0 -128
128 lines not on this page · raw message
testcases/kernel/timers/clock_settime/clock_settime03.c deleted +0 -173
173 lines not on this page · raw message
Signature · 1 line
2.20.0.rc1
PATCH v2 1/2 syscalls/clock_settime01.c: create syscall clock_settime
In reply to Rafael David TinocoHi!
Quoted 24 lines
new file mode 100644
index 000000000..97d720fa2testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +19
-0@@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2018 Linaro Limited. All rights reserved. +* Author: Rafael David Tinoco <[email protected]> +*/ + +/* +* Basic test for clock_settime(2) on REALTIME clock: +* +* 1) advance DELTA_SEC seconds +* 2) go backwards DELTA_SEC seconds +* +* Accept DELTA_PER deviation on both (specially going backwards). +*/ + +#include "config.h" +#include "tst_test.h" +#include "lapi/syscalls.h" +
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 29
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +10
-0+#define DELTA_SEC 10/* 10 seconds delta */ +#define DELTA_PER 0.1/* 1 percent deviation */ + +static struct timespec real_begin, mono_begin, mono_end; + +static void clock_elapsed (struct timespec *begin,struct timespec *end, +struct timespec *elapsed) +{ + elapsed->tv_sec = end->tv_sec - begin->tv_sec; + elapsed->tv_nsec = end->tv_nsec - begin->tv_nsec;
If you do this the elapsed may end up in non-normalized state, i.e. elapsed->tv_nsec may end up negative.
We do have all kinds of inline functions for conversion and arimetic in tst_timer.h so there is no point of rolling your own here.
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 32
Quoted 3 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +3
-0+} + +static void clock_return (void )
^
I would have named this restore, but that is very minor.
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 39
Quoted 7 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +7
-0+{ +static struct timespec elapsed, adjust; + +clock_elapsed (&mono_begin, &mono_end, &elapsed); + + adjust.tv_sec = real_begin.tv_sec + elapsed.tv_sec; + adjust.tv_nsec = real_begin.tv_nsec + elapsed.tv_nsec;
We should normalize the addition here as well, i.e. carry over to seconds if the number of nanoseconds gets greater than 1s.
Ideally we should add a function to add two timespec structures into the tst_timer.h header (in a separate patch).
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 48
Quoted 8 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +8
-0+if (clock_settime (CLOCK_REALTIME , &adjust) !=0 ) +tst_res (TBROK |TTERRNO ,"could restore realtime clock" ); +} + +static void clock_fixnow (void ) +{ +if (clock_gettime (CLOCK_MONOTONIC_RAW , &mono_end) !=0 ) +tst_res (TBROK |TTERRNO ,"could not get elapsed time" );
We should make sure here that both real_begin and mono_begin were set before we attempt to restore the system time. A restore_time flag se to 1 after we successfully read both will do.
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 61
Quoted 12 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +12
-0+clock_return (); +} + +static void setup (void ) +{ +/* save initial monotonic time to restore it when needed */ + +if (clock_gettime (CLOCK_REALTIME , &real_begin) !=0 ) +tst_res (TBROK |TTERRNO ,"could not get initial real time" ); + +if (clock_gettime (CLOCK_MONOTONIC_RAW , &mono_begin) !=0 ) +tst_res (TBROK |TTERRNO ,"couldn't get initial monotonic time" );
^
This should have been tst_brk() doing tst_res() with TBROK does not make much sense.
Also we do have tst_safe_clocks.h, if you include that you can use SAFE_CLOCK_GETTIME() instead.
Overall the idea of restoring wall clock using monotonic timer is a good one, maybe we should even move this code to a library so that all tests that change wall clock would need just set restore_wallclock flag in the tst_test structure...
Quoted 13 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +13
-0+} + +static void cleanup (void ) +{ +clock_fixnow (); +} + +static void verify_clock_settime (void ) +{ +static struct timespec begin, change, end, elapsed; + +/* test 01: move forward */ +
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 84
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +10
-0+if (clock_gettime (CLOCK_REALTIME , &begin) !=0 ) +tst_res (TBROK |TTERRNO ,"could not get realtime at the begin" ); + + change.tv_sec = begin.tv_sec +DELTA_SEC ; + +if (clock_settime (CLOCK_REALTIME , &change) !=0 ) +tst_res (TBROK |TTERRNO ,"could not set realtime change" ); + +if (clock_gettime (CLOCK_REALTIME , &end) !=0 ) +tst_res (TBROK |TTERRNO ,"could not get realtime after change" );
Here as well.
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 88
Quoted 3 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +3
-0+clock_elapsed (&begin, &end, &elapsed); + +if (elapsed.tv_sec < (float ) (DELTA_SEC - (DELTA_SEC *DELTA_PER )))
It would be much easier to just use tst_timespec_diff_ms() and check that the result is in reasonable range. I.e. check lower bound as well.
Quoted 16 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +16
-0+tst_res (TFAIL ,"clock_settime(2): could not advance time" ); + else + tst_res(TPASS, "clock_settime(2): was able to advance time"); + +/* test 02: move backward */ + +if (clock_gettime (CLOCK_REALTIME , &begin) !=0 ) +tst_res (TBROK |TTERRNO ,"could not get realtime at the begin" ); + + change.tv_sec = begin.tv_sec -DELTA_SEC ; + +if (clock_settime (CLOCK_REALTIME , &change) !=0 ) +tst_res (TBROK |TTERRNO ,"could not set realtime change" ); + +if (clock_gettime (CLOCK_REALTIME , &end) !=0 ) +tst_res (TBROK |TTERRNO ,"could not get realtime after change" );
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 114
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +10
-0+ +clock_elapsed (&begin, &end, &elapsed); + + elapsed.tv_sec = ~elapsed.tv_sec; + elapsed.tv_nsec = ~elapsed.tv_nsec; + +if (elapsed.tv_sec < (float ) (DELTA_SEC - (DELTA_SEC *DELTA_PER ))) +tst_res (TFAIL ,"clock_settime(2): could not recede time" ); +else +tst_res (TPASS ,"clock_settime(2): was able to recede time" );
Here as well.
Quoted 143 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +8
-0+} + +static struct tst_test test = { + .setup = setup, + .test_all = verify_clock_settime, + .cleanup = cleanup, + .needs_root =1 , +};testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +128
-0@@ -0,0 +1,171 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2018 Linaro Limited. All rights reserved. +* Author: Rafael David Tinoco <[email protected]> +*/ + +/* +* Basic tests for errors of clock_settime(2) on different clock types. +*/ + +#include "config.h" +#include "tst_test.h" +#include "lapi/syscalls.h" + +#define DELTA_SEC 10 +#define NSEC_PER_SEC (1000000000L) +#define MAX_CLOCKS 16 + +static struct timespec clock_realtime_saved; + +struct test_case { +clockid_t type; +struct timespec newtime; +int exp_err; +int replace; +}; + +struct test_case tc[] = { + {/* case 01: REALTIME: timespec NULL */ + .type =CLOCK_REALTIME , + .newtime.tv_sec =-2 , + .exp_err =EFAULT , + .replace =1 , + }, + {/* case 02: REALTIME: tv_sec = -1 */ + .type =CLOCK_REALTIME , + .newtime.tv_sec =-1 , + .exp_err =EINVAL , + .replace =1 , + }, + {/* case 03: REALTIME: tv_nsec = -1 */ + .type =CLOCK_REALTIME , + .newtime.tv_nsec =-1 , + .exp_err =EINVAL , + .replace =1 , + }, + {/* case 04: REALTIME: tv_nsec = 1s+1 */ + .type =CLOCK_REALTIME , + .newtime.tv_nsec =NSEC_PER_SEC +1 , + .exp_err =EINVAL , + .replace =1 , + }, + {/* case 05: MONOTONIC */ + .type =CLOCK_MONOTONIC , + .exp_err =EINVAL , + }, + {/* case 06: MAXCLOCK */ + .type =MAX_CLOCKS , + .exp_err =EINVAL , + }, + {/* case 07: MAXCLOCK+1 */ + .type =MAX_CLOCKS +1 , + .exp_err =EINVAL , + }, +/* Linux specific */ + {/* case 08: CLOCK_MONOTONIC_COARSE */ + .type =CLOCK_MONOTONIC_COARSE , + .exp_err =EINVAL , + }, + {/* case 09: CLOCK_MONOTONIC_RAW */ + .type =CLOCK_MONOTONIC_RAW , + .exp_err =EINVAL , + }, + {/* case 10: CLOCK_BOOTTIME */ + .type =CLOCK_BOOTTIME , + .exp_err =EINVAL , + }, + {/* case 11: CLOCK_PROCESS_CPUTIME_ID */ + .type =CLOCK_PROCESS_CPUTIME_ID , + .exp_err =EINVAL , + }, + {/* case 12: CLOCK_THREAD_CPUTIME_ID */ + .type =CLOCK_THREAD_CPUTIME_ID , + .exp_err =EINVAL , + }, +}; + +/* +* Some tests may cause libc to segfault when passing bad arguments. +*/ +static int sys_clock_settime (clockid_t clk_id,struct timespec *tp) +{ +return tst_syscall (__NR_clock_settime, clk_id, tp); +} + +static int sys_clock_gettime (clockid_t clk_id,struct timespec *tp) +{ +return tst_syscall (__NR_clock_gettime, clk_id, tp); +} + +static void cleanup (void ) +{ +/* restore realtime clock */ + +if (sys_clock_settime (CLOCK_REALTIME , &clock_realtime_saved) <0 ) +tst_res (TBROK |TTERRNO ,"clock_settime(2): could not set " +"current time back" ); +} + +static void setup (void ) +{ +if (sys_clock_gettime (CLOCK_REALTIME , &clock_realtime_saved) <0 ) +tst_res (TBROK |TTERRNO ,"clock_gettime(2): could not get " +"current time" ); +} + +static void verify_clock_settime (unsigned int i) +{ +struct timespec spec, *specptr; + +if (tc[i].replace ==0 ) { + +/* add 1 sec to test clock */ + + specptr = &spec; + specptr->tv_sec = clock_realtime_saved.tv_sec +1 ; + specptr->tv_nsec = clock_realtime_saved.tv_nsec; +
testcases/kernel/syscalls/clock_settime/clock_settime02.c line 138
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +10
-0+ }else { + +/* bad pointer case */ + +if (tc[i].newtime.tv_sec ==-2 ) + specptr =tst_get_bad_addr (cleanup); + +/* use given values */ + +else {
Still curly braces missing here, but that is minor.
And maybe we just need to turn the newtime into a pointer in the tcases structure. Then you can initialize global variable to current time + epsion and use pointer to it or even initialize it inline as:
static struct timespec valid_time;
struct test_case tc[] = {
{
.type = CLOCK_REALTIME,
.exp_err = EFAULT,
},
{
.type = CLOCK_REALTIME;
.newtime = &valid_time;
.exp_err = EINVAL,
{
.type = CLOCK_REALTIME,
.newtime = &(struct timespec){},
.exp_err = EINVAL,
.replace = 1,
},
...
};And we can loop in the test setup and set NULL address to the result of tst_get_bad_addr() as well.
Quoted 36 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +33
-0+ specptr = &spec; + specptr->tv_sec = tc[i].newtime.tv_sec; + specptr->tv_nsec = tc[i].newtime.tv_nsec; + } + } + +TEST (sys_clock_settime (tc[i].type, specptr)); + +if (TST_RET ==-1 ) { + +if (tc[i].exp_err ==TST_ERR ) { + +tst_res (TPASS ,"clock_settime(2): failed as expected" ); + + }else { +tst_res (TFAIL |TTERRNO ,"clock_settime(2): " +"failed with different error" ); + } + +return ; + } + +tst_res (TFAIL |TTERRNO ,"clock_settime(2): clock type %d failed" , + tc[i].type); +} + +static struct tst_test test = { + .setup = setup, + .test = verify_clock_settime, + .cleanup = cleanup, + .tcnt =ARRAY_SIZE (tc), + .needs_root =1 , +};Signature · 1 line
2.20.0.rc1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 syscalls/clock_settime01.c: create syscall clock_settime
Quoted 30 lines · Cyril Hrubis
Hi!
Quoted 29 lines
new file mode 100644
index 000000000..97d720fa2testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +24
-0@@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2018 Linaro Limited. All rights reserved. +* Author: Rafael David Tinoco <[email protected]> +*/ + +/* +* Basic test for clock_settime(2) on REALTIME clock: +* +* 1) advance DELTA_SEC seconds +* 2) go backwards DELTA_SEC seconds +* +* Accept DELTA_PER deviation on both (specially going backwards). +*/ + +#include "config.h" +#include "tst_test.h" +#include "lapi/syscalls.h" + +#define DELTA_SEC 10/* 10 seconds delta */ +#define DELTA_PER 0.1/* 1 percent deviation */ + +static struct timespec real_begin, mono_begin, mono_end; +
Quoted 8 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 29
Quoted 5 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +5
-0+static void clock_elapsed (struct timespec *begin,struct timespec *end, +struct timespec *elapsed) +{ + elapsed->tv_sec = end->tv_sec - begin->tv_sec; + elapsed->tv_nsec = end->tv_nsec - begin->tv_nsec;If you do this the elapsed may end up in non-normalized state, i.e.
elapsed->tv_nsecmay end up negative.
#)... definitely, will stick to what tst_timer.h has.
Quoted 11 lines
We do have all kinds of inline functions for conversion and arimetic in
tst_timer.hso there is no point of rolling your own here.testcases/kernel/syscalls/clock_settime/clock_settime01.c line 32
Quoted 3 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +3
-0+} + +static void clock_return (void )^
I would have named this restore, but that is very minor.
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 39
Quoted 7 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +7
-0+{ +static struct timespec elapsed, adjust; + +clock_elapsed (&mono_begin, &mono_end, &elapsed); + + adjust.tv_sec = real_begin.tv_sec + elapsed.tv_sec; + adjust.tv_nsec = real_begin.tv_nsec + elapsed.tv_nsec;We should normalize the addition here as well, i.e. carry over to seconds if the number of nanoseconds gets greater than 1s.
definitely, stupid mistake on my side, will fix.
Quoted 3 lines
Ideally we should add a function to add two timespec structures into the
tst_timer.hheader (in a separate patch).
Alright.
Quoted 13 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 48
Quoted 9 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +8
-0+if (clock_settime (CLOCK_REALTIME , &adjust) !=0 ) +tst_res (TBROK |TTERRNO ,"could restore realtime clock" ); +} + +static void clock_fixnow (void ) +{ +if (clock_gettime (CLOCK_MONOTONIC_RAW , &mono_end) !=0 ) +tst_res (TBROK |TTERRNO ,"could not get elapsed time" );We should make sure here that both
real_beginandmono_beginwere set before we attempt to restore the system time. Arestore_timeflag se to 1 after we successfully read both will do.
Alright.
Quoted 17 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 61
Quoted 13 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +12
-0+clock_return (); +} + +static void setup (void ) +{ +/* save initial monotonic time to restore it when needed */ + +if (clock_gettime (CLOCK_REALTIME , &real_begin) !=0 ) +tst_res (TBROK |TTERRNO ,"could not get initial real time" ); + +if (clock_gettime (CLOCK_MONOTONIC_RAW , &mono_begin) !=0 ) +tst_res (TBROK |TTERRNO ,"couldn't get initial monotonic time" );^
This should have beentst_brk()doingtst_res()with TBROK does not make much sense.
Quoted 7 lines
Also we do have
tst_safe_clocks.h, if you include that you can useSAFE_CLOCK_GETTIME()instead.Overall the idea of restoring wall clock using monotonic timer is a good one, maybe we should even move this code to a library so that all tests that change wall clock would need just set
restore_wallclockflag in thetst_teststructure...
Will look into that.
Quoted 27 lines
Quoted 14 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +13
-0+} + +static void cleanup (void ) +{ +clock_fixnow (); +} + +static void verify_clock_settime (void ) +{ +static struct timespec begin, change, end, elapsed; + +/* test 01: move forward */ +testcases/kernel/syscalls/clock_settime/clock_settime01.c line 84
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +10
-0+if (clock_gettime (CLOCK_REALTIME , &begin) !=0 ) +tst_res (TBROK |TTERRNO ,"could not get realtime at the begin" ); + + change.tv_sec = begin.tv_sec +DELTA_SEC ; + +if (clock_settime (CLOCK_REALTIME , &change) !=0 ) +tst_res (TBROK |TTERRNO ,"could not set realtime change" ); + +if (clock_gettime (CLOCK_REALTIME , &end) !=0 ) +tst_res (TBROK |TTERRNO ,"could not get realtime after change" );Here as well.
Quoted 6 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 88
Quoted 3 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +3
-0+clock_elapsed (&begin, &end, &elapsed); + +if (elapsed.tv_sec < (float ) (DELTA_SEC - (DELTA_SEC *DELTA_PER )))It would be much easier to just use
tst_timespec_diff_ms()and check that the result is in reasonable range. I.e. check lower bound as well.
Yep, I missed tst_timer.h entirely it seems =o), won't reinvent the wheel.
Quoted 210 lines
Quoted 17 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +16
-0+tst_res (TFAIL ,"clock_settime(2): could not advance time" ); + else + tst_res(TPASS, "clock_settime(2): was able to advance time"); + +/* test 02: move backward */ + +if (clock_gettime (CLOCK_REALTIME , &begin) !=0 ) +tst_res (TBROK |TTERRNO ,"could not get realtime at the begin" ); + + change.tv_sec = begin.tv_sec -DELTA_SEC ; + +if (clock_settime (CLOCK_REALTIME , &change) !=0 ) +tst_res (TBROK |TTERRNO ,"could not set realtime change" ); + +if (clock_gettime (CLOCK_REALTIME , &end) !=0 ) +tst_res (TBROK |TTERRNO ,"could not get realtime after change" );testcases/kernel/syscalls/clock_settime/clock_settime01.c line 114
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +10
-0+ +clock_elapsed (&begin, &end, &elapsed); + + elapsed.tv_sec = ~elapsed.tv_sec; + elapsed.tv_nsec = ~elapsed.tv_nsec; + +if (elapsed.tv_sec < (float ) (DELTA_SEC - (DELTA_SEC *DELTA_PER ))) +tst_res (TFAIL ,"clock_settime(2): could not recede time" ); +else +tst_res (TPASS ,"clock_settime(2): was able to recede time" );Here as well.
Quoted 143 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +8
-0+} + +static struct tst_test test = { + .setup = setup, + .test_all = verify_clock_settime, + .cleanup = cleanup, + .needs_root =1 , +};testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +128
-0@@ -0,0 +1,171 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2018 Linaro Limited. All rights reserved. +* Author: Rafael David Tinoco <[email protected]> +*/ + +/* +* Basic tests for errors of clock_settime(2) on different clock types. +*/ + +#include "config.h" +#include "tst_test.h" +#include "lapi/syscalls.h" + +#define DELTA_SEC 10 +#define NSEC_PER_SEC (1000000000L) +#define MAX_CLOCKS 16 + +static struct timespec clock_realtime_saved; + +struct test_case { +clockid_t type; +struct timespec newtime; +int exp_err; +int replace; +}; + +struct test_case tc[] = { + {/* case 01: REALTIME: timespec NULL */ + .type =CLOCK_REALTIME , + .newtime.tv_sec =-2 , + .exp_err =EFAULT , + .replace =1 , + }, + {/* case 02: REALTIME: tv_sec = -1 */ + .type =CLOCK_REALTIME , + .newtime.tv_sec =-1 , + .exp_err =EINVAL , + .replace =1 , + }, + {/* case 03: REALTIME: tv_nsec = -1 */ + .type =CLOCK_REALTIME , + .newtime.tv_nsec =-1 , + .exp_err =EINVAL , + .replace =1 , + }, + {/* case 04: REALTIME: tv_nsec = 1s+1 */ + .type =CLOCK_REALTIME , + .newtime.tv_nsec =NSEC_PER_SEC +1 , + .exp_err =EINVAL , + .replace =1 , + }, + {/* case 05: MONOTONIC */ + .type =CLOCK_MONOTONIC , + .exp_err =EINVAL , + }, + {/* case 06: MAXCLOCK */ + .type =MAX_CLOCKS , + .exp_err =EINVAL , + }, + {/* case 07: MAXCLOCK+1 */ + .type =MAX_CLOCKS +1 , + .exp_err =EINVAL , + }, +/* Linux specific */ + {/* case 08: CLOCK_MONOTONIC_COARSE */ + .type =CLOCK_MONOTONIC_COARSE , + .exp_err =EINVAL , + }, + {/* case 09: CLOCK_MONOTONIC_RAW */ + .type =CLOCK_MONOTONIC_RAW , + .exp_err =EINVAL , + }, + {/* case 10: CLOCK_BOOTTIME */ + .type =CLOCK_BOOTTIME , + .exp_err =EINVAL , + }, + {/* case 11: CLOCK_PROCESS_CPUTIME_ID */ + .type =CLOCK_PROCESS_CPUTIME_ID , + .exp_err =EINVAL , + }, + {/* case 12: CLOCK_THREAD_CPUTIME_ID */ + .type =CLOCK_THREAD_CPUTIME_ID , + .exp_err =EINVAL , + }, +}; + +/* +* Some tests may cause libc to segfault when passing bad arguments. +*/ +static int sys_clock_settime (clockid_t clk_id,struct timespec *tp) +{ +return tst_syscall (__NR_clock_settime, clk_id, tp); +} + +static int sys_clock_gettime (clockid_t clk_id,struct timespec *tp) +{ +return tst_syscall (__NR_clock_gettime, clk_id, tp); +} + +static void cleanup (void ) +{ +/* restore realtime clock */ + +if (sys_clock_settime (CLOCK_REALTIME , &clock_realtime_saved) <0 ) +tst_res (TBROK |TTERRNO ,"clock_settime(2): could not set " +"current time back" ); +} + +static void setup (void ) +{ +if (sys_clock_gettime (CLOCK_REALTIME , &clock_realtime_saved) <0 ) +tst_res (TBROK |TTERRNO ,"clock_gettime(2): could not get " +"current time" ); +} + +static void verify_clock_settime (unsigned int i) +{ +struct timespec spec, *specptr; + +if (tc[i].replace ==0 ) { + +/* add 1 sec to test clock */ + + specptr = &spec; + specptr->tv_sec = clock_realtime_saved.tv_sec +1 ; + specptr->tv_nsec = clock_realtime_saved.tv_nsec; +testcases/kernel/syscalls/clock_settime/clock_settime02.c line 138
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +10
-0+ }else { + +/* bad pointer case */ + +if (tc[i].newtime.tv_sec ==-2 ) + specptr =tst_get_bad_addr (cleanup); + +/* use given values */ + +else {Still curly braces missing here, but that is minor.
And maybe we just need to turn the newtime into a pointer in the tcases structure. Then you can initialize global variable to current time + epsion and use pointer to it or even initialize it inline as:
static struct timespec
valid_time;struct test_case tc[] = { { .type = CLOCK_REALTIME, .exp_err = EFAULT, }, { .type = CLOCK_REALTIME; .newtime = &valid_time; .exp_err = EINVAL, { .type = CLOCK_REALTIME, .newtime = &(struct timespec){}, .exp_err = EINVAL, .replace = 1, }, ... };
Quoted 2 lines
And we can loop in the test setup and set NULL address to the result of
tst_get_bad_addr()as well.
Good idea.
Quoted 29 lines
Quoted 29 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +28
-0+ specptr = &spec; + specptr->tv_sec = tc[i].newtime.tv_sec; + specptr->tv_nsec = tc[i].newtime.tv_nsec; + } + } + +TEST (sys_clock_settime (tc[i].type, specptr)); + +if (TST_RET ==-1 ) { + +if (tc[i].exp_err ==TST_ERR ) { + +tst_res (TPASS ,"clock_settime(2): failed as expected" ); + + }else { +tst_res (TFAIL |TTERRNO ,"clock_settime(2): " +"failed with different error" ); + } + +return ; + } + +tst_res (TFAIL |TTERRNO ,"clock_settime(2): clock type %d failed" , + tc[i].type); +} + +static struct tst_test test = { + .setup = setup,
Quoted 9 lines
Quoted 8 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +5
-0+ .test = verify_clock_settime, + .cleanup = cleanup, + .tcnt = ARRAY_SIZE(tc), + .needs_root = 1, +};Signature · 1 line
2.20.0.rc1
Thanks for reviewing... will re-work it.
Signature · 2 lines
Rafael D. Tinoco Linaro - Kernel Validation
PATCH v3 1/6 tst_timer.h: add tst_timespect_rem_us() function
In reply to Cyril HrubisExpand tst_timer.h functionality by having a function to also remove given microseconds from a given timespec.
--- include/tst_timer.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
include/tst_timer.h +17 -0
@@ -151,6 +151,23 @@ static inline struct timespec tst_timespec_add_us(struct timespec t,return t; } +/* +* Removes us microseconds to t. +*/ +static inline struct timespec tst_timespec_rem_us (struct timespec t, +long long us) +{ + t.tv_sec -= us /1000000 ; + t.tv_nsec -= (us %1000000 ) *1000 ; + +if (t.tv_nsec <0 ) { + t.tv_sec--; + t.tv_nsec +=1000000000 ; + } + +return t; +} +/* * Returns difference between two timespec structures. */
Signature · 1 line
2.20.0.rc1
PATCH v3 2/6 lib: add tst_clock_settime() to tst_clocks.h
Adds tst_clock_settime() function to the lib.
--- include/tst_clocks.h | 2 ++ lib/tst_clocks.c | 5 +++++ 2 files changed, 7 insertions(+)
include/tst_clocks.h +2 -0
@@ -26,4 +26,6 @@ int tst_clock_getres(clockid_t clk_id, struct timespec *res);int tst_clock_gettime (clockid_t clk_id,struct timespec *ts); +int tst_clock_settime (clockid_t clk_id,struct timespec *ts); +#endif /* TST_CLOCKS__ */
lib/tst_clocks.c +5 -0
@@ -35,3 +35,8 @@ int tst_clock_gettime(clockid_t clk_id, struct timespec *ts) {return syscall (SYS_clock_gettime, clk_id, ts); } + +int tst_clock_settime (clockid_t clk_id,struct timespec *ts) +{ +return syscall (SYS_clock_settime, clk_id, ts); +}
Signature · 1 line
2.20.0.rc1
PATCH v3 3/6 lib: include SAFE_CLOCK_SETTIME() macro
In reply to Rafael David TinocoAdds SAFE_CLOCK_SETTIME() macro to tst_safe_clocks.h.
--- include/tst_safe_clocks.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/tst_safe_clocks.h +14 -0
@@ -30,9 +30,23 @@ static inline void safe_clock_gettime(const char *file, const int lineno, "%s:%d clock_gettime() failed", file, lineno); } + +static inline void safe_clock_settime (const char *file,const int lineno, +clockid_t clk_id,struct timespec *tp) +{ +int rval; + + rval =clock_settime (clk_id, tp); +if (rval !=0 ) +tst_brk (TBROK |TERRNO , +"%s:%d clock_gettime() failed" , file, lineno); +} +#define SAFE_CLOCK_GETRES (clk_id, res)\ safe_clock_getres(__FILE__, __LINE__, (clk_id), (res))#define SAFE_CLOCK_GETTIME (clk_id, tp)\ safe_clock_gettime(__FILE__, __LINE__, (clk_id), (tp)) +#define SAFE_CLOCK_SETTIME (clk_id, tp)\ + safe_clock_settime(__FILE__, __LINE__, (clk_id), (tp))
Signature · 1 line
2.20.0.rc1
PATCH v3 4/6 lib: new restore_wallclock field to restore realtime clock
In reply to Rafael David TinocoSome tests around clocks need to restore the correct date and time after the tests, including possible iterations, run.
This commit introduces a new field to tst_test called "restore_wallclock", which makes the test to save current realtime clock during setup phase, and, later, during cleanup, restore it to the appropriate time using a monotonic raw clock difference.
--- include/tst_test.h | 1 + lib/tst_test.c | 6 ++++++ lib/tst_wallclock.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lib/tst_wallclock.c
include/tst_test.h +1 -0
@@ -131,6 +131,7 @@ struct tst_test { int needs_rofs:1; int child_needs_reinit:1; int needs_devfs:1; + int restore_wallclock:1;/* * If set the test function will be executed for all available * filesystems and the current filesytem type would be set in the
lib/tst_test.c +6 -0
@@ -868,6 +868,9 @@ static void do_setup(int argc, char *argv[])if (tst_test->resource_files)copy_resources (); + +if (tst_test->restore_wallclock) +tst_wallclock_save (); }static void do_test_setup (void )
@@ -899,6 +902,9 @@ static void do_cleanup(void)tst_sys_conf_restore (0 );cleanup_ipc (); + +if (tst_test->restore_wallclock) +tst_wallclock_restore (); }static void run_tests (void )
lib/tst_wallclock.c new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.20.0.rc1
PATCH v3 4/6 lib: new restore_wallclock field to restore realtime clock
Hi!
Quoted 8 lines
Some tests around clocks need to restore the correct date and time after the tests, including possible iterations, run.
This commit introduces a new field to
tst_testcalled "restore_wallclock", which makes the test to save current realtime clock during setup phase, and, later, during cleanup, restore it to the appropriate time using a monotonic raw clock difference.
Quoted 5 lines
Signed-off-by Rafael David Tinoco <[email protected]>--- include/tst_test.h | 1 + lib/tst_test.c | 6 ++++++ lib/tst_wallclock.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
We need to add include/tst_wallclock.h for the function prototypes which should be then included in the tst_test.c.
And we should definitelly add a paragraph about this functionality into the doc/test-writing-guidelines.txt.
Quoted 73 lines
3 files changed, 51 insertions(+) create mode 100644 lib/tst_wallclock.cinclude/tst_test.h +1
-0@@ -131,6 +131,7 @@ struct tst_test { int needs_rofs:1; int child_needs_reinit:1; int needs_devfs:1; + int restore_wallclock:1;/* * If set the test function will be executed for all available * filesystems and the current filesytem type would be set in the lib/tst_test.c +6
-0@@ -868,6 +868,9 @@ static void do_setup(int argc, char *argv[])if (tst_test->resource_files)copy_resources (); + +if (tst_test->restore_wallclock) +tst_wallclock_save (); }static void do_test_setup (void )@@ -899,6 +902,9 @@ static void do_cleanup(void)tst_sys_conf_restore (0 );cleanup_ipc (); + +if (tst_test->restore_wallclock) +tst_wallclock_restore (); }static void run_tests (void )lib/tst_wallclock.c new file +28
-0@@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2018 Linaro Limited. All rights reserved. +* Author: Rafael David Tinoco <[email protected]> +*/ + +#include <errno.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" +#include "tst_timer.h" +#include "tst_clocks.h" +#include "lapi/posix_clocks.h" + +static struct timespec real_begin, mono_begin; + +void tst_wallclock_save (void ) +{ +/* save initial monotonic time to restore it when needed */ + +if (tst_clock_gettime (CLOCK_REALTIME , &real_begin)) +tst_brk (TBROK |TERRNO ,"tst_clock_gettime() realtime failed" ); + +if (tst_clock_gettime (CLOCK_MONOTONIC_RAW , &mono_begin)) +tst_brk (TBROK |TERRNO ,"tst_clock_gettime() monotonic failed" ); +} +
lib/tst_wallclock.c line 38
Quoted 10 lines
lib/tst_wallclock.c new file +10
-0+void tst_wallclock_restore (void ) +{ +static struct timespec mono_end, elapsed, adjust; + +if (tst_clock_gettime (CLOCK_MONOTONIC_RAW , &mono_end)) +tst_brk (TBROK |TERRNO ,"tst_clock_gettime() monotonic failed" ); + + elapsed =tst_timespec_diff (mono_end, mono_begin); + + adjust =tst_timespec_add_us (real_begin,tst_timespec_to_us (elapsed));
It may be a bit cleaner to add tst_timespec_add() so that we do not have to convert the value between ns and us back and forth, but that is very minor as well.
Quoted 8 lines
lib/tst_wallclock.c new file +5
-0+/* restore realtime clock based on monotonic delta */ + +if (tst_clock_settime (CLOCK_REALTIME , &adjust)) +tst_brk (TBROK |TERRNO ,"tst_clock_settime() realtime failed" ); +}Signature · 1 line
2.20.0.rc1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 5/6 syscalls/clock_settime: create syscall clock_settime tests
In reply to Rafael David Tinococlock_settime01 creates a new test, using new API, based on existing and older kernel/timers/clock_settime02 test. clock_settime02 creates another test based on older kernel/timers/clock_settime03 test. Both will be deleted in the next commits.
--- runtest/syscalls | 3 + .../kernel/syscalls/clock_settime/.gitignore | 2 + .../kernel/syscalls/clock_settime/Makefile | 8 + .../syscalls/clock_settime/clock_settime01.c | 75 +++++++++ .../syscalls/clock_settime/clock_settime02.c | 150 ++++++++++++++++++ 5 files changed, 238 insertions(+) create mode 100644 testcases/kernel/syscalls/clock_settime/.gitignore create mode 100644 testcases/kernel/syscalls/clock_settime/Makefile create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime01.c create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime02.c
runtest/syscalls +3 -0
@@ -79,6 +79,9 @@ clock_nanosleep01 clock_nanosleep01 clock_nanosleep02 clock_nanosleep02 clock_nanosleep2_01 clock_nanosleep2_01 +clock_settime01 clock_settime01 +clock_settime02 clock_settime02 + clone01 clone01 clone02 clone02 clone03 clone03
testcases/kernel/syscalls/clock_settime/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +clock_settime01 +clock_settime02
testcases/kernel/syscalls/clock_settime/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# Copyright (c) 2018 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +75 -0
75 lines not on this page · raw message
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +150 -0
150 lines not on this page · raw message
Signature · 1 line
2.20.0.rc1
PATCH v3 5/6 syscalls/clock_settime: create syscall clock_settime tests
Quoted 159 lines · Rafael David Tinoco
Fixes 343
clock_settime01creates a new test, using new API, based on existing and olderkernel/timers/clock_settime02test.clock_settime02creates another test based on olderkernel/timers/clock_settime03test. Both will be deleted in the next commits.Signed-off-by Rafael David Tinoco <[email protected]>--- runtest/syscalls | 3 + .../kernel/syscalls/clock_settime/.gitignore | 2 + .../kernel/syscalls/clock_settime/Makefile | 8 + .../syscalls/clock_settime/clock_settime01.c | 75 +++++++++ .../syscalls/clock_settime/clock_settime02.c | 150 ++++++++++++++++++ 5 files changed, 238 insertions(+) create mode 100644 testcases/kernel/syscalls/clock_settime/.gitignore create mode 100644 testcases/kernel/syscalls/clock_settime/Makefile create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime01.c create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime02.cruntest/syscalls +3
-0@@ -79,6 +79,9 @@ clock_nanosleep01 clock_nanosleep01 clock_nanosleep02 clock_nanosleep02 clock_nanosleep2_01 clock_nanosleep2_01 +clock_settime01 clock_settime01 +clock_settime02 clock_settime02 + clone01 clone01 clone02 clone02 clone03 clone03testcases/kernel/syscalls/clock_settime/.gitignore new file +2
-0@@ -0,0 +1,2 @@ +clock_settime01 +clock_settime02testcases/kernel/syscalls/clock_settime/Makefile new file +8
-0@@ -0,0 +1,8 @@ +# Copyright (c) 2018 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/syscalls/clock_settime/clock_settime01.c new file +75
-0@@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2018 Linaro Limited. All rights reserved. +* Author: Rafael David Tinoco <[email protected]> +*/ + +/* +* Basic test for clock_settime(2) on REALTIME clock: +* +* 1) advance DELTA_SEC seconds +* 2) go backwards DELTA_SEC seconds +* +* Restore wall clock at the end of test. +*/ + +#include "config.h" +#include "tst_timer.h" +#include "tst_safe_clocks.h" +#include "tst_test.h" +#include "lapi/syscalls.h" + +#define DELTA_SEC 10 +#define DELTA_SEC_US (long long) (DELTA_SEC * 1000000) +#define DELTA_SEC_VAR_POS (long long) (DELTA_SEC_US * 1.10) +#define DELTA_SEC_VAR_NEG (long long) (DELTA_SEC_US * 0.90) + +static void verify_clock_settime (void ) +{ +long long elapsed; +struct timespec begin, change, end; + +/* test 01: move forward */ + +SAFE_CLOCK_GETTIME (CLOCK_REALTIME , &begin); + + change =tst_timespec_add_us (begin,DELTA_SEC_US ); + +if (clock_settime (CLOCK_REALTIME , &change) !=0 ) +tst_brk (TBROK |TTERRNO ,"could not set realtime change" ); + +SAFE_CLOCK_GETTIME (CLOCK_REALTIME , &end); + + elapsed =tst_timespec_diff_us (end, begin); + +if (elapsed >DELTA_SEC_US && elapsed <DELTA_SEC_VAR_POS ) { +tst_res (TPASS ,"clock_settime(2): was able to advance time" ); + }else { +tst_res (TFAIL ,"clock_settime(2): could not advance time" ); + } + +/* test 02: move backward */ + +SAFE_CLOCK_GETTIME (CLOCK_REALTIME , &begin); + + change =tst_timespec_rem_us (begin,DELTA_SEC_US ); + +if (clock_settime (CLOCK_REALTIME , &change) !=0 ) +tst_brk (TBROK |TTERRNO ,"could not set realtime change" ); + +SAFE_CLOCK_GETTIME (CLOCK_REALTIME , &end); + + elapsed =tst_timespec_diff_us (end, begin); + +if (~(elapsed) >DELTA_SEC_VAR_NEG ) { +tst_res (TPASS ,"clock_settime(2): was able to recede time" ); + }else { +tst_res (TFAIL ,"clock_settime(2): could not recede time" ); + } +} + +static struct tst_test test = { + .test_all = verify_clock_settime, + .needs_root =1 , + .restore_wallclock =1 , +};testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +16
-0@@ -0,0 +1,150 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2018 Linaro Limited. All rights reserved. +* Author: Rafael David Tinoco <[email protected]> +*/ + +/* +* Basic tests for errors of clock_settime(2) on different clock types. +*/ + +#include "config.h" +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "tst_timer.h" +#include "tst_safe_clocks.h" +
testcases/kernel/syscalls/clock_settime/clock_settime02.c line 26
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +10
-0+#define DELTA_SEC 10 +#define NSEC_PER_SEC (1000000000L) +#define MAX_CLOCKS 16 + +struct test_case { +clockid_t type; +struct timespec newtime; +int exp_err; +int replace; +};
Cyril, I haven't done a global timespec, having a pointer inside the test_case structure, just because there are a few other tests, like when having sec to -1, nsec to -1, etc.. and I wouldn't be able to set those during compilation time.. I hope you don't mind, test is functional and working good.
Signature · 2 lines
Rafael D. Tinoco Linaro - Kernel Validation
PATCH v3 5/6 syscalls/clock_settime: create syscall clock_settime tests
In reply to Rafael David TinocoHi!
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 23
Quoted 8 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +8
-0+#include "config.h" +#include "tst_timer.h" +#include "tst_safe_clocks.h" +#include "tst_test.h" +#include "lapi/syscalls.h" + +#define DELTA_SEC 10 +#define DELTA_SEC_US (long long) (DELTA_SEC * 1000000)
^
Maybe just DELTA_US having both SEC and US in the name is confusing.
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 25
Quoted 2 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +2
-0+#define DELTA_SEC_VAR_POS (long long) (DELTA_SEC_US * 1.10) +#define DELTA_SEC_VAR_NEG (long long) (DELTA_SEC_US * 0.90)
It would be probably more clear to just define epsilon here as
#define DELTA_EPS (DELTA_US * 0.1)
Then use it as DELTA_US + DELTA_EPS and DELTA_US - DELTA_EPS
Quoted 13 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +13
-0+static void verify_clock_settime (void ) +{ +long long elapsed; +struct timespec begin, change, end; + +/* test 01: move forward */ + +SAFE_CLOCK_GETTIME (CLOCK_REALTIME , &begin); + + change =tst_timespec_add_us (begin,DELTA_SEC_US ); + +if (clock_settime (CLOCK_REALTIME , &change) !=0 ) +tst_brk (TBROK |TTERRNO ,"could not set realtime change" );
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 49
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +10
-0+ +SAFE_CLOCK_GETTIME (CLOCK_REALTIME , &end); + + elapsed =tst_timespec_diff_us (end, begin); + +if (elapsed >DELTA_SEC_US && elapsed <DELTA_SEC_VAR_POS ) { +tst_res (TPASS ,"clock_settime(2): was able to advance time" ); + }else { +tst_res (TFAIL ,"clock_settime(2): could not advance time" ); + }
The curly braces around these one line statements are useless here.
Quoted 4 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +4
-0+/* test 02: move backward */ + +SAFE_CLOCK_GETTIME (CLOCK_REALTIME , &begin); +
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 64
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +10
-0+ change =tst_timespec_rem_us (begin,DELTA_SEC_US ); + +if (clock_settime (CLOCK_REALTIME , &change) !=0 ) +tst_brk (TBROK |TTERRNO ,"could not set realtime change" ); + +SAFE_CLOCK_GETTIME (CLOCK_REALTIME , &end); + + elapsed =tst_timespec_diff_us (end, begin); + +if (~(elapsed) >DELTA_SEC_VAR_NEG ) {
We still does not check that the time wasn't set too much into history so this should be adjusted just like the previous condition to:
if (~(elapsed) < DELTA_US && ~(elapsed) > DELTA_US - DELTA_EPS)
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 68
Quoted 4 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +4
-0+tst_res (TPASS ,"clock_settime(2): was able to recede time" ); + }else { +tst_res (TFAIL ,"clock_settime(2): could not recede time" ); + }
Again useless curly braces.
Quoted 101 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +7
-0+} + +static struct tst_test test = { + .test_all = verify_clock_settime, + .needs_root =1 , + .restore_wallclock =1 , +};testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +88
-0@@ -0,0 +1,150 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2018 Linaro Limited. All rights reserved. +* Author: Rafael David Tinoco <[email protected]> +*/ + +/* +* Basic tests for errors of clock_settime(2) on different clock types. +*/ + +#include "config.h" +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "tst_timer.h" +#include "tst_safe_clocks.h" + +#define DELTA_SEC 10 +#define NSEC_PER_SEC (1000000000L) +#define MAX_CLOCKS 16 + +struct test_case { +clockid_t type; +struct timespec newtime; +int exp_err; +int replace; +}; + +struct test_case tc[] = { + {/* case 01: REALTIME: timespec NULL */ + .type =CLOCK_REALTIME , + .newtime.tv_sec =-2 , + .exp_err =EFAULT , + .replace =1 , + }, + {/* case 02: REALTIME: tv_sec = -1 */ + .type =CLOCK_REALTIME , + .newtime.tv_sec =-1 , + .exp_err =EINVAL , + .replace =1 , + }, + {/* case 03: REALTIME: tv_nsec = -1 */ + .type =CLOCK_REALTIME , + .newtime.tv_nsec =-1 , + .exp_err =EINVAL , + .replace =1 , + }, + {/* case 04: REALTIME: tv_nsec = 1s+1 */ + .type =CLOCK_REALTIME , + .newtime.tv_nsec =NSEC_PER_SEC +1 , + .exp_err =EINVAL , + .replace =1 , + }, + {/* case 05: MONOTONIC */ + .type =CLOCK_MONOTONIC , + .exp_err =EINVAL , + }, + {/* case 06: MAXCLOCK */ + .type =MAX_CLOCKS , + .exp_err =EINVAL , + }, + {/* case 07: MAXCLOCK+1 */ + .type =MAX_CLOCKS +1 , + .exp_err =EINVAL , + }, +/* Linux specific */ + {/* case 08: CLOCK_MONOTONIC_COARSE */ + .type =CLOCK_MONOTONIC_COARSE , + .exp_err =EINVAL , + }, + {/* case 09: CLOCK_MONOTONIC_RAW */ + .type =CLOCK_MONOTONIC_RAW , + .exp_err =EINVAL , + }, + {/* case 10: CLOCK_BOOTTIME */ + .type =CLOCK_BOOTTIME , + .exp_err =EINVAL , + }, + {/* case 11: CLOCK_PROCESS_CPUTIME_ID */ + .type =CLOCK_PROCESS_CPUTIME_ID , + .exp_err =EINVAL , + }, + {/* case 12: CLOCK_THREAD_CPUTIME_ID */ + .type =CLOCK_THREAD_CPUTIME_ID , + .exp_err =EINVAL , + }, +}; + +/*
testcases/kernel/syscalls/clock_settime/clock_settime02.c line 98
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +10
-0+* Some tests may cause libc to segfault when passing bad arguments. +*/ +static int sys_clock_settime (clockid_t clk_id,struct timespec *tp) +{ +return tst_syscall (__NR_clock_settime, clk_id, tp); +} + +static void verify_clock_settime (unsigned int i) +{ +struct timespec saved, spec, *specptr;
I would have initialized the specptr = &spec here and only replaced it down there if we are hitting the EFAULT case.
testcases/kernel/syscalls/clock_settime/clock_settime02.c line 107
Quoted 8 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +8
-0+if (tc[i].replace ==0 ) { + +SAFE_CLOCK_GETTIME (CLOCK_REALTIME , &saved); + +/* add 1 sec to test clock */ + specptr = &spec; + specptr->tv_sec = saved.tv_sec +1 ; + specptr->tv_nsec = saved.tv_nsec;
And we don't need the saved here anymore, so we can really do clock_gettime() on the specptr here, right?
testcases/kernel/syscalls/clock_settime/clock_settime02.c line 115
Quoted 7 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +7
-0+ }else { + + +if (tc[i].newtime.tv_sec ==-2 ) { + +/* bad pointer case */ + specptr =tst_get_bad_addr (NULL );
Maybe we can just look for EFAULT errno instead of having magic tv_sec value.
testcases/kernel/syscalls/clock_settime/clock_settime02.c line 121
Quoted 6 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +6
-0+ }else { + +/* use given values */ + specptr = &spec; + specptr->tv_sec = tc[i].newtime.tv_sec; + specptr->tv_nsec = tc[i].newtime.tv_nsec;
You can do simple spec = tc[i].newtime here.
Quoted 6 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +3
-0+ } + } +TEST (sys_clock_settime (tc[i].type, specptr));
testcases/kernel/syscalls/clock_settime/clock_settime02.c line 135
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +10
-0+ +if (TST_RET ==-1 ) { + +if (tc[i].exp_err ==TST_ERR ) { + +tst_res (TPASS ,"clock_settime(2): failed as expected" ); + + }else { +tst_res (TFAIL |TTERRNO ,"clock_settime(2): " +"failed with different error" );
I would be better to print the expected errno here as well something as:
tst_res(TFAIL | TTERRNO, "clock_settime(%s, ...) expected %s", clock_name(tc[i].type), tst_strerrno(tc[i].exp_err));
testcases/kernel/syscalls/clock_settime/clock_settime02.c line 142
Quoted 7 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +7
-0+ } + +return ; + } + +tst_res (TFAIL |TTERRNO ,"clock_settime(2): clock type %d failed" , + tc[i].type);
Shouldn't this say:
tst_res(TFAIL, "clock_settime(%s, ...) passed unexpectedly, expected %s", clock_name(tc[i].type), tst_strerrno(tc[i].exp_err));
Quoted 11 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +8
-0+} + +static struct tst_test test = { + .test = verify_clock_settime, + .tcnt =ARRAY_SIZE (tc), + .needs_root =1 , + .restore_wallclock =1 , +};Signature · 1 line
2.20.0.rc1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/8 lib: add tst_clock_settime() to tst_clocks.h
Adds tst_clock_settime() function to the lib.
--- include/tst_clocks.h | 2 ++ lib/tst_clocks.c | 5 +++++ 2 files changed, 7 insertions(+)
include/tst_clocks.h +2 -0
@@ -26,4 +26,6 @@ int tst_clock_getres(clockid_t clk_id, struct timespec *res);int tst_clock_gettime (clockid_t clk_id,struct timespec *ts); +int tst_clock_settime (clockid_t clk_id,struct timespec *ts); +#endif /* TST_CLOCKS__ */
lib/tst_clocks.c +5 -0
@@ -35,3 +35,8 @@ int tst_clock_gettime(clockid_t clk_id, struct timespec *ts) {return syscall (SYS_clock_gettime, clk_id, ts); } + +int tst_clock_settime (clockid_t clk_id,struct timespec *ts) +{ +return syscall (SYS_clock_settime, clk_id, ts); +}
Signature · 1 line
2.20.1
PATCH v4 2/8 lib: include SAFE_CLOCK_SETTIME() macro
Adds SAFE_CLOCK_SETTIME() macro to tst_safe_clocks.h.
--- include/tst_safe_clocks.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/tst_safe_clocks.h +14 -0
@@ -30,9 +30,23 @@ static inline void safe_clock_gettime(const char *file, const int lineno, "%s:%d clock_gettime() failed", file, lineno); } + +static inline void safe_clock_settime (const char *file,const int lineno, +clockid_t clk_id,struct timespec *tp) +{ +int rval; + + rval =clock_settime (clk_id, tp); +if (rval !=0 ) +tst_brk (TBROK |TERRNO , +"%s:%d clock_gettime() failed" , file, lineno); +} +#define SAFE_CLOCK_GETRES (clk_id, res)\ safe_clock_getres(__FILE__, __LINE__, (clk_id), (res))#define SAFE_CLOCK_GETTIME (clk_id, tp)\ safe_clock_gettime(__FILE__, __LINE__, (clk_id), (tp)) +#define SAFE_CLOCK_SETTIME (clk_id, tp)\ + safe_clock_settime(__FILE__, __LINE__, (clk_id), (tp))
Signature · 1 line
2.20.1
PATCH v4 3/8 tst_timer: Add tst_timespec_add()
In reply to Rafael David TinocoThis commit adds a tst_timespec_add() function that adds two given timespec structs. It is needed in order to avoid unneeded ns <-> us conversions because, so far, there is only tst_timespec_add_us() available.
--- include/tst_timer.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
include/tst_timer.h +19 -0
@@ -151,6 +151,25 @@ static inline struct timespec tst_timespec_add_us(struct timespec t,return t; } +/* +* Adds two timespec structures. +*/ +static inline struct timespec tst_timespec_add (struct timespec t1, +struct timespec t2) +{ +struct timespec res; + + res.tv_sec = t1.tv_sec + t2.tv_sec; + res.tv_nsec = t1.tv_nsec + t2.tv_nsec; + +if (res.tv_nsec >=1000000000 ) { + res.tv_sec++; + res.tv_nsec -=1000000000 ; + } + +return res; +} +/* * Returns difference between two timespec structures. */
Signature · 1 line
2.20.1
PATCH v4 4/8 lib: new restore_wallclock field to restore realtime clock
In reply to Rafael David TinocoSome tests that change the system-wide clock need to have a way to restore the correct time after their execution.
This commit introduces a new field to tst_test struct called "restore_wallclock": it makes the test to save current realtime clock during setup phase, and, later, during cleanup, restore it to the appropriate time using a monotonic raw clock difference.
--- doc/test-writing-guidelines.txt | 35 +++++++++++++++++++++++++ include/tst_test.h | 1 + include/tst_wallclock.h | 15 +++++++++++ lib/tst_test.c | 7 +++++ lib/tst_wallclock.c | 45 +++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 include/tst_wallclock.h create mode 100644 lib/tst_wallclock.c
doc/test-writing-guidelines.txt +35 -0
@@ -1539,6 +1539,41 @@ static struct tst_test test = { }; ------------------------------------------------------------------------------- +2.2.29 Changing the Wall Clock Time during test execution +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +There are some tests that, for different reasons, might need to change the +system-wide clock time. Whenever this happens, it is imperative that the clock +is restored, at the end of test's execution, taking in consideration the amount +of time elapsed during that test. + +In order for that to happen, struct tst_test has a variable called +"restore_wallclock" that should be set to "1" so LTP knows it should: (1) +initialize a monotonic clock during test setup phase and (2) use that monotonic +clock to fix the system-wide clock time at the test cleanup phase. + +[source,c] +------------------------------------------------------------------------------- +#include "tst_test.h" + +static void setup(void) +{ + ... +} + +static void run(void) +{ + ... +} + +sturct tst_test test = { + ... + .setup = setup, + .test_all = run, + .restore_wallclock = 1, + ... +}; +------------------------------------------------------------------------------- 2.3 Writing a testcase in shell ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/tst_test.h +1 -0
@@ -135,6 +135,7 @@ struct tst_test { int needs_rofs:1; int child_needs_reinit:1; int needs_devfs:1; + int restore_wallclock:1;/* * If set the test function will be executed for all available * filesystems and the current filesytem type would be set in the
include/tst_wallclock.h new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 Linaro Limited. All rights reserved. +* Author: Rafael David Tinoco <[email protected]> +*/ + + +#ifndef TST_WALLCLK_H__ +#define TST_WALLCLK_H__ + +void tst_wallclock_save (void ); + +void tst_wallclock_restore (void ); + +#endif /* TST_WALLCLK_H__ */
lib/tst_test.c +7 -0
@@ -35,6 +35,7 @@#include "tst_timer_test.h" #include "tst_clocks.h" #include "tst_timer.h" +#include "tst_wallclock.h" #include "tst_sys_conf.h" #include "tst_kconfig.h"
@@ -872,6 +873,9 @@ static void do_setup(int argc, char *argv[])if (tst_test->resource_files)copy_resources (); + +if (tst_test->restore_wallclock) +tst_wallclock_save (); }static void do_test_setup (void )
@@ -903,6 +907,9 @@ static void do_cleanup(void)tst_sys_conf_restore (0 );cleanup_ipc (); + +if (tst_test->restore_wallclock) +tst_wallclock_restore (); }static void run_tests (void )
lib/tst_wallclock.c new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v4 4/8 lib: new restore_wallclock field to restore realtime clock
Hi!
I've changed the tst_wallclock.c so that it restores the time only if it was saved previously, otherwise we will either set completely wrong time if something has failed prior call to tst_wallclock_save() or generage bogus error messages when the test exits because of unsufficient priviledges.
full diff:
lib/tst_wallclock.c +9 -0
@@ -16,6 +16,8 @@static struct timespec real_begin, mono_begin; +static int clock_saved; +void tst_wallclock_save (void ) {/* save initial monotonic time to restore it when needed */
@@ -25,12 +27,19 @@ void tst_wallclock_save(void)if (tst_clock_gettime (CLOCK_MONOTONIC_RAW , &mono_begin))tst_brk (TBROK |TERRNO ,"tst_clock_gettime() monotonic failed" ); + + clock_saved =1 ; }void tst_wallclock_restore (void ) {static struct timespec mono_end, elapsed, adjust; +if (!clock_saved) +return ; + + clock_saved =0 ; +if (tst_clock_gettime (CLOCK_MONOTONIC_RAW , &mono_end))tst_brk (TBROK |TERRNO ,"tst_clock_gettime() monotonic failed" );
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 5/8 tst_timer: Add tst_timespec_sub_us()
In reply to Rafael David TinocoThis commit adds a tst_timespec_sub_us() function that subtracts microseconds from a given timespec struct.
--- include/tst_timer.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
include/tst_timer.h +17 -0
@@ -170,6 +170,23 @@ static inline struct timespec tst_timespec_add(struct timespec t1,return res; } +/* +* Subtracts us microseconds from t. +*/ +static inline struct timespec tst_timespec_sub_us (struct timespec t, +long long us) +{ + t.tv_sec -= us /1000000 ; + t.tv_nsec -= (us %1000000 ) *1000 ; + +if (t.tv_nsec <0 ) { + t.tv_sec--; + t.tv_nsec +=1000000000 ; + } + +return t; +} +/* * Returns difference between two timespec structures. */
Signature · 1 line
2.20.1
PATCH v4 6/8 tst_timer: Turn clock_name() function public
In reply to Rafael David TinocoThis commit exposes clock_name() function by removing its static definition and creating a public function prototype. This function is needed by clock/alarm tests and their error messages.
--- include/tst_timer.h | 5 +++++ lib/tst_timer.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-)
include/tst_timer.h +5 -0
@@ -332,4 +332,9 @@ static inline long long tst_timer_elapsed_us(void) return tst_timespec_to_us(tst_timer_elapsed()); } +/* +* Returns a string containing given clock type name +*/ +const char *clock_name (clockid_t ); +#endif /* TST_TIMER */
lib/tst_timer.c +1 -1
@@ -15,7 +15,7 @@static struct timespec start_time, stop_time;static clockid_t clock_id; -static const char *clock_name (clockid_t clk_id) +const char *clock_name (clockid_t clk_id) {switch (clk_id) {case CLOCK_REALTIME :
Signature · 1 line
2.20.1
PATCH v4 6/8 tst_timer: Turn clock_name() function public
Hi!
I've renamed the function to tst_clock_name() just to keep it consistent with the rest of the LTP API.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 7/8 syscalls/clock_settime: create syscall clock_settime tests
In reply to Rafael David Tinococlock_settime01 creates a new test, using new API, based on existing and older kernel/timers/clock_settime02 test. clock_settime02 creates another test based on older kernel/timers/clock_settime03 test. Both will be deleted in the next commits.
--- runtest/syscalls | 3 + .../kernel/syscalls/clock_settime/.gitignore | 2 + .../kernel/syscalls/clock_settime/Makefile | 8 + .../syscalls/clock_settime/clock_settime01.c | 72 +++++++++ .../syscalls/clock_settime/clock_settime02.c | 148 ++++++++++++++++++ 5 files changed, 233 insertions(+) create mode 100644 testcases/kernel/syscalls/clock_settime/.gitignore create mode 100644 testcases/kernel/syscalls/clock_settime/Makefile create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime01.c create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime02.c
runtest/syscalls +3 -0
@@ -79,6 +79,9 @@ clock_nanosleep01 clock_nanosleep01 clock_nanosleep02 clock_nanosleep02 clock_nanosleep2_01 clock_nanosleep2_01 +clock_settime01 clock_settime01 +clock_settime02 clock_settime02 + clone01 clone01 clone02 clone02 clone03 clone03
testcases/kernel/syscalls/clock_settime/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +clock_settime01 +clock_settime02
testcases/kernel/syscalls/clock_settime/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# Copyright (c) 2018 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +72 -0
72 lines not on this page · raw message
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v4 7/8 syscalls/clock_settime: create syscall clock_settime tests
Hi!
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 47
Quoted 4 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +4
-0+if (elapsed >DELTA_US && elapsed < (DELTA_US +DELTA_EPS )) +tst_res (TPASS ,"clock_settime(2): was able to advance time" ); +else +tst_res (TFAIL ,"clock_settime(2): could not advance time" );
I've changed this to elapsed >= DELTA_US just in case.
Quoted 7 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +7
-0+/* test 02: move backward */ + +SAFE_CLOCK_GETTIME (CLOCK_REALTIME , &begin); + + change =tst_timespec_sub_us (begin,DELTA_US ); + +if (clock_settime (CLOCK_REALTIME , &change) !=0 )
testcases/kernel/syscalls/clock_settime/clock_settime01.c line 65
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +10
-0+tst_brk (TBROK |TTERRNO ,"could not set realtime change" ); + +SAFE_CLOCK_GETTIME (CLOCK_REALTIME , &end); + + elapsed =tst_timespec_diff_us (end, begin); + +if (~(elapsed) <DELTA_US && ~(elapsed) > (DELTA_US -DELTA_EPS )) +tst_res (TPASS ,"clock_settime(2): was able to recede time" ); +else +tst_res (TFAIL ,"clock_settime(2): could not recede time" );
And here as well.
Quoted 127 lines
testcases/kernel/syscalls/clock_settime/clock_settime01.c new file +7
-0+} + +static struct tst_test test = { + .test_all = verify_clock_settime, + .needs_root =1 , + .restore_wallclock =1 , +};testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +114
-0@@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 Linaro Limited. All rights reserved. +* Author: Rafael David Tinoco <[email protected]> +*/ + +/* +* Basic tests for errors of clock_settime(2) on different clock types. +*/ + +#include "config.h" +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "tst_timer.h" +#include "tst_safe_clocks.h" + +#define DELTA_SEC 10 +#define NSEC_PER_SEC (1000000000L) +#define MAX_CLOCKS 16 + +struct test_case { +clockid_t type; +struct timespec newtime; +int exp_err; +int replace; +}; + +struct test_case tc[] = { + {/* case 01: REALTIME: timespec NULL */ + .type =CLOCK_REALTIME , + .exp_err =EFAULT , + .replace =1 , + }, + {/* case 02: REALTIME: tv_sec = -1 */ + .type =CLOCK_REALTIME , + .newtime.tv_sec =-1 , + .exp_err =EINVAL , + .replace =1 , + }, + {/* case 03: REALTIME: tv_nsec = -1 */ + .type =CLOCK_REALTIME , + .newtime.tv_nsec =-1 , + .exp_err =EINVAL , + .replace =1 , + }, + {/* case 04: REALTIME: tv_nsec = 1s+1 */ + .type =CLOCK_REALTIME , + .newtime.tv_nsec =NSEC_PER_SEC +1 , + .exp_err =EINVAL , + .replace =1 , + }, + {/* case 05: MONOTONIC */ + .type =CLOCK_MONOTONIC , + .exp_err =EINVAL , + }, + {/* case 06: MAXCLOCK */ + .type =MAX_CLOCKS , + .exp_err =EINVAL , + }, + {/* case 07: MAXCLOCK+1 */ + .type =MAX_CLOCKS +1 , + .exp_err =EINVAL , + }, +/* Linux specific */ + {/* case 08: CLOCK_MONOTONIC_COARSE */ + .type =CLOCK_MONOTONIC_COARSE , + .exp_err =EINVAL , + }, + {/* case 09: CLOCK_MONOTONIC_RAW */ + .type =CLOCK_MONOTONIC_RAW , + .exp_err =EINVAL , + }, + {/* case 10: CLOCK_BOOTTIME */ + .type =CLOCK_BOOTTIME , + .exp_err =EINVAL , + }, + {/* case 11: CLOCK_PROCESS_CPUTIME_ID */ + .type =CLOCK_PROCESS_CPUTIME_ID , + .exp_err =EINVAL , + }, + {/* case 12: CLOCK_THREAD_CPUTIME_ID */ + .type =CLOCK_THREAD_CPUTIME_ID , + .exp_err =EINVAL , + }, +}; + +/* +* Some tests may cause libc to segfault when passing bad arguments. +*/ +static int sys_clock_settime (clockid_t clk_id,struct timespec *tp) +{ +return tst_syscall (__NR_clock_settime, clk_id, tp); +} + +static void verify_clock_settime (unsigned int i) +{ +struct timespec spec, *specptr; + + specptr = &spec; + +if (tc[i].replace ==0 ) { + +SAFE_CLOCK_GETTIME (CLOCK_REALTIME , specptr); + +/* add 1 sec to wall clock */ + specptr->tv_sec +=1 ; + + }else { + +/* use given time spec */ + *specptr = tc[i].newtime; + } + +/* bad pointer case */
testcases/kernel/syscalls/clock_settime/clock_settime02.c line 124
Quoted 10 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +10
-0+if (tc[i].exp_err ==EFAULT ) + specptr =tst_get_bad_addr (NULL ); + +TEST (sys_clock_settime (tc[i].type, specptr)); + +if (TST_RET ==-1 ) { + +if (tc[i].exp_err ==TST_ERR ) { + +tst_res (TPASS ,"clock_settime(2): failed as expected" );
I've made this message a bit more verbose, we print withc kind of errno we got and name of the clock.
testcases/kernel/syscalls/clock_settime/clock_settime02.c line 131
Quoted 7 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +7
-0+ + }else { + +tst_res (TFAIL |TTERRNO ,"clock_settime(2): clock %s " +"expected %s, failed with %s instead." , +clock_name (tc[i].type), +tst_strerrno (tc[i].exp_err));
The format string didn't match the parameters here, fixed that.
Quoted 20 lines
testcases/kernel/syscalls/clock_settime/clock_settime02.c new file +17
-0+ } + +return ; + } + +tst_res (TFAIL |TTERRNO ,"clock_settime(2): clock %s passed " +"unexpectedly, expected %s" , +clock_name (tc[i].type), +tst_strerrno (tc[i].exp_err)); +} + +static struct tst_test test = { + .test = verify_clock_settime, + .tcnt =ARRAY_SIZE (tc), + .needs_root =1 , + .restore_wallclock =1 , +};Signature · 1 line
2.20.1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 8/8 timers/clock_settime: remove clock_settime tests
In reply to Rafael David Tinococlock_settime{01,02} syscall tests were created, using the new API, based on existing and older kernel/timers/clock_settime{02,03} tests.
This commit deletes older timers/clock_settime/* tests.
--- runtest/timers | 2 - .../kernel/timers/clock_settime/.gitignore | 2 - .../kernel/timers/clock_settime/Makefile | 27 --- .../timers/clock_settime/clock_settime02.c | 128 ------------- .../timers/clock_settime/clock_settime03.c | 173 ------------------ 5 files changed, 332 deletions(-) delete mode 100644 testcases/kernel/timers/clock_settime/.gitignore delete mode 100644 testcases/kernel/timers/clock_settime/Makefile delete mode 100644 testcases/kernel/timers/clock_settime/clock_settime02.c delete mode 100644 testcases/kernel/timers/clock_settime/clock_settime03.c
runtest/timers +0 -2
@@ -1,8 +1,6 @@ #DESCRIPTION:Posix Timer Tests clock_gettime02 clock_gettime02 clock_gettime03 clock_gettime03 -clock_settime02 clock_settime02 -clock_settime03 clock_settime03 timer_create02 timer_create02 timer_create03 timer_create03 timer_create04 timer_create04
testcases/kernel/timers/clock_settime/.gitignore deleted +0 -2
@@ -1,2 +0,0 @@ -/clock_settime02 -/clock_settime03
testcases/kernel/timers/clock_settime/Makefile deleted +0 -27
@@ -1,27 +0,0 @@ -# -# Copyright (c) International Business Machines Corp., 2001 -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# - -top_srcdir ?= ../../../.. - -include $(top_srcdir)/include/mk/testcases.mk - -CPPFLAGS += -D_GNU_SOURCE -I$(abs_srcdir)/../include - -LDLIBS += -lpthread -lrt - -include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/timers/clock_settime/clock_settime02.c deleted +0 -128
128 lines not on this page · raw message
testcases/kernel/timers/clock_settime/clock_settime03.c deleted +0 -173
173 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v4 1/8 lib: add tst_clock_settime() to tst_clocks.h
In reply to Rafael David TinocoHi!
Series pushed with some fine tunning (will respond to respective patches), thanks!
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/8 lib: add tst_clock_settime() to tst_clocks.h
Quoted 9 lines · Cyril Hrubis
Hi!
Series pushed with some fine tunning (will respond to respective patches), thanks!Signature · 2 lines
Cyril Hrubis [email protected]
Thanks a lot!
Best,
Rafael
PATCH v3 6/6 timers/clock_settime: remove clock_settime tests
In reply to Rafael David Tinococlock_settime01 creates a new test, using new API, based on existing and older kernel/timers/clock_settime tests. It includes tests from files clock_settime02 and clock_settime03.
This commit deletes timers/clock_settime/* tests.
--- runtest/timers | 2 - .../kernel/timers/clock_settime/.gitignore | 2 - .../kernel/timers/clock_settime/Makefile | 27 --- .../timers/clock_settime/clock_settime02.c | 128 ------------- .../timers/clock_settime/clock_settime03.c | 173 ------------------ 5 files changed, 332 deletions(-) delete mode 100644 testcases/kernel/timers/clock_settime/.gitignore delete mode 100644 testcases/kernel/timers/clock_settime/Makefile delete mode 100644 testcases/kernel/timers/clock_settime/clock_settime02.c delete mode 100644 testcases/kernel/timers/clock_settime/clock_settime03.c
runtest/timers +0 -2
@@ -1,8 +1,6 @@ #DESCRIPTION:Posix Timer Tests clock_gettime02 clock_gettime02 clock_gettime03 clock_gettime03 -clock_settime02 clock_settime02 -clock_settime03 clock_settime03 timer_create02 timer_create02 timer_create03 timer_create03 timer_create04 timer_create04
testcases/kernel/timers/clock_settime/.gitignore deleted +0 -2
@@ -1,2 +0,0 @@ -/clock_settime02 -/clock_settime03
testcases/kernel/timers/clock_settime/Makefile deleted +0 -27
@@ -1,27 +0,0 @@ -# -# Copyright (c) International Business Machines Corp., 2001 -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# - -top_srcdir ?= ../../../.. - -include $(top_srcdir)/include/mk/testcases.mk - -CPPFLAGS += -D_GNU_SOURCE -I$(abs_srcdir)/../include - -LDLIBS += -lpthread -lrt - -include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/timers/clock_settime/clock_settime02.c deleted +0 -128
128 lines not on this page · raw message
testcases/kernel/timers/clock_settime/clock_settime03.c deleted +0 -173
173 lines not on this page · raw message
Signature · 1 line
2.20.0.rc1
PATCH v3 6/6 timers/clock_settime: remove clock_settime tests
Ping ? =o)
Quoted 11 lines · Rafael David Tinoco
Fixes 343
clock_settime01creates a new test, using new API, based on existing and olderkernel/timers/clock_settimetests. It includes tests from filesclock_settime02andclock_settime03.This commit deletes timers/clock_settime/* tests.
Signed-off-by Rafael David Tinoco <[email protected]>
PATCH v3 6/6 timers/clock_settime: remove clock_settime tests
Hi!
Quoted 1 line
Ping ? =o)
We are in the middle of the pre-release freeze, I will get to you once the release is finalized.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 6/6 timers/clock_settime: remove clock_settime tests
Quoted 5 lines · Cyril Hrubis
Hi!
Quoted 1 line
Ping ? =o)
We are in the middle of the pre-release freeze, I will get to you once the release is finalized.
Alright. Thanks! I wasn’t sure because of EOY!
Good luck! o/
PATCH v3 6/6 timers/clock_settime: remove clock_settime tests
In reply to Rafael David TinocoI know you guys are catching up after the freeze, just making sure you don’t loose track of these 6 patches when you have time!
Thanks
Rafael
Quoted 17 lines
On 8 Jan 2019, at 10:04, Rafael David Tinoco
<[email protected]> wrote:Ping ? =o)
Quoted 12 lines
On 12 Dec 2018, at 18:37, Rafael David Tinoco
<[email protected]> wrote:Fixes 343
clock_settime01creates a new test, using new API, based on existing and olderkernel/timers/clock_settimetests. It includes tests from filesclock_settime02andclock_settime03.This commit deletes timers/clock_settime/* tests.
Signed-off-by Rafael David Tinoco <[email protected]>
PATCH v3 6/6 timers/clock_settime: remove clock_settime tests
Hi!
Quoted 2 lines
I know you guys are catching up after the freeze, just making sure you don???t loose track of these 6 patches when you have time!
Thanks for the ping :-).
I've just finished LTP GSoC application and was about to get to the patch review.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/6 tst_timer.h: add tst_timespect_rem_us() function
In reply to Rafael David TinocoHi!
Quoted 13 lines
Expand
tst_timer.hfunctionality by having a function to also remove given microseconds from a given timespec.Signed-off-by Rafael David Tinoco <[email protected]>--- include/tst_timer.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)include/tst_timer.h +0
-0
include/tst_timer.h static inline struct timespec tst_timespec_add_us(struct timespec t, · line 158
Quoted 8 lines
include/tst_timer.h +5
-0@@ -151,6 +151,23 @@ static inline struct timespec tst_timespec_add_us(struct timespec t,return t; } +/* +* Removes us microseconds to t. +*/ +static inline struct timespec tst_timespec_rem_us (struct timespec t, +long long us)
^
This is very minor but better name would be sub as in substract
Quoted 15 lines
include/tst_timer.h +12
-0+{ + t.tv_sec -= us /1000000 ; + t.tv_nsec -= (us %1000000 ) *1000 ; + +if (t.tv_nsec <0 ) { + t.tv_sec--; + t.tv_nsec +=1000000000 ; + } + +return t; +} +/* * Returns difference between two timespec structures. */
Signature · 2 lines
Cyril Hrubis [email protected]