summaryrefslogtreecommitdiff
path: root/platform/android/scripts/parse-jacoco-report.py
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2019-03-19 13:32:06 +0100
committerŁukasz Paczos <lukas.paczos@gmail.com>2019-03-19 15:58:03 +0100
commit8262a44875c2d82033e1f9e16639d7efbca58e77 (patch)
tree5e892be6f6f9502fb9717dbf2b17b85987417d17 /platform/android/scripts/parse-jacoco-report.py
parentc2fe532b9bbc9db9b2bbab109f0f47f7cc9584d7 (diff)
downloadqtlocation-mapboxgl-upstream/lp-android-code-coverage.tar.gz
[android] unit and instrumentation tests code coverage reportupstream/lp-android-code-coverage
Diffstat (limited to 'platform/android/scripts/parse-jacoco-report.py')
-rwxr-xr-xplatform/android/scripts/parse-jacoco-report.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/platform/android/scripts/parse-jacoco-report.py b/platform/android/scripts/parse-jacoco-report.py
new file mode 100755
index 0000000000..4d06fda6cc
--- /dev/null
+++ b/platform/android/scripts/parse-jacoco-report.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+import os
+import re
+from io import open
+
+reportPath = os.getcwd() + "/platform/android/MapboxGLAndroidSDK/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml"
+with open(reportPath, 'r', encoding='utf-8') as jacocoReport:
+ line = jacocoReport.readline().strip()
+
+ # find the last INSTRUCTION coverage report which is a sum of all separate ones
+ instructionIndex = line.rfind('type="INSTRUCTION"')
+ startIndex = line.find('missed', instructionIndex)
+ endIndex = line.find('/>', startIndex)
+
+ # find the missed and covered lines counts
+ numbers = re.match(r'missed="(\d+)" covered="(\d+)"', line[startIndex:endIndex])
+ missed = int(numbers.group(1))
+ covered = int(numbers.group(2))
+
+ # calculate the code coverage percentage
+ percentage = round(covered * 100.0 / (missed + covered), 2)
+ print("Android tests code coverage: %s%%" % (str(percentage)))
+
+ # invoke the script that send the data to s3
+ testEnvironment = "LOCAL"
+ if os.environ.get('IS_LOCAL_DEVELOPMENT').lower()=='false':
+ testEnvironment = "CI"
+
+ cmd = os.getcwd() + ("/scripts/code-coverage.sh %.2f %s %s" % (percentage, "Android", testEnvironment))
+ os.system(cmd)