diff mbox series

open_posix/conformance/clock/1.1: check PASS condition periodically

Message ID ddffbf17d3b5fd2d7812a18435d5cc49b848de8d.1634548566.git.jstancek@redhat.com
State Accepted, archived
Headers show
Series open_posix/conformance/clock/1.1: check PASS condition periodically | expand

Commit Message

Jan Stancek Oct. 18, 2021, 9:17 a.m. UTC
LTP commit 61312c62a392 ("open_posix/conformance/clock/1.1:
Deterministic timing") changed test to busy loop for 5 seconds.
This made the test sometimes fail in environments with high steal
time.

Move PASS condition inside loop, so in ideal case test can finish
as soon as it has spent >1 sec of CPU time. Also drop the wrap-around
check, since that takes order of minutes to happen.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 .../conformance/interfaces/clock/1-1.c        | 49 +++++++------------
 1 file changed, 18 insertions(+), 31 deletions(-)

Comments

Li Wang Oct. 19, 2021, 9:11 a.m. UTC | #1
On Mon, Oct 18, 2021 at 5:18 PM Jan Stancek <jstancek@redhat.com> wrote:

> LTP commit 61312c62a392 ("open_posix/conformance/clock/1.1:
> Deterministic timing") changed test to busy loop for 5 seconds.
> This made the test sometimes fail in environments with high steal
> time.
>
> Move PASS condition inside loop, so in ideal case test can finish
> as soon as it has spent >1 sec of CPU time. Also drop the wrap-around
> check, since that takes order of minutes to happen.
>

Looks like more reliable than that 5sec busy loop, let's see how it
performs then.


>
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
>

Reviewed-by: Li Wang <liwang@redhat.com>
Cyril Hrubis Oct. 25, 2021, 9:09 a.m. UTC | #2
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Jan Stancek Oct. 25, 2021, 9:29 a.m. UTC | #3
On Mon, Oct 25, 2021 at 11:09 AM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

Thanks, pushed.
diff mbox series

Patch

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c
index 384be0648f0b..e255720df6b1 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c
@@ -20,45 +20,32 @@ 
 #include <time.h>
 #include "posixtest.h"
 
-#define BUSY_LOOP_SECONDS 5
+#define MAX_RUNTIME_SECONDS 15
 
 int main(void)
 {
 	clock_t c1, c2;
 	double sec1, sec2;
-	time_t end;
+	time_t end = time(NULL) + MAX_RUNTIME_SECONDS;
 
 	c1 = clock();
-	sec1 = c1 / CLOCKS_PER_SEC;
-
-	end = time(NULL) + BUSY_LOOP_SECONDS;
-
-	while (end >= time(NULL)) {
-		clock();
+	if (c1 == (clock_t)-1) {
+		printf("processor time not available\n");
+		return PTS_UNRESOLVED;
 	}
-
-	c2 = clock();
-	sec2 = c2 / CLOCKS_PER_SEC;
-
-	if (sec2 > sec1) {
-		printf("Times T1=%.2f, T2=%.2f\n", sec1, sec2);
-		printf("Test PASSED\n");
-		return PTS_PASS;
-	} else {
-		if (sec2 < sec1) {
-			/*
-			 * probably wrapping happened; however, since
-			 * we do not know the wrap value, results are
-			 * undefined
-			 */
-			printf("TEST AGAIN:  Times probably wrapped\n");
-			return PTS_UNRESOLVED;
-		} else {
-			printf("Error with processor times T1=%.2f, T2=%.2f\n",
-			       sec1, sec2);
-			return PTS_FAIL;
+	sec1 = (double) c1 / CLOCKS_PER_SEC;
+
+	do {
+		c2 = clock();
+		sec2 = (double) c2 / CLOCKS_PER_SEC;
+		if (sec2 - sec1 > 1) {
+			printf("Times T1=%.2lf, T2=%.2lf\n", sec1, sec2);
+			printf("Test PASSED\n");
+			return PTS_PASS;
 		}
-	}
+	} while (end >= time(NULL));
 
-	return PTS_UNRESOLVED;
+	printf("Error with processor times T1=%.2lf, T2=%.2lf\n",
+	       sec1, sec2);
+	return PTS_FAIL;
 }