From 0eb99f44c596b7d6476524cebe72dc4ec970389a Mon Sep 17 00:00:00 2001 From: Peter Seres Date: Wed, 18 Oct 2023 14:17:11 +0200 Subject: [PATCH] Add a new ninja target to run parser, runtime, ets-cts test cases and clang-tidy. Fixes internall issue #13849 Change-Id: Id4543bbcacc417fe66287350380afec0fd9c326f Signed-off-by: Peter Seres --- CMakeLists.txt | 8 +++ check_quality.py | 151 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 check_quality.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 26499a0d0..b6fea809b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,6 +203,14 @@ add_dependencies(tests core_tests) include(cmake/Testing.cmake) + +#-----Test code quality--------------------------------------------------------- +add_custom_target(es2panda-pre-test + COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/check_quality.py --working-dir ${PANDA_ROOT} --build-root ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Run parser, runtime, ets-cts test cases and clang-tidy." + JOB_POOL console + ) + # ----- Template Based Generator ----------------------------------------------- include(cmake/TemplateBasedGen.cmake) diff --git a/check_quality.py b/check_quality.py new file mode 100644 index 000000000..c59f31e60 --- /dev/null +++ b/check_quality.py @@ -0,0 +1,151 @@ +import re +import argparse +import subprocess + + +def print_summary(log_lines, searched_words, end_word=""): + was_any_log = False + should_print = False + + for line in log_lines: + for word in searched_words: + if any(word in line for word in searched_words): + should_print = True + was_any_log = True + + if end_word and end_word in line: + should_print=False + + if should_print: + print(line.strip()) + if not was_any_log: + print("Problem occourd: ", was_any_log) + + print(f"\n") + + +def print_progress_to_console(line, is_clang_tidy, pattern_progress_bar, pattern_clang_tidy): + if is_clang_tidy: + match = re.match(pattern_clang_tidy, line) + if match: + print(f"[{match.group(1)}/{match.group(2)}] {match.group(3)}") + else: + match = pattern_progress_bar.search(line) + if match: + print(line, end='') + + +def test_process_runner(runtime_process, is_clang_tidy=False): + pattern_progress_bar = re.compile(r'\b(\d{1,3}%)\|(.+?)\| (\d+)/(\d+) \[\d{2}:\d{2}<\d{2}:\d{2},\s*\d+\.\d+it/s\]$') + pattern_clang_tidy = re.compile(r"^\[(\d+)\/(\d+)\]\s+Done\s+clang-tidy:\s+.*?\/es2panda\/(.+\.cpp)$") + + should_print = False + log_lines = [] + + for line in runtime_process.stdout: + print_progress_to_console(line, is_clang_tidy, pattern_progress_bar, pattern_clang_tidy) + + if not should_print: + should_print = 'Summary(' in line or 'New failures at ' in line + else: + print(line, end='') + + log_lines.append(line) + + return log_lines + + +def main(): + parser = argparse.ArgumentParser(description="Program description.") + parser.add_argument("--working-dir", required=False, help="Path to the working dir") + parser.add_argument("--build-root", required=False, help="Path to the working dir") + + args = parser.parse_args() + print(f"Argumentum: Working dir: {args.working_dir}") + print(f"Argumentum: Build root: {args.build_root}") + + command_helper = ["python3", f"{args.working_dir}/tests/tests-u-runner/main.py", "--build-dir", f"{args.build_root}", + "--processes", "all", "--show-progress", "--force-generate" + ] + + # Run Parser tests + parser_test_run_command = command_helper + ["--parser" ] + + try: + parser_process = subprocess.Popen(parser_test_run_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) + parser_log = test_process_runner(parser_process) + + except subprocess.CalledProcessError as e: + parser_log = str(e) + print("An error occurred during processing parser tests: ", parser_log) + + except Exception as e: + parser_log = str(e) + print("An error occurred during processing parser tests: ", parser_log) + + # Run Runtime tests + runtime_test_run_command = command_helper + ["--ets-runtime", "--timeout", "60"] + + try: + runtime_process = subprocess.Popen(runtime_test_run_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) + runtime_log = test_process_runner(runtime_process) + + except subprocess.CalledProcessError as e: + runtime_log = str(e) + print("An error occurred during processing runtime tests: ", runtime_log) + + except Exception as e: + runtime_log = str(e) + print("An error occurred during processing runtime tests: ", runtime_log) + + # Run Ets-cts test + ets_cts_test_run_command = command_helper + ["--ets-cts"] + + try: + ets_cts_process = subprocess.Popen(ets_cts_test_run_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) + ets_cts_log = test_process_runner(ets_cts_process) + + except subprocess.CalledProcessError as e: + ets_cts_log = str(e) + print("An error occurred during processing ets-cts tests: ", ets_cts_log) + + except Exception as e: + ets_cts_log = str(e) + print("An error occurred during processing ets-cts tests: ", ets_cts_log) + + # Run Clang-tidy + try: + subprocess.run(["cp", ".clang-tidy", f"{args.build_root}"]) + + clang_tidy_run_command = [f"{args.working_dir}/scripts/clang-tidy/clang_tidy_check.py", "--filename-filter=es2panda", + f"{args.working_dir}", f"{args.build_root}" + ] + + clang_tidy_process = subprocess.Popen(clang_tidy_run_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) + clang_tidy_log = test_process_runner(clang_tidy_process, True) + + except subprocess.CalledProcessError as e: + clang_tidy_log = str(e) + print("An error occurred during processing Clang-tidy tests: ", clang_tidy_log) + except Exception as e: + clang_tidy_log = str(e) + print("An error occurred during processing Clang-tidy tests: ", clang_tidy_log) + + + print("\n\nTest results: \n") + + print("Parser test results:") + print_summary(parser_log, ["New failures at", "Summary("]) + + print("Runtime test results:") + print_summary(runtime_log, ["New failures at", "Summary("]) + + print("Ets-cts test results:") + print_summary(ets_cts_log, ["New failures at", "Summary("]) + + print("Clang-tidy results:") + print_summary(clang_tidy_log,['Clang-tidy was passed successfully!', "Failed:"], "Done clang-tidy:") + + +if __name__ == "__main__": + main() -- Gitee