Skip to content

Commit

Permalink
[Android] Create a dummy app to upload to Appurify for gtests.
Browse files Browse the repository at this point in the history
BUG=428729

Review URL: https://codereview.chromium.org/833403002

Cr-Commit-Position: refs/heads/master@{#310159}
  • Loading branch information
jbudorick authored and Commit bot committed Jan 6, 2015
1 parent 6ae6733 commit 335cbe5
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 28 deletions.
14 changes: 14 additions & 0 deletions build/android/pylib/remote/device/dummy/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")

# GYP: //build/android/pylib/remote/device/dummy/dummy.gyp:remote_device_dummy_apk
android_apk("remote_device_dummy_apk") {
android_manifest = "//build/android/AndroidManifest.xml"
java_files = [ "src/org/chromium/dummy/Dummy.java" ]
apk_name = "remote_device_dummy"
testonly = true
}
25 changes: 25 additions & 0 deletions build/android/pylib/remote/device/dummy/dummy.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Running gtests on a remote device via am instrument requires both an "app"
# APK and a "test" APK with different package names. Our gtests only use one
# APK, so we build a dummy APK to upload as the app.

{
'targets': [
{
# GN: //build/android/pylib/remote/device/dummy:remote_device_dummy_apk
'target_name': 'remote_device_dummy_apk',
'type': 'none',
'variables': {
'apk_name': 'remote_device_dummy',
'java_in_dir': '.',
'android_manifest_path': '../../../../../../build/android/AndroidManifest.xml',
},
'includes': [
'../../../../../../build/java_apk.gypi',
]
},
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.dummy;

/** Does nothing. */
class Dummy {}

19 changes: 8 additions & 11 deletions build/android/pylib/remote/device/remote_device_gtest_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
class RemoteDeviceGtestRun(remote_device_test_run.RemoteDeviceTestRun):
"""Run gtests and uirobot tests on a remote device."""

DEFAULT_RUNNER_TYPE = 'robotium'
DEFAULT_RUNNER_PACKAGE = (
'org.chromium.native_test.ChromiumNativeTestInstrumentationTestRunner')

Expand All @@ -30,24 +29,22 @@ def TestPackage(self):
def _TriggerSetUp(self):
"""Set up the triggering of a test run."""
logging.info('Triggering test run.')
self._app_id = self._UploadAppToDevice(self._test_instance.apk)

if not self._env.runner_type:
runner_type = self.DEFAULT_RUNNER_TYPE
logging.info('Using default runner type: %s', self.DEFAULT_RUNNER_TYPE)
else:
runner_type = self._env.runner_type
if self._env.runner_type:
logging.warning('Ignoring configured runner_type "%s"',
self._env.runner_type)

if not self._env.runner_package:
runner_package = self.DEFAULT_RUNNER_PACKAGE
logging.info('Using default runner package: %s',
self.DEFAULT_RUNNER_TYPE)
self.DEFAULT_RUNNER_PACKAGE)
else:
runner_package = self._env.runner_package

self._test_id = self._UploadTestToDevice(runner_type)
config_body = {'runner': runner_package}
self._SetTestConfig(runner_type, config_body)
dummy_app_path = os.path.join(
constants.GetOutDirectory(), 'apks', 'remote_device_dummy.apk')
self._AmInstrumentTestSetup(dummy_app_path, self._test_instance.apk,
runner_package)

_INSTRUMENTATION_STREAM_LEADER = 'INSTRUMENTATION_STATUS: stream='

Expand Down
41 changes: 25 additions & 16 deletions build/android/pylib/remote/device/remote_device_test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,37 @@ def _GetTestStatus(self, test_run_id):
logging.info('Test status: %s' % self._results['detailed_status'])
return self._results['status']

def _UploadAppToDevice(self, apk_path):
def _AmInstrumentTestSetup(self, app_path, test_path, runner_package):
config = {'runner': runner_package}

self._app_id = self._UploadAppToDevice(app_path)
self._test_id = self._UploadTestToDevice('robotium', test_path)

logging.info('Setting config: %s' % config)
self._SetTestConfig('robotium', config)

def _UploadAppToDevice(self, app_path):
"""Upload app to device."""
logging.info('Upload %s to remote service.' % apk_path)
apk_name = os.path.basename(apk_path)
with open(apk_path, 'rb') as apk_src:
upload_results = appurify_sanitized.api.apps_upload(self._env.token,
apk_src, 'raw', name=apk_name)
logging.info('Upload %s to remote service.' % app_path)
apk_name = os.path.basename(app_path)
with open(app_path, 'rb') as apk_src:
upload_results = appurify_sanitized.api.apps_upload(
self._env.token, apk_src, 'raw', name=apk_name)
remote_device_helper.TestHttpResponse(
upload_results, 'Unable to upload %s.' %(apk_path))
upload_results, 'Unable to upload %s.' % app_path)
return upload_results.json()['response']['app_id']

def _UploadTestToDevice(self, test_type):
def _UploadTestToDevice(self, test_type, test_path):
"""Upload test to device
Args:
test_type: Type of test that is being uploaded. Ex. uirobot, gtest..
"""
logging.info('Uploading %s to remote service.' % self._test_instance.apk)
with open(self._test_instance.apk, 'rb') as test_src:
logging.info('Uploading %s to remote service.' % test_path)
with open(test_path, 'rb') as test_src:
upload_results = appurify_sanitized.api.tests_upload(
self._env.token, test_src, 'raw', test_type, app_id=self._app_id)
self._env.token, test_src, 'raw', test_type)
remote_device_helper.TestHttpResponse(upload_results,
'Unable to upload %s.' %(self._test_instance.apk))
'Unable to upload %s.' % test_path)
return upload_results.json()['response']['test_id']

def _SetTestConfig(self, runner_type, body):
Expand All @@ -174,7 +183,7 @@ def _SetTestConfig(self, runner_type, body):
config.write(''.join('%s\n' % l for l in config_data))
config.flush()
config.seek(0)
config_response = appurify_sanitized.api.config_upload(self._env.token,
config, self._test_id)
remote_device_helper.TestHttpResponse(config_response,
'Unable to upload test config.')
config_response = appurify_sanitized.api.config_upload(
self._env.token, config, self._test_id)
remote_device_helper.TestHttpResponse(
config_response, 'Unable to upload test config.')
1 change: 1 addition & 0 deletions build/apk_test.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'dependencies': [
'<(DEPTH)/base/base.gyp:base_java',
'<(DEPTH)/build/android/pylib/device/commands/commands.gyp:chromium_commands',
'<(DEPTH)/build/android/pylib/remote/device/dummy/dummy.gyp:remote_device_dummy_apk',
'<(DEPTH)/tools/android/android_tools.gyp:android_tools',
],
'conditions': [
Expand Down
6 changes: 5 additions & 1 deletion build/config/android/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -1450,14 +1450,18 @@ template("unittest_apk") {
android_apk(target_name) {
_apk_name = test_suite_name
final_apk_path = "$root_build_dir/${_apk_name}_apk/${_apk_name}-debug.apk"
java_files = [ "//testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java" ]
java_files = [
"//testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java",
"//testing/android/java/src/org/chromium/native_test/ChromiumNativeTestInstrumentationTestRunner.java",
]
android_manifest = "//testing/android/java/AndroidManifest.xml"
native_libs = [ unittests_binary ]
if (defined(invoker.asset_location)) {
asset_location = invoker.asset_location
}
deps = [
"//base:base_java",
"//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
]
if (defined(invoker.deps)) {
deps += invoker.deps
Expand Down

0 comments on commit 335cbe5

Please sign in to comment.