1#!/usr/bin/env python3
2#
3# Copyright (C) 2020 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"""
17Script for verifying that we can invoke methods of the WlanFacade.
18
19"""
20from acts.base_test import BaseTestClass
21from acts import asserts, signals
22
23
24class WlanFacadeTest(BaseTestClass):
25    def setup_class(self):
26        super().setup_class()
27        if len(self.fuchsia_devices) < 1:
28            raise signals.TestAbortClass(
29                "Sorry, please try verifying FuchsiaDevice is in your "
30                "config file and try again.")
31
32    def on_fail(self, test_name, begin_time):
33        for fd in self.fuchsia_devices:
34            try:
35                fd.take_bug_report(test_name, begin_time)
36                fd.get_log(test_name, begin_time)
37            except Exception:
38                pass
39
40            try:
41                if fd.device.hard_reboot_on_fail:
42                    fd.hard_power_cycle(self.pdu_devices)
43            except AttributeError:
44                pass
45
46    def test_get_phy_id_list(self):
47        result = self.fuchsia_devices[0].wlan_lib.wlanPhyIdList()
48        error = result['error']
49        asserts.assert_true(error is None, error)
50
51        self.log.info('Got Phy IDs %s' % result['result'])
52        return True
53
54    def test_get_country(self):
55        wlan_lib = self.fuchsia_devices[0].wlan_lib
56
57        result = wlan_lib.wlanPhyIdList()
58        error = result['error']
59        asserts.assert_true(error is None, error)
60        phy_id = result['result'][0]
61
62        result = wlan_lib.wlanGetCountry(phy_id)
63        error = result['error']
64        asserts.assert_true(error is None, error)
65
66        country_bytes = result['result']
67        country_string = str(array.array('b', country_bytes),
68                             encoding='us-ascii')
69        self.log.info('Got country %s (%s)', country_string, country_bytes)
70        return True
71