brintos

brintos / linux-shallow public Read only

0
0
Text · 2.8 KiB · 2450110 Raw
81 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * KUnit basic device implementation4 *5 * Helpers for creating and managing fake devices for KUnit tests.6 *7 * Copyright (C) 2023, Google LLC.8 * Author: David Gow <davidgow@google.com>9 */10 11#ifndef _KUNIT_DEVICE_H12#define _KUNIT_DEVICE_H13 14#if IS_ENABLED(CONFIG_KUNIT)15 16#include <kunit/test.h>17 18struct device;19struct device_driver;20 21/**22 * kunit_driver_create() - Create a struct device_driver attached to the kunit_bus23 * @test: The test context object.24 * @name: The name to give the created driver.25 *26 * Creates a struct device_driver attached to the kunit_bus, with the name @name.27 * This driver will automatically be cleaned up on test exit.28 *29 * Return: a stub struct device_driver, managed by KUnit, with the name @name.30 */31struct device_driver *kunit_driver_create(struct kunit *test, const char *name);32 33/**34 * kunit_device_register() - Create a struct device for use in KUnit tests35 * @test: The test context object.36 * @name: The name to give the created device.37 *38 * Creates a struct kunit_device (which is a struct device) with the given name,39 * and a corresponding driver. The device and driver will be cleaned up on test40 * exit, or when kunit_device_unregister is called. See also41 * kunit_device_register_with_driver, if you wish to provide your own42 * struct device_driver.43 *44 * Return: a pointer to a struct device which will be cleaned up when the test45 * exits, or an error pointer if the device could not be allocated or registered.46 */47struct device *kunit_device_register(struct kunit *test, const char *name);48 49/**50 * kunit_device_register_with_driver() - Create a struct device for use in KUnit tests51 * @test: The test context object.52 * @name: The name to give the created device.53 * @drv: The struct device_driver to associate with the device.54 *55 * Creates a struct kunit_device (which is a struct device) with the given56 * name, and driver. The device will be cleaned up on test exit, or when57 * kunit_device_unregister is called. See also kunit_device_register, if you58 * wish KUnit to create and manage a driver for you.59 *60 * Return: a pointer to a struct device which will be cleaned up when the test61 * exits, or an error pointer if the device could not be allocated or registered.62 */63struct device *kunit_device_register_with_driver(struct kunit *test,64						 const char *name,65						 const struct device_driver *drv);66 67/**68 * kunit_device_unregister() - Unregister a KUnit-managed device69 * @test: The test context object which created the device70 * @dev: The device.71 *72 * Unregisters and destroys a struct device which was created with73 * kunit_device_register or kunit_device_register_with_driver. If KUnit created74 * a driver, cleans it up as well.75 */76void kunit_device_unregister(struct kunit *test, struct device *dev);77 78#endif79 80#endif81