<div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 28, 2018 at 10:38 PM, Jan Stancek <span dir="ltr"><<a href="mailto:jstancek@redhat.com" target="_blank">jstancek@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-"><br>
<br>
----- Original Message -----<br>
> Hello,<br>
> <br>
> Cyril Hrubis <<a href="mailto:chrubis@suse.cz">chrubis@suse.cz</a>> writes:<br>
> <br>
> > Hi!<br>
> > It's just an idea, but we can make this even more elegant API.<br>
> ><br>
> > We measure the time in the test library anyway, so what about we added<br>
> > something as tst_timeout_reached() that would return number of seconds<br>
> > remaining to 80% of the real timeout or 0 if in a case that the timeout<br>
> > was reached. Then we can use this as a soft-timeout in all the testcases<br>
> > without any additional steps.<br>
> ><br>
> > --<br>
> > Cyril Hrubis<br>
> > <a href="mailto:chrubis@suse.cz">chrubis@suse.cz</a><br>
> <br>
> 80% is probably way more than many of the CVE test cases need unless the<br>
> overall timeout is reduced from 5 minutes. Probably 20% would be<br>
> OK. Assuming this is the kind of usage scenario you had in mind.<br>
<br>
</span>I'd leave it to user. Give him data how much time is left,<br>
and let him decide what is sensible limit for soft-timeout.<br><br></blockquote><div><div class="gmail_default" style="font-size:small;display:inline"></div></div><div><div class="gmail_default" style="font-size:small;display:inline"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Hmm, I'm not sure if I have any misunderstood on Cyril's words. But from what I think, m</span><span style="text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">aybe 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.</span><br style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Here I draw the main idea base on Jan's V3 patch:</span></div> </div></div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_default"><span style="font-size:small"></span>diff --git a/include/tst_test.h b/include/tst_test.h</div><div class="gmail_default">index 98dacf3..7318c3e 100644</div><div class="gmail_default">--- a/include/tst_test.h</div><div class="gmail_default">+++ b/include/tst_test.h</div><div class="gmail_default">@@ -218,6 +218,7 @@ const char *tst_strsig(int sig);</div><div class="gmail_default"> const char *tst_strstatus(int status);</div><div class="gmail_default"> </div><div class="gmail_default"> void tst_set_timeout(int timeout);</div><div class="gmail_default">+unsigned int tst_timeout_reached(float ratio);</div><div class="gmail_default"> </div><div class="gmail_default"> #ifndef TST_NO_DEFAULT_MAIN</div><div class="gmail_default"> </div><div class="gmail_default">diff --git a/lib/tst_test.c b/lib/tst_test.c</div><div class="gmail_default">index 2f3d357..7864aa5 100644</div><div class="gmail_default">--- a/lib/tst_test.c</div><div class="gmail_default">+++ b/lib/tst_test.c</div><div class="gmail_default">@@ -47,6 +47,8 @@ static int iterations = 1;</div><div class="gmail_default"> static float duration = -1;</div><div class="gmail_default"> static pid_t main_pid, lib_pid;</div><div class="gmail_default"> static int mntpoint_mounted;</div><div class="gmail_default">+static clockid_t tst_clock;</div><div class="gmail_default">+static struct timespec tst_start_time;</div><div class="gmail_default"> </div><div class="gmail_default"> struct results {</div><div class="gmail_default"> <span style="white-space:pre"> </span>int passed;</div><div class="gmail_default">@@ -758,6 +760,7 @@ static void do_setup(int argc, char *argv[])</div><div class="gmail_default"> </div><div class="gmail_default"> <span style="white-space:pre"> </span>if (tst_test->sample)</div><div class="gmail_default"> <span style="white-space:pre"> </span>tst_test = tst_timer_test_setup(tst_test);</div><div class="gmail_default">+<span style="white-space:pre"> </span>tst_clock = tst_timer_find_clock();</div><div class="gmail_default"> </div><div class="gmail_default"> <span style="white-space:pre"> </span>parse_opts(argc, argv);</div><div class="gmail_default"> </div><div class="gmail_default">@@ -1012,6 +1015,8 @@ void tst_set_timeout(int timeout)</div><div class="gmail_default"> <span style="white-space:pre"> </span>results->timeout = results->timeout * m + 0.5;</div><div class="gmail_default"> <span style="white-space:pre"> </span>}</div><div class="gmail_default"> </div><div class="gmail_default">+<span style="white-space:pre"> </span>if (tst_clock_gettime(tst_clock, &tst_start_time))</div><div class="gmail_default">+<span style="white-space:pre"> </span>tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");</div><div class="gmail_default"> <span style="white-space:pre"> </span>tst_res(TINFO, "Timeout per run is %uh %02um %02us",</div><div class="gmail_default"> <span style="white-space:pre"> </span>results->timeout/3600, (results->timeout%3600)/60,</div><div class="gmail_default"> <span style="white-space:pre"> </span>results->timeout % 60);</div><div class="gmail_default">@@ -1022,6 +1027,24 @@ void tst_set_timeout(int timeout)</div><div class="gmail_default"> <span style="white-space:pre"> </span>heartbeat();</div><div class="gmail_default"> }</div><div class="gmail_default"> </div><div class="gmail_default">+unsigned int tst_timeout_reached(float ratio)</div><div class="gmail_default">+{</div><div class="gmail_default">+ static struct timespec now;</div><div class="gmail_default">+ unsigned int elapsed;</div><div class="gmail_default">+</div><div class="gmail_default">+ if (ratio >= 1 || ratio <= 0)</div><div class="gmail_default">+ tst_brk(TBROK, "ratio should be: 0 < ratio < 1");</div><div class="gmail_default">+</div><div class="gmail_default">+ if (tst_clock_gettime(tst_clock, &now))</div><div class="gmail_default">+ tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");</div><div class="gmail_default">+</div><div class="gmail_default">+ elapsed = tst_timespec_diff_ms(now, tst_start_time) / 1000;</div><div class="gmail_default">+ if (elapsed >= (results->timeout * ratio))</div><div class="gmail_default">+ return 1;</div><div class="gmail_default">+</div><div class="gmail_default">+ return 0;</div><div class="gmail_default">+}</div><div class="gmail_default">+</div><div class="gmail_default"> static int fork_testrun(void)</div><div class="gmail_default"> {</div><div class="gmail_default"> <span style="white-space:pre"> </span>int status;</div><div class="gmail_default">diff --git a/testcases/kernel/syscalls/move_pages/move_pages12.c b/testcases/kernel/syscalls/move_pages/move_pages12.c</div><div class="gmail_default">index 43acb42..0dc94ee 100644</div><div class="gmail_default">--- a/testcases/kernel/syscalls/move_pages/move_pages12.c</div><div class="gmail_default">+++ b/testcases/kernel/syscalls/move_pages/move_pages12.c</div><div class="gmail_default">@@ -123,14 +123,15 @@ static void do_test(void)</div><div class="gmail_default"> <span style="white-space:pre"> </span>memset(addr, 0, TEST_PAGES * hpsz);</div><div class="gmail_default"> </div><div class="gmail_default"> <span style="white-space:pre"> </span>SAFE_MUNMAP(addr, TEST_PAGES * hpsz);</div><div class="gmail_default">-<span style="white-space:pre"> </span>}</div><div class="gmail_default"> </div><div class="gmail_default">-<span style="white-space:pre"> </span>if (i == LOOPS) {</div><div class="gmail_default">-<span style="white-space:pre"> </span>SAFE_KILL(cpid, SIGKILL);</div><div class="gmail_default">-<span style="white-space:pre"> </span>SAFE_WAITPID(cpid, &status, 0);</div><div class="gmail_default">-<span style="white-space:pre"> </span>if (!WIFEXITED(status))</div><div class="gmail_default">-<span style="white-space:pre"> </span>tst_res(TPASS, "Bug not reproduced");</div><div class="gmail_default">+<span style="white-space:pre"> </span>if(tst_timeout_reached(0.8))</div><div class="gmail_default">+<span style="white-space:pre"> </span>break;</div><div class="gmail_default"> <span style="white-space:pre"> </span>}</div><div class="gmail_default">+</div><div class="gmail_default">+<span style="white-space:pre"> </span>SAFE_KILL(cpid, SIGKILL);</div><div class="gmail_default">+<span style="white-space:pre"> </span>SAFE_WAITPID(cpid, &status, 0);</div><div class="gmail_default">+<span style="white-space:pre"> </span>if (!WIFEXITED(status))</div><div class="gmail_default">+<span style="white-space:pre"> </span>tst_res(TPASS, "Bug not reproduced");</div><div class="gmail_default"> }</div></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Regards,<br>Li Wang<br></div></div></div></div>
</div></div>