Skip to content

Commit d65b523

Browse files
authored
FBX-19 add automated code coverage (#551)
* add code coverage to tests on yamato * fix path to check code coverage script * fix filename * update min coverage percent
1 parent 3fd19cd commit d65b523

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

.yamato/upm-ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ platforms:
1313
type: Unity::VM::osx
1414
image: package-ci/mac:stable
1515
flavor: b1.medium
16+
coverage:
17+
minPercent: 57.6
1618
---
1719
pack:
1820
name: Pack
@@ -40,7 +42,8 @@ test_{{ platform.name }}_{{ editor.version }}:
4042
flavor: {{ platform.flavor}}
4143
commands:
4244
- npm install -g upm-ci-utils@stable --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
43-
- upm-ci package test --unity-version {{ editor.version }} --package-path com.unity.formats.fbx
45+
- upm-ci package test --unity-version {{ editor.version }} --package-path com.unity.formats.fbx --enable-code-coverage --code-coverage-options 'generateHtmlReport;assemblyFilters:+Unity.Formats.Fbx.Editor,+Unity.Formats.Fbx.Runtime'
46+
- python tests/yamato/check_coverage_percent.py upm-ci~/test-results/ {{ coverage.minPercent }}
4447
artifacts:
4548
logs:
4649
paths:
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
### Implementation taken from https://github.com/Unity-Technologies/ml-agents/pull/3642/files
2+
3+
from __future__ import print_function
4+
import sys
5+
import os
6+
7+
SUMMARY_XML_FILENAME = "Summary.xml"
8+
9+
# Note that this is python2 compatible, since that's currently what's installed on most CI images.
10+
11+
def check_coverage(root_dir, min_percentage):
12+
# Walk the root directory looking for the summary file that
13+
# is output by the code coverage checks. It's possible that
14+
# we'll need to refine this later in case there are multiple
15+
# such files.
16+
summary_xml = None
17+
for dirpath, _, filenames in os.walk(root_dir):
18+
if SUMMARY_XML_FILENAME in filenames:
19+
summary_xml = os.path.join(dirpath, SUMMARY_XML_FILENAME)
20+
break
21+
if not summary_xml:
22+
print("Couldn't find {} in root directory".format(SUMMARY_XML_FILENAME))
23+
sys.exit(1)
24+
25+
with open(summary_xml) as f:
26+
# Rather than try to parse the XML, just look for a line of the form
27+
# <Linecoverage>73.9</Linecoverage>
28+
lines = f.readlines()
29+
for l in lines:
30+
if "Linecoverage" in l:
31+
pct = l.replace("<Linecoverage>", "").replace("</Linecoverage>", "")
32+
pct = float(pct)
33+
if pct < min_percentage:
34+
print(
35+
"Coverage {} is below the min percentage of {}.".format(
36+
pct, min_percentage
37+
)
38+
)
39+
sys.exit(1)
40+
else:
41+
print(
42+
"Coverage {} is above the min percentage of {}.".format(
43+
pct, min_percentage
44+
)
45+
)
46+
sys.exit(0)
47+
48+
# Couldn't find the results in the file.
49+
print("Couldn't find Linecoverage in summary file")
50+
sys.exit(1)
51+
52+
53+
def main():
54+
root_dir = sys.argv[1]
55+
min_percent = float(sys.argv[2])
56+
if min_percent > 0:
57+
check_coverage(root_dir, min_percent)
58+
59+
60+
if __name__ == "__main__":
61+
main()

0 commit comments

Comments
 (0)