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
17import time
18from devicetest.core.test_case import TestCase, CheckPoint
19from hypium import UiDriver
20from tools.get_source_path import get_source_path
21from tools.push_remove_source import push_source, remove_source
22
23
24class case08_once003(TestCase):
25
26    def __init__(self, configs):
27        self.TAG = self.__class__.__name__
28        TestCase.__init__(self, self.TAG, configs)
29        self.tests = [
30            "test_step"
31        ]
32        self.driver = UiDriver(self.device1)
33        self.sn = self.device1.device_sn
34        self.source_path = {}
35
36    def setup(self):
37        self.log.info("case08_once003 start")
38        need_source = {"cfg": True, "fwk": False, "listen_test": True, "audio_ability": False, "ondemand": True,
39                       "proxy": True, "para": True}
40        self.source_path = get_source_path(need_source=need_source, casename="level0/case08_once003")
41        self.driver.System.execute_command("ondemand param true")
42        push_source(source_path=self.source_path, driver=self.driver, sn=self.sn, update_param=True)
43
44    def test_step(self):
45        driver = self.driver
46        driver.System.execute_command("ondemand param true")
47        max_wait_time = 5
48        wait_time = 0
49        result = driver.System.execute_command("hidumper -ls")
50        while ("1494" not in result and wait_time <= max_wait_time):
51            wait_time += 1
52            time.sleep(1)
53            result = driver.System.execute_command("hidumper -ls")
54        CheckPoint("The first 1494 was successfully loaded")
55        assert "1494" in result
56
57        driver.System.execute_command("ondemand param false")
58        time.sleep(20)
59        result = driver.System.execute_command("hidumper -ls")
60        max_wait_time = 5
61        wait_time = 0
62        while ("1494" in result and wait_time <= max_wait_time):
63            wait_time += 1
64            time.sleep(1)
65            result = driver.System.execute_command("hidumper -ls")
66        CheckPoint("The first 1494 was successfully unloaded")
67        assert "1494" not in result
68
69        driver.System.execute_command("ondemand param true")
70        result = driver.System.execute_command("hidumper -ls")
71        max_wait_time = 5
72        wait_time = 0
73        while ("1494" not in result and wait_time <= max_wait_time):
74            wait_time += 1
75            time.sleep(1)
76            result = driver.System.execute_command("hidumper -ls")
77        lastwait_time = wait_time
78        CheckPoint("The second 1494 was successfully loaded")
79        assert "1494" in result
80
81        driver.System.execute_command("ondemand param false")
82        time.sleep(20 + lastwait_time)
83        result = driver.System.execute_command("hidumper -ls")
84        CheckPoint("It only took effect once, and the second time 1494 failed to unload")
85        assert "1494" in result
86
87    def teardown(self):
88        remove_source(source_path=self.source_path, driver=self.driver, sn=self.sn)
89        self.log.info("case08_once003 down")
90