markdr | dd1893d | 2018-02-05 17:13:47 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Ang Li | bd1dd2e | 2016-03-22 19:13:56 -0700 | [diff] [blame] | 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 | |
Ang Li | 4848c64 | 2016-06-21 18:29:06 -0700 | [diff] [blame] | 17 | import mock |
Mark De Ruyter | 05c72ab | 2019-09-04 15:31:21 -0700 | [diff] [blame] | 18 | import os |
Ang Li | bd1dd2e | 2016-03-22 19:13:56 -0700 | [diff] [blame] | 19 | import shutil |
| 20 | import tempfile |
| 21 | import unittest |
| 22 | |
Mark De Ruyter | 9792f78 | 2019-12-03 18:14:47 -0800 | [diff] [blame] | 23 | from mobly.config_parser import TestRunConfig |
| 24 | |
Ang Li | bd1dd2e | 2016-03-22 19:13:56 -0700 | [diff] [blame] | 25 | from acts import keys |
Ang Li | bd1dd2e | 2016-03-22 19:13:56 -0700 | [diff] [blame] | 26 | from acts import test_runner |
Ang Li | b280a72 | 2016-06-08 10:39:33 -0700 | [diff] [blame] | 27 | |
| 28 | import acts_android_device_test |
Ang Li | bd1dd2e | 2016-03-22 19:13:56 -0700 | [diff] [blame] | 29 | import mock_controller |
Mark De Ruyter | 05c72ab | 2019-09-04 15:31:21 -0700 | [diff] [blame] | 30 | import IntegrationTest |
Ang Li | bd1dd2e | 2016-03-22 19:13:56 -0700 | [diff] [blame] | 31 | |
| 32 | |
| 33 | class ActsTestRunnerTest(unittest.TestCase): |
| 34 | """This test class has unit tests for the implementation of everything |
| 35 | under acts.test_runner. |
| 36 | """ |
Ang Li | bd1dd2e | 2016-03-22 19:13:56 -0700 | [diff] [blame] | 37 | def setUp(self): |
| 38 | self.tmp_dir = tempfile.mkdtemp() |
Mark De Ruyter | 9792f78 | 2019-12-03 18:14:47 -0800 | [diff] [blame] | 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 = { |
Mark De Ruyter | 05c72ab | 2019-09-04 15:31:21 -0700 | [diff] [blame] | 46 | 'icecream': 42, |
| 47 | 'extra_param': 'haha' |
Ang Li | bd1dd2e | 2016-03-22 19:13:56 -0700 | [diff] [blame] | 48 | } |
| 49 | self.mock_run_list = [('SampleTest', None)] |
| 50 | |
| 51 | def tearDown(self): |
| 52 | shutil.rmtree(self.tmp_dir) |
| 53 | |
Ang Li | 06fc984 | 2016-04-22 18:25:38 -0700 | [diff] [blame] | 54 | def test_run_twice(self): |
Ang Li | 8c7039d | 2016-05-10 13:36:35 -0700 | [diff] [blame] | 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 | """ |
Mark De Ruyter | 9792f78 | 2019-12-03 18:14:47 -0800 | [diff] [blame] | 60 | mock_test_config = self.base_mock_test_config.copy() |
Ang Li | 06fc984 | 2016-04-22 18:25:38 -0700 | [diff] [blame] | 61 | tb_key = keys.Config.key_testbed.value |
| 62 | mock_ctrlr_config_name = mock_controller.ACTS_CONTROLLER_CONFIG_NAME |
Betty Zhou | 15d1780 | 2017-07-26 16:03:51 -0700 | [diff] [blame] | 63 | my_config = [{ |
Mark De Ruyter | 05c72ab | 2019-09-04 15:31:21 -0700 | [diff] [blame] | 64 | 'serial': 'xxxx', |
| 65 | 'magic': 'Magic1' |
Betty Zhou | 15d1780 | 2017-07-26 16:03:51 -0700 | [diff] [blame] | 66 | }, { |
Mark De Ruyter | 05c72ab | 2019-09-04 15:31:21 -0700 | [diff] [blame] | 67 | 'serial': 'xxxx', |
| 68 | 'magic': 'Magic2' |
Betty Zhou | 15d1780 | 2017-07-26 16:03:51 -0700 | [diff] [blame] | 69 | }] |
Mark De Ruyter | 9792f78 | 2019-12-03 18:14:47 -0800 | [diff] [blame] | 70 | mock_test_config.controller_configs[mock_ctrlr_config_name] = my_config |
markdr | f436a98 | 2017-11-08 13:15:34 -0800 | [diff] [blame] | 71 | tr = test_runner.TestRunner(mock_test_config, |
| 72 | [('IntegrationTest', None)]) |
Ang Li | 06fc984 | 2016-04-22 18:25:38 -0700 | [diff] [blame] | 73 | tr.run() |
Ang Li | 06fc984 | 2016-04-22 18:25:38 -0700 | [diff] [blame] | 74 | tr.run() |
| 75 | tr.stop() |
Ang Li | 06fc984 | 2016-04-22 18:25:38 -0700 | [diff] [blame] | 76 | results = tr.results.summary_dict() |
Mark De Ruyter | 05c72ab | 2019-09-04 15:31:21 -0700 | [diff] [blame] | 77 | self.assertEqual(results['Requested'], 2) |
| 78 | self.assertEqual(results['Executed'], 2) |
| 79 | self.assertEqual(results['Passed'], 2) |
Ang Li | 06fc984 | 2016-04-22 18:25:38 -0700 | [diff] [blame] | 80 | |
Mark De Ruyter | 51b44e2 | 2019-11-15 17:44:47 -0800 | [diff] [blame] | 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)) |
Betty Zhou | 0543ccc | 2017-08-08 17:28:21 -0700 | [diff] [blame] | 90 | @mock.patch( |
| 91 | 'acts.controllers.android_device.AndroidDevice.ensure_screen_on', |
| 92 | return_value=True) |
markdr | c018ee2 | 2017-12-05 16:32:06 -0800 | [diff] [blame] | 93 | @mock.patch( |
| 94 | 'acts.controllers.android_device.AndroidDevice.exit_setup_wizard', |
| 95 | return_value=True) |
Mark De Ruyter | 9792f78 | 2019-12-03 18:14:47 -0800 | [diff] [blame] | 96 | def test_run_two_test_classes(self, *_): |
Xianyuan Jia | 0b3acca | 2019-03-28 18:42:35 +0000 | [diff] [blame] | 97 | """Verifies that running more than one test class in one test run works |
| 98 | properly. |
Ang Li | 4848c64 | 2016-06-21 18:29:06 -0700 | [diff] [blame] | 99 | |
| 100 | This requires using a built-in controller module. Using AndroidDevice |
| 101 | module since it has all the mocks needed already. |
| 102 | """ |
Mark De Ruyter | 9792f78 | 2019-12-03 18:14:47 -0800 | [diff] [blame] | 103 | mock_test_config = self.base_mock_test_config.copy() |
Ang Li | 4848c64 | 2016-06-21 18:29:06 -0700 | [diff] [blame] | 104 | tb_key = keys.Config.key_testbed.value |
| 105 | mock_ctrlr_config_name = mock_controller.ACTS_CONTROLLER_CONFIG_NAME |
Betty Zhou | 15d1780 | 2017-07-26 16:03:51 -0700 | [diff] [blame] | 106 | my_config = [{ |
Mark De Ruyter | 05c72ab | 2019-09-04 15:31:21 -0700 | [diff] [blame] | 107 | 'serial': 'xxxx', |
| 108 | 'magic': 'Magic1' |
Betty Zhou | 15d1780 | 2017-07-26 16:03:51 -0700 | [diff] [blame] | 109 | }, { |
Mark De Ruyter | 05c72ab | 2019-09-04 15:31:21 -0700 | [diff] [blame] | 110 | 'serial': 'xxxx', |
| 111 | 'magic': 'Magic2' |
Betty Zhou | 15d1780 | 2017-07-26 16:03:51 -0700 | [diff] [blame] | 112 | }] |
Mark De Ruyter | 9792f78 | 2019-12-03 18:14:47 -0800 | [diff] [blame] | 113 | mock_test_config.controller_configs[mock_ctrlr_config_name] = my_config |
| 114 | mock_test_config.controller_configs['AndroidDevice'] = [{ |
| 115 | 'serial': |
| 116 | '1', |
| 117 | 'skip_sl4a': |
| 118 | True |
Betty Zhou | 15d1780 | 2017-07-26 16:03:51 -0700 | [diff] [blame] | 119 | }] |
markdr | f436a98 | 2017-11-08 13:15:34 -0800 | [diff] [blame] | 120 | tr = test_runner.TestRunner(mock_test_config, |
| 121 | [('IntegrationTest', None), |
| 122 | ('IntegrationTest', None)]) |
Ang Li | 4848c64 | 2016-06-21 18:29:06 -0700 | [diff] [blame] | 123 | tr.run() |
| 124 | tr.stop() |
Ang Li | 4848c64 | 2016-06-21 18:29:06 -0700 | [diff] [blame] | 125 | results = tr.results.summary_dict() |
Mark De Ruyter | 05c72ab | 2019-09-04 15:31:21 -0700 | [diff] [blame] | 126 | self.assertEqual(results['Requested'], 2) |
| 127 | self.assertEqual(results['Executed'], 2) |
| 128 | self.assertEqual(results['Passed'], 2) |
Ang Li | 4848c64 | 2016-06-21 18:29:06 -0700 | [diff] [blame] | 129 | |
Ang Li | bd1dd2e | 2016-03-22 19:13:56 -0700 | [diff] [blame] | 130 | |
Mark De Ruyter | 05c72ab | 2019-09-04 15:31:21 -0700 | [diff] [blame] | 131 | if __name__ == '__main__': |
Ang Li | 4848c64 | 2016-06-21 18:29:06 -0700 | [diff] [blame] | 132 | unittest.main() |