All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mauro.chehab@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH v3 03/10] runner: cleanup code_cov directory, if any
Date: Wed, 16 Mar 2022 15:59:56 +0100	[thread overview]
Message-ID: <20220316150003.1583681-4-mauro.chehab@linux.intel.com> (raw)
In-Reply-To: <20220316150003.1583681-1-mauro.chehab@linux.intel.com>

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

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

Reviewed-by: Petri Latvala <petri.latvala@intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@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

  parent reply	other threads:[~2022-03-16 15:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16 14:59 [igt-dev] [PATCH v3 00/10] Add support to collect code coverage data Mauro Carvalho Chehab
2022-03-16 14:59 ` [igt-dev] [PATCH v3 01/10] runner: check if it has root permissions Mauro Carvalho Chehab
2022-03-16 14:59 ` [igt-dev] [PATCH v3 02/10] runner: Add support for code coverage Mauro Carvalho Chehab
2022-03-16 14:59 ` Mauro Carvalho Chehab [this message]
2022-03-16 14:59 ` [igt-dev] [PATCH v3 04/10] scripts/code_cov_gather*/sh: add help scripts " Mauro Carvalho Chehab
2022-03-16 14:59 ` [igt-dev] [PATCH v3 05/10] scripts/code_cov_gather_on_build.sh: Improve the script Mauro Carvalho Chehab
2022-03-16 14:59 ` [igt-dev] [PATCH v3 06/10] scripts/code_cov_capture.sh: add a script to use lcov on build+test machine Mauro Carvalho Chehab
2022-03-16 15:00 ` [igt-dev] [PATCH v3 07/10] scripts/code_cov_gen_report.sh: add a script to generate code coverage reports Mauro Carvalho Chehab
2022-03-16 15:00 ` [igt-dev] [PATCH v3 08/10] scripts/run-tests.sh: add code coverage support Mauro Carvalho Chehab
2022-03-16 15:00 ` [igt-dev] [PATCH v3 09/10] scripts:code_cov_gather_on_test: use a faster script Mauro Carvalho Chehab
2022-03-16 15:00 ` [igt-dev] [PATCH v3 10/10] docs: add documentation for code coverage Mauro Carvalho Chehab
2022-03-16 15:44 ` [igt-dev] ✓ Fi.CI.BAT: success for Add support to collect code coverage data Patchwork
2022-03-16 16:53 ` [igt-dev] ✓ Fi.CI.IGT: " 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=20220316150003.1583681-4-mauro.chehab@linux.intel.com \
    --to=mauro.chehab@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /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.