All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhangjin Wu <falcon@tinylab.org>
To: w@1wt.eu
Cc: arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, thomas@t-8ch.de
Subject: Re: [PATCH v2 09/14] selftests/nolibc: allow quit qemu-system when poweroff fails
Date: Tue, 25 Jul 2023 22:59:55 +0800	[thread overview]
Message-ID: <20230725145955.37685-1-falcon@tinylab.org> (raw)
In-Reply-To: <20230722130248.GK17311@1wt.eu>

Hi, Willy

> On Wed, Jul 19, 2023 at 09:27:08PM +0800, Zhangjin Wu wrote:
> > The kernel of some architectures can not poweroff qemu-system normally,
> > especially for tinyconfig.
> > 
> > Some architectures may have no kernel poweroff support, the others may
> > require more kernel config options and therefore slow down the
> > tinyconfig build and test. and also, it's very hard (and some even not
> > possible) to find out the exact poweroff related kernel config options
> > for every architecture.
> > 
> > Since the low-level poweroff support is heavily kernel & qemu dependent,
> > it is not that critical to both nolibc and nolibc-test, let's simply
> > ignore the poweroff required kernel config options for tinyconfig (and
> > even for defconfig) and quit qemu-system after a specified timeout or
> > with an expected system halt or poweroff string (these strings mean our
> > reboot() library routine is perfectly ok).
> > 
> > QEMU_TIMEOUT value can be configured for every architecture based on
> > their time cost requirement of boot+test+poweroff.
> > 
> > Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
> > ---
> >  tools/testing/selftests/nolibc/Makefile | 23 +++++++++++++++++++++--
> >  1 file changed, 21 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
> > index 541f3565e584..a03fab020ebe 100644
> > --- a/tools/testing/selftests/nolibc/Makefile
> > +++ b/tools/testing/selftests/nolibc/Makefile
> > @@ -93,6 +93,9 @@ QEMU_ARGS_s390       = -M s390-ccw-virtio -m 1G -append "console=ttyS0 panic=-1
> >  QEMU_ARGS_loongarch  = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
> >  QEMU_ARGS            = $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_EXTRA)
> >  
> > +# QEMU_TIMEOUT: some architectures can not poweroff normally, especially for tinyconfig
> > +QEMU_TIMEOUT             = $(QEMU_TIMEOUT_$(XARCH))
> > +
> >  # OUTPUT is only set when run from the main makefile, otherwise
> >  # it defaults to this nolibc directory.
> >  OUTPUT ?= $(CURDIR)/
> > @@ -224,16 +227,32 @@ kernel: extconfig
> >  # common macros for qemu run/rerun targets
> >  QEMU_SYSTEM_RUN = qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(KERNEL_IMAGE)" -serial stdio $(QEMU_ARGS)
> >  
> > +ifneq ($(QEMU_TIMEOUT),)
> > +TIMEOUT_CMD = t=$(QEMU_TIMEOUT); \
> > +	while [ $$t -gt 0 ]; do                                                       \
> > +	    sleep 5; t=$$(expr $$t - 5); echo "detecting power off ...";              \
> > +	    if grep -qE "reboot: System halted|reboot: Power down" "$(RUN_OUT)"; then \
> > +		pkill -9 qemu-system-$(QEMU_ARCH);                                    \
> > +		echo "powered off, test finish"; t=1; break;                          \
> > +	    fi;                                                                       \
> > +	done;                                                                         \
> > +	if [ $$t -le 0 ]; then pkill -9 qemu-system-$(QEMU_ARCH); echo "qemu-system-$(QEMU_ARCH) timeout"; fi
> 
> Please have a look at the "timeout" command whichi makes all this much
> simpler.

Yeah, I used 'timeout --forgeground' before, but it is still a dead wait
and it is very hard for us to configure a just right wait time.

If the configured wait time is short, the qemu will be killed during the
test or before running the test, If the configured wait time is long, we
will need to dead wait there even if the test is finished, although
during interactive running, we can press 'CTRL + A X', but for
background running, it is just time waste.

To fix up this issue, the above method used at last allow to detect the
output string, when the test finish and print something lines like:

    reboot: System halted
    reboot: Power down.

We will use pkill to send signal to tell qemu quit, so, it is ok for us
to configure a even'big' timeout, if the kernel can normally poweroff or
if nolibc can successfully send the poweroff syscall, the above message
will be detected and qemu will quit as expected, it will completely
avoid dead wait, the configured timeout will never happen, this is
comfortable.

The worst case is only when qemu or kernel reject to boot, for example,
a qemu bios missing or mismatch issue or a kernel regression or a wrong
kernel config option, for these cases, the real timeout logic will work
for us.

As a summary, our timeout logic here include two parts: one is
'poweroff' related string detection, another is the real timeout logic. 

Based on current implementation, I even plan to add the test finish
string in the expected strings:

    Leaving init with final status

And even further, when a hang detected (no normal poweroff or test
finish string detected), print the whole or last part of running log to
tell users what happens.

> Also, please get used to never ever use kill -9 first. This
> is exactly the way to leave temporary files and IPCs wandering around
> while many programs that care about cleanups at least try to do that
> upon a regular TERM or INT signal.
>

Ok, thanks, will use TERM or INT signal instead.

> Willy

  reply	other threads:[~2023-07-25 15:01 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19 13:16 [PATCH v2 00/14] selftests/nolibc: add minimal kernel config support - part1 Zhangjin Wu
2023-07-19 13:17 ` [PATCH v2 01/14] selftests/nolibc: allow report with existing test log Zhangjin Wu
2023-07-19 13:19 ` [PATCH v2 02/14] selftests/nolibc: add macros to enhance maintainability Zhangjin Wu
2023-07-22 12:20   ` Willy Tarreau
2023-07-25 12:37     ` Zhangjin Wu
2023-07-19 13:20 ` [PATCH v2 03/14] selftests/nolibc: print running log to screen Zhangjin Wu
2023-07-22 12:29   ` Willy Tarreau
2023-07-25 12:46     ` Zhangjin Wu
2023-07-19 13:21 ` [PATCH v2 04/14] selftests/nolibc: fix up O= option support Zhangjin Wu
2023-07-19 13:22 ` [PATCH v2 05/14] selftests/nolibc: add menuconfig for development Zhangjin Wu
2023-07-22 12:35   ` Willy Tarreau
2023-07-25 13:51     ` Zhangjin Wu
2023-07-27 13:24       ` Zhangjin Wu
2023-07-29  8:22         ` Willy Tarreau
2023-07-29 13:54           ` Zhangjin Wu
2023-07-19 13:23 ` [PATCH v2 06/14] selftests/nolibc: add mrproper " Zhangjin Wu
2023-07-22 12:36   ` Willy Tarreau
2023-07-19 13:24 ` [PATCH v2 07/14] selftests/nolibc: defconfig: remove mrproper target Zhangjin Wu
2023-07-22 12:46   ` Willy Tarreau
2023-07-25 14:04     ` Zhangjin Wu
2023-07-19 13:26 ` [PATCH v2 08/14] selftests/nolibc: string the core targets Zhangjin Wu
2023-07-22 12:57   ` Willy Tarreau
2023-07-25 14:20     ` Zhangjin Wu
2023-07-29  7:53       ` Willy Tarreau
2023-07-29  9:54         ` Zhangjin Wu
2023-07-29 17:15           ` Willy Tarreau
2023-07-29 17:44             ` Zhangjin Wu
2023-07-19 13:27 ` [PATCH v2 09/14] selftests/nolibc: allow quit qemu-system when poweroff fails Zhangjin Wu
2023-07-22 13:02   ` Willy Tarreau
2023-07-25 14:59     ` Zhangjin Wu [this message]
2023-07-29  8:04       ` Willy Tarreau
2023-07-19 13:28 ` [PATCH v2 10/14] selftests/nolibc: allow customize CROSS_COMPILE by architecture Zhangjin Wu
2023-07-19 13:29 ` [PATCH v2 11/14] selftests/nolibc: customize CROSS_COMPILE for 32/64-bit powerpc Zhangjin Wu
2023-07-19 13:30 ` [PATCH v2 12/14] selftests/nolibc: add tinyconfig target Zhangjin Wu
2023-07-22 13:07   ` Willy Tarreau
2023-07-25 15:13     ` Zhangjin Wu
2023-07-19 13:31 ` [PATCH v2 13/14] selftests/nolibc: tinyconfig: add extra common options Zhangjin Wu
2023-07-19 13:32 ` [PATCH v2 14/14] selftests/nolibc: tinyconfig: add support for 32/64-bit powerpc Zhangjin Wu
2023-07-22 13:17   ` Willy Tarreau
2023-07-25 16:04     ` Zhangjin Wu

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=20230725145955.37685-1-falcon@tinylab.org \
    --to=falcon@tinylab.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=thomas@t-8ch.de \
    --cc=w@1wt.eu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.