1#!/usr/bin/env python3
2#
3#   Copyright 2019 - 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
17from acts import signals
18
19from acts.base_test import BaseTestClass
20from acts.test_utils.abstract_devices.wlan_device import create_wlan_device
21
22
23class WlanInterfaceTest(BaseTestClass):
24    def setup_class(self):
25        dut = self.user_params.get('dut', None)
26        if dut:
27          if dut == 'fuchsia_devices':
28             self.dut = create_wlan_device(self.fuchsia_devices[0])
29          elif dut == 'android_devices':
30             self.dut = create_wlan_device(self.android_devices[0])
31          else:
32             raise ValueError('Invalid DUT specified in config. (%s)' % self.user_params['dut'])
33        else:
34            # Default is an Fuchsia device
35            self.dut = create_wlan_device(self.fuchsia_devices[0])
36
37    def test_destroy_iface(self):
38        """Test that we don't error out when destroying the WLAN interface.
39
40        Steps:
41        1. Find a wlan interface
42        2. Destroy it
43
44        Expected Result:
45        Verify there are no errors in destroying the wlan interface.
46
47        Returns:
48          signals.TestPass if no errors
49          signals.TestFailure if there are any errors during the test.
50
51        TAGS: WLAN
52        Priority: 1
53        """
54        wlan_interfaces = self.dut.get_wlan_interface_id_list()
55        if len(wlan_interfaces) < 1:
56            raise signals.TestFailure("Not enough wlan interfaces for test")
57        if not self.dut.destroy_wlan_interface(wlan_interfaces[0]):
58            raise signals.TestFailure("Failed to destroy WLAN interface")
59        raise signals.TestPass("Success")
60