1#!/usr/bin/env python3
2#-*- coding: utf-8 -*-
3
4# Copyright (c) 2024 Huawei Device Co., Ltd.
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
17
18import time
19from devicetest.core.test_case import TestCase, CheckPoint
20from hypium import UiDriver
21from tools.get_source_path import get_source_path
22from tools.push_remove_source import push_source, remove_source
23
24
25class case18_switch001(TestCase):
26
27    def __init__(self, configs):
28        self.TAG = self.__class__.__name__
29        TestCase.__init__(self, self.TAG, configs)
30        self.tests = [
31            "test_step"
32        ]
33        self.driver = UiDriver(self.device1)
34        self.sn = self.device1.device_sn
35        self.source_path = {}
36
37    def setup(self):
38        self.log.info("case18_switch001 start")
39        self.driver.Screen.wake_up()
40        self.driver.Wifi.disable()
41        need_source = {"cfg": True, "fwk": False, "listen_test": True, "audio_ability": False, "ondemand": True,
42                       "proxy": True, "para": False}
43        self.source_path = get_source_path(need_source=need_source, casename="level0/case18_switch001")
44        push_source(source_path=self.source_path, driver=self.driver, sn=self.sn)
45
46    def test_step(self):
47        driver = self.driver
48        result = driver.System.execute_command("hidumper -ls")
49        assert "1494" not in result
50
51        driver.Wifi.enable()
52        result = driver.System.execute_command("hidumper -ls")
53        max_wait_time = 10
54        wait_time = 0
55        while ("1494" not in result and wait_time <= max_wait_time):
56            wait_time += 1
57            time.sleep(1)
58            result = driver.System.execute_command("hidumper -ls")
59        CheckPoint("After turning on WiFi, 1494 was successfully loaded")
60        assert "1494" in result
61
62        driver.Wifi.disable()
63        time.sleep(20)
64        result = driver.System.execute_command("hidumper -ls")
65        max_wait_time = 5
66        wait_time = 0
67        while ("1494" in result and wait_time <= max_wait_time):
68            wait_time += 1
69            time.sleep(1)
70            result = driver.System.execute_command("hidumper -ls")
71        CheckPoint("After turning off WiFi, 1494 successfully unloaded")
72        assert "1494" not in result
73
74    def teardown(self):
75        remove_source(source_path=self.source_path, driver=self.driver, sn=self.sn)
76        self.log.info("case18_switch001 down")
77