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.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.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        self.dut.droid.wakeLockAcquireBright()
64        self.dut.droid.wakeUpNow()
65
66    def teardown_test(self):
67        self.dut.droid.wakeLockRelease()
68        self.dut.droid.goToSleepNow()
69        wutils.reset_wifi(self.dut)
70
71
72    def on_fail(self, test_name, begin_time):
73        self.dut.take_bug_report(test_name, begin_time)
74        self.dut.cat_adb_log(test_name, begin_time)
75
76    def teardown_class(self):
77        if "AccessPoint" in self.user_params:
78            del self.user_params["open_network"]
79
80    """Tests"""
81
82    @test_tracker_info(uuid="d6f1661b-6732-4939-8c28-f20917774ec0")
83    def test_ringbuffers_are_dumped_during_lsdebug(self):
84        """Steps:
85        1. Connect to a open network.
86        2. Delete old files under data/vendor/tombstones/wifi
87        3. Call lshal debug on wifi hal component
88        4. Verify that files are created under data/vender/tombstones/wifi
89        """
90        wutils.connect_to_wifi_network(self.dut, self.open_network)
91        time.sleep(DEFAULT_WAIT_TIME)
92        self.dut.adb.shell("rm data/vendor/tombstones/wifi/*")
93        try:
94            self.dut.adb.shell("lshal debug android.hardware.wifi@1.2::IWifi")
95        except UnicodeDecodeError:
96            """ Gets this error because adb.shell trys to parse the output to a string
97            but ringbuffer dumps should already be generated """
98            self.log.info("Unicode decode error occurred, but this is ok")
99        file_count_plus_one = self.dut.adb.shell("ls -l data/vendor/tombstones/wifi | wc -l")
100        if int(file_count_plus_one) <= 1:
101            raise signals.TestFailure("Failed to create ringbuffer debug files.")