1#!/usr/bin/env python3
2#
3# Copyright (C) 2018 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 testing WiFi recovery after device reboot
18
19"""
20from acts.base_test import BaseTestClass
21
22import os
23import uuid
24
25from acts import asserts
26from acts.controllers.ap_lib import hostapd_constants
27from acts.test_utils.abstract_devices.utils_lib.wlan_utils import is_connected
28from acts.test_utils.abstract_devices.utils_lib.wlan_utils import setup_ap_and_associate
29from acts.test_utils.abstract_devices.utils_lib.wlan_utils import disconnect
30from acts.test_utils.abstract_devices.wlan_device import create_wlan_device
31from acts.test_utils.fuchsia import utils
32from acts.test_utils.tel.tel_test_utils import setup_droid_properties
33from acts.utils import rand_ascii_str
34
35class RebootStressTest(BaseTestClass):
36    # Default number of test iterations here.
37    # Override using parameter in config file.
38    # Eg: "reboot_stress_test_iterations": "10"
39    num_of_iterations = 3
40
41    def setup_class(self):
42        super().setup_class()
43        self.ssid = rand_ascii_str(10)
44        self.fd = self.fuchsia_devices[0]
45        self.wlan_device = create_wlan_device(self.fd)
46        self.ap = self.access_points[0]
47        self.num_of_iterations = int(
48            self.user_params.get("reboot_stress_test_iterations",
49                                 self.num_of_iterations))
50
51        setup_ap_and_associate(
52            access_point=self.ap,
53            client=self.wlan_device,
54            profile_name='whirlwind',
55            channel=hostapd_constants.AP_DEFAULT_CHANNEL_2G,
56            ssid=self.ssid)
57
58    def teardown_test(self):
59        disconnect(self.wlan_device)
60        self.wlan_device.reset_wifi()
61        self.ap.stop_all_aps()
62
63    def test_reboot_stress(self):
64        for x in range(0, self.num_of_iterations):
65            # Reboot device
66            self.fd.reboot()
67
68            # Did we connect back to WiFi?
69            asserts.assert_true(
70                is_connected(self.wlan_device), 'Failed to connect.')
71        return True
72