mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-21 15:23:57 -04:00
Tools: add typing and add option for examples on coverage
This commit is contained in:
parent
dcb6b59962
commit
d01f9e3ec5
@ -24,7 +24,7 @@ root_dir = os.path.realpath(os.path.join(tools_dir, '../..'))
|
||||
class CoverageRunner(object):
|
||||
"""Coverage Runner Class."""
|
||||
|
||||
def __init__(self, verbose=False, check_tests=True):
|
||||
def __init__(self, verbose=False, check_tests=True) -> None:
|
||||
"""Set the files Path."""
|
||||
self.REPORT_DIR = os.path.join(root_dir, "reports/lcov-report")
|
||||
self.INFO_FILE = os.path.join(root_dir, self.REPORT_DIR, "lcov.info")
|
||||
@ -37,13 +37,13 @@ class CoverageRunner(object):
|
||||
self.check_tests = check_tests
|
||||
self.start_time = time.time()
|
||||
|
||||
def progress(self, text):
|
||||
def progress(self, text) -> None:
|
||||
"""Pretty printer."""
|
||||
delta_time = time.time() - self.start_time
|
||||
formatted_text = "****** AT-%06.1f: %s" % (delta_time, text)
|
||||
print(formatted_text)
|
||||
|
||||
def init_coverage(self, use_example=False):
|
||||
def init_coverage(self, use_example=False) -> None:
|
||||
"""Initialize ArduPilot for coverage.
|
||||
|
||||
This needs to be run with the binaries built.
|
||||
@ -64,6 +64,7 @@ class CoverageRunner(object):
|
||||
binaries_dir = os.path.join(root_dir, 'build/sitl/bin')
|
||||
dirs_to_check = [["binaries", binaries_dir], ["tests", os.path.join(root_dir, 'build/linux/tests')]]
|
||||
if use_example:
|
||||
self.progress("Adding examples")
|
||||
dirs_to_check.append(["examples", os.path.join(root_dir, 'build/linux/examples')])
|
||||
for dirc in dirs_to_check:
|
||||
if not (self.check_build(dirc[0], dirc[1])):
|
||||
@ -98,7 +99,7 @@ class CoverageRunner(object):
|
||||
exit(1)
|
||||
self.progress("Initialization done")
|
||||
|
||||
def check_build(self, name, path):
|
||||
def check_build(self, name, path) -> bool:
|
||||
"""Check that build directory is not empty and that binaries are built with the coverage flags."""
|
||||
self.progress("Checking that %s are set up and built" % name)
|
||||
if os.path.exists(path):
|
||||
@ -114,7 +115,7 @@ class CoverageRunner(object):
|
||||
self.progress("%s was't built with coverage support" % name)
|
||||
return False
|
||||
|
||||
def run_build(self, use_example=False):
|
||||
def run_build(self, use_example=False) -> None:
|
||||
"""Clean the build directory and build binaries for coverage."""
|
||||
|
||||
os.chdir(root_dir)
|
||||
@ -127,6 +128,7 @@ class CoverageRunner(object):
|
||||
|
||||
try:
|
||||
if use_example:
|
||||
self.progress("Building examples")
|
||||
subprocess.run([waf_light, "configure", "--board=linux", "--debug", "--coverage"], check=True)
|
||||
subprocess.run([waf_light, "examples"], check=True)
|
||||
subprocess.run(
|
||||
@ -144,7 +146,7 @@ class CoverageRunner(object):
|
||||
exit(1)
|
||||
self.progress("Build examples and vehicle binaries done !")
|
||||
|
||||
def run_full(self, use_example=False):
|
||||
def run_full(self, use_example=False) -> None:
|
||||
"""Run full coverage on maximum of ArduPilot binaries and test functions."""
|
||||
self.progress("Running full test suite...")
|
||||
self.run_build()
|
||||
@ -158,6 +160,7 @@ class CoverageRunner(object):
|
||||
subprocess.run([self.autotest,
|
||||
"--timeout=" + str(TIMEOUT),
|
||||
"--debug",
|
||||
"--coverage",
|
||||
"--no-clean",
|
||||
"--speedup=" + str(SPEEDUP),
|
||||
"run.examples"], check=self.check_tests)
|
||||
@ -183,7 +186,7 @@ class CoverageRunner(object):
|
||||
# used code, can we run other tests or things? Replay, perhaps?
|
||||
self.update_stats()
|
||||
|
||||
def update_stats(self):
|
||||
def update_stats(self) -> None:
|
||||
"""Update Coverage statistics only.
|
||||
|
||||
Assumes that coverage tests have been run.
|
||||
@ -277,6 +280,10 @@ if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Runs tests with gcov coverage support.')
|
||||
parser.add_argument('-v', '--verbose', action='store_true',
|
||||
help='Output everything on terminal.')
|
||||
parser.add_argument('-c', '--no-check-tests', action='store_true',
|
||||
help='Do not fail if tests do not run.')
|
||||
parser.add_argument('--add-examples', action='store_true',
|
||||
help='Add examples to coverage.')
|
||||
group = parser.add_mutually_exclusive_group()
|
||||
group.add_argument('-i', '--init', action='store_true',
|
||||
help='Initialise ArduPilot for coverage. It should be run after building the binaries.')
|
||||
@ -286,20 +293,17 @@ if __name__ == '__main__':
|
||||
help='Clean the build directory and build binaries for coverage.')
|
||||
group.add_argument('-u', '--update', action='store_true',
|
||||
help='Update coverage statistics. To be used after running some tests.')
|
||||
group.add_argument('-c', '--no-check-tests', action='store_true',
|
||||
help='Do not fail if tests do not run.')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
runner = CoverageRunner(verbose=args.verbose, check_tests=not args.no_check_tests)
|
||||
if args.init:
|
||||
runner.init_coverage()
|
||||
runner.init_coverage(args.add_examples)
|
||||
sys.exit(0)
|
||||
if args.full:
|
||||
runner.run_full()
|
||||
runner.run_full(args.add_examples)
|
||||
sys.exit(0)
|
||||
if args.build:
|
||||
runner.run_build()
|
||||
runner.run_build(args.add_examples)
|
||||
sys.exit(0)
|
||||
if args.update:
|
||||
runner.update_stats()
|
||||
|
Loading…
Reference in New Issue
Block a user