1#!/usr/bin/env python3
2#
3#   Copyright 2020 - The Android secure 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"""
17Test to verify that a DUT's client interface's status can be queried.
18"""
19
20from acts import signals
21from acts.base_test import BaseTestClass
22
23
24class WlanStatusTest(BaseTestClass):
25    """WLAN status test class.
26
27    Test Bed Requirements:
28    * One or more Fuchsia devices with WLAN client capabilities.
29    """
30
31    def setup_class(self):
32        super().setup_class()
33        for fd in self.fuchsia_devices:
34            fd.wlan_policy_lib.wlanCreateClientController()
35
36    def test_wlan_stopped_client_status(self):
37        """Queries WLAN status on DUTs with no WLAN ifaces.
38
39        Tests that DUTs without WLAN interfaces have empty results and return
40        an error when queried for status.
41        """
42        for fd in self.fuchsia_devices:
43            fd.wlan_policy_lib.wlanStopClientConnections()
44
45            status = fd.wlan_lib.wlanStatus()
46            self.log.debug(status)
47            if not status["error"] or status["result"]:
48                raise signals.TestFailure(
49                    "DUT's WLAN client status should be empty")
50
51        raise signals.TestPass("Success")
52
53    def test_wlan_started_client_status(self):
54        """Queries WLAN status on DUTs with WLAN ifaces.
55
56        Tests that, once WLAN client interfaces have been created, each one
57        returns a result and that none of them return errors when queried for
58        status.
59        """
60        for fd in self.fuchsia_devices:
61            fd.wlan_policy_lib.wlanStartClientConnections()
62
63            status = fd.wlan_lib.wlanStatus()
64            self.log.debug(status)
65            if status["error"] or not status["result"]:
66                raise signals.TestFailure(
67                    "DUT's WLAN client status should be populated")
68
69        raise signals.TestPass("Success")
70