From 6d629d8474578fa0b63e3cc177d65cd3a7f49522 Mon Sep 17 00:00:00 2001 From: Jingjing Liu Date: Mon, 27 Mar 2017 15:35:29 -0700 Subject: uninstall apps after finishing tests Hope this could fix the issue that console buildbot stalling with emulator open (https://b.corp.google.com/issues/34466365) Test: run each affacted test, passed; run whole console tests, passed Change-Id: I3352efe01e485f5cb0dda187a211f188a7a8fb63 --- emu_test/test_console/run_adb_shell.py | 5 ++--- emu_test/test_console/testcase_call.py | 4 ++++ emu_test/test_console/testcase_geo.py | 4 ++++ emu_test/test_console/testcase_orientation.py | 4 ++++ emu_test/test_console/testcase_sms.py | 4 ++++ emu_test/test_console/uninstall_app.py | 23 +++++++++++++++++++++++ emu_test/test_console/utils/util.py | 12 ++++++++++++ 7 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 emu_test/test_console/uninstall_app.py 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) -- cgit v1.2.3