From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1629710EB03 for ; Mon, 28 Mar 2022 14:55:24 +0000 (UTC) From: Maxime Ripard To: igt-dev@lists.freedesktop.org, Petri Latvala , Arkadiusz Hiler Date: Mon, 28 Mar 2022 16:55:04 +0200 Message-Id: <20220328145509.2331195-4-maxime@cerno.tech> In-Reply-To: <20220328145509.2331195-1-maxime@cerno.tech> References: <20220328145509.2331195-1-maxime@cerno.tech> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [igt-dev] [PATCH i-g-t v2 3/8] lib/igt_frame: Move frame path creation to function List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pekka Paalanen , Maxime Ripard Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: 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 --- 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