From: Swati Sharma <swati2.sharma@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Naladala Ramanaidu <ramanaidu.naladala@intel.com>,
Swati Sharma <swati2.sharma@intel.com>
Subject: [PATCH i-g-t 4/8] lib/igt_core: Enhance __igt_fopen_data to support additional directories
Date: Sat, 11 Jan 2025 01:20:56 +0530 [thread overview]
Message-ID: <20250110195100.150301-5-swati2.sharma@intel.com> (raw)
In-Reply-To: <20250110195100.150301-1-swati2.sharma@intel.com>
From: Naladala Ramanaidu <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.25.1
next prev parent reply other threads:[~2025-01-10 19:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-10 19:50 [PATCH i-g-t 0/8] New sharpness tool Swati Sharma
2025-01-10 19:50 ` [PATCH i-g-t 1/8] data: Move PNG images to new data directory Swati Sharma
2025-01-10 19:50 ` [PATCH i-g-t 2/8] runner/settings: Constify absolute_path parameter Swati Sharma
2025-01-10 19:50 ` [PATCH i-g-t 3/8] runner/settings: Add function to set IGT_RUNNER_DATA environment variable Swati Sharma
2025-01-10 19:50 ` Swati Sharma [this message]
2025-01-10 19:50 ` [PATCH i-g-t 5/8] lib/igt_kms: Add "sharpness strength" as crtc property Swati Sharma
2025-01-10 19:50 ` [PATCH i-g-t 6/8] tools: Add new sharpness tool Swati Sharma
2025-04-08 18:48 ` Naladala, Ramanaidu
2025-01-10 19:50 ` [PATCH i-g-t 7/8] data: Add image Swati Sharma
2025-01-10 19:51 ` [PATCH i-g-t 8/8] meson: Add sharpness tool Swati Sharma
2025-01-10 20:02 ` ✗ Fi.CI.BUILD: failure for New sharpness tool (rev2) 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=20250110195100.150301-5-swati2.sharma@intel.com \
--to=swati2.sharma@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=ramanaidu.naladala@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.