Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2175977pxb; Fri, 25 Mar 2022 12:26:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZXBlI4D11N5cKqEa86icIYqiEaOoGJU8Th+/UqvCe7n+6NnExtQ3hdRVtULIaeFKTgi0W X-Received: by 2002:a63:1a0c:0:b0:382:1ced:62c0 with SMTP id a12-20020a631a0c000000b003821ced62c0mr892298pga.36.1648236418263; Fri, 25 Mar 2022 12:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648236418; cv=none; d=google.com; s=arc-20160816; b=k9YJ/aU52NwvDM3owL4R3v3zWzkaavt5/ITT15HtwCfqorcBox+ObD1tKb0DgSMUPr ZT6QY+1Xorex2t8VHcXXMj89BrabD5IM+h9nYv9xDq+s6/WTFrM61T/W86Lge/3Ny0Kh qvTiJWBZSY5S8fErZO+6N6yNQbYdKZOSdxBSO1t/3Rf27mafy/FSYoc2jFRrIi/AW+Ww pviZc7m4ZJejg56aBKUY+W7af9E/2PiZVByYai8yYK0cCElHS0W5TxbdHko9wv5xWM1v 1vR1H/59CAjDh4W2Ho/33BFrhPwFCr9H3XtyOHWR9wd8k8n6FR4U3diLafoNzzF0DzR5 RmtQ== 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=Ki2n6Qz/XFIPEOMiE4aANqyu6w6m1Klwn+ORu/krnhM=; b=b5J41Dlsl8R2RVH1cLd6Uz6GUHMd4vBf2BoNgnw131fdCiYruIJ1yJFNQqixLPeXV/ JpRRyNe9MzXsCtXCKoruRqlUiyiD64WdDL9RhFYahqClgoOmHadsdZMcBZ8kdD6/Krhk 8a804b1kDKRjYZY4Wh2VPqeliQzwghObsW5jv4Icz4LmsppwIIC46u+VbPfI1/WAIn9d QOp8VO4Ul4KtsYk9sF1XAimM+F1IV5ycy31NJefc3PQd41NRcuiLj+FeblD3O667UEcX tOjJhZYRpIaFypNgFOUV0nKe8HJbo0ZXZ+Qw4bA3Aek8LesfGM3DGcVtIi0mGQpprShw 6Znw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IzZK7Aq+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l1-20020a656801000000b003816043eef3si3025349pgt.232.2022.03.25.12.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 12:26:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IzZK7Aq+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6EC122AFA31; Fri, 25 Mar 2022 11:36:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345602AbiCWXxg (ORCPT + 99 others); Wed, 23 Mar 2022 19:53:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346660AbiCWXxH (ORCPT ); Wed, 23 Mar 2022 19:53:07 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CBD93FD86 for ; Wed, 23 Mar 2022 16:51:36 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id r23so3768623edb.0 for ; Wed, 23 Mar 2022 16:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ki2n6Qz/XFIPEOMiE4aANqyu6w6m1Klwn+ORu/krnhM=; b=IzZK7Aq+TzUq3EtZ+DoEiDDVUaz99N2AMqhG5DFFxKXnbDEE/G7/AOXa1+qUGXUz2r GJ1gYUxTgPhGa6uZqJhOWjNsUO43RS0yZJBk4ka5t7VSgSgVe+Qi0MlX9iCHk0++cNSM vQqr/WCOA542elAvDQwEyK6O4cIPjFM8KkNlEjnqZBOFkKfnD7Nj15RsvBsvt8vZINGM neMIXCME2yTVZ/EzyFj+2ViIitW0aS7mmbaJpF7HkcBOSbq6w19JPa/f9+cPu5GVi4mN bZ/en89/of+2pOtWluF73BKiNWGwqoZPbuHTHAUyaNQmwM9KVcE46msF9886C2Y6cTc7 77GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ki2n6Qz/XFIPEOMiE4aANqyu6w6m1Klwn+ORu/krnhM=; b=V9yf6w7Gbt3IzB6nXndnTvRpQfJ6/9wCrPxC/XpOGGora1tLE/QMQogfcQ8AmEuWbp VwUmla+wWHODekvCPdJC2b6mQatct4FIPAW9qCfRtDmuPNH/lQGKiyWHJz6NKghB1WeG 63IvfXWuEK3ACcY5IEibx9x0fkacvb00kct1FZz0FMdHnFrvvn/gHDDVFLDMiuJ2CqvE lq9Y42zNEqFRwmP0GiCMJnQ0IfKZA1W/PdnsudwyI4JeJ1roZhmSUzIlZVSkMJfbtzXg BuCqWCdJM4DG4XeMrOAfvf0ztkbAmjW1VU7Oam0NfUzg2jrbIYtxH9+qVpIAecPJLFUN gkEA== X-Gm-Message-State: AOAM531WD8Y9aF/NXEdFP5hWk35dVPII3WUSx5sGxfhoR9UsozHTZGIe PN6zTXePwjn1YYYPFLKgKAUPwwgkMQuyKXVHM925Ow== X-Received: by 2002:a05:6402:4388:b0:419:443d:b4e9 with SMTP id o8-20020a056402438800b00419443db4e9mr3409290edc.149.1648079494776; Wed, 23 Mar 2022 16:51:34 -0700 (PDT) MIME-Version: 1.0 References: <20220316024432.1454366-1-dlatypov@google.com> In-Reply-To: From: Brendan Higgins Date: Wed, 23 Mar 2022 19:51:23 -0400 Message-ID: Subject: Re: [PATCH] kunit: split resource API from test.h into new resource.h To: Daniel Latypov Cc: David Gow , Linux Kernel Mailing List , KUnit Development , "open list:KERNEL SELFTEST FRAMEWORK" , Shuah Khan Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 On Wed, Mar 16, 2022 at 12:19 PM 'Daniel Latypov' via KUnit Development wrote: > > On Wed, Mar 16, 2022 at 12:41 AM David Gow wrote: > > > > On Wed, Mar 16, 2022 at 10:44 AM Daniel Latypov wrote: > > > > > > Background: > > > Currently, a reader looking at kunit/test.h will find the file is quite > > > long, and the first meaty comment is a doc comment about struct > > > kunit_resource. > > > > > > Most users will not ever use the KUnit resource API directly. > > > They'll use kunit_kmalloc() and friends, or decide it's simpler to do > > > cleanups via labels (it often can be) instead of figuring out how to use > > > the API. > > > > > > > A depressing (but probably not untrue) thought. I think that, even if > > I'm not sure it's that depressing. > Without some compiler support (e.g. GCC's `cleanup`), I can see there > being a number of one-off things that don't warrant formalizing into a > resource. > > More detail: > It works OK when there's one pointer parameter, e.g. [1], but I feel > like you'd normally need to capture at least one more local variable. > So then you need to define a new struct to hold all the values, which > is where I'd draw the line personally. > > [1] https://elixir.bootlin.com/linux/v5.17-rc8/source/lib/kunit/executor_test.c#L182 > > > most people were to use the resource API, having it in test.h makes it > > harder, as having the resource functions separate makes it easier to > > understand as well. > > > > > It's also logically separate from everything else in test.h. > > > Removing it from the file doesn't cause any compilation errors (since > > > struct kunit has `struct list_head resources` to store them). > > > > > > This commit: > > > Let's move it into a kunit/resource.h file and give it a separate page > > > in the docs, kunit/api/resource.rst. > > > > Yay! This makes a lot of sense to me, as I've wasted a lot of time > > scrolling through test.h. > > > > > > > > We include resource.h at the bottom of test.h since > > > * don't want to force existing users to add a new include if they use the API > > > * it accesses `lock` inside `struct kunit` in a inline func > > > * so we can't just forward declare, and the alternatives require > > > uninlining the func, adding hepers to lock/unlock, or other more > > > invasive changes. > > > > I don't like this, but still think it's an improvement on what we have > > now. Ultimately, I think adding helpers to lock/unlock or similar and > > Yes, I can see us maybe needing this in the future. > Right now, outside of test.c, there's only one callsite for each (in > resource.h). Another alternative workaround is to split even more stuff out into other header files. Personally I would prefer not to wrap the lock/unlock functions; I like seeing the kind of locking that's happening. Plus, such a helper would be pretty gross: void kunit_lock(struct kunit *test, unsigned long* flags) {...} It wouldn't actually clean up the call site, just facilitate breaking out code into a header. > > making users include this separately is probably the right thing to > > do, as nesting the headers like this is a bit ugly, but I won't lose > > sleep over leaving it till later. > > Ack, I can add a TODO to indicate we want to clean this up? I am fine with this. > It's a bit annoying right now, but it'll only get more annoying in the future. > > > > > > > > > Now the first big comment in test.h is about kunit_case, which is a lot > > > more relevant to what a new user wants to know. > > > > > > A side effect of this is git blame won't properly track history by > > > default, users need to run > > > $ git blame -L ,1 -C17 include/kunit/resource.h > > > > This is a pain, but is probably worth it. Thanks for including the > > command in the commit message, which should mitigate it slightly. > > > > > > > > Signed-off-by: Daniel Latypov > > > --- > > > > This was starting to annoy me, too, as it was a pain to read through > > everything in test.h. It'll be a bit of short-term pain, > > merge-conflict wise if we have other changes to the resource system > > (which I fear is likely), but is worth it. > > > > Reviewed-by: David Gow > > > > -- David > > > > > > > > NOTE: this file doesn't split out code from test.c to a new resource.c > > > file. > > > I'm primarily concerned with users trying to read the headers, so I > > > didn't think messing up git blame (w/ default settings) was worth it. > > > But I can make that change if it feels appropriate (it might also be > > > messier). > > > > Personally, I think it's probably worth splitting this out as well. > > And the sooner we do it, the less history we'll obscure. :-) > > Yeah, that was my thought. > But if you think this would help users, then I think we have a case to > make this change. > > Should I send a v2 with resource.c split out? > Brendan (and any others who have an opinion), what's your preference? I personally don't think test.c is so huge that it is a problem to understand, but I can see it getting there. If it's going to happen, sooner is probably better. > > > > But I agree, it's less of an issue as it only directly affects people > > working on KUnit itself. Though making it easier for users to find and > > read the implementation of these functions could help them understand > > API "gotchas", so I think it's worthwhile. > > > > > > > > --- > > > Documentation/dev-tools/kunit/api/index.rst | 5 + > > > .../dev-tools/kunit/api/resource.rst | 13 + > > > include/kunit/resource.h | 319 ++++++++++++++++++ > > > include/kunit/test.h | 301 +---------------- > > > 4 files changed, 339 insertions(+), 299 deletions(-) > > > create mode 100644 Documentation/dev-tools/kunit/api/resource.rst > > > create mode 100644 include/kunit/resource.h > > > > > <...snip...>