Skip to contentSkip to conversation

syscalls/prctl08: New test for prctl() with PR_{SET, GET}_TIMERSLACK

PATCH Superseded Yang Xu 2 participants 20 messages Oct 9, 2019 – Nov 25, 2019 Library code

lore
Share & tools
lore

Yang Xu

author
#0 lore raw

PATCH v3 1/1 syscalls/prctl08: New test for prctl() with PR_{SET, GET}_TIMERSLACK

-----
v2->v3:
1.add some check
2.compare time should not expire early before sleep
I want to take more samples, but .sample and .test have conflict and I
don't konw how to slove it.
-----

---
 include/lapi/prctl.h                       |   5 +
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/prctl/.gitignore |   1 +
 testcases/kernel/syscalls/prctl/Makefile   |   1 +
 testcases/kernel/syscalls/prctl/prctl08.c  | 129 +++++++++++++++++++++
 5 files changed, 137 insertions(+)
 create mode 100644 testcases/kernel/syscalls/prctl/prctl08.c
include/lapi/prctl.h +5 -0
index 8ee492259..0b4e196c3 100644
@@ -19,6 +19,11 @@
 # define PR_SET_SECCOMP  22
 #endif
 
+#ifndef PR_SET_TIMERSLACK
+# define PR_SET_TIMERSLACK 29
+# define PR_GET_TIMERSLACK 30
+#endif
+
 #ifndef PR_SET_CHILD_SUBREAPER
 # define PR_SET_CHILD_SUBREAPER	36
 # define PR_GET_CHILD_SUBREAPER	37
runtest/syscalls +1 -0
index 4e6310193..76961a684 100644
@@ -878,6 +878,7 @@ prctl04 prctl04
 prctl05 prctl05
 prctl06 prctl06
 prctl07 prctl07
+prctl08 prctl08
 
 pread01 pread01
 pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
index 2178db366..fe36a8e0f 100644
@@ -6,3 +6,4 @@
 /prctl06
 /prctl06_execve
 /prctl07
+/prctl08
testcases/kernel/syscalls/prctl/Makefile +1 -0
index cf19507c0..f0adc6fae 100644
@@ -21,5 +21,6 @@ top_srcdir		?= ../../../..
 include $(top_srcdir)/include/mk/testcases.mk
 
 prctl07: LDLIBS += $(CAP_LIBS)
+prctl08: LDLIBS += -lrt
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/prctl/prctl08.c new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
2.18.1
#1 lore raw

PATCH v3 1/1 syscalls/prctl08: New test for prctl() with PR_{SET, GET}_TIMERSLACK

Hi!

Quoted 6 lines

-----
v2->v3:
1.add some check
2.compare time should not expire early before sleep
I want to take more samples, but .sample and .test have conflict and I
don't konw how to slove it.

Well, you can't have a single test that implements both timer sampling tests and, at the same time, regular test function. You have to split these into two separate testcases. I guess that the best would be splitting the test into two, one that just sets arnd reads back the slack values and one that samples a timer.

Quoted 203 lines

-----

---
 include/lapi/prctl.h                       |   5 +
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/prctl/.gitignore |   1 +
 testcases/kernel/syscalls/prctl/Makefile   |   1 +
 testcases/kernel/syscalls/prctl/prctl08.c  | 129 +++++++++++++++++++++
 5 files changed, 137 insertions(+)
 create mode 100644 testcases/kernel/syscalls/prctl/prctl08.c
include/lapi/prctl.h +5 -0
index 8ee492259..0b4e196c3 100644
@@ -19,6 +19,11 @@
 # define PR_SET_SECCOMP  22
 #endif
 
+#ifndef PR_SET_TIMERSLACK
+# define PR_SET_TIMERSLACK 29
+# define PR_GET_TIMERSLACK 30
+#endif
+
 #ifndef PR_SET_CHILD_SUBREAPER
 # define PR_SET_CHILD_SUBREAPER	36
 # define PR_GET_CHILD_SUBREAPER	37
runtest/syscalls +1 -0
index 4e6310193..76961a684 100644
@@ -878,6 +878,7 @@ prctl04 prctl04
 prctl05 prctl05
 prctl06 prctl06
 prctl07 prctl07
+prctl08 prctl08
 
 pread01 pread01
 pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
index 2178db366..fe36a8e0f 100644
@@ -6,3 +6,4 @@
 /prctl06
 /prctl06_execve
 /prctl07
+/prctl08
testcases/kernel/syscalls/prctl/Makefile +1 -0
index cf19507c0..f0adc6fae 100644
@@ -21,5 +21,6 @@ top_srcdir		?= ../../../..
 include $(top_srcdir)/include/mk/testcases.mk
 
 prctl07: LDLIBS += $(CAP_LIBS)
+prctl08: LDLIBS += -lrt
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/prctl/prctl08.c new file +129 -0
new file mode 100644
index 000000000..d0384c95c
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * Test PR_GET_TIMERSLACK and PR_SET_TIMERSLACK of prctl(2).
+ * 1)Each thread has two associated timer slack values: a "default"
+ *   value, and a "current" value. PR_SET_TIMERSLACK sets the "current"
+ *   timer slack value for the calling thread.
+ * 2)When a new thread is created, the two timer slack values are made
+ *   the same as the "current" value of the creating thread.
+ * 3)The maximum timer slack value is ULONG_MAX. On 32bit machines, it
+ *   is a valid value(about 4s). On 64bit machines, it is about 500 years
+ *   and no person will set this over 4s.  prctl return value is int, so
+ *   we test themaximum value is INT_MAX.
+ * 4)we also check current value via /proc/self/timerslack_ns if it is
+ *  supported.
+ */
+
+#include <sys/prctl.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <linux/limits.h>
+#include "lapi/syscalls.h"
+#include "lapi/prctl.h"
+#include "tst_timer_test.h"
+#include "tst_test.h"
+
+#define PROC_NS_PATH "/proc/self/timerslack_ns"
+
+static struct tcase {
+	unsigned long setvalue;
+	unsigned long cmptime;
+} tcases[] = {
+	{1, 50000},
+	{70000, 50000},
+	{INT_MAX, 50000},
+};
+
+static int proc_flag = 1;
+
+static void check_proc_ns(char *message, unsigned long value)
+{
+	unsigned long proc_value;
+
+	SAFE_FILE_SCANF(PROC_NS_PATH, "%lu", &proc_value);
+	if (proc_value == value)
+		tst_res(TPASS, "%s %s  got %lu expectedly",
+				message, PROC_NS_PATH, proc_value);
+	else
+		tst_res(TFAIL, "%s %s expected %lu got %lu",
+				message, PROC_NS_PATH, value, proc_value);
+}
+
+static void check_get_timerslack(char *message, unsigned long value)
+{
+	TEST(prctl(PR_GET_TIMERSLACK));
+	if ((unsigned long)TST_RET == value)
+		tst_res(TPASS, "%s prctl(PR_GET_TIMERSLACK) got %lu expectedly",
+				message, value);
+	else
+		tst_res(TFAIL, "%s prctl(PR_GET_TIMERSLACK) expected %lu got %lu",
+				message, value, TST_RET);
+
+	if (proc_flag)
+		check_proc_ns(message, value);
+
+}
+
+static void verify_prctl(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int pid;
+
+	struct timespec timereq = { .tv_sec = 0, .tv_nsec = 50000 };
+	struct timespec timecmp = { .tv_sec = 0, .tv_nsec = tc->cmptime};
+
+	TEST(prctl(PR_SET_TIMERSLACK, tc->setvalue));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "prctl(PR_SET_TIMERSLACK, %lu) failed",
+					  tc->setvalue);
+		return;
+	}
+
+	tst_res(TPASS, "prctl(PR_SET_TIMERSLACK, %lu) succeed", tc->setvalue);
+	check_get_timerslack("Parent process", tc->setvalue);
+
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		/*check the current value of child process*/
+		check_get_timerslack("Child process", tc->setvalue);
+		prctl(PR_SET_TIMERSLACK, 0);
+		/*check the default value of child process*/
+		check_get_timerslack("After reset to 0, child process", tc->setvalue);
+		tst_timer_start(CLOCK_MONOTONIC);
+		TEST(nanosleep(&timereq, NULL));
+		tst_timer_stop();
+
+		if (tst_timespec_lt(tst_timer_elapsed(), timecmp))
+			tst_brk(TFAIL, "nanosleep() slept less than timecmp");
+
+		tst_res(TPASS, "nanosleep() slept more than timecmp, %llius",
+				tst_timer_elapsed_us());
+		exit(0);
+	}
+}
+
+static void setup(void)
+{
+	if (access(PROC_NS_PATH, F_OK) == -1) {
+		tst_res(TCONF, "proc doesn't support timerslack_ns interface");
+		proc_flag = 0;
+	}
+
+	TEST(prctl(PR_GET_TIMERSLACK));
+	if (TST_RET == 50000)
+		tst_res(TINFO, "current timerslack value is 50000");
+	else
+		tst_brk(TCONF,
+			"current environment doesn't meet test, please set timerslack to 50us");
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test = verify_prctl,
+	.tcnt = ARRAY_SIZE(tcases),
+	.forks_child = 1,
+};
Signature · 7 lines
2.18.1




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH v4 1/2 syscalls/prctl08: New test for prctl() with PR_{SET, GET}_TIMERSLACK

------
v3->v4:
split it into two cases, prctl08 test read/set timer slack value and prctl09 is a timer samle test.
Also, in prctl08, I split into 5 point(0,1,middle,max and inherit).
-----

---
 include/lapi/prctl.h                       |   5 +
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/prctl/.gitignore |   1 +
 testcases/kernel/syscalls/prctl/prctl08.c  | 135 +++++++++++++++++++++
 4 files changed, 142 insertions(+)
 create mode 100644 testcases/kernel/syscalls/prctl/prctl08.c
include/lapi/prctl.h +5 -0
index 8ee492259..0b4e196c3 100644
@@ -19,6 +19,11 @@
 # define PR_SET_SECCOMP  22
 #endif
 
+#ifndef PR_SET_TIMERSLACK
+# define PR_SET_TIMERSLACK 29
+# define PR_GET_TIMERSLACK 30
+#endif
+
 #ifndef PR_SET_CHILD_SUBREAPER
 # define PR_SET_CHILD_SUBREAPER	36
 # define PR_GET_CHILD_SUBREAPER	37
runtest/syscalls +1 -0
index 4e6310193..76961a684 100644
@@ -878,6 +878,7 @@ prctl04 prctl04
 prctl05 prctl05
 prctl06 prctl06
 prctl07 prctl07
+prctl08 prctl08
 
 pread01 pread01
 pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
index 2178db366..fe36a8e0f 100644
@@ -6,3 +6,4 @@
 /prctl06
 /prctl06_execve
 /prctl07
+/prctl08
testcases/kernel/syscalls/prctl/prctl08.c new file +135 -0

135 lines not on this page · raw message

Signature · 1 line
2.18.1
author
#3 lore raw

PATCH v4 1/2 syscalls/prctl08: New test for prctl() with PR_{SET, GET}_TIMERSLACK

Hi Cyril
Ping.

Quoted 195 lines

------
v3->v4:
split it into two cases, prctl08 test read/set timer slack value and prctl09 is a timer samle test.
Also, in prctl08, I split into 5 point(0,1,middle,max and inherit).
-----

---
  include/lapi/prctl.h                       |   5 +
  runtest/syscalls                           |   1 +
  testcases/kernel/syscalls/prctl/.gitignore |   1 +
  testcases/kernel/syscalls/prctl/prctl08.c  | 135 +++++++++++++++++++++
  4 files changed, 142 insertions(+)

create mode 100644 testcases/kernel/syscalls/prctl/prctl08.c

include/lapi/prctl.h +5 -0
index 8ee492259..0b4e196c3 100644
@@ -19,6 +19,11 @@
  # define PR_SET_SECCOMP  22
  #endif
 
+#ifndef PR_SET_TIMERSLACK
+# define PR_SET_TIMERSLACK 29
+# define PR_GET_TIMERSLACK 30
+#endif
+
  #ifndef PR_SET_CHILD_SUBREAPER
  # define PR_SET_CHILD_SUBREAPER	36
  # define PR_GET_CHILD_SUBREAPER	37
runtest/syscalls +1 -0
index 4e6310193..76961a684 100644
@@ -878,6 +878,7 @@ prctl04 prctl04
  prctl05 prctl05
  prctl06 prctl06
  prctl07 prctl07
+prctl08 prctl08
 
  pread01 pread01
  pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
index 2178db366..fe36a8e0f 100644
@@ -6,3 +6,4 @@
  /prctl06
  /prctl06_execve
  /prctl07
+/prctl08
testcases/kernel/syscalls/prctl/prctl08.c new file +135 -0
new file mode 100644
index 000000000..9aa15b06d
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * Test PR_GET_TIMERSLACK and PR_SET_TIMERSLACK of prctl(2).
+ * 1)Each thread has two associated timer slack values: a "default"
+ *   value, and a "current" value. PR_SET_TIMERSLACK sets the "current"
+ *   timer slack value for the calling thread.
+ * 2)When a new thread is created, the two timer slack values are made
+ *   the same as the "current" value of the creating thread.
+ * 3)The maximum timer slack value is ULONG_MAX. On 32bit machines, it
+ *   is a valid value(about 4s). On 64bit machines, it is about 500 years
+ *   and no person will set this over 4s.  prctl return value is int, so
+ *   we test themaximum value is INT_MAX.
+ * 4)we also check current value via /proc/self/timerslack_ns if it is
+ *  supported.
+ */
+
+#include <sys/prctl.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <linux/limits.h>
+#include "lapi/syscalls.h"
+#include "lapi/prctl.h"
+#include "tst_test.h"
+
+#define PROC_TIMERSLACK_PATH "/proc/self/timerslack_ns"
+
+static void check_get_timerslack(char *message, unsigned long value);
+static void check_inherit_timerslack(char *message, unsigned long value);
+
+static struct tcase {
+	void (*func_check)();
+	unsigned long setvalue;
+	unsigned long expvalue;
+	char message[50];
+} tcases[] = {
+	{check_get_timerslack, 0, 50000, "Reset"},
+	{check_get_timerslack, 1, 1, "Min"},
+	{check_get_timerslack, 70000, 70000, "Middle"},
+	{check_get_timerslack, INT_MAX, INT_MAX, "Max"},
+	{check_inherit_timerslack, 70000, 70000, "Child process"},
+};
+
+static int proc_flag = 1;
+
+static void check_proc_timerslack(char *message, unsigned long value)
+{
+	unsigned long proc_value;
+
+	SAFE_FILE_SCANF(PROC_TIMERSLACK_PATH, "%lu", &proc_value);
+	if (proc_value == value)
+		tst_res(TPASS, "%s %s  got %lu expectedly",
+				message, PROC_TIMERSLACK_PATH, proc_value);
+	else
+		tst_res(TFAIL, "%s %s expected %lu got %lu",
+				message, PROC_TIMERSLACK_PATH, value, proc_value);
+}
+
+static void check_get_timerslack(char *message, unsigned long value)
+{
+	TEST(prctl(PR_GET_TIMERSLACK));
+	if ((unsigned long)TST_RET == value)
+		tst_res(TPASS, "%s prctl(PR_GET_TIMERSLACK) got %lu expectedly",
+				message, value);
+	else
+		tst_res(TFAIL, "%s prctl(PR_GET_TIMERSLACK) expected %lu got %lu",
+				message, value, TST_RET);
+
+	if (proc_flag)
+		check_proc_timerslack(message, value);
+
+}
+
+static void check_inherit_timerslack(char *message, unsigned long value)
+{
+	int pid;
+	unsigned long current_value;
+	unsigned long default_value;
+
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		current_value = prctl(PR_GET_TIMERSLACK);
+		prctl(PR_SET_TIMERSLACK, 0);
+		default_value = prctl(PR_GET_TIMERSLACK);
+		if (current_value == value && default_value == value)
+			tst_res(TPASS,
+				"%s two timer slack values are made the same as the current value(%lu) of the creating thread.",
+				message, value);
+		else
+			tst_res(TFAIL,
+				"%s current_value is %lu, default value is %lu, the parent current value is %lu",
+				message, current_value, default_value, value);
+	}
+
+}
+
+static void verify_prctl(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	TEST(prctl(PR_SET_TIMERSLACK, tc->setvalue));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "prctl(PR_SET_TIMERSLACK, %lu) failed",
+					  tc->setvalue);
+		return;
+	}
+
+	tst_res(TPASS, "prctl(PR_SET_TIMERSLACK, %lu) succeed", tc->setvalue);
+	tc->func_check(tc->message, tc->expvalue);
+}
+
+static void setup(void)
+{
+	if (access(PROC_TIMERSLACK_PATH, F_OK) == -1) {
+		tst_res(TCONF, "proc doesn't support timerslack_ns interface");
+		proc_flag = 0;
+	}
+
+	TEST(prctl(PR_GET_TIMERSLACK));
+	if (TST_RET == 50000)
+		tst_res(TINFO, "current timerslack value is 50us");
+	else
+		tst_brk(TCONF,
+			"current environment doesn't meet test, please set timerslack to 50us");
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test = verify_prctl,
+	.tcnt = ARRAY_SIZE(tcases),
+	.forks_child = 1,
+};
author
#4 lore raw

PATCH v4 2/2 syscalls/prctl09: New timer sample test for PR_SET_TIMERSLACK

In reply to Yang Xu
---
 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
runtest/syscalls +1 -0
index 76961a684..705d7f87e 100644
@@ -879,6 +879,7 @@ prctl05 prctl05
 prctl06 prctl06
 prctl07 prctl07
 prctl08 prctl08
+prctl09 prctl09
 
 pread01 pread01
 pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
index fe36a8e0f..0f2c9b194 100644
@@ -7,3 +7,4 @@
 /prctl06_execve
 /prctl07
 /prctl08
+/prctl09
testcases/kernel/syscalls/prctl/Makefile +1 -1
index cf19507c0..c02b6d1de 100644
@@ -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
testcases/kernel/syscalls/prctl/prctl09.c new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.18.1
#5 lore raw

PATCH v4 2/2 syscalls/prctl09: New timer sample test for PR_SET_TIMERSLACK

Hi!

testcases/kernel/syscalls/prctl/prctl09.c line 21

Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl09.c new file +10 -0
+#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.

Quoted 29 lines
testcases/kernel/syscalls/prctl/prctl09.c new file +24 -0
+	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,
+};
Signature · 1 line
2.18.1
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#6 lore raw

PATCH v4 2/2 syscalls/prctl09: New timer sample test for PR_SET_TIMERSLACK

Quoted 13 lines · Cyril Hrubis

Hi!

testcases/kernel/syscalls/prctl/prctl09.c line 21

Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl09.c new file +10 -0
+#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.

Quoted 8 lines

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.

Quoted 22 lines
Quoted 22 lines
testcases/kernel/syscalls/prctl/prctl09.c new file +21 -0
+	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 = {
Quoted 8 lines
Quoted 8 lines
testcases/kernel/syscalls/prctl/prctl09.c new file +3 -0
+	.scall = "prctl()",
+	.sample = sample_fn,
+};
Signature · 1 line
2.18.1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191108/8c6cfde6/attachment.htm>

#7 lore raw

PATCH v4 1/2 syscalls/prctl08: New test for prctl() with PR_{SET, GET}_TIMERSLACK

In reply to Yang Xu

Hi!

Quoted 176 lines

------
v3->v4:
split it into two cases, prctl08 test read/set timer slack value and prctl09 is a timer samle test.
Also, in prctl08, I split into 5 point(0,1,middle,max and inherit).
-----

---
 include/lapi/prctl.h                       |   5 +
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/prctl/.gitignore |   1 +
 testcases/kernel/syscalls/prctl/prctl08.c  | 135 +++++++++++++++++++++
 4 files changed, 142 insertions(+)
 create mode 100644 testcases/kernel/syscalls/prctl/prctl08.c
include/lapi/prctl.h +5 -0
index 8ee492259..0b4e196c3 100644
@@ -19,6 +19,11 @@
 # define PR_SET_SECCOMP  22
 #endif
 
+#ifndef PR_SET_TIMERSLACK
+# define PR_SET_TIMERSLACK 29
+# define PR_GET_TIMERSLACK 30
+#endif
+
 #ifndef PR_SET_CHILD_SUBREAPER
 # define PR_SET_CHILD_SUBREAPER	36
 # define PR_GET_CHILD_SUBREAPER	37
runtest/syscalls +1 -0
index 4e6310193..76961a684 100644
@@ -878,6 +878,7 @@ prctl04 prctl04
 prctl05 prctl05
 prctl06 prctl06
 prctl07 prctl07
+prctl08 prctl08
 
 pread01 pread01
 pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
index 2178db366..fe36a8e0f 100644
@@ -6,3 +6,4 @@
 /prctl06
 /prctl06_execve
 /prctl07
+/prctl08
testcases/kernel/syscalls/prctl/prctl08.c new file +117 -0
new file mode 100644
index 000000000..9aa15b06d
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * Test PR_GET_TIMERSLACK and PR_SET_TIMERSLACK of prctl(2).
+ * 1)Each thread has two associated timer slack values: a "default"
+ *   value, and a "current" value. PR_SET_TIMERSLACK sets the "current"
+ *   timer slack value for the calling thread.
+ * 2)When a new thread is created, the two timer slack values are made
+ *   the same as the "current" value of the creating thread.
+ * 3)The maximum timer slack value is ULONG_MAX. On 32bit machines, it
+ *   is a valid value(about 4s). On 64bit machines, it is about 500 years
+ *   and no person will set this over 4s.  prctl return value is int, so
+ *   we test themaximum value is INT_MAX.
+ * 4)we also check current value via /proc/self/timerslack_ns if it is
+ *  supported.
+ */
+
+#include <sys/prctl.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <linux/limits.h>
+#include "lapi/syscalls.h"
+#include "lapi/prctl.h"
+#include "tst_test.h"
+
+#define PROC_TIMERSLACK_PATH "/proc/self/timerslack_ns"
+
+static void check_get_timerslack(char *message, unsigned long value);
+static void check_inherit_timerslack(char *message, unsigned long value);
+
+static struct tcase {
+	void (*func_check)();
+	unsigned long setvalue;
+	unsigned long expvalue;
+	char message[50];
+} tcases[] = {
+	{check_get_timerslack, 0, 50000, "Reset"},
+	{check_get_timerslack, 1, 1, "Min"},
+	{check_get_timerslack, 70000, 70000, "Middle"},
+	{check_get_timerslack, INT_MAX, INT_MAX, "Max"},
+	{check_inherit_timerslack, 70000, 70000, "Child process"},
+};
+
+static int proc_flag = 1;
+
+static void check_proc_timerslack(char *message, unsigned long value)
+{
+	unsigned long proc_value;
+
+	SAFE_FILE_SCANF(PROC_TIMERSLACK_PATH, "%lu", &proc_value);
+	if (proc_value == value)
+		tst_res(TPASS, "%s %s  got %lu expectedly",
+				message, PROC_TIMERSLACK_PATH, proc_value);
+	else
+		tst_res(TFAIL, "%s %s expected %lu got %lu",
+				message, PROC_TIMERSLACK_PATH, value, proc_value);
+}
+
+static void check_get_timerslack(char *message, unsigned long value)
+{
+	TEST(prctl(PR_GET_TIMERSLACK));
+	if ((unsigned long)TST_RET == value)
+		tst_res(TPASS, "%s prctl(PR_GET_TIMERSLACK) got %lu expectedly",
+				message, value);
+	else
+		tst_res(TFAIL, "%s prctl(PR_GET_TIMERSLACK) expected %lu got %lu",
+				message, value, TST_RET);
+
+	if (proc_flag)
+		check_proc_timerslack(message, value);
+
+}
+
+static void check_inherit_timerslack(char *message, unsigned long value)
+{
+	int pid;
+	unsigned long current_value;
+	unsigned long default_value;
+
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		current_value = prctl(PR_GET_TIMERSLACK);
+		prctl(PR_SET_TIMERSLACK, 0);
+		default_value = prctl(PR_GET_TIMERSLACK);
+		if (current_value == value && default_value == value)
+			tst_res(TPASS,
+				"%s two timer slack values are made the same as the current value(%lu) of the creating thread.",
+				message, value);
+		else
+			tst_res(TFAIL,
+				"%s current_value is %lu, default value is %lu, the parent current value is %lu",
+				message, current_value, default_value, value);
+	}
+
+}
+
+static void verify_prctl(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	TEST(prctl(PR_SET_TIMERSLACK, tc->setvalue));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "prctl(PR_SET_TIMERSLACK, %lu) failed",
+					  tc->setvalue);
+		return;
+	}
+
+	tst_res(TPASS, "prctl(PR_SET_TIMERSLACK, %lu) succeed", tc->setvalue);
+	tc->func_check(tc->message, tc->expvalue);
+}
+
+static void setup(void)
+{
+	if (access(PROC_TIMERSLACK_PATH, F_OK) == -1) {

testcases/kernel/syscalls/prctl/prctl08.c line 127

Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl08.c new file +10 -0
+		tst_res(TCONF, "proc doesn't support timerslack_ns interface");
+		proc_flag = 0;
+	}
+
+	TEST(prctl(PR_GET_TIMERSLACK));
+	if (TST_RET == 50000)
+		tst_res(TINFO, "current timerslack value is 50us");
+	else
+		tst_brk(TCONF,
+			"current environment doesn't meet test, please set timerslack to 50us");

Why can't we just store the result here into a global and use it later on in the reset case?

Given that we have check function already all we need to do is to add one more function that passes the global to the check_get_timerslack() instead of the expected value.

Quoted 13 lines
testcases/kernel/syscalls/prctl/prctl08.c new file +8 -0
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test = verify_prctl,
+	.tcnt = ARRAY_SIZE(tcases),
+	.forks_child = 1,
+};
Signature · 1 line
2.18.1
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#8 lore raw

PATCH v4 1/2 syscalls/prctl08: New test for prctl() with PR_{SET, GET}_TIMERSLACK

Quoted 190 lines · Cyril Hrubis

Hi!

Quoted 176 lines

------
v3->v4:
split it into two cases, prctl08 test read/set timer slack value and prctl09 is a timer samle test.
Also, in prctl08, I split into 5 point(0,1,middle,max and inherit).
-----

---
  include/lapi/prctl.h                       |   5 +
  runtest/syscalls                           |   1 +
  testcases/kernel/syscalls/prctl/.gitignore |   1 +
  testcases/kernel/syscalls/prctl/prctl08.c  | 135 +++++++++++++++++++++
  4 files changed, 142 insertions(+)

create mode 100644 testcases/kernel/syscalls/prctl/prctl08.c

include/lapi/prctl.h +5 -0
index 8ee492259..0b4e196c3 100644
@@ -19,6 +19,11 @@
  # define PR_SET_SECCOMP  22
  #endif
 
+#ifndef PR_SET_TIMERSLACK
+# define PR_SET_TIMERSLACK 29
+# define PR_GET_TIMERSLACK 30
+#endif
+
  #ifndef PR_SET_CHILD_SUBREAPER
  # define PR_SET_CHILD_SUBREAPER	36
  # define PR_GET_CHILD_SUBREAPER	37
runtest/syscalls +1 -0
index 4e6310193..76961a684 100644
@@ -878,6 +878,7 @@ prctl04 prctl04
  prctl05 prctl05
  prctl06 prctl06
  prctl07 prctl07
+prctl08 prctl08
 
  pread01 pread01
  pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
index 2178db366..fe36a8e0f 100644
@@ -6,3 +6,4 @@
  /prctl06
  /prctl06_execve
  /prctl07
+/prctl08
testcases/kernel/syscalls/prctl/prctl08.c new file +117 -0
new file mode 100644
index 000000000..9aa15b06d
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * Test PR_GET_TIMERSLACK and PR_SET_TIMERSLACK of prctl(2).
+ * 1)Each thread has two associated timer slack values: a "default"
+ *   value, and a "current" value. PR_SET_TIMERSLACK sets the "current"
+ *   timer slack value for the calling thread.
+ * 2)When a new thread is created, the two timer slack values are made
+ *   the same as the "current" value of the creating thread.
+ * 3)The maximum timer slack value is ULONG_MAX. On 32bit machines, it
+ *   is a valid value(about 4s). On 64bit machines, it is about 500 years
+ *   and no person will set this over 4s.  prctl return value is int, so
+ *   we test themaximum value is INT_MAX.
+ * 4)we also check current value via /proc/self/timerslack_ns if it is
+ *  supported.
+ */
+
+#include <sys/prctl.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <linux/limits.h>
+#include "lapi/syscalls.h"
+#include "lapi/prctl.h"
+#include "tst_test.h"
+
+#define PROC_TIMERSLACK_PATH "/proc/self/timerslack_ns"
+
+static void check_get_timerslack(char *message, unsigned long value);
+static void check_inherit_timerslack(char *message, unsigned long value);
+
+static struct tcase {
+	void (*func_check)();
+	unsigned long setvalue;
+	unsigned long expvalue;
+	char message[50];
+} tcases[] = {
+	{check_get_timerslack, 0, 50000, "Reset"},
+	{check_get_timerslack, 1, 1, "Min"},
+	{check_get_timerslack, 70000, 70000, "Middle"},
+	{check_get_timerslack, INT_MAX, INT_MAX, "Max"},
+	{check_inherit_timerslack, 70000, 70000, "Child process"},
+};
+
+static int proc_flag = 1;
+
+static void check_proc_timerslack(char *message, unsigned long value)
+{
+	unsigned long proc_value;
+
+	SAFE_FILE_SCANF(PROC_TIMERSLACK_PATH, "%lu", &proc_value);
+	if (proc_value == value)
+		tst_res(TPASS, "%s %s  got %lu expectedly",
+				message, PROC_TIMERSLACK_PATH, proc_value);
+	else
+		tst_res(TFAIL, "%s %s expected %lu got %lu",
+				message, PROC_TIMERSLACK_PATH, value, proc_value);
+}
+
+static void check_get_timerslack(char *message, unsigned long value)
+{
+	TEST(prctl(PR_GET_TIMERSLACK));
+	if ((unsigned long)TST_RET == value)
+		tst_res(TPASS, "%s prctl(PR_GET_TIMERSLACK) got %lu expectedly",
+				message, value);
+	else
+		tst_res(TFAIL, "%s prctl(PR_GET_TIMERSLACK) expected %lu got %lu",
+				message, value, TST_RET);
+
+	if (proc_flag)
+		check_proc_timerslack(message, value);
+
+}
+
+static void check_inherit_timerslack(char *message, unsigned long value)
+{
+	int pid;
+	unsigned long current_value;
+	unsigned long default_value;
+
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		current_value = prctl(PR_GET_TIMERSLACK);
+		prctl(PR_SET_TIMERSLACK, 0);
+		default_value = prctl(PR_GET_TIMERSLACK);
+		if (current_value == value && default_value == value)
+			tst_res(TPASS,
+				"%s two timer slack values are made the same as the current value(%lu) of the creating thread.",
+				message, value);
+		else
+			tst_res(TFAIL,
+				"%s current_value is %lu, default value is %lu, the parent current value is %lu",
+				message, current_value, default_value, value);
+	}
+
+}
+
+static void verify_prctl(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	TEST(prctl(PR_SET_TIMERSLACK, tc->setvalue));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "prctl(PR_SET_TIMERSLACK, %lu) failed",
+					  tc->setvalue);
+		return;
+	}
+
+	tst_res(TPASS, "prctl(PR_SET_TIMERSLACK, %lu) succeed", tc->setvalue);
+	tc->func_check(tc->message, tc->expvalue);
+}
+
+static void setup(void)
+{
+	if (access(PROC_TIMERSLACK_PATH, F_OK) == -1) {

testcases/kernel/syscalls/prctl/prctl08.c line 127

Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl08.c new file +10 -0
+		tst_res(TCONF, "proc doesn't support timerslack_ns interface");
+		proc_flag = 0;
+	}
+
+	TEST(prctl(PR_GET_TIMERSLACK));
+	if (TST_RET == 50000)
+		tst_res(TINFO, "current timerslack value is 50us");
+	else
+		tst_brk(TCONF,
+			"current environment doesn't meet test, please set timerslack to 50us");

Why can't we just store the result here into a global and use it later on in the reset case?

Quoted 3 lines

Given that we have check function already all we need to do is to add one more function that passes the global to the check_get_timerslack() instead of the expected value.

Hi Cyril

It sounds reasonable. We should not limit it in 50us. I will follow your advise.

Thanks
Yang Xu

Quoted 5 lines
Quoted 5 lines
testcases/kernel/syscalls/prctl/prctl08.c new file +5 -0
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test = verify_prctl,
Quoted 8 lines
Quoted 8 lines
testcases/kernel/syscalls/prctl/prctl08.c new file +3 -0
+	.tcnt = ARRAY_SIZE(tcases),
+	.forks_child = 1,
+};
Signature · 1 line
2.18.1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191108/ff1610fb/attachment.htm>

author
#9 lore raw

PATCH v5 1/2 syscalls/prctl08: New test for prctl() with PR_{SET, GET}_TIMERSLACK

In reply to Cyril Hrubis
---
 include/lapi/prctl.h                       |   5 +
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/prctl/.gitignore |   1 +
 testcases/kernel/syscalls/prctl/prctl08.c  | 139 +++++++++++++++++++++
 4 files changed, 146 insertions(+)
 create mode 100644 testcases/kernel/syscalls/prctl/prctl08.c
include/lapi/prctl.h +5 -0
index 8ee492259..0b4e196c3 100644
@@ -19,6 +19,11 @@
 # define PR_SET_SECCOMP  22
 #endif
 
+#ifndef PR_SET_TIMERSLACK
+# define PR_SET_TIMERSLACK 29
+# define PR_GET_TIMERSLACK 30
+#endif
+
 #ifndef PR_SET_CHILD_SUBREAPER
 # define PR_SET_CHILD_SUBREAPER	36
 # define PR_GET_CHILD_SUBREAPER	37
runtest/syscalls +1 -0
index 12d3e0d3b..fee91f909 100644
@@ -879,6 +879,7 @@ prctl04 prctl04
 prctl05 prctl05
 prctl06 prctl06
 prctl07 prctl07
+prctl08 prctl08
 
 pread01 pread01
 pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
index 2178db366..fe36a8e0f 100644
@@ -6,3 +6,4 @@
 /prctl06
 /prctl06_execve
 /prctl07
+/prctl08
testcases/kernel/syscalls/prctl/prctl08.c new file +139 -0

139 lines not on this page · raw message

Signature · 1 line
2.18.0
author
#10 lore raw

PATCH v5 1/2 syscalls/prctl08: New test for prctl() with PR_{SET, GET}_TIMERSLACK

Hi
Does anyone have some comments for this two patches?

Quoted 181 lines
---
  include/lapi/prctl.h                       |   5 +
  runtest/syscalls                           |   1 +
  testcases/kernel/syscalls/prctl/.gitignore |   1 +
  testcases/kernel/syscalls/prctl/prctl08.c  | 139 +++++++++++++++++++++
  4 files changed, 146 insertions(+)

create mode 100644 testcases/kernel/syscalls/prctl/prctl08.c

include/lapi/prctl.h +5 -0
index 8ee492259..0b4e196c3 100644
@@ -19,6 +19,11 @@
  # define PR_SET_SECCOMP  22
  #endif
 
+#ifndef PR_SET_TIMERSLACK
+# define PR_SET_TIMERSLACK 29
+# define PR_GET_TIMERSLACK 30
+#endif
+
  #ifndef PR_SET_CHILD_SUBREAPER
  # define PR_SET_CHILD_SUBREAPER	36
  # define PR_GET_CHILD_SUBREAPER	37
runtest/syscalls +1 -0
index 12d3e0d3b..fee91f909 100644
@@ -879,6 +879,7 @@ prctl04 prctl04
  prctl05 prctl05
  prctl06 prctl06
  prctl07 prctl07
+prctl08 prctl08
 
  pread01 pread01
  pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
index 2178db366..fe36a8e0f 100644
@@ -6,3 +6,4 @@
  /prctl06
  /prctl06_execve
  /prctl07
+/prctl08
testcases/kernel/syscalls/prctl/prctl08.c new file +129 -0
new file mode 100644
index 000000000..fd8ccb6ad
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * Test PR_GET_TIMERSLACK and PR_SET_TIMERSLACK of prctl(2).
+ * 1)Each thread has two associated timer slack values: a "default"
+ *   value, and a "current" value. PR_SET_TIMERSLACK sets the "current"
+ *   timer slack value for the calling thread.
+ * 2)When a new thread is created, the two timer slack values are made
+ *   the same as the "current" value of the creating thread.
+ * 3)The maximum timer slack value is ULONG_MAX. On 32bit machines, it
+ *   is a valid value(about 4s). On 64bit machines, it is about 500 years
+ *   and no person will set this over 4s.  prctl return value is int, so
+ *   we test themaximum value is INT_MAX.
+ * 4)we also check current value via /proc/self/timerslack_ns if it is
+ *  supported.
+ */
+
+#include <sys/prctl.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <linux/limits.h>
+#include "lapi/syscalls.h"
+#include "lapi/prctl.h"
+#include "tst_test.h"
+
+#define PROC_TIMERSLACK_PATH "/proc/self/timerslack_ns"
+
+static void check_reset_timerslack(char *message);
+static void check_get_timerslack(char *message, unsigned long value);
+static void check_inherit_timerslack(char *message, unsigned long value);
+static unsigned long origin_value;
+
+static struct tcase {
+	void (*func_check)();
+	unsigned long setvalue;
+	unsigned long expvalue;
+	char message[50];
+} tcases[] = {
+	{check_reset_timerslack, 0, 50000, "Reset"},
+	{check_get_timerslack, 1, 1, "Min"},
+	{check_get_timerslack, 70000, 70000, "Middle"},
+	{check_get_timerslack, INT_MAX, INT_MAX, "Max"},
+	{check_inherit_timerslack, 70000, 70000, "Child process"},
+};
+
+static int proc_flag = 1;
+
+static void check_reset_timerslack(char *message)
+{
+	check_get_timerslack(message, origin_value);
+}
+
+static void check_proc_timerslack(char *message, unsigned long value)
+{
+	unsigned long proc_value;
+
+	SAFE_FILE_SCANF(PROC_TIMERSLACK_PATH, "%lu", &proc_value);
+	if (proc_value == value)
+		tst_res(TPASS, "%s %s  got %lu expectedly",
+				message, PROC_TIMERSLACK_PATH, proc_value);
+	else
+		tst_res(TFAIL, "%s %s expected %lu got %lu",
+				message, PROC_TIMERSLACK_PATH, value, proc_value);
+}
+
+static void check_get_timerslack(char *message, unsigned long value)
+{
+	TEST(prctl(PR_GET_TIMERSLACK));
+	if ((unsigned long)TST_RET == value)
+		tst_res(TPASS, "%s prctl(PR_GET_TIMERSLACK) got %lu expectedly",
+				message, value);
+	else
+		tst_res(TFAIL, "%s prctl(PR_GET_TIMERSLACK) expected %lu got %lu",
+				message, value, TST_RET);
+
+	if (proc_flag)
+		check_proc_timerslack(message, value);
+
+}
+
+static void check_inherit_timerslack(char *message, unsigned long value)
+{
+	int pid;
+	unsigned long current_value;
+	unsigned long default_value;
+
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		current_value = prctl(PR_GET_TIMERSLACK);
+		prctl(PR_SET_TIMERSLACK, 0);
+		default_value = prctl(PR_GET_TIMERSLACK);
+		if (current_value == value && default_value == value)
+			tst_res(TPASS,
+				"%s two timer slack values are made the same as the current value(%lu) of the creating thread.",
+				message, value);
+		else
+			tst_res(TFAIL,
+				"%s current_value is %lu, default value is %lu, the parent current value is %lu",
+				message, current_value, default_value, value);
+	}
+
+}
+
+static void verify_prctl(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	TEST(prctl(PR_SET_TIMERSLACK, tc->setvalue));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "prctl(PR_SET_TIMERSLACK, %lu) failed",
+					  tc->setvalue);
+		return;
+	}
+
+	tst_res(TPASS, "prctl(PR_SET_TIMERSLACK, %lu) succeed", tc->setvalue);
+	tc->func_check(tc->message, tc->expvalue);
+}
+
+static void setup(void)
+{
+	if (access(PROC_TIMERSLACK_PATH, F_OK) == -1) {
+		tst_res(TCONF, "proc doesn't support timerslack_ns interface");
+		proc_flag = 0;
+	}
+
+	TEST(prctl(PR_GET_TIMERSLACK));

testcases/kernel/syscalls/prctl/prctl08.c line 139

Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl08.c new file +10 -0
+	origin_value = TST_RET;
+	tst_res(TINFO, "current timerslack value is %lu", origin_value);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test = verify_prctl,
+	.tcnt = ARRAY_SIZE(tcases),
+	.forks_child = 1,
+};

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191115/5b6e3ef4/attachment.htm>

author
#11 lore raw

PATCH v5 2/2 syscalls/prctl09: New timer sample test for PR_SET_TIMERSLACK

In reply to Yang Xu

It also moves test setup function before timer setup function, so we can get this set value.

---
 lib/tst_timer_test.c                       |  8 ++--
 runtest/syscalls                           |  1 +
 testcases/kernel/syscalls/prctl/.gitignore |  1 +
 testcases/kernel/syscalls/prctl/Makefile   |  2 +-
 testcases/kernel/syscalls/prctl/prctl09.c  | 47 ++++++++++++++++++++++
 5 files changed, 53 insertions(+), 6 deletions(-)
 create mode 100644 testcases/kernel/syscalls/prctl/prctl09.c
lib/tst_timer_test.c +3 -5
index f6459e5c0..13e9deff2 100644
@@ -340,6 +340,9 @@ static void timer_setup(void)
 	struct timespec t;
 	int ret;
 
+	if (setup)
+		setup();
+
 	tst_clock_getres(CLOCK_MONOTONIC, &t);
 
 	tst_res(TINFO, "CLOCK_MONOTONIC resolution %lins", (long)t.tv_nsec);
@@ -360,16 +363,11 @@ static void timer_setup(void)
 	tst_res(TINFO, "PR_GET_TIMERSLACK not defined, using %uus",
 		timerslack);
 #endif /* PR_GET_TIMERSLACK */
-
 	parse_timer_opts();
 
 	samples = SAFE_MALLOC(sizeof(long long) * MAX(MAX_SAMPLES, sample_cnt));
-
 	if (set_latency() < 0)
 		tst_res(TINFO, "Failed to set zero latency constraint: %m");
-
-	if (setup)
-		setup();
 }
 
 static void timer_cleanup(void)
runtest/syscalls +1 -0
index fee91f909..e4e162b23 100644
@@ -880,6 +880,7 @@ prctl05 prctl05
 prctl06 prctl06
 prctl07 prctl07
 prctl08 prctl08
+prctl09 prctl09
 
 pread01 pread01
 pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
index fe36a8e0f..0f2c9b194 100644
@@ -7,3 +7,4 @@
 /prctl06_execve
 /prctl07
 /prctl08
+/prctl09
testcases/kernel/syscalls/prctl/Makefile +1 -1
index cf19507c0..c02b6d1de 100644
@@ -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
testcases/kernel/syscalls/prctl/prctl09.c new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.18.0
#12 lore raw

PATCH v5 2/2 syscalls/prctl09: New timer sample test for PR_SET_TIMERSLACK

Hi!

Quoted 2 lines

It also moves test setup function before timer setup function, so we can get this set value.

Can we please change the library code in a separate patch with appropripate description of the change?

Otherwise it looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#13 lore raw

PATCH v5 2/2 syscalls/prctl09: New timer sample test for PR_SET_TIMERSLACK

Quoted 5 lines · Cyril Hrubis

Hi!

Quoted 2 lines

It also moves test setup function before timer setup function, so we can get this set value.

Can we please change the library code in a separate patch with appropripate description of the change?

Of course. I will put the library code change in a separate patch.

Quoted 3 lines

Otherwise it looks good.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191118/1549998d/attachment.htm>

author
#14 lore raw

PATCH v6 1/2 lib/tst_timer_test: move test setup function before PR_GET_TIMERSLACK

In reply to Cyril Hrubis

Move test setup function before PR_GET_TIMERSLACK in timer setup function so that the library includes the newly set timerslack in the calculation.

---
 lib/tst_timer_test.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
lib/tst_timer_test.c +3 -5
index f6459e5c0..13e9deff2 100644
@@ -340,6 +340,9 @@ static void timer_setup(void)
 	struct timespec t;
 	int ret;
 
+	if (setup)
+		setup();
+
 	tst_clock_getres(CLOCK_MONOTONIC, &t);
 
 	tst_res(TINFO, "CLOCK_MONOTONIC resolution %lins", (long)t.tv_nsec);
@@ -360,16 +363,11 @@ static void timer_setup(void)
 	tst_res(TINFO, "PR_GET_TIMERSLACK not defined, using %uus",
 		timerslack);
 #endif /* PR_GET_TIMERSLACK */
-
 	parse_timer_opts();
 
 	samples = SAFE_MALLOC(sizeof(long long) * MAX(MAX_SAMPLES, sample_cnt));
-
 	if (set_latency() < 0)
 		tst_res(TINFO, "Failed to set zero latency constraint: %m");
-
-	if (setup)
-		setup();
 }
 
 static void timer_cleanup(void)
Signature · 1 line
2.18.0
author
#15 lore raw

PATCH v6 1/2 lib/tst_timer_test: move test setup function before PR_GET_TIMERSLACK

Hi Cyril

?I think this patch can be merged if it is ok.

Thanks
Yang Xu

Quoted 30 lines

Move test setup function before PR_GET_TIMERSLACK in timer setup function so that the library includes the newly set timerslack in the calculation.

---
  lib/tst_timer_test.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)
lib/tst_timer_test.c +3 -1
index f6459e5c0..13e9deff2 100644
@@ -340,6 +340,9 @@ static void timer_setup(void)
  	struct timespec t;
  	int ret;
 
+	if (setup)
+		setup();
+
  	tst_clock_getres(CLOCK_MONOTONIC, &t);
 
  	tst_res(TINFO, "CLOCK_MONOTONIC resolution %lins", (long)t.tv_nsec);
@@ -360,16 +363,11 @@ static void timer_setup(void)
  	tst_res(TINFO, "PR_GET_TIMERSLACK not defined, using %uus",
  		timerslack);
  #endif /* PR_GET_TIMERSLACK */
-
  	parse_timer_opts();
 

lib/tst_timer_test.c static void timer_setup(void) · line 373

Quoted 10 lines
lib/tst_timer_test.c +0 -4
  	samples = SAFE_MALLOC(sizeof(long long) * MAX(MAX_SAMPLES, sample_cnt));
-
  	if (set_latency() < 0)
  		tst_res(TINFO, "Failed to set zero latency constraint: %m");
-
-	if (setup)
-		setup();
  }
 
  static void timer_cleanup(void)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191120/b98d0025/attachment.htm>

author
#16 lore raw

PATCH v6 1/2 lib/tst_timer_test: move test setup function before PR_GET_TIMERSLACK

Hi

ping.

Quoted 43 lines

Hi Cyril
?I think this patch can be merged if it is ok.
Thanks
Yang Xu

Quoted 39 lines

Move test setup function before PR_GET_TIMERSLACK in timer setup function so that the library includes the newly set timerslack in the calculation.

---
  lib/tst_timer_test.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)
lib/tst_timer_test.c +3 -5
index f6459e5c0..13e9deff2 100644
@@ -340,6 +340,9 @@ static void timer_setup(void)
  	struct timespec t;
  	int ret;
 
+	if (setup)
+		setup();
+
  	tst_clock_getres(CLOCK_MONOTONIC, &t);
 
  	tst_res(TINFO, "CLOCK_MONOTONIC resolution %lins", (long)t.tv_nsec);
@@ -360,16 +363,11 @@ static void timer_setup(void)
  	tst_res(TINFO, "PR_GET_TIMERSLACK not defined, using %uus",
  		timerslack);
  #endif /* PR_GET_TIMERSLACK */
-
  	parse_timer_opts();
 
  	samples = SAFE_MALLOC(sizeof(long long) * MAX(MAX_SAMPLES, sample_cnt));
-
  	if (set_latency() < 0)
  		tst_res(TINFO, "Failed to set zero latency constraint: %m");
-
-	if (setup)
-		setup();
  }
 
Quoted 2 lines

lib/tst_timer_test.c static void timer_setup(void) · line 373

Quoted 1 line
lib/tst_timer_test.c +0 -0
  static void timer_cleanup(void)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191125/2bb2fafe/attachment.htm>

author
#17 lore raw

PATCH v6 2/2 syscalls/prctl09: New timer sample test for PR_SET_TIMERSLACK

In reply to Yang Xu
---
 runtest/syscalls                           |  1 +
 testcases/kernel/syscalls/prctl/.gitignore |  1 +
 testcases/kernel/syscalls/prctl/Makefile   |  2 +-
 testcases/kernel/syscalls/prctl/prctl09.c  | 47 ++++++++++++++++++++++
 4 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/syscalls/prctl/prctl09.c
runtest/syscalls +1 -0
index fee91f909..e4e162b23 100644
@@ -880,6 +880,7 @@ prctl05 prctl05
 prctl06 prctl06
 prctl07 prctl07
 prctl08 prctl08
+prctl09 prctl09
 
 pread01 pread01
 pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
index fe36a8e0f..0f2c9b194 100644
@@ -7,3 +7,4 @@
 /prctl06_execve
 /prctl07
 /prctl08
+/prctl09
testcases/kernel/syscalls/prctl/Makefile +1 -1
index cf19507c0..c02b6d1de 100644
@@ -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
testcases/kernel/syscalls/prctl/prctl09.c new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.18.0
#18 lore raw

PATCH v6 2/2 syscalls/prctl09: New timer sample test for PR_SET_TIMERSLACK

Hi!
Both pushed, thanks.

Sorry for the delay.

Signature · 2 lines
Cyril Hrubis
[email protected]