Skip to contentSkip to conversation

tests/kms_dp_dsc: Force a full modeset when we force dsc enable

PATCH Superseded Manasi Navare 3 participants 8 messages Apr 5, 2019 – Apr 8, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tests/kms_dp_dsc: Force a full modeset when we force dsc enable

DSC enable gets configured during compute_config and needs a full modeset to force DSC.
Sometimes in between the tests, if the initial output is same as the mode being set for DSC then it will not do a full modeset. So we disable the output before forcing a mode with DSC enable.

You need the kernel patch:
https://patchwork.freedesktop.org/series/59084/

v2:
* Restore the value of force dsc enable after the test and in igt_exit_handler
* Add igt_install_exit_handler to restore values on fail/exit

Fixes db19bccc1c22 ("test/kms_dp_dsc: Basic KMS test to validate VESA DSC on DP/eDP")
Cc Petri Latvala <[email protected]>
Cc Anusha Srivatsa <[email protected]>
Cc Imre Deak <[email protected]>
---
 tests/kms_dp_dsc.c | 133 +++++++++++++++++++++++++++------------------
 1 file changed, 81 insertions(+), 52 deletions(-)
tests/kms_dp_dsc.c +81 -52
index da93cd74..acaee890 100644
@@ -63,119 +63,147 @@ typedef struct {
 	int crtc;
 	enum pipe pipe;
 	char conn_name[128];
+	bool force_dsc_en;
 } data_t;
 
+data_t data = {};
+
 static inline void manual(const char *expected)
 {
 	igt_debug_manual_check("all", expected);
 }
 
-static bool is_dp_dsc_supported(data_t *data)
+static bool is_dp_dsc_supported(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_require(igt_debugfs_simple_read(data->debugfs_fd, file_name, buf,
+	igt_require(igt_debugfs_simple_read(data.debugfs_fd, file_name, buf,
 					    sizeof(buf)) > 0);
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "DSC_Sink_Support: yes");
 }
 
-static bool is_dp_fec_supported(data_t *data)
+static bool is_dp_fec_supported(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "FEC_Sink_Support: yes");
 }
 
-static bool is_dp_dsc_enabled(data_t *data)
+static bool is_dp_dsc_enabled(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "DSC_Enabled: yes");
 }
 
-static void force_dp_dsc_enable(data_t *data)
+static bool is_force_dsc_enabled(void)
+{
+	char file_name[128] = {0};
+	char buf[512];
+
+	strcpy(file_name, data.conn_name);
+	strcat(file_name, "/i915_dsc_fec_support");
+	igt_debugfs_read(data.drm_fd, file_name, buf);
+
+	return strstr(buf, "Force_DSC_Enable: yes");
+}
+
+static void force_dp_dsc_enable(void)
 {
 	char file_name[128] = {0};
 	int ret;
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debug ("Forcing DSC enable on %s\n", data->conn_name);
-	ret = igt_sysfs_write(data->debugfs_fd, file_name, "1", 1);
+	igt_debug ("Forcing DSC enable on %s\n", data.conn_name);
+	ret = igt_sysfs_write(data.debugfs_fd, file_name, "1", 1);
 	igt_assert_f(ret > 0, "debugfs_write failed");
 }
 
-static void clear_dp_dsc_enable(data_t *data)
+static void restore_dp_dsc_enable(void)
 {
 	char file_name[128] = {0};
 	int ret;
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debug ("Clearing DSC enable on %s\n", data->conn_name);
-	ret = igt_sysfs_write(data->debugfs_fd, file_name, "0", 1);
+	igt_debug ("Restoring DSC enable on %s\n", data.conn_name);
+	ret = igt_sysfs_write(data.debugfs_fd, file_name,
+			      data.force_dsc_en ? "1" : "0", 1);
 	igt_assert_f(ret > 0, "debugfs_write failed");
 }
 
-static void test_cleanup(data_t *data) {
+static void test_cleanup(void) {
 	igt_plane_t *primary;
 
-	if (data->output) {
-		primary = igt_output_get_plane_type(data->output,
+	if (data.output) {
+		primary = igt_output_get_plane_type(data.output,
 						    DRM_PLANE_TYPE_PRIMARY);
 		igt_plane_set_fb(primary, NULL);
-		igt_display_commit(&data->display);
-		igt_remove_fb(data->drm_fd, &data->fb_test_pattern);
+		igt_display_commit(&data.display);
+		igt_remove_fb(data.drm_fd, &data.fb_test_pattern);
 	}
 }
 
+static void kms_dp_dsc_exit_handler(int sig) {
+
+	restore_dp_dsc_enable();
+}
+
 
 /*
  * Re-probe connectors and do a modeset with DSC
  *
  */
-static void update_display(data_t *data, enum dsc_test_type test_type)
+static void update_display(enum dsc_test_type test_type)
 {
 	igt_plane_t *primary;
-	data->mode = igt_output_get_mode(data->output);
-	data->connector = data->output->config.connector;
+	data.mode = igt_output_get_mode(data.output);
+	data.connector = data.output->config.connector;
 
-	if (data->connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
-	    data->pipe == PIPE_A) {
+	if (data.connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
+	    data.pipe == PIPE_A) {
 		igt_debug("DSC not supported on Pipe A on external DP\n");
 		return;
 	}
 
+	/* Disable the output first */
+	igt_output_set_pipe(data.output, PIPE_NONE);
+	igt_display_commit(&data.display);
+
 	if (test_type == test_basic_dsc_enable) {
 		bool enabled;
 
-		igt_debug("DSC is supported on %s\n", data->conn_name);
-		force_dp_dsc_enable(data);
+		igt_debug("DSC is supported on %s\n", data.conn_name);
+		force_dp_dsc_enable();
 
-		igt_create_pattern_fb(data->drm_fd, data->mode->hdisplay,
-				      data->mode->vdisplay,
+		igt_output_set_pipe(data.output, data.pipe);
+		igt_create_pattern_fb(data.drm_fd, data.mode->hdisplay,
+				      data.mode->vdisplay,
 				      DRM_FORMAT_XRGB8888,
 				      LOCAL_DRM_FORMAT_MOD_NONE,
-				      &data->fb_test_pattern);
-		primary = igt_output_get_plane_type(data->output,
+				      &data.fb_test_pattern);
+		primary = igt_output_get_plane_type(data.output,
 						    DRM_PLANE_TYPE_PRIMARY);
-		igt_plane_set_fb(primary, &data->fb_test_pattern);
-		igt_display_commit(&data->display);
+
+		/* Now set the output to the desired mode */
+		igt_plane_set_fb(primary, &data.fb_test_pattern);
+		igt_display_commit(&data.display);
 
 		/*
 		 * Until we have CRC check support, manually check if RGB test
@@ -183,38 +211,37 @@ static void update_display(data_t *data, enum dsc_test_type test_type)
 		 */
 		manual("RGB test pattern without corruption");
 
-		enabled = is_dp_dsc_enabled(data);
-		clear_dp_dsc_enable(data);
+		enabled = is_dp_dsc_enabled();
+		restore_dp_dsc_enable();
 
 		igt_assert_f(enabled,
-			     "Default DSC enable failed on Connector: %s Pipe: %s",
-			     data->conn_name,
-			     kmstest_pipe_name(data->pipe));
+			     "Default DSC enable failed on Connector: %s Pipe: %s\n",
+			     data.conn_name,
+			     kmstest_pipe_name(data.pipe));
 	} else {
 		igt_assert(!"Unknown test type\n");
 	}
 }
 
-static void run_test(data_t *data, igt_output_t *output,
+static void run_test(igt_output_t *output,
 		     enum dsc_test_type test_type)
 {
 	enum pipe pipe;
 
-	for_each_pipe(&data->display, pipe) {
+	for_each_pipe(&data.display, pipe) {
 
 		if (igt_pipe_connector_valid(pipe, output)) {
-			igt_output_set_pipe(output, pipe);
-			data->pipe = pipe;
-			data->output = output;
-			update_display(data, test_type);
-			test_cleanup(data);
+			data.pipe = pipe;
+			data.output = output;
+			update_display(test_type);
+			test_cleanup();
 		}
 	}
 }
 
 igt_main
 {
-	data_t data = {};
+	//data_t data = {};
 	igt_output_t *output;
 	drmModeRes *res;
 	drmModeConnector *connector;
@@ -225,6 +252,7 @@ igt_main
 		data.drm_fd = drm_open_driver_master(DRIVER_ANY);
 		data.debugfs_fd = igt_debugfs_dir(data.drm_fd);
 		kmstest_set_vt_graphics_mode();
+		igt_install_exit_handler(kms_dp_dsc_exit_handler);
 		igt_display_require(&data.display, data.drm_fd);
 		igt_require(res = drmModeGetResources(data.drm_fd));
 	}
@@ -245,19 +273,20 @@ igt_main
 				sprintf(data.conn_name, "%s-%d",
 					kmstest_connector_type_str(connector->connector_type),
 					connector->connector_type_id);
-				if(!is_dp_dsc_supported(&data)) {
+				if(!is_dp_dsc_supported()) {
 					igt_debug("DSC not supported on connector %s \n",
 						  data.conn_name);
 					continue;
 				}
 				if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
-				    !is_dp_fec_supported(&data)) {
+				    !is_dp_fec_supported()) {
 					igt_debug("DSC cannot be enabled without FEC on %s\n",
 						  data.conn_name);
 					continue;
 				}
 				test_conn_cnt++;
-				run_test(&data, output, test_basic_dsc_enable);
+				data.force_dsc_en = is_force_dsc_enabled();
+				run_test(output, test_basic_dsc_enable);
 			}
 			igt_skip_on(test_conn_cnt == 0);
 		}
Signature · 6 lines
2.19.1

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

[igt-dev] ✓ Fi.CI.BAT: success for tests/kms_dp_dsc: Force a full modeset when we force dsc enable (rev2)

== Series Details ==

== Series Details ==

Series: tests/kms_dp_dsc: Force a full modeset when we force dsc enable (rev2)
URL : https://patchwork.freedesktop.org/series/58887/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_5882 -> IGTPW_2804
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://patchwork.freedesktop.org/api/1.0/series/58887/revisions/2/mbox/

Known issues
------------

Here are the changes found in IGTPW_2804 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_exec_suspend@basic-s3:
- fi-blb-e6850: PASS -> INCOMPLETE [fdo#107718]

* igt@i915_selftest@live_contexts:
- fi-bdw-gvtdvm: PASS -> DMESG-FAIL [fdo#110235 ]

* igt@kms_frontbuffer_tracking@basic:
- fi-byt-clapper: PASS -> FAIL [fdo#103167]

#### Possible fixes ####

* igt@i915_pm_rpm@module-reload:
- fi-skl-6770hq: DMESG-WARN [fdo#105541] -> PASS
- {fi-icl-u3}: DMESG-WARN [fdo#107724] -> PASS

* igt@kms_pipe_crc_basic@hang-read-crc-pipe-a:
- fi-byt-clapper: FAIL [fdo#103191] / [fdo#107362] -> PASS +1

* igt@kms_pipe_crc_basic@read-crc-pipe-b:
- fi-byt-clapper: FAIL [fdo#107362] -> PASS

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
[fdo#103191]: https://bugs.freedesktop.org/show_bug.cgi?id=103191
[fdo#105541]: https://bugs.freedesktop.org/show_bug.cgi?id=105541
[fdo#107362]: https://bugs.freedesktop.org/show_bug.cgi?id=107362
[fdo#107718]: https://bugs.freedesktop.org/show_bug.cgi?id=107718
[fdo#107724]: https://bugs.freedesktop.org/show_bug.cgi?id=107724
[fdo#110235 ]: https://bugs.freedesktop.org/show_bug.cgi?id=110235

Participating hosts (50 -> 42)
------------------------------

Missing (8): fi-kbl-soraka fi-ilk-m540 fi-byt-j1900 fi-byt-squawks fi-bsw-cyan fi-gdg-551 fi-bdw-samus fi-skl-6600u

Build changes
-------------

* IGT: IGT_4932 -> IGTPW_2804

CI_DRM_5882: 012535789c9c890854cd1e0fb926f44931a82a63 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_2804: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2804/
IGT_4932: 08cf63a8fac11e3594b57580331fb319241a0d69 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2804/
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#2 lore raw

[igt-dev] ✓ Fi.CI.IGT: success for tests/kms_dp_dsc: Force a full modeset when we force dsc enable (rev2)

In reply to Manasi Navare
== Series Details ==

== Series Details ==

Series: tests/kms_dp_dsc: Force a full modeset when we force dsc enable (rev2)
URL : https://patchwork.freedesktop.org/series/58887/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_5882_full -> IGTPW_2804_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://patchwork.freedesktop.org/api/1.0/series/58887/revisions/2/mbox/

Known issues
------------

Here are the changes found in IGTPW_2804_full that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_eio@reset-stress:
- shard-snb: PASS -> FAIL [fdo#109661]

* igt@gem_exec_suspend@basic-s3:
- shard-apl: PASS -> DMESG-WARN [fdo#108566]

* igt@i915_pm_rps@min-max-config-loaded:
- shard-apl: PASS -> FAIL [fdo#102250]

* igt@kms_atomic_transition@3x-modeset-transitions:
- shard-snb: NOTRUN -> SKIP [fdo#109271] / [fdo#109278] +12

* igt@kms_atomic_transition@3x-modeset-transitions-fencing:
- shard-kbl: NOTRUN -> SKIP [fdo#109271] / [fdo#109278]

* igt@kms_atomic_transition@plane-all-modeset-transition-internal-panels:
- shard-kbl: NOTRUN -> SKIP [fdo#109271] +23

* igt@kms_busy@extended-modeset-hang-newfb-render-a:
- shard-hsw: PASS -> DMESG-WARN [fdo#110222] +1

* igt@kms_busy@extended-modeset-hang-newfb-render-b:
- shard-kbl: PASS -> DMESG-WARN [fdo#110222]

* igt@kms_busy@extended-modeset-hang-newfb-with-reset-render-b:
- shard-snb: PASS -> DMESG-WARN [fdo#110222] +2

* igt@kms_content_protection@legacy:
- shard-snb: NOTRUN -> SKIP [fdo#109271] +72

* igt@kms_cursor_legacy@2x-long-flip-vs-cursor-atomic:
- shard-glk: PASS -> FAIL [fdo#104873]

* igt@kms_flip@2x-flip-vs-expired-vblank:
- shard-glk: PASS -> FAIL [fdo#105363]

* igt@kms_frontbuffer_tracking@fbcpsr-shrfb-scaledprimary:
- shard-apl: NOTRUN -> SKIP [fdo#109271] +12

* igt@kms_plane_alpha_blend@pipe-b-alpha-basic:
- shard-kbl: NOTRUN -> FAIL [fdo#108145] / [fdo#108590]

* igt@kms_plane_scaling@pipe-c-scaler-with-pixel-format:
- shard-glk: PASS -> SKIP [fdo#109271] / [fdo#109278]

* igt@kms_rotation_crc@multiplane-rotation-cropping-top:
- shard-kbl: PASS -> FAIL [fdo#109016]

* igt@kms_vblank@pipe-a-accuracy-idle:
- shard-glk: PASS -> FAIL [fdo#102583]

* igt@kms_vblank@pipe-c-ts-continuation-modeset-rpm:
- shard-apl: PASS -> FAIL [fdo#104894]

* igt@prime_nv_api@i915_self_import:
- shard-glk: NOTRUN -> SKIP [fdo#109271] +7

#### Possible fixes ####

* igt@i915_pm_rc6_residency@rc6-accuracy:
- shard-snb: SKIP [fdo#109271] -> PASS

* igt@i915_suspend@sysfs-reader:
- shard-kbl: INCOMPLETE [fdo#103665] -> PASS

* igt@kms_busy@extended-modeset-hang-newfb-with-reset-render-c:
- shard-hsw: DMESG-WARN [fdo#110222] -> PASS
- shard-kbl: DMESG-WARN [fdo#110222] -> PASS

* igt@kms_color@pipe-a-ctm-max:
- shard-kbl: FAIL [fdo#108147] -> PASS
- shard-apl: FAIL [fdo#108147] -> PASS

* igt@kms_cursor_crc@cursor-64x64-sliding:
- shard-apl: FAIL [fdo#103232] -> PASS
- shard-kbl: FAIL [fdo#103232] -> PASS

* igt@kms_cursor_legacy@2x-long-nonblocking-modeset-vs-cursor-atomic:
- shard-glk: FAIL [fdo#106509] / [fdo#107409] -> PASS

* igt@kms_flip@2x-flip-vs-expired-vblank-interruptible:
- shard-glk: FAIL [fdo#105363] -> PASS

* igt@kms_frontbuffer_tracking@fbc-2p-scndscrn-shrfb-plflip-blt:
- shard-glk: FAIL [fdo#103167] -> PASS

* igt@kms_vblank@pipe-b-ts-continuation-modeset-rpm:
- shard-apl: FAIL [fdo#104894] -> PASS +1
- shard-kbl: FAIL [fdo#104894] -> PASS +1

[fdo#102250]: https://bugs.freedesktop.org/show_bug.cgi?id=102250
[fdo#102583]: https://bugs.freedesktop.org/show_bug.cgi?id=102583
[fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
[fdo#103232]: https://bugs.freedesktop.org/show_bug.cgi?id=103232
[fdo#103665]: https://bugs.freedesktop.org/show_bug.cgi?id=103665
[fdo#104873]: https://bugs.freedesktop.org/show_bug.cgi?id=104873
[fdo#104894]: https://bugs.freedesktop.org/show_bug.cgi?id=104894
[fdo#105363]: https://bugs.freedesktop.org/show_bug.cgi?id=105363
[fdo#106509]: https://bugs.freedesktop.org/show_bug.cgi?id=106509
[fdo#107409]: https://bugs.freedesktop.org/show_bug.cgi?id=107409
[fdo#108145]: https://bugs.freedesktop.org/show_bug.cgi?id=108145
[fdo#108147]: https://bugs.freedesktop.org/show_bug.cgi?id=108147
[fdo#108566]: https://bugs.freedesktop.org/show_bug.cgi?id=108566
[fdo#108590]: https://bugs.freedesktop.org/show_bug.cgi?id=108590
[fdo#109016]: https://bugs.freedesktop.org/show_bug.cgi?id=109016
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109278]: https://bugs.freedesktop.org/show_bug.cgi?id=109278
[fdo#109661]: https://bugs.freedesktop.org/show_bug.cgi?id=109661
[fdo#110222]: https://bugs.freedesktop.org/show_bug.cgi?id=110222

Participating hosts (10 -> 5)
------------------------------

Missing (5): shard-skl pig-hsw-4770r pig-glk-j5005 shard-iclb pig-skl-6260u

Build changes
-------------

* IGT: IGT_4932 -> IGTPW_2804
* Piglit: piglit_4509 -> None

CI_DRM_5882: 012535789c9c890854cd1e0fb926f44931a82a63 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_2804: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2804/
IGT_4932: 08cf63a8fac11e3594b57580331fb319241a0d69 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2804/
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#3 lore raw
In reply to Manasi Navare
Quoted 27 lines · Manasi Navare

DSC enable gets configured during compute_config and needs a full modeset to force DSC.
Sometimes in between the tests, if the initial output is same as the mode being set for DSC then it will not do a full modeset. So we disable the output before forcing a mode with DSC enable.

You need the kernel patch:
https://patchwork.freedesktop.org/series/59084/

v2:
* Restore the value of force dsc enable after the test and in igt_exit_handler
* Add igt_install_exit_handler to restore values on fail/exit

Fixes db19bccc1c22 ("test/kms_dp_dsc: Basic KMS test to validate VESA DSC on DP/eDP")
Cc Petri Latvala <[email protected]>
Cc Anusha Srivatsa <[email protected]>
Cc Imre Deak <[email protected]>
---
 tests/kms_dp_dsc.c | 133 +++++++++++++++++++++++++++------------------
 1 file changed, 81 insertions(+), 52 deletions(-)
tests/kms_dp_dsc.c +0 -0
index da93cd74..acaee890 100644

tests/kms_dp_dsc.c typedef struct { · line 66

Quoted 4 lines
tests/kms_dp_dsc.c +1 -0
@@ -63,119 +63,147 @@ typedef struct {
 	int crtc;
 	enum pipe pipe;
 	char conn_name[128];
+	bool force_dsc_en;

force_dsc_en_orig?

tests/kms_dp_dsc.c typedef struct { · line 70

Quoted 4 lines
tests/kms_dp_dsc.c +2 -0
 } data_t;
 
+data_t data = {};
+

Maybe make only debugfs_fd and force_dsc_en_orig global to reduce the churn? Also init debugfs_fd to -1, so the exit handler knows if it's been closed already.

Quoted 73 lines
tests/kms_dp_dsc.c +24 -12
 static inline void manual(const char *expected)
 {
 	igt_debug_manual_check("all", expected);
 }
 
-static bool is_dp_dsc_supported(data_t *data)
+static bool is_dp_dsc_supported(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_require(igt_debugfs_simple_read(data->debugfs_fd, file_name, buf,
+	igt_require(igt_debugfs_simple_read(data.debugfs_fd, file_name, buf,
 					    sizeof(buf)) > 0);
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "DSC_Sink_Support: yes");
 }
 
-static bool is_dp_fec_supported(data_t *data)
+static bool is_dp_fec_supported(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "FEC_Sink_Support: yes");
 }
 
-static bool is_dp_dsc_enabled(data_t *data)
+static bool is_dp_dsc_enabled(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "DSC_Enabled: yes");
 }
 
-static void force_dp_dsc_enable(data_t *data)
+static bool is_force_dsc_enabled(void)
+{
+	char file_name[128] = {0};
+	char buf[512];
+
+	strcpy(file_name, data.conn_name);
+	strcat(file_name, "/i915_dsc_fec_support");
+	igt_debugfs_read(data.drm_fd, file_name, buf);
+
+	return strstr(buf, "Force_DSC_Enable: yes");
+}
+
+static void force_dp_dsc_enable(void)
 {
 	char file_name[128] = {0};
 	int ret;
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);

tests/kms_dp_dsc.c typedef struct { · line 138

Quoted 10 lines
tests/kms_dp_dsc.c +3 -3
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debug ("Forcing DSC enable on %s\n", data->conn_name);
-	ret = igt_sysfs_write(data->debugfs_fd, file_name, "1", 1);
+	igt_debug ("Forcing DSC enable on %s\n", data.conn_name);
+	ret = igt_sysfs_write(data.debugfs_fd, file_name, "1", 1);
 	igt_assert_f(ret > 0, "debugfs_write failed");
 }
 
-static void clear_dp_dsc_enable(data_t *data)
+static void restore_dp_dsc_enable(void)

Better named as restore_force_dsc_en()?

tests/kms_dp_dsc.c typedef struct { · line 130

Quoted 4 lines
tests/kms_dp_dsc.c +0 -0
 {
 	char file_name[128] = {0};
 	int ret;
 

You need to check if the sig handler was called multiple times for some reason:

	if (debugfs_fd < 0)
		return;

tests/kms_dp_dsc.c typedef struct { · line 147

Quoted 8 lines
tests/kms_dp_dsc.c +4 -3
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debug ("Clearing DSC enable on %s\n", data->conn_name);
-	ret = igt_sysfs_write(data->debugfs_fd, file_name, "0", 1);
+	igt_debug ("Restoring DSC enable on %s\n", data.conn_name);
+	ret = igt_sysfs_write(data.debugfs_fd, file_name,
+			      data.force_dsc_en ? "1" : "0", 1);
	close(debugfs_fd);
	debugfs_fd = -1;
Quoted 118 lines
tests/kms_dp_dsc.c +39 -30
 	igt_assert_f(ret > 0, "debugfs_write failed");
 }
 
-static void test_cleanup(data_t *data) {
+static void test_cleanup(void) {
 	igt_plane_t *primary;
 
-	if (data->output) {
-		primary = igt_output_get_plane_type(data->output,
+	if (data.output) {
+		primary = igt_output_get_plane_type(data.output,
 						    DRM_PLANE_TYPE_PRIMARY);
 		igt_plane_set_fb(primary, NULL);
-		igt_display_commit(&data->display);
-		igt_remove_fb(data->drm_fd, &data->fb_test_pattern);
+		igt_display_commit(&data.display);
+		igt_remove_fb(data.drm_fd, &data.fb_test_pattern);
 	}
 }
 
+static void kms_dp_dsc_exit_handler(int sig) {
+
+	restore_dp_dsc_enable();
+}
+
 
 /*
  * Re-probe connectors and do a modeset with DSC
  *
  */
-static void update_display(data_t *data, enum dsc_test_type test_type)
+static void update_display(enum dsc_test_type test_type)
 {
 	igt_plane_t *primary;
-	data->mode = igt_output_get_mode(data->output);
-	data->connector = data->output->config.connector;
+	data.mode = igt_output_get_mode(data.output);
+	data.connector = data.output->config.connector;
 
-	if (data->connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
-	    data->pipe == PIPE_A) {
+	if (data.connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
+	    data.pipe == PIPE_A) {
 		igt_debug("DSC not supported on Pipe A on external DP\n");
 		return;
 	}
 
+	/* Disable the output first */
+	igt_output_set_pipe(data.output, PIPE_NONE);
+	igt_display_commit(&data.display);
+
 	if (test_type == test_basic_dsc_enable) {
 		bool enabled;
 
-		igt_debug("DSC is supported on %s\n", data->conn_name);
-		force_dp_dsc_enable(data);
+		igt_debug("DSC is supported on %s\n", data.conn_name);
+		force_dp_dsc_enable();
 
-		igt_create_pattern_fb(data->drm_fd, data->mode->hdisplay,
-				      data->mode->vdisplay,
+		igt_output_set_pipe(data.output, data.pipe);
+		igt_create_pattern_fb(data.drm_fd, data.mode->hdisplay,
+				      data.mode->vdisplay,
 				      DRM_FORMAT_XRGB8888,
 				      LOCAL_DRM_FORMAT_MOD_NONE,
-				      &data->fb_test_pattern);
-		primary = igt_output_get_plane_type(data->output,
+				      &data.fb_test_pattern);
+		primary = igt_output_get_plane_type(data.output,
 						    DRM_PLANE_TYPE_PRIMARY);
-		igt_plane_set_fb(primary, &data->fb_test_pattern);
-		igt_display_commit(&data->display);
+
+		/* Now set the output to the desired mode */
+		igt_plane_set_fb(primary, &data.fb_test_pattern);
+		igt_display_commit(&data.display);
 
 		/*
 		 * Until we have CRC check support, manually check if RGB test
@@ -183,38 +211,37 @@ static void update_display(data_t *data, enum dsc_test_type test_type)
 		 */
 		manual("RGB test pattern without corruption");
 
-		enabled = is_dp_dsc_enabled(data);
-		clear_dp_dsc_enable(data);
+		enabled = is_dp_dsc_enabled();
+		restore_dp_dsc_enable();
 
 		igt_assert_f(enabled,
-			     "Default DSC enable failed on Connector: %s Pipe: %s",
-			     data->conn_name,
-			     kmstest_pipe_name(data->pipe));
+			     "Default DSC enable failed on Connector: %s Pipe: %s\n",
+			     data.conn_name,
+			     kmstest_pipe_name(data.pipe));
 	} else {
 		igt_assert(!"Unknown test type\n");
 	}
 }
 
-static void run_test(data_t *data, igt_output_t *output,
+static void run_test(igt_output_t *output,
 		     enum dsc_test_type test_type)
 {
 	enum pipe pipe;
 
-	for_each_pipe(&data->display, pipe) {
+	for_each_pipe(&data.display, pipe) {
 
 		if (igt_pipe_connector_valid(pipe, output)) {
-			igt_output_set_pipe(output, pipe);
-			data->pipe = pipe;
-			data->output = output;
-			update_display(data, test_type);
-			test_cleanup(data);
+			data.pipe = pipe;
+			data.output = output;

tests/kms_dp_dsc.c static void update_display(data_t *data, enum dsc_test_type test_type) · line 244

Quoted 10 lines
tests/kms_dp_dsc.c +3 -1
+			update_display(test_type);
+			test_cleanup();
 		}
 	}
 }
 
 igt_main
 {
-	data_t data = {};
+	//data_t data = {};

Leftover line.

tests/kms_dp_dsc.c igt_main · line 255

Quoted 8 lines
tests/kms_dp_dsc.c +1 -0
 	igt_output_t *output;
 	drmModeRes *res;
 	drmModeConnector *connector;
@@ -225,6 +252,7 @@ igt_main
 		data.drm_fd = drm_open_driver_master(DRIVER_ANY);
 		data.debugfs_fd = igt_debugfs_dir(data.drm_fd);
 		kmstest_set_vt_graphics_mode();
+		igt_install_exit_handler(kms_dp_dsc_exit_handler);

Before this you need to actually save the original value, otherwise the exit handler may restore an uninitialized value in case it's called before you save it.

Quoted 17 lines
tests/kms_dp_dsc.c +2 -2
 		igt_display_require(&data.display, data.drm_fd);
 		igt_require(res = drmModeGetResources(data.drm_fd));
 	}
@@ -245,19 +273,20 @@ igt_main
 				sprintf(data.conn_name, "%s-%d",
 					kmstest_connector_type_str(connector->connector_type),
 					connector->connector_type_id);
-				if(!is_dp_dsc_supported(&data)) {
+				if(!is_dp_dsc_supported()) {
 					igt_debug("DSC not supported on connector %s \n",
 						  data.conn_name);
 					continue;
 				}
 				if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
-				    !is_dp_fec_supported(&data)) {
+				    !is_dp_fec_supported()) {
 					igt_debug("DSC cannot be enabled without FEC on %s\n",

tests/kms_dp_dsc.c igt_main · line 292

Quoted 10 lines
tests/kms_dp_dsc.c +2 -1
 						  data.conn_name);
 					continue;
 				}
 				test_conn_cnt++;
-				run_test(&data, output, test_basic_dsc_enable);
+				data.force_dsc_en = is_force_dsc_enabled();
+				run_test(output, test_basic_dsc_enable);
 			}
 			igt_skip_on(test_conn_cnt == 0);
 		}

Under igt_fixture you close debugfs_fd, but that's not good, since the exit handler will be called even during normal process exit, and so the exit handler will find unexpectedly that the fd it needs is closed.

Just leave the closing up to the exit handler as I commented above, leaving a comment about this fact under igt_fixture.

--Imre

Quoted 3 lines
Signature · 1 line
2.19.1

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

#4 lore raw
Quoted 23 lines · Imre Deak
Quoted 22 lines · Manasi Navare

DSC enable gets configured during compute_config and needs a full modeset to force DSC.
Sometimes in between the tests, if the initial output is same as the mode being set for DSC then it will not do a full modeset. So we disable the output before forcing a mode with DSC enable.

You need the kernel patch:
https://patchwork.freedesktop.org/series/59084/

v2:
* Restore the value of force dsc enable after the test and in igt_exit_handler
* Add igt_install_exit_handler to restore values on fail/exit

Fixes db19bccc1c22 ("test/kms_dp_dsc: Basic KMS test to validate VESA DSC on DP/eDP")
Cc Petri Latvala <[email protected]>
Cc Anusha Srivatsa <[email protected]>
Cc Imre Deak <[email protected]>
---
 tests/kms_dp_dsc.c | 133 +++++++++++++++++++++++++++------------------
 1 file changed, 81 insertions(+), 52 deletions(-)
Quoted 11 lines

tests/kms_dp_dsc.c typedef struct { · line 66

Quoted 9 lines
tests/kms_dp_dsc.c +1 -0
index da93cd74..acaee890 100644
@@ -63,119 +63,147 @@ typedef struct {
 	int crtc;
 	enum pipe pipe;
 	char conn_name[128];
+	bool force_dsc_en;

force_dsc_en_orig?

Sure, I will rename this

Quoted 9 lines

tests/kms_dp_dsc.c typedef struct { · line 70

Quoted 5 lines
tests/kms_dp_dsc.c +2 -0
 } data_t;
 
+data_t data = {};
+

Maybe make only debugfs_fd and force_dsc_en_orig global to reduce the churn? Also init debugfs_fd to -1, so the exit handler knows if it's been closed already.

But then for restore I also need data.conn_name. So i thought I would make the whole thing global.

Quoted 82 lines
Quoted 82 lines
tests/kms_dp_dsc.c +26 -14
 static inline void manual(const char *expected)
 {
 	igt_debug_manual_check("all", expected);
 }
 
-static bool is_dp_dsc_supported(data_t *data)
+static bool is_dp_dsc_supported(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_require(igt_debugfs_simple_read(data->debugfs_fd, file_name, buf,
+	igt_require(igt_debugfs_simple_read(data.debugfs_fd, file_name, buf,
 					    sizeof(buf)) > 0);
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "DSC_Sink_Support: yes");
 }
 
-static bool is_dp_fec_supported(data_t *data)
+static bool is_dp_fec_supported(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "FEC_Sink_Support: yes");
 }
 
-static bool is_dp_dsc_enabled(data_t *data)
+static bool is_dp_dsc_enabled(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "DSC_Enabled: yes");
 }
 
-static void force_dp_dsc_enable(data_t *data)
+static bool is_force_dsc_enabled(void)
+{
+	char file_name[128] = {0};
+	char buf[512];
+
+	strcpy(file_name, data.conn_name);
+	strcat(file_name, "/i915_dsc_fec_support");
+	igt_debugfs_read(data.drm_fd, file_name, buf);
+
+	return strstr(buf, "Force_DSC_Enable: yes");
+}
+
+static void force_dp_dsc_enable(void)
 {
 	char file_name[128] = {0};
 	int ret;
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debug ("Forcing DSC enable on %s\n", data->conn_name);
-	ret = igt_sysfs_write(data->debugfs_fd, file_name, "1", 1);
+	igt_debug ("Forcing DSC enable on %s\n", data.conn_name);
+	ret = igt_sysfs_write(data.debugfs_fd, file_name, "1", 1);
 	igt_assert_f(ret > 0, "debugfs_write failed");
 }
 
Quoted 4 lines

tests/kms_dp_dsc.c typedef struct { · line 138

Quoted 2 lines
tests/kms_dp_dsc.c +1 -1
-static void clear_dp_dsc_enable(data_t *data)
+static void restore_dp_dsc_enable(void)

Better named as restore_force_dsc_en()?

Ok

Quoted 11 lines

tests/kms_dp_dsc.c typedef struct { · line 130

Quoted 5 lines
tests/kms_dp_dsc.c +0 -0
 {
 	char file_name[128] = {0};
 	int ret;
 

You need to check if the sig handler was called multiple times for some reason:

	if (debugfs_fd < 0)
		return;

Ok will add this check here

Quoted 12 lines

tests/kms_dp_dsc.c typedef struct { · line 147

Quoted 9 lines
tests/kms_dp_dsc.c +4 -3
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debug ("Clearing DSC enable on %s\n", data->conn_name);
-	ret = igt_sysfs_write(data->debugfs_fd, file_name, "0", 1);
+	igt_debug ("Restoring DSC enable on %s\n", data.conn_name);
+	ret = igt_sysfs_write(data.debugfs_fd, file_name,
+			      data.force_dsc_en ? "1" : "0", 1);
	close(debugfs_fd);
	debugfs_fd = -1;

But if I close it here, I cant call restore function in update_display() after the test is completed. Probably i dont need it there?

Quoted 125 lines
Quoted 125 lines
tests/kms_dp_dsc.c +41 -30
 	igt_assert_f(ret > 0, "debugfs_write failed");
 }
 
-static void test_cleanup(data_t *data) {
+static void test_cleanup(void) {
 	igt_plane_t *primary;
 
-	if (data->output) {
-		primary = igt_output_get_plane_type(data->output,
+	if (data.output) {
+		primary = igt_output_get_plane_type(data.output,
 						    DRM_PLANE_TYPE_PRIMARY);
 		igt_plane_set_fb(primary, NULL);
-		igt_display_commit(&data->display);
-		igt_remove_fb(data->drm_fd, &data->fb_test_pattern);
+		igt_display_commit(&data.display);
+		igt_remove_fb(data.drm_fd, &data.fb_test_pattern);
 	}
 }
 
+static void kms_dp_dsc_exit_handler(int sig) {
+
+	restore_dp_dsc_enable();
+}
+
 
 /*
  * Re-probe connectors and do a modeset with DSC
  *
  */
-static void update_display(data_t *data, enum dsc_test_type test_type)
+static void update_display(enum dsc_test_type test_type)
 {
 	igt_plane_t *primary;
-	data->mode = igt_output_get_mode(data->output);
-	data->connector = data->output->config.connector;
+	data.mode = igt_output_get_mode(data.output);
+	data.connector = data.output->config.connector;
 
-	if (data->connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
-	    data->pipe == PIPE_A) {
+	if (data.connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
+	    data.pipe == PIPE_A) {
 		igt_debug("DSC not supported on Pipe A on external DP\n");
 		return;
 	}
 
+	/* Disable the output first */
+	igt_output_set_pipe(data.output, PIPE_NONE);
+	igt_display_commit(&data.display);
+
 	if (test_type == test_basic_dsc_enable) {
 		bool enabled;
 
-		igt_debug("DSC is supported on %s\n", data->conn_name);
-		force_dp_dsc_enable(data);
+		igt_debug("DSC is supported on %s\n", data.conn_name);
+		force_dp_dsc_enable();
 
-		igt_create_pattern_fb(data->drm_fd, data->mode->hdisplay,
-				      data->mode->vdisplay,
+		igt_output_set_pipe(data.output, data.pipe);
+		igt_create_pattern_fb(data.drm_fd, data.mode->hdisplay,
+				      data.mode->vdisplay,
 				      DRM_FORMAT_XRGB8888,
 				      LOCAL_DRM_FORMAT_MOD_NONE,
-				      &data->fb_test_pattern);
-		primary = igt_output_get_plane_type(data->output,
+				      &data.fb_test_pattern);
+		primary = igt_output_get_plane_type(data.output,
 						    DRM_PLANE_TYPE_PRIMARY);
-		igt_plane_set_fb(primary, &data->fb_test_pattern);
-		igt_display_commit(&data->display);
+
+		/* Now set the output to the desired mode */
+		igt_plane_set_fb(primary, &data.fb_test_pattern);
+		igt_display_commit(&data.display);
 
 		/*
 		 * Until we have CRC check support, manually check if RGB test
@@ -183,38 +211,37 @@ static void update_display(data_t *data, enum dsc_test_type test_type)
 		 */
 		manual("RGB test pattern without corruption");
 
-		enabled = is_dp_dsc_enabled(data);
-		clear_dp_dsc_enable(data);
+		enabled = is_dp_dsc_enabled();
+		restore_dp_dsc_enable();
 
 		igt_assert_f(enabled,
-			     "Default DSC enable failed on Connector: %s Pipe: %s",
-			     data->conn_name,
-			     kmstest_pipe_name(data->pipe));
+			     "Default DSC enable failed on Connector: %s Pipe: %s\n",
+			     data.conn_name,
+			     kmstest_pipe_name(data.pipe));
 	} else {
 		igt_assert(!"Unknown test type\n");
 	}
 }
 
-static void run_test(data_t *data, igt_output_t *output,
+static void run_test(igt_output_t *output,
 		     enum dsc_test_type test_type)
 {
 	enum pipe pipe;
 
-	for_each_pipe(&data->display, pipe) {
+	for_each_pipe(&data.display, pipe) {
 
 		if (igt_pipe_connector_valid(pipe, output)) {
-			igt_output_set_pipe(output, pipe);
-			data->pipe = pipe;
-			data->output = output;
-			update_display(data, test_type);
-			test_cleanup(data);
+			data.pipe = pipe;
+			data.output = output;
+			update_display(test_type);
+			test_cleanup();
 		}
 	}
 }
 
Quoted 6 lines

tests/kms_dp_dsc.c static void update_display(data_t *data, enum dsc_test_type test_type) · line 244

Quoted 4 lines
tests/kms_dp_dsc.c +1 -1
 igt_main
 {
-	data_t data = {};
+	//data_t data = {};

Leftover line.

Yes, sorry about that, will clean it up

Quoted 13 lines

tests/kms_dp_dsc.c igt_main · line 255

Quoted 9 lines
tests/kms_dp_dsc.c +1 -0
 	igt_output_t *output;
 	drmModeRes *res;
 	drmModeConnector *connector;
@@ -225,6 +252,7 @@ igt_main
 		data.drm_fd = drm_open_driver_master(DRIVER_ANY);
 		data.debugfs_fd = igt_debugfs_dir(data.drm_fd);
 		kmstest_set_vt_graphics_mode();
+		igt_install_exit_handler(kms_dp_dsc_exit_handler);

Before this you need to actually save the original value, otherwise the exit handler may restore an uninitialized value in case it's called before you save it.

Since the value is per connector, I cant save it until I have gone through the whole connector type checks. I will move the igt_install_exit_handler(kms_dp_dsc_exit_handler); to before run_test call then?

Quoted 33 lines
Quoted 18 lines
tests/kms_dp_dsc.c +2 -2
 		igt_display_require(&data.display, data.drm_fd);
 		igt_require(res = drmModeGetResources(data.drm_fd));
 	}
@@ -245,19 +273,20 @@ igt_main
 				sprintf(data.conn_name, "%s-%d",
 					kmstest_connector_type_str(connector->connector_type),
 					connector->connector_type_id);
-				if(!is_dp_dsc_supported(&data)) {
+				if(!is_dp_dsc_supported()) {
 					igt_debug("DSC not supported on connector %s \n",
 						  data.conn_name);
 					continue;
 				}
 				if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
-				    !is_dp_fec_supported(&data)) {
+				    !is_dp_fec_supported()) {
 					igt_debug("DSC cannot be enabled without FEC on %s\n",

tests/kms_dp_dsc.c igt_main · line 292

Quoted 10 lines
tests/kms_dp_dsc.c +2 -1
 						  data.conn_name);
 					continue;
 				}
 				test_conn_cnt++;
-				run_test(&data, output, test_basic_dsc_enable);
+				data.force_dsc_en = is_force_dsc_enabled();
+				run_test(output, test_basic_dsc_enable);
 			}
 			igt_skip_on(test_conn_cnt == 0);
 		}

Under igt_fixture you close debugfs_fd, but that's not good, since the exit handler will be called even during normal process exit, and so the exit handler will find unexpectedly that the fd it needs is closed.

Quoted 2 lines

Just leave the closing up to the exit handler as I commented above, leaving a comment about this fact under igt_fixture.

Ok will remove the debugfs fd from the igt_fixture()

Manasi

Quoted 6 lines

--Imre

Quoted 3 lines
Signature · 1 line
2.19.1

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

#5 lore raw
Quoted 48 lines · Manasi Navare
Quoted 23 lines · Imre Deak
Quoted 22 lines · Manasi Navare

DSC enable gets configured during compute_config and needs a full modeset to force DSC.
Sometimes in between the tests, if the initial output is same as the mode being set for DSC then it will not do a full modeset. So we disable the output before forcing a mode with DSC enable.

You need the kernel patch:
https://patchwork.freedesktop.org/series/59084/

v2:
* Restore the value of force dsc enable after the test and in igt_exit_handler
* Add igt_install_exit_handler to restore values on fail/exit

Fixes db19bccc1c22 ("test/kms_dp_dsc: Basic KMS test to validate VESA DSC on DP/eDP")
Cc Petri Latvala <[email protected]>
Cc Anusha Srivatsa <[email protected]>
Cc Imre Deak <[email protected]>
---
 tests/kms_dp_dsc.c | 133 +++++++++++++++++++++++++++------------------
 1 file changed, 81 insertions(+), 52 deletions(-)
Quoted 11 lines

tests/kms_dp_dsc.c typedef struct { · line 66

Quoted 9 lines
tests/kms_dp_dsc.c +1 -0
index da93cd74..acaee890 100644
@@ -63,119 +63,147 @@ typedef struct {
 	int crtc;
 	enum pipe pipe;
 	char conn_name[128];
+	bool force_dsc_en;

force_dsc_en_orig?

Sure, I will rename this

Quoted 9 lines

tests/kms_dp_dsc.c typedef struct { · line 70

Quoted 5 lines
tests/kms_dp_dsc.c +2 -0
 } data_t;
 
+data_t data = {};
+

Maybe make only debugfs_fd and force_dsc_en_orig global to reduce the churn? Also init debugfs_fd to -1, so the exit handler knows if it's been closed already.

Quoted 2 lines

But then for restore I also need data.conn_name. So i thought I would make the whole thing global.

I'd still avoid the churn (making the review easier) by adding a new global

	int force_dsc_restore_fd = -1;

using it for restoring the global force_dsc_en_orig. By doing that you won't need conn_name in the exit handler, see below.

Quoted 102 lines
Quoted 81 lines
Quoted 81 lines
tests/kms_dp_dsc.c +26 -14
 static inline void manual(const char *expected)
 {
 	igt_debug_manual_check("all", expected);
 }
 
-static bool is_dp_dsc_supported(data_t *data)
+static bool is_dp_dsc_supported(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_require(igt_debugfs_simple_read(data->debugfs_fd, file_name, buf,
+	igt_require(igt_debugfs_simple_read(data.debugfs_fd, file_name, buf,
 					    sizeof(buf)) > 0);
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "DSC_Sink_Support: yes");
 }
 
-static bool is_dp_fec_supported(data_t *data)
+static bool is_dp_fec_supported(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "FEC_Sink_Support: yes");
 }
 
-static bool is_dp_dsc_enabled(data_t *data)
+static bool is_dp_dsc_enabled(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "DSC_Enabled: yes");
 }
 
-static void force_dp_dsc_enable(data_t *data)
+static bool is_force_dsc_enabled(void)
+{
+	char file_name[128] = {0};
+	char buf[512];
+
+	strcpy(file_name, data.conn_name);
+	strcat(file_name, "/i915_dsc_fec_support");
+	igt_debugfs_read(data.drm_fd, file_name, buf);
+
+	return strstr(buf, "Force_DSC_Enable: yes");
+}
+
+static void force_dp_dsc_enable(void)
 {
 	char file_name[128] = {0};
 	int ret;
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debug ("Forcing DSC enable on %s\n", data->conn_name);
-	ret = igt_sysfs_write(data->debugfs_fd, file_name, "1", 1);
+	igt_debug ("Forcing DSC enable on %s\n", data.conn_name);
+	ret = igt_sysfs_write(data.debugfs_fd, file_name, "1", 1);
 	igt_assert_f(ret > 0, "debugfs_write failed");
 }
 
Quoted 4 lines

tests/kms_dp_dsc.c typedef struct { · line 138

Quoted 2 lines
tests/kms_dp_dsc.c +1 -1
-static void clear_dp_dsc_enable(data_t *data)
+static void restore_dp_dsc_enable(void)

Better named as restore_force_dsc_en()?

Ok

Quoted 11 lines

tests/kms_dp_dsc.c typedef struct { · line 130

Quoted 5 lines
tests/kms_dp_dsc.c +0 -0
 {
 	char file_name[128] = {0};
 	int ret;
 

You need to check if the sig handler was called multiple times for some reason:

	if (debugfs_fd < 0)
		return;

Ok will add this check here

Quoted 8 lines
Quoted 8 lines

tests/kms_dp_dsc.c typedef struct { · line 147

Quoted 8 lines
tests/kms_dp_dsc.c +4 -3
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debug ("Clearing DSC enable on %s\n", data->conn_name);
-	ret = igt_sysfs_write(data->debugfs_fd, file_name, "0", 1);
+	igt_debug ("Restoring DSC enable on %s\n", data.conn_name);
+	ret = igt_sysfs_write(data.debugfs_fd, file_name,
+			      data.force_dsc_en ? "1" : "0", 1);

Instead of the above:

static void restore_force_dsc_en(void)

{
	if (force_dsc_restore_fd < 0)
		return;

	igt_debug("Restoring DSC enable\n");
	igt_assert(write(force_dsc_restore_fd, force_dsc_en_orig ? "1" : "0", 1) == 1);

	close(force_dsc_restore_fd);
	force_dsc_restore_fd = -1;
}
Quoted 3 lines

But if I close it here, I cant call restore function in update_display() after the test is completed. Probably i dont need it there?

Yes it's needed, we want to do the restore for each connector.

Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
tests/kms_dp_dsc.c +19 -10
 	igt_assert_f(ret > 0, "debugfs_write failed");
 }
 
-static void test_cleanup(data_t *data) {
+static void test_cleanup(void) {
 	igt_plane_t *primary;
 
-	if (data->output) {
-		primary = igt_output_get_plane_type(data->output,
+	if (data.output) {
+		primary = igt_output_get_plane_type(data.output,
 						    DRM_PLANE_TYPE_PRIMARY);
 		igt_plane_set_fb(primary, NULL);
-		igt_display_commit(&data->display);
-		igt_remove_fb(data->drm_fd, &data->fb_test_pattern);
+		igt_display_commit(&data.display);
+		igt_remove_fb(data.drm_fd, &data.fb_test_pattern);
 	}
 }
 
+static void kms_dp_dsc_exit_handler(int sig) {
+
+	restore_dp_dsc_enable();
+}
+
 
 /*
  * Re-probe connectors and do a modeset with DSC
  *
  */
-static void update_display(data_t *data, enum dsc_test_type test_type)
+static void update_display(enum dsc_test_type test_type)
 {
 	igt_plane_t *primary;
-	data->mode = igt_output_get_mode(data->output);
-	data->connector = data->output->config.connector;
+	data.mode = igt_output_get_mode(data.output);
+	data.connector = data.output->config.connector;
 
-	if (data->connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
-	    data->pipe == PIPE_A) {
+	if (data.connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
+	    data.pipe == PIPE_A) {
 		igt_debug("DSC not supported on Pipe A on external DP\n");
 		return;
 	}
 
+	/* Disable the output first */
+	igt_output_set_pipe(data.output, PIPE_NONE);
+	igt_display_commit(&data.display);
+
 	if (test_type == test_basic_dsc_enable) {
 		bool enabled;
 
Quoted 3 lines
Quoted 3 lines

tests/kms_dp_dsc.c typedef struct { · line 192

Quoted 3 lines
tests/kms_dp_dsc.c +1 -2
-		igt_debug("DSC is supported on %s\n", data->conn_name);
-		force_dp_dsc_enable(data);
+		igt_debug("DSC is supported on %s\n", data.conn_name);

Here call a new save_force_dsc_en() function containing:

		force_dsc_en_orig = is_force_dsc_enabled(data);
		strcpy(file_name, data->conn_name);
		strcat(file_name, "/i915_dsc_fec_support");
		force_dsc_restore_fd = openat(igt_debugfs_dir(data->drm_fd),
					      file_name, O_WRONLY);
		igt_assert(force_dsc_restore_fd >= 0);
Quoted 90 lines
Quoted 67 lines
Quoted 67 lines
tests/kms_dp_dsc.c +21 -18
+		force_dp_dsc_enable();
 
-		igt_create_pattern_fb(data->drm_fd, data->mode->hdisplay,
-				      data->mode->vdisplay,
+		igt_output_set_pipe(data.output, data.pipe);
+		igt_create_pattern_fb(data.drm_fd, data.mode->hdisplay,
+				      data.mode->vdisplay,
 				      DRM_FORMAT_XRGB8888,
 				      LOCAL_DRM_FORMAT_MOD_NONE,
-				      &data->fb_test_pattern);
-		primary = igt_output_get_plane_type(data->output,
+				      &data.fb_test_pattern);
+		primary = igt_output_get_plane_type(data.output,
 						    DRM_PLANE_TYPE_PRIMARY);
-		igt_plane_set_fb(primary, &data->fb_test_pattern);
-		igt_display_commit(&data->display);
+
+		/* Now set the output to the desired mode */
+		igt_plane_set_fb(primary, &data.fb_test_pattern);
+		igt_display_commit(&data.display);
 
 		/*
 		 * Until we have CRC check support, manually check if RGB test
@@ -183,38 +211,37 @@ static void update_display(data_t *data, enum dsc_test_type test_type)
 		 */
 		manual("RGB test pattern without corruption");
 
-		enabled = is_dp_dsc_enabled(data);
-		clear_dp_dsc_enable(data);
+		enabled = is_dp_dsc_enabled();
+		restore_dp_dsc_enable();
 
 		igt_assert_f(enabled,
-			     "Default DSC enable failed on Connector: %s Pipe: %s",
-			     data->conn_name,
-			     kmstest_pipe_name(data->pipe));
+			     "Default DSC enable failed on Connector: %s Pipe: %s\n",
+			     data.conn_name,
+			     kmstest_pipe_name(data.pipe));
 	} else {
 		igt_assert(!"Unknown test type\n");
 	}
 }
 
-static void run_test(data_t *data, igt_output_t *output,
+static void run_test(igt_output_t *output,
 		     enum dsc_test_type test_type)
 {
 	enum pipe pipe;
 
-	for_each_pipe(&data->display, pipe) {
+	for_each_pipe(&data.display, pipe) {
 
 		if (igt_pipe_connector_valid(pipe, output)) {
-			igt_output_set_pipe(output, pipe);
-			data->pipe = pipe;
-			data->output = output;
-			update_display(data, test_type);
-			test_cleanup(data);
+			data.pipe = pipe;
+			data.output = output;
+			update_display(test_type);
+			test_cleanup();
 		}
 	}
 }
 
Quoted 6 lines

tests/kms_dp_dsc.c static void update_display(data_t *data, enum dsc_test_type test_type) · line 244

Quoted 4 lines
tests/kms_dp_dsc.c +1 -1
 igt_main
 {
-	data_t data = {};
+	//data_t data = {};

Leftover line.

Yes, sorry about that, will clean it up

Quoted 13 lines

tests/kms_dp_dsc.c igt_main · line 255

Quoted 9 lines
tests/kms_dp_dsc.c +1 -0
 	igt_output_t *output;
 	drmModeRes *res;
 	drmModeConnector *connector;
@@ -225,6 +252,7 @@ igt_main
 		data.drm_fd = drm_open_driver_master(DRIVER_ANY);
 		data.debugfs_fd = igt_debugfs_dir(data.drm_fd);
 		kmstest_set_vt_graphics_mode();
+		igt_install_exit_handler(kms_dp_dsc_exit_handler);

Before this you need to actually save the original value, otherwise the exit handler may restore an uninitialized value in case it's called before you save it.

Quoted 4 lines

Since the value is per connector, I cant save it until I have gone through the whole connector type checks. I will move the igt_install_exit_handler(kms_dp_dsc_exit_handler); to before run_test call then?

It can stay here based on the above comments.

Quoted 33 lines
Quoted 33 lines
Quoted 18 lines
tests/kms_dp_dsc.c +2 -2
 		igt_display_require(&data.display, data.drm_fd);
 		igt_require(res = drmModeGetResources(data.drm_fd));
 	}
@@ -245,19 +273,20 @@ igt_main
 				sprintf(data.conn_name, "%s-%d",
 					kmstest_connector_type_str(connector->connector_type),
 					connector->connector_type_id);
-				if(!is_dp_dsc_supported(&data)) {
+				if(!is_dp_dsc_supported()) {
 					igt_debug("DSC not supported on connector %s \n",
 						  data.conn_name);
 					continue;
 				}
 				if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
-				    !is_dp_fec_supported(&data)) {
+				    !is_dp_fec_supported()) {
 					igt_debug("DSC cannot be enabled without FEC on %s\n",

tests/kms_dp_dsc.c igt_main · line 292

Quoted 10 lines
tests/kms_dp_dsc.c +2 -1
 						  data.conn_name);
 					continue;
 				}
 				test_conn_cnt++;
-				run_test(&data, output, test_basic_dsc_enable);
+				data.force_dsc_en = is_force_dsc_enabled();
+				run_test(output, test_basic_dsc_enable);
 			}
 			igt_skip_on(test_conn_cnt == 0);
 		}

Under igt_fixture you close debugfs_fd, but that's not good, since the exit handler will be called even during normal process exit, and so the exit handler will find unexpectedly that the fd it needs is closed.

Quoted 4 lines
Quoted 2 lines

Just leave the closing up to the exit handler as I commented above, leaving a comment about this fact under igt_fixture.

Ok will remove the debugfs fd from the igt_fixture()

Based on the above you'll still need to close here debugfs_fd, as we'll now use a separate fd for restoring.

Quoted 8 lines

Manasi

Quoted 6 lines

--Imre

Quoted 3 lines
Signature · 1 line
2.19.1

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

#6 lore raw
Quoted 9 lines · Imre Deak
Quoted 8 lines · Manasi Navare
Quoted 7 lines · Imre Deak
Quoted 6 lines · Manasi Navare

DSC enable gets configured during compute_config and needs a full modeset to force DSC.
Sometimes in between the tests, if the initial output is same as the mode being set for DSC then it will not do a full modeset. So we disable the output before forcing a mode with DSC enable.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

You need the kernel patch:
https://patchwork.freedesktop.org/series/59084/

v2:
* Restore the value of force dsc enable after the test and in igt_exit_handler
* Add igt_install_exit_handler to restore values on fail/exit

Also, please split the fix restoring force_dsc_en into a separate patch.

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

#7 lore raw
In reply to Imre Deak

Thanks for your feedback Imre, I will make the necessary changes and split these into two separate patches.

Regards
Manasi

Quoted 390 lines · Imre Deak
Quoted 48 lines · Manasi Navare
Quoted 23 lines · Imre Deak
Quoted 22 lines · Manasi Navare

DSC enable gets configured during compute_config and needs a full modeset to force DSC.
Sometimes in between the tests, if the initial output is same as the mode being set for DSC then it will not do a full modeset. So we disable the output before forcing a mode with DSC enable.

You need the kernel patch:
https://patchwork.freedesktop.org/series/59084/

v2:
* Restore the value of force dsc enable after the test and in igt_exit_handler
* Add igt_install_exit_handler to restore values on fail/exit

Fixes db19bccc1c22 ("test/kms_dp_dsc: Basic KMS test to validate VESA DSC on DP/eDP")
Cc Petri Latvala <[email protected]>
Cc Anusha Srivatsa <[email protected]>
Cc Imre Deak <[email protected]>
---
 tests/kms_dp_dsc.c | 133 +++++++++++++++++++++++++++------------------
 1 file changed, 81 insertions(+), 52 deletions(-)
Quoted 11 lines

tests/kms_dp_dsc.c typedef struct { · line 66

Quoted 9 lines
tests/kms_dp_dsc.c +1 -0
index da93cd74..acaee890 100644
@@ -63,119 +63,147 @@ typedef struct {
 	int crtc;
 	enum pipe pipe;
 	char conn_name[128];
+	bool force_dsc_en;

force_dsc_en_orig?

Sure, I will rename this

Quoted 9 lines

tests/kms_dp_dsc.c typedef struct { · line 70

Quoted 5 lines
tests/kms_dp_dsc.c +2 -0
 } data_t;
 
+data_t data = {};
+

Maybe make only debugfs_fd and force_dsc_en_orig global to reduce the churn? Also init debugfs_fd to -1, so the exit handler knows if it's been closed already.

Quoted 2 lines

But then for restore I also need data.conn_name. So i thought I would make the whole thing global.

I'd still avoid the churn (making the review easier) by adding a new global

	int force_dsc_restore_fd = -1;

using it for restoring the global force_dsc_en_orig. By doing that you won't need conn_name in the exit handler, see below.

Quoted 102 lines
Quoted 81 lines
Quoted 81 lines
tests/kms_dp_dsc.c +26 -14
 static inline void manual(const char *expected)
 {
 	igt_debug_manual_check("all", expected);
 }
 
-static bool is_dp_dsc_supported(data_t *data)
+static bool is_dp_dsc_supported(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_require(igt_debugfs_simple_read(data->debugfs_fd, file_name, buf,
+	igt_require(igt_debugfs_simple_read(data.debugfs_fd, file_name, buf,
 					    sizeof(buf)) > 0);
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "DSC_Sink_Support: yes");
 }
 
-static bool is_dp_fec_supported(data_t *data)
+static bool is_dp_fec_supported(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "FEC_Sink_Support: yes");
 }
 
-static bool is_dp_dsc_enabled(data_t *data)
+static bool is_dp_dsc_enabled(void)
 {
 	char file_name[128] = {0};
 	char buf[512];
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debugfs_read(data->drm_fd, file_name, buf);
+	igt_debugfs_read(data.drm_fd, file_name, buf);
 
 	return strstr(buf, "DSC_Enabled: yes");
 }
 
-static void force_dp_dsc_enable(data_t *data)
+static bool is_force_dsc_enabled(void)
+{
+	char file_name[128] = {0};
+	char buf[512];
+
+	strcpy(file_name, data.conn_name);
+	strcat(file_name, "/i915_dsc_fec_support");
+	igt_debugfs_read(data.drm_fd, file_name, buf);
+
+	return strstr(buf, "Force_DSC_Enable: yes");
+}
+
+static void force_dp_dsc_enable(void)
 {
 	char file_name[128] = {0};
 	int ret;
 
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debug ("Forcing DSC enable on %s\n", data->conn_name);
-	ret = igt_sysfs_write(data->debugfs_fd, file_name, "1", 1);
+	igt_debug ("Forcing DSC enable on %s\n", data.conn_name);
+	ret = igt_sysfs_write(data.debugfs_fd, file_name, "1", 1);
 	igt_assert_f(ret > 0, "debugfs_write failed");
 }
 
Quoted 4 lines

tests/kms_dp_dsc.c typedef struct { · line 138

Quoted 2 lines
tests/kms_dp_dsc.c +1 -1
-static void clear_dp_dsc_enable(data_t *data)
+static void restore_dp_dsc_enable(void)

Better named as restore_force_dsc_en()?

Ok

Quoted 11 lines

tests/kms_dp_dsc.c typedef struct { · line 130

Quoted 5 lines
tests/kms_dp_dsc.c +0 -0
 {
 	char file_name[128] = {0};
 	int ret;
 

You need to check if the sig handler was called multiple times for some reason:

	if (debugfs_fd < 0)
		return;

Ok will add this check here

Quoted 8 lines
Quoted 8 lines

tests/kms_dp_dsc.c typedef struct { · line 147

Quoted 8 lines
tests/kms_dp_dsc.c +4 -3
-	strcpy(file_name, data->conn_name);
+	strcpy(file_name, data.conn_name);
 	strcat(file_name, "/i915_dsc_fec_support");
-	igt_debug ("Clearing DSC enable on %s\n", data->conn_name);
-	ret = igt_sysfs_write(data->debugfs_fd, file_name, "0", 1);
+	igt_debug ("Restoring DSC enable on %s\n", data.conn_name);
+	ret = igt_sysfs_write(data.debugfs_fd, file_name,
+			      data.force_dsc_en ? "1" : "0", 1);

Instead of the above:

static void restore_force_dsc_en(void)

{
	if (force_dsc_restore_fd < 0)
		return;

	igt_debug("Restoring DSC enable\n");
	igt_assert(write(force_dsc_restore_fd, force_dsc_en_orig ? "1" : "0", 1) == 1);

	close(force_dsc_restore_fd);
	force_dsc_restore_fd = -1;
}
Quoted 3 lines

But if I close it here, I cant call restore function in update_display() after the test is completed. Probably i dont need it there?

Yes it's needed, we want to do the restore for each connector.

Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
tests/kms_dp_dsc.c +19 -10
 	igt_assert_f(ret > 0, "debugfs_write failed");
 }
 
-static void test_cleanup(data_t *data) {
+static void test_cleanup(void) {
 	igt_plane_t *primary;
 
-	if (data->output) {
-		primary = igt_output_get_plane_type(data->output,
+	if (data.output) {
+		primary = igt_output_get_plane_type(data.output,
 						    DRM_PLANE_TYPE_PRIMARY);
 		igt_plane_set_fb(primary, NULL);
-		igt_display_commit(&data->display);
-		igt_remove_fb(data->drm_fd, &data->fb_test_pattern);
+		igt_display_commit(&data.display);
+		igt_remove_fb(data.drm_fd, &data.fb_test_pattern);
 	}
 }
 
+static void kms_dp_dsc_exit_handler(int sig) {
+
+	restore_dp_dsc_enable();
+}
+
 
 /*
  * Re-probe connectors and do a modeset with DSC
  *
  */
-static void update_display(data_t *data, enum dsc_test_type test_type)
+static void update_display(enum dsc_test_type test_type)
 {
 	igt_plane_t *primary;
-	data->mode = igt_output_get_mode(data->output);
-	data->connector = data->output->config.connector;
+	data.mode = igt_output_get_mode(data.output);
+	data.connector = data.output->config.connector;
 
-	if (data->connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
-	    data->pipe == PIPE_A) {
+	if (data.connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
+	    data.pipe == PIPE_A) {
 		igt_debug("DSC not supported on Pipe A on external DP\n");
 		return;
 	}
 
+	/* Disable the output first */
+	igt_output_set_pipe(data.output, PIPE_NONE);
+	igt_display_commit(&data.display);
+
 	if (test_type == test_basic_dsc_enable) {
 		bool enabled;
 
Quoted 3 lines
Quoted 3 lines

tests/kms_dp_dsc.c typedef struct { · line 192

Quoted 3 lines
tests/kms_dp_dsc.c +1 -2
-		igt_debug("DSC is supported on %s\n", data->conn_name);
-		force_dp_dsc_enable(data);
+		igt_debug("DSC is supported on %s\n", data.conn_name);

Here call a new save_force_dsc_en() function containing:

		force_dsc_en_orig = is_force_dsc_enabled(data);
		strcpy(file_name, data->conn_name);
		strcat(file_name, "/i915_dsc_fec_support");
		force_dsc_restore_fd = openat(igt_debugfs_dir(data->drm_fd),
					      file_name, O_WRONLY);
		igt_assert(force_dsc_restore_fd >= 0);
Quoted 90 lines
Quoted 67 lines
Quoted 67 lines
tests/kms_dp_dsc.c +21 -18
+		force_dp_dsc_enable();
 
-		igt_create_pattern_fb(data->drm_fd, data->mode->hdisplay,
-				      data->mode->vdisplay,
+		igt_output_set_pipe(data.output, data.pipe);
+		igt_create_pattern_fb(data.drm_fd, data.mode->hdisplay,
+				      data.mode->vdisplay,
 				      DRM_FORMAT_XRGB8888,
 				      LOCAL_DRM_FORMAT_MOD_NONE,
-				      &data->fb_test_pattern);
-		primary = igt_output_get_plane_type(data->output,
+				      &data.fb_test_pattern);
+		primary = igt_output_get_plane_type(data.output,
 						    DRM_PLANE_TYPE_PRIMARY);
-		igt_plane_set_fb(primary, &data->fb_test_pattern);
-		igt_display_commit(&data->display);
+
+		/* Now set the output to the desired mode */
+		igt_plane_set_fb(primary, &data.fb_test_pattern);
+		igt_display_commit(&data.display);
 
 		/*
 		 * Until we have CRC check support, manually check if RGB test
@@ -183,38 +211,37 @@ static void update_display(data_t *data, enum dsc_test_type test_type)
 		 */
 		manual("RGB test pattern without corruption");
 
-		enabled = is_dp_dsc_enabled(data);
-		clear_dp_dsc_enable(data);
+		enabled = is_dp_dsc_enabled();
+		restore_dp_dsc_enable();
 
 		igt_assert_f(enabled,
-			     "Default DSC enable failed on Connector: %s Pipe: %s",
-			     data->conn_name,
-			     kmstest_pipe_name(data->pipe));
+			     "Default DSC enable failed on Connector: %s Pipe: %s\n",
+			     data.conn_name,
+			     kmstest_pipe_name(data.pipe));
 	} else {
 		igt_assert(!"Unknown test type\n");
 	}
 }
 
-static void run_test(data_t *data, igt_output_t *output,
+static void run_test(igt_output_t *output,
 		     enum dsc_test_type test_type)
 {
 	enum pipe pipe;
 
-	for_each_pipe(&data->display, pipe) {
+	for_each_pipe(&data.display, pipe) {
 
 		if (igt_pipe_connector_valid(pipe, output)) {
-			igt_output_set_pipe(output, pipe);
-			data->pipe = pipe;
-			data->output = output;
-			update_display(data, test_type);
-			test_cleanup(data);
+			data.pipe = pipe;
+			data.output = output;
+			update_display(test_type);
+			test_cleanup();
 		}
 	}
 }
 
Quoted 6 lines

tests/kms_dp_dsc.c static void update_display(data_t *data, enum dsc_test_type test_type) · line 244

Quoted 4 lines
tests/kms_dp_dsc.c +1 -1
 igt_main
 {
-	data_t data = {};
+	//data_t data = {};

Leftover line.

Yes, sorry about that, will clean it up

Quoted 13 lines

tests/kms_dp_dsc.c igt_main · line 255

Quoted 9 lines
tests/kms_dp_dsc.c +1 -0
 	igt_output_t *output;
 	drmModeRes *res;
 	drmModeConnector *connector;
@@ -225,6 +252,7 @@ igt_main
 		data.drm_fd = drm_open_driver_master(DRIVER_ANY);
 		data.debugfs_fd = igt_debugfs_dir(data.drm_fd);
 		kmstest_set_vt_graphics_mode();
+		igt_install_exit_handler(kms_dp_dsc_exit_handler);

Before this you need to actually save the original value, otherwise the exit handler may restore an uninitialized value in case it's called before you save it.

Quoted 4 lines

Since the value is per connector, I cant save it until I have gone through the whole connector type checks. I will move the igt_install_exit_handler(kms_dp_dsc_exit_handler); to before run_test call then?

It can stay here based on the above comments.

Quoted 33 lines
Quoted 33 lines
Quoted 18 lines
tests/kms_dp_dsc.c +2 -2
 		igt_display_require(&data.display, data.drm_fd);
 		igt_require(res = drmModeGetResources(data.drm_fd));
 	}
@@ -245,19 +273,20 @@ igt_main
 				sprintf(data.conn_name, "%s-%d",
 					kmstest_connector_type_str(connector->connector_type),
 					connector->connector_type_id);
-				if(!is_dp_dsc_supported(&data)) {
+				if(!is_dp_dsc_supported()) {
 					igt_debug("DSC not supported on connector %s \n",
 						  data.conn_name);
 					continue;
 				}
 				if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
-				    !is_dp_fec_supported(&data)) {
+				    !is_dp_fec_supported()) {
 					igt_debug("DSC cannot be enabled without FEC on %s\n",

tests/kms_dp_dsc.c igt_main · line 292

Quoted 10 lines
tests/kms_dp_dsc.c +2 -1
 						  data.conn_name);
 					continue;
 				}
 				test_conn_cnt++;
-				run_test(&data, output, test_basic_dsc_enable);
+				data.force_dsc_en = is_force_dsc_enabled();
+				run_test(output, test_basic_dsc_enable);
 			}
 			igt_skip_on(test_conn_cnt == 0);
 		}

Under igt_fixture you close debugfs_fd, but that's not good, since the exit handler will be called even during normal process exit, and so the exit handler will find unexpectedly that the fd it needs is closed.

Quoted 16 lines
Quoted 4 lines
Quoted 2 lines

Just leave the closing up to the exit handler as I commented above, leaving a comment about this fact under igt_fixture.

Ok will remove the debugfs fd from the igt_fixture()

Based on the above you'll still need to close here debugfs_fd, as we'll now use a separate fd for restoring.

Quoted 8 lines

Manasi

Quoted 6 lines

--Imre

Quoted 3 lines
Signature · 1 line
2.19.1

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