1#!/usr/bin/env python3 2# 3# Copyright 2016 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import mock 18import os 19import shutil 20import tempfile 21import unittest 22 23from mobly.config_parser import TestRunConfig 24 25from acts import keys 26from acts import test_runner 27 28import acts_android_device_test 29import mock_controller 30import IntegrationTest 31 32 33class ActsTestRunnerTest(unittest.TestCase): 34 """This test class has unit tests for the implementation of everything 35 under acts.test_runner. 36 """ 37 def setUp(self): 38 self.tmp_dir = tempfile.mkdtemp() 39 self.base_mock_test_config = TestRunConfig() 40 self.base_mock_test_config.testbed_name = 'SampleTestBed' 41 self.base_mock_test_config.log_path = self.tmp_dir 42 self.base_mock_test_config.controller_configs = { 43 'testpaths': [os.path.dirname(IntegrationTest.__file__)] 44 } 45 self.base_mock_test_config.user_params = { 46 'icecream': 42, 47 'extra_param': 'haha' 48 } 49 self.mock_run_list = [('SampleTest', None)] 50 51 def tearDown(self): 52 shutil.rmtree(self.tmp_dir) 53 54 def test_run_twice(self): 55 """Verifies that: 56 1. Repeated run works properly. 57 2. The original configuration is not altered if a test controller 58 module modifies configuration. 59 """ 60 mock_test_config = self.base_mock_test_config.copy() 61 tb_key = keys.Config.key_testbed.value 62 mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME 63 my_config = [{ 64 'serial': 'xxxx', 65 'magic': 'Magic1' 66 }, { 67 'serial': 'xxxx', 68 'magic': 'Magic2' 69 }] 70 mock_test_config.controller_configs[mock_ctrlr_config_name] = my_config 71 tr = test_runner.TestRunner(mock_test_config, 72 [('IntegrationTest', None)]) 73 tr.run() 74 tr.run() 75 tr.stop() 76 results = tr.results.summary_dict() 77 self.assertEqual(results['Requested'], 2) 78 self.assertEqual(results['Executed'], 2) 79 self.assertEqual(results['Passed'], 2) 80 81 @mock.patch('acts.controllers.adb.AdbProxy', 82 return_value=acts_android_device_test.MockAdbProxy( 83 1, return_value='')) 84 @mock.patch('acts.controllers.fastboot.FastbootProxy', 85 return_value=acts_android_device_test.MockFastbootProxy(1)) 86 @mock.patch('acts.controllers.android_device.list_adb_devices', 87 return_value=['1']) 88 @mock.patch('acts.controllers.android_device.get_all_instances', 89 return_value=acts_android_device_test.get_mock_ads(1)) 90 @mock.patch( 91 'acts.controllers.android_device.AndroidDevice.ensure_screen_on', 92 return_value=True) 93 @mock.patch( 94 'acts.controllers.android_device.AndroidDevice.exit_setup_wizard', 95 return_value=True) 96 @mock.patch('acts.controllers.android_device.AndroidDevice.start_services') 97 def test_run_two_test_classes(self, *_): 98 """Verifies that running more than one test class in one test run works 99 properly. 100 101 This requires using a built-in controller module. Using AndroidDevice 102 module since it has all the mocks needed already. 103 """ 104 mock_test_config = self.base_mock_test_config.copy() 105 tb_key = keys.Config.key_testbed.value 106 mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME 107 my_config = [{ 108 'serial': 'xxxx', 109 'magic': 'Magic1' 110 }, { 111 'serial': 'xxxx', 112 'magic': 'Magic2' 113 }] 114 mock_test_config.controller_configs[mock_ctrlr_config_name] = my_config 115 mock_test_config.controller_configs['AndroidDevice'] = [{ 116 'serial': 117 '1', 118 'skip_sl4a': 119 True 120 }] 121 tr = test_runner.TestRunner(mock_test_config, 122 [('IntegrationTest', None), 123 ('IntegrationTest', None)]) 124 tr.run() 125 tr.stop() 126 results = tr.results.summary_dict() 127 self.assertEqual(results['Requested'], 2) 128 self.assertEqual(results['Executed'], 2) 129 self.assertEqual(results['Passed'], 2) 130 131 132if __name__ == '__main__': 133 unittest.main() 134