blob: a7cb5ff5820dd14536880b7452356cbb8388dce9 [file] [log] [blame]
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -07001#!/usr/bin/env python3
2#
3# Copyright 2019 - 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
Hector6048d232020-03-05 18:54:19 -080017import mock
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070018import unittest
19
Xianyuan Jia239dbea2019-08-19 16:21:49 -070020from acts.test_utils.instrumentation.config_wrapper import ConfigWrapper
Hector6048d232020-03-05 18:54:19 -080021from acts.test_utils.instrumentation.device.command.adb_command_types import \
22 GenericCommand
Xianyuan Jia31b53e42019-07-26 12:26:03 -070023from acts.test_utils.instrumentation.instrumentation_base_test import \
24 InstrumentationBaseTest
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070025
Xianyuan Jia997ca682019-08-20 17:58:06 -070026MOCK_INSTRUMENTATION_CONFIG = {
Xianyuan Jia239dbea2019-08-19 16:21:49 -070027 'MockController': {
Xianyuan Jiaa9855092019-10-01 16:20:21 -070028 'param1': 1,
29 'param2': 4
Xianyuan Jia239dbea2019-08-19 16:21:49 -070030 },
31 'MockInstrumentationBaseTest': {
32 'MockController': {
Xianyuan Jiaa9855092019-10-01 16:20:21 -070033 'param2': 2,
34 'param3': 5
Xianyuan Jia239dbea2019-08-19 16:21:49 -070035 },
36 'test_case': {
37 'MockController': {
38 'param3': 3
39 }
40 }
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070041 }
42}
43
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070044
45class MockInstrumentationBaseTest(InstrumentationBaseTest):
46 """Mock test class to initialize required attributes."""
Hector6048d232020-03-05 18:54:19 -080047
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070048 def __init__(self):
Xianyuan Jia239dbea2019-08-19 16:21:49 -070049 self.current_test_name = None
Hector6048d232020-03-05 18:54:19 -080050 self.ad_dut = mock.Mock()
51 self.log = mock.Mock()
Xianyuan Jia997ca682019-08-20 17:58:06 -070052 self._instrumentation_config = ConfigWrapper(
53 MOCK_INSTRUMENTATION_CONFIG)
Xianyuan Jiae327f5b2019-09-19 11:15:04 -070054 self._class_config = self._instrumentation_config.get_config(
55 self.__class__.__name__)
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070056
57
58class InstrumentationBaseTestTest(unittest.TestCase):
59 def setUp(self):
60 self.instrumentation_test = MockInstrumentationBaseTest()
61
Xianyuan Jia239dbea2019-08-19 16:21:49 -070062 def test_get_controller_config_for_test_case(self):
63 """Test that _get_controller_config returns the corresponding
64 controller config for the current test case.
65 """
66 self.instrumentation_test.current_test_name = 'test_case'
Xianyuan Jiaa9855092019-10-01 16:20:21 -070067 config = self.instrumentation_test._get_merged_config(
Xianyuan Jia239dbea2019-08-19 16:21:49 -070068 'MockController')
Xianyuan Jiaa9855092019-10-01 16:20:21 -070069 self.assertEqual(config.get('param1'), 1)
70 self.assertEqual(config.get('param2'), 2)
71 self.assertEqual(config.get('param3'), 3)
Xianyuan Jia239dbea2019-08-19 16:21:49 -070072
73 def test_get_controller_config_for_test_class(self):
74 """Test that _get_controller_config returns the controller config for
75 the current test class (while no test case is running).
76 """
Xianyuan Jiaa9855092019-10-01 16:20:21 -070077 config = self.instrumentation_test._get_merged_config(
Xianyuan Jia239dbea2019-08-19 16:21:49 -070078 'MockController')
Xianyuan Jiaa9855092019-10-01 16:20:21 -070079 self.assertEqual(config.get('param1'), 1)
80 self.assertEqual(config.get('param2'), 2)
81 self.assertEqual(config.get('param3'), 5)
Xianyuan Jia239dbea2019-08-19 16:21:49 -070082
Hector6048d232020-03-05 18:54:19 -080083 def test_adb_run_literal_commands(self):
84 result = self.instrumentation_test.adb_run('ls /something')
85 self.assertIn('ls /something', result.keys())
86
87 result = self.instrumentation_test.adb_run(
88 ['ls /something', 'ls /other'])
89 self.assertIn('ls /something', result.keys())
90 self.assertIn('ls /other', result.keys())
91
92 def test_adb_run_generic_commands(self):
93 result = self.instrumentation_test.adb_run(
94 GenericCommand('ls /something'))
95 self.assertIn('ls /something', result.keys())
96
97 result = self.instrumentation_test.adb_run(
98 [GenericCommand('ls /something'),
99 GenericCommand('ls /other')])
100 self.assertIn('ls /something', result.keys())
101 self.assertIn('ls /other', result.keys())
102
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -0700103
104if __name__ == '__main__':
105 unittest.main()