[PATCH i-g-t v1 2/2] tests/intel/kms_pm_backlight: Refactor and use functions from lib

Santhosh Reddy Guddati santhosh.reddy.guddati at intel.com
Tue Oct 15 16:23:36 UTC 2024


Refactor the code to use the backlight_read and write from library
update struct names to maintain consistency.
Move defines to lib.

Signed-off-by: Santhosh Reddy Guddati <santhosh.reddy.guddati at intel.com>
---
 tests/intel/kms_pm_backlight.c | 77 +++++-----------------------------
 1 file changed, 11 insertions(+), 66 deletions(-)

diff --git a/tests/intel/kms_pm_backlight.c b/tests/intel/kms_pm_backlight.c
index 196b5af03..59002e3f4 100644
--- a/tests/intel/kms_pm_backlight.c
+++ b/tests/intel/kms_pm_backlight.c
@@ -72,13 +72,6 @@
  * Functionality: backlight, dpms
  */
 
-struct context {
-	int max;
-	int old;
-	igt_output_t *output;
-	char path[PATH_MAX];
-};
-
 enum {
 	TEST_NONE = 0,
 	TEST_DPMS,
@@ -87,7 +80,6 @@ enum {
 };
 
 #define TOLERANCE 5 /* percent */
-#define BACKLIGHT_PATH "/sys/class/backlight"
 
 #define FADESTEPS 10
 #define FADESPEED 100 /* milliseconds between steps */
@@ -96,55 +88,7 @@ enum {
 
 IGT_TEST_DESCRIPTION("Basic backlight sysfs test");
 
-static int backlight_read(int *result, const char *fname, struct context *context)
-{
-	int fd;
-	char full[PATH_MAX];
-	char dst[64];
-	int r, e;
-
-	igt_assert(snprintf(full, PATH_MAX, "%s/%s/%s", BACKLIGHT_PATH, context->path, fname)
-			    < PATH_MAX);
-	fd = open(full, O_RDONLY);
-	if (fd == -1)
-		return -errno;
-
-	r = read(fd, dst, sizeof(dst));
-	e = errno;
-	close(fd);
-
-	if (r < 0)
-		return -e;
-
-	errno = 0;
-	*result = strtol(dst, NULL, 10);
-	return errno;
-}
-
-static int backlight_write(int value, const char *fname, struct context *context)
-{
-	int fd;
-	char full[PATH_MAX];
-	char src[64];
-	int len;
-
-	igt_assert(snprintf(full, PATH_MAX, "%s/%s/%s", BACKLIGHT_PATH, context->path, fname)
-		   < PATH_MAX);
-	fd = open(full, O_WRONLY);
-	if (fd == -1)
-		return -errno;
-
-	len = snprintf(src, sizeof(src), "%i", value);
-	len = write(fd, src, len);
-	close(fd);
-
-	if (len < 0)
-		return len;
-
-	return 0;
-}
-
-static void test_and_verify(struct context *context, int val)
+static void test_and_verify(intel_backlight_context_t *context, int val)
 {
 	const int tolerance = val * TOLERANCE / 100;
 	int result;
@@ -162,14 +106,14 @@ static void test_and_verify(struct context *context, int val)
 		     result, val, tolerance);
 }
 
-static void test_brightness(struct context *context)
+static void test_brightness(intel_backlight_context_t *context)
 {
 	test_and_verify(context, 0);
 	test_and_verify(context, context->max);
 	test_and_verify(context, context->max / 2);
 }
 
-static void test_bad_brightness(struct context *context)
+static void test_bad_brightness(intel_backlight_context_t *context)
 {
 	int val;
 	/* First write some sane value */
@@ -186,7 +130,7 @@ static void test_bad_brightness(struct context *context)
 	igt_assert_eq(val, context->max / 2);
 }
 
-static void test_fade(struct context *context)
+static void test_fade(intel_backlight_context_t *context)
 {
 	int i;
 	static const struct timespec ts = { .tv_sec = 0, .tv_nsec = FADESPEED*1000000 };
@@ -218,7 +162,7 @@ check_dpms(igt_output_t *output)
 	igt_assert(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_ACTIVE));
 }
 
-static void check_dpms_cycle(struct context *context)
+static void check_dpms_cycle(intel_backlight_context_t *context)
 {
 	int max, val_1, val_2;
 
@@ -286,11 +230,11 @@ igt_main
 	igt_output_t *output;
 	char file_path_n[PATH_MAX] = "";
 	bool dual_edp = false;
-	struct context contexts[NUM_EDP_OUTPUTS];
+	intel_backlight_context_t contexts[NUM_EDP_OUTPUTS];
 	struct {
 		const char *name;
 		const char *desc;
-		void (*test_t) (struct context *);
+		void (*test_t)(intel_backlight_context_t *context);
 		int flags;
 	} tests[] = {
 		{ "basic-brightness", "test the basic brightness.", test_brightness, TEST_NONE },
@@ -320,11 +264,12 @@ igt_main
 
 			if (found)
 				snprintf(file_path_n, PATH_MAX, "%s/card%i-%s-backlight/brightness",
-					 BACKLIGHT_PATH, igt_device_get_card_index(display.drm_fd),
+					 INTEL_BACKLIGHT_PATH,
+					 igt_device_get_card_index(display.drm_fd),
 					 igt_output_name(output));
 			else
 				snprintf(file_path_n, PATH_MAX, "%s/intel_backlight/brightness",
-					 BACKLIGHT_PATH);
+					 INTEL_BACKLIGHT_PATH);
 
 			fd = open(file_path_n, O_RDONLY);
 			if (fd == -1)
@@ -340,7 +285,7 @@ igt_main
 			close(fd);
 
 			/* should be ../../cardX-$output */
-			snprintf(file_path_n, PATH_MAX, "%s/%s/device", BACKLIGHT_PATH,
+			snprintf(file_path_n, PATH_MAX, "%s/%s/device", INTEL_BACKLIGHT_PATH,
 				 contexts[i].path);
 			igt_assert_lt(16, readlink(file_path_n, full_name, sizeof(full_name) - 1));
 			name = basename(full_name);
-- 
2.34.1



More information about the igt-dev mailing list