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 time 19 20from devicetest.core.test_case import TestCase, get_report_dir 21from hypium import UiExplorer 22from hypium.action.host import host 23from hypium.action.os_hypium.checker import Assert 24from hypium.action.os_hypium.device_logger import DeviceLogger, AsyncCommand 25from devicetest.utils.file_util import get_resource_path 26 27sa_lib_test_path = get_resource_path( 28 "resource/SO_RESOURCE/liblisten_test.z.so", 29 isdir=None) 30sa_lib_ability_c_path = get_resource_path( 31 "resource/SO_RESOURCE/libtest_audio_ability.z.so", 32 isdir=None) 33sa_proxy_path = get_resource_path( 34 "resource/SO_RESOURCE/libtest_sa_proxy_cache.z.so", 35 isdir=None) 36sa_listen_cfg_path = get_resource_path( 37 "resource/level/lifecycle_state_008/listen_test.cfg", 38 isdir=None) 39sa_listen_json_path = get_resource_path( 40 "resource/level/lifecycle_state_008/listen_test.json", 41 isdir=None) 42sa_ondemand_path = get_resource_path( 43 "resource/SO_RESOURCE/ondemand", 44 isdir=None) 45sa_tool_path = get_resource_path( 46 "resource/SO_RESOURCE/TestTool", 47 isdir=None) 48 49class LifeCycle_State_008(TestCase): 50 51 def __init__(self, controllers): 52 sele.TAG = self.__class__.__name__ 53 TestCase.__init__(self, self.TAG, controllers) 54 self.tests = [ 55 "test_step" 56 ] 57 self.driver = UiExplore(self.driver1) 58 self.sn = self.driver1.device_sn 59 60 def setup(self): 61 driver = self.driver 62 host.shell("hdc -t {} shell kill -9 `pidof listen_test`".format(self.sn)) 63 # host.shell("hdc -t {} target mount".format(self.sn)) 64 # driver.Storage.push_file(local_path=sa_lib_test_path, device_path="/systemlib/lib/") 65 # host.shell("hdc -t {} shell chmod 644 /system/lib/lib/liblisten_test.z.so".format(self.sn)) 66 67 # driver.Storage.push_file(local_path=sa_proxy_path, device_path="/systemlib/lib/") 68 # host.shell("hdc -t {} shell chmod 644 /system/lib/lib/libtest_sa_proxy_cache.z.so".format(self.sn)) 69 70 # driver.Storage.push_file(local_path=sa_lib_ability_c_path, device_path="/systemlib/lib/") 71 # host.shell("hdc -t {} shell chmod 644 /system/lib/lib/libtest_audio_ability.z.so".format(self.sn)) 72 73 # driver.Storage.push_file(local_path=sa_listen_cfg_path, device_path="/system/etc/init/") 74 # host.shell("hdc -t {} shell chmod 644 /system/etc/init/listen_test.cfg".format(self.sn)) 75 76 # driver.Storage.push_file(local_path=sa_listen_json_path, device_path="/system/profile/") 77 # host.shell("hdc -t {} shell chmod 644 /system/profile/listen_test.json".format(self.sn)) 78 79 # driver.Storage.push_file(local_path=sa_ondemand_path, device_path="/systemlib/bin/") 80 # host.shell("hdc -t {} shell chmod 755 /system/bin/ondemand".format(self.sn)) 81 82 # driver.Storage.push_file(local_path=sa_tool_path, device_path="/systemlib/bin/") 83 # host.shell("hdc -t {} shell chmod 755 /system/bin/TestTool".format(self.sn)) 84 # driver.System.reboot() 85 86 def test_step(self): 87 driver = self.driver 88 # 用例步骤 89 # 1、执行push_bat脚本, 推入测试资源 90 # 2、执行"hdc shell"命令, 进入shell命令行 91 # 3、执行"ondemand"命令, 执行测试程序 92 # 4、输入"ondemand", 进入测试模式 93 # 5、输入任意字符后回车, 开始执行test case 94 # 6、再打开一个cmd用来查看hilog, 执行hilog | grep "SA Scheduler" 95 # 预期结果 96 # 控制台打印: OnLoadSystemAbilitySuccesss systemAbilityId:1494 97 # Hilog打印: 98 # [SA Scheduler][SA: 1494] save load event 99 # [SA Scheduler][process: listen_test] stopped 100 # [SA Scheduler][SA: 1497] loaded 101 #清理日志 102 driver.shell('hilog -r') 103 # 开始保存日志 104 device_logger = DeviceLogger(driver).set_filter_string("I C018") 105 device_logger.start_log(get_report_dir() + '//lifecycle_state_008_txt') 106 result = driver.System.execute_command("ondemand test 8") 107 assert "OnLoadSystemAbilitySuccesss systemAbilityId:1494" in result 108 # 停止日志 109 device_logger.stop_log() 110 # 检查日志输出 111 device_logger.check_log("Scheduler SA:1499 handle load failed event", EXCEPTION=True) 112 device_logger.check_log("Scheduler SA:1494 loaded", EXCEPTION=True) 113 114 def teardown(self): 115 self.driver.System.execute_command("kill -9 `pidof listen_test`") 116 # self.driver.Storage.remove_file("/system/lib/lib/liblisten_test.z.so") 117 # self.driver.Storage.remove_file("/system/lib/lib/libtest_sa_proxy_cache.z.so") 118 # self.driver.Storage.remove_file("/system/lib/lib/libtest_audio_ability.z.so") 119 # self.driver.Storage.remove_file("/system/etc/init/listen_test.cfg") 120 # self.driver.Storage.remove_file("/system/etc/init/listen_test.json") 121 # self.driver.Storage.remove_file("/system/bin/ondemand") 122 self.log.info("done") 123