From patchwork Wed Jul 19 13:46:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Kocialkowki X-Patchwork-Id: 9852037 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7829D602BD for ; Wed, 19 Jul 2017 13:46:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 667C0285BE for ; Wed, 19 Jul 2017 13:46:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B0C328662; Wed, 19 Jul 2017 13:46:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8F44B285BE for ; Wed, 19 Jul 2017 13:46:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D6EBF6E528; Wed, 19 Jul 2017 13:46:26 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0BF256E0BC for ; Wed, 19 Jul 2017 13:46:23 +0000 (UTC) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jul 2017 06:46:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,381,1496127600"; d="scan'208";a="113083507" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP; 19 Jul 2017 06:46:22 -0700 Received: from workstation.fi.intel.com (workstation.fi.intel.com [10.237.68.144]) by linux.intel.com (Postfix) with ESMTP id A71D95808DF; Wed, 19 Jul 2017 06:46:20 -0700 (PDT) From: Paul Kocialkowski To: intel-gfx@lists.freedesktop.org Date: Wed, 19 Jul 2017 16:46:07 +0300 Message-Id: <20170719134610.8278-5-paul.kocialkowski@linux.intel.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170719134610.8278-1-paul.kocialkowski@linux.intel.com> References: <20170705080435.26789-1-paul.kocialkowski@linux.intel.com> <20170719134610.8278-1-paul.kocialkowski@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v5 4/7] Introduce common frame dumping configuration and helpers X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP This introduces a common FrameDumpPath configuration field, as well as helper functions in dedicated igt_frame for writing cairo surfaces to png files. Signed-off-by: Paul Kocialkowski --- lib/Makefile.sources | 2 + lib/igt.h | 1 + lib/igt_core.c | 12 +++++ lib/igt_core.h | 2 +- lib/igt_frame.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_frame.h | 43 ++++++++++++++++ 6 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 lib/igt_frame.c create mode 100644 lib/igt_frame.h diff --git a/lib/Makefile.sources b/lib/Makefile.sources index 53fdb54c..c2e58809 100644 --- a/lib/Makefile.sources +++ b/lib/Makefile.sources @@ -83,6 +83,8 @@ lib_source_list = \ uwildmat/uwildmat.c \ igt_kmod.c \ igt_kmod.h \ + igt_frame.c \ + igt_frame.h \ $(NULL) .PHONY: version.h.tmp diff --git a/lib/igt.h b/lib/igt.h index a069deb3..d16a4991 100644 --- a/lib/igt.h +++ b/lib/igt.h @@ -34,6 +34,7 @@ #include "igt_draw.h" #include "igt_dummyload.h" #include "igt_fb.h" +#include "igt_frame.h" #include "igt_gt.h" #include "igt_kms.h" #include "igt_pm.h" diff --git a/lib/igt_core.c b/lib/igt_core.c index 1ba79361..5a3b00e8 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -235,6 +235,10 @@ * An example configuration follows: * * |[ + * # The common configuration secton follows. + * [Common] + * FrameDumpPath=/tmp # The path to dump frames that fail comparison checks + * * # The following section is used for configuring the Device Under Test. * # It is not mandatory and allows overriding default values. * [DUT] @@ -290,6 +294,7 @@ static struct { static pthread_mutex_t log_buffer_mutex = PTHREAD_MUTEX_INITIALIZER; GKeyFile *igt_key_file; +char *frame_dump_path; const char *igt_test_name(void) { @@ -621,6 +626,13 @@ static int config_parse(void) if (!igt_key_file) return 0; + frame_dump_path = getenv("IGT_FRAME_DUMP_PATH"); + + if (!frame_dump_path) + frame_dump_path = g_key_file_get_string(igt_key_file, "Common", + "FrameDumpPath", + &error); + rc = g_key_file_get_integer(igt_key_file, "DUT", "SuspendResumeDelay", &error); if (error && error->code == G_KEY_FILE_ERROR_INVALID_VALUE) diff --git a/lib/igt_core.h b/lib/igt_core.h index 0739ca83..1619a9d6 100644 --- a/lib/igt_core.h +++ b/lib/igt_core.h @@ -50,7 +50,7 @@ extern const char* __igt_test_description __attribute__((weak)); extern bool __igt_plain_output; extern GKeyFile *igt_key_file; - +extern char *frame_dump_path; /** * IGT_TEST_DESCRIPTION: diff --git a/lib/igt_frame.c b/lib/igt_frame.c new file mode 100644 index 00000000..dfafe53d --- /dev/null +++ b/lib/igt_frame.c @@ -0,0 +1,137 @@ +/* + * Copyright © 2017 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Paul Kocialkowski + */ + +#include "config.h" + +#include +#include +#include + +#include "igt.h" + +/** + * SECTION:igt_frame + * @short_description: Library for frame-related tests + * @title: Frame + * @include: igt_frame.h + * + * This library contains helpers for frame-related tests. This includes common + * frame dumping as well as frame comparison helpers. + */ + +/** + * igt_frame_dump_is_enabled: + * + * Get whether frame dumping is enabled. + * + * Returns: A boolean indicating whether frame dumping is enabled + */ +bool igt_frame_dump_is_enabled(void) +{ + return frame_dump_path != NULL; +} + +static void igt_write_frame_to_png(cairo_surface_t *surface, int fd, + const char *qualifier, const char *suffix) +{ + char path[PATH_MAX]; + const char *test_name; + const char *subtest_name; + 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", + frame_dump_path, test_name, subtest_name, qualifier, + suffix); + else + snprintf(path, PATH_MAX, "%s/frame-%s-%s-%s.png", + frame_dump_path, test_name, subtest_name, qualifier); + + igt_debug("Dumping %s frame to %s...\n", qualifier, path); + + status = cairo_surface_write_to_png(surface, path); + + igt_assert_eq(status, CAIRO_STATUS_SUCCESS); + + index = strlen(path); + + if (fd >= 0 && index < (PATH_MAX - 1)) { + path[index++] = '\n'; + path[index] = '\0'; + + write(fd, path, strlen(path)); + } +} + +/** + * igt_write_compared_frames_to_png: + * @reference: The reference cairo surface + * @capture: The captured cairo surface + * @reference_suffix: The suffix to give to the reference png file + * @capture_suffix: The suffix to give to the capture png file + * + * Write previously compared frames to png files. + */ +void igt_write_compared_frames_to_png(cairo_surface_t *reference, + cairo_surface_t *capture, + const char *reference_suffix, + const char *capture_suffix) +{ + char *id; + const char *test_name; + const char *subtest_name; + char path[PATH_MAX]; + int fd = -1; + + if (!igt_frame_dump_is_enabled()) + return; + + id = getenv("IGT_FRAME_DUMP_ID"); + + test_name = igt_test_name(); + subtest_name = igt_subtest_name(); + + if (id) + snprintf(path, PATH_MAX, "%s/frame-%s-%s-%s.txt", + frame_dump_path, test_name, subtest_name, id); + else + snprintf(path, PATH_MAX, "%s/frame-%s-%s.txt", + frame_dump_path, test_name, subtest_name); + + fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + igt_assert(fd >= 0); + + igt_debug("Writing dump report to %s...\n", path); + + igt_write_frame_to_png(reference, fd, "reference", reference_suffix); + igt_write_frame_to_png(capture, fd, "capture", capture_suffix); + + close(fd); +} diff --git a/lib/igt_frame.h b/lib/igt_frame.h new file mode 100644 index 00000000..ec6a1643 --- /dev/null +++ b/lib/igt_frame.h @@ -0,0 +1,43 @@ +/* + * Copyright © 2017 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Paul Kocialkowski + */ + +#ifndef IGT_FRAME_H +#define IGT_FRAME_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "igt.h" +#include + +bool igt_frame_dump_is_enabled(void); +void igt_write_compared_frames_to_png(cairo_surface_t *reference, + cairo_surface_t *capture, + const char *reference_suffix, + const char *capture_suffix); + +#endif