/* 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. */ staticstruct device *kunit_bus_device;
/* A device owned by a KUnit test. */ struct kunit_device { struct device dev; /* The KUnit test which owns this device. */ struct kunit *owner; /* If the driver is managed by KUnit and unique to this device. */ conststruct device_driver *driver;
};
/* Register the 'kunit_bus' used for fake devices. */ int kunit_bus_init(void)
{ int error;
kunit_bus_device = root_device_register("kunit"); if (IS_ERR(kunit_bus_device)) return PTR_ERR(kunit_bus_device);
error = bus_register(&kunit_bus_type); if (error)
root_device_unregister(kunit_bus_device); return error;
}
/* Unregister the 'kunit_bus' in case the KUnit module is unloaded. */ void kunit_bus_shutdown(void)
{ /* Make sure the bus exists before we unregister it. */ if (IS_ERR_OR_NULL(kunit_bus_device)) return;
/* * 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, constchar *name)
{ struct device_driver *driver; int err = -ENOMEM;
/* Helper which creates a kunit_device, attaches it to the kunit_bus*/ staticstruct kunit_device *kunit_device_register_internal(struct kunit *test, constchar *name, conststruct device_driver *drv)
{ struct kunit_device *kunit_dev; int err = -ENOMEM;
kunit_dev = kzalloc(sizeof(*kunit_dev), GFP_KERNEL); if (!kunit_dev) return ERR_PTR(err);
/* * 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, constchar *name)
{ struct device_driver *drv; struct kunit_device *dev;
drv = kunit_driver_create(test, name); if (IS_ERR(drv)) return ERR_CAST(drv);
dev = kunit_device_register_internal(test, name, drv); if (IS_ERR(dev)) {
kunit_release_action(test, driver_unregister_wrapper, (void *)drv); return ERR_CAST(dev);
}
/* Request the driver be freed. */
dev->driver = drv;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.