1#!/usr/bin/env python3.4
2#
3#   Copyright 2018 - 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 itertools
18import pprint
19import queue
20import time
21
22import acts.base_test
23import acts.signals as signals
24import acts_contrib.test_utils.wifi.wifi_test_utils as wutils
25import acts.utils
26
27from acts import asserts
28from acts.test_decorators import test_tracker_info
29from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
30
31WifiEnums = wutils.WifiEnums
32
33DEFAULT_WAIT_TIME = 2
34
35
36class WifiDiagnosticsTest(WifiBaseTest):
37    """
38    Test Bed Requirement:
39    * One Android device
40    * An open Wi-Fi network.
41    * Verbose logging is on.
42    """
43
44    def setup_class(self):
45        super().setup_class()
46
47        self.dut = self.android_devices[0]
48        wutils.wifi_test_device_init(self.dut)
49        req_params = []
50        opt_param = ["open_network"]
51        self.unpack_userparams(
52            req_param_names=req_params, opt_param_names=opt_param)
53
54        if "AccessPoint" in self.user_params:
55            self.legacy_configure_ap_and_start()
56        wutils.wifi_toggle_state(self.dut, True)
57        asserts.assert_true(
58            len(self.open_network) > 0,
59            "Need at least one open network.")
60        self.open_network = self.open_network[0]["2g"]
61
62    def setup_test(self):
63        super().setup_test()
64        self.dut.droid.wakeLockAcquireBright()
65        self.dut.droid.wakeUpNow()
66
67    def teardown_test(self):
68        super().teardown_test()
69        self.dut.droid.wakeLockRelease()
70        self.dut.droid.goToSleepNow()
71        wutils.reset_wifi(self.dut)
72
73    def teardown_class(self):
74        if "AccessPoint" in self.user_params:
75            del self.user_params["open_network"]
76
77    """Tests"""
78
79    @test_tracker_info(uuid="d6f1661b-6732-4939-8c28-f20917774ec0")
80    def test_ringbuffers_are_dumped_during_lsdebug(self):
81        """Steps:
82        1. Connect to a open network.
83        2. Delete old files under data/vendor/tombstones/wifi
84        3. Call lshal debug on wifi hal component
85        4. Verify that files are created under data/vender/tombstones/wifi
86        """
87        wutils.connect_to_wifi_network(self.dut, self.open_network)
88        time.sleep(DEFAULT_WAIT_TIME)
89        self.dut.adb.shell("rm data/vendor/tombstones/wifi/*")
90        try:
91            self.dut.adb.shell("lshal debug android.hardware.wifi@1.2::IWifi")
92        except UnicodeDecodeError:
93            """ Gets this error because adb.shell trys to parse the output to a string
94            but ringbuffer dumps should already be generated """
95            self.log.info("Unicode decode error occurred, but this is ok")
96        file_count_plus_one = self.dut.adb.shell("ls -l data/vendor/tombstones/wifi | wc -l")
97        if int(file_count_plus_one) <= 1:
98            raise signals.TestFailure("Failed to create ringbuffer debug files.")