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 21from devicetest.utils.file.file_util import get_resource_path 22from hypium import UiExplore 23from hypium.action.host import host 24from hypium.action.os_hypium.device_logger import AsyncCommand 25 26 27sa_lib_test_path = get_resource_path( 28 "resource/SO_RESOURCE/liblisten_test.z.so", 29 isdir=None) 30 31sa_lib_ability_c_path = get_resource_path( 32 "resource/SO_RESOURCE/libtest_audio_ability.z.so", 33 isdir=None) 34 35sa_proxy_path = get_resource_path( 36 "resource/SO_RESOURCE/libtest_sa_proxy_cache.z.so", 37 isdir=None) 38 39sa_listen_cfg_path = get_resource_path( 40 "resource/level/lifecycle_state_024/listen_test.cfg", 41 isdir=None) 42 43sa_listen_json_path = get_resource_path( 44 "resource/level/lifecycle_state_024/listen_test.json", 45 isdir=None) 46 47sa_ondemand_path = get_resource_path( 48 "resource/SO_RESOURCE/ondemand", 49 isdir=None) 50 51sa_tool_path = get_resource_path( 52 "resource/SO_RESOURCE/TestTool", 53 isdir=None) 54 55 56class LifeCycle_State_024(TestCase): 57 58 def __init__(self, controllers): 59 sele.TAG = self.__class__.__name__ 60 TestCase.__init__(self, self.TAG, controllers) 61 self.tests = [ 62 "test_step" 63 ] 64 self.driver = UiExplore(self.driver1) 65 self.sn = self.driver1.device_sn 66 67 def setup(self): 68 driver = self.driver 69 host.shell("hdc -t {} shell kill -9 `pidof listen_test`".format(self.sn)) 70 # host.shell("hdc -t {} target mount".format(self.sn)) 71 # driver.Storage.push_file(local_path=sa_lib_test_path, device_path="/systemlib/lib/") 72 # host.shell("hdc -t {} shell chmod 644 /system/lib/lib/liblisten_test.z.so".format(self.sn)) 73 74 # driver.Storage.push_file(local_path=sa_proxy_path, device_path="/systemlib/lib/") 75 # host.shell("hdc -t {} shell chmod 644 /system/lib/lib/libtest_sa_proxy_cache.z.so".format(self.sn)) 76 77 # driver.Storage.push_file(local_path=sa_lib_ability_c_path, device_path="/systemlib/lib/") 78 # host.shell("hdc -t {} shell chmod 644 /system/lib/lib/libtest_audio_ability.z.so".format(self.sn)) 79 80 # driver.Storage.push_file(local_path=sa_listen_cfg_path, device_path="/system/etc/init/") 81 # host.shell("hdc -t {} shell chmod 644 /system/etc/init/listen_test.cfg".format(self.sn)) 82 83 # driver.Storage.push_file(local_path=sa_listen_json_path, device_path="/system/profile/") 84 # host.shell("hdc -t {} shell chmod 644 /system/profile/listen_test.json".format(self.sn)) 85 86 # driver.Storage.push_file(local_path=sa_ondemand_path, device_path="/systemlib/bin/") 87 # host.shell("hdc -t {} shell chmod 755 /system/bin/ondemand".format(self.sn)) 88 89 # driver.Storage.push_file(local_path=sa_tool_path, device_path="/systemlib/bin/") 90 # host.shell("hdc -t {} shell chmod 755 /system/bin/TestTool".format(self.sn)) 91 # driver.System.reboot() 92 93 def test_step(self): 94 driver = self.driver 95 # 用例同步 96 # 执行"ondemand test 24"命令, 执行测试程序 97 # 预期结果 98 # 控制台打印: 99 # GetSystemAbility result: success 100 result = driver.System.execute_command("ondemand test 24") 101 assert "GetSystemAbility systemAbilityId:1494 faild" in result 102 103 def teardown(self): 104 self.driver.System.execute_command("kill -9 `pidof listen_test`") 105 self.driver.Storage.remove_file("/system/lib/lib/liblisten_test.z.so") 106 self.driver.Storage.remove_file("/system/lib/lib/libtest_sa_proxy_cache.z.so") 107 self.driver.Storage.remove_file("/system/lib/lib/libtest_audio_ability.z.so") 108 self.driver.Storage.remove_file("/system/etc/init/listen_test.cfg") 109 self.driver.Storage.remove_file("/system/etc/init/listen_test.json") 110 self.driver.Storage.remove_file("/system/bin/ondemand") 111 self.log.info("done")