@@ -42,6 +42,7 @@
#include <time.h>
#include <math.h>
#include "tst_atomic.h"
+#include "tst_timer.h"
#ifndef CLOCK_MONOTONIC_RAW
# define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
@@ -280,6 +281,17 @@ static inline int tst_fzsync_wait_b(struct tst_fzsync_pair *pair)
return tst_fzsync_pair_wait(pair, &pair->b_cntr, &pair->a_cntr);
}
+/**
+ * tst_fzsync_pair_exit - Signal that the other thread should exit
+ *
+ * Causes tst_fzsync_pair_wait() and tst_fzsync_pair_wait_update() to return
+ * 0.
+ */
+static inline void tst_fzsync_pair_exit(struct tst_fzsync_pair *pair)
+{
+ tst_atomic_store(1, &pair->exit);
+}
+
/**
* tst_fzsync_pair_wait_update_{a,b} - Wait and then recalculate
*
@@ -301,10 +313,26 @@ static inline int tst_fzsync_wait_b(struct tst_fzsync_pair *pair)
static inline int tst_fzsync_wait_update_a(struct tst_fzsync_pair *pair)
{
static int loop_index;
+ int timer_state = tst_timer_state_ms(60000);
+ int exit = 0;
+
+ if (!(timer_state & TST_TIMER_STARTED)) {
+ tst_timer_start(CLOCK_MONOTONIC_RAW);
+ } else if (timer_state & TST_TIMER_EXPIRED) {
+ tst_res(TINFO,
+ "Exceeded fuzzy sync time limit, requesting exit");
+ exit = 1;
+ }
tst_fzsync_pair_wait(pair, &pair->a_cntr, &pair->b_cntr);
- loop_index++;
- tst_fzsync_pair_update(loop_index, pair);
+
+ if (exit) {
+ tst_fzsync_pair_exit(pair);
+ } else {
+ loop_index++;
+ tst_fzsync_pair_update(loop_index, pair);
+ }
+
return tst_fzsync_pair_wait(pair, &pair->a_cntr, &pair->b_cntr);
}
@@ -313,14 +341,3 @@ static inline int tst_fzsync_wait_update_b(struct tst_fzsync_pair *pair)
tst_fzsync_pair_wait(pair, &pair->b_cntr, &pair->a_cntr);
return tst_fzsync_pair_wait(pair, &pair->b_cntr, &pair->a_cntr);
}
-
-/**
- * tst_fzsync_pair_exit - Signal that the other thread should exit
- *
- * Causes tst_fzsync_pair_wait() and tst_fzsync_pair_wait_update() to return
- * 0.
- */
-static inline void tst_fzsync_pair_exit(struct tst_fzsync_pair *pair)
-{
- tst_atomic_store(1, &pair->exit);
-}
@@ -65,7 +65,8 @@ static void run(void)
unsigned int i, j, fail = 0;
for (i = 0; i < LOOPS; i++) {
- tst_fzsync_wait_update_a(&pair);
+ if (!tst_fzsync_wait_update_a(&pair))
+ break;
tst_fzsync_delay_a(&pair);
seq[seq_n] = 'A';
seq_n = i * 2 + 1;
@@ -118,7 +118,8 @@ static void run(void)
t.c_lflag |= ECHO;
tcsetattr(master_fd, TCSANOW, &t);
- tst_fzsync_wait_update_a(&fzsync_pair);
+ if (!tst_fzsync_wait_update_a(&fzsync_pair))
+ break;
tst_fzsync_delay_a(&fzsync_pair);
tst_fzsync_time_a(&fzsync_pair);
@@ -140,7 +140,8 @@ static void run(void)
if (socketpair(AF_LOCAL, SOCK_DGRAM, 0, (int *)socket_fds))
tst_brk(TBROK | TERRNO, "Socket creation failed");
- tst_fzsync_wait_update_a(&fzsync_pair);
+ if (!tst_fzsync_wait_update_a(&fzsync_pair))
+ break;
tst_fzsync_delay_a(&fzsync_pair);
stat = tst_syscall(__NR_recvmmsg,
@@ -115,7 +115,8 @@ static void run(void)
SAFE_CONNECT(sockfd,
(struct sockaddr *)&iaddr, sizeof(iaddr));
- tst_fzsync_wait_update_a(&fzsync_pair);
+ if (!tst_fzsync_wait_update_a(&fzsync_pair))
+ break;
tst_fzsync_delay_a(&fzsync_pair);
connect(sockfd, (struct sockaddr *)&uaddr, sizeof(uaddr));
tst_fzsync_time_a(&fzsync_pair);
@@ -102,7 +102,8 @@ static void verify_inotify(void)
if (wd < 0)
tst_brk(TBROK | TERRNO, "inotify_add_watch() failed.");
- tst_fzsync_wait_update_a(&fzsync_pair);
+ if (!tst_fzsync_wait_update_a(&fzsync_pair))
+ break;
tst_fzsync_delay_a(&fzsync_pair);
wd = myinotify_rm_watch(inotify_fd, wd);
Use the tst_timer library to check how long the main test loop has been running for and break the loop if it exceeds 60 seconds. This prevents an overall test timeout which is reported as a failure. Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com> --- include/tst_fuzzy_sync.h | 43 +++++++++++++------ lib/newlib_tests/test16.c | 3 +- testcases/cve/cve-2014-0196.c | 3 +- testcases/cve/cve-2016-7117.c | 3 +- testcases/cve/cve-2017-2671.c | 3 +- testcases/kernel/syscalls/inotify/inotify09.c | 3 +- 6 files changed, 40 insertions(+), 18 deletions(-)