Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB9FCC88E72 for ; Thu, 17 Sep 2026 14:55:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2444710E4D0; Thu, 17 Sep 2026 14:55:05 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="UtefngZU"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id F228010E02B for ; Thu, 17 Sep 2026 14:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1789656821; x=1821192821; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tEjPrTmaTWx2Aifiibv63H14hz1g3VgPLWu8H7+yNpI=; b=UtefngZUGfQY+VefXoTCua7jJ5U8YWHv4rZAAS8JzPr5VCyQ7Bxe02k7 XiY/GMLpRlsQLqdXsZPAxnWJyklfNAoLOCbL37zchERBa17cngKK92cbg aICrB64sX6onEXzI6zlJH/Un97bGJR88KtKiO63UO1koLDQf+eO0Gbsu4 ysEJxcE/gyYtqsntV0drIJp3UJQkXtktUI+lmizGZlIVh2jeMUSocz8JF xB7A6ooX77E4+PmQ5UIa6wWYYHNsjH2zp5c8xFs9l8ZjNNe+3uLKqoLMC aloKDZ5UfwIx9yCQBCqIaysw1eANNS0EDsqjfS7gzwBxCLdWXd3zp+Gpm Q==; X-CSE-ConnectionGUID: XpsMxKCVStifqdfHsIXklQ== X-CSE-MsgGUID: NsWHasZmSrWNUcHz0HM3Zg== X-IronPort-AV: E=McAfee;i="6800,10657,11905"; a="89221036" X-IronPort-AV: E=Sophos;i="6.27,103,1787036400"; d="scan'208";a="89221036" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Sep 2026 07:53:40 -0700 X-CSE-ConnectionGUID: I5k0VCM0Re6Wf1pKqmwu8Q== X-CSE-MsgGUID: 9hJETbYdTCepuoTQZfNUBA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,103,1787036400"; d="scan'208";a="270161068" Received: from amilburn-desk.amilburn-desk (HELO localhost) ([10.245.245.74]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Sep 2026 07:53:39 -0700 From: Kamil Konieczny To: igt-dev@lists.freedesktop.org Cc: Kamil Konieczny , Karthik B S , Swati Sharma , =?UTF-8?q?Zbigniew=20Kempczy=C5=84ski?= Subject: [PATCH i-g-t v3 1/2] lib/igt_core: Create new way for finding PNG data files Date: Thu, 17 Sep 2026 16:53:30 +0200 Message-ID: <20260917145331.78274-2-kamil.konieczny@linux.intel.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917145331.78274-1-kamil.konieczny@linux.intel.com> References: <20260917145331.78274-1-kamil.konieczny@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" Reference to build path break reproducibility, as a build could be done on different directories. Data paths are used only when loading a data file containing screen image. Remove build path from the function which use it. Create a new way for finding PNG data files, so a developer can run a test from a build dir and a test could find and load it. Cc: Karthik B S Cc: Swati Sharma Cc: "Zbigniew KempczyƄski" Closes: https://gitlab.freedesktop.org/drm/igt-gpu-tools/-/work_items/190 Signed-off-by: Kamil Konieczny --- lib/igt_core.c | 63 ++++++++++++++++++++++++++++++++++++------------- lib/igt_core.h | 3 +-- lib/meson.build | 1 - 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/lib/igt_core.c b/lib/igt_core.c index 4efddb908..9937cb559 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -366,6 +366,8 @@ enum { static int igt_exitcode = IGT_EXIT_SUCCESS; static const char *command_str; +static const char *command_full_path; +static char command_base_path[PATH_MAX]; static char* igt_log_domain_filter; static struct { @@ -1125,6 +1127,17 @@ static int common_init(int *argc, char **argv, IGT_INIT_LIST_HEAD(&subgroup_descriptions); igt_vec_init(&hook_strs, sizeof(char *)); + command_full_path = argv[0]; + snprintf(command_base_path, ARRAY_SIZE(command_base_path), "%s", argv[0]); + if (strrchr(command_base_path, '/')) { + char *end = strrchr(command_base_path, '/'); + + *end = 0; + } + + if (!strlen(command_base_path)) + strcpy(command_base_path, "."); + command_str = argv[0]; if (strrchr(command_str, '/')) command_str = strrchr(command_str, '/') + 1; @@ -3389,31 +3402,47 @@ void igt_reset_timeout(void) } /** - * __igt_fopen_data: - * @igt_srcdir: Directory path for source files. - * @igt_datadir: Directory path for data files - * @igt_imgdir: Directory path for image files. + * __igt_fopen_data_file: + * @dir: Directory path for source files. + * @rel: Relative path. * @filename: Name of the file to be opened. * - * This function attempts to open a data file from a list of specified - * directories. A file pointer to the opened file. If the file cannot - * be opened, it returns NULL and logs a critical error message. - * + * This function attempts to open a data file from a specified directory dir/dir2/. + * Returns a file pointer to the opened file or NULL. */ -FILE *__igt_fopen_data(const char *igt_srcdir, const char *igt_datadir, - const char *igt_imgdir, const char *filename) +static FILE *__igt_fopen_data_file(const char *dir, const char *rel, const char *filename) { char path[PATH_MAX]; FILE *fp; - const char *dirs[] = {igt_datadir, igt_srcdir, igt_imgdir, - getenv("IGT_DATA_PATH"), "./data"}; - for (int i = 0; i < ARRAY_SIZE(dirs); i++) { + snprintf(path, ARRAY_SIZE(path), "%s/%s/%s", dir, rel, filename); + fp = fopen(path, "r"); + + return fp; +} + +/** + * igt_fopen_data: + * @filename: Name of the file to be opened. + * + * This function attempts to open a data file from a list of known directories. + * + * Returns a file pointer to the opened file. If the file cannot be opened, it + * returns NULL and logs a critical error message. + */ +FILE *igt_fopen_data(const char *filename) +{ + static const char *igt_datadir = IGT_DATADIR; + static const char *igt_srcdir = IGT_SRCDIR; + static const char *reldirs[] = {".", "..", "./data", "../data", "../../data" }; + const char *dirs[] = {igt_datadir, igt_srcdir, command_base_path, + getenv("IGT_DATA_PATH"), "."}; + FILE *fp = NULL; + + for (int i = 0; i < ARRAY_SIZE(dirs) && !fp; i++) { if (dirs[i]) { - snprintf(path, sizeof(path), "%s/%s", dirs[i], filename); - fp = fopen(path, "r"); - if (fp) - break; + for (int j = 0; j < ARRAY_SIZE(reldirs) && !fp; j++) + fp = __igt_fopen_data_file(dirs[i], reldirs[j], filename); } } diff --git a/lib/igt_core.h b/lib/igt_core.h index afaf35aa8..c0908a8ed 100644 --- a/lib/igt_core.h +++ b/lib/igt_core.h @@ -1532,8 +1532,7 @@ FILE *__igt_fopen_data(const char *igt_srcdir, const char *igt_datadir, * Open a datafile for test, first try from installation directory, * then from build directory, and finally from current directory. */ -#define igt_fopen_data(filename) \ - __igt_fopen_data(IGT_SRCDIR, IGT_DATADIR, IGT_IMGDIR, filename) +FILE *igt_fopen_data(const char *filename); int igt_system(const char *command); int igt_system_quiet(const char *command); diff --git a/lib/meson.build b/lib/meson.build index d1a770b6d..2ac632758 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -371,7 +371,6 @@ foreach f: lib_sources '-DIGT_DATADIR="@0@"'.format(join_paths(prefix, datadir)), '-DIGT_SRCDIR="@0@"'.format(srcdir), '-DIGT_LOG_DOMAIN="@0@"'.format(f.split('.')[0]), - '-DIGT_IMGDIR="@0@"'.format(imgdir), ]) lib_intermediates += lib -- 2.55.0