From f0784451e9e671a1acd6eac0dc0c750a7d83b4eb Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Mon, 10 Feb 2020 21:46:34 -0500 Subject: [PATCH] Tests: Fix: `wait_on_file()` returns too early MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Issue ===== With the current implementation, when calling the `wait_on_file()` function with the `file_exist` parameter set to false the function will return even if the target file exists. In a scenario where we enter the loop and the targer file exist, the first call to `stat()` will return 0 and will not enter any of the `if` and break from the loop directly. Solution ======== If the file exists, only break from the loop if it's the desired exit condition. Signed-off-by: Francis Deslauriers Change-Id: Ia3e9c41a2a515815d3ff931d8f7c1c14a52b31ae Signed-off-by: Jérémie Galarneau --- .../tools/notification/notification.c | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/regression/tools/notification/notification.c b/tests/regression/tools/notification/notification.c index 19df9bc30..f076bbd0e 100644 --- a/tests/regression/tools/notification/notification.c +++ b/tests/regression/tools/notification/notification.c @@ -59,16 +59,31 @@ void wait_on_file(const char *path, bool file_exist) ret = stat(path, &buf); if (ret == -1 && errno == ENOENT) { if (file_exist) { - (void) poll(NULL, 0, 10); /* 10 ms delay */ - continue; /* retry */ + /* + * The file does not exist. wait a bit and + * continue looping until it does. + */ + (void) poll(NULL, 0, 10); + continue; } - break; /* File does not exist */ + + /* + * File does not exist and the exit condition we want. + * Break from the loop and return. + */ + break; } if (ret) { perror("stat"); exit(EXIT_FAILURE); } - break; /* found */ + /* + * stat() returned 0, so the file exists. break now only if + * that's the exit condition we want. + */ + if (file_exist) { + break; + } } } -- 2.34.1