Mark De Ruyter | d9c540a | 2018-05-04 11:21:55 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2016 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 6 | # use this file except in compliance with the License. You may obtain a copy of |
| 7 | # 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, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations under |
| 15 | # the License. |
| 16 | """ |
| 17 | Script for initializing a cmd line tool for PTS and other purposes. |
| 18 | Required custom config parameters: |
| 19 | 'target_mac_address': '00:00:00:00:00:00' |
| 20 | |
| 21 | Optional config parameters: |
| 22 | 'sim_conf_file' : '/path_to_config/' |
| 23 | """ |
Xianyuan Jia | 63751fb | 2020-11-17 00:07:40 +0000 | [diff] [blame^] | 24 | from acts_contrib.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest |
tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame] | 25 | from cmd_input import CmdInput |
| 26 | from queue import Empty |
tturney | cb5ee66 | 2017-09-26 11:07:54 -0700 | [diff] [blame] | 27 | |
tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame] | 28 | import os |
| 29 | import uuid |
| 30 | |
Xianyuan Jia | 63751fb | 2020-11-17 00:07:40 +0000 | [diff] [blame^] | 31 | from acts_contrib.test_utils.tel.tel_test_utils import setup_droid_properties |
tturney | cb5ee66 | 2017-09-26 11:07:54 -0700 | [diff] [blame] | 32 | |
tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame] | 33 | |
| 34 | class BtCmdLineTest(BluetoothBaseTest): |
| 35 | target_mac_address = "" |
| 36 | |
Xianyuan Jia | f17e4bf | 2019-09-05 17:16:23 -0700 | [diff] [blame] | 37 | def setup_class(self): |
| 38 | super().setup_class() |
tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame] | 39 | if not "target_mac_address" in self.user_params.keys(): |
tturney | 68f4a8c | 2017-11-07 08:22:19 -0800 | [diff] [blame] | 40 | self.log.warning("Missing user config \"target_mac_address\"!") |
| 41 | self.target_mac_address = "" |
| 42 | else: |
| 43 | self.target_mac_address = self.user_params[ |
| 44 | "target_mac_address"].upper() |
tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame] | 45 | |
| 46 | self.android_devices[0].droid.bluetoothSetLocalName("CMD LINE Test") |
| 47 | if len(self.android_devices) > 1: |
| 48 | #Setup for more complex testcases |
| 49 | if not "sim_conf_file" in self.user_params.keys(): |
| 50 | self.log.error( |
| 51 | "Missing mandatory user config \"sim_conf_file\"!") |
| 52 | return False |
tturney | cb5ee66 | 2017-09-26 11:07:54 -0700 | [diff] [blame] | 53 | sim_conf_file = self.user_params["sim_conf_file"][0] |
tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame] | 54 | # If the sim_conf_file is not a full path, attempt to find it |
| 55 | # relative to the config file. |
| 56 | if not os.path.isfile(sim_conf_file): |
| 57 | sim_conf_file = os.path.join( |
Xianyuan Jia | 0c8267e | 2019-04-08 15:43:58 -0700 | [diff] [blame] | 58 | self.user_params[Config.key_config_path.value], |
| 59 | sim_conf_file) |
tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame] | 60 | if not os.path.isfile(sim_conf_file): |
| 61 | log.error("Unable to load user config " + sim_conf_file + |
| 62 | " from test config file.") |
| 63 | return False |
| 64 | for ad in self.android_devices: |
| 65 | setup_droid_properties(self.log, ad, sim_conf_file) |
| 66 | music_path_str = "music_path" |
| 67 | android_music_path = "/sdcard/Music/" |
| 68 | if music_path_str not in self.user_params: |
tturney | cb5ee66 | 2017-09-26 11:07:54 -0700 | [diff] [blame] | 69 | self.log.error("Need music for A2DP testcases") |
tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame] | 70 | return False |
| 71 | music_path = self.user_params[music_path_str] |
| 72 | self._add_music_to_primary_android_device(music_path, |
| 73 | android_music_path) |
Xianyuan Jia | f17e4bf | 2019-09-05 17:16:23 -0700 | [diff] [blame] | 74 | return True |
tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame] | 75 | |
| 76 | def _add_music_to_primary_android_device(self, music_path, |
| 77 | android_music_path): |
| 78 | music_list = [] |
| 79 | for dirname, dirnames, filenames in os.walk(music_path): |
| 80 | for filename in filenames: |
| 81 | file = os.path.join(dirname, filename) |
| 82 | #TODO: Handle file paths with spaces |
tturney | cb5ee66 | 2017-09-26 11:07:54 -0700 | [diff] [blame] | 83 | self.android_devices[0].adb.push("{} {}".format( |
| 84 | file, android_music_path)) |
tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame] | 85 | |
tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame] | 86 | def test_pts_cmd_line_helper(self): |
| 87 | cmd_line = CmdInput() |
| 88 | cmd_line.setup_vars(self.android_devices, self.target_mac_address, |
| 89 | self.log) |
| 90 | cmd_line.cmdloop() |
| 91 | return True |