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_010/listen_test.cfg", 38 isdir=None) 39sa_listen_json_path = get_resource_path( 40 "resource/level/lifecycle_state_010/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_010(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] loaded 99 #清理日志 100 driver.shell('hilog -r') 101 # 开始保存日志 102 device_logger = DeviceLogger(driver).set_filter_string("Scheduler SA:1494") 103 device_logger.start_log(get_report_dir() + '//lifecycle_state_010_txt') 104 log_path = os.path.join(self.get_case_report_path(), "lifecycle_state_010_txt") 105 command = AsyncCommand(driver).set_output_file(log_path) 106 command.start_device_command("ondemand test") 107 time.sleep(130) 108 # 停止后台命令 109 command.stop() 110 # 停止日志 111 device_logger.stop_log() 112 # 断言 113 # 检查日志输出 114 countResult = Disk_drop_log.count_keys_disk_dropping_logs(self.get_case_report_path(), 115 "OnLoadSystemAbilitySuccesss systemAbilityId:1494") 116 assert countResult >= 23 117 device_logger.check_log("Scheduler SA:1494 loaded", EXCEPTION=True) 118 device_logger.check_log("Scheduler SA:1494 not loaded", EXCEPTION=True) 119 120 log_check_result = device_logger.check_log("Scheduler SA:1494 loaded", EXCEPTION=True) 121 Assert.equal(self, log_check_result1, True) 122 123 def teardown(self): 124 self.driver.System.execute_command("kill -9 `pidof listen_test`") 125 self.driver.Storage.remove_file("/system/lib/lib/liblisten_test.z.so") 126 self.driver.Storage.remove_file("/system/lib/lib/libtest_sa_proxy_cache.z.so") 127 self.driver.Storage.remove_file("/system/lib/lib/libtest_audio_ability.z.so") 128 self.driver.Storage.remove_file("/system/etc/init/listen_test.cfg") 129 self.driver.Storage.remove_file("/system/etc/init/listen_test.json") 130 self.driver.Storage.remove_file("/system/bin/ondemand") 131 self.log.info("done") 132