Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp148949rdb; Tue, 5 Dec 2023 01:02:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXyPZokVKS5BjVVv1Wp4Cw/fbahoZlb5+6tKez8ZGmtXMPsqPUA4w0CZ6Wuy8QgDbrG2VI X-Received: by 2002:a05:6a00:6ca8:b0:6ce:658a:d7c1 with SMTP id jc40-20020a056a006ca800b006ce658ad7c1mr884660pfb.49.1701766947231; Tue, 05 Dec 2023 01:02:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701766947; cv=none; d=google.com; s=arc-20160816; b=NaHfXPVbgUKMBuJruWP41b9faB+VFu1CXuQ+3tvS5Ens2OJ0C9DcuA8wBX2PIQmFbb NfV6xtGJEYezWr/o44t5W9JandLjx9xYeKfqnpJvWWa8lD/ttrNnOLuFBKx3gVAf7EHM FAvfgcDZ+hpWRjm3eNcI19d/1k+cNL95MBcAt9b6BAzgqyV7xG0pLtEIbFnBowZZbLXp NoMqQ3jGOc3lZsNyA3Fn758wYTnlZ+eLeGHXAotph+I+r8YiZY7uxZpoFHij80pl9Ubp VASHY0rnP58ucdBR0SIfeB6TQ/FFwWzJY4/F8XG+1pdnetTChXQdzPDZyTrwuAjU+Qp9 6NGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=qo8i5IYRjlZgwCsP3D58Oe04OH+UdKgWCsXiqTqK3wc=; fh=r7fZGRR8v30r5dQSnPvbTKahJwoD+y5fWrnQWbsgLb4=; b=XxBPgw+nHvRpYiMzhQJwwzxmiM2yLkIawNbgRaPuChmDts52/aYoHTWztasBsBzYLN woIQvtBdxQ+gGsFV9iLVKk45adET5nfC/vFdDAffHgxW3JTpSZ1g8pvhLwwLNdVmIXc+ 8bsTBt+1f09o8dwvbIOSaXQxAj1mc3L4Tq5TCM3tQ4ajWMXFwOynEd86WyeLSGxdua8k n9YIsADeWu3hR8xb7IiVIr0are3Ly8QAELUnM2JOza397Ye1ej2rAY0Y59v8dTtfEYky e0EbU/4gGJmXx6bHc9CwuDY4oSfGQSDkqWzOq0FUE0YY8QHsjfC/eVaT260Lds4zO4r7 w97w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Zpc8OeN3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id bd33-20020a056a0027a100b006ce49c21894si3662386pfb.162.2023.12.05.01.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 01:02:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Zpc8OeN3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 529E880465CD; Tue, 5 Dec 2023 01:02:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234860AbjLEJCK (ORCPT + 99 others); Tue, 5 Dec 2023 04:02:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbjLEJCI (ORCPT ); Tue, 5 Dec 2023 04:02:08 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6A4FC9; Tue, 5 Dec 2023 01:02:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701766935; x=1733302935; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=ZOeyE7NVJTkhBLEolveT7OB0fqrr4Rs84xpHFHSA1K4=; b=Zpc8OeN3i+J4ehszqWiHQ9zdYAtpeezT/BBvLgmbmKqr+oL1KUnfDnkh OJzGuci/8zZQhdozD/NDVYJgfY3VgWYJMttTeSyReSgNrpNTrSt11ftJI KvYDsmSlI51N3R0AVaMVxECONXumhYFOcmp/T4Fn+kn76+oWugZSb5eqH rZsy9T/Kt9Ukj0wbHdw4Aixg9YPq3Iwd733vdXgPfVQlYkfrB30/OG6BA 4yuKr+4gjuXxdHWu16SgcbsLGZvRj4yq4N5WJ/DScwr/SgQk8OF9xa0UN uq6DrEcftpg+Xgs1mNRD1yo1SP8oM0kyBwNMpD7plbQnC4wpzty+Nt65C g==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="15413830" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="15413830" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2023 01:02:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="1018158044" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="1018158044" Received: from aslawinx-mobl.ger.corp.intel.com (HELO [10.94.0.53]) ([10.94.0.53]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2023 01:02:09 -0800 Message-ID: Date: Tue, 5 Dec 2023 10:02:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/4] kunit: Add APIs for managing devices Content-Language: en-US To: davidgow@google.com, Rae Moar , Brendan Higgins , Greg Kroah-Hartman , Matti Vaittinen , Stephen Boyd , Shuah Khan , Jonathan Corbet , Kees Cook , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Maxime Ripard 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 References: <20231205-kunit_bus-v1-0-635036d3bc13@google.com> <20231205-kunit_bus-v1-1-635036d3bc13@google.com> From: =?UTF-8?Q?Amadeusz_S=C5=82awi=C5=84ski?= In-Reply-To: <20231205-kunit_bus-v1-1-635036d3bc13@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 05 Dec 2023 01:02:24 -0800 (PST) On 12/5/2023 8:31 AM, davidgow@google.com wrote: > Tests for drivers often require a struct device to pass to other > functions. While it's possible to create these with > root_device_register(), or to use something like a platform device, this > is both a misuse of those APIs, and can be difficult to clean up after, > for example, a failed assertion. > > Add some KUnit-specific functions for registering and unregistering a > struct device: > - kunit_device_register() > - kunit_device_register_with_driver() > - kunit_device_unregister() > > These helpers allocate a on a 'kunit' bus which will either probe the > driver passed in (kunit_device_register_with_driver), or will create a > stub driver (kunit_device_register) which is cleaned up on test shutdown. > > Devices are automatically unregistered on test shutdown, but can be > manually unregistered earlier with kunit_device_unregister() in order > to, for example, test device release code. > > Signed-off-by: David Gow > --- > Documentation/dev-tools/kunit/usage.rst | 49 +++++++++ > include/kunit/device.h | 76 ++++++++++++++ > lib/kunit/Makefile | 3 +- > lib/kunit/device.c | 176 ++++++++++++++++++++++++++++++++ > lib/kunit/kunit-test.c | 68 +++++++++++- > lib/kunit/test.c | 3 + > 6 files changed, 373 insertions(+), 2 deletions(-) > > diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst > index 9db12e91668e..a222a98edceb 100644 > --- a/Documentation/dev-tools/kunit/usage.rst > +++ b/Documentation/dev-tools/kunit/usage.rst > @@ -797,3 +797,52 @@ structures as shown below: > KUnit is not enabled, or if no test is running in the current task, it will do > nothing. This compiles down to either a no-op or a static key check, so will > have a negligible performance impact when no test is running. > + > +Managing Fake Devcices and Drivers > +---------------------------------- Typo: Devices