1#!/usr/bin/env python3 2# 3# Copyright 2020 - 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 17import time 18 19from acts import asserts 20from cert.gd_base_test_facade_only import GdFacadeOnlyBaseTestClass 21from google.protobuf import empty_pb2 as empty_proto 22from facade import rootservice_pb2 as facade_rootservice 23from hci.facade import controller_facade_pb2 as controller_facade 24 25 26class ControllerTest(GdFacadeOnlyBaseTestClass): 27 28 def setup_test(self): 29 self.device_under_test.rootservice.StartStack( 30 facade_rootservice.StartStackRequest( 31 module_under_test=facade_rootservice.BluetoothModule.Value( 32 'HCI_INTERFACES'),)) 33 self.cert_device.rootservice.StartStack( 34 facade_rootservice.StartStackRequest( 35 module_under_test=facade_rootservice.BluetoothModule.Value( 36 'HCI_INTERFACES'),)) 37 38 self.device_under_test.wait_channel_ready() 39 self.cert_device.wait_channel_ready() 40 41 def teardown_test(self): 42 self.device_under_test.rootservice.StopStack( 43 facade_rootservice.StopStackRequest()) 44 self.cert_device.rootservice.StopStack( 45 facade_rootservice.StopStackRequest()) 46 47 def test_get_addresses(self): 48 cert_address_response = self.cert_device.hci_controller.GetMacAddress( 49 empty_proto.Empty()) 50 dut_address_response = self.device_under_test.hci_controller.GetMacAddress( 51 empty_proto.Empty()) 52 asserts.assert_true( 53 cert_address_response.address != dut_address_response.address, 54 msg="Expected cert and dut address to be different %s" % 55 cert_address_response.address) 56 time.sleep(1) # This shouldn't be needed b/149120542 57 58 def test_get_local_extended_features(self): 59 request = controller_facade.PageNumberMsg() 60 request.page_number = 1 61 dut_feature_response1 = self.device_under_test.hci_controller.GetLocalExtendedFeatures( 62 request) 63 request0 = controller_facade.PageNumberMsg() 64 request0.page_number = 0 65 dut_feature_response0 = self.device_under_test.hci_controller.GetLocalExtendedFeatures( 66 request0) 67 asserts.assert_true( 68 dut_feature_response1.page != dut_feature_response0.page, 69 msg="Expected cert dut feature pages to be different %d" % 70 dut_feature_response1.page) 71 72 def test_write_local_name(self): 73 self.device_under_test.hci_controller.WriteLocalName( 74 controller_facade.NameMsg(name=b'ImTheDUT')) 75 self.cert_device.hci_controller.WriteLocalName( 76 controller_facade.NameMsg(name=b'ImTheCert')) 77 cert_name_msg = self.cert_device.hci_controller.GetLocalName( 78 empty_proto.Empty()).name 79 dut_name_msg = self.device_under_test.hci_controller.GetLocalName( 80 empty_proto.Empty()).name 81 asserts.assert_true( 82 dut_name_msg == b'ImTheDUT', 83 msg="unexpected dut name %s" % dut_name_msg) 84 asserts.assert_true( 85 cert_name_msg == b'ImTheCert', 86 msg="unexpected cert name %s" % cert_name_msg) 87