1#!/usr/bin/env python3
2#
3# Copyright (C) 2019 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"""
17This is a test to verify two or more Fuchsia devices don't have the same mac
18address.
19
20Setup:
21This test requires at least two fuchsia devices.
22"""
23
24import time
25
26from acts import signals
27from acts.base_test import BaseTestClass
28from acts.test_decorators import test_tracker_info
29from acts.test_utils.bt.bt_test_utils import generate_id_by_size
30
31
32class FuchsiaBtMacAddressTest(BaseTestClass):
33    scan_timeout_seconds = 10
34
35    def setup_class(self):
36        super().setup_class()
37
38        if len(self.fuchsia_devices) < 2:
39            raise signals.TestAbortAll("Need at least two Fuchsia devices")
40        for device in self.fuchsia_devices:
41            device.btc_lib.initBluetoothControl()
42
43    # TODO: add @test_tracker_info(uuid='')
44    def test_verify_different_mac_addresses(self):
45        """Verify that all connected Fuchsia devices have unique mac addresses.
46
47        Steps:
48        1. Get mac address from each device
49
50        Expected Result:
51        Verify duplicate mac addresses don't exist.
52
53        Returns:
54          signals.TestPass if no errors
55          signals.TestFailure if there are any errors during the test.
56
57        TAGS: BR/EDR, BT
58        Priority: 1
59        """
60        mac_addr_list = []
61        for device in self.fuchsia_devices:
62            mac_addr_list.append(
63                device.btc_lib.getActiveAdapterAddress().get("result"))
64        if len(mac_addr_list) != len(set(mac_addr_list)):
65            raise signals.TestFailure(
66                "Found duplicate mac addresses {}.".format(mac_addr_list))
67        raise signals.TestPass(
68            "Success: All Bluetooth Mac address unique: {}".format(
69                mac_addr_list))
70