[LTP] [PATCH] open_posix/conformance/clock/1.1: check PASS condition periodically
Jan Stancek
jstancek@redhat.com
Mon Oct 18 11:17:24 CEST 2021
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(-)
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;
}
--
2.27.0
More information about the ltp
mailing list