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 18 19 20 21 22#!/usr/bin/env python3 23#-*- coding: utf-8 -*- 24 25# Copyright (c) 2025 Huawei Device Co., Ltd. 26# Licensed under the Apache License, Version 2.0 (the "License"); 27# you may not use this file except in compliance with the License. 28# You may obtain a copy of the License at 29# 30# http://www.apache.org/licenses/LICENSE-2.0 31# 32# Unless required by applicable law or agreed to in writing, software 33# distributed under the License is distributed on an "AS IS" BASIS, 34# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 35# See the License for the specific language governing permissions and 36# limitations under the License. 37 38import time 39 40from hypium import UiExplore 41from hypium.action.host import host 42from hypium.action.os_hypium.device_logger import DeviceLogger 43from devicetest.core.test_case import TestCase, CheckPoint, get_report_dir 44from devicetest.utils.file.file_util import get_resource_path 45 46sa_lib_test_path = get_resource_path( 47 "resource/SO_RESOURCE/liblisten_test.z.so", 48 isdir=None) 49 50sa_lib_ability_c_path = get_resource_path( 51 "resource/SO_RESOURCE/libtest_audio_ability.z.so", 52 isdir=None) 53 54sa_proxy_path = get_resource_path( 55 "resource/SO_RESOURCE/libtest_sa_proxy_cache.z.so", 56 isdir=None) 57 58sa_listen_cfg_path = get_resource_path( 59 "resource/level/lifecycle_state_026/listen_test.cfg", 60 isdir=None) 61 62sa_listen_json_path = get_resource_path( 63 "resource/level/lifecycle_state_026/listen_test.json", 64 isdir=None) 65 66sa_ondemand_path = get_resource_path( 67 "resource/SO_RESOURCE/ondemand", 68 isdir=None) 69 70sa_tool_path = get_resource_path( 71 "resource/SO_RESOURCE/TestTool", 72 isdir=None) 73 74sa_samgr_path = get_resource_path( 75 "resource/level/lifecycle/lifecycle_state_026/samgr.para", 76 isdir=None) 77 78sa_samgr_dac_path = get_resource_path( 79 "resource/level/lifecycle/lifecycle_state_026/samgr.para.dac", 80 isdir=None) 81 82sa_para_origin = get_resource_path( 83 "resource/origin_file/samgr.para", isdir=None) 84 85sa_para_dac_origin = get_resource_path( 86 "resource/origin_file/samgr.para.dac", isdir=None) 87 88class LifeCycle_State_026(TestCase): 89 90 def __init__(self, controllers): 91 sele.TAG = self.__class__.__name__ 92 TestCase.__init__(self, self.TAG, controllers) 93 self.tests = [ 94 "test_step" 95 ] 96 self.driver = UiExplore(self.driver1) 97 self.sn = self.driver1.device_sn 98 99 def setup(self): 100 driver = self.driver 101 host.shell("hdc -t {} shell kill -9 `pidof listen_test`".format(self.sn)) 102 # host.shell("hdc -t {} target mount".format(self.sn)) 103 # driver.Storage.push_file(local_path=sa_lib_test_path, device_path="/systemlib/lib/") 104 # host.shell("hdc -t {} shell chmod 644 /system/lib/lib/liblisten_test.z.so".format(self.sn)) 105 106 # driver.Storage.push_file(local_path=sa_proxy_path, device_path="/systemlib/lib/") 107 # host.shell("hdc -t {} shell chmod 644 /system/lib/lib/libtest_sa_proxy_cache.z.so".format(self.sn)) 108 109 # driver.Storage.push_file(local_path=sa_lib_ability_c_path, device_path="/systemlib/lib/") 110 # host.shell("hdc -t {} shell chmod 644 /system/lib/lib/libtest_audio_ability.z.so".format(self.sn)) 111 112 # driver.Storage.push_file(local_path=sa_listen_cfg_path, device_path="/system/etc/init/") 113 # host.shell("hdc -t {} shell chmod 644 /system/etc/init/listen_test.cfg".format(self.sn)) 114 115 # driver.Storage.push_file(local_path=sa_listen_json_path, device_path="/system/profile/") 116 # host.shell("hdc -t {} shell chmod 644 /system/profile/listen_test.json".format(self.sn)) 117 118 # driver.Storage.push_file(local_path=sa_ondemand_path, device_path="/systemlib/bin/") 119 # host.shell("hdc -t {} shell chmod 755 /system/bin/ondemand".format(self.sn)) 120 121 # driver.Storage.push_file(local_path=sa_tool_path, device_path="/systemlib/bin/") 122 # host.shell("hdc -t {} shell chmod 755 /system/bin/TestTool".format(self.sn)) 123 124 # driver.Storage.push_file(local_path=sa_samgr_path, device_path="/systemlib/etc/param") 125 # host.shell("hdc -t {} shell chmod 755 /system/etc/param/samgr.para".format(self.sn)) 126 127 # driver.Storage.push_file(local_path=sa_samgr_dac_path, device_path="/systemlib/etc/param") 128 # host.shell("hdc -t {} shell chmod 755 /system/etc/param/samgr.para.dac".format(self.sn)) 129 # driver.System.reboot() 130 131 def test_step(self): 132 driver = self.driver 133 # 用例同步 134 # 执行"ondemand test 24"命令, 执行测试程序 135 # 预期结果 136 # 控制台打印: 137 # GetSystemAbility result: success 138 result = driver.System.execute_command("ondemand test 26") 139 assert "GetSystemAbility systemAbilityId:1494 faild" in result 140 # 1、打开日志目录 141 # 2、关闭wifi (20s后卸载) 142 # 3、等待5s, hidumper -ls查看1494存在 143 # 4、打开wifi出发加载, 移除延时卸载 144 # 5、等待15s后hidumper -ls查看1494是否存在 145 # 6、停止日志落盘, 查看Scheduler SA:1494 rm delay unlaod event 146 # 147 # driver = selef.driver 148 #device_logger = DeviceLogger(driver).set_filter_string("Scheduler") 149 #device_logger.start_log(get_report_dir() + '//lifecycle_state_026.txt') 150 # 打开WiFi 151 #driver.wifi.enable() 152 #time.sleep(10) 153 # #关闭WiFi 154 #driver.wifi.disable() 155 #time.sleep(5) 156 # #打开WiFi 157 #driver.wifi.enable() 158 #time.sleep(15) 159 #device_logger.stop_log() 160 #log_check_result = device_logger.check_log("Scheduler SA:1494 rm delay unlaod event", EXCEPTION=False) 161 #assert log_check_result is True 162 #result = driver.System.execute_command("hidumper -ls") 163 #assert "1494" in result 164 165 def teardown(self): 166 self.driver.System.execute_command("kill -9 `pidof listen_test`") 167 self.driver.Storage.remove_file("/system/lib/lib/liblisten_test.z.so") 168 self.driver.Storage.remove_file("/system/lib/lib/libtest_sa_proxy_cache.z.so") 169 self.driver.Storage.remove_file("/system/lib/lib/libtest_audio_ability.z.so") 170 self.driver.Storage.remove_file("/system/etc/init/listen_test.cfg") 171 self.driver.Storage.remove_file("/system/etc/init/listen_test.json") 172 self.driver.Storage.remove_file("/system/bin/ondemand") 173 self.driver.Storage.remove_file("/system/etc/param/samgr.para") 174 self.driver.Storage.remove_file("/system/etc/param/samgr.para.dac") 175 self.driver.Storage.push_file(local_path=sa_para_origin, device_path="/systemlib/etc/param") 176 self.driver.Storage.push_file(local_path=sa_para_dac_origin, device_path="/systemlib/etc/param") 177 self.log.info("清理动作: 关闭设置") 178 179