From patchwork Thu Jul 27 20:30:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 127166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:d09a:b0:134:c3fc:3153 with SMTP id jc26csp190026rwb; Thu, 27 Jul 2023 13:49:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlFTVpWiqRYUao6nUoW6bDihCLtEVgfSocnOnu8WHD9hH7yIZkL5XxdtdFtSrTgjjmOQJX+T X-Received: by 2002:a05:6a21:3392:b0:133:5f6a:fb6 with SMTP id yy18-20020a056a21339200b001335f6a0fb6mr245170pzb.1.1690490969157; Thu, 27 Jul 2023 13:49:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690490969; cv=none; d=google.com; s=arc-20160816; b=nmp7gqakLodXdi9rmLdylWAfuQ/UbiYzsVSHz7JYpwEI8eRbjuTNliuk6i9Ae6NlnU T2+sUW75r+Er+4Nj9rZxQY1I9I4c0bfCiyzlFjMVyyTWWalkgU/buqOe7JrF15HCEwBG PQM4C9ImB6nLLQNjBw76kXrx8QLQiMsj8OVJ39LpgK6J8Yboyn3zyfvHgw6bsa394rPt 3Q3S02jNX58yKEi/ft6WCqCGGwPgTt9KnaDs4++saVNfgp6VoQqPIzdXtmzh3HvX7vcd XXox+zgqlNcO9GoLnXG0MqHG+aq/cAvE6oUC3EoKIA0Bu4LmzQiR4Fbd4eN3/LxySpVC Z2zA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=C0YzCn4LVD+emf+zdHtZhextI5R9pLIWIAWh5lB1JCY=; fh=CR7OSt3Y+a8PS+dgzZNHcKmuduX0vKjLX+CD3ki537g=; b=hLP2LpA4q+HVatl6RbUDRyPrdEj8p+0VaZhKv89vvEybM8wnUt4J3Xby7MS43ezfGH NckHZBUflZ13k5XRLtA0866+sxI0xHyNyyRkJNuRnOXxFCcSzhq/ZTEgp4ASPKg5wZCc ihubUv7od2UHD7YijYDzQ2bwSYLmCsU8C1Q5LLqg2IHgt6bxKxPwtFOR6S3r9z59yXAX BEICN9YdzUxGmE48oDhXhYXA2JYJ6q3XyJIh4Zi+qXBtQoCHkXFd9NF/uwkjX3Xpg2Qq NXIClxPfySuaCUcDoGCPTvm5ZNRtE/5+3jarlPTRR45hR4G0zkRaqQGITU2IIkdvYwIU gCwQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bu16-20020a632950000000b00563b7d87d83si1679501pgb.424.2023.07.27.13.49.16; Thu, 27 Jul 2023 13:49:29 -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 S230478AbjG0Uaz (ORCPT + 99 others); Thu, 27 Jul 2023 16:30:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231421AbjG0Uaw (ORCPT ); Thu, 27 Jul 2023 16:30:52 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F37BB30E4; Thu, 27 Jul 2023 13:30:42 -0700 (PDT) X-QQ-mid: bizesmtp89t1690489832t5sr73z5 Received: from linux-lab-host.localdomain ( [61.141.78.189]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 28 Jul 2023 04:30:31 +0800 (CST) X-QQ-SSF: 01200000000000D0X000000A0000000 X-QQ-FEAT: pmyeiOl6PGn82x4eFXPNEITOuWWU+TvnNm56XXJBynRue1cBZR4uW6sldlrWd 4avjCims+5xy9Qf/PYidPSKOOcbnAkxppQvdPEejuwpc4PM6jyWFcyZTUuDqVJdJ5JmoooI jL/XkwNL1y1hjcw8FyqydaCs4yicA/VuDE3SFw6wgCvkTXIyWQZt4DRiLIMNPr6eEUD+m72 f+xek+riwnuTGiwPrYymmfQffQqEBn7xLjaQbhA9sfEOtixwjGr0uWR3dBgWyKcpPJduAeb K2hMuJGt0tN6UMAuv3o32/8NH0U0c6Xm8snJ0+XJly6iTA9nuPqlwdvO8mQAPAd/qr53uSM 1WulUhXMoKeKR1ocG/O6MNH8ckx1LbDykelL+Evnc/anK0xbMA1VPoKqamurc2uMWMOEz1E X-QQ-GoodBg: 0 X-BIZMAIL-ID: 6404872216917566907 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v3 08/12] selftests/nolibc: allow quit qemu-system when poweroff fails Date: Fri, 28 Jul 2023 04:30:31 +0800 Message-Id: <4b4d792299ca5356f8f5af5fc9a27c687b0e4e38.1690489039.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772608258938133082 X-GMAIL-MSGID: 1772608258938133082 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 can be configured for every architecture based on their time cost requirement of bios boot + kernel boot + test + poweroff. By default, 10 seconds timeout is configured, this is enough for most of the architectures, otherwise, customize one by architecture. To tell users the test running progress in time, some critical running status are also printed and detected. Suggested-by: Willy Tarreau Link: https://lore.kernel.org/lkml/20230722130248.GK17311@1wt.eu/ Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/Makefile | 30 +++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index a214745e0f3e..9a57de3b283c 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -105,6 +105,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 = $(or $(QEMU_TIMEOUT_$(XARCH)),10) + # OUTPUT is only set when run from the main makefile, otherwise # it defaults to this nolibc directory. OUTPUT ?= $(CURDIR)/ @@ -229,16 +232,39 @@ kernel: $(KERNEL_CONFIG) # 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) +TIMEOUT_CMD = t=$(QEMU_TIMEOUT); past=0; \ + bios_timeout=$$(expr $$t - 7); kernel_timeout=$$(expr $$t - 5); init_timeout=$$(expr $$t - 3); test_timeout=$$(expr $$t - 1); \ + err=""; bios=0; kernel=0; init=0; test=0; poweredoff=0; panic=0; \ + echo "Running $(KERNEL_IMAGE) on qemu-system-$(QEMU_ARCH)"; \ + while [ $$t -gt 0 ]; do \ + sleep 2; t=$$(expr $$t - 2); past=$$(expr $$past + 2); \ + if [ $$bios -eq 0 ] && grep -E "Linux version|Kernel command line|printk: console" "$(RUN_OUT)"; then bios=1; fi; \ + if [ $$bios -eq 1 -a $$kernel -eq 0 ] && grep -E "Run .* as init process" "$(RUN_OUT)"; then kernel=1; fi; \ + if [ $$kernel -eq 1 -a $$init -eq 0 ] && grep -E "Running test" "$(RUN_OUT)"; then init=1; fi; \ + if [ $$init -eq 1 -a $$test -eq 0 ] && grep -E "Leaving init with final status|Exiting with status" "$(RUN_OUT)"; then test=1; fi; \ + if [ $$init -eq 1 ] && grep -E "Kernel panic - not syncing: Attempted to kill init" "$(RUN_OUT)"; then err="test"; sleep 1; break; fi; \ + if [ $$test -eq 1 ] && grep -E "reboot: System halted|reboot: Power down" "$(RUN_OUT)"; then poweredoff=1; sleep 1; break; fi; \ + if [ $$past -gt $$bios_timeout -a $$bios -eq 0 ]; then err="bios"; break; fi; \ + if [ $$past -gt $$kernel_timeout -a $$kernel -eq 0 ]; then err="kernel"; break; fi; \ + if [ $$past -gt $$init_timeout -a $$init -eq 0 ]; then err="init"; break; fi; \ + if [ $$past -gt $$test_timeout -a $$test -eq 0 ]; then err="test"; break; fi; \ + done; \ + if [ -z "$$err" -a $$poweredoff -eq 0 -a $$panic -eq 0 ]; then err="qemu-system-$(QEMU_ARCH)"; fi; \ + if [ -n "$$err" ]; then echo "$$err may timeout, test failed"; tail -10 $(RUN_OUT); else echo "powered off, test finish"; fi; \ + pkill -15 qemu-system-$(QEMU_ARCH) || true + +TIMEOUT_QEMU_RUN = ($(QEMU_SYSTEM_RUN) > "$(RUN_OUT)" &); $(TIMEOUT_CMD) + # run the tests after building the kernel PHONY += $(KERNEL_IMAGE) $(KERNEL_IMAGE): kernel run: $(KERNEL_IMAGE) - $(Q)$(QEMU_SYSTEM_RUN) > "$(RUN_OUT)" + $(Q)$(TIMEOUT_QEMU_RUN) $(Q)$(REPORT) "$(RUN_OUT)" # re-run the tests from an existing kernel rerun: - $(Q)$(QEMU_SYSTEM_RUN) > "$(RUN_OUT)" + $(Q)$(TIMEOUT_QEMU_RUN) $(Q)$(REPORT) "$(RUN_OUT)" # report with existing test log