Skip to content

Commit c81db28

Browse files
committed
Testsuite: switch to Python3 and e3-testsuite
Also introduce a Mypy setup, to type-check the testsuite code (only that for now). Change-Id: Ib90b1ac7e344fb34c7560dc0ff32ca95e0705cd7 TN: U622-042
1 parent dd0d8a1 commit c81db28

File tree

12 files changed

+693
-343
lines changed

12 files changed

+693
-343
lines changed

mypy.ini

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[mypy]
2+
python_version=3.7
3+
4+
# TODO: create a stub for the gdb modules and then enable type-checking on the
5+
# gnatdbg package.
6+
files=
7+
testsuite/run.py,
8+
testsuite/support
9+
10+
no_implicit_optional = True
11+
12+
[mypy-run]
13+
disallow_untyped_defs = True
14+
disallow_incomplete_defs = True
15+
disallow_untyped_decorators = True
16+
17+
[mypy-support.*]
18+
disallow_untyped_defs = True
19+
disallow_incomplete_defs = True
20+
disallow_untyped_decorators = True
21+
22+
[mypy-coverage.*]
23+
ignore_missing_imports = True
24+
25+
[mypy-pexpect.*]
26+
ignore_missing_imports = True

testsuite/coverage.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ exclude_lines =
88
def __repr__
99
raise NotImplementedError()
1010
assert False
11-
# no-code-coverage
11+
no-code-coverage

testsuite/run-test

Lines changed: 0 additions & 14 deletions
This file was deleted.

testsuite/run.py

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,92 @@
11
#! /usr/bin/env python
22

3-
"""
4-
Usage::
3+
from __future__ import annotations
54

6-
run.py [OPTIONS]
5+
import argparse
6+
import os
7+
import sys
78

8-
Run the gnatdbg testsuite.
9-
"""
9+
from e3.testsuite import Testsuite as BaseTestsuite
1010

11-
import os
11+
from support.gdb import GDBSession
12+
from support.python_driver import PythonDriver
13+
from support.utils import TestsuiteConfig
14+
15+
16+
class Testsuite(BaseTestsuite):
17+
18+
tests_subdir = "tests"
19+
test_driver_map = {
20+
"python": PythonDriver,
21+
}
22+
23+
def add_options(self, parser: argparse.ArgumentParser) -> None:
24+
parser.add_argument(
25+
"--coverage", "-C", action="store_true",
26+
help="Compute gnatdbg code coverage"
27+
)
28+
parser.add_argument(
29+
"--no-auto-pythonpath", "-A", action="store_true",
30+
help="Do not update PYTHONPATH to reach gnatdbg"
31+
)
32+
33+
def set_up(self) -> None:
34+
super().set_up()
35+
36+
assert self.main.args
37+
ts_config = TestsuiteConfig(
38+
no_auto_pythonpath=self.main.args.no_auto_pythonpath,
39+
coverage=self.main.args.coverage,
40+
coverage_dir=os.path.join(self.output_dir, "coverage"),
41+
coverage_rcfile=os.path.join(self.root_dir, "coverage.ini"),
42+
)
43+
self.env.ts_config = ts_config
44+
45+
if ts_config.coverage:
46+
# Create a directory that we"ll use to:
47+
#
48+
# 1) collect coverage data for each testcase;
49+
# 2) generate the HTML report.
50+
os.mkdir(ts_config.coverage_dir)
51+
os.environ["COVERAGE_DIR"] = ts_config.coverage_dir
52+
os.environ["COVERAGE_RCFILE"] = ts_config.coverage_rcfile
53+
54+
def tear_down(self) -> None:
55+
ts_config: TestsuiteConfig = self.env.ts_config
56+
if ts_config.coverage:
57+
# Process coverage data with the same Python interpreter and
58+
# "coverage" package that was used to produce them. To achieve
59+
# this, spawn GDB just like testcases.
60+
gdb = GDBSession(
61+
log_file=os.path.join(ts_config.coverage_dir, "gdb.log"),
62+
load_gnatdbg=False
63+
)
64+
gdb.import_coverage()
65+
gdb.execute("python import glob")
66+
67+
# Consolidate coverage data for each testcase and generate both a
68+
# sumary textual report on the standard output and a detailed HTML
69+
# report.
70+
gdb.execute("""python
71+
c = coverage.Coverage(data_file={data_file!r}, config_file={config_file!r})
72+
c.combine(glob.glob({data_files_glob!r}))
73+
c.html_report(directory={coverage_dir!r}, title="gnatdbg coverage report")
74+
end""".format(
75+
data_file=os.path.join(ts_config.coverage_dir, ".coverage"),
76+
data_files_glob=os.path.join(
77+
ts_config.coverage_dir, "*.coverage"
78+
),
79+
config_file=ts_config.coverage_rcfile,
80+
coverage_dir=ts_config.coverage_dir
81+
))
82+
83+
html_index = os.path.join(ts_config.coverage_dir, "index.html")
84+
assert os.path.exists(html_index)
85+
print("Detailed HTML coverage report available at:"
86+
" {}".format(html_index))
1287

13-
from support import Testsuite
88+
super().tear_down()
1489

1590

16-
if __name__ == '__main__':
17-
Testsuite(os.path.dirname(__file__)).testsuite_main()
91+
if __name__ == "__main__":
92+
sys.exit(Testsuite().testsuite_main())

testsuite/support/__init__.py

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +0,0 @@
1-
import os.path
2-
3-
from gnatpython.testsuite import Testsuite as BaseTestsuite
4-
5-
from support.gdb import GDBSession
6-
from support.python_driver import PythonDriver
7-
8-
9-
class Testsuite(BaseTestsuite):
10-
11-
CROSS_SUPPORT = True
12-
TEST_SUBDIR = 'tests'
13-
DRIVERS = {
14-
'python': PythonDriver,
15-
}
16-
17-
def add_options(self):
18-
self.main.add_option(
19-
'--coverage', '-C', action='store_true',
20-
help='Compute gnatdbg code coverage'
21-
)
22-
self.main.add_option(
23-
'--no-auto-pythonpath', '-A', action='store_true',
24-
help='Do not update PYTHONPATH to reach gnatdbg'
25-
)
26-
27-
@property
28-
def coverage_enabled(self):
29-
return self.global_env['options'].coverage
30-
31-
@property
32-
def coverage_dir(self):
33-
return os.path.join(self.global_env['output_dir'], 'coverage')
34-
35-
@property
36-
def coverage_rcfile(self):
37-
return os.path.join(
38-
os.path.dirname(os.path.abspath(__file__)),
39-
'..',
40-
'coverage.ini'
41-
)
42-
43-
def tear_up(self):
44-
super(Testsuite, self).tear_up()
45-
46-
if self.coverage_enabled:
47-
# Create a directory that we'll use to:
48-
#
49-
# 1) collect coverage data for each testcase;
50-
# 2) generate the HTML report.
51-
os.mkdir(self.coverage_dir)
52-
53-
self.global_env['coverage_dir'] = self.coverage_dir
54-
os.environ['COVERAGE_DIR'] = self.coverage_dir
55-
os.environ['COVERAGE_RCFILE'] = self.coverage_rcfile
56-
57-
def tear_down(self):
58-
if self.coverage_enabled:
59-
# Process coverage data with the same Python interpreter and
60-
# "coverage" package that was used to produce them. To achieve
61-
# this, spawn GDB just like testcases.
62-
gdb = GDBSession(
63-
log_file=os.path.join(self.coverage_dir, 'gdb.log'),
64-
load_gnatdbg=False
65-
)
66-
gdb.import_coverage()
67-
gdb.execute('python import glob')
68-
69-
# Consolidate coverage data for each testcase and generate both a
70-
# sumary textual report on the standard output and a detailed HTML
71-
# report.
72-
gdb.execute('''python
73-
c = coverage.Coverage(data_file={data_file!r}, config_file={config_file!r})
74-
c.combine(glob.glob({data_files_glob!r}))
75-
c.html_report(directory={coverage_dir!r}, title='gnatdbg coverage report')
76-
end'''.format(
77-
data_file=os.path.join(self.coverage_dir, '.coverage'),
78-
data_files_glob=os.path.join(self.coverage_dir, '*.coverage'),
79-
config_file=self.coverage_rcfile,
80-
coverage_dir=self.coverage_dir
81-
))
82-
83-
html_index = os.path.join(self.coverage_dir, 'index.html')
84-
assert os.path.exists(html_index)
85-
print('Detailed HTML coverage report available at:'
86-
' {}'.format(html_index))
87-
88-
super(Testsuite, self).tear_down()

testsuite/support/base_driver.py

Lines changed: 0 additions & 130 deletions
This file was deleted.

testsuite/support/build.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
from __future__ import annotations
2+
13
import sys
4+
from typing import List
25

3-
from gnatpython.ex import Run
6+
from e3.os.process import Run
47

58

6-
def gnatmake(main, debug=True, cargs=[]):
9+
def gnatmake(main: str, debug: bool = True, cargs: List[str] = []) -> None:
710
"""
811
Run GNATmake on the given main source file.
912

0 commit comments

Comments
 (0)