1*d03c720eS[email protected] /* SPDX-License-Identifier: GPL-2.0 */ 2*d03c720eS[email protected] /* 3*d03c720eS[email protected] * KUnit basic device implementation 4*d03c720eS[email protected] * 5*d03c720eS[email protected] * Helpers for creating and managing fake devices for KUnit tests. 6*d03c720eS[email protected] * 7*d03c720eS[email protected] * Copyright (C) 2023, Google LLC. 8*d03c720eS[email protected] * Author: David Gow <[email protected]> 9*d03c720eS[email protected] */ 10*d03c720eS[email protected] 11*d03c720eS[email protected] #ifndef _KUNIT_DEVICE_H 12*d03c720eS[email protected] #define _KUNIT_DEVICE_H 13*d03c720eS[email protected] 14*d03c720eS[email protected] #if IS_ENABLED(CONFIG_KUNIT) 15*d03c720eS[email protected] 16*d03c720eS[email protected] #include <kunit/test.h> 17*d03c720eS[email protected] 18*d03c720eS[email protected] struct device; 19*d03c720eS[email protected] struct device_driver; 20*d03c720eS[email protected] 21*d03c720eS[email protected] /** 22*d03c720eS[email protected] * kunit_driver_create() - Create a struct device_driver attached to the kunit_bus 23*d03c720eS[email protected] * @test: The test context object. 24*d03c720eS[email protected] * @name: The name to give the created driver. 25*d03c720eS[email protected] * 26*d03c720eS[email protected] * Creates a struct device_driver attached to the kunit_bus, with the name @name. 27*d03c720eS[email protected] * This driver will automatically be cleaned up on test exit. 28*d03c720eS[email protected] * 29*d03c720eS[email protected] * Return: a stub struct device_driver, managed by KUnit, with the name @name. 30*d03c720eS[email protected] */ 31*d03c720eS[email protected] struct device_driver *kunit_driver_create(struct kunit *test, const char *name); 32*d03c720eS[email protected] 33*d03c720eS[email protected] /** 34*d03c720eS[email protected] * kunit_device_register() - Create a struct device for use in KUnit tests 35*d03c720eS[email protected] * @test: The test context object. 36*d03c720eS[email protected] * @name: The name to give the created device. 37*d03c720eS[email protected] * 38*d03c720eS[email protected] * Creates a struct kunit_device (which is a struct device) with the given name, 39*d03c720eS[email protected] * and a corresponding driver. The device and driver will be cleaned up on test 40*d03c720eS[email protected] * exit, or when kunit_device_unregister is called. See also 41*d03c720eS[email protected] * kunit_device_register_with_driver, if you wish to provide your own 42*d03c720eS[email protected] * struct device_driver. 43*d03c720eS[email protected] * 44*d03c720eS[email protected] * Return: a pointer to a struct device which will be cleaned up when the test 45*d03c720eS[email protected] * exits, or an error pointer if the device could not be allocated or registered. 46*d03c720eS[email protected] */ 47*d03c720eS[email protected] struct device *kunit_device_register(struct kunit *test, const char *name); 48*d03c720eS[email protected] 49*d03c720eS[email protected] /** 50*d03c720eS[email protected] * kunit_device_register_with_driver() - Create a struct device for use in KUnit tests 51*d03c720eS[email protected] * @test: The test context object. 52*d03c720eS[email protected] * @name: The name to give the created device. 53*d03c720eS[email protected] * @drv: The struct device_driver to associate with the device. 54*d03c720eS[email protected] * 55*d03c720eS[email protected] * Creates a struct kunit_device (which is a struct device) with the given 56*d03c720eS[email protected] * name, and driver. The device will be cleaned up on test exit, or when 57*d03c720eS[email protected] * kunit_device_unregister is called. See also kunit_device_register, if you 58*d03c720eS[email protected] * wish KUnit to create and manage a driver for you. 59*d03c720eS[email protected] * 60*d03c720eS[email protected] * Return: a pointer to a struct device which will be cleaned up when the test 61*d03c720eS[email protected] * exits, or an error pointer if the device could not be allocated or registered. 62*d03c720eS[email protected] */ 63*d03c720eS[email protected] struct device *kunit_device_register_with_driver(struct kunit *test, 64*d03c720eS[email protected] const char *name, 65*d03c720eS[email protected] const struct device_driver *drv); 66*d03c720eS[email protected] 67*d03c720eS[email protected] /** 68*d03c720eS[email protected] * kunit_device_unregister() - Unregister a KUnit-managed device 69*d03c720eS[email protected] * @test: The test context object which created the device 70*d03c720eS[email protected] * @dev: The device. 71*d03c720eS[email protected] * 72*d03c720eS[email protected] * Unregisters and destroys a struct device which was created with 73*d03c720eS[email protected] * kunit_device_register or kunit_device_register_with_driver. If KUnit created 74*d03c720eS[email protected] * a driver, cleans it up as well. 75*d03c720eS[email protected] */ 76*d03c720eS[email protected] void kunit_device_unregister(struct kunit *test, struct device *dev); 77*d03c720eS[email protected] 78*d03c720eS[email protected] #endif 79*d03c720eS[email protected] 80*d03c720eS[email protected] #endif 81