[CRIU] [PATCH 2/2][v2] zdtm.py: add support of test reports in TAP format

Sergey Bronnikov sergeyb at openvz.org
Fri Mar 4 03:53:25 PST 2016


Usually we run CRIU tests automatically using Jenkins CI and it reports status
as PASS/FAIL for overall testsuite on used environment. You should dig into log
files to figure out how many tests were failed and skipped. This patch brings
support of cute reports in TAP (Test Anything Protocol) format.

The sample of report:

TAP version 13
1..242
ok 1 - conntracks # SKIP manual run only
ok 2 - busyloop00
ok 3 - sleeping00
ok 4 - pid00
ok 5 - caps00
ok 6 - wait00

NOTE: report will be generated only when options --ignore-fails and --report
are specified.

Signed-off-by: Sergey Bronnikov <sergeyb at openvz.org>
---
 test/zdtm.py | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/test/zdtm.py b/test/zdtm.py
index 75e4514..9996102 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -18,6 +18,7 @@ import imp
 import socket
 import fcntl
 import errno
+import datetime
 
 os.chdir(os.path.dirname(os.path.abspath(__file__)))
 
@@ -961,9 +962,12 @@ class launcher:
 		self.__opts = opts
 		self.__total = nr_tests
 		self.__nr = 0
+		self.__runtest = 0
 		self.__max = int(opts['parallel'] or 1)
 		self.__subs = {}
 		self.__fail = False
+		self.__file_report = None
+		self.__make_tap_report = False
 		if self.__max > 1 and self.__total > 1:
 			self.__use_log = True
 		elif opts['report']:
@@ -971,6 +975,25 @@ class launcher:
 		else:
 			self.__use_log = False
 
+		if opts['report'] and opts['ignore_fails']:
+			self.__make_tap_report = True
+
+		if self.__make_tap_report:
+			now = datetime.datetime.now()
+			start_time = now.strftime("%Y-%m-%d-%H-%M-%S")
+
+			if report_dir:
+				reportname = report_dir + "/" + "criu-testreport-" + start_time + ".tap"
+			else:
+				reportname = "criu-testreport-" + start_time + ".tap"
+
+			self.__file_report = open(reportname, 'a')
+			print >> self.__file_report, "# Hardware architecture: " + arch
+			print >> self.__file_report, "# Timestamp: " + start_time + " (GMT+1)"
+			print >> self.__file_report, "# "
+			print >> self.__file_report, "TAP version 13"
+			print >> self.__file_report, "1.." + str(nr_tests)
+
 	def __show_progress(self):
 		perc = self.__nr * 16 / self.__total
 		print "=== Run %d/%d %s" % (self.__nr, self.__total, '=' * perc + '-' * (16 - perc))
@@ -978,6 +1001,9 @@ class launcher:
 	def skip(self, name, reason):
 		print "Skipping %s (%s)" % (name, reason)
 		self.__nr += 1
+		self.__runtest += 1
+		if self.__make_tap_report:
+			print >> self.__file_report, "ok %d - %s # SKIP %s" % (self.__runtest, name.split('/')[-1:][0], reason)
 
 	def run_test(self, name, desc, flavor):
 
@@ -1005,19 +1031,25 @@ class launcher:
 		sub = subprocess.Popen(["./zdtm_ct", "zdtm.py"], \
 				env = dict(os.environ, CR_CT_TEST_INFO = arg ), \
 				stdout = log, stderr = subprocess.STDOUT)
-		self.__subs[sub.pid] = { 'sub': sub, 'log': logf }
+		self.__subs[sub.pid] = { 'sub': sub, 'log': logf, 'name': name }
 
 		if test_flag(desc, 'excl'):
 			self.wait()
 
 	def __wait_one(self, flags):
 		pid, status = os.waitpid(0, flags)
+		self.__runtest += 1
 		if pid != 0:
 			sub = self.__subs.pop(pid)
 			if status != 0:
+				if self.__make_tap_report:
+					print >> self.__file_report, "not ok %d - %s" % (self.__runtest, sub['name'].split('/')[-1:][0])
 				self.__fail = True
 				if sub['log']:
 					add_to_report(sub['log'], "output")
+			else:
+				if self.__make_tap_report:
+					print >> self.__file_report, "ok %d - %s" % (self.__runtest, sub['name'].split('/')[-1:][0])
 
 			if sub['log']:
 				print open(sub['log']).read()
@@ -1046,6 +1078,8 @@ class launcher:
 
 	def finish(self):
 		self.__wait_all()
+		if self.__make_tap_report:
+			self.__file_report.close()
 		if self.__fail:
 			print_sep("FAIL", "#")
 			sys.exit(1)
-- 
2.5.0


-- 
sergeyb@


More information about the CRIU mailing list