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