[igt-dev] [PATCH i-g-t v2 3/8] lib/igt_frame: Move frame path creation to function

Maxime Ripard maxime at cerno.tech
Mon Mar 28 14:55:04 UTC 2022


The igt_write_frame_to_png() has some logic to create the PNG filename
Since we'll need the same logic in a future function, let's move it to a
separate function.

Signed-off-by: Maxime Ripard <maxime at cerno.tech>
---
 lib/igt_frame.c | 42 ++++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/lib/igt_frame.c b/lib/igt_frame.c
index 530ccbc32df2..ba29ac028e1b 100644
--- a/lib/igt_frame.c
+++ b/lib/igt_frame.c
@@ -57,6 +57,30 @@ bool igt_frame_dump_is_enabled(void)
 	return igt_frame_dump_path != NULL;
 }
 
+static char *igt_get_frame_path(const char *qualifier, const char *suffix,
+				const char *extension)
+{
+	char *path;
+	const char *test_name;
+	const char *subtest_name;
+	test_name = igt_test_name();
+	subtest_name = igt_subtest_name();
+
+	path = malloc(PATH_MAX);
+	igt_assert(path);
+
+	if (suffix)
+		snprintf(path, PATH_MAX, "%s/frame-%s-%s-%s-%s.%s",
+			 igt_frame_dump_path, test_name, subtest_name, qualifier,
+			 suffix, extension);
+	else
+		snprintf(path, PATH_MAX, "%s/frame-%s-%s-%s.%s",
+			 igt_frame_dump_path, test_name, subtest_name, qualifier,
+			 extension);
+
+	return path;
+}
+
 static void igt_log_frame_path(int summary_fd, char *path)
 {
 	int index = strlen(path);
@@ -72,22 +96,11 @@ static void igt_log_frame_path(int summary_fd, char *path)
 static void igt_write_frame_to_png(cairo_surface_t *surface, int summary_fd,
 				   const char *qualifier, const char *suffix)
 {
-	char path[PATH_MAX];
-	const char *test_name;
-	const char *subtest_name;
+	char *path;
 	cairo_status_t status;
-	int index;
 
-	test_name = igt_test_name();
-	subtest_name = igt_subtest_name();
-
-	if (suffix)
-		snprintf(path, PATH_MAX, "%s/frame-%s-%s-%s-%s.png",
-			 igt_frame_dump_path, test_name, subtest_name, qualifier,
-			 suffix);
-	else
-		snprintf(path, PATH_MAX, "%s/frame-%s-%s-%s.png",
-			 igt_frame_dump_path, test_name, subtest_name, qualifier);
+	path = igt_get_frame_path(qualifier, suffix, "png");
+	igt_assert(path);
 
 	igt_debug("Dumping %s frame to %s...\n", qualifier, path);
 
@@ -96,6 +109,7 @@ static void igt_write_frame_to_png(cairo_surface_t *surface, int summary_fd,
 	igt_assert_eq(status, CAIRO_STATUS_SUCCESS);
 
 	igt_log_frame_path(summary_fd, path);
+	free(path);
 }
 
 /**
-- 
2.35.1



More information about the igt-dev mailing list