Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2219266yba; Mon, 6 May 2019 01:49:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwz5Wh+LlSmIkQDXxJL9ALNsv+ALlkTEsOpZWvUP1sU3GKx82uXjv/V60xRJ2ZdB339ZP37 X-Received: by 2002:a17:902:8bc7:: with SMTP id r7mr7936736plo.74.1557132575352; Mon, 06 May 2019 01:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557132575; cv=none; d=google.com; s=arc-20160816; b=OFH+pVKXNsicfQc2zoy7UVTre+G8NpB/LxQTEsypRwQLZ5VNfIkXWzZ4NJcQS4jzcT dlPuJ7iQHQh3CNyXkMNazJjUoqG/nko3935D3kI5i0Wx4VlAG3GGo40e38sd4YPTAUbs w6a+sgDtMX4CoNau2n4Ys+/hxWMLoI9isTadlCMdzbxrsJ1lLZOCNdyhBGCQvHjwOJU2 GevsgXZUy/YuASns2HFUYIRO7sVVfOzrpyWzXanFzfVg95lLjMZDuLiAgEFHbpByJ5nB FOXEJmkhXKW6V1R3+3FDy6Wzm1VXwN7doqaaT98XFCqQnLdhu0Yk3W5uOu+q3pYldI6t W7sQ== 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=MeIMthOxRJANSArvv5AObvGzpm/HBsUqmQ+gWt5K6h4=; b=r0PXQr1AIv4BGh+jMKULBPcRgZ5M5YPEjClsR/gk9OaYqA9HHZP8KmNyihmaNGRMEF 6WlssFF+FOhUCfC7HgHsqbxQn1zIDbml9PPohcNImR439R8LIBtpDASWgX/bXYgGguQM se0yBs0VRWYK5HBRIddpqQwKE1y0mYcbv97o+3vZC30qpPXpNwI8fYNV/UXrNVLBnXUi DPULqfypbFDsXycFGvsztJ6FMYtAdez5GIK3qtjoIcE3QCwjS7rgdrZjE6RNCy71h+PL LmJJ4hQvKlZGMz1MB8hjilTxeG82Voh0tPqxfoC0jPIUEMQjpxRITr9+SJsVzzfR8GpC Eu4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EnO7STvy; 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 a1si14299452pgh.517.2019.05.06.01.49.16; Mon, 06 May 2019 01:49:35 -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=EnO7STvy; 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 S1726283AbfEFIsX (ORCPT + 99 others); Mon, 6 May 2019 04:48:23 -0400 Received: from mail-oi1-f194.google.com ([209.85.167.194]:34133 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726085AbfEFIsW (ORCPT ); Mon, 6 May 2019 04:48:22 -0400 Received: by mail-oi1-f194.google.com with SMTP id v10so8992140oib.1 for ; Mon, 06 May 2019 01:48:22 -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=MeIMthOxRJANSArvv5AObvGzpm/HBsUqmQ+gWt5K6h4=; b=EnO7STvybywxQ2wAHAyVtfRt84WqWHo207o6kKVYZqrOG/ThSPPoSiv9GKUUU6krNY ZPKR5EsUOem3trEr0yMncM+DcCpGDrZ0FDCeazMNQyv2Pd5e5dQ6QhqISngWLdNZe7mc eawHIqLnKoEL5GaC7a/wL78gStXrV93eaNw5LiiwdvjwLuumdactPs7Xo+O1nOLBrCoI q7RNn20cdCpK2RkkKmjieZ4bqnI6tlUECZmK1Q2Q7GxKkiiHbNI+h1D6YkpszJ0eKle6 VcM9pzRThTNiXpbPMDpK9Er1S78DZpzSLNHj1u5T0r9XUmsbM0Jw6UaKS//SSn1+WQji 72ig== 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=MeIMthOxRJANSArvv5AObvGzpm/HBsUqmQ+gWt5K6h4=; b=pFn9kcwCwWEu6+lIHeC5VMypvfHf0VyEHPuNAgZoE+ZAiIDQ5soca9kd+M92zmxmAr EJnCvkE3kn02h3pziBJumaPNlsarnuRv88M46jrUk8KPXYnfRUhh2FIz/nV47XN4IfJG GWmm9sHvrGZLUD8D0g2rnQ28edJg9XvjJ0YUEHP3/RhXEUnZWEcqpeJgZZclAx+8Ssaz LS7fUcjXHu9DPmR5TKZ0r/wH5jLsQwmMooBW+k7FMj5C9WNwGh43oFFTfl4wN1krrOy6 7XmPDn+qCHpmnbQFh1G4x6+d/j10LceBKTys/3Lvi2lbfoKfDxYAoedIyhLFQ6m33Pyf ZCQw== X-Gm-Message-State: APjAAAUvjiklvLCfhKO/ttTzdxmi4+QLjgE/Tt4M/pHvmNsucPHtWrmw QPWtLrOx4LAOTZiHzfY3BfIelSL2cAuMtlUdnsbCfQ== X-Received: by 2002:aca:a84d:: with SMTP id r74mr402573oie.44.1557132501212; Mon, 06 May 2019 01:48:21 -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: From: Brendan Higgins Date: Mon, 6 May 2019 01:48:09 -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 , 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 Fri, May 3, 2019 at 5:33 AM Logan Gunthorpe wrote: > > > > On 2019-05-03 12:48 a.m., Brendan Higgins wrote: > > 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. > > It is a commonly understood pattern, but I don't think it's what the > code is doing. Try-catch cleans up an entire stack and allows each level > of the stack to apply local cleanup. This implementation simply exits a > thread and has none of that complexity. To me, it seems like an odd > abstraction here as it's really just a test runner that can exit early > (though I haven't seen the follow-up UML implementation). Yeah, that is closer to what the UML specific version does, but that's a conversation for another time. > > I would prefer to see this cleaned up such that the abstraction matches > more what's going on but I don't feel that strongly about it so I'll > leave it up to you to figure out what's best unless other reviewers have > stronger opinions. Cool. Let's revisit this with the follow-up patchset. > > >> > >> [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. > > Adding indirection and function pointers solely for the purpose of > mocking out while testing doesn't sit well with me and I don't think it > should be a pattern that's encouraged. Adding extra complexity like this > to a design to make it unit-testable doesn't seem like something that > makes sense in kernel code. Especially given that indirect calls are > more expensive in the age of spectre. Indirection is a pretty common method to make something mockable or fakeable. Nevertheless, probably an easier discussion to have once we have some examples to discuss. > > Also, mocking these particular functions seems like it's an artifact of > how you've designed the try/catch abstraction. If the abstraction was > more around an abort-able test runner then it doesn't make sense to need > to mock out the abort/fail functions as you will be testing overly > generic features of something that don't seem necessary to the > implementation. > > >> > >> [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. > > Yes, remove them now and add them back when you use them in follow-up > patches. If reviewers find problems with the follow-up patches or have a > better suggestion on how to do what ever it is you are doing, then you > just have this unnecessary code and there's wasted developer time and > review bandwidth that will need to be spent cleaning it up. Fair enough. Next patchset will have the remaining unused indirection you pointed out removed. Thanks!