test: let the device custom create method return a bool

This is so we can tell litest to create the device anyway, useful for when all
we have to do in the custom create is allocate some memory.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2019-03-22 15:44:32 +10:00
parent 5a041de7a6
commit 11adaadd51
3 changed files with 16 additions and 9 deletions

View file

@ -28,7 +28,7 @@
#define NAME "All event codes keyboard"
static void all_codes_create(struct litest_device *d);
static bool all_codes_create(struct litest_device *d);
static struct input_id input_id = {
.bustype = 0x11,
@ -48,7 +48,7 @@ TEST_DEVICE("keyboard-all-codes",
.absinfo = NULL,
)
static void
static bool
all_codes_create(struct litest_device *d)
{
int events[KEY_MAX * 2 + 2];
@ -70,4 +70,5 @@ all_codes_create(struct litest_device *d)
&input_id,
NULL,
events);
return false;
}

View file

@ -44,8 +44,11 @@ struct litest_test_device {
* For such devices, no overrides are possible. If create is NULL,
* the information in name, id, events, absinfo is used to
* create the device instead.
*
* @return true if the device needs to be created by litest, false if
* the device creates itself
*/
void (*create)(struct litest_device *d);
bool (*create)(struct litest_device *d);
/**
* The device name. Only used when create is NULL.

View file

@ -1395,6 +1395,7 @@ litest_create(enum litest_device_type which,
const char *path;
int fd, rc;
bool found = false;
bool create_device = true;
list_for_each(dev, &devices, node) {
if (dev->type == which) {
@ -1411,16 +1412,18 @@ litest_create(enum litest_device_type which,
/* device has custom create method */
if (dev->create) {
dev->create(d);
create_device = dev->create(d);
if (abs_override || events_override) {
litest_abort_msg("Custom create cannot be overridden");
}
} else {
abs = merge_absinfo(dev->absinfo, abs_override);
events = merge_events(dev->events, events_override);
name = name_override ? name_override : dev->name;
id = id_override ? id_override : dev->id;
}
abs = merge_absinfo(dev->absinfo, abs_override);
events = merge_events(dev->events, events_override);
name = name_override ? name_override : dev->name;
id = id_override ? id_override : dev->id;
if (create_device) {
d->uinput = litest_create_uinput_device_from_description(name,
id,
abs,