-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.py
More file actions
134 lines (108 loc) · 4.9 KB
/
Copy pathbuild.py
File metadata and controls
134 lines (108 loc) · 4.9 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/python3
import logging
import re
import shutil
from datetime import datetime
from enum import Enum
from glob import iglob, glob
from io import StringIO
from zipfile import ZipFile
from junit_xml import TestSuite, TestCase, to_xml_report_string
from os import environ
from pathlib import Path
from typing import Tuple
from matrix_runner import main, matrix_axis, matrix_action, matrix_command, ConsoleReport, CropReport, ReportFilter
# Colors for the Unittest result badge
UNITTEST_BADGE_COLOR = {
True: 'green', # stable: all tests passing
False: 'yellow', # unstable: not all tests passing
None: 'red' # error: no test results generated
}
class UnityReport(ReportFilter):
class Result(ReportFilter.Result, ReportFilter.Summary):
@staticmethod
def common_fix(s1, s2):
steps = range(min(len(s1), len(s2)) - 1, -1, -1)
return next((s2[:n] for n in steps if s1[-n:] == s2[:n]), '')
@property
def stream(self) -> StringIO:
if not self._stream:
try:
self._stream = StringIO()
input = self._other.stream
input.seek(0)
tcs = []
cwd = Path.cwd()
for line in input:
m = re.match('(.*):(\d+):(\w+):(PASS|FAIL)(:(.*))?', line)
if m:
file = Path(m.group(1))
try:
file = file.relative_to(cwd)
except ValueError as e:
if "is not in the subpath" in e.args[0]:
logging.info(e)
lookup = glob(str(Path.cwd().joinpath("**").joinpath(file.name)), recursive=True)
if len(lookup) != 1:
raise e
logging.info("Found similar named file at '%s'.", str(lookup[0]))
file = Path(lookup[0]).relative_to(Path.cwd())
if m.group(1).endswith(str(file)):
cwd = Path(m.group(1)[0:-len(str(file))])
logging.info("Deduced working directory is '%s'.", str(cwd))
tc = TestCase(m.group(3), file=file, line=m.group(2))
if m.group(4) == "FAIL":
tc.add_failure_info(message=m.group(6).strip())
tcs += [tc]
self.ts = TestSuite("Cloud-CI basic tests", tcs)
self._stream.write(to_xml_report_string([self.ts]))
except Exception as e:
self._stream = e
if isinstance(self._stream, Exception):
raise RuntimeError from self._stream
else:
return self._stream
@property
def summary(self) -> Tuple[int, int]:
passed = len([tc for tc in self.ts.test_cases if not (tc.is_failure() or tc.is_error() or tc.is_skipped())])
executed = len(self.ts.test_cases)
return passed, executed
def __init__(self, *args):
super(UnityReport, self).__init__()
self.args = args
def timestamp(t: datetime = datetime.now()):
return t.strftime("%Y%m%d%H%M%S")
@matrix_axis("target", "t", "The project target(s) to build")
class TargetAxis(Enum):
debug = ('CMSDK_CM7_VHT')
@matrix_action
def build(config, results):
"""Build the config(s) with CMSIS-Build"""
yield run_cbuild(config)
if not results[0].success:
return
file = f"Basic-{timestamp()}.zip"
logging.info(f"Archiving build output to {file}...")
with ZipFile(file, "w") as archive:
archive.write(f"Objects/Basic.axf")
archive.write(f"Objects/Basic.axf.map")
archive.write(f"Objects/Basic.{config.target}.clog")
@matrix_action
def run(config, results):
"""Run the config(s) with fast model"""
yield run_vht(config)
ts = timestamp()
if not results[0].success:
print(f"::set-output name=badge::Unittest-failed-{UNITTEST_BADGE_COLOR[None]}")
else:
results[0].test_report.write(f"Basic-{ts}.xunit")
passed, executed = results[0].test_report.summary
print(f"::set-output name=badge::Unittest-{passed}%20of%20{executed}%20passed-{UNITTEST_BADGE_COLOR[passed == executed]}")
@matrix_command(needs_shell=False)
def run_cbuild(config):
return ["bash", "-c", f"cbuild.sh --quiet Basic.{config.target}.cprj"]
@matrix_command(test_report=ConsoleReport()|CropReport("---\[ UNITY BEGIN \]---", '---\[ UNITY END \]---')|UnityReport())
def run_vht(config):
return ["VHT_MPS2_Cortex-M7", "-q", "--stat", "--simlimit", 1, "-f", "vht_config.txt", "Objects/Basic.axf"]
if __name__ == "__main__":
main()