From patchwork Tue Jul 18 17:26:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Watt X-Patchwork-Id: 27673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44DD7EB64DD for ; Tue, 18 Jul 2023 17:26:25 +0000 (UTC) Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) by mx.groups.io with SMTP id smtpd.web10.1922.1689701183626261695 for ; Tue, 18 Jul 2023 10:26:23 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@gmail.com header.s=20221208 header.b=R45ZA6FK; spf=pass (domain: gmail.com, ip: 209.85.160.48, mailfrom: jpewhacker@gmail.com) Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-1b05d63080cso4772317fac.2 for ; Tue, 18 Jul 2023 10:26:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689701182; x=1692293182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+O+h+nWuKnDPa3mn+oNMlR9T01HUBI3+/nwk7K2NT6s=; b=R45ZA6FK5QQrTK4WDN3skRhKx/VnDDZKjwm8M/Ahi63SPcVMTyIlctrBcUHHpa6dVM /eL8+g0DO7FC2fUW8bbZ/081caNx/8xE0bgQh1IwDnCx5dJsrd/fs565hZGw8vyLw1KY CV/yvjEVBX/dt7xbzatItnAM6XoTy/U0QYlwyLF1KugR/nngv/bvWuwN7pVwiJGb3fW7 O2gcyOst7b7kufWcD3v4jCCLiFsBSHElj9DLhnAE3F4LFJcMxXhsrSrWQ+W60RRxNF2J 0Cf2EkZ1LXyesKoXIpdfkVByQ0v+t0UFrVa6l8nTjwXP1rNqz4wcMVQKoiuqi+qlWNCE YZcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689701182; x=1692293182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+O+h+nWuKnDPa3mn+oNMlR9T01HUBI3+/nwk7K2NT6s=; b=cpUYREX7qvpDsrkezfOYNSOvf1jW1n6YaKxbZBLwqQzgS3bwF3wT/899BwXuJ3hZAT WGWJQ7YByHr/yq0XwsBq4Lr9t3mK4bgAKtwFAzI+RScE8SJZ5eQxyYO2vPa0XHIF90kp TgMjAkgdhuOmmptLHHOew9B3KJq6VjyY0a0qX/X8CwwVsH5+svkxjq14S8McoJKKeHCG 7aEY0TY6zATPGUTzfuJfREQ7LU75SHFuF0KRDjYFQkxnFNioCYE3pk/eXPzKHw//EV08 ZTji5B1XpRw7y7IJl1ifO3WDmYT+we7VuSkBfRpQSsy7kEDzXKAQ6GnXKQp3Y/WiUcIX 4e0w== X-Gm-Message-State: ABy/qLZ9r8k9eV6IN/XR3GMbcglKH1hGHho9DAaJo9Rzh0PhRqzNEnQx y6IXSof7L0OAmBdSfbaiRs+5alEHcAo= X-Google-Smtp-Source: APBJJlFU4M4a7KKPDSCtE4JDSoh5AsPdtoNIHpto25slmhqKYHLUPKloG07Fc/HjIz5CfCWJ35Ew2A== X-Received: by 2002:a05:6870:c354:b0:1b0:3e54:946 with SMTP id e20-20020a056870c35400b001b03e540946mr20924182oak.50.1689701180724; Tue, 18 Jul 2023 10:26:20 -0700 (PDT) Received: from localhost.localdomain ([2601:282:4300:19e0::65c]) by smtp.gmail.com with ESMTPSA id 129-20020a4a0687000000b00565ebacf9cfsm1005120ooj.33.2023.07.18.10.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 10:26:19 -0700 (PDT) From: Joshua Watt X-Google-Original-From: Joshua Watt To: yocto@lists.yoctoproject.org Cc: Joshua Watt Subject: [ptest-runner][PATCH 1/5] Revert "Change test timeout to be total elapsed time" Date: Tue, 18 Jul 2023 11:26:10 -0600 Message-Id: <20230718172614.469304-2-JPEWhacker@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230718172614.469304-1-JPEWhacker@gmail.com> References: <20230718172614.469304-1-JPEWhacker@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 18 Jul 2023 17:26:25 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto/message/60607 This reverts commit e50f2175d9c6b8aeb8b0bf687e5cca64a0f6e61a. The timeout is actually the amount of time to wait until there is no output from the test, not the total test time. Signed-off-by: Joshua Watt --- tests/data/hang/ptest/run-ptest | 1 - tests/utils.c | 2 +- utils.c | 23 +++++++++++------------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/data/hang/ptest/run-ptest b/tests/data/hang/ptest/run-ptest index 9031be3..738041d 100755 --- a/tests/data/hang/ptest/run-ptest +++ b/tests/data/hang/ptest/run-ptest @@ -3,6 +3,5 @@ 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 849a412..d82b90e 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 = 3; + unsigned int timeout = 1; test_ptest_expected_failure(head, timeout, "hang", search_for_timeout_and_duration); diff --git a/utils.c b/utils.c index 353d6dc..34ca2f0 100644 --- a/utils.c +++ b/utils.c @@ -403,8 +403,7 @@ 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, now; - time_t timeout_deadline; + time_t sttime, entime; time_t duration; int slave; int pgid = -1; @@ -490,7 +489,6 @@ 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); @@ -521,17 +519,18 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, if (done) { break; } - now = time(NULL); - if (now >= timeout_deadline) { - kill(-child, SIGKILL); - _child_reader.timeouted = 1; - break; - } - int ret = poll(pfds, 2, (timeout_deadline - now) * 1000); + int ret = poll(pfds, 2, _child_reader.timeout*1000); - if (ret == 0) { - continue; + 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 + */ + kill(-child, SIGKILL); + _child_reader.timeouted = 1; } for (int i = 0; i < 2; i++) { From patchwork Tue Jul 18 17:26:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Watt X-Patchwork-Id: 27672 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46EDAC001DF for ; Tue, 18 Jul 2023 17:26:25 +0000 (UTC) Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) by mx.groups.io with SMTP id smtpd.web11.1870.1689701183211045389 for ; Tue, 18 Jul 2023 10:26:23 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@gmail.com header.s=20221208 header.b=pLQlu0Dl; spf=pass (domain: gmail.com, ip: 209.85.161.43, mailfrom: jpewhacker@gmail.com) Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-56598263d1dso3869647eaf.0 for ; Tue, 18 Jul 2023 10:26:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689701182; x=1692293182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/chmA5HZfGusxWMEjNKsIshsKdY9O33vilaiD1u7PvM=; b=pLQlu0DlGIOzDPjvsE+9xgz49uWNyNDbxIAOP/fWA43tNtSMWxFVXrgamH7JZNHtrD 0QgzLyemFe7t7NrpD8PtCAbO+PmZ/8NLRlXtwboC7nBLHUKhUJ0+iPzuszN+07hUiOzl i358a9LzAkdWBUCiFyfEkVeYAZM1p5lTCbUsbkhPVfzgG7Vuc6HadbbceMTEknpjo5zC 0qPSso+tMjskbEnEdI4z4cdtk37h9izlAxxZ/0yS1JD6P5EglHTg2fVaPkmbnVb5wtgw v6kpZAJUI95BSp5bLeTvr5lR6Mwp4YjedGIC7chwwVV/XdyukBPhSygglcVAHwvSlvvH BQ7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689701182; x=1692293182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/chmA5HZfGusxWMEjNKsIshsKdY9O33vilaiD1u7PvM=; b=VqAOM7pxoksuiIRt8LJIluk55I+rbGK5bcLQu6fj4cGzgmle/5GadyBQcOvGK79WuD 9MV7epf9NH50F6p1GakBxlD8TXpP+3JmjSK+CwcBTi0zrROrei9WCfpvida/JCmQI7lg UG9mNud29hlgQZ6+kAbrXGp6kevR5w5wctA1nMaO2MErgLrnVy9OIB5g2Thj/EASK1Fl vb60kquESrRiXaTbQvWyNIXlt3FXeOr5OBowLkCsyvQ8YrAjZDvqp3b3jXsa8av5Yt8O ZXN/B5rehRzPq1FXekF652FDagRhdULIKIWYVgtB8oVgmQg6LgVTMWAtmGsW7Nax66Mg WuUw== X-Gm-Message-State: ABy/qLZ79htu3SkK6wnnV56Q1c9h0wWqfOlWgCc1GGlGyJcnxPzO3csV DShxZbwee/K2+B0ZT1tRp6UmwK8UDaQ= X-Google-Smtp-Source: APBJJlGB8P/YL4YgVxLuEAY5UHDzAfhJgk5dafwRSmiWr+OUrBJYJhn2RNhDPhpaIgCGwMdu2Av7qQ== X-Received: by 2002:a4a:271b:0:b0:566:f406:9b7c with SMTP id l27-20020a4a271b000000b00566f4069b7cmr6878925oof.3.1689701181633; Tue, 18 Jul 2023 10:26:21 -0700 (PDT) Received: from localhost.localdomain ([2601:282:4300:19e0::65c]) by smtp.gmail.com with ESMTPSA id 129-20020a4a0687000000b00565ebacf9cfsm1005120ooj.33.2023.07.18.10.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 10:26:21 -0700 (PDT) From: Joshua Watt X-Google-Original-From: Joshua Watt To: yocto@lists.yoctoproject.org Cc: Joshua Watt Subject: [ptest-runner][PATCH 2/5] Only collect system state on timeout Date: Tue, 18 Jul 2023 11:26:11 -0600 Message-Id: <20230718172614.469304-3-JPEWhacker@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230718172614.469304-1-JPEWhacker@gmail.com> References: <20230718172614.469304-1-JPEWhacker@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 18 Jul 2023 17:26:25 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto/message/60606 To match the behavior of the previous ptest-runner, only collect system state when a test has timed out Signed-off-by: Joshua Watt --- utils.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/utils.c b/utils.c index 34ca2f0..d0e6a99 100644 --- a/utils.c +++ b/utils.c @@ -556,21 +556,18 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, } } } - collect_system_state(_child_reader.fps[0]); - for (int i = 0; i < 2; i++) { - fflush(_child_reader.fps[i]); - } - - /* - * This kill is just in case the child did - * something really silly like close its - * stdout and stderr but then go into an - * infinite loop and never exit. Normally, it - * will just fail because the child is already - * dead - */ - if (!_child_reader.timeouted) { + if (_child_reader.timeouted) { + collect_system_state(fp); + } else { + /* + * This kill is just in case the child did + * something really silly like close its + * stdout and stderr but then go into an + * infinite loop and never exit. Normally, it + * will just fail because the child is already + * dead + */ kill(-child, SIGKILL); } waitpid(child, &status, 0); From patchwork Tue Jul 18 17:26:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Watt X-Patchwork-Id: 27674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29770EB64DC for ; Tue, 18 Jul 2023 17:26:35 +0000 (UTC) Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by mx.groups.io with SMTP id smtpd.web11.1871.1689701185183593378 for ; Tue, 18 Jul 2023 10:26:25 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@gmail.com header.s=20221208 header.b=eP3PV2cc; spf=pass (domain: gmail.com, ip: 209.85.210.42, mailfrom: jpewhacker@gmail.com) Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-6b9e478e122so706583a34.1 for ; Tue, 18 Jul 2023 10:26:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689701183; x=1692293183; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AwbO4EJM/CWYrg7CgWs2TyXTOJ4GQa4W36VYE/9QcEw=; b=eP3PV2ccuqIlvluP0hGn/A7vp2FHmySf2U9jlSZvGgGVxiZxrOCOyhPl5laRdFdqKz P5Ik2DcF/LxMui/HRXos1Z0327ktCAAL6eMRcXDqbJBZKsmBKJSPM4iYdzBOgWk8aaaF ACGNAt94jWo29Icz6ORkVPiHZ/me+Go6GVxWnU+Rb4QDGNjMORQzy723EQkc5kpfdosu KfX6TPOJw0hU8DGJtNNHbmCQilNGrHkN4s6MYLSU5wIcvpSNgLBehiT1Zm6R/uHZRcq0 TLxZhWvhMwKJB55z6RvWq+Hcg+ncWX/4JRgeDZ9wQiW/LTAyZpWFdI0DCbPx22MvRNYO /3sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689701183; x=1692293183; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AwbO4EJM/CWYrg7CgWs2TyXTOJ4GQa4W36VYE/9QcEw=; b=RCNBGNVEtjTxaMjA19NBJkqAgw4iReD6y6r1q53ykneiWzdHtVLAnf/khLN0923dYI JUBTJc8ZX7F3I4UPxD5jhlCXnZHyb1SeAu8FjSy+FIYkzlu5foba4rwNPaxkHrqYbGsl xOiKw3laJbvZlQib29BQgjpxjlXtmBp0iNpguzIPlM9Ons62JuSxMLxPp4f9BAjVfNa2 xEZ8Da5DBOWRcWl9l+TveeRNGE23pwyKzlm29NEtx2BnydmPuw58cK6hQf9FOsuA6lpf oruwVcQtSRDZzXXasFcsTymnBrAk8Ur3jTrQ5yR9M7Uh6UeNHAHjjkhTv5bl6UUiKOe8 /JZg== X-Gm-Message-State: ABy/qLYBsRiHGTE1AMqbgaREn0s1+u6X7J8P/oCsR8brmZnHYvCklTWv KZB3PLJIaiH9RgshYGEy4j2IAYP1mrQ= X-Google-Smtp-Source: APBJJlFxBDDRaegHGo+b6WHFEF7EMO7dA0BotODrn1yEKYh2HBA+fcZ80KrLWJQpqCXspWa+dw0Ujg== X-Received: by 2002:a05:6870:3306:b0:1ba:5464:774d with SMTP id x6-20020a056870330600b001ba5464774dmr11321832oae.19.1689701183574; Tue, 18 Jul 2023 10:26:23 -0700 (PDT) Received: from localhost.localdomain ([2601:282:4300:19e0::65c]) by smtp.gmail.com with ESMTPSA id 129-20020a4a0687000000b00565ebacf9cfsm1005120ooj.33.2023.07.18.10.26.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 10:26:22 -0700 (PDT) From: Joshua Watt X-Google-Original-From: Joshua Watt To: yocto@lists.yoctoproject.org Cc: Joshua Watt Subject: [ptest-runner][PATCH 3/5] Report test failure on timeout Date: Tue, 18 Jul 2023 11:26:12 -0600 Message-Id: <20230718172614.469304-4-JPEWhacker@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230718172614.469304-1-JPEWhacker@gmail.com> References: <20230718172614.469304-1-JPEWhacker@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 18 Jul 2023 17:26:35 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto/message/60608 Even when a test times out, an "ERROR:" message should be printed so that the OE selftest parser knows the test has failed. Signed-off-by: Joshua Watt --- utils.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/utils.c b/utils.c index d0e6a99..aacf123 100644 --- a/utils.c +++ b/utils.c @@ -575,23 +575,20 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, entime = time(NULL); duration = entime - sttime; - int exit_code = 0; - - if (!_child_reader.timeouted) { - if (WIFEXITED(status)) { - exit_code = WEXITSTATUS(status); - if (exit_code) { - fprintf(fp, "\nERROR: Exit status is %d\n", exit_code); - rc += 1; - } - } else if (WIFSIGNALED(status)) { - int signal = WTERMSIG(status); - fprintf(fp, "\nERROR: Exited from signal %s (%d)\n", strsignal(signal), signal); - rc += 1; - } else { - fprintf(fp, "\nERROR: Exited for unknown reason (%d)\n", status); + int exit_code = -1; + if (WIFEXITED(status)) { + exit_code = WEXITSTATUS(status); + if (exit_code) { + fprintf(fp, "\nERROR: Exit status is %d\n", exit_code); rc += 1; } + } else if (WIFSIGNALED(status)) { + int signal = WTERMSIG(status); + fprintf(fp, "\nERROR: Exited from signal %s (%d)\n", strsignal(signal), signal); + rc += 1; + } else { + fprintf(fp, "\nERROR: Exited for unknown reason (%d)\n", status); + rc += 1; } fprintf(fp, "DURATION: %d\n", (int) duration); if (_child_reader.timeouted) { From patchwork Tue Jul 18 17:26:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Watt X-Patchwork-Id: 27675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F00DC001DF for ; Tue, 18 Jul 2023 17:26:35 +0000 (UTC) Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) by mx.groups.io with SMTP id smtpd.web10.1923.1689701186265322816 for ; Tue, 18 Jul 2023 10:26:26 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@gmail.com header.s=20221208 header.b=FvY07xnz; spf=pass (domain: gmail.com, ip: 209.85.210.44, mailfrom: jpewhacker@gmail.com) Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-6b9b835d302so2788137a34.1 for ; Tue, 18 Jul 2023 10:26:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689701185; x=1692293185; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q0P7fzlMoPiY/NNkquroxGdBAj1XyAgJhy6dA2mIHQA=; b=FvY07xnzsJb4+lnTKWVjyIQITl3JnYCu11Juafk05mRaETrzAXIWCDxsCvnUjWk1ti kju7s4QSyV59Ibunzv/kkcEURG94mGqbeS/HNUjnPZrIkxtkPVDi8pWzRfz79KqM8OTX sQ8EY3YpYCGegIk7BlIee4KIZ1q3xd8uuc+Btl+J1OmHFcDwDrUjrpk3Gl7o5b5/qR58 NcEdYIz8NWXjdyYlAL2+RlB+fbRlrslyqMY94lyj7F2GkDVkKZ0FYr/8EdObg7yJWyTa vFdawKVXM1V5NksuVHQNiK9C074TGv2nH483f4Zd4ImgPzlFtdyfI92Z6WrgAKVjceJM cMRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689701185; x=1692293185; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q0P7fzlMoPiY/NNkquroxGdBAj1XyAgJhy6dA2mIHQA=; b=eEHviyZTrIPC2O1YFWCjlWeSs4zGJ2akXG5wT8MPZp59liE3xfnMFAEEBtQAfFVXXe t+tw+Gq34O0IqrD9rKgZqwaPlbHgCIqO1zGpM2lyh0qaE4OUzO4rwss9h8gz3QY11hab 8SG2YekZv8+1Qhz2lgZQyWwt4nrG+LBM4ZaN5wnDsOryro3PR9YXC/Ma+I51/kp62OLB SqhfgJiZL6z/vbUGWGslh7r/jAZM8z/ZH2SLJMCpas9kuG0Cxez4mJ95JIxjjIAjHPDQ jn5ZDJFGRDDl6i/u3B81CQd0sgh7KbSFFUVU8JpldpfavHWL94H/LnxTDIHi63oHal1D QDfQ== X-Gm-Message-State: ABy/qLb5cumBKo+to/0kksJSBF3R87d3GU7aLQQ6vXmQi6cTd5e1Zmsd WTt06/xrUwGfb71Swlx4poU4eVPvjO4= X-Google-Smtp-Source: APBJJlGQB7NSjexY0KsrNtmFkLqBFvhdZCe7Qy/hRqJMod3rnXzUfu0doxY4XBjSPqndaNHfkJhR1w== X-Received: by 2002:a05:6871:720:b0:1b0:18e8:9535 with SMTP id f32-20020a056871072000b001b018e89535mr13010877oap.56.1689701184942; Tue, 18 Jul 2023 10:26:24 -0700 (PDT) Received: from localhost.localdomain ([2601:282:4300:19e0::65c]) by smtp.gmail.com with ESMTPSA id 129-20020a4a0687000000b00565ebacf9cfsm1005120ooj.33.2023.07.18.10.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 10:26:23 -0700 (PDT) From: Joshua Watt X-Google-Original-From: Joshua Watt To: yocto@lists.yoctoproject.org Cc: Joshua Watt Subject: [ptest-runner][PATCH 4/5] Remove _child_reader singleton Date: Tue, 18 Jul 2023 11:26:13 -0600 Message-Id: <20230718172614.469304-5-JPEWhacker@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230718172614.469304-1-JPEWhacker@gmail.com> References: <20230718172614.469304-1-JPEWhacker@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 18 Jul 2023 17:26:35 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto/message/60609 Instead of using the _child_reader singleton to track the child process, use variables on the stack. Also, limit the variable scope as much as possible and used named constants for the pipe indices. Signed-off-by: Joshua Watt --- utils.c | 108 +++++++++++++++++++++++++------------------------------- 1 file changed, 48 insertions(+), 60 deletions(-) diff --git a/utils.c b/utils.c index aacf123..bd52544 100644 --- a/utils.c +++ b/utils.c @@ -55,14 +55,10 @@ #define UNUSED(x) (void)(x) -static struct { - int fds[2]; - FILE *fps[2]; - - unsigned int timeout; - int timeouted; - int padding1; -} _child_reader; +enum { + PIPE_READ = 0, + PIPE_WRITE = 1, +}; static inline char * get_stime(char *stime, size_t size, time_t t) @@ -398,15 +394,7 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, FILE *xh = NULL; struct ptest_list *p; - char stime[GET_STIME_BUF_SIZE]; - pid_t child; - int pipefd_stdout[2] = {-1, -1}; - int pipefd_stderr[2] = {-1, -1}; - time_t sttime, entime; - time_t duration; - int slave; - int pgid = -1; if (opts.xml_filename) { xh = xml_create(ptest_list_length(head), opts.xml_filename); @@ -423,12 +411,16 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, fprintf(fp, "START: %s\n", progname); PTEST_LIST_ITERATE_START(head, p) + int pipefd_stdout[2] = {-1, -1}; + int pipefd_stderr[2] = {-1, -1}; + int pgid = -1; + if ((rc = pipe2(pipefd_stdout, 0)) == -1) break; if ((rc = pipe2(pipefd_stderr, 0)) == -1) { - close(pipefd_stdout[0]); - close(pipefd_stdout[1]); + close(pipefd_stdout[PIPE_READ]); + close(pipefd_stdout[PIPE_WRITE]); break; } @@ -443,16 +435,18 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, fprintf(fp, "ERROR: getpgid() failed, %s\n", strerror(errno)); } - child = fork(); + pid_t child = fork(); if (child == -1) { fprintf(fp, "ERROR: Fork %s\n", strerror(errno)); rc = -1; break; } else if (child == 0) { + int slave; + close(0); /* Close read ends of the pipe */ - do_close(&pipefd_stdout[0]); - do_close(&pipefd_stderr[0]); + do_close(&pipefd_stdout[PIPE_READ]); + do_close(&pipefd_stderr[PIPE_READ]); if ((slave = setup_slave_pty(fp)) < 0) { fprintf(fp, "ERROR: could not setup pty (%d).", slave); @@ -469,37 +463,35 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, fprintf(fp, "ERROR: Unable to attach to controlling tty, %s\n", strerror(errno)); } - run_child(p->run_ptest, pipefd_stdout[1], pipefd_stderr[1]); + run_child(p->run_ptest, pipefd_stdout[PIPE_WRITE], pipefd_stderr[PIPE_WRITE]); } else { - int status; + bool timedout = false; + char stime[GET_STIME_BUF_SIZE]; /* Close write ends of the pipe, otherwise this process will never get EOF when the child dies */ - do_close(&pipefd_stdout[1]); - do_close(&pipefd_stderr[1]); - - _child_reader.fds[0] = pipefd_stdout[0]; - _child_reader.fds[1] = pipefd_stderr[0]; - _child_reader.fps[0] = fp; - _child_reader.fps[1] = fp_stderr; - _child_reader.timeout = opts.timeout; - _child_reader.timeouted = 0; + do_close(&pipefd_stdout[PIPE_WRITE]); + do_close(&pipefd_stderr[PIPE_WRITE]); + if (setpgid(child, pgid) == -1) { fprintf(fp, "ERROR: setpgid() failed, %s\n", strerror(errno)); } - sttime = time(NULL); - fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, sttime)); + time_t start_time= time(NULL); + fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, start_time)); fprintf(fp, "BEGIN: %s\n", ptest_dir); - set_nonblocking(_child_reader.fds[0]); - set_nonblocking(_child_reader.fds[1]); - struct pollfd pfds[2]; - for (int i = 0; i < 2; i++) { - pfds[i].fd = _child_reader.fds[i]; - pfds[i].events = POLLIN; - } + FILE* dest_fps[2]; + set_nonblocking(pipefd_stdout[PIPE_READ]); + pfds[0].fd = pipefd_stdout[PIPE_READ]; + pfds[0].events = POLLIN; + dest_fps[0] = fp; + + set_nonblocking(pipefd_stderr[PIPE_READ]); + pfds[1].fd = pipefd_stderr[PIPE_READ]; + pfds[1].events = POLLIN; + dest_fps[1] = fp_stderr; while (true) { /* @@ -520,9 +512,9 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, break; } - int ret = poll(pfds, 2, _child_reader.timeout*1000); + int ret = poll(pfds, 2, opts.timeout*1000); - if (ret == 0 && !_child_reader.timeouted) { + if (ret == 0 && !timedout) { /* kill the child if we haven't * already. Note that we * continue to read data from @@ -530,7 +522,7 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, * sure we get all the output */ kill(-child, SIGKILL); - _child_reader.timeouted = 1; + timedout = true; } for (int i = 0; i < 2; i++) { @@ -551,13 +543,13 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, } continue; } else { - fwrite(buf, (size_t)n, 1, _child_reader.fps[i]); + fwrite(buf, (size_t)n, 1, dest_fps[i]); } } } } - if (_child_reader.timeouted) { + if (timedout) { collect_system_state(fp); } else { /* @@ -570,10 +562,11 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, */ kill(-child, SIGKILL); } + int status; waitpid(child, &status, 0); - entime = time(NULL); - duration = entime - sttime; + time_t end_time = time(NULL); + time_t duration = end_time - start_time; int exit_code = -1; if (WIFEXITED(status)) { @@ -591,30 +584,25 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, rc += 1; } fprintf(fp, "DURATION: %d\n", (int) duration); - if (_child_reader.timeouted) { + if (timedout) { fprintf(fp, "TIMEOUT: %s\n", ptest_dir); rc += 1; } if (opts.xml_filename) - xml_add_case(xh, exit_code, ptest_dir, _child_reader.timeouted, (int) duration); + xml_add_case(xh, exit_code, ptest_dir, timedout, (int) duration); fprintf(fp, "END: %s\n", ptest_dir); - fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, entime)); + fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, end_time)); } free(ptest_dir); - do_close(&pipefd_stdout[0]); - do_close(&pipefd_stdout[1]); - do_close(&pipefd_stderr[0]); - do_close(&pipefd_stderr[1]); + do_close(&pipefd_stdout[PIPE_READ]); + do_close(&pipefd_stdout[PIPE_WRITE]); + do_close(&pipefd_stderr[PIPE_READ]); + do_close(&pipefd_stderr[PIPE_WRITE]); PTEST_LIST_ITERATE_END fprintf(fp, "STOP: %s\n", progname); - - do_close(&pipefd_stdout[0]); - do_close(&pipefd_stdout[1]); - do_close(&pipefd_stderr[0]); - do_close(&pipefd_stderr[1]); } while (0); if (rc == -1) From patchwork Tue Jul 18 17:26:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Watt X-Patchwork-Id: 27676 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 297B3EB64DD for ; Tue, 18 Jul 2023 17:26:35 +0000 (UTC) Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) by mx.groups.io with SMTP id smtpd.web10.1924.1689701187767811699 for ; Tue, 18 Jul 2023 10:26:27 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@gmail.com header.s=20221208 header.b=MjaONyVj; spf=pass (domain: gmail.com, ip: 209.85.161.41, mailfrom: jpewhacker@gmail.com) Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-563439ea4a2so3762421eaf.0 for ; Tue, 18 Jul 2023 10:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689701186; x=1692293186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aWbBbhHmUegupJ010srIZoJNpqjVp73X9lIWxTJhjKc=; b=MjaONyVj8ypgkc+6yXciuxYYVtcesJ4Hlq+TbHbqignDt8vGV95TOGvdfDgRhkTJ2g +pNlJ67OtmJwhfCvLtkCi++Etv8O7lWsIGbjy6zFI5N1ljmMc1lvplFQ0jcv2ISDHp0C ZoxAMS0WXP35gptXDKBgQKy90suJ4VB/ug+g7D3PaEx5EaysHeN77LrMerp3ThTnidje FkT1TzuFPPZIF2eKQLBCx7wqfgy5uFr52dHx1VkUKDqCp1CH3vTept/gd9yfhzOstezG Q0FC93IldvXqhG+D6tWEj1VEQAuEK4ZeHIhKehBIyskPOka4d6Tj+HknOHJHasr2hJds ihjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689701186; x=1692293186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aWbBbhHmUegupJ010srIZoJNpqjVp73X9lIWxTJhjKc=; b=mB0t648oxalIhVM+MGqURl4jwimvBY004ZT5Mg071yUYfu5RC7bHtA/7LZCyqTxgBU sdWb9ohN4eiRWTNxa1htVpyA0imktKssYeQST16xATMf8oZUzuERu1SvgLpOeqq5YKS5 Cd3xPYJNhTH9DHp84W0yeLl0TUyXo0GmB2zbwoeQTRwwXU67Q1+8oJ8lV6GtZ7PqDcgD lenG6AJSpReGcP3byzPwefN9j+PlhYr6doggAbbsbN4zgyZjvGeJfiOEAWgTxeTmXMNT PovLahTJ+bs3alL5wdCRJ2BgijILdpl1hJVwvlsKS62iIuKUih0m5iLWvaUVWe3h5whl c+XQ== X-Gm-Message-State: ABy/qLZxLtFd/kRHJM/vFHugNfb6yJmQ8zu2vdW75DA8HO3Hyjznma0v Y0LdklSz57ELIj3goS4mkTPvoB1IPsw= X-Google-Smtp-Source: APBJJlFv/0Vus93+4XEHDoLP7PitiS+x5B59QL3yM700n/idaQT1TfItYvRsdds5a+u3dY4Y3n0/Dg== X-Received: by 2002:a4a:d295:0:b0:567:92:c45d with SMTP id h21-20020a4ad295000000b005670092c45dmr7338555oos.5.1689701186448; Tue, 18 Jul 2023 10:26:26 -0700 (PDT) Received: from localhost.localdomain ([2601:282:4300:19e0::65c]) by smtp.gmail.com with ESMTPSA id 129-20020a4a0687000000b00565ebacf9cfsm1005120ooj.33.2023.07.18.10.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 10:26:25 -0700 (PDT) From: Joshua Watt X-Google-Original-From: Joshua Watt To: yocto@lists.yoctoproject.org Cc: Joshua Watt Subject: [ptest-runner][PATCH 5/5] Flush stdout and stderr after test Date: Tue, 18 Jul 2023 11:26:14 -0600 Message-Id: <20230718172614.469304-6-JPEWhacker@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230718172614.469304-1-JPEWhacker@gmail.com> References: <20230718172614.469304-1-JPEWhacker@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 18 Jul 2023 17:26:35 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto/message/60610 After reporting test results, flush the output buffers to ensure the files are written out. Also flush again at the end of running all tests Signed-off-by: Joshua Watt --- utils.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utils.c b/utils.c index bd52544..59b8b77 100644 --- a/utils.c +++ b/utils.c @@ -601,6 +601,9 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, do_close(&pipefd_stderr[PIPE_READ]); do_close(&pipefd_stderr[PIPE_WRITE]); + fflush(fp); + fflush(fp_stderr); + PTEST_LIST_ITERATE_END fprintf(fp, "STOP: %s\n", progname); } while (0); @@ -611,6 +614,9 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts, if (opts.xml_filename) xml_finish(xh); + fflush(fp); + fflush(fp_stderr); + return rc; }