Yocto Project Discussions
 help / color / mirror / Atom feed
From: Joshua Watt <jpewhacker@gmail.com>
To: yocto@lists.yoctoproject.org
Cc: Joshua Watt <JPEWhacker@gmail.com>
Subject: [ptest-runner][PATCH 4/4] Change test timeout to be total elapsed time
Date: Mon, 17 Jul 2023 08:28:31 -0600	[thread overview]
Message-ID: <20230717142831.1634172-5-JPEWhacker@gmail.com> (raw)
In-Reply-To: <20230717142831.1634172-1-JPEWhacker@gmail.com>

Changes the way that tests time out to be the total elapsed time for the
test, not just the time between receiving output from the test. This
matches the implementation before 8259375 ("runner: Remove threads and
mutexes").

Also update the timeout test case to test for this correctly.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
 tests/data/hang/ptest/run-ptest |  1 +
 tests/utils.c                   |  2 +-
 utils.c                         | 23 ++++++++++++-----------
 3 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/tests/data/hang/ptest/run-ptest b/tests/data/hang/ptest/run-ptest
index 738041d..9031be3 100755
--- a/tests/data/hang/ptest/run-ptest
+++ b/tests/data/hang/ptest/run-ptest
@@ -3,5 +3,6 @@
 echo "hang" 1>&2
 echo "hang"
 while true; do
+	echo "hang"
 	sleep 1
 done
diff --git a/tests/utils.c b/tests/utils.c
index d82b90e..849a412 100644
--- a/tests/utils.c
+++ b/tests/utils.c
@@ -224,7 +224,7 @@ search_for_timeout_and_duration(const int rp, FILE *fp_stdout)
 START_TEST(test_run_timeout_duration_ptest)
 {
 	struct ptest_list *head = get_available_ptests(opts_directory);
-	unsigned int timeout = 1;
+	unsigned int timeout = 3;
 
 	test_ptest_expected_failure(head, timeout, "hang", search_for_timeout_and_duration);
 
diff --git a/utils.c b/utils.c
index 34ca2f0..353d6dc 100644
--- a/utils.c
+++ b/utils.c
@@ -403,7 +403,8 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
 	pid_t child;
 	int pipefd_stdout[2] = {-1, -1};
 	int pipefd_stderr[2] = {-1, -1};
-	time_t sttime, entime;
+	time_t sttime, entime, now;
+	time_t timeout_deadline;
 	time_t duration;
 	int slave;
 	int pgid = -1;
@@ -489,6 +490,7 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
 				}
 
 				sttime = time(NULL);
+				timeout_deadline = sttime + opts.timeout;
 				fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, sttime));
 				fprintf(fp, "BEGIN: %s\n", ptest_dir);
 
@@ -519,18 +521,17 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
 					if (done) {
 						break;
 					}
-
-					int ret = poll(pfds, 2, _child_reader.timeout*1000);
-
-					if (ret == 0 && !_child_reader.timeouted) {
-						/* kill the child if we haven't
-						 * already. Note that we
-						 * continue to read data from
-						 * the pipes until EOF to make
-						 * sure we get all the output
-						 */
+					now = time(NULL);
+					if (now >= timeout_deadline) {
 						kill(-child, SIGKILL);
 						_child_reader.timeouted = 1;
+						break;
+					}
+
+					int ret = poll(pfds, 2, (timeout_deadline - now) * 1000);
+
+					if (ret == 0) {
+						continue;
 					}
 
 					for (int i = 0; i < 2; i++) {
-- 
2.33.0



      parent reply	other threads:[~2023-07-17 14:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-17 14:28 [ptest-runner][PATCH 0/4] Stop running ptests in parallel Joshua Watt
2023-07-17 14:28 ` [ptest-runner][PATCH 1/4] Revert "runner: Correctly handle running parallel tests" Joshua Watt
2023-07-17 14:28 ` [ptest-runner][PATCH 2/4] Recreate pipe for each test Joshua Watt
2023-07-17 14:28 ` [ptest-runner][PATCH 3/4] Report if child dies from a signal Joshua Watt
2023-07-17 14:28 ` Joshua Watt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230717142831.1634172-5-JPEWhacker@gmail.com \
    --to=jpewhacker@gmail.com \
    --cc=yocto@lists.yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox