Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp974621pxp; Wed, 16 Mar 2022 23:09:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8HK0lMm6fPzaRBdxLm+fXEQq/AfmoeUtLmvsTEa9pvR+VpJogPigaOreBoOGViC+0Qpey X-Received: by 2002:a17:902:a9c7:b0:153:29c6:e101 with SMTP id b7-20020a170902a9c700b0015329c6e101mr3084037plr.92.1647497370055; Wed, 16 Mar 2022 23:09:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647497370; cv=none; d=google.com; s=arc-20160816; b=AZMm4wISK6cb2ODLwiTk2165sq6osbCifvFbLlClP8Sz4MTJBAYU9fQTM4b1s4csLa JmHuFZajq/bLBb4k5h+6Z+fi3KbXSCmLjnfH7UIBv7C3uOKVShF/App0iD94h8v/BwmU tfvfla4iho1iPrZrJy9rBBHRpsThfg8Ya1JnY/GrtSzc/3A5elpJIRGZSbFHWJdhdggf 0MXgm4IyYD+SOR3WRMZjG0EhfMZAdtaPy/b9b9RZtT+TsysPgSmYU1wZ944+Z5gy76Sq neMYgVOojBMaj62CkWKp08LonuMUdvCcQV2Us0pifQjUmlV7JGYGY+8ZrWKCU/pespx7 4dvA== 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=9R+r1ohG1xCnpzC1qrsRmiSwShPkfg0ZOVxajhsdBXQ=; b=lAECO97+UtmI00VL03T6xsIdljU70rDDWyniUM/0zX8Fk/K8aj3QjweAGGZMBx/8qf 7yefZtN7LISXLPPxshu3085kPPvlqDgaraFBSrGluANMz8+Ouxs/EY+bzK87ApAbwKWb Yqf/a2ZR4tS+Snf/G36rOeaoPP63i/BR6Jb7Xn5FAKb5NNyMlwGbU7mIq4A0tSsSGHse 0FCv5CFhg4PEiYtVAKhSn9Vz5t4iHq0PnnEs1MhkowChu+TcWuuX4QWLH7cnpwWsW1JX GhNcAEGVrpbR30I3yXk9GdTaAcP5myNmHE/2D3HDZEN2l6VGtz8n4o2Bfg/6ZJcGFExj 9ynQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qi9FqeLp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id y10-20020aa7804a000000b004f70b6a9251si3498573pfm.363.2022.03.16.23.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 23:09:30 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qi9FqeLp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 1E968939B6; Wed, 16 Mar 2022 22:21:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236520AbiCPQUp (ORCPT + 99 others); Wed, 16 Mar 2022 12:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244432AbiCPQUl (ORCPT ); Wed, 16 Mar 2022 12:20:41 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07C286D4D9 for ; Wed, 16 Mar 2022 09:19:16 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id d10so5242288eje.10 for ; Wed, 16 Mar 2022 09:19:15 -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=9R+r1ohG1xCnpzC1qrsRmiSwShPkfg0ZOVxajhsdBXQ=; b=qi9FqeLpLieqgQ59FaHOoa+yZmTX88lHcN3nvMY9vttgnNQqJJFXReFu54ETu5sZhG ol+10DgD84IYFTcb6bqne0P4eM47tjCOXAFSakQRAMKrLnZ0JcLIVD9d6JTKAUlOqQxC i4H4ax9AxxtyaSAgVGLgmqLDVbV0d2ZgeFqYeYX4BsqoQtbbE7wZtXvcKEZO1gJletKa BUEsCy8Y10vn5Y21uOm4eV2GcQCMoMGAuT84ujf6vEq5pWjBlUobUwBaROrHHwWt/iIt GlDlteycpbqQSDQL31WqLIHl5cqYeZnoVPDjwp3ZXGvwFrFEs9kEQ9sWL3jxykiYAPsx 7wnQ== 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=9R+r1ohG1xCnpzC1qrsRmiSwShPkfg0ZOVxajhsdBXQ=; b=e05jicfz5w6pjmbQ/Q62EAMgv6us73BT/DtJERD0bOLGKQ/IwAn4tsmEicFzuJOWtm 1n0lRI4tAUR0u8u04UFjHzJxNSVejAExAxeFDInL+GV82P/a/kbFJpUaKVk9CO4byt3g BT9Dx6B+FjHTzjJSYk+9F7tc7SmXnW93SuVh+DetVe2+BAN9UjMgnrH1x7KzBu7xpcSK PIqNBpuwOr2sZS0isRL/1PKyVN95QJgXuZOxTvbj9VgayApRC/LorRXOwR2j57tBcJ8U zyDND8dySHpCGWFRX8Ch3xqFKDPU5LG2ErN0r4odmievDSKPXerUsiUIyijIfjzUvHM6 SlkA== X-Gm-Message-State: AOAM533ksoGq3RzxmUlQUtXjd09370weBNjFE+N5obDJHHI6SiNRMcDj x3wtEHQ7t+0Q3G2AsgcurVo+Cp6fRk/CoCLtWjl4MUFI+S7oBw== X-Received: by 2002:a17:907:1609:b0:6db:b385:d13b with SMTP id hb9-20020a170907160900b006dbb385d13bmr608694ejc.542.1647447554142; Wed, 16 Mar 2022 09:19:14 -0700 (PDT) MIME-Version: 1.0 References: <20220316024432.1454366-1-dlatypov@google.com> In-Reply-To: From: Daniel Latypov Date: Wed, 16 Mar 2022 11:19:02 -0500 Message-ID: Subject: Re: [PATCH] kunit: split resource API from test.h into new resource.h To: David Gow Cc: Brendan Higgins , 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: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). > 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? 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? > > 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...>