Skip to contentSkip to conversation

lib: Require drmModeResources()

PATCH Superseded José Roberto de Souza 2 participants 4 messages Sep 13, 2018 Library code

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 lib: Require drmModeResources()

From: Chris Wilson <[email protected]>

If modesetting is not supported, the drmModeGetResources() call will fail with -EINVAL (or -ENOTSUPP). As no displays are connected, skip.

---
 lib/igt_kms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/igt_kms.c +1 -1
index 4563bfd9..c20cf1eb 100644
@@ -1857,7 +1857,7 @@ void igt_display_init(igt_display_t *display, int drm_fd)
 	display->drm_fd = drm_fd;
 
 	resources = drmModeGetResources(display->drm_fd);
-	igt_assert(resources);
+	igt_require(resources);
 
 	/*
 	 * We cache the number of pipes, that number is a physical limit of the
Signature · 6 lines
2.19.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#1 lore raw

PATCH v4 2/2 tests: Check and skip unhandled tests that needs display

'lib: Require drmModeResources()' take care of all tests that calls igt_display_init(), here handling other tests that needs display and do not call it.

v2:
- Not skipping all tests in debugfs_test, perf_pmu and perf_pmu, now skiping only the required subtests

v3:
- Renamed igt_require_display to igt_display_required, to keep naming consistent
- Added igt_display_available()
- Checking if display is available by quering a modeset capability instead of drmModeGetResources()
- Not skiping read_all_entries tests when display is disabled

v4:
- Using 'lib: Require drmModeResources()', so all tests already handled by that patch had the igt_display_require() call removed.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Ville Syrjälä <[email protected]>
---
 lib/igt_kms.c                     | 30 +++++++++++++-
 lib/igt_kms.h                     |  2 +
 tests/debugfs_test.c              | 15 +++++--
 tests/kms_3d.c                    |  1 +
 tests/kms_addfb_basic.c           |  4 +-
 tests/kms_draw_crc.c              |  1 +
 tests/kms_fbcon_fbt.c             |  1 +
 tests/kms_force_connector_basic.c |  1 +
 tests/kms_getfb.c                 |  4 +-
 tests/kms_hdmi_inject.c           |  1 +
 tests/kms_setmode.c               |  1 +
 tests/kms_sysfs_edid_timing.c     |  5 +++
 tests/kms_tv_load_detect.c        |  1 +
 tests/perf_pmu.c                  | 16 +++----
 tests/pm_lpsp.c                   |  1 +
 tests/pm_rpm.c                    | 69 ++++++++++++++++++++++++-------
 tests/prime_vgem.c                |  2 +
 tests/testdisplay.c               |  1 +
 18 files changed, 129 insertions(+), 27 deletions(-)
lib/igt_kms.c +29 -1
index c20cf1eb..2bc92c81 100644
@@ -2018,6 +2018,34 @@ int igt_display_get_n_pipes(igt_display_t *display)
 	return display->n_pipes;
 }
 
+/**
+ * igt_display_require:
+ * @drm_fd: a drm file descriptor
+ *
+ * Checks if driver supports modeset and have display enabled.
+ */
+void igt_display_require(int fd)
+{
+	bool available = igt_display_available(fd);
+	igt_require_f(available, "drm driver do not support modeset\n");
+}
+
+/**
+ * igt_display_available:
+ * @drm_fd: a drm file descriptor
+ *
+ * Return true if driver supports modeset and have display enabled.
+ */
+bool igt_display_available(int fd)
+{
+	uint64_t cap;
+
+	/* Check if driver support modeset by checking one of the modeset
+	 * specific capabilities, in case of error it is not supported.
+	 */
+	return !drmGetCap(fd, DRM_CAP_DUMB_BUFFER, &cap);
+}
+
 /**
  * igt_display_require_output:
  * @display: A pointer to an #igt_display_t structure
@@ -3895,7 +3923,7 @@ void igt_enable_connectors(void)
 	drm_fd = drm_open_driver(DRIVER_ANY);
 
 	res = drmModeGetResources(drm_fd);
-	igt_assert(res != NULL);
+	igt_require(res != NULL);
 
 	for (int i = 0; i < res->count_connectors; i++) {
 		drmModeConnector *c;
lib/igt_kms.h +2 -0
index 3862efa2..feafeda9 100644
@@ -388,6 +388,8 @@ void igt_display_commit_atomic(igt_display_t *display, uint32_t flags, void *use
 int  igt_display_try_commit2(igt_display_t *display, enum igt_commit_style s);
 int  igt_display_drop_events(igt_display_t *display);
 int  igt_display_get_n_pipes(igt_display_t *display);
+void igt_display_require(int fd);
+bool igt_display_available(int fd);
 void igt_display_require_output(igt_display_t *display);
 void igt_display_require_output_on_pipe(igt_display_t *display, enum pipe pipe);
 
tests/debugfs_test.c +12 -3
index 2e87e442..79243b1a 100644
@@ -102,10 +102,16 @@ igt_main
 		debugfs = igt_debugfs_dir(fd);
 
 		kmstest_set_vt_graphics_mode();
-		igt_display_init(&display, fd);
+		if (igt_display_available(fd))
+			igt_display_init(&display, fd);
+		else
+			display.n_pipes = 0;
 	}
 
 	igt_subtest("read_all_entries") {
+		if (!display.n_pipes)
+			goto skip_modeset;
+
 		/* try to light all pipes */
 		for_each_pipe(&display, pipe) {
 			igt_output_t *output;
@@ -132,7 +138,7 @@ igt_main
 		}
 
 		igt_display_commit2(&display, display.is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
-
+skip_modeset:
 		read_and_discard_sysfs_entries(debugfs, 0);
 	}
 
@@ -140,6 +146,9 @@ igt_main
 		igt_output_t *output;
 		igt_plane_t *plane;
 
+		if (!display.n_pipes)
+			goto skip_modeset2;
+
 		for_each_connected_output(&display, output)
 			igt_output_set_pipe(output, PIPE_NONE);
 
@@ -148,7 +157,7 @@ igt_main
 				igt_plane_set_fb(plane, NULL);
 
 		igt_display_commit2(&display, display.is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
-
+skip_modeset2:
 		read_and_discard_sysfs_entries(debugfs, 0);
 	}
 
tests/kms_3d.c +1 -0
index bfc981ee..18764c41 100644
@@ -36,6 +36,7 @@ igt_simple_main
 	int mode_count, connector_id;
 
 	drm_fd = drm_open_driver_master(DRIVER_INTEL);
+	igt_display_require(drm_fd);
 	res = drmModeGetResources(drm_fd);
 
 	igt_assert(drmSetClientCap(drm_fd, DRM_CLIENT_CAP_STEREO_3D, 1) >= 0);
tests/kms_addfb_basic.c +3 -1
index ce48d24f..5d3f9b85 100644
@@ -671,8 +671,10 @@ int fd;
 
 igt_main
 {
-	igt_fixture
+	igt_fixture {
 		fd = drm_open_driver_master(DRIVER_ANY);
+		igt_display_require(fd);
+	}
 
 	invalid_tests(fd);
 
tests/kms_draw_crc.c +1 -0
index 86dcf392..51c92b71 100644
@@ -251,6 +251,7 @@ static void setup_environment(void)
 
 	drm_fd = drm_open_driver_master(DRIVER_INTEL);
 	igt_require(drm_fd >= 0);
+	igt_display_require(drm_fd);
 
 	drm_res = drmModeGetResources(drm_fd);
 	igt_assert(drm_res->count_connectors <= MAX_CONNECTORS);
tests/kms_fbcon_fbt.c +1 -0
index 138eda9b..017be053 100644
@@ -293,6 +293,7 @@ static void setup_environment(void)
 
 	drm_fd = drm_open_driver_master(DRIVER_INTEL);
 	igt_require(drm_fd >= 0);
+	igt_display_require(drm_fd);
 	igt_assert(close(drm_fd) == 0);
 }
 
tests/kms_force_connector_basic.c +1 -0
index 89431232..720d79bd 100644
@@ -89,6 +89,7 @@ int main(int argc, char **argv)
 		unsigned vga_connector_id = 0;
 
 		drm_fd = drm_open_driver_master(DRIVER_INTEL);
+		igt_display_require(drm_fd);
 		res = drmModeGetResources(drm_fd);
 		igt_assert(res);
 
tests/kms_getfb.c +3 -1
index 81d796a4..67088883 100644
@@ -198,8 +198,10 @@ igt_main
 {
 	int fd;
 
-	igt_fixture
+	igt_fixture {
 		fd = drm_open_driver_master(DRIVER_ANY);
+		igt_display_require(fd);
+	}
 
 	igt_subtest_group
 		test_handle_input(fd);
tests/kms_hdmi_inject.c +1 -0
index 22570a4b..66ed2094 100644
@@ -254,6 +254,7 @@ igt_main
 
 	igt_fixture {
 		drm_fd = drm_open_driver_master(DRIVER_INTEL);
+		igt_display_require(drm_fd);
 		res = drmModeGetResources(drm_fd);
 
 		connector = get_connector(drm_fd, res);
tests/kms_setmode.c +1 -0
index 47d04fb5..93d9a76d 100644
@@ -854,6 +854,7 @@ int main(int argc, char **argv)
 
 	igt_fixture {
 		drm_fd = drm_open_driver_master(DRIVER_ANY);
+		igt_display_require(drm_fd);
 		if (!dry_run)
 			kmstest_set_vt_graphics_mode();
 
tests/kms_sysfs_edid_timing.c +5 -0
index 12013881..2a3350fe 100644
@@ -41,6 +41,11 @@ igt_simple_main
 {
 	DIR *dirp;
 	struct dirent *de;
+	int drm_fd;
+
+	drm_fd = drm_open_driver_master(DRIVER_ANY);
+	igt_display_require(drm_fd);
+	close(drm_fd);
 
 	dirp = opendir("/sys/class/drm");
 	igt_assert(dirp != NULL);
tests/kms_tv_load_detect.c +1 -0
index 5684b267..a05afd15 100644
@@ -37,6 +37,7 @@ int main(int argc, char **argv)
 
 	igt_fixture {
 		drm_fd = drm_open_driver_master(DRIVER_INTEL);
+		igt_display_require(drm_fd);
 		res = drmModeGetResources(drm_fd);
 		igt_assert(res);
 
tests/perf_pmu.c +9 -7
index 6ab2595b..83dd9ee2 100644
@@ -1395,15 +1395,17 @@ test_rc6(int gem_fd, unsigned int flags)
 	fd = open_pmu(I915_PMU_RC6_RESIDENCY);
 
 	if (flags & TEST_RUNTIME_PM) {
-		drmModeRes *res;
+		if (igt_display_available(gem_fd)) {
+			drmModeRes *res;
 
-		res = drmModeGetResources(gem_fd);
-		igt_assert(res);
+			res = drmModeGetResources(gem_fd);
+			igt_assert(res);
 
-		/* force all connectors off */
-		kmstest_set_vt_graphics_mode();
-		kmstest_unset_all_crtcs(gem_fd, res);
-		drmModeFreeResources(res);
+			/* force all connectors off */
+			kmstest_set_vt_graphics_mode();
+			kmstest_unset_all_crtcs(gem_fd, res);
+			drmModeFreeResources(res);
+		}
 
 		igt_require(igt_setup_runtime_pm());
 		igt_require(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED));
tests/pm_lpsp.c +1 -0
index a741cb78..01c8f79e 100644
@@ -195,6 +195,7 @@ igt_main
 
 		drm_fd = drm_open_driver_master(DRIVER_INTEL);
 		igt_require(drm_fd >= 0);
+		igt_display_require(drm_fd);
 
 		devid = intel_get_drm_devid(drm_fd);
 
tests/pm_rpm.c +55 -14

212 lines not on this page · raw message

tests/prime_vgem.c +2 -0
index b821fbb8..399e4ebe 100644
@@ -747,6 +747,8 @@ static void test_flip(int i915, int vgem, unsigned hang)
 	struct vgem_bo bo[2];
 	uint32_t fb_id[2], handle[2], crtc_id;
 
+	igt_display_require(i915);
+
 	signal(SIGHUP, sighandler);
 
 	for (int i = 0; i < 2; i++) {
tests/testdisplay.c +1 -0
index 0ff98a2b..28f64a75 100644
@@ -716,6 +716,7 @@ int main(int argc, char **argv)
 		test_all_modes = 1;
 
 	drm_fd = drm_open_driver(DRIVER_ANY);
+	igt_display_require(drm_fd);
 
 	if (test_stereo_modes &&
 	    drmSetClientCap(drm_fd, DRM_CLIENT_CAP_STEREO_3D, 1) < 0) {
Signature · 6 lines
2.19.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#2 lore raw

Re: [igt-dev] [PATCH i-g-t v4 2/2] tests: Check and skip unhandled tests that needs display

Quoting José Roberto de Souza (2018-09-13 21:39:35)

Quoted 111 lines

'lib: Require drmModeResources()' take care of all tests that calls igt_display_init(), here handling other tests that needs display and do not call it.

v2:
- Not skipping all tests in debugfs_test, perf_pmu and perf_pmu, now skiping only the required subtests

v3:
- Renamed igt_require_display to igt_display_required, to keep naming consistent
- Added igt_display_available()
- Checking if display is available by quering a modeset capability instead of drmModeGetResources()
- Not skiping read_all_entries tests when display is disabled

v4:
- Using 'lib: Require drmModeResources()', so all tests already handled by that patch had the igt_display_require() call removed.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Ville Syrjälä <[email protected]>
---
 lib/igt_kms.c                     | 30 +++++++++++++-
 lib/igt_kms.h                     |  2 +
 tests/debugfs_test.c              | 15 +++++--
 tests/kms_3d.c                    |  1 +
 tests/kms_addfb_basic.c           |  4 +-
 tests/kms_draw_crc.c              |  1 +
 tests/kms_fbcon_fbt.c             |  1 +
 tests/kms_force_connector_basic.c |  1 +
 tests/kms_getfb.c                 |  4 +-
 tests/kms_hdmi_inject.c           |  1 +
 tests/kms_setmode.c               |  1 +
 tests/kms_sysfs_edid_timing.c     |  5 +++
 tests/kms_tv_load_detect.c        |  1 +
 tests/perf_pmu.c                  | 16 +++----
 tests/pm_lpsp.c                   |  1 +
 tests/pm_rpm.c                    | 69 ++++++++++++++++++++++++-------
 tests/prime_vgem.c                |  2 +
 tests/testdisplay.c               |  1 +
 18 files changed, 129 insertions(+), 27 deletions(-)
lib/igt_kms.c +29 -1
index c20cf1eb..2bc92c81 100644
@@ -2018,6 +2018,34 @@ int igt_display_get_n_pipes(igt_display_t *display)
        return display->n_pipes;
 }
 
+/**
+ * igt_display_require:
+ * @drm_fd: a drm file descriptor
+ *
+ * Checks if driver supports modeset and have display enabled.
+ */
+void igt_display_require(int fd)
+{
+       bool available = igt_display_available(fd);
+       igt_require_f(available, "drm driver do not support modeset\n");
+}
+
+/**
+ * igt_display_available:
+ * @drm_fd: a drm file descriptor
+ *
+ * Return true if driver supports modeset and have display enabled.
+ */
+bool igt_display_available(int fd)
+{
+       uint64_t cap;
+
+       /* Check if driver support modeset by checking one of the modeset
+        * specific capabilities, in case of error it is not supported.
+        */
+       return !drmGetCap(fd, DRM_CAP_DUMB_BUFFER, &cap);
+}
+
 /**
  * igt_display_require_output:
  * @display: A pointer to an #igt_display_t structure
@@ -3895,7 +3923,7 @@ void igt_enable_connectors(void)
        drm_fd = drm_open_driver(DRIVER_ANY);
 
        res = drmModeGetResources(drm_fd);
-       igt_assert(res != NULL);
+       igt_require(res != NULL);
 
        for (int i = 0; i < res->count_connectors; i++) {
                drmModeConnector *c;
lib/igt_kms.h +2 -0
index 3862efa2..feafeda9 100644
@@ -388,6 +388,8 @@ void igt_display_commit_atomic(igt_display_t *display, uint32_t flags, void *use
 int  igt_display_try_commit2(igt_display_t *display, enum igt_commit_style s);
 int  igt_display_drop_events(igt_display_t *display);
 int  igt_display_get_n_pipes(igt_display_t *display);
+void igt_display_require(int fd);
+bool igt_display_available(int fd);
 void igt_display_require_output(igt_display_t *display);
 void igt_display_require_output_on_pipe(igt_display_t *display, enum pipe pipe);
 
tests/debugfs_test.c +0 -0
index 2e87e442..79243b1a 100644

tests/debugfs_test.c igt_main · line 108

Quoted 8 lines
tests/debugfs_test.c +4 -1
@@ -102,10 +102,16 @@ igt_main
                debugfs = igt_debugfs_dir(fd);
 
                kmstest_set_vt_graphics_mode();
-               igt_display_init(&display, fd);
+               if (igt_display_available(fd))
+                       igt_display_init(&display, fd);
+               else
+                       display.n_pipes = 0;

Bleurgh. That's why I wasn't so keen on display_init including the require.

Could we compromise by igt_require(igt_display_init(()); for tests that need it?

tests/debugfs_test.c igt_main · line 116

Quoted 8 lines
tests/debugfs_test.c +3 -0
        }
 
        igt_subtest("read_all_entries") {
+               if (!display.n_pipes)
+                       goto skip_modeset;
+
                /* try to light all pipes */
                for_each_pipe(&display, pipe) {

But why isn't for_each_pipe() a no-op if !n_pipes?

It seems to be for(pipe = 0; pipe < display.n_pipes; pipe++)

tests/debugfs_test.c igt_main · line 140

Quoted 5 lines
tests/debugfs_test.c +0 -0
                        igt_output_t *output;
@@ -132,7 +138,7 @@ igt_main
                }
 
                igt_display_commit2(&display, display.is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);

So presumably its ^. Something like

lib/igt_kms.c +7 -0
index 99d4c37..549d4e0 100644
@@ -3260,6 +3260,10 @@ static int do_display_commit(igt_display_t *display,
 {
        int i, ret = 0;
        enum pipe pipe;
+
+       if (!display->n_pipes)
+               return 0;
+
        LOG_INDENT(display, "commit");
 
        igt_display_refresh(display);
@@ -3312,6 +3316,9 @@ int igt_display_try_commit_atomic(igt_display_t *display, uint32_t flags, void *
 {
        int ret;
 
+       if (!display->n_pipes)
+               return 0;
+
        LOG_INDENT(display, "commit");
 
        igt_display_refresh(display);

as suitable defense.

Quoted 28 lines
tests/debugfs_test.c +5 -1
+skip_modeset:
                read_and_discard_sysfs_entries(debugfs, 0);
        }
 
@@ -140,6 +146,9 @@ igt_main
                igt_output_t *output;
                igt_plane_t *plane;
 
+               if (!display.n_pipes)
+                       goto skip_modeset2;
+
                for_each_connected_output(&display, output)
                        igt_output_set_pipe(output, PIPE_NONE);
 
@@ -148,7 +157,7 @@ igt_main
                                igt_plane_set_fb(plane, NULL);
 
                igt_display_commit2(&display, display.is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
-
+skip_modeset2:
                read_and_discard_sysfs_entries(debugfs, 0);
        }
 
tests/kms_3d.c +0 -0
index bfc981ee..18764c41 100644

tests/kms_3d.c igt_simple_main · line 42

Quoted 7 lines
tests/kms_3d.c +1 -0
@@ -36,6 +36,7 @@ igt_simple_main
        int mode_count, connector_id;
 
        drm_fd = drm_open_driver_master(DRIVER_INTEL);
+       igt_display_require(drm_fd);
        res = drmModeGetResources(drm_fd);
 
        igt_assert(drmSetClientCap(drm_fd, DRM_CLIENT_CAP_STEREO_3D, 1) >= 0);

s/igt_assert/igt_require/

tests/kms_addfb_basic.c int fd; · line 676

Quoted 12 lines
tests/kms_addfb_basic.c +2 -1
index ce48d24f..5d3f9b85 100644
@@ -671,8 +671,10 @@ int fd;
 
 igt_main
 {
-       igt_fixture
+       igt_fixture {
                fd = drm_open_driver_master(DRIVER_ANY);
+               igt_display_require(fd);

igt_require(has_addfb2()); is how we do it normally.

Quoted 9 lines
tests/kms_addfb_basic.c +1 -0
+       }
 
        invalid_tests(fd);
 
tests/kms_draw_crc.c +0 -0
index 86dcf392..51c92b71 100644

tests/kms_draw_crc.c static void setup_environment(void) · line 256

Quoted 6 lines
tests/kms_draw_crc.c +1 -0
@@ -251,6 +251,7 @@ static void setup_environment(void)
 
        drm_fd = drm_open_driver_master(DRIVER_INTEL);
        igt_require(drm_fd >= 0);
+       igt_display_require(drm_fd);
 
        drm_res = drmModeGetResources(drm_fd);

igt_require(drm_res)?

tests/kms_getfb.c igt_main · line 203

Quoted 12 lines
tests/kms_getfb.c +2 -1
index 81d796a4..67088883 100644
@@ -198,8 +198,10 @@ igt_main
 {
        int fd;
 
-       igt_fixture
+       igt_fixture {
                fd = drm_open_driver_master(DRIVER_ANY);
+               igt_display_require(fd);

This should be another igt_require(has_getfb());

So this looks like it becomes a lot simpler if we take the path of disallowing DRIVER_MODESET for INTEL_INFO()->num_pipes == 0 and suggest that all other drivers that allow disabling their KMS interface also drop the MODESET feature.
-Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#3 lore raw

Re: [igt-dev] [PATCH i-g-t v4 2/2] tests: Check and skip unhandled tests that needs display

Quoted 135 lines · Chris Wilson

Quoting José Roberto de Souza (2018-09-13 21:39:35)

Quoted 122 lines

'lib: Require drmModeResources()' take care of all tests that calls igt_display_init(), here handling other tests that needs display and
do not call it.

v2:
- Not skipping all tests in debugfs_test, perf_pmu and perf_pmu, now skiping only the required subtests

v3:
- Renamed igt_require_display to igt_display_required, to keep naming
consistent
- Added igt_display_available()
- Checking if display is available by quering a modeset capability instead of drmModeGetResources()
- Not skiping read_all_entries tests when display is disabled

v4:
- Using 'lib: Require drmModeResources()', so all tests already handled by that patch had the igt_display_require() call removed.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Ville Syrjälä <[email protected]>
---
 lib/igt_kms.c                     | 30 +++++++++++++-
 lib/igt_kms.h                     |  2 +
 tests/debugfs_test.c              | 15 +++++--
 tests/kms_3d.c                    |  1 +
 tests/kms_addfb_basic.c           |  4 +-
 tests/kms_draw_crc.c              |  1 +
 tests/kms_fbcon_fbt.c             |  1 +
 tests/kms_force_connector_basic.c |  1 +
 tests/kms_getfb.c                 |  4 +-
 tests/kms_hdmi_inject.c           |  1 +
 tests/kms_setmode.c               |  1 +
 tests/kms_sysfs_edid_timing.c     |  5 +++
 tests/kms_tv_load_detect.c        |  1 +
 tests/perf_pmu.c                  | 16 +++----
 tests/pm_lpsp.c                   |  1 +
 tests/pm_rpm.c                    | 69 ++++++++++++++++++++++++---
----
 tests/prime_vgem.c                |  2 +
 tests/testdisplay.c               |  1 +
 18 files changed, 129 insertions(+), 27 deletions(-)
lib/igt_kms.c +17 -0
index c20cf1eb..2bc92c81 100644
@@ -2018,6 +2018,34 @@ int igt_display_get_n_pipes(igt_display_t
 *display)
        return display->n_pipes;
 }
 
+/**
+ * igt_display_require:
+ * @drm_fd: a drm file descriptor
+ *
+ * Checks if driver supports modeset and have display enabled.
+ */
+void igt_display_require(int fd)
+{
+       bool available = igt_display_available(fd);
+       igt_require_f(available, "drm driver do not support
 modeset\n");
+}
+
+/**
+ * igt_display_available:
+ * @drm_fd: a drm file descriptor
+ *
+ * Return true if driver supports modeset and have display

enabled.
+ */

lib/igt_kms.c +5 -0
+bool igt_display_available(int fd)
+{
+       uint64_t cap;
+
+       /* Check if driver support modeset by checking one of the

modeset
+ * specific capabilities, in case of error it is not
supported.

lib/igt_kms.c +5 -1
+        */
+       return !drmGetCap(fd, DRM_CAP_DUMB_BUFFER, &cap);
+}
+
 /**
  * igt_display_require_output:
  * @display: A pointer to an #igt_display_t structure
@@ -3895,7 +3923,7 @@ void igt_enable_connectors(void)
        drm_fd = drm_open_driver(DRIVER_ANY);
 
        res = drmModeGetResources(drm_fd);
-       igt_assert(res != NULL);
+       igt_require(res != NULL);
 
        for (int i = 0; i < res->count_connectors; i++) {
                drmModeConnector *c;
lib/igt_kms.h +2 -0
index 3862efa2..feafeda9 100644
@@ -388,6 +388,8 @@ void igt_display_commit_atomic(igt_display_t
 *display, uint32_t flags, void *use
 int  igt_display_try_commit2(igt_display_t *display, enum
 igt_commit_style s);
 int  igt_display_drop_events(igt_display_t *display);
 int  igt_display_get_n_pipes(igt_display_t *display);
+void igt_display_require(int fd);
+bool igt_display_available(int fd);
 void igt_display_require_output(igt_display_t *display);

void igt_display_require_output_on_pipe(igt_display_t *display,
enum pipe pipe);

tests/debugfs_test.c +0 -0
index 2e87e442..79243b1a 100644

tests/debugfs_test.c igt_main · line 108

Quoted 8 lines
tests/debugfs_test.c +4 -1
@@ -102,10 +102,16 @@ igt_main
                debugfs = igt_debugfs_dir(fd);
 
                kmstest_set_vt_graphics_mode();
-               igt_display_init(&display, fd);
+               if (igt_display_available(fd))
+                       igt_display_init(&display, fd);
+               else
+                       display.n_pipes = 0;

Bleurgh. That's why I wasn't so keen on display_init including the require.

Quoted 3 lines

Could we compromise by igt_require(igt_display_init(()); for tests that
need it?

You mean zero igt_display_t when KMS is not suported and return false? If so, it will add igt_require(igt_display_init(()); to several tests, I don't think it is worthy to just make debugfs_test more pretty.

Quoted 10 lines

tests/debugfs_test.c igt_main · line 116

Quoted 9 lines
tests/debugfs_test.c +3 -0
        }
 
        igt_subtest("read_all_entries") {
+               if (!display.n_pipes)
+                       goto skip_modeset;
+
                /* try to light all pipes */
                for_each_pipe(&display, pipe) {
Quoted 3 lines

But why isn't for_each_pipe() a no-op if !n_pipes?

It seems to be for(pipe = 0; pipe < display.n_pipes; pipe++)

As you got bellow it fails in the igt_display_commit2, here just skiping both before hand but I'm fine with both ways.

Quoted 38 lines

tests/debugfs_test.c igt_main · line 141

Quoted 7 lines
tests/debugfs_test.c +0 -0
                        igt_output_t *output;
@@ -132,7 +138,7 @@ igt_main
                }
 
                igt_display_commit2(&display, display.is_atomic ?
 COMMIT_ATOMIC : COMMIT_LEGACY);

So presumably its ^. Something like

lib/igt_kms.c +4 -0
index 99d4c37..549d4e0 100644
@@ -3260,6 +3260,10 @@ static int do_display_commit(igt_display_t
 *display,
 {
        int i, ret = 0;
        enum pipe pipe;
+
+       if (!display->n_pipes)
+               return 0;
+
        LOG_INDENT(display, "commit");
 
        igt_display_refresh(display);
lib/igt_kms.c +3 -0
@@ -3312,6 +3316,9 @@ int igt_display_try_commit_atomic(igt_display_t
 *display, uint32_t flags, void *
 {
        int ret;
 
+       if (!display->n_pipes)
+               return 0;
+
        LOG_INDENT(display, "commit");
 
        igt_display_refresh(display);
Quoted 1 line

as suitable defense.

not sure, it may be misleading return 0 in those functions, if DRIVER_MODESET is unset user would not even be able to initialize igt_display_t anyways unless we go by your 'igt_require(igt_display_init(())' suggestion.

Quoted 32 lines
Quoted 32 lines
tests/debugfs_test.c +5 -1
+skip_modeset:
                read_and_discard_sysfs_entries(debugfs, 0);
        }
@@ -140,6 +146,9 @@ igt_main
                igt_output_t *output;
                igt_plane_t *plane;
 
+               if (!display.n_pipes)
+                       goto skip_modeset2;
+
                for_each_connected_output(&display, output)
                        igt_output_set_pipe(output, PIPE_NONE);
 
@@ -148,7 +157,7 @@ igt_main
                                igt_plane_set_fb(plane, NULL);
 
                igt_display_commit2(&display, display.is_atomic ?
 COMMIT_ATOMIC : COMMIT_LEGACY);
-
+skip_modeset2:
                read_and_discard_sysfs_entries(debugfs, 0);
        }
tests/kms_3d.c +0 -0
index bfc981ee..18764c41 100644
@@ -36,6 +36,7 @@ igt_simple_main
        int mode_count, connector_id;
 
Quoted 8 lines
Quoted 6 lines
tests/kms_3d.c +1 -0
        drm_fd = drm_open_driver_master(DRIVER_INTEL);
+       igt_display_require(drm_fd);
        res = drmModeGetResources(drm_fd);
 
        igt_assert(drmSetClientCap(drm_fd,

DRM_CLIENT_CAP_STEREO_3D, 1) >= 0);

s/igt_assert/igt_require/

drm_setclientcap() is returning 0 for every client capability even with DRIVER_MODESET unset. I sent a patch fixing it in kernel so we can use igt_require here.

Quoted 7 lines
Quoted 7 lines
tests/kms_addfb_basic.c +0 -0
index ce48d24f..5d3f9b85 100644
@@ -671,8 +671,10 @@ int fd;
 
Quoted 8 lines

tests/kms_addfb_basic.c int fd; · line 676

Quoted 6 lines
tests/kms_addfb_basic.c +2 -1
 igt_main
 {
-       igt_fixture
+       igt_fixture {
                fd = drm_open_driver_master(DRIVER_ANY);
+               igt_display_require(fd);

igt_require(has_addfb2()); is how we do it normally.

I saw your patch adding that but as you are still waiting for comments in kernel patches, so skiping it for now.

Quoted 11 lines
Quoted 11 lines
tests/kms_addfb_basic.c +1 -0
+       }
 
        invalid_tests(fd);
 
tests/kms_draw_crc.c +0 -0
index 86dcf392..51c92b71 100644
@@ -251,6 +251,7 @@ static void setup_environment(void)
 
Quoted 7 lines

tests/kms_draw_crc.c static void setup_environment(void) · line 256

Quoted 5 lines
tests/kms_draw_crc.c +1 -0
        drm_fd = drm_open_driver_master(DRIVER_INTEL);
        igt_require(drm_fd >= 0);
+       igt_display_require(drm_fd);
 
        drm_res = drmModeGetResources(drm_fd);

igt_require(drm_res)?

Sounds good, applying this to the other similar cases.

There is now only 4 users of igt_display_require()
- kms_addfb_basic
- kms_getfb
both will die when you patches are merged
- prime_vgem
it uses DRM_IOCTL_MODE_ADDFB2 and drmModePageFlip() the second
one returns -EINVAL with KMS disbaled and for other error cases, so I guess is better just skip in the begiging of test_flip() with igt_display_require()
- pm_rpm
discussed above

And igt_display_available() have:
- debugfs_test
discussed above

Quoted 16 lines

tests/kms_getfb.c igt_main · line 203

Quoted 13 lines
tests/kms_getfb.c +2 -1
index 81d796a4..67088883 100644
@@ -198,8 +198,10 @@ igt_main
 {
        int fd;
 
-       igt_fixture
+       igt_fixture {
                fd = drm_open_driver_master(DRIVER_ANY);
+               igt_display_require(fd);

This should be another igt_require(has_getfb());

Quoted 6 lines

So this looks like it becomes a lot simpler if we take the path of disallowing DRIVER_MODESET for INTEL_INFO()->num_pipes == 0 and suggest
that all other drivers that allow disabling their KMS interface also drop the MODESET feature.
-Chris

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev