linux/lib/kunit/device.c

// SPDX-License-Identifier: GPL-2.0
/*
 * KUnit-managed device implementation
 *
 * Implementation of struct kunit_device helpers for fake devices whose
 * lifecycle is managed by KUnit.
 *
 * Copyright (C) 2023, Google LLC.
 * Author: David Gow <[email protected]>
 */

#include <linux/device.h>
#include <linux/dma-mapping.h>

#include <kunit/test.h>
#include <kunit/device.h>
#include <kunit/resource.h>

#include "device-impl.h"

/* Wrappers for use with kunit_add_action() */
KUNIT_DEFINE_ACTION_WRAPPER(device_unregister_wrapper, device_unregister, struct device *);
KUNIT_DEFINE_ACTION_WRAPPER(driver_unregister_wrapper, driver_unregister, struct device_driver *);

/* The root device for the KUnit bus, parent of all kunit_devices. */
static struct device *kunit_bus_device;

/* A device owned by a KUnit test. */
struct kunit_device {};

#define to_kunit_device(d)

static const struct bus_type kunit_bus_type =;

/* Register the 'kunit_bus' used for fake devices. */
int kunit_bus_init(void)
{}

/* Unregister the 'kunit_bus' in case the KUnit module is unloaded. */
void kunit_bus_shutdown(void)
{}

/* Release a 'fake' KUnit device. */
static void kunit_device_release(struct device *d)
{}

/*
 * Create and register a KUnit-managed struct device_driver on the kunit_bus.
 * Returns an error pointer on failure.
 */
struct device_driver *kunit_driver_create(struct kunit *test, const char *name)
{}
EXPORT_SYMBOL_GPL();

/* Helper which creates a kunit_device, attaches it to the kunit_bus*/
static struct kunit_device *kunit_device_register_internal(struct kunit *test,
							   const char *name,
							   const struct device_driver *drv)
{}

/*
 * Create and register a new KUnit-managed device, using the user-supplied device_driver.
 * On failure, returns an error pointer.
 */
struct device *kunit_device_register_with_driver(struct kunit *test,
						 const char *name,
						 const struct device_driver *drv)
{}
EXPORT_SYMBOL_GPL();

/*
 * Create and register a new KUnit-managed device, including a matching device_driver.
 * On failure, returns an error pointer.
 */
struct device *kunit_device_register(struct kunit *test, const char *name)
{}
EXPORT_SYMBOL_GPL();

/* Unregisters a KUnit-managed device early (including the driver, if automatically created). */
void kunit_device_unregister(struct kunit *test, struct device *dev)
{}
EXPORT_SYMBOL_GPL();