Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp242942imp; Tue, 19 Feb 2019 22:45:39 -0800 (PST) X-Google-Smtp-Source: AHgI3IZaeCySyHlCXOryeCPcB942wd9fjQTF5IdXC9zHvEF5JGD8Al2vfnK15fp/sYJGcStjLYbi X-Received: by 2002:a62:221a:: with SMTP id i26mr32952183pfi.174.1550645139018; Tue, 19 Feb 2019 22:45:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550645139; cv=none; d=google.com; s=arc-20160816; b=fwwgQoCqr2sOjGbBbVifkvywiCwtPsD0Lhyb2OWuogDh9Guz9Qgjhks2TNbZ2Y74Ly 15BmWK2HmdQOX7mk57uJEqWnRHB1OhlkmpBBOK+OoRd66yAWpnYkJlujTJJoGd8C+2Tu 5eXbfon9H2nT0R22y4W6gXZeXpNt170oiGWv+nu0Wbcf0tYzMyi+l2rtUzguMsr9XMIF KcDzwo3u4cjWb6ZP+it2rdU3+B6kmNqFZYROrOAIx1anjhUw0g3drnlr3r8WI3EJcV47 +Du415vSZEFuvS8Q7TwGHsRUmahny9eZcPza3AUB69M9C62ViK2pkAl3sCAqcebxF12n ZaIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=LODZetcs0AnT93QYQC0UK8k2tg9s5tX3hMm2xNga27I=; b=zqKp3CRwYRKWSwff8O2lvZWWX7kZCINM56eTZ/He1azh6mU3jr4muR82MiCFaeE4wS +5luwlSpevalXCecUTKo8kMDxRpQVXg8O7F0gjnJhs6gYVzWYD+1fNjuO3pyb65Y3lxT tmi8kmQZ34JQoMJySsWuobH2epnmiIclEp0LU6gj1yt4S+DE8df2Tk/IIGti87Drnr1n ASrOoD3GoKIBCvs6FlFWpzhx8fucwXtP0ciUHeAqQAcbRDLFqRC2Px7RIlpFvPQHHVIK dpL1CDLe9dBLTeO8inMeOa9zAIBqEGGTzbHiV6PC5XHKi0ztUGg5hCxTLefjVAw24Bne 3Wkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kuCs+nQ8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x64si18211479pfx.87.2019.02.19.22.45.24; Tue, 19 Feb 2019 22:45:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kuCs+nQ8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730497AbfBTGo2 (ORCPT + 99 others); Wed, 20 Feb 2019 01:44:28 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:38376 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725890AbfBTGo2 (ORCPT ); Wed, 20 Feb 2019 01:44:28 -0500 Received: by mail-pg1-f195.google.com with SMTP id m2so9101639pgl.5; Tue, 19 Feb 2019 22:44:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=LODZetcs0AnT93QYQC0UK8k2tg9s5tX3hMm2xNga27I=; b=kuCs+nQ8OpBtGvxxn3MOBEVS0ZXl2jxhX6B7xop63kucnr/h6FRNrWni4/vUjsEFkL cIiISlOypm7kpWLDcoM0QDLRfWtAMbipPeshkasB38UpWyKg8wnIWQKtNAhKClu5DeHc LlHCoiIb095x6B9b0bAkO3WvWDgzQCP3GEX1ts2Qgb8w+MeASdpx/Semtt1qqNYRWWxO txiXo0ObyFyknmeZjeut1sP4UbBU7igHfZy5ut3gmi9oapA64ETjmol+7DCdL+HwNdoa bIjqKPSKMPt7Ga+XmeNpQiT4Sc9xVrDWHoB09N+cUshH2e0kJ0WmGaou5RvS+78wABkX mvOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=LODZetcs0AnT93QYQC0UK8k2tg9s5tX3hMm2xNga27I=; b=I+xVRXmWLrxvZzmKaU//R5Np7Ufqe0XTEegLmNTpDfHV/bcjFFgziVlokqJOit+Ej/ 7CBk3L7jMkytWe5jql0LWBzKE8Dw3qYrVE/leSs/k8sKqyPqajHgOeaG/fUIyGSPwh9L +IGWK0DRynv2lnRXub+yir0gymYAsQAYK9tfhJFzjwAw2KruIHAqrx+K7lShPz4UmLZQ icquJW41Nh9Ka12C3sBQ4DCaMqFAWTHxIAr6WCz9JkcPDrP0ZSeBzsVzuDchnVTBe7X9 L6lXpXFktNJHYndmEOleqzGgZte3IGTP5djs9Kp0oViaAIkvJU47bex36a1L3YL3PG/H ImlA== X-Gm-Message-State: AHQUAuZMCI7FitygYXMNI4U+vhlMDB10049N6FLhg6l+FLeTqXgX25DY GFIhZXn9NskHA1Afftiu230= X-Received: by 2002:a63:7444:: with SMTP id e4mr4762824pgn.398.1550645067019; Tue, 19 Feb 2019 22:44:27 -0800 (PST) Received: from [192.168.1.70] (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id s21sm35375176pfk.133.2019.02.19.22.44.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 22:44:26 -0800 (PST) Subject: Re: [RFC v4 08/17] kunit: test: add support for test abort To: Brendan Higgins Cc: Kees Cook , Luis Chamberlain , shuah@kernel.org, Rob Herring , Kieran Bingham , Greg KH , Joel Stanley , Michael Ellerman , Joe Perches , brakmo@fb.com, Steven Rostedt , "Bird, Timothy" , Kevin Hilman , Julia Lawall , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, Linux Kernel Mailing List , Jeff Dike , Richard Weinberger , linux-um@lists.infradead.org, Daniel Vetter , dri-devel , Dan Williams , linux-nvdimm , Knut Omang , devicetree , Petr Mladek , Sasha Levin , Amir Goldstein , dan.carpenter@oracle.com, wfg@linux.intel.com References: <20190214213729.21702-1-brendanhiggins@google.com> <20190214213729.21702-9-brendanhiggins@google.com> From: Frank Rowand Message-ID: <0124ed28-466c-e954-ddde-495419630a9f@gmail.com> Date: Tue, 19 Feb 2019 22:44:23 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/19/19 7:39 PM, Brendan Higgins wrote: > On Mon, Feb 18, 2019 at 11:52 AM Frank Rowand wrote: >> >> On 2/14/19 1:37 PM, Brendan Higgins wrote: >>> Add support for aborting/bailing out of test cases. Needed for >>> implementing assertions. >>> >>> Signed-off-by: Brendan Higgins >>> --- >>> Changes Since Last Version >>> - This patch is new introducing a new cross-architecture way to abort >>> out of a test case (needed for KUNIT_ASSERT_*, see next patch for >>> details). >>> - On a side note, this is not a complete replacement for the UML abort >>> mechanism, but covers the majority of necessary functionality. UML >>> architecture specific featurs have been dropped from the initial >>> patchset. >>> --- >>> include/kunit/test.h | 24 +++++ >>> kunit/Makefile | 3 +- >>> kunit/test-test.c | 127 ++++++++++++++++++++++++++ >>> kunit/test.c | 208 +++++++++++++++++++++++++++++++++++++++++-- >>> 4 files changed, 353 insertions(+), 9 deletions(-) >>> create mode 100644 kunit/test-test.c >> >> < snip > >> >>> diff --git a/kunit/test.c b/kunit/test.c >>> index d18c50d5ed671..6e5244642ab07 100644 >>> --- a/kunit/test.c >>> +++ b/kunit/test.c >>> @@ -6,9 +6,9 @@ >>> * Author: Brendan Higgins >>> */ >>> >>> -#include >>> #include >>> -#include >>> +#include >>> +#include >>> #include >>> >>> static bool kunit_get_success(struct kunit *test) >>> @@ -32,6 +32,27 @@ static void kunit_set_success(struct kunit *test, bool success) >>> spin_unlock_irqrestore(&test->lock, flags); >>> } >>> >>> +static bool kunit_get_death_test(struct kunit *test) >>> +{ >>> + unsigned long flags; >>> + bool death_test; >>> + >>> + spin_lock_irqsave(&test->lock, flags); >>> + death_test = test->death_test; >>> + spin_unlock_irqrestore(&test->lock, flags); >>> + >>> + return death_test; >>> +} >>> + >>> +static void kunit_set_death_test(struct kunit *test, bool death_test) >>> +{ >>> + unsigned long flags; >>> + >>> + spin_lock_irqsave(&test->lock, flags); >>> + test->death_test = death_test; >>> + spin_unlock_irqrestore(&test->lock, flags); >>> +} >>> + >>> static int kunit_vprintk_emit(const struct kunit *test, >>> int level, >>> const char *fmt, >>> @@ -70,13 +91,29 @@ static void kunit_fail(struct kunit *test, struct kunit_stream *stream) >>> stream->commit(stream); >>> } >>> >>> +static void __noreturn kunit_abort(struct kunit *test) >>> +{ >>> + kunit_set_death_test(test, true); >>> + >>> + test->try_catch.throw(&test->try_catch); >>> + >>> + /* >>> + * Throw could not abort from test. >>> + */ >>> + kunit_err(test, "Throw could not abort from test!"); >>> + show_stack(NULL, NULL); >>> + BUG(); >> >> kunit_abort() is what will be call as the result of an assert failure. > > Yep. Does that need clarified somewhere. >> >> BUG(), which is a panic, which is crashing the system is not acceptable >> in the Linux kernel. You will just annoy Linus if you submit this. > > Sorry, I thought this was an acceptable use case since, a) this should > never be compiled in a production kernel, b) we are in a pretty bad, > unpredictable state if we get here and keep going. I think you might > have said elsewhere that you think "a" is not valid? In any case, I > can replace this with a WARN, would that be acceptable? A WARN may or may not make sense, depending on the context. It may be sufficient to simply report a test failure (as in the old version of case (2) below. Answers to "a)" and "b)": a) it might be in a production kernel a') it is not acceptable in my development kernel either b) No. You don't crash a developer's kernel either unless it is required to avoid data corruption. b') And you can not do replacements like: (1) in of_unittest_check_tree_linkage() ----- old ----- if (!of_root) return; ----- new ----- KUNIT_ASSERT_NOT_ERR_OR_NULL(test, of_root); (2) in of_unittest_property_string() ----- old ----- /* of_property_read_string_index() tests */ rc = of_property_read_string_index(np, "string-property", 0, strings); unittest(rc == 0 && !strcmp(strings[0], "foobar"), "of_property_read_string_index() failure; rc=%i\n", rc); ----- new ----- /* of_property_read_string_index() tests */ rc = of_property_read_string_index(np, "string-property", 0, strings); KUNIT_ASSERT_EQ(test, rc, 0); KUNIT_EXPECT_STREQ(test, strings[0], "foobar"); If a test fails, that is no reason to abort testing. The remainder of the unit tests can still run. There may be cascading failures, but that is ok.