1#!/usr/bin/env python3
2#-*- coding: utf-8 -*-
3
4# Copyright (c) 2024 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.path
18import time
19from devicetest.core.test_case import TestCase, Step, CheckPoint, get_report_dir
20from hypium import UiDriver
21import tools.disk_drop_log
22from tools.get_source_path import get_source_path
23from tools.push_remove_source import push_source, remove_source
24
25
26class case24_sub001(TestCase):
27
28    def __init__(self, configs):
29        self.TAG = self.__class__.__name__
30        TestCase.__init__(self, self.TAG, configs)
31        self.tests = [
32            "test_step"
33        ]
34        self.driver = UiDriver(self.device1)
35        self.sn = self.device1.device_sn
36        self.source_path = {}
37
38    def setup(self):
39        self.log.info("case24_sub001 start")
40        need_source = {"cfg": True, "fwk": True, "listen_test": True, "audio_ability": True, "ondemand": True,
41                       "proxy": True, "para": False}
42        self.source_path = get_source_path(need_source=need_source, casename="level0/case24_sub001")
43        push_source(source_path=self.source_path, driver=self.driver, sn=self.sn)
44
45    def test_step(self):
46        driver = self.driver
47        result = driver.System.execute_command("hidumper -ls")
48        max_wait_time = 5
49        wait_time = 0
50        while ("1494" not in result and wait_time <= max_wait_time):
51            wait_time += 1
52            time.sleep(1)
53            result = driver.System.execute_command("hidumper -ls")
54        CheckPoint("1494 is loaded after booting up")
55        assert "1494" in result
56
57        log_revice_path = os.path.join(self.get_case_report_path(), "disk_drop")
58        tools.disk_drop_log.pulling_disk_dropping_logs(log_revice_path, self.sn)
59        tools.disk_drop_log.parse_disk_dropping_logs(log_revice_path)
60        result = tools.disk_drop_log.check_disk_dropping_logs(log_revice_path,
61                                                              "OnAddSystemAbility systemAbilityId:1901 added!")
62        CheckPoint("The log contains 'ListenAbility: OnAddSystemAbility systemAbilityId:1901 added!'")
63        assert result is True
64        result = tools.disk_drop_log.check_disk_dropping_logs(log_revice_path,
65                                                              "OnAddSystemAbility systemAbilityId:4700 added!")
66        CheckPoint("The log contains 'ListenAbility: OnAddSystemAbility systemAbilityId:4700 added!'")
67        assert result is True
68
69    def teardown(self):
70        self.driver.Screen.close()
71        remove_source(source_path=self.source_path, driver=self.driver, sn=self.sn)
72        self.log.info("case24_sub001 down")
73