-
Notifications
You must be signed in to change notification settings - Fork 11
/
lobster-trlc-system-test.py
executable file
·113 lines (94 loc) · 3.66 KB
/
lobster-trlc-system-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
#
# lobster-trlc-system-test - Extract tracing tags for LOBSTER
# Copyright (C) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
#
# This component of TRLC program is free software: you can
# redistribute it and/or modify it under the terms of the GNU Affero
# General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program. If not, see
# <https://www.gnu.org/licenses/>.
# pylint: disable=invalid-name
import os
import sys
from lobster.items import Tracing_Tag, Activity
from lobster.location import File_Reference
from lobster.io import lobster_write
from trlc.trlc import Source_Manager
from trlc.errors import Message_Handler
TEST_DIR = "tests-system"
TARGET = "system-tests.lobster"
def process(testname, mapping):
test_dir = os.path.join(TEST_DIR, testname)
assert os.path.isdir(test_dir)
assert isinstance(mapping, dict)
tag_file = os.path.join(test_dir, "tracing")
item = Activity(
tag = Tracing_Tag(namespace = "trlc-st",
tag = testname),
location = File_Reference(filename = test_dir),
framework = "TRLCST",
kind = "Test Directory")
include_test = False
if os.path.isfile(tag_file):
include_test = True
with open(tag_file, "r", encoding="UTF-8") as fd:
tags = [Tracing_Tag(namespace = "req",
tag = line.strip())
for line in fd.read().splitlines()
if line.strip()]
for tag in tags:
item.add_tracing_target(tag)
if testname.startswith("rbt-"):
include_test = True
components = testname[4:].lower().split("-")
if len(components) >= 2:
try:
int(components[-1])
components.pop()
except ValueError:
pass
requirement = mapping.get("-".join(components),
"_".join(item.capitalize()
for item in components))
item.add_tracing_target(
Tracing_Tag(namespace = "req",
tag = "LRM.%s" % requirement))
if include_test:
return [item]
else:
# We don't need to know about untraced regression tests
return []
def main():
sm = Source_Manager(mh = Message_Handler(),
lint_mode = False,
parse_trlc = True,
verify_mode = False)
sm.register_directory("language-reference-manual")
stab = sm.process()
pkg_lrm = stab.lookup_assuming(sm.mh, "LRM")
mapping = {}
for item in pkg_lrm.symbols.iter_record_objects():
mapping[item.name.lower().replace("_", "-")] = item.name
items = []
for dirent in sorted(os.scandir(TEST_DIR),
key=lambda de: de.name):
if dirent.is_dir():
if dirent.name == "htmlcov":
continue
items += process(dirent.name, mapping)
with open(TARGET, "w", encoding="UTF-8") as fd:
lobster_write(fd, Activity, "lobster-trlc-system-test", items)
print("Written %u items to %s" % (len(items), TARGET))
return 0
if __name__ == "__main__":
sys.exit(main())