Files
deskflow/scripts/tests.py
Nick Bolton 47849db4d9 Run Valgrind on unit tests in CI to detect memory leaks (#7401)
* Move QApplication out of main to reduce memory impact when running individual tests

* Add --valgrind arg and colorize output when command returns non-zero exit code

* Fixed: colorama not always available

* Test multiple Qt tests

* Fixed: Windows Qt test failing due to missing QCoreApplication

* Simplify fake args for Qt

* Use --ci-env arg

* Create Valgrind analysis workflow

* Rename vars for fake args

* Parse and output valgrind summary

* Add build mode to comment

* Use GITHUB_OUTPUT to output summary

* Merge valgrind comment

* Improve comment

* Use `tee` instead of `--log-file` to also print stdout

* Improve comment about debug and release

* Simplify output writing in parse step

* Improve step name

* Correct comment about summaries

* Remove commented out code

* Better var name

* Missing copyright

* Rename global to shared

* Remove space

* Revert change to ConfigTests.cpp
2024-07-17 09:22:46 +01:00

61 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse, os, sys
import lib.cmd_utils as cmd_utils
import lib.env as env
def main():
# important: load venv before loading modules that install deps.
env.ensure_in_venv(__file__)
parser = argparse.ArgumentParser()
parser.add_argument("--unit-tests", action="store_true")
parser.add_argument("--integ-tests", action="store_true")
parser.add_argument(
"--filter-file",
type=str,
help="Takes the base filename without extension and uses it as a filter",
)
parser.add_argument(
"--ignore-return-code",
action="store_true",
help="Ignore the return code of the test command",
)
parser.add_argument(
"--valgrind",
action="store_true",
help="Run the test command with valgrind",
)
args = parser.parse_args()
binary = get_binary_path(args)
if args.filter_file:
file_base = os.path.basename(args.filter_file)
without_ext = os.path.splitext(file_base)[0]
command = [binary, f"--gtest_filter={without_ext}*"]
else:
command = [binary]
if args.valgrind:
command = ["valgrind"] + command
result = cmd_utils.run(command, print_cmd=True, check=False)
if not args.ignore_return_code:
sys.exit(result.returncode)
def get_binary_path(args):
base_dir = "./build/bin"
if args.unit_tests:
return f"{base_dir}/unittests"
elif args.integ_tests:
return f"{base_dir}/integtests"
else:
raise RuntimeError("No test type specified")
if __name__ == "__main__":
main()