Bug 1433322 - 3. Run GeckoView unit tests with 'mach android test'; r=nalexander

Run unit tests under geckoview/ when running 'mach android test'. This
also lets us run those tests on Taskcluster.

The test report parser for 'mach android test' had a bug where the input
directory was wrong. As a result, we weren't producing test output at
all. This patch fixes the input directory, and outputs an error if no
reports are found at all to avoid this bug in the future.

MozReview-Commit-ID: IiswQaSPCr0
This commit is contained in:
Jim Chen 2018-02-08 13:36:22 -05:00
Родитель 338a932c87
Коммит 50ae81a660
4 изменённых файлов: 46 добавлений и 11 удалений

Просмотреть файл

@ -148,6 +148,10 @@ android {
dependencies {
implementation "com.android.support:support-v4:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
implementation "com.android.support:palette-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:3.5.1'
testImplementation 'org.mockito:mockito-core:1.10.19'
}
apply from: "${topsrcdir}/mobile/android/gradle/with_gecko_binaries.gradle"

Просмотреть файл

@ -68,7 +68,7 @@ def gradle_android_build_config():
@depends(gradle_android_build_config)
def gradle_android_app_variant_name(build_config):
def gradle_android_variant_name(build_config):
'''Like "officialPhotonDebug".'''
def uncapitalize(s):
if s:
@ -76,9 +76,14 @@ def gradle_android_app_variant_name(build_config):
else:
return s
return uncapitalize(build_config.app.variant.name)
return namespace(
app=uncapitalize(build_config.app.variant.name),
geckoview=uncapitalize(build_config.geckoview.variant.name),
)
set_config('GRADLE_ANDROID_APP_VARIANT_NAME', gradle_android_app_variant_name)
set_config('GRADLE_ANDROID_APP_VARIANT_NAME', gradle_android_variant_name.app)
set_config('GRADLE_ANDROID_GECKOVIEW_VARIANT_NAME', gradle_android_variant_name.geckoview)
@depends(gradle_android_build_config)
@ -138,6 +143,8 @@ def gradle_android_test_tasks(build_config):
'''Gradle tasks run by |mach android test|.'''
return [
'app:test{app.variant.name}UnitTest'.format(app=build_config.app),
'geckoview:test{geckoview.variant.name}UnitTest'.format(
geckoview=build_config.geckoview),
]
set_config('GRADLE_ANDROID_TEST_TASKS', gradle_android_test_tasks)

Просмотреть файл

@ -71,7 +71,16 @@ class MachCommands(MachCommandBase):
def android_test(self, args):
ret = self.gradle(self.substs['GRADLE_ANDROID_TEST_TASKS'] + ["--continue"] + args, verbose=True)
# Findbug produces both HTML and XML reports. Visit the
ret |= self._parse_android_test_results('public/app/unittest', 'gradle/build/mobile/android/app',
(self.substs['GRADLE_ANDROID_APP_VARIANT_NAME'],))
ret |= self._parse_android_test_results('public/geckoview/unittest', 'gradle/build/mobile/android/geckoview',
(self.substs['GRADLE_ANDROID_GECKOVIEW_VARIANT_NAME'],))
return ret
def _parse_android_test_results(self, artifactdir, gradledir, variants):
# Unit tests produce both HTML and XML reports. Visit the
# XML report(s) to report errors and link to the HTML
# report(s) for human consumption.
import itertools
@ -81,14 +90,22 @@ class MachCommands(MachCommandBase):
FileFinder,
)
root_url = self._root_url(
artifactdir='public/android/unittest',
objdir='gradle/build/mobile/android/app/reports/tests')
ret = 0
found_reports = False
reports = (self.substs['GRADLE_ANDROID_APP_VARIANT_NAME'],)
for report in reports:
finder = FileFinder(os.path.join(self.topobjdir, 'gradle/build/mobile/android/app/test-results/', report))
root_url = self._root_url(
artifactdir=artifactdir,
objdir=gradledir + '/reports/tests')
def capitalize(s):
# Can't use str.capitalize because it lower cases trailing letters.
return (s[0].upper() + s[1:]) if s else ''
for variant in variants:
report = 'test{}UnitTest'.format(capitalize(variant))
finder = FileFinder(os.path.join(self.topobjdir, gradledir + '/test-results/', report))
for p, _ in finder.find('TEST-*.xml'):
found_reports = True
f = open(os.path.join(finder.base, p), 'rt')
tree = ET.parse(f)
root = tree.getroot()
@ -132,6 +149,10 @@ class MachCommands(MachCommandBase):
print('SUITE-END | android-test | {} {}'.format(report, root.get('name')))
if not found_reports:
print('TEST-UNEXPECTED-FAIL | android-test | No reports found under {}'.format(gradledir))
return 1
return ret

Просмотреть файл

@ -15,9 +15,12 @@ android-test/opt:
GRADLE_USER_HOME: "/builds/worker/workspace/build/src/mobile/android/gradle/dotgradle-offline"
PERFHERDER_EXTRA_OPTIONS: android-test
artifacts:
- name: public/android/unittest
- name: public/app/unittest
path: /builds/worker/workspace/build/src/obj-firefox/gradle/build/mobile/android/app/reports/tests
type: directory
- name: public/geckoview/unittest
path: /builds/worker/workspace/build/src/obj-firefox/gradle/build/mobile/android/geckoview/reports/tests
type: directory
- name: public/build
path: /builds/worker/artifacts/
type: directory