Skip to contentSkip to conversation

Add IGT test for compositor control of ABM

PATCH New Mario Limonciello 1 participant 4 messages Jul 21, 2025

lore
Share & tools
lore
#0 lore raw

cover Add IGT test for compositor control of ABM

From: Mario Limonciello <[email protected]>

After the Display Next 2025 hackfest a patch series was introduced to allow the compositor to control ABM. sysfs writes are blocked when set.

Add support for testing that the writes really are blocked.

Mario Limonciello (3):
tests/amdgpu: Remove unneeded includes
tests/amdgpu: Rename set_abm_level to set_abm_level_sysfs tests/amdgpu: Add support for testing compositor control of ABM

 tests/amdgpu/amd_abm.c | 103 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 91 insertions(+), 12 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH 1/3 tests/amdgpu: Remove unneeded includes

From: Mario Limonciello <[email protected]>

---
 tests/amdgpu/amd_abm.c | 2 --
 1 file changed, 2 deletions(-)
tests/amdgpu/amd_abm.c +0 -2
index 97813d80f..f55b055f9 100644
@@ -20,7 +20,6 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-#include "igt.h"
 #include "drmtest.h"
 #include "igt_kms.h"
 #include <limits.h>
@@ -28,7 +27,6 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
 #include <fcntl.h>
 #include <time.h>
 
Signature · 1 line
2.50.1
#2 lore raw

PATCH 2/3 tests/amdgpu: Rename set_abm_level to set_abm_level_sysfs

In reply to Mario Limonciello

From: Mario Limonciello <[email protected]>

The compositor can set the ABM level directly, so rename the function to clarify which method is being used.

---
 tests/amdgpu/amd_abm.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
tests/amdgpu/amd_abm.c +10 -10
index f55b055f9..3c6a7307f 100644
@@ -50,7 +50,7 @@ typedef struct data {
 	uint32_t *fb_mem;
 } data_t;
 
-static void set_abm_level(data_t *data, igt_output_t *output, int level);
+static void set_abm_level_sysfs(data_t *data, igt_output_t *output, int level);
 
 static void fbmem_draw_smpte_pattern(uint32_t *fbmem, int width, int height)
 {
@@ -173,7 +173,7 @@ static void test_fini(data_t *data)
 	for_each_valid_output_on_pipe(&data->display, pipe, output) {
 		if (output->config.connector->connector_type != DRM_MODE_CONNECTOR_eDP)
 			continue;
-		set_abm_level(data, output, 0);
+		set_abm_level_sysfs(data, output, 0);
 	}
 
 	igt_display_reset(display);
@@ -247,7 +247,7 @@ static int backlight_write_brightness(int value)
 	return 0;
 }
 
-static void set_abm_level(data_t *data, igt_output_t *output, int level)
+static void set_abm_level_sysfs(data_t *data, igt_output_t *output, int level)
 {
 	char buf[PATH_MAX];
 	int fd;
@@ -334,7 +334,7 @@ static void backlight_dpms_cycle(data_t *data)
 		ret = backlight_read_max_brightness(&max_brightness);
 		igt_assert_eq(ret, 0);
 
-		set_abm_level(data, output, 0);
+		set_abm_level_sysfs(data, output, 0);
 		backlight_write_brightness(max_brightness / 2);
 		usleep(100000);
 		pwm_1 = read_target_backlight_pwm(data->drm_fd, output->name);
@@ -365,7 +365,7 @@ static void backlight_monotonic_basic(data_t *data)
 
 		brightness_step = max_brightness / 10;
 
-		set_abm_level(data, output, 0);
+		set_abm_level_sysfs(data, output, 0);
 		backlight_write_brightness(max_brightness);
 		usleep(100000);
 		prev_pwm = read_target_backlight_pwm(data->drm_fd, output->name);
@@ -399,7 +399,7 @@ static void backlight_monotonic_abm(data_t *data)
 
 		brightness_step = max_brightness / 10;
 		for (i = 1; i < 5; i++) {
-			set_abm_level(data, output, i);
+			set_abm_level_sysfs(data, output, i);
 			backlight_write_brightness(max_brightness);
 			usleep(100000);
 			prev_pwm = read_target_backlight_pwm(data->drm_fd, output->name);
@@ -431,14 +431,14 @@ static void abm_enabled(data_t *data)
 		ret = backlight_read_max_brightness(&max_brightness);
 		igt_assert_eq(ret, 0);
 
-		set_abm_level(data, output, 0);
+		set_abm_level_sysfs(data, output, 0);
 		backlight_write_brightness(max_brightness-max_brightness/10);
 		usleep(100000);
 		prev_pwm = read_target_backlight_pwm(data->drm_fd, output->name);
 		pwm_without_abm = prev_pwm;
 
 		for (i = 1; i < 5; i++) {
-			set_abm_level(data, output, i);
+			set_abm_level_sysfs(data, output, i);
 			usleep(100000);
 			page_flip(data, output, 10);
 			pwm = read_target_backlight_pwm(data->drm_fd, output->name);
@@ -466,7 +466,7 @@ static void abm_gradual(data_t *data)
 
 		igt_assert_eq(ret, 0);
 
-		set_abm_level(data, output, 0);
+		set_abm_level_sysfs(data, output, 0);
 		backlight_write_brightness(max_brightness-max_brightness/10);
 
 		sleep(convergence_delay);
@@ -474,7 +474,7 @@ static void abm_gradual(data_t *data)
 		curr = read_current_backlight_pwm(data->drm_fd, output->name);
 
 		igt_assert_eq(prev_pwm, curr);
-		set_abm_level(data, output, 4);
+		set_abm_level_sysfs(data, output, 4);
 		for (i = 0; i < 10; i++) {
 			usleep(100000);
 			page_flip(data, output, 10);
Signature · 1 line
2.50.1
#3 lore raw

PATCH 3/3 tests/amdgpu: Add support for testing compositor control of ABM

In reply to Mario Limonciello

From: Mario Limonciello <[email protected]>

The compositor can directly control ABM, but sysfs should be blocked when this happens. Ensure that sysfs writes fail at that time.

To avoid potential test failures, ensure that sysfs control is enabled at the start of all other tests.

---
 tests/amdgpu/amd_abm.c | 81 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
tests/amdgpu/amd_abm.c +81 -0
index 3c6a7307f..090806d6a 100644
@@ -107,6 +107,45 @@ static void fbmem_draw_smpte_pattern(uint32_t *fbmem, int width, int height)
 	}
 }
 
+static bool set_abm_level_compositor(data_t *data, igt_output_t *output, const char *level)
+{
+	uint32_t type = DRM_MODE_OBJECT_CONNECTOR;
+	uint32_t output_id = output->id;
+	drmModePropertyPtr prop = NULL;
+	uint64_t abm_prop_value;
+	uint32_t abm_prop_id;
+	bool abm_prop_exists;
+	int i;
+
+	abm_prop_exists = kmstest_get_property(
+		data->drm_fd, output_id, type, "adaptive backlight modulation",
+		&abm_prop_id, &abm_prop_value, &prop);
+
+	/* not supported in this kernel */
+	if (!abm_prop_exists)
+		return false;
+
+	igt_assert(prop->count_enums != 0);
+
+	for (i = 0; i < prop->count_enums; i++) {
+		if (strcmp(prop->enums[i].name, level) == 0) {
+			abm_prop_value = prop->enums[i].value;
+			break;
+		}
+	}
+
+	igt_assert_f(i != prop->count_enums,
+		    "ABM property value '%s' not found in connector %s\n",
+		    level, output->name);
+
+	drmModeFreeProperty(prop);
+
+	igt_assert(drmModeConnectorSetProperty(data->drm_fd, output->id,
+					       abm_prop_id, abm_prop_value) == 0);
+
+	return true;
+}
+
 /* Common test setup. */
 static void test_init(data_t *data)
 {
@@ -160,6 +199,8 @@ static void test_init(data_t *data)
 	fbmem_draw_smpte_pattern(data->fb_mem, data->w, data->h);
 	igt_create_color_fb(data->drm_fd, data->mode->hdisplay,
 		data->mode->vdisplay, DRM_FORMAT_XRGB8888, 0, 0.05, 0.05, 0.05, &data->ref_fb2);
+
+	set_abm_level_compositor(data, data->output, "sysfs");
 }
 
 /* Common test cleanup. */
@@ -449,6 +490,44 @@ static void abm_enabled(data_t *data)
 	}
 }
 
+static void abm_compositor(data_t *data)
+{
+	igt_output_t *output;
+	char buf[PATH_MAX];
+	enum pipe pipe;
+	int fd;
+
+	for_each_valid_output_on_pipe(&data->display, pipe, output) {
+		if (output->config.connector->connector_type != DRM_MODE_CONNECTOR_eDP)
+			continue;
+
+		/* allow sysfs writes */
+		if (!set_abm_level_compositor(data, output, "sysfs"))
+			igt_skip("No ABM property\n");
+
+		/* Set ABM to 4 */
+		set_abm_level_sysfs(data, output, 4);
+
+		/* block sysfs and turn off ABM */
+		set_abm_level_compositor(data, output, "min");
+
+		/* ensure a sysfs write fails */
+		igt_assert(snprintf(buf, PATH_MAX, PANEL_POWER_SAVINGS_PATH,
+			   output->name) < PATH_MAX);
+		fd = open(buf, O_WRONLY);
+		igt_assert_eq(snprintf(buf, sizeof(buf), "%d", 4), 1);
+		igt_assert_eq(write(fd, buf, 1), -1);
+		igt_assert_eq(close(fd), 0);
+		igt_assert_eq(errno, EBUSY);
+
+		/* re-enable sysfs */
+		set_abm_level_compositor(data, output, "sysfs");
+
+		/* Set ABM to 0 with sysfs */
+		set_abm_level_sysfs(data, output, 0);
+	}
+}
+
 static void abm_gradual(data_t *data)
 {
 	int ret, i;
@@ -524,6 +603,8 @@ igt_main
 		abm_enabled(&data);
 	igt_subtest("abm_gradual")
 		abm_gradual(&data);
+	igt_subtest("abm_compositor")
+		abm_compositor(&data);
 
 	igt_fixture {
 		test_fini(&data);
Signature · 1 line
2.50.1