Commit Diff


commit - b4c49119d3621357c652174a33023faa2d4c0e0c
commit + f30e2f1167b17b9c886f46ca260c1d70826be336
blob - d37c4cf413db1f8ae354e559a237a3bb089ae35a
blob + e0425295db5306e882df683a3b8dee1482aa7c65
--- .gitignore
+++ .gitignore
@@ -30,6 +30,8 @@ Testing/
 ./build
 /build
 .idea/
+luacov.stats.out
+luacov.report.out
 # Ignore Makefile in the stupid way for `tar --exclude-vcs-ignores`
 /Makefile
 ./Makefile
blob - 76100441e38aa6428e485f83acba3e705faaec4f
blob + e1948b73ede366e9d2f01a2a6063d661b43a3fd3
--- .test.mk
+++ .test.mk
@@ -25,6 +25,9 @@ COVERITY_URL = https://scan.coverity.com/builds?projec
 CMAKE = ${CMAKE_ENV} cmake -S ${SRC_DIR} -B ${BUILD_DIR}
 CMAKE_BUILD = ${CMAKE_BUILD_ENV} cmake --build ${BUILD_DIR} --parallel ${NPROC}
 
+LUACOV_STATS ?= luacov.stats.out
+LUACOV_REPORT ?= luacov.report.out
+
 .PHONY: configure
 configure:
 	${CMAKE} ${CMAKE_PARAMS} ${CMAKE_EXTRA_PARAMS}
@@ -120,6 +123,13 @@ test-coverage: CMAKE_PARAMS = -G Ninja -DCMAKE_BUILD_T
 test-coverage: TEST_RUN_PARAMS += --long
 test-coverage: OUTPUT_FILE = coverage.info
 test-coverage: build run-luajit-test run-test
+	# TODO: setup tarantool
+	# tarantool ${SRC_DIR}/tools/luacov_to_info.lua ${SRC_DIR}/luacov.stats.out > ${SRC_DIR}/luacov.report.out
+	# sed -i -e 's@'"$$(realpath .)"'/@@' $(LUACOV_STATS)
+	# luacov expirationd.lua
+	# grep -A999 '^Summary' $(LUACOV_REPORT)
+	# TODO: --add-tracefile
+	# TODO: setup luacov/cluacov
 	lcov --capture \
 	     --compat-libtool \
 	     --directory ${BUILD_DIR}/src/ \
blob - /dev/null
blob + 06f5e1a54a3ddb0e4d861e724e0243d5db773b10 (mode 644)
--- /dev/null
+++ tools/luacov_to_info.lua
@@ -0,0 +1,56 @@
+#!/usr/bin/env luajit
+
+local luacov = require('luacov')
+local ReporterBase = require('luacov.reporter').ReporterBase
+local LcovReporter = setmetatable({}, ReporterBase)
+LcovReporter.__index = LcovReporter
+
+function LcovReporter:on_new_file(filename)
+	self.finfo = self.current_files[filename] or {name=filename, coverage={}}
+end
+
+function LcovReporter:on_mis_line(_, lineno, _)
+	self.finfo.coverage[lineno] = self.finfo.coverage[lineno] or 0
+end
+
+function LcovReporter:on_hit_line(_, lineno, _, hits)
+	self.finfo.coverage[lineno] = (self.finfo.coverage[lineno] or 0) + hits
+end
+
+function LcovReporter:on_end_file()
+	self.current_files[self.finfo.name] = self.finfo
+	self.finfo = nil
+end
+
+-- Write out results in lcov format
+local function write_lcov_info(files)
+	for fname, finfo in pairs(files) do
+		local instrumented, nonzero = 0, 0
+		print('TN:')
+		print(string.format('SF:%s', fname))
+		for i, hits in pairs(finfo.coverage) do
+			print(string.format('DA:%d,%d', i, hits))
+			instrumented = instrumented + 1
+			if hits > 0 then
+				nonzero = nonzero + 1
+			end
+		end
+		print(string.format('LH:%d', nonzero))
+		print(string.format('LF:%d', instrumented))
+		print('end_of_record')
+	end
+end
+
+-- Accumulate total coverage.
+local all_files = {}
+for _, fname in ipairs(arg) do
+	local conf = luacov.load_config()
+	conf.statsfile = fname
+	local reporter = assert(LcovReporter:new(conf))
+	reporter.current_files = all_files
+	reporter:run()
+	reporter:close()
+end
+
+-- Write results.
+write_lcov_info(all_files)