Message ID | 20231205-kunit_bus-v1-2-635036d3bc13@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3264869vqy; Mon, 4 Dec 2023 23:32:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJvNbsOiPbsO/NKNiGPTBby9lM2fwrhkhV9VnacOPJDyxbc5WCBNfucZz1gqA+mCDvFfsz X-Received: by 2002:a05:6358:3106:b0:16b:ac8e:c5f3 with SMTP id c6-20020a056358310600b0016bac8ec5f3mr6663561rwe.14.1701761539677; Mon, 04 Dec 2023 23:32:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701761539; cv=none; d=google.com; s=arc-20160816; b=lwRmZJYSByCaIrIfUf0lcPNxHO4HmX0KBHEAkuxMaNVWpXh0c7Cg9t92bDdsIb24rY pMq6wpbKUZ8vySK8J81iGa8lRDwAuI9ULrEQSjlYs8xosMkydUDhyyRs17meuvH8yM34 jI+t+GrNj/t+XPfzD+mK3KS+DhDs263ChOGqns/pf2NPZ3yA+6JKcl5S1NWLwpQJX7sJ gcTWSkcPxqKTsAP3AtrB5LY+PhNrprwXZ77zg0LryTekQtk1e6lgAT4xxyo7T6vNALT7 L2rUHOg4+EhDigkhqxZGDvrqCcFhJz0A5pf/3C0BzME7dYeXvVmJ9E1LrSvLyIC0XI5c dPjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=K0zdW7CBKdTcyZ6NkC3IZ70G/WJIHzJoU6Zyjp/hyXw=; fh=FBRasfUlr9n+nXXXlXR1Gg7/LVBbWP8wdjqI9r8Tmds=; b=LODQVLd6V7EK2QDf+V8o8q7dZ2UQZZ65DcirG1/XWiRwMbJckbYavLWaPwfQyj2yoM XTUzkEeo/AfdLUTF3inAnFQYvWMDde3n8kxqCq3gflWq2BPqS/6lhFxuHkYkm0W1JBRn VTB3U2Fe149vrRmufDuPs1gugdSH1592Fh9Fx104P+7WwsdaEcc+Gl6Midgt5qmMWs8b IGRS3EmtHVe6N6FO7AeXjOSDHVpObV7a2kNTKfPOb2KSmxEoSLdksXJCSWFpGC8Bjw47 RMOqDohICeCnE9ZQYN91sXr4IX9xpQUfSmp3JO3VYuViaJsQPqOxlakYfSxMCREjqsM9 KmHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ODWFWSuE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id o21-20020a635a15000000b005740b4723f9si9556919pgb.811.2023.12.04.23.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:32:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ODWFWSuE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 0B6BE80C7133; Mon, 4 Dec 2023 23:32:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344331AbjLEHb4 (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Tue, 5 Dec 2023 02:31:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344587AbjLEHby (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 5 Dec 2023 02:31:54 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCC40129 for <linux-kernel@vger.kernel.org>; Mon, 4 Dec 2023 23:32:00 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-db98b9c0fceso307702276.1 for <linux-kernel@vger.kernel.org>; Mon, 04 Dec 2023 23:32:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701761520; x=1702366320; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=K0zdW7CBKdTcyZ6NkC3IZ70G/WJIHzJoU6Zyjp/hyXw=; b=ODWFWSuEFkV8GCsHmRatZGcony01v/uW8FqEAWHZ6v9DKNcJr7LGwv6RREzSth54Ij 0tfb8D/Yqk1dy4XES+mC+pN1hzucQVSEC9EOKMcy/fxjQWqNvBxTlrsBBdTmUqe4+BcV 23Gnvl2glpk7aWBBBKV3CcfznbCgyqtAF6kecf22J5aL9mSFLJnZxzbvnm88zivJP3Xe utUwuAIb000bpYgKsIoQTqrexGfTygbx3GIu8xqVFNjGrQ3fftlD3K+8Lh/1JjeQwZPM DpLH1qS04Or6194+Zs/o3+dYTeFTyJgJOE9Pv3GmrqU9H7CCms4burSVn3G3KME2vDuM wlVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701761520; x=1702366320; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=K0zdW7CBKdTcyZ6NkC3IZ70G/WJIHzJoU6Zyjp/hyXw=; b=GiHoe4HXHbiqBJjFnn3pQHVhFEd945rseoP1Q9ePCKYQfFQhvFF70NIg2DRR/P0Bp5 GHqlJhPfEaGoC28+3omF88LBCGA3/x4WUI6uQd5mDFPDA6lwxsi0wrCZ/+5Ehb9QZMsc 6rzM/+dqZGqau/VCs0NfyzOZtQAokVoalA4XMSuE7jhSuykfoT7EvxiuMmKN/HR1ex8U zzf41nB+A5y0egxeS+032ce/+nHKilykOn1Eq2ZdXrUahAsv+qW0GUV0Cbi0JKkkPYzN 7i+vQVzbiaP0L09OloAy0KwGPVy543ZwEMSHnB6A1+qPFnVo9RPwi6P7os/ePgP83QZp nRdw== X-Gm-Message-State: AOJu0YyT8Hw3b+GK/xlm6z7/ts0xPTS4/uzTTGLgwDKMzUNvKSUILoxU NPpjMVT29QELTPzMdM35ImE5PO6tY/SV7g== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a25:d04c:0:b0:db5:4b1d:c63c with SMTP id h73-20020a25d04c000000b00db54b1dc63cmr312842ybg.11.1701761520168; Mon, 04 Dec 2023 23:32:00 -0800 (PST) Date: Tue, 05 Dec 2023 15:31:34 +0800 In-Reply-To: <20231205-kunit_bus-v1-0-635036d3bc13@google.com> Mime-Version: 1.0 References: <20231205-kunit_bus-v1-0-635036d3bc13@google.com> X-Mailer: b4 0.13-dev-099c9 Message-ID: <20231205-kunit_bus-v1-2-635036d3bc13@google.com> Subject: [PATCH 2/4] fortify: test: Use kunit_device From: davidgow@google.com To: Rae Moar <rmoar@google.com>, Brendan Higgins <brendan.higgins@linux.dev>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Matti Vaittinen <mazziesaccount@gmail.com>, Stephen Boyd <sboyd@kernel.org>, Shuah Khan <skhan@linuxfoundation.org>, Jonathan Corbet <corbet@lwn.net>, Kees Cook <keescook@chromium.org>, Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>, Maxime Ripard <mripard@kernel.org> Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, linux-sound@vger.kernel.org, David Gow <davidgow@google.com> Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 04 Dec 2023 23:32:16 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784426308471947751 X-GMAIL-MSGID: 1784426308471947751 |
Series | kunit: Add helpers for creating test-managed devices | |
Commit Message
David Gow
Dec. 5, 2023, 7:31 a.m. UTC
Using struct root_device to create fake devices for tests is something
of a hack. The new struct kunit_device is meant for this purpose, so use
it instead.
Signed-off-by: David Gow <davidgow@google.com>
---
lib/fortify_kunit.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
On 12/5/23 09:31, davidgow@google.com wrote: > Using struct root_device to create fake devices for tests is something > of a hack. The new struct kunit_device is meant for this purpose, so use > it instead. > > Signed-off-by: David Gow <davidgow@google.com> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
On Tue, Dec 05, 2023 at 03:31:34PM +0800, davidgow@google.com wrote: > Using struct root_device to create fake devices for tests is something > of a hack. The new struct kunit_device is meant for this purpose, so use > it instead. > > Signed-off-by: David Gow <davidgow@google.com> > --- > lib/fortify_kunit.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/lib/fortify_kunit.c b/lib/fortify_kunit.c > index c8c33cbaae9e..f7a1fce8849b 100644 > --- a/lib/fortify_kunit.c > +++ b/lib/fortify_kunit.c > @@ -16,6 +16,7 @@ > #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > > #include <kunit/test.h> > +#include <kunit/device.h> > #include <linux/device.h> > #include <linux/slab.h> > #include <linux/string.h> > @@ -269,7 +270,7 @@ DEFINE_ALLOC_SIZE_TEST_PAIR(kvmalloc) > size_t len; \ > \ > /* Create dummy device for devm_kmalloc()-family tests. */ \ > - dev = root_device_register(dev_name); \ > + dev = kunit_device_register(test, dev_name); \ > KUNIT_ASSERT_FALSE_MSG(test, IS_ERR(dev), \ > "Cannot register test device\n"); \ > \ > @@ -303,7 +304,7 @@ DEFINE_ALLOC_SIZE_TEST_PAIR(kvmalloc) > checker(len, devm_kmemdup(dev, "Ohai", len, gfp), \ > devm_kfree(dev, p)); \ > \ > - device_unregister(dev); \ > + kunit_device_unregister(test, dev); \ > } while (0) > DEFINE_ALLOC_SIZE_TEST_PAIR(devm_kmalloc) Acked-by: Kees Cook <keescook@chromium.org> (As an aside; shouldn't this get automatically cleaned up like other kunit resources, though?)
On Thu, 7 Dec 2023 at 05:07, Kees Cook <keescook@chromium.org> wrote: > > On Tue, Dec 05, 2023 at 03:31:34PM +0800, davidgow@google.com wrote: > > Using struct root_device to create fake devices for tests is something > > of a hack. The new struct kunit_device is meant for this purpose, so use > > it instead. > > > > Signed-off-by: David Gow <davidgow@google.com> > > --- > > lib/fortify_kunit.c | 5 +++-- > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/lib/fortify_kunit.c b/lib/fortify_kunit.c > > index c8c33cbaae9e..f7a1fce8849b 100644 > > --- a/lib/fortify_kunit.c > > +++ b/lib/fortify_kunit.c > > @@ -16,6 +16,7 @@ > > #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > > > > #include <kunit/test.h> > > +#include <kunit/device.h> > > #include <linux/device.h> > > #include <linux/slab.h> > > #include <linux/string.h> > > @@ -269,7 +270,7 @@ DEFINE_ALLOC_SIZE_TEST_PAIR(kvmalloc) > > size_t len; \ > > \ > > /* Create dummy device for devm_kmalloc()-family tests. */ \ > > - dev = root_device_register(dev_name); \ > > + dev = kunit_device_register(test, dev_name); \ > > KUNIT_ASSERT_FALSE_MSG(test, IS_ERR(dev), \ > > "Cannot register test device\n"); \ > > \ > > @@ -303,7 +304,7 @@ DEFINE_ALLOC_SIZE_TEST_PAIR(kvmalloc) > > checker(len, devm_kmemdup(dev, "Ohai", len, gfp), \ > > devm_kfree(dev, p)); \ > > \ > > - device_unregister(dev); \ > > + kunit_device_unregister(test, dev); \ > > } while (0) > > DEFINE_ALLOC_SIZE_TEST_PAIR(devm_kmalloc) > > Acked-by: Kees Cook <keescook@chromium.org> > > (As an aside; shouldn't this get automatically cleaned up like other > kunit resources, though?) > We can't just get rid of the {kunit_,}device_unregister() here, because otherwise we'd have several devices with the same name during the test. So, yes, these get automatically cleaned up, but the test would have to be restructured to either give each device a different name, or split the tests up further. -- David
diff --git a/lib/fortify_kunit.c b/lib/fortify_kunit.c index c8c33cbaae9e..f7a1fce8849b 100644 --- a/lib/fortify_kunit.c +++ b/lib/fortify_kunit.c @@ -16,6 +16,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <kunit/test.h> +#include <kunit/device.h> #include <linux/device.h> #include <linux/slab.h> #include <linux/string.h> @@ -269,7 +270,7 @@ DEFINE_ALLOC_SIZE_TEST_PAIR(kvmalloc) size_t len; \ \ /* Create dummy device for devm_kmalloc()-family tests. */ \ - dev = root_device_register(dev_name); \ + dev = kunit_device_register(test, dev_name); \ KUNIT_ASSERT_FALSE_MSG(test, IS_ERR(dev), \ "Cannot register test device\n"); \ \ @@ -303,7 +304,7 @@ DEFINE_ALLOC_SIZE_TEST_PAIR(kvmalloc) checker(len, devm_kmemdup(dev, "Ohai", len, gfp), \ devm_kfree(dev, p)); \ \ - device_unregister(dev); \ + kunit_device_unregister(test, dev); \ } while (0) DEFINE_ALLOC_SIZE_TEST_PAIR(devm_kmalloc)