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