diff --git a/tests/tests-u-runner/runner/coverage_utils.py b/tests/tests-u-runner/runner/coverage_utils.py index 8deabd0903ee45233c9e98f1dd02c2ca2f148a8c..7c6ff9bd59b4c3bd5bd4166737b249fbf2ed2281 100644 --- a/tests/tests-u-runner/runner/coverage_utils.py +++ b/tests/tests-u-runner/runner/coverage_utils.py @@ -2,6 +2,7 @@ import subprocess from os import remove from pathlib import Path +from params import TestEnv def merge_and_delete_prowraw_files(profraw_file, profdata_file, params): @@ -21,3 +22,74 @@ def merge_and_delete_prowraw_files(profraw_file, profdata_file, params): remove(profraw_file) else: print(f"File with name {profraw_file} not exist") + + +class LLVM_COV_REPORT: + def __init__(self, runner_name, test_env: TestEnv): + self.test_env = test_env + + self.html_report_dir = test_env.args.llvm_cov_genthml_dir + self.profdata_dir = test_env.args.generate_profraw + self.bin_dir = ('%s/bin') % (test_env.args.build_dir) + + self.runner_name = runner_name + self.llvm_profdata_program = test_env.cmd_env["LLVM_PROFDATA_PROGRAM"] + self.llvm_cov_program = 'llvm-cov-14' + + self.profdata_list_file=('/tmp/profdatalist-%s.txt') % (self.runner_name) + self.final_profdata_file = ('%s/%s.profdata') % (self.html_report_dir, self.runner_name) + self.report_dot_info = ('%s/report-%s.info') % (self.html_report_dir, self.runner_name) + + + def make_report_info(self): + find_command = ('$(find %s/* -name \"*.so\" -exec echo \" --object={}\" \; )') % ( + self.test_env.args.build_dir) + command = [self.llvm_cov_program, 'export', '-format=lcov', '-Xdemangler', 'c++fit', + ''.join('-instr-profile=', self.final_profdata_file), find_command, + ''.join('--object=', self.bin_dir, '/ark'), + ''.join('--object=', self.bin_dir, '/ark_aot'), + ''.join('--object=', self.bin_dir, '/ark_asm'), + ''.join('--object=', self.bin_dir, '/ark_disasm'), + ''.join('--object=', self.bin_dir, '/c2abc'), + ''.join('--object=', self.bin_dir, '/c2p'), + ''.join('--object=', self.bin_dir, '/es2panda'), + ''.join('--object=', self.bin_dir, '/irtoc_ecmascript_fastpath_exec'), + ''.join('--object=', self.bin_dir, '/irtoc_fastpath_exec'), + ''.join('--object=', self.bin_dir, '/irtoc_interpreter_exec'), + ''.join('--object=', self.bin_dir, '/irtoc_java_fastpath_exec'), + ''.join('--object=', self.bin_dir, '/panda'), + ''.join('--object=', self.bin_dir, '/pandasm'), + ''.join('--object=', self.bin_dir, '/paoc'), + ''.join('--object=', self.bin_dir, '/verifier'), + '>', + ''.join(self.report_dot_info) + ] + self.run_command(command) + + + def make_html_report(self): + command = ['genhtml', ''.join('--output-directory=', self.html_report_dir), self.report_dot_info] + self.run_command(command) + + + def make_profdata_list_file(self): + command = ['find', self.profdata_dir, '-name', '*.profdata', '-print', '>', self.profdata_list_file] + self.run_command(command) + + + def make_final_profdata_file(self): + command = [self.llvm_profdata_program, 'merge', '--sparse', + ''.join('--input-files=', self.profdata_list_file), '-o', self.final_profdata_file] + self.run_command(command) + + + def run_command(self, command): + proc = subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=self.test_env.cmd_env + ) + try: + proc.communicate() + except subprocess.TimeoutExpired as e: + print('Process failed by timeout') diff --git a/tests/tests-u-runner/runner/runner_file_based.py b/tests/tests-u-runner/runner/runner_file_based.py index b1e8112b23bed4d77bdb57caaef555ab32406082..89c23074dc23c6ec8cb542fd6933c6b00cb10e9f 100644 --- a/tests/tests-u-runner/runner/runner_file_based.py +++ b/tests/tests-u-runner/runner/runner_file_based.py @@ -15,6 +15,7 @@ from runner.report_format import ReportFormat from runner.runner_base import Runner from runner.test_base import Test from runner.utils import write_2_file +from coverage_utils import LLVM_COV_REPORT INDEX_TITLE = "${Title}" INDEX_OPTIONS = "${Options}" @@ -228,6 +229,13 @@ class RunnerFileBased(Runner): self.update_excluded_test_list(excluded_but_passed, excluded_still_failed) + if self.args.llvm_cov_genthml_dir: + coverage_report = LLVM_COV_REPORT(self.name, self.test_env) + coverage_report.make_profdata_list_file() + coverage_report.make_final_profdata_file() + coverage_report.make_report_info() + coverage_report.make_html_report() + Log.default(_LOGGER, "Summary(%s):" % self.name) Log.default(_LOGGER, "Total: %5d" % total_tests) Log.default(_LOGGER, "Passed: %5d" % self.passed) diff --git a/tests/tests-u-runner/runner/starter.py b/tests/tests-u-runner/runner/starter.py index b7b45ce66152f8b37ea734c31b36b227c033dbd6..2e431174872d386237ab821e2179d23220ed779a 100644 --- a/tests/tests-u-runner/runner/starter.py +++ b/tests/tests-u-runner/runner/starter.py @@ -245,4 +245,9 @@ def get_args(): '--generated-path', action='store', dest='generated_folder', type=str, help='path where generated source code will be saved') + parser.add_argument( + '--llvm-cov-genhtml-to', dest='llvm_cov_genthml_dir', default=None, type=lambda + arg: make_dir_if_not_exist(parser, arg), + help='Stacks files in the specified directory') + return parser.parse_args()