blob: adcfa6408a2edec783a4d4373e61d138d4781e91 [file] [log] [blame]
markdrdd1893d2018-02-05 17:13:47 -08001#!/usr/bin/env python3
Ang Libd1dd2e2016-03-22 19:13:56 -07002#
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 Li4848c642016-06-21 18:29:06 -070017import mock
Mark De Ruyter05c72ab2019-09-04 15:31:21 -070018import os
Ang Libd1dd2e2016-03-22 19:13:56 -070019import shutil
20import tempfile
21import unittest
22
Mark De Ruyter9792f782019-12-03 18:14:47 -080023from mobly.config_parser import TestRunConfig
24
Ang Libd1dd2e2016-03-22 19:13:56 -070025from acts import keys
Ang Libd1dd2e2016-03-22 19:13:56 -070026from acts import test_runner
Ang Lib280a722016-06-08 10:39:33 -070027
28import acts_android_device_test
Ang Libd1dd2e2016-03-22 19:13:56 -070029import mock_controller
Mark De Ruyter05c72ab2019-09-04 15:31:21 -070030import IntegrationTest
Ang Libd1dd2e2016-03-22 19:13:56 -070031
32
33class ActsTestRunnerTest(unittest.TestCase):
34 """This test class has unit tests for the implementation of everything
35 under acts.test_runner.
36 """
Ang Libd1dd2e2016-03-22 19:13:56 -070037 def setUp(self):
38 self.tmp_dir = tempfile.mkdtemp()
Mark De Ruyter9792f782019-12-03 18:14:47 -080039 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 Ruyter05c72ab2019-09-04 15:31:21 -070046 'icecream': 42,
47 'extra_param': 'haha'
Ang Libd1dd2e2016-03-22 19:13:56 -070048 }
49 self.mock_run_list = [('SampleTest', None)]
50
51 def tearDown(self):
52 shutil.rmtree(self.tmp_dir)
53
Ang Li06fc9842016-04-22 18:25:38 -070054 def test_run_twice(self):
Ang Li8c7039d2016-05-10 13:36:35 -070055 """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 Ruyter9792f782019-12-03 18:14:47 -080060 mock_test_config = self.base_mock_test_config.copy()
Ang Li06fc9842016-04-22 18:25:38 -070061 tb_key = keys.Config.key_testbed.value
62 mock_ctrlr_config_name = mock_controller.ACTS_CONTROLLER_CONFIG_NAME
Betty Zhou15d17802017-07-26 16:03:51 -070063 my_config = [{
Mark De Ruyter05c72ab2019-09-04 15:31:21 -070064 'serial': 'xxxx',
65 'magic': 'Magic1'
Betty Zhou15d17802017-07-26 16:03:51 -070066 }, {
Mark De Ruyter05c72ab2019-09-04 15:31:21 -070067 'serial': 'xxxx',
68 'magic': 'Magic2'
Betty Zhou15d17802017-07-26 16:03:51 -070069 }]
Mark De Ruyter9792f782019-12-03 18:14:47 -080070 mock_test_config.controller_configs[mock_ctrlr_config_name] = my_config
markdrf436a982017-11-08 13:15:34 -080071 tr = test_runner.TestRunner(mock_test_config,
72 [('IntegrationTest', None)])
Ang Li06fc9842016-04-22 18:25:38 -070073 tr.run()
Ang Li06fc9842016-04-22 18:25:38 -070074 tr.run()
75 tr.stop()
Ang Li06fc9842016-04-22 18:25:38 -070076 results = tr.results.summary_dict()
Mark De Ruyter05c72ab2019-09-04 15:31:21 -070077 self.assertEqual(results['Requested'], 2)
78 self.assertEqual(results['Executed'], 2)
79 self.assertEqual(results['Passed'], 2)
Ang Li06fc9842016-04-22 18:25:38 -070080
Mark De Ruyter51b44e22019-11-15 17:44:47 -080081 @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 Zhou0543ccc2017-08-08 17:28:21 -070090 @mock.patch(
91 'acts.controllers.android_device.AndroidDevice.ensure_screen_on',
92 return_value=True)
markdrc018ee22017-12-05 16:32:06 -080093 @mock.patch(
94 'acts.controllers.android_device.AndroidDevice.exit_setup_wizard',
95 return_value=True)
Mark De Ruyter9792f782019-12-03 18:14:47 -080096 def test_run_two_test_classes(self, *_):
Xianyuan Jia0b3acca2019-03-28 18:42:35 +000097 """Verifies that running more than one test class in one test run works
98 properly.
Ang Li4848c642016-06-21 18:29:06 -070099
100 This requires using a built-in controller module. Using AndroidDevice
101 module since it has all the mocks needed already.
102 """
Mark De Ruyter9792f782019-12-03 18:14:47 -0800103 mock_test_config = self.base_mock_test_config.copy()
Ang Li4848c642016-06-21 18:29:06 -0700104 tb_key = keys.Config.key_testbed.value
105 mock_ctrlr_config_name = mock_controller.ACTS_CONTROLLER_CONFIG_NAME
Betty Zhou15d17802017-07-26 16:03:51 -0700106 my_config = [{
Mark De Ruyter05c72ab2019-09-04 15:31:21 -0700107 'serial': 'xxxx',
108 'magic': 'Magic1'
Betty Zhou15d17802017-07-26 16:03:51 -0700109 }, {
Mark De Ruyter05c72ab2019-09-04 15:31:21 -0700110 'serial': 'xxxx',
111 'magic': 'Magic2'
Betty Zhou15d17802017-07-26 16:03:51 -0700112 }]
Mark De Ruyter9792f782019-12-03 18:14:47 -0800113 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 Zhou15d17802017-07-26 16:03:51 -0700119 }]
markdrf436a982017-11-08 13:15:34 -0800120 tr = test_runner.TestRunner(mock_test_config,
121 [('IntegrationTest', None),
122 ('IntegrationTest', None)])
Ang Li4848c642016-06-21 18:29:06 -0700123 tr.run()
124 tr.stop()
Ang Li4848c642016-06-21 18:29:06 -0700125 results = tr.results.summary_dict()
Mark De Ruyter05c72ab2019-09-04 15:31:21 -0700126 self.assertEqual(results['Requested'], 2)
127 self.assertEqual(results['Executed'], 2)
128 self.assertEqual(results['Passed'], 2)
Ang Li4848c642016-06-21 18:29:06 -0700129
Ang Libd1dd2e2016-03-22 19:13:56 -0700130
Mark De Ruyter05c72ab2019-09-04 15:31:21 -0700131if __name__ == '__main__':
Ang Li4848c642016-06-21 18:29:06 -0700132 unittest.main()