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