1
0
forked from drath/libratbag

test: fix the loading of the test driver

This test driver is already twisting a little bit the API, so twist it
a little bit more.

An other solution would be to just add a (void* data) parameter to .probe()
but there is no point in it because only test_driver would be used.

Create a new probe callback only used when using the test driver, so make
check is happy.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
Benjamin Tissoires
2015-10-09 16:26:39 -04:00
parent 3605bede48
commit ebad4ecd0a
3 changed files with 25 additions and 9 deletions

View File

@@ -23,6 +23,8 @@
#include "config.h"
#include <errno.h>
#include "libratbag-private.h"
#include "libratbag-test.h"
@@ -81,12 +83,15 @@ test_write_profile(struct ratbag_profile *profile)
}
static int
test_probe(struct ratbag_device *device)
test_fake_probe(struct ratbag_device *device)
{
struct ratbag_test_device *test_device;
return -ENODEV;
}
/* FIXME: after the move to hwdb the test_device is no
* longer passed in. */
static int
test_probe(struct ratbag_device *device, void *data)
{
struct ratbag_test_device *test_device = data;
ratbag_set_drv_data(device, test_device);
ratbag_device_init_profiles(device,
@@ -109,7 +114,9 @@ test_remove(struct ratbag_device *device)
struct ratbag_driver test_driver = {
.name = "Test driver",
.probe = test_probe,
.id = "test_driver",
.probe = test_fake_probe,
.__test_probe = test_probe,
.remove = test_remove,
.read_profile = test_read_profile,
.write_profile = test_write_profile,

View File

@@ -181,6 +181,8 @@ struct ratbag_driver {
int dpi_x, int dpi_y);
/* private */
int (*__test_probe)(struct ratbag_device *device, void *data);
struct list link;
};

View File

@@ -294,9 +294,13 @@ ratbag_find_driver(struct ratbag_device *device,
int rc;
const char *driver_name;
driver_name = udev_prop_value(device->udev_device, "RATBAG_DRIVER");
if (!driver_name)
return NULL;
if (!test_device) {
driver_name = udev_prop_value(device->udev_device, "RATBAG_DRIVER");
if (!driver_name)
return NULL;
} else {
driver_name = "test_driver";
}
list_for_each(driver, &ratbag->drivers, link) {
if (!streq(driver->id, driver_name))
@@ -304,7 +308,10 @@ ratbag_find_driver(struct ratbag_device *device,
device->driver = driver;
rc = driver->probe(device);
if (test_device)
rc = driver->__test_probe(device, test_device);
else
rc = driver->probe(device);
if (rc == 0) {
if (!ratbag_sanity_check_device(device)) {
return NULL;