Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp218340yba; Fri, 3 May 2019 00:00:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMrFuEHHT6/imEGwHrB2DH3pUV522FmreggiUm7p8upybVH2lb+hbYwmbUvGu49WBDjvWH X-Received: by 2002:a63:ef53:: with SMTP id c19mr8633600pgk.120.1556866841459; Fri, 03 May 2019 00:00:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556866841; cv=none; d=google.com; s=arc-20160816; b=sKUt8Hxtu2qp3nhklZaMkux7xK4sF2GApmsItpy3pZKHMjlLJG6pe0qwguxirjviCB 24etFp7NTSe7kN7TtwvPlI0vE5zby0Lq1yqXVNngQEl93l287QPyV6c9YoPysc3FbhQV FUuR5qAJnNWo5Ogjjr+CtxWcGHI3zIjhoNHz488+Cmjf7J0VUgM1Ovw4DZAh8r82qUti xDLqtt1vTcfcSPeCoUZOqOdcZyQSIeRcgt/jxu+FGs2K5AAQcGgyOY8/gTcP+E7U6GQG uXrt5cc31rEsm7K3ozQnMfDGo3bxsmj3T6mKjy9uz5TTXN3K5tRLBRhbnVpWoQPf2xww qg1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=B/vgrL6mFJjbubEtdk9xy4dCVOTfDfNigFjtHMJz6Hg=; b=kGbwk6Z5GETQZaySdHUUTqnDpu1dhAw/flapfU5eMa0+KxugDOMcjGclN/GdJuyxNb jsGg4N4qpF9P4oTXw8yY0GdCp7pPtzesY8Dvf0zxuWu+JBjV0YycEcgQ6MKHukpL0CyZ 8n58cymSs40FDVh+BBza5GFiDXJHuo8TN5i7xN7E7MnqtJZS+86pxDz55PBalTSg9Rye suf9nxGnh4NKrepIVNZCThTOBV5hdV7zVzoCLDErHB65Dec8r0EILRp8vudWmdi4FzJr bpAPxG8GJCVLmqasTd99+pNC3HiW8zZEqI2hUyKRSwjrbkP24bESK3YPqpEj9DZ3BUPU 16YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=BWFlXcxd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i29si55366pgl.243.2019.05.03.00.00.25; Fri, 03 May 2019 00:00:41 -0700 (PDT) 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=@google.com header.s=20161025 header.b=BWFlXcxd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726963AbfECGsn (ORCPT + 99 others); Fri, 3 May 2019 02:48:43 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:33529 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725804AbfECGsn (ORCPT ); Fri, 3 May 2019 02:48:43 -0400 Received: by mail-ot1-f67.google.com with SMTP id s11so4428504otp.0 for ; Thu, 02 May 2019 23:48:42 -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=B/vgrL6mFJjbubEtdk9xy4dCVOTfDfNigFjtHMJz6Hg=; b=BWFlXcxdKPCg7HeydPM9nymqdJaKu5v0FhgYXNSsx2wC9FgZ6BWl9owIL4tp34RHzV 0O2CI2x3Gf2dd6TLPVl+UCJIuR6ugbJgNiJ5ahKuIYIQ+IA6TXvM7s76WSfiT5u9UOjU BAmfjJWmXXmLvLfanifCHtnmcT9eQgxYIv2/nMEQ/h+Jh7SQ4Wq8KAXXS2vmQSRvUjv3 lY5jQIBJ2XBRYHgExTQbP6djFMEjOYOf+5XNpdQj+/aplIkBZPZ/tX1ygb8a9ZyYzeEG YiV5A2XgkK4p5mdxg0WTkGqiAuXfNRl77gHQcoJRclt/bqm0TtNUGFDJL3udF8SKeGs/ dUEg== 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=B/vgrL6mFJjbubEtdk9xy4dCVOTfDfNigFjtHMJz6Hg=; b=e3bf3WTREKKvKbtDlVuwdA2E9ohecjExJjnOBY9qgZ4wOJf/BXW7OKdFnbT3N1Ahip 8DAJcSo/ybcaaxk2jxIijbqS/3eC0eTPUhYgI6hY/2OcsPUI2TA+t3h1KegXrGoaV+07 ctY2VWB+tkLvlQwwWzXGhJ86m8Y3GARsxpxQrGcl2czAuOJxMvgwB2zRe8ghxRPvEulh zmC6atgqxK5fBTTGrfYRrFFIkOclFcilkNp3dHvtX5Ixz7apNnvnDjvc7Q1vaZwgGZuW Y/glIQoKNa4NfKmXLKZyVemFO8Pcw102Kx8RDR+nTFpVd5UQppOdSpVSveNjSfF248KP ZvxQ== X-Gm-Message-State: APjAAAVBrEvlV3vgQBhpxVzTo/M6e9lXq0229YRbv8TxZzS2//fKwlWh J9T7RuOW/jkG1HoW+nxjGfufCQY02w2FjA57NcB/nQ== X-Received: by 2002:a9d:5cc3:: with SMTP id r3mr5382470oti.338.1556866121691; Thu, 02 May 2019 23:48:41 -0700 (PDT) MIME-Version: 1.0 References: <20190501230126.229218-1-brendanhiggins@google.com> <20190501230126.229218-9-brendanhiggins@google.com> <0a605543-477a-1854-eb35-6e586606889b@deltatee.com> In-Reply-To: <0a605543-477a-1854-eb35-6e586606889b@deltatee.com> From: Brendan Higgins Date: Thu, 2 May 2019 23:48:30 -0700 Message-ID: Subject: Re: [PATCH v2 08/17] kunit: test: add support for test abort To: Logan Gunthorpe Cc: Frank Rowand , Greg KH , Kees Cook , Kieran Bingham , Luis Chamberlain , Rob Herring , Stephen Boyd , shuah@kernel.org, devicetree , dri-devel , kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, Linux Kernel Mailing List , linux-kselftest@vger.kernel.org, linux-nvdimm , linux-um@lists.infradead.org, Sasha Levin , "Bird, Timothy" , Amir Goldstein , Dan Carpenter , Dan Williams , Daniel Vetter , Jeff Dike , Joel Stanley , Julia Lawall , Kevin Hilman , Knut Omang , Michael Ellerman , Petr Mladek , Richard Weinberger , David Rientjes , Steven Rostedt , wfg@linux.intel.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 2, 2019 at 8:15 PM Logan Gunthorpe wrote: > > > > On 2019-05-01 5:01 p.m., Brendan Higgins wrote: > > +/* > > + * struct kunit_try_catch - provides a generic way to run code which might fail. > > + * @context: used to pass user data to the try and catch functions. > > + * > > + * kunit_try_catch provides a generic, architecture independent way to execute > > + * an arbitrary function of type kunit_try_catch_func_t which may bail out by > > + * calling kunit_try_catch_throw(). If kunit_try_catch_throw() is called, @try > > + * is stopped at the site of invocation and @catch is catch is called. > > I found some of the C++ comparisons in this series a bit distasteful but > wasn't going to say anything until I saw the try catch.... But looking > into the implementation it's just a thread that can exit early which > seems fine to me. Just a poor choice of name I guess... Guilty as charged (I have a long history with C++, sorry). Would you prefer I changed the name? I just figured that try-catch is a commonly understood pattern that describes exactly what I am doing. > > [snip] > > > +static void __noreturn kunit_abort(struct kunit *test) > > +{ > > + kunit_set_death_test(test, true); > > + > > + kunit_try_catch_throw(&test->try_catch); > > + > > + /* > > + * Throw could not abort from test. > > + * > > + * XXX: we should never reach this line! As kunit_try_catch_throw is > > + * marked __noreturn. > > + */ > > + WARN_ONCE(true, "Throw could not abort from test!\n"); > > +} > > + > > int kunit_init_test(struct kunit *test, const char *name) > > { > > spin_lock_init(&test->lock); > > @@ -77,6 +103,7 @@ int kunit_init_test(struct kunit *test, const char *name) > > test->name = name; > > test->vprintk = kunit_vprintk; > > test->fail = kunit_fail; > > + test->abort = kunit_abort; > > There are a number of these function pointers which seem to be pointless > to me as you only ever set them to one function. Just call the function > directly. As it is, it is an unnecessary indirection for someone reading > the code. If and when you have multiple implementations of the function > then add the pointer. Don't assume you're going to need it later on and > add all this maintenance burden if you never use it.. Ah, yes, Frank (and probably others) previously asked me to remove unnecessary method pointers; I removed all the totally unused ones. As for these, I don't use them in this patchset, but I use them in my patchsets that will follow up this one. These in particular are present so that they can be mocked out for testing. > > [snip] > > > +void kunit_generic_try_catch_init(struct kunit_try_catch *try_catch) > > +{ > > + try_catch->run = kunit_generic_run_try_catch; > > + try_catch->throw = kunit_generic_throw; > > +} > > Same here. There's only one implementation of try_catch and I can't > really see any sensible justification for another implementation. Even > if there is, add the indirection when the second implementation is > added. This isn't C++ and we don't need to make everything a "method". These methods are for a UML specific implementation in a follow up patchset, which is needed for some features like crash recovery, death tests, and removes dependence on kthreads. I know this probably sounds like premature complexity. Arguably it is in hindsight, but I wrote those features before I pulled out these interfaces (they were actually both originally in this patchset, but I dropped them to make this patchset easier to review). I can remove these methods and add them back in when I actually use them in the follow up patchsets if you prefer. Thanks!