Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Naladala Ramanaidu <ramanaidu.naladala@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: swati2.sharma@intel.com, santhosh.reddy.guddati@intel.com,
	Naladala Ramanaidu <ramanaidu.naladala@intel.com>
Subject: [PATCH i-g-t v2 4/5] lib/igt_core: Enhance __igt_fopen_data to support additional directories
Date: Wed,  8 Jan 2025 01:36:13 +0530	[thread overview]
Message-ID: <20250107200614.963199-5-ramanaidu.naladala@intel.com> (raw)
In-Reply-To: <20250107200614.963199-1-ramanaidu.naladala@intel.com>

Add an additional parameter for the image directory. Refactor the
function to use an array of directories to iterate through, reducing
redundancy. Include a check for the "IGT_RUNNER_DATA" environment
variable.

v2: Fix review comments.   (Santhosh, Kamil)

Signed-off-by: Naladala Ramanaidu <ramanaidu.naladala@intel.com>
Signed-off-by: Swati Sharma <swati2.sharma@intel.com>
---
 lib/igt_core.c | 31 +++++++++++++++----------------
 lib/igt_core.h |  6 +++---
 2 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 407f7b551..cd43d276a 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -3305,27 +3305,26 @@ void igt_reset_timeout(void)
 	igt_set_timeout(0, NULL);
 }
 
-FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
-		       const char* filename)
+FILE *__igt_fopen_data(const char *igt_srcdir, const char *igt_datadir,
+		       const char *igt_imgdir, const char *filename)
 {
 	char path[PATH_MAX];
 	FILE *fp;
-
-	snprintf(path, sizeof(path), "%s/%s", igt_datadir, filename);
-	fp = fopen(path, "r");
-	if (!fp) {
-		snprintf(path, sizeof(path), "%s/%s", igt_srcdir, filename);
-		fp = fopen(path, "r");
-	}
-	if (!fp) {
-		snprintf(path, sizeof(path), "./%s", filename);
-		fp = fopen(path, "r");
+	size_t i;
+	const char *dirs[] = {igt_datadir, igt_srcdir, igt_imgdir,
+				     getenv("IGT_RUNNER_DATA"), "./data"};
+
+	for (i = 0; i < ARRAY_SIZE(dirs); i++) {
+		if (dirs[i]) {
+			snprintf(path, sizeof(path), "%s/%s", dirs[i], filename);
+			fp = fopen(path, "r");
+			if (fp)
+				return fp;
+		}
 	}
 
-	if (!fp)
-		igt_critical("Could not open data file \"%s\": %m\n", filename);
-
-	return fp;
+	igt_critical("Could not open data file \"%s\": %m\n", filename);
+	return NULL;
 }
 
 static void log_output(int *fd, enum igt_log_level level)
diff --git a/lib/igt_core.h b/lib/igt_core.h
index f0ba1a381..05134a104 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -1456,8 +1456,8 @@ static inline uint32_t igt_seconds_elapsed(struct timespec *start)
 
 void igt_reset_timeout(void);
 
-FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
-		       const char* filename);
+FILE *__igt_fopen_data(const char *igt_srcdir, const char *igt_datadir,
+		       const char *igt_imgdir, const char *filename);
 /**
  * igt_fopen_data:
  * @filename: filename to open.
@@ -1466,7 +1466,7 @@ FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
  * then from build directory, and finally from current directory.
  */
 #define igt_fopen_data(filename) \
-	__igt_fopen_data(IGT_SRCDIR, IGT_DATADIR, filename)
+	__igt_fopen_data(IGT_SRCDIR, IGT_DATADIR, IGT_IMGDIR, filename)
 
 int igt_system(const char *command);
 int igt_system_quiet(const char *command);
-- 
2.43.0


  parent reply	other threads:[~2025-01-07 20:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-07 20:06 [PATCH i-g-t v2 0/5] Update image assets Naladala Ramanaidu
2025-01-07 20:06 ` [PATCH i-g-t v2 1/5] data: Move PNG images to new data directory Naladala Ramanaidu
2025-01-07 20:06 ` [PATCH i-g-t v2 2/5] runner/settings: Constify absolute_path parameter Naladala Ramanaidu
2025-01-16 12:29   ` Kamil Konieczny
2025-01-07 20:06 ` [PATCH i-g-t v2 3/5] runner/settings: Add function to set IGT_RUNNER_DATA environment variable Naladala Ramanaidu
2025-01-16  9:51   ` Kamil Konieczny
2025-01-16 12:36   ` Kamil Konieczny
2025-02-18 21:14     ` Naladala, Ramanaidu
2025-01-07 20:06 ` Naladala Ramanaidu [this message]
2025-01-07 20:06 ` [PATCH i-g-t v2 5/5] HAX patch do not merge Naladala Ramanaidu
2025-01-07 23:16 ` ✗ i915.CI.BAT: failure for Update image assets (rev3) Patchwork
2025-01-07 23:17 ` ✓ Xe.CI.BAT: success " Patchwork
2025-01-09 15:19 ` ✗ Xe.CI.Full: failure " Patchwork
2025-01-10  6:37 ` ✓ i915.CI.BAT: success " Patchwork
2025-01-14 11:48 ` ✗ i915.CI.Full: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250107200614.963199-5-ramanaidu.naladala@intel.com \
    --to=ramanaidu.naladala@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=santhosh.reddy.guddati@intel.com \
    --cc=swati2.sharma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox