Commit d1e352d1 authored by Daniel Vetter's avatar Daniel Vetter

tests/kms_lease: exercise uevent

And make sure we get the LEASE=1 value, indicating a lessee change.

v2: Apparently netlink reading can leak EAGAIN out through
udev_monitor_receive_device. No idea what's going on there, so let's
wrap some duct tape around it.

v3: Lyude reported that we might get a few udev events on startup of
the test. Drain those first.

v4: Use the igt hotplug library functions, they already take care of
all the uevent special cases.

Cc: Lyude Paul <lyude@redhat.com>
Cc: Keith Packard <keithp@keithp.com>
Reviewed-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
Signed-off-by: Daniel Vetter's avatarDaniel Vetter <daniel.vetter@intel.com>
parent d57546bd
Pipeline #20775 passed with stages
in 7 minutes and 58 seconds
......@@ -4015,16 +4015,8 @@ struct udev_monitor *igt_watch_hotplug(void)
return mon;
}
/**
* igt_hotplug_detected:
* @mon: A udev monitor initialized with #igt_watch_hotplug
* @timeout_secs: How long to wait for a hotplug event to occur.
*
* Assert that a hotplug event was received since we last checked the monitor.
*
* Returns: true if a sysfs hotplug event was received, false if we timed out
*/
bool igt_hotplug_detected(struct udev_monitor *mon, int timeout_secs)
static bool event_detected(struct udev_monitor *mon, int timeout_secs,
const char *property)
{
struct udev_device *dev;
const char *hotplug_val;
......@@ -4042,7 +4034,7 @@ bool igt_hotplug_detected(struct udev_monitor *mon, int timeout_secs)
while (!hotplug_received && poll(&fd, 1, timeout_secs * 1000)) {
dev = udev_monitor_receive_device(mon);
hotplug_val = udev_device_get_property_value(dev, "HOTPLUG");
hotplug_val = udev_device_get_property_value(dev, property);
if (hotplug_val && atoi(hotplug_val) == 1)
hotplug_received = true;
......@@ -4052,6 +4044,34 @@ bool igt_hotplug_detected(struct udev_monitor *mon, int timeout_secs)
return hotplug_received;
}
/**
* igt_hotplug_detected:
* @mon: A udev monitor initialized with #igt_watch_hotplug
* @timeout_secs: How long to wait for a hotplug event to occur.
*
* Assert that a hotplug event was received since we last checked the monitor.
*
* Returns: true if a sysfs hotplug event was received, false if we timed out
*/
bool igt_hotplug_detected(struct udev_monitor *mon, int timeout_secs)
{
return event_detected(mon, timeout_secs, "HOTPLUG");
}
/**
* igt_lease_change_detected:
* @mon: A udev monitor initialized with #igt_watch_hotplug
* @timeout_secs: How long to wait for a lease change event to occur.
*
* Assert that a lease change event was received since we last checked the monitor.
*
* Returns: true if a sysfs lease change event was received, false if we timed out
*/
bool igt_lease_change_detected(struct udev_monitor *mon, int timeout_secs)
{
return event_detected(mon, timeout_secs, "LEASE");
}
/**
* igt_flush_hotplugs:
* @mon: A udev monitor initialized with #igt_watch_hotplug
......
......@@ -749,6 +749,8 @@ const unsigned char* igt_kms_get_alt_edid(void);
struct udev_monitor *igt_watch_hotplug(void);
bool igt_hotplug_detected(struct udev_monitor *mon,
int timeout_secs);
bool igt_lease_change_detected(struct udev_monitor *mon,
int timeout_secs);
void igt_flush_hotplugs(struct udev_monitor *mon);
void igt_cleanup_hotplug(struct udev_monitor *mon);
......
......@@ -40,6 +40,8 @@
#include <sys/time.h>
#include <sys/wait.h>
#include <libudev.h>
#include <drm.h>
IGT_TEST_DESCRIPTION("Test of CreateLease.");
......@@ -974,6 +976,37 @@ static void implicit_plane_lease(data_t *data)
drmSetClientCap(data->master.fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
}
static void lease_uevent(data_t *data)
{
int lease_fd;
struct local_drm_mode_list_lessees mll;
struct udev_monitor *uevent_monitor;
uevent_monitor = igt_watch_hotplug();
igt_flush_hotplugs(uevent_monitor);
lease_fd = create_simple_lease(data->master.fd, data);
igt_assert(!igt_lease_change_detected(uevent_monitor, 1));
mll.pad = 0;
mll.count_lessees = 0;
mll.lessees_ptr = 0;
igt_assert_eq(list_lessees(data->master.fd, &mll), 0);
igt_assert_eq(mll.count_lessees, 1);
close(lease_fd);
igt_assert(igt_lease_change_detected(uevent_monitor, 1));
mll.lessees_ptr = 0;
igt_assert_eq(list_lessees(data->master.fd, &mll), 0);
igt_assert_eq(mll.count_lessees, 0);
igt_cleanup_hotplug(uevent_monitor);
}
igt_main
{
data_t data;
......@@ -1021,4 +1054,7 @@ igt_main
igt_subtest("implicit-plane-lease")
implicit_plane_lease(&data);
igt_subtest("lease-uevent")
lease_uevent(&data);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment