summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJingjing Liu <jingjingliu@google.com>2017-03-28 21:34:08 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-03-28 21:34:08 +0000
commit4ce7e0855699ba2faced65ab61c6b4e53879951d (patch)
tree8a086c776e96b157c096e72cb01aa7a032d85ea4
parent9c98e8b412cdffca50f651a28a18425ecc32a066 (diff)
parent3f1ba012a7a12e71244b42a07fc9001cba4b1291 (diff)
downloadadt-infra-4ce7e0855699ba2faced65ab61c6b4e53879951d.tar.gz
Merge "uninstall apps after finishing tests" am: 2df671b38d am: 6f82a2ee2b am: 18b6117fe7
am: 3f1ba012a7 Change-Id: I5584925c8993b74a0cbe4e8f72bab58084e2134a
-rw-r--r--emu_test/test_console/run_adb_shell.py5
-rw-r--r--emu_test/test_console/testcase_call.py4
-rw-r--r--emu_test/test_console/testcase_geo.py4
-rw-r--r--emu_test/test_console/testcase_orientation.py4
-rw-r--r--emu_test/test_console/testcase_sms.py4
-rw-r--r--emu_test/test_console/uninstall_app.py23
-rw-r--r--emu_test/test_console/utils/util.py12
7 files changed, 53 insertions, 3 deletions
diff --git a/emu_test/test_console/run_adb_shell.py b/emu_test/test_console/run_adb_shell.py
index 00d32405..48d562c5 100644
--- a/emu_test/test_console/run_adb_shell.py
+++ b/emu_test/test_console/run_adb_shell.py
@@ -6,8 +6,7 @@ import time
from utils import util
-main_apk_package = 'com.android.devtools.server'
-launcher_class_name = '%s.Server' % main_apk_package
+launcher_class_name = '%s.Server' % util.MAIN_APK_PACKAGE
instrumentation_runner = 'android.support.test.runner.AndroidJUnitRunner'
num_trials = 1
@@ -21,7 +20,7 @@ while True:
'-w', '-e' 'class',
launcher_class_name,
('%s.test/%s'
- % (main_apk_package,
+ % (util.MAIN_APK_PACKAGE,
instrumentation_runner))])
break
except subprocess.CalledProcessError as err:
diff --git a/emu_test/test_console/testcase_call.py b/emu_test/test_console/testcase_call.py
index 8c169a1e..71dbc68d 100644
--- a/emu_test/test_console/testcase_call.py
+++ b/emu_test/test_console/testcase_call.py
@@ -37,6 +37,10 @@ class PhoneCallTest(testcase_base.BaseConsoleTest):
def setUpClass(cls):
util.run_script_run_adb_shell(TESTCASE_CALL_DIR)
+ @classmethod
+ def tearDownClass(cls):
+ util.unstall_apps(TESTCASE_CALL_DIR)
+
def _process_request_telephony_service(self, payload):
r = requests.post(SERVLET_TELEPHONY, data=json.dumps(payload))
if r.raise_for_status():
diff --git a/emu_test/test_console/testcase_geo.py b/emu_test/test_console/testcase_geo.py
index 36aa230b..93029085 100644
--- a/emu_test/test_console/testcase_geo.py
+++ b/emu_test/test_console/testcase_geo.py
@@ -34,6 +34,10 @@ class GeoTest(testcase_base.BaseConsoleTest):
def setUpClass(cls):
util.run_script_run_adb_shell(TESTCASE_CALL_DIR)
+ @classmethod
+ def tearDownClass(cls):
+ util.unstall_apps(TESTCASE_CALL_DIR)
+
def _process_request_geo_service(self, payload):
"""Processes post request to geo service.
diff --git a/emu_test/test_console/testcase_orientation.py b/emu_test/test_console/testcase_orientation.py
index a6946273..d372242a 100644
--- a/emu_test/test_console/testcase_orientation.py
+++ b/emu_test/test_console/testcase_orientation.py
@@ -38,6 +38,10 @@ class OrientationTest(testcase_base.BaseConsoleTest):
def setUpClass(cls):
util.run_script_run_adb_shell(TESTCASE_CALL_DIR)
+ @classmethod
+ def tearDownClass(cls):
+ util.unstall_apps(TESTCASE_CALL_DIR)
+
def _process_request_orientation_service(self, payload):
"""Processes post request to orientation service.
diff --git a/emu_test/test_console/testcase_sms.py b/emu_test/test_console/testcase_sms.py
index c693f16a..764be972 100644
--- a/emu_test/test_console/testcase_sms.py
+++ b/emu_test/test_console/testcase_sms.py
@@ -37,6 +37,10 @@ class SmsTest(testcase_base.BaseConsoleTest):
def setUpClass(cls):
util.run_script_run_adb_shell(TESTCASE_CALL_DIR)
+ @classmethod
+ def tearDownClass(cls):
+ util.unstall_apps(TESTCASE_CALL_DIR)
+
def _process_request_sms_service(self, payload):
"""Processes post request to sms service.
diff --git a/emu_test/test_console/uninstall_app.py b/emu_test/test_console/uninstall_app.py
new file mode 100644
index 00000000..847c1bed
--- /dev/null
+++ b/emu_test/test_console/uninstall_app.py
@@ -0,0 +1,23 @@
+"""This script is to run adb to uninstall apps."""
+
+import subprocess
+import sys
+import time
+
+from utils import util
+
+test_apk_package = '%s.test' % util.MAIN_APK_PACKAGE
+
+num_trials = 1
+while True:
+ if num_trials is util.ADB_NUM_MAX_TRIALS:
+ sys.exit(-1)
+ try:
+ print ('Run adb shell to uninstall apps, trial num: %s' % str(num_trials))
+ subprocess.call(['adb', 'uninstall', util.MAIN_APK_PACKAGE])
+ subprocess.call(['adb', 'uninstall', test_apk_package])
+ break
+ except subprocess.CalledProcessError as err:
+ print 'Subprocess call error: {0}'.format(err)
+ time.sleep(util.ADB_TRIAL_WAIT_TIME_S)
+ num_trials += 1
diff --git a/emu_test/test_console/utils/util.py b/emu_test/test_console/utils/util.py
index 8899f483..984ee89c 100644
--- a/emu_test/test_console/utils/util.py
+++ b/emu_test/test_console/utils/util.py
@@ -69,8 +69,10 @@ CMD_EMPTY_AUTH_TOKEN = '%s \n' % AUTH
CMD_EXIT = 'exit\n'
SCRIPT_TO_INSTALL_APK = 'install_apk.py'
SCRIPT_TO_RUN_ADB_SHELL = 'run_adb_shell.py'
+SCRIPT_TO_UNINSTALL_APP = 'uninstall_app.py'
PYTHON_INTERPRETER = 'python'
CMD_ROTATE = 'rotate\n'
+MAIN_APK_PACKAGE = 'com.android.devtools.server'
def check_read_until(console_output):
@@ -304,3 +306,13 @@ def run_script_run_adb_shell(testcase_call_dir):
subprocess.call([PYTHON_INTERPRETER, script_install_apk])
subprocess.Popen([PYTHON_INTERPRETER, script_run_adb_shell])
time.sleep(SETUP_WAIT_TIMEOUT_S)
+
+def unstall_apps(testcase_call_dir):
+ """Run Python script to uninstall apps.
+
+ Args:
+ testcase_call_dir: The directory where the test case is called from.
+ """
+ subprocess.Popen([PYTHON_INTERPRETER,
+ '%s/%s' % (testcase_call_dir, SCRIPT_TO_UNINSTALL_APP)])
+ time.sleep(SETUP_WAIT_TIMEOUT_S)