/* SPDX-License-Identifier: GPL-2.0 */1/*2* KUnit basic device implementation3*4* Helpers for creating and managing fake devices for KUnit tests.5*6* Copyright (C) 2023, Google LLC.7* Author: David Gow <[email protected]>8*/910#ifndef _KUNIT_DEVICE_H11#define _KUNIT_DEVICE_H1213#if IS_ENABLED(CONFIG_KUNIT)1415#include <kunit/test.h>1617struct device;18struct device_driver;1920/**21* kunit_driver_create() - Create a struct device_driver attached to the kunit_bus22* @test: The test context object.23* @name: The name to give the created driver.24*25* Creates a struct device_driver attached to the kunit_bus, with the name @name.26* This driver will automatically be cleaned up on test exit.27*28* Return: a stub struct device_driver, managed by KUnit, with the name @name.29*/30struct device_driver *kunit_driver_create(struct kunit *test, const char *name);3132/**33* kunit_device_register() - Create a struct device for use in KUnit tests34* @test: The test context object.35* @name: The name to give the created device.36*37* Creates a struct kunit_device (which is a struct device) with the given name,38* and a corresponding driver. The device and driver will be cleaned up on test39* exit, or when kunit_device_unregister is called. See also40* kunit_device_register_with_driver, if you wish to provide your own41* struct device_driver.42*43* Return: a pointer to a struct device which will be cleaned up when the test44* exits, or an error pointer if the device could not be allocated or registered.45*/46struct device *kunit_device_register(struct kunit *test, const char *name);4748/**49* kunit_device_register_with_driver() - Create a struct device for use in KUnit tests50* @test: The test context object.51* @name: The name to give the created device.52* @drv: The struct device_driver to associate with the device.53*54* Creates a struct kunit_device (which is a struct device) with the given55* name, and driver. The device will be cleaned up on test exit, or when56* kunit_device_unregister is called. See also kunit_device_register, if you57* wish KUnit to create and manage a driver for you.58*59* Return: a pointer to a struct device which will be cleaned up when the test60* exits, or an error pointer if the device could not be allocated or registered.61*/62struct device *kunit_device_register_with_driver(struct kunit *test,63const char *name,64const struct device_driver *drv);6566/**67* kunit_device_unregister() - Unregister a KUnit-managed device68* @test: The test context object which created the device69* @dev: The device.70*71* Unregisters and destroys a struct device which was created with72* kunit_device_register or kunit_device_register_with_driver. If KUnit created73* a driver, cleans it up as well.74*/75void kunit_device_unregister(struct kunit *test, struct device *dev);7677#endif7879#endif808182