Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp1130168rwo; Sat, 22 Jul 2023 07:08:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlEksCAmJ9fPDeqsbx+DZEjmRc59ya2soKONZtDdMb90dxhO2kdHkX8d6kI9OaF3BiKCroB+ X-Received: by 2002:a17:90a:7404:b0:267:ed84:c74d with SMTP id a4-20020a17090a740400b00267ed84c74dmr2780955pjg.22.1690034933939; Sat, 22 Jul 2023 07:08:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690034933; cv=none; d=google.com; s=arc-20160816; b=UNGSZvQJE8Ik/9+oKmSKQiJrVpc2XF5sN95jk+70vreuEUMEozpEZ7VoSZg77w5aC6 mkZEagpiPG+4bgwKBTfxrxNgB0Fif4s6r9REHwljucWxKMLUtTgLh49fpS7QdNkojFT6 SchhzS6grbxKALWFmOisSyVkZljeqG1fykFxfIWqlLSw2JtyYyTmDldsTsYNDLPuMJzz dh+SCRhqssinzNSU62vMFWOAyHhvqauft+/AiGsjnDlfs+2lwdf0MKory44ZfzxsUPw4 glkY9jvZJR9CwU1XXJIR4gyVDbL2AEx8MG7q0PgcRQK0CMF0PE0hYpUO5XwA6s1N0yIO mnrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=BC837DRE4IjYxjFqGdCwCsO3UxfjW3UDTP6b2Tso2yQ=; fh=ujwW7c4tbJyQEFqfHDIuJXTy68vjNzYK6N7f8YmL270=; b=VwxpUO0xuv7UDci/7bbCLa76OPA42kHgsbkhcPA/SPXEGikGNvH/HRYGiDCqxKw1Kn fipq5Q0fUxc/0JUoqbDYcGzSFSt1a3zZO4ybkKuAZ5qDYpTF3zfXfSyxhr2MZFue8FAp WdD9X4iTWT6AGbPWIDOD6kOUnHUHbQKyCuqIirt758cChkoaB4EnL1ISR6YfJpjbVxWm s93o/308dZuWO7tSvdab0FA2VyyVTi0u1DSj8tA9PocnW3T9Gw8aZKISeCaJnCpwXXjS adakR5ul9sieM+wyPvsIVJ5rEtLoIxys3xiHOE9yknzQk8osNzpuYW4rQW1LrFO1BUWd RQZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020a17090ab94500b00262ee7c6cafsi5329108pjw.87.2023.07.22.07.08.41; Sat, 22 Jul 2023 07:08:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230168AbjGVNDD (ORCPT + 99 others); Sat, 22 Jul 2023 09:03:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230160AbjGVNDB (ORCPT ); Sat, 22 Jul 2023 09:03:01 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A97BD26BF; Sat, 22 Jul 2023 06:02:57 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 36MD2mTj017462; Sat, 22 Jul 2023 15:02:48 +0200 Date: Sat, 22 Jul 2023 15:02:48 +0200 From: Willy Tarreau To: Zhangjin Wu Cc: thomas@t-8ch.de, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v2 09/14] selftests/nolibc: allow quit qemu-system when poweroff fails Message-ID: <20230722130248.GK17311@1wt.eu> References: <511b2f6009fb830b3f32b4be3dca99596c684fa3.1689759351.git.falcon@tinylab.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <511b2f6009fb830b3f32b4be3dca99596c684fa3.1689759351.git.falcon@tinylab.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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. 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. Willy