Message ID | 1570767798-26685-2-git-send-email-xuyang2018.jy@cn.fujitsu.com |
---|---|
State | Changes Requested |
Headers | show |
Series | [v4,1/2] syscalls/prctl08: New test for prctl() with PR_{SET, GET}_TIMERSLACK | expand |
Hi! > +#include <errno.h> > +#include <sys/prctl.h> > +#include "lapi/prctl.h" > +#include "tst_timer_test.h" > + > +int sample_fn(int clk_id, long long usec) > +{ > + struct timespec t = tst_us_to_timespec(usec); > + > + TEST(prctl(PR_SET_TIMERSLACK, 200000)); This is a bit more complicated. First of all it does not make sense to set the timerslack in the sample function. It should be done once in the test setup. Also in the tst_timer_test.c we store the timerslack value in the timer_setup(), which executes the test setup() at the end of the function, so we would have to move the part that gets the timerslack() after the test setup() function so that the library includes the newly set timerslack in the calculation. > + if (TST_RET != 0) { > + tst_res(TFAIL | TTERRNO, > + "prctl(), returned %li", TST_RET); > + return 1; > + } > + > + tst_timer_start(clk_id); > + TEST(nanosleep(&t, NULL)); > + tst_timer_stop(); > + tst_timer_sample(); > + > + if (TST_RET != 0) { > + tst_res(TFAIL | TTERRNO, > + "nanosleep() returned %li", TST_RET); > + return 1; > + } > + > + return 0; > +} > + > +static struct tst_test test = { > + .scall = "prctl()", > + .sample = sample_fn, > +}; > -- > 2.18.1 > > >
on 2019/11/07 21:23, Cyril Hrubis wrote: > Hi! >> +#include <errno.h> >> +#include <sys/prctl.h> >> +#include "lapi/prctl.h" >> +#include "tst_timer_test.h" >> + >> +int sample_fn(int clk_id, long long usec) >> +{ >> + struct timespec t = tst_us_to_timespec(usec); >> + >> + TEST(prctl(PR_SET_TIMERSLACK, 200000)); > This is a bit more complicated. > > First of all it does not make sense to set the timerslack in the sample > function. It should be done once in the test setup. > > Also in the tst_timer_test.c we store the timerslack value in the > timer_setup(), which executes the test setup() at the end of the > function, so we would have to move the part that gets the timerslack() > after the test setup() function so that the library includes the newly > set timerslack in the calculation. Ok. I will set timerslack to 200us in setup and move timer_setup after test set up so that we can get the 200us value. > >> + if (TST_RET != 0) { >> + tst_res(TFAIL | TTERRNO, >> + "prctl(), returned %li", TST_RET); >> + return 1; >> + } >> + >> + tst_timer_start(clk_id); >> + TEST(nanosleep(&t, NULL)); >> + tst_timer_stop(); >> + tst_timer_sample(); >> + >> + if (TST_RET != 0) { >> + tst_res(TFAIL | TTERRNO, >> + "nanosleep() returned %li", TST_RET); >> + return 1; >> + } >> + >> + return 0; >> +} >> + >> +static struct tst_test test = { >> + .scall = "prctl()", >> + .sample = sample_fn, >> +}; >> -- >> 2.18.1 >> >> >>
diff --git a/runtest/syscalls b/runtest/syscalls index 76961a684..705d7f87e 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -879,6 +879,7 @@ prctl05 prctl05 prctl06 prctl06 prctl07 prctl07 prctl08 prctl08 +prctl09 prctl09 pread01 pread01 pread01_64 pread01_64 diff --git a/testcases/kernel/syscalls/prctl/.gitignore b/testcases/kernel/syscalls/prctl/.gitignore index fe36a8e0f..0f2c9b194 100644 --- a/testcases/kernel/syscalls/prctl/.gitignore +++ b/testcases/kernel/syscalls/prctl/.gitignore @@ -7,3 +7,4 @@ /prctl06_execve /prctl07 /prctl08 +/prctl09 diff --git a/testcases/kernel/syscalls/prctl/Makefile b/testcases/kernel/syscalls/prctl/Makefile index cf19507c0..c02b6d1de 100644 --- a/testcases/kernel/syscalls/prctl/Makefile +++ b/testcases/kernel/syscalls/prctl/Makefile @@ -21,5 +21,5 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk prctl07: LDLIBS += $(CAP_LIBS) - +prctl09: LDLIBS += -lrt include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/prctl/prctl09.c b/testcases/kernel/syscalls/prctl/prctl09.c new file mode 100644 index 000000000..e8d9aabd0 --- /dev/null +++ b/testcases/kernel/syscalls/prctl/prctl09.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com> + */ + +/* + * Test Description: + * This is a timer sampling tests that timer slack is 200us. + */ + +#include <errno.h> +#include <sys/prctl.h> +#include "lapi/prctl.h" +#include "tst_timer_test.h" + +int sample_fn(int clk_id, long long usec) +{ + struct timespec t = tst_us_to_timespec(usec); + + TEST(prctl(PR_SET_TIMERSLACK, 200000)); + if (TST_RET != 0) { + tst_res(TFAIL | TTERRNO, + "prctl(), returned %li", TST_RET); + return 1; + } + + tst_timer_start(clk_id); + TEST(nanosleep(&t, NULL)); + tst_timer_stop(); + tst_timer_sample(); + + if (TST_RET != 0) { + tst_res(TFAIL | TTERRNO, + "nanosleep() returned %li", TST_RET); + return 1; + } + + return 0; +} + +static struct tst_test test = { + .scall = "prctl()", + .sample = sample_fn, +};
Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com> --- runtest/syscalls | 1 + testcases/kernel/syscalls/prctl/.gitignore | 1 + testcases/kernel/syscalls/prctl/Makefile | 2 +- testcases/kernel/syscalls/prctl/prctl09.c | 45 ++++++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/prctl/prctl09.c