[PATCH 4/5] lib: update fopen() to accomodate imgdir

Reddy Guddati, Santhosh santhosh.reddy.guddati at intel.com
Wed Nov 20 03:06:40 UTC 2024


Hi Rama,

On 19-11-2024 13:22, Naladala Ramanaidu wrote:
> From: "Naladala, Ramanaidu" <ramanaidu.naladala at intel.com>
> 
> Update fopen() to accomodate imgage directory path. Tests like kms_3d
> use this function while creating fb from png image.
> 
> Signed-off-by: Ramanaidu Naladala <ramanaidu.naladala at intel.com>
> Signed-off-by: Swati Sharma <swati2.sharma at intel.com>
> ---
>   lib/igt_core.c | 17 +++++++++++++++--
>   lib/igt_core.h |  4 ++--
>   2 files changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index 407f7b551..8dae8f51d 100644
> --- a/lib/igt_core.c
> +++ b/lib/igt_core.c
> @@ -3306,10 +3306,11 @@ void igt_reset_timeout(void)
>   }
>   
>   FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
> -		       const char* filename)
> +		       const char* igt_imgdir, const char* filename)
>   {
>   	char path[PATH_MAX];
>   	FILE *fp;
> +	char *abpath;
>   
>   	snprintf(path, sizeof(path), "%s/%s", igt_datadir, filename);
>   	fp = fopen(path, "r");
> @@ -3317,8 +3318,20 @@ FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
>   		snprintf(path, sizeof(path), "%s/%s", igt_srcdir, filename);
>   		fp = fopen(path, "r");
>   	}
> +
> +	if (!fp) {
> +		snprintf(path, sizeof(path), "%s/%s", igt_imgdir, filename);
> +		fp = fopen(path, "r");
> +        }
> +
> +	if (!fp) {
> +		abpath = getenv("IMGDIR");
 >> check for the return value of getenv before usig abpath.
	if (abpath) {}
> +                snprintf(path, sizeof(path), "%s/%s", abpath, filename);
> +                fp = fopen(path, "r");
> +        }
> +
>   	if (!fp) {
> -		snprintf(path, sizeof(path), "./%s", filename);
> +		snprintf(path, sizeof(path), "./data/%s", filename);
>   		fp = fopen(path, "r");
>   	}
 >> Also , imo It would be better to move the repeated code for 
constructing path to a seperate helper function.
>   
> diff --git a/lib/igt_core.h b/lib/igt_core.h
> index 90f57402f..5b058a8d0 100644
> --- a/lib/igt_core.h
> +++ b/lib/igt_core.h
> @@ -1457,7 +1457,7 @@ 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);
> +		       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);



More information about the igt-dev mailing list