[igt-dev] [PATCH v3 03/10] runner: cleanup code_cov directory, if any

Mauro Carvalho Chehab mauro.chehab at linux.intel.com
Wed Mar 16 14:59:56 UTC 2022


From: Mauro Carvalho Chehab <mchehab at kernel.org>

Ensure that "-o" parameter will also cleanup the contents of the
code coverage results directory.

Reviewed-by: Petri Latvala <petri.latvala at intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab at kernel.org>
---
 runner/executor.c | 59 ++++++++++++++++++++++++++++++++++++-----------
 runner/settings.h |  2 +-
 2 files changed, 47 insertions(+), 14 deletions(-)

diff --git a/runner/executor.c b/runner/executor.c
index ab00900c6d44..b4efc4fdbf81 100644
--- a/runner/executor.c
+++ b/runner/executor.c
@@ -20,6 +20,7 @@
 #include <sys/types.h>
 #include <sys/utsname.h>
 #include <sys/wait.h>
+#include <dirent.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -1446,8 +1447,11 @@ static bool clear_test_result_directory(int dirfd)
 
 static bool clear_old_results(char *path)
 {
+	struct dirent *entry;
+	char name[PATH_MAX];
 	int dirfd;
 	size_t i;
+	DIR *dir;
 
 	if ((dirfd = open(path, O_DIRECTORY | O_RDONLY)) < 0) {
 		if (errno == ENOENT) {
@@ -1469,7 +1473,6 @@ static bool clear_old_results(char *path)
 	}
 
 	for (i = 0; true; i++) {
-		char name[32];
 		int resdirfd;
 
 		snprintf(name, sizeof(name), "%zd", i);
@@ -1488,6 +1491,31 @@ static bool clear_old_results(char *path)
 		}
 	}
 
+	strcpy(name, path);
+	strcat(name, "/" CODE_COV_RESULTS_PATH);
+	if ((dir = opendir(name)) != NULL) {
+		char *p;
+
+		strcat(name, "/");
+		p = name + strlen(name);
+
+		while ((entry = readdir(dir)) != NULL) {
+			if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
+				continue;
+
+			strcpy(p, entry->d_name);
+			if (unlink(name))  {
+				errf("Error removing %s\n", name);
+			}
+		}
+
+		closedir(dir);
+		if (unlinkat(dirfd, CODE_COV_RESULTS_PATH, AT_REMOVEDIR)) {
+			errf("Warning: Result directory %s/%s contains extra files\n",
+			     path, CODE_COV_RESULTS_PATH);
+		}
+	}
+
 	close(dirfd);
 
 	return true;
@@ -1818,7 +1846,7 @@ static void code_coverage_stop(struct settings *settings, const char *job_name,
 	name[j] = '\0';
 
 	strcpy(fname, settings->results_path);
-	strcat(fname, CODE_COV_RESULTS_PATH "/");
+	strcat(fname, "/" CODE_COV_RESULTS_PATH "/");
 	strcat(fname, name);
 
 	argv[0] = settings->code_coverage_script;
@@ -1844,17 +1872,6 @@ bool execute(struct execute_state *state,
 		return true;
 	}
 
-	if (settings->enable_code_coverage && !settings->cov_results_per_test) {
-		char *reason = NULL;
-
-		code_coverage_start(settings, -1, &reason);
-		if (reason != NULL) {
-			errf("%s\n", reason);
-			free(reason);
-			status = false;
-		}
-	}
-
 	if ((resdirfd = open(settings->results_path, O_DIRECTORY | O_RDONLY)) < 0) {
 		/* Initialize state should have done this */
 		errf("Error: Failure opening results path %s\n",
@@ -1862,6 +1879,22 @@ bool execute(struct execute_state *state,
 		return false;
 	}
 
+	if (settings->enable_code_coverage) {
+		if (!settings->cov_results_per_test) {
+			char *reason = NULL;
+
+			code_coverage_start(settings, -1, &reason);
+			if (reason != NULL) {
+				errf("%s\n", reason);
+				free(reason);
+				close(resdirfd);
+				return false;
+			}
+		}
+
+		mkdirat(resdirfd, CODE_COV_RESULTS_PATH, 0755);
+	}
+
 	if ((testdirfd = open(settings->test_root, O_DIRECTORY | O_RDONLY)) < 0) {
 		errf("Error: Failure opening test root %s\n",
 		     settings->test_root);
diff --git a/runner/settings.h b/runner/settings.h
index 3c2a3ee9c336..bbd965d27882 100644
--- a/runner/settings.h
+++ b/runner/settings.h
@@ -22,7 +22,7 @@ _Static_assert(ABORT_ALL == (ABORT_TAINT | ABORT_LOCKDEP | ABORT_PING), "ABORT_A
 
 #define GCOV_DIR		"/sys/kernel/debug/gcov"
 #define GCOV_RESET GCOV_DIR	"/reset"
-#define CODE_COV_RESULTS_PATH	"/code_cov"
+#define CODE_COV_RESULTS_PATH	"code_cov"
 
 struct regex_list {
 	char **regex_strings;
-- 
2.35.1



More information about the igt-dev mailing list