Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1792573pxy; Thu, 29 Apr 2021 14:56:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrhynSVl+ky6+kIjEOCt6V93g05xVhy/FCUnjzFEQLi6C73wK/qDld4hXEvkcdgwnj7Hkb X-Received: by 2002:a17:906:a0c6:: with SMTP id bh6mr607825ejb.359.1619733379566; Thu, 29 Apr 2021 14:56:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619733379; cv=none; d=google.com; s=arc-20160816; b=VR0fEPyyezJOQiIcmPrvSzblJgVdltD8EFKQU3nwC2XWKmHi9wQqLNbJ/Gm+9f09TL HCQhJttuvDUnPT6Mn//KfzVWkHdCiYTihc77hQgEzfu0U1NteRLMsD6C+1cbPnhu9P6A WXOqvpSnCWEvRDDGY6ABUvNQkN1rSs8M2HxE4EWhwpXSY7cn/TkZYKnn7B9xIPykixF4 VGxxQer1fO0SOgf6DAqGxpBhKlui9nYq2Qa+kIP9GqaYkP0BT8bUzV1JI5pdqhlkC9qm Rt0nbRSgn1wEgJIVqn2k1Nt1MMK4axKN8TV9mmdUwh5GFMDOd2J7yH0Vbx1+J+jQK2vP bsLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=EjH+o6UjzQ/Am12P1LLl5WjEAhv3JEtTZEWuxrZg3O0=; b=TPRyKhuVICyIiHp/fS3sqofUp5s+c5vgeaCiENn1TDkbK/8uhov0QZzSQrZoFczLy3 cENXtA9ouMNQCbcBhSu0/ENjeqBvyLAPKiU6riRnlF/V4kcqFcSyVSCjs4pPLQMf8H4u Pd5HGgmgiTl5HOVtzdf+LSEBRQy2UI6HfSna6NRWJympHEfL9kGnlKXY3I/8hDuWbh4d HejdcQyCflLVOBeIsu7n4yMPNRltWcHNqNP8kHm943CMN/Kk7/jQ+Yz2dGLwOg98Md1o GjshzSGmC6Zg2EuOCAUn+GAlNQVfClkAEjHgeZv+c4YYs5jTMCM3vEI492zwH24XscFE 93lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ha119dA0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s2si4270670edr.28.2021.04.29.14.55.56; Thu, 29 Apr 2021 14:56:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ha119dA0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237254AbhD2Vxt (ORCPT + 99 others); Thu, 29 Apr 2021 17:53:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235732AbhD2Vxs (ORCPT ); Thu, 29 Apr 2021 17:53:48 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F38DDC06138D for ; Thu, 29 Apr 2021 14:53:00 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id a36so67469078ljq.8 for ; Thu, 29 Apr 2021 14:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EjH+o6UjzQ/Am12P1LLl5WjEAhv3JEtTZEWuxrZg3O0=; b=Ha119dA0JNsUpBFRKqGtG4fA4JtuHTwk8w90di3c/eFv5DMhUhzO57V9YFQxD4FY5K n4Fe5wb3RYCw45myOLUdo03vx35EIK+pOxiKRb+Ayw7IR6G1nlz52lsoP9A87rRrLNr7 mx6/ijMStfVsrI+xm5w54lnWMAQW1+TDC5SdURI60f4mSfFmwZVM7SVxl/Kjw2Pa6deJ Zq06mpnFSUmlAcgRS0qxLJ1yC8mZMiy8BiVrQc09cbBgfk9j2Mqbtm+F8hiA0/VSrZ0L cGMHC6wSiS9mLjtLHxpWPUTJm6W1X3nfw33//OOz4L2TsSL5o161R/vkTJvG36xqhULu M+4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EjH+o6UjzQ/Am12P1LLl5WjEAhv3JEtTZEWuxrZg3O0=; b=QY8gYtiy+EX3Kx8qZqu55uN3JPlb9tMA+YuxRGvrZ6ID0Vo+lNkO/N+vqKawoT0PCf od36f84sT83bnz3P3rfBoexe0vUgPD2+6Aen3LFh4qCP3tWXDBzhhVCDJz0UkiKrwMh8 vcBN/6bAXZQOxNQIlelOeKaxMsy8MMxccXRkGpeCdJxKPpTiccbTZ4NxgVp2YXjz9q+3 Vsn+KJ3pJBDLVjm8mZajJWmA/TQJ0gJBZbbVgyLiJzKe4bp4V/C50CMB18I2oaTdnA9W amag6+RIz5mGqvDMOdhZowld++TKUW+t6eZqF5/3Rz1pu2KisydlXW3gnf66g/cv75MX eY8g== X-Gm-Message-State: AOAM531KDC2IdBjJxdZlDy/5nj4a7omr9ohxjLeULI8cosMspYyR/Ao0 O6x5IwHxk9qy01Vpk9o+kdN9cj+vuiAldNRWJaZSTA== X-Received: by 2002:a2e:9357:: with SMTP id m23mr1266773ljh.446.1619733179148; Thu, 29 Apr 2021 14:52:59 -0700 (PDT) MIME-Version: 1.0 References: <20210429205109.2847831-1-brendanhiggins@google.com> <20210429205109.2847831-2-brendanhiggins@google.com> In-Reply-To: <20210429205109.2847831-2-brendanhiggins@google.com> From: Daniel Latypov Date: Thu, 29 Apr 2021 14:52:48 -0700 Message-ID: Subject: Re: [RFC v2 1/4] kunit: Add 'kunit_shutdown' option To: Brendan Higgins Cc: shuah@kernel.org, David Gow , "open list:KERNEL SELFTEST FRAMEWORK" , KUnit Development , Linux Kernel Mailing List , Jonathan Corbet , linux-doc@vger.kernel.org, Stephen Boyd , Kees Cook , frowand.list@gmail.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 29, 2021 at 1:51 PM Brendan Higgins wrote: > > From: David Gow > > Add a new kernel command-line option, 'kunit_shutdown', which allows the > user to specify that the kernel poweroff, halt, or reboot after > completing all KUnit tests; this is very handy for running KUnit tests > on UML or a VM so that the UML/VM process exits cleanly immediately > after running all tests without needing a special initramfs. > > Signed-off-by: David Gow > Signed-off-by: Brendan Higgins > Reviewed-by: Stephen Boyd Tested-By: Daniel Latypov Testing this out, I think this also helps fix coverage on UML. I used to have to hack in something like this: diff --git a/arch/um/os-Linux/util.c b/arch/um/os-Linux/util.c index 07327425d06e..e13763faedd9 100644 --- a/arch/um/os-Linux/util.c +++ b/arch/um/os-Linux/util.c @@ -146,7 +146,7 @@ void os_dump_core(void) while ((pid = waitpid(-1, NULL, WNOHANG | __WALL)) > 0) os_kill_ptraced_process(pid, 0); - uml_abort(); + exit(127); } void um_early_printk(const char *s, unsigned int n) And afaict, this patch removes the need to do so. (But I made a few mistakes when initially trying to test that out, so I'm not 100% certain I didn't make another). > --- > lib/kunit/executor.c | 20 ++++++++++++++++++++ > tools/testing/kunit/kunit_kernel.py | 2 +- > tools/testing/kunit/kunit_parser.py | 2 +- > 3 files changed, 22 insertions(+), 2 deletions(-) > > diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c > index 15832ed446685..7db619624437c 100644 > --- a/lib/kunit/executor.c > +++ b/lib/kunit/executor.c > @@ -1,5 +1,6 @@ > // SPDX-License-Identifier: GPL-2.0 > > +#include > #include > #include > #include > @@ -18,6 +19,9 @@ module_param(filter_glob, charp, 0); > MODULE_PARM_DESC(filter_glob, > "Filter which KUnit test suites run at boot-time, e.g. list*"); > > +static char *kunit_shutdown; > +core_param(kunit_shutdown, kunit_shutdown, charp, 0644); > + > static struct kunit_suite * const * > kunit_filter_subsuite(struct kunit_suite * const * const subsuite) > { > @@ -82,6 +86,20 @@ static struct suite_set kunit_filter_suites(void) > return filtered; > } > > +static void kunit_handle_shutdown(void) > +{ > + if (!kunit_shutdown) > + return; > + > + if (!strcmp(kunit_shutdown, "poweroff")) > + kernel_power_off(); > + else if (!strcmp(kunit_shutdown, "halt")) > + kernel_halt(); > + else if (!strcmp(kunit_shutdown, "reboot")) > + kernel_restart(NULL); > + > +} > + > static void kunit_print_tap_header(struct suite_set *suite_set) > { > struct kunit_suite * const * const *suites, * const *subsuite; > @@ -112,6 +130,8 @@ int kunit_run_all_tests(void) > kfree(suite_set.start); > } > > + kunit_handle_shutdown(); > + > return 0; > } > > diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py > index f309a33256cd3..7d5b77967d48f 100644 > --- a/tools/testing/kunit/kunit_kernel.py > +++ b/tools/testing/kunit/kunit_kernel.py > @@ -206,7 +206,7 @@ class LinuxSourceTree(object): > def run_kernel(self, args=None, build_dir='', filter_glob='', timeout=None) -> Iterator[str]: > if not args: > args = [] > - args.extend(['mem=1G', 'console=tty']) > + args.extend(['mem=1G', 'console=tty','kunit_shutdown=halt']) > if filter_glob: > args.append('kunit.filter_glob='+filter_glob) > self._ops.linux_bin(args, timeout, build_dir) > diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py > index e8bcc139702e2..8d8d4d70b39dd 100644 > --- a/tools/testing/kunit/kunit_parser.py > +++ b/tools/testing/kunit/kunit_parser.py > @@ -49,7 +49,7 @@ class TestStatus(Enum): > > kunit_start_re = re.compile(r'TAP version [0-9]+$') > kunit_end_re = re.compile('(List of all partitions:|' > - 'Kernel panic - not syncing: VFS:)') > + 'Kernel panic - not syncing: VFS:|reboot: System halted)') > > def isolate_kunit_output(kernel_output) -> Iterator[str]: > started = False > -- > 2.31.1.498.g6c1eba8ee3d-goog >