[CRIU] [PATCH 1/2] gcov: mount criu sources into a test mount tree

Andrey Vagin avagin at openvz.org
Fri Mar 4 13:37:59 PST 2016


From: Andrei Vagin <avagin at openvz.org>

CRIU processes save *.gcda and *.gcno files near source files,
so when we restore tests into another mount namespace,
we need to have access to sources from this namespace.

Cc: Sergey Bronnikov <sergeyb at openvz.org>
Reported-by: Sergey Bronnikov <sergeyb at openvz.org>
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 Makefile           |  7 +------
 test/zdtm.py       | 15 +++++++++++++++
 test/zdtm/lib/ns.c | 12 +++++++++++-
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 7569387..77288ff 100644
--- a/Makefile
+++ b/Makefile
@@ -197,13 +197,8 @@ PHONY += cscope
 gcov:
 	$(E) " GCOV"
 	$(Q) test -d gcov || mkdir gcov && \
-	cp criu/*.{gcno,c,h} test/`pwd`/criu/   && \
-	geninfo --output-filename gcov/crtools.h.info --no-recursion criu/ && \
-	geninfo --output-filename gcov/crtools.ns.info --no-recursion test/`pwd`/criu/ && \
-	sed -i "s#/test`pwd`##" gcov/crtools.ns.info && \
+	geninfo --output-filename gcov/criu.info --no-recursion criu/ && \
 	cd gcov && \
-	lcov --rc lcov_branch_coverage=1 --add-tracefile crtools.h.info \
-	--add-tracefile crtools.ns.info --output-file criu.info && \
 	genhtml --rc lcov_branch_coverage=1 --output-directory html criu.info
 	@echo "Code coverage report is in `pwd`/gcov/html/ directory."
 PHONY += gcov
diff --git a/test/zdtm.py b/test/zdtm.py
index 966ed3d..819e536 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -352,6 +352,12 @@ class zdtm_test:
 			if self.__flavor.uns:
 				env['ZDTM_USERNS'] = "1"
 				self.__add_wperms()
+			if os.getenv("GCOV"):
+				criu_dir = os.path.dirname(os.getcwd())
+				criu_dir_r = "%s%s" % (self.__flavor.root, criu_dir)
+
+				env['ZDTM_CRIU'] = os.path.dirname(os.getcwd());
+				subprocess.check_call(["mkdir", "-p", criu_dir_r])
 
 		self.__make_action('pid', env, self.__flavor.root)
 
@@ -707,6 +713,11 @@ class criu_cli:
 
 		a_opts += [ "--timeout", "10" ]
 
+		criu_dir = os.path.dirname(os.getcwd())
+		if os.getenv("GCOV"):
+			a_opts.append("--ext-mount-map")
+			a_opts.append("%s:zdtm" % criu_dir)
+
 		self.__criu_act(action, opts = a_opts + opts)
 
 		if self.__page_server:
@@ -720,6 +731,10 @@ class criu_cli:
 		r_opts += self.__test.getropts()
 
 		self.__prev_dump_iter = None
+		criu_dir = os.path.dirname(os.getcwd())
+		if os.getenv("GCOV"):
+			r_opts.append("--ext-mount-map")
+			r_opts.append("zdtm:%s" % criu_dir)
 		self.__criu_act("restore", opts = r_opts + ["--restore-detached"])
 
 	@staticmethod
diff --git a/test/zdtm/lib/ns.c b/test/zdtm/lib/ns.c
index bc5c395..1f4a1a0 100644
--- a/test/zdtm/lib/ns.c
+++ b/test/zdtm/lib/ns.c
@@ -23,7 +23,7 @@ extern int pivot_root(const char *new_root, const char *put_old);
 static int prepare_mntns(void)
 {
 	int dfd, ret;
-	char *root;
+	char *root, *criu_path;
 	char path[PATH_MAX];
 
 	root = getenv("ZDTM_ROOT");
@@ -47,6 +47,16 @@ static int prepare_mntns(void)
 		return -1;
 	}
 
+	criu_path = getenv("ZDTM_CRIU");
+	if (criu_path) {
+		snprintf(path, sizeof(path), "%s%s", root, criu_path);
+		if (mount(criu_path, path, NULL, MS_BIND, NULL) ||
+		    mount(NULL, path, NULL, MS_PRIVATE, NULL)) {
+			pr_perror("Unable to mount %s", path);
+			return -1;
+		}
+	}
+
 	/* Move current working directory to the new root */
 	ret = readlink("/proc/self/cwd", path, sizeof(path) - 1);
 	if (ret < 0)
-- 
2.5.0



More information about the CRIU mailing list