All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 1/2] lib: add tst_get_timeout()
@ 2018-08-28 11:07 Jan Stancek
  2018-08-28 11:07 ` [LTP] [PATCH v2 2/2] move_pages12: end early if runtime gets close to test time Jan Stancek
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jan Stancek @ 2018-08-28 11:07 UTC (permalink / raw)
  To: ltp

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 include/tst_test.h | 1 +
 lib/tst_test.c     | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/include/tst_test.h b/include/tst_test.h
index 98dacf3873ab..f801d276d2e5 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -217,6 +217,7 @@ const char *tst_strsig(int sig);
  */
 const char *tst_strstatus(int status);
 
+unsigned int tst_get_timeout(void);
 void tst_set_timeout(int timeout);
 
 #ifndef TST_NO_DEFAULT_MAIN
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 2f3d357d2fcc..7bd18205ae7f 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -992,6 +992,11 @@ static void sigint_handler(int sig LTP_ATTRIBUTE_UNUSED)
 	}
 }
 
+unsigned int tst_get_timeout(void)
+{
+	return results->timeout;
+}
+
 void tst_set_timeout(int timeout)
 {
 	char *mul = getenv("LTP_TIMEOUT_MUL");
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v2 2/2] move_pages12: end early if runtime gets close to test time
  2018-08-28 11:07 [LTP] [PATCH v2 1/2] lib: add tst_get_timeout() Jan Stancek
@ 2018-08-28 11:07 ` Jan Stancek
  2018-08-28 12:34 ` [LTP] [PATCH v2 1/2] lib: add tst_get_timeout() Li Wang
  2018-08-28 12:58 ` Cyril Hrubis
  2 siblings, 0 replies; 8+ messages in thread
From: Jan Stancek @ 2018-08-28 11:07 UTC (permalink / raw)
  To: ltp

Most systems can complete this reproducer in standard test time.
Small groups of systems (e.g. aarch64 with 512M hugepages) can hit
a timeout.

Add a check for elapsed time and end test early if we are getting close (80%).

Fixes: #387

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 testcases/kernel/syscalls/move_pages/move_pages12.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/testcases/kernel/syscalls/move_pages/move_pages12.c b/testcases/kernel/syscalls/move_pages/move_pages12.c
index 43acb42aabb1..284be957148f 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages12.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages12.c
@@ -40,6 +40,7 @@
 #include <sys/wait.h>
 
 #include "tst_test.h"
+#include "tst_timer.h"
 #include "move_pages_support.h"
 #include "lapi/mmap.h"
 
@@ -101,6 +102,9 @@ static void do_test(void)
 	int i;
 	pid_t cpid = -1;
 	int status;
+	unsigned int test_time = (tst_get_timeout() / 5) * 4;
+
+	tst_timer_start(CLOCK_MONOTONIC);
 
 	addr = SAFE_MMAP(NULL, TEST_PAGES * hpsz, PROT_READ | PROT_WRITE,
 		MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
@@ -123,14 +127,15 @@ static void do_test(void)
 		memset(addr, 0, TEST_PAGES * hpsz);
 
 		SAFE_MUNMAP(addr, TEST_PAGES * hpsz);
-	}
 
-	if (i == LOOPS) {
-		SAFE_KILL(cpid, SIGKILL);
-		SAFE_WAITPID(cpid, &status, 0);
-		if (!WIFEXITED(status))
-			tst_res(TPASS, "Bug not reproduced");
+		if (tst_timer_expired_ms(test_time))
+			break;
 	}
+
+	SAFE_KILL(cpid, SIGKILL);
+	SAFE_WAITPID(cpid, &status, 0);
+	if (!WIFEXITED(status))
+		tst_res(TPASS, "Bug not reproduced");
 }
 
 static void alloc_free_huge_on_node(unsigned int node, size_t size)
@@ -183,6 +188,8 @@ static void setup(void)
 	int ret;
 	long memfree;
 
+	tst_timer_check(CLOCK_MONOTONIC);
+
 	check_config(TEST_NODES);
 
 	if (access(PATH_HUGEPAGES, F_OK))
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v2 1/2] lib: add tst_get_timeout()
  2018-08-28 11:07 [LTP] [PATCH v2 1/2] lib: add tst_get_timeout() Jan Stancek
  2018-08-28 11:07 ` [LTP] [PATCH v2 2/2] move_pages12: end early if runtime gets close to test time Jan Stancek
@ 2018-08-28 12:34 ` Li Wang
  2018-08-28 12:58 ` Cyril Hrubis
  2 siblings, 0 replies; 8+ messages in thread
From: Li Wang @ 2018-08-28 12:34 UTC (permalink / raw)
  To: ltp

On Tue, Aug 28, 2018 at 7:07 PM, Jan Stancek <jstancek@redhat.com> wrote:

> Signed-off-by: Jan Stancek <jstancek@redhat.com>
>
...
> +{
> +       return results->timeout;
> +}
>

Patch set looks good to me.

At the beginning, I thought to use tst_timeout_mul() function which will be
introduced by Richard's new 1/5 patch 'lib: Allow user to easily get
LTP_TIMEOUT_MUL value". But after looking at this tst_get_timeout(), it
seems more useful to ltp testcase in future. So I stand by this method.

And, test get pass on kernel 4.19.0-rc1+ x86_64.


-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20180828/3e86d0e8/attachment.html>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v2 1/2] lib: add tst_get_timeout()
  2018-08-28 11:07 [LTP] [PATCH v2 1/2] lib: add tst_get_timeout() Jan Stancek
  2018-08-28 11:07 ` [LTP] [PATCH v2 2/2] move_pages12: end early if runtime gets close to test time Jan Stancek
  2018-08-28 12:34 ` [LTP] [PATCH v2 1/2] lib: add tst_get_timeout() Li Wang
@ 2018-08-28 12:58 ` Cyril Hrubis
  2018-08-28 14:20   ` Richard Palethorpe
  2 siblings, 1 reply; 8+ messages in thread
From: Cyril Hrubis @ 2018-08-28 12:58 UTC (permalink / raw)
  To: ltp

Hi!
It's just an idea, but we can make this even more elegant API.

We measure the time in the test library anyway, so what about we added
something as tst_timeout_reached() that would return number of seconds
remaining to 80% of the real timeout or 0 if in a case that the timeout
was reached. Then we can use this as a soft-timeout in all the testcases
without any additional steps.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v2 1/2] lib: add tst_get_timeout()
  2018-08-28 12:58 ` Cyril Hrubis
@ 2018-08-28 14:20   ` Richard Palethorpe
  2018-08-28 14:38     ` Jan Stancek
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Palethorpe @ 2018-08-28 14:20 UTC (permalink / raw)
  To: ltp

Hello,

Cyril Hrubis <chrubis@suse.cz> writes:

> Hi!
> It's just an idea, but we can make this even more elegant API.
>
> We measure the time in the test library anyway, so what about we added
> something as tst_timeout_reached() that would return number of seconds
> remaining to 80% of the real timeout or 0 if in a case that the timeout
> was reached. Then we can use this as a soft-timeout in all the testcases
> without any additional steps.
>
> --
> Cyril Hrubis
> chrubis@suse.cz

80% is probably way more than many of the CVE test cases need unless the
overall timeout is reduced from 5 minutes. Probably 20% would be
OK. Assuming this is the kind of usage scenario you had in mind.

We could also call it tst_timeout_approaching, tst_timeout_near or
tst_time_to_fail... not sure if they are any better.

--
Thank you,
Richard.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v2 1/2] lib: add tst_get_timeout()
  2018-08-28 14:20   ` Richard Palethorpe
@ 2018-08-28 14:38     ` Jan Stancek
  2018-08-29  4:52       ` Li Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Stancek @ 2018-08-28 14:38 UTC (permalink / raw)
  To: ltp



----- Original Message -----
> Hello,
> 
> Cyril Hrubis <chrubis@suse.cz> writes:
> 
> > Hi!
> > It's just an idea, but we can make this even more elegant API.
> >
> > We measure the time in the test library anyway, so what about we added
> > something as tst_timeout_reached() that would return number of seconds
> > remaining to 80% of the real timeout or 0 if in a case that the timeout
> > was reached. Then we can use this as a soft-timeout in all the testcases
> > without any additional steps.
> >
> > --
> > Cyril Hrubis
> > chrubis@suse.cz
> 
> 80% is probably way more than many of the CVE test cases need unless the
> overall timeout is reduced from 5 minutes. Probably 20% would be
> OK. Assuming this is the kind of usage scenario you had in mind.

I'd leave it to user. Give him data how much time is left,
and let him decide what is sensible limit for soft-timeout.

I'll send example in v3 series shortly.

> 
> We could also call it tst_timeout_approaching, tst_timeout_near or
> tst_time_to_fail... not sure if they are any better.
> 
> --
> Thank you,
> Richard.
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v2 1/2] lib: add tst_get_timeout()
  2018-08-28 14:38     ` Jan Stancek
@ 2018-08-29  4:52       ` Li Wang
  2018-08-29  7:18         ` Jan Stancek
  0 siblings, 1 reply; 8+ messages in thread
From: Li Wang @ 2018-08-29  4:52 UTC (permalink / raw)
  To: ltp

On Tue, Aug 28, 2018 at 10:38 PM, Jan Stancek <jstancek@redhat.com> wrote:

>
>
> ----- Original Message -----
> > Hello,
> >
> > Cyril Hrubis <chrubis@suse.cz> writes:
> >
> > > Hi!
> > > It's just an idea, but we can make this even more elegant API.
> > >
> > > We measure the time in the test library anyway, so what about we added
> > > something as tst_timeout_reached() that would return number of seconds
> > > remaining to 80% of the real timeout or 0 if in a case that the timeout
> > > was reached. Then we can use this as a soft-timeout in all the
> testcases
> > > without any additional steps.
> > >
> > > --
> > > Cyril Hrubis
> > > chrubis@suse.cz
> >
> > 80% is probably way more than many of the CVE test cases need unless the
> > overall timeout is reduced from 5 minutes. Probably 20% would be
> > OK. Assuming this is the kind of usage scenario you had in mind.
>
> I'd leave it to user. Give him data how much time is left,
> and let him decide what is sensible limit for soft-timeout.
>
> Hmm, I'm not sure if I have any misunderstood on Cyril's words. But from
what I think, maybe we also could give more flexible to customize the
soft-timeout as tst_timeout_reached(0.8) to return true when testcase
reached 80% of the real timeout. This makes thing more easier and can
satisfy some kind of demanded.

Here I draw the main idea base on Jan's V3 patch:


diff --git a/include/tst_test.h b/include/tst_test.h
index 98dacf3..7318c3e 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -218,6 +218,7 @@ const char *tst_strsig(int sig);
 const char *tst_strstatus(int status);

 void tst_set_timeout(int timeout);
+unsigned int tst_timeout_reached(float ratio);

 #ifndef TST_NO_DEFAULT_MAIN

diff --git a/lib/tst_test.c b/lib/tst_test.c
index 2f3d357..7864aa5 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -47,6 +47,8 @@ static int iterations = 1;
 static float duration = -1;
 static pid_t main_pid, lib_pid;
 static int mntpoint_mounted;
+static clockid_t tst_clock;
+static struct timespec tst_start_time;

 struct results {
  int passed;
@@ -758,6 +760,7 @@ static void do_setup(int argc, char *argv[])

  if (tst_test->sample)
  tst_test = tst_timer_test_setup(tst_test);
+ tst_clock = tst_timer_find_clock();

  parse_opts(argc, argv);

@@ -1012,6 +1015,8 @@ void tst_set_timeout(int timeout)
  results->timeout = results->timeout * m + 0.5;
  }

+ if (tst_clock_gettime(tst_clock, &tst_start_time))
+ tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
  tst_res(TINFO, "Timeout per run is %uh %02um %02us",
  results->timeout/3600, (results->timeout%3600)/60,
  results->timeout % 60);
@@ -1022,6 +1027,24 @@ void tst_set_timeout(int timeout)
  heartbeat();
 }

+unsigned int tst_timeout_reached(float ratio)
+{
+       static struct timespec now;
+       unsigned int elapsed;
+
+       if (ratio >= 1 || ratio <= 0)
+               tst_brk(TBROK, "ratio should be: 0 < ratio < 1");
+
+       if (tst_clock_gettime(tst_clock, &now))
+               tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
+
+       elapsed = tst_timespec_diff_ms(now, tst_start_time) / 1000;
+       if (elapsed >= (results->timeout * ratio))
+               return 1;
+
+       return 0;
+}
+
 static int fork_testrun(void)
 {
  int status;
diff --git a/testcases/kernel/syscalls/move_pages/move_pages12.c
b/testcases/kernel/syscalls/move_pages/move_pages12.c
index 43acb42..0dc94ee 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages12.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages12.c
@@ -123,14 +123,15 @@ static void do_test(void)
  memset(addr, 0, TEST_PAGES * hpsz);

  SAFE_MUNMAP(addr, TEST_PAGES * hpsz);
- }

- if (i == LOOPS) {
- SAFE_KILL(cpid, SIGKILL);
- SAFE_WAITPID(cpid, &status, 0);
- if (!WIFEXITED(status))
- tst_res(TPASS, "Bug not reproduced");
+ if(tst_timeout_reached(0.8))
+ break;
  }
+
+ SAFE_KILL(cpid, SIGKILL);
+ SAFE_WAITPID(cpid, &status, 0);
+ if (!WIFEXITED(status))
+ tst_res(TPASS, "Bug not reproduced");
 }

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20180829/abed3a77/attachment-0001.html>

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v2 1/2] lib: add tst_get_timeout()
  2018-08-29  4:52       ` Li Wang
@ 2018-08-29  7:18         ` Jan Stancek
  0 siblings, 0 replies; 8+ messages in thread
From: Jan Stancek @ 2018-08-29  7:18 UTC (permalink / raw)
  To: ltp



----- Original Message -----
> On Tue, Aug 28, 2018 at 10:38 PM, Jan Stancek <jstancek@redhat.com> wrote:
> 
> >
> >
> > ----- Original Message -----
> > > Hello,
> > >
> > > Cyril Hrubis <chrubis@suse.cz> writes:
> > >
> > > > Hi!
> > > > It's just an idea, but we can make this even more elegant API.
> > > >
> > > > We measure the time in the test library anyway, so what about we added
> > > > something as tst_timeout_reached() that would return number of seconds
> > > > remaining to 80% of the real timeout or 0 if in a case that the timeout
> > > > was reached. Then we can use this as a soft-timeout in all the
> > testcases
> > > > without any additional steps.
> > > >
> > > > --
> > > > Cyril Hrubis
> > > > chrubis@suse.cz
> > >
> > > 80% is probably way more than many of the CVE test cases need unless the
> > > overall timeout is reduced from 5 minutes. Probably 20% would be
> > > OK. Assuming this is the kind of usage scenario you had in mind.
> >
> > I'd leave it to user. Give him data how much time is left,
> > and let him decide what is sensible limit for soft-timeout.
> >
> > Hmm, I'm not sure if I have any misunderstood on Cyril's words. But from
> what I think, maybe we also could give more flexible to customize the
> soft-timeout as tst_timeout_reached(0.8) to return true when testcase
> reached 80% of the real timeout. This makes thing more easier and can
> satisfy some kind of demanded.

Sure, but then we are always working with ratios, and can't do something like
"15 seconds before timeout do X". 


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-08-29  7:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-28 11:07 [LTP] [PATCH v2 1/2] lib: add tst_get_timeout() Jan Stancek
2018-08-28 11:07 ` [LTP] [PATCH v2 2/2] move_pages12: end early if runtime gets close to test time Jan Stancek
2018-08-28 12:34 ` [LTP] [PATCH v2 1/2] lib: add tst_get_timeout() Li Wang
2018-08-28 12:58 ` Cyril Hrubis
2018-08-28 14:20   ` Richard Palethorpe
2018-08-28 14:38     ` Jan Stancek
2018-08-29  4:52       ` Li Wang
2018-08-29  7:18         ` Jan Stancek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.