• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 time
18from devicetest.core.test_case import TestCase, CheckPoint
19from hypium import UiDriver
20import subprocess
21import shlex
22
23
24def run_command_with_timeout(command, timeout):
25    proc = subprocess.Popen(shlex.split(command))
26    start_time = time.monotonic()
27    while proc.poll() is None:
28        time.sleep(0.1)
29        if time.monotonic() - start_time > timeout:
30            proc.kill()
31            return -1
32    return proc.returncode
33
34
35class case26_init001(TestCase):
36
37    def __init__(self, configs):
38        self.TAG = self.__class__.__name__
39        TestCase.__init__(self, self.TAG, configs)
40        self.tests = [
41            "test_step"
42        ]
43        self.driver = UiDriver(self.device1)
44
45    def setup(self):
46        self.log.info("case26_init001 start")
47
48    def test_step(self):
49        driver = self.driver
50        CheckPoint("First kill samgr, enter fastboot or restart")
51        result = driver.System.get_pid("samgr")
52        assert result is not None
53        time.sleep(1)
54        driver.shell("kill -9 `pidof samgr`")
55        command = "fastboot reboot"
56        timeout = 3
57        current_number = 0
58        max_number = 10
59        return_code = -1
60        while current_number < max_number and return_code == -1:
61            return_code = run_command_with_timeout(command, timeout)
62            current_number += 1
63        if return_code == 0:
64            time.sleep(30)
65
66        CheckPoint("Second kill samgr, enter fastboot or restart")
67        result = driver.System.get_pid("samgr")
68        assert result is not None
69        driver.shell("kill -9 `pidof samgr`")
70        current_number = 0
71        return_code = -1
72        while current_number < max_number and return_code == -1:
73            return_code = run_command_with_timeout(command, timeout)
74            current_number += 1
75        if return_code == 0:
76            time.sleep(30)
77
78    def teardown(self):
79        self.log.info("case26_init001 done")
80