tturney | 412efba | 2017-05-12 14:58:18 -0700 | [diff] [blame^] | 1 | #/usr/bin/env python3.4 |
| 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 | """ |
| 24 | from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest |
| 25 | from cmd_input import CmdInput |
| 26 | from queue import Empty |
| 27 | import os |
| 28 | import uuid |
| 29 | |
| 30 | |
| 31 | class BtCmdLineTest(BluetoothBaseTest): |
| 32 | target_mac_address = "" |
| 33 | |
| 34 | def __init__(self, controllers): |
| 35 | BluetoothBaseTest.__init__(self, controllers) |
| 36 | if not "target_mac_address" in self.user_params.keys(): |
| 37 | self.log.error( |
| 38 | "Missing mandatory user config \"target_mac_address\"!") |
| 39 | return False |
| 40 | self.target_mac_address = self.user_params["target_mac_address"].upper( |
| 41 | ) |
| 42 | |
| 43 | self.android_devices[0].droid.bluetoothSetLocalName("CMD LINE Test") |
| 44 | if len(self.android_devices) > 1: |
| 45 | #Setup for more complex testcases |
| 46 | if not "sim_conf_file" in self.user_params.keys(): |
| 47 | self.log.error( |
| 48 | "Missing mandatory user config \"sim_conf_file\"!") |
| 49 | return False |
| 50 | sim_conf_file = self.user_params["sim_conf_file"] |
| 51 | # If the sim_conf_file is not a full path, attempt to find it |
| 52 | # relative to the config file. |
| 53 | if not os.path.isfile(sim_conf_file): |
| 54 | sim_conf_file = os.path.join( |
| 55 | self.user_params[Config.key_config_path], sim_conf_file) |
| 56 | if not os.path.isfile(sim_conf_file): |
| 57 | log.error("Unable to load user config " + sim_conf_file + |
| 58 | " from test config file.") |
| 59 | return False |
| 60 | for ad in self.android_devices: |
| 61 | setup_droid_properties(self.log, ad, sim_conf_file) |
| 62 | music_path_str = "music_path" |
| 63 | android_music_path = "/sdcard/Music/" |
| 64 | if music_path_str not in self.user_params: |
| 65 | log.error("Need music for A2DP testcases") |
| 66 | return False |
| 67 | music_path = self.user_params[music_path_str] |
| 68 | self._add_music_to_primary_android_device(music_path, |
| 69 | android_music_path) |
| 70 | |
| 71 | def _add_music_to_primary_android_device(self, music_path, |
| 72 | android_music_path): |
| 73 | music_list = [] |
| 74 | for dirname, dirnames, filenames in os.walk(music_path): |
| 75 | for filename in filenames: |
| 76 | file = os.path.join(dirname, filename) |
| 77 | #TODO: Handle file paths with spaces |
| 78 | self.android_devices[0].adb.push("{} {}".format( |
| 79 | file, android_music_path)) |
| 80 | |
| 81 | def setup_class(self): |
| 82 | return True |
| 83 | |
| 84 | def test_pts_cmd_line_helper(self): |
| 85 | cmd_line = CmdInput() |
| 86 | cmd_line.setup_vars(self.android_devices, self.target_mac_address, |
| 87 | self.log) |
| 88 | cmd_line.cmdloop() |
| 89 | return True |