From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id CD88110F21F for ; Thu, 14 Apr 2022 12:25:29 +0000 (UTC) From: Mauro Carvalho Chehab To: igt-dev@lists.freedesktop.org, Petri Latvala Date: Thu, 14 Apr 2022 14:24:54 +0200 Message-Id: <3419c77ef1bb3477ec70b4cd3c7df1380cdbba8f.1649939026.git.mchehab@kernel.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [igt-dev] [PATCH v3 04/12] runner: execute code coverage script also from PATH List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ch Sai Gowtham , Andrzej Hajda Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: From: Mauro Carvalho Chehab In order to prepare to execute the code coverage scripts from the PATH, change the logic at settings in order for it to seek for the script in the PATH, if it doesn't contain any directories on its filename. Note: file search routines were moved (unchanged) on this path, in order to avoid forward prototype declarations. Reviewed-by: Petri Latvala Signed-off-by: Mauro Carvalho Chehab --- To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH v3 00/12] at: https://lore.kernel.org/all/cover.1649939026.git.mchehab@kernel.org/ runner/settings.c | 109 +++++++++++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 41 deletions(-) diff --git a/runner/settings.c b/runner/settings.c index cd64b964e5ac..bb63a9f4a1e5 100644 --- a/runner/settings.c +++ b/runner/settings.c @@ -403,6 +403,73 @@ static bool executable_file(const char *filename) return !access(filename, X_OK); } +static char *_dirname(const char *path) +{ + char *tmppath = strdup(path); + char *tmpname = dirname(tmppath); + tmpname = strdup(tmpname); + free(tmppath); + return tmpname; +} + +static char *_basename(const char *path) +{ + char *tmppath = strdup(path); + char *tmpname = basename(tmppath); + tmpname = strdup(tmpname); + free(tmppath); + return tmpname; +} + +char *absolute_path(char *path) +{ + char *result = NULL; + char *base, *dir; + char *ret; + + result = realpath(path, NULL); + if (result != NULL) + return result; + + dir = _dirname(path); + ret = absolute_path(dir); + free(dir); + + base = _basename(path); + asprintf(&result, "%s/%s", ret, base); + free(base); + free(ret); + + return result; +} + +static char *bin_path(char *fname) +{ + char *path, *p; + char file[PATH_MAX]; + + if (strchr(fname, '/')) + return absolute_path(fname); + + path = strdup(getenv("PATH")); + p = strtok(path, ":"); + do { + if (*p) { + strcpy(file, p); + strcat(file, "/"); + strcat(file, fname); + if (executable_file(file)) { + free(path); + return strdup(file); + } + } + p = strtok(NULL, ":"); + } while (p); + + free(path); + return strdup(fname); +} + static void print_version(void) { struct utsname uts; @@ -536,7 +603,7 @@ bool parse_options(int argc, char **argv, settings->cov_results_per_test = true; break; case OPT_CODE_COV_SCRIPT: - settings->code_coverage_script = absolute_path(optarg); + settings->code_coverage_script = bin_path(optarg); break; case OPT_MULTIPLE: @@ -703,46 +770,6 @@ bool validate_settings(struct settings *settings) return true; } -static char *_dirname(const char *path) -{ - char *tmppath = strdup(path); - char *tmpname = dirname(tmppath); - tmpname = strdup(tmpname); - free(tmppath); - return tmpname; -} - -static char *_basename(const char *path) -{ - char *tmppath = strdup(path); - char *tmpname = basename(tmppath); - tmpname = strdup(tmpname); - free(tmppath); - return tmpname; -} - -char *absolute_path(char *path) -{ - char *result = NULL; - char *base, *dir; - char *ret; - - result = realpath(path, NULL); - if (result != NULL) - return result; - - dir = _dirname(path); - ret = absolute_path(dir); - free(dir); - - base = _basename(path); - asprintf(&result, "%s/%s", ret, base); - free(base); - free(ret); - - return result; -} - static char settings_filename[] = "metadata.txt"; bool serialize_settings(struct settings *settings) { -- 2.35.1