• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2#   Copyright 2021 - The Android Open Source Project
3#
4#   Licensed under the Apache License, Version 2.0 (the "License");
5#   you may not use this file except in compliance with the License.
6#   You may obtain a copy of the License at
7#
8#       http://www.apache.org/licenses/LICENSE-2.0
9#
10#   Unless required by applicable law or agreed to in writing, software
11#   distributed under the License is distributed on an "AS IS" BASIS,
12#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13#   See the License for the specific language governing permissions and
14#   limitations under the License.
15
16
17from acts import asserts
18from acts.controllers.openwrt_ap import MOBLY_CONTROLLER_CONFIG_NAME as OPENWRT
19from acts.test_decorators import test_tracker_info
20from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
21from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
22
23
24class MulticastDNSTest(WifiBaseTest):
25    """Verify Multicast DNS can work on Android devices."""
26
27    def setup_class(self):
28        """Setup Openwrt and unpack params for mDNS test."""
29        self.dut = self.android_devices[0]
30        req_params = []
31        opt_params = ["configure_OpenWrt", "wifi_network"]
32        self.unpack_userparams(req_params, opt_params)
33        if OPENWRT in self.user_params:
34            self.openwrt = self.access_points[0]
35            if hasattr(self, "configure_OpenWrt") and self.configure_OpenWrt == "skip":
36                self.dut.log.info("Skip configure Wifi interface due to config setup.")
37            else:
38                self.configure_openwrt_ap_and_start(wpa_network=True)
39                self.wifi_network = self.openwrt.get_wifi_network()
40
41    def on_fail(self, test_name, begin_time):
42        """Take bugreport if test failed."""
43        self.dut.take_bug_report(test_name, begin_time)
44
45    def teardown_test(self):
46        """Reset wifi settings after test case."""
47        wutils.reset_wifi(self.dut)
48
49    def verify_ping(self, hostname, expect_ping_pass=True):
50        """Verify if result of the ping as excepted.
51
52        Args:
53            hostname: ping address.
54            expect_ping_pass: excepted ping result is True or False.
55        Returns:
56            Boolean if ping result work as expected.
57        """
58        out = self.dut.adb.shell("ping -c 1 %s" % hostname)
59        result = ("100%" not in out) == expect_ping_pass
60        if not result:
61            self.dut.log.info(out)
62        return result
63
64    def test_mdns_query_ipv4_only(self):
65        """Verify mdns query work in ipv4 only network."""
66        self.openwrt.network_setting.disable_ipv6()
67        self.openwrt.network_setting.setup_mdns()
68        wutils.wifi_connect(self.dut, self.wifi_network)
69        asserts.assert_true(self.verify_ping("openwrt.local"),
70                            "Fail to ping openwrt.local.")
71
72    def test_mdns_query_ipv4_ipv6(self):
73        """Verify mdns query work in ipv4 & ipv6 network."""
74        self.openwrt.network_setting.enable_ipv6()
75        self.openwrt.network_setting.setup_mdns()
76        wutils.wifi_connect(self.dut, self.wifi_network)
77        asserts.assert_true(self.verify_ping("openwrt.local"),
78                            "Fail to ping openwrt.local.")
79
80