1#!/usr/bin/env python3 2# coding=utf-8 3 4# 5# Copyright (c) 2020-2021 Huawei Device Co., Ltd. 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18from utils import * 19 20DeviceKey = "1501003847544634520655ef9320c795" 21hdcPath = "D:\\tools\\hdc\\hdc_std.exe" 22 23 24def rebootTest(): 25 print("------------------------TEST START---------------------------") 26 rebootLoop = 100 27 rebootedTime = 1 28 rebootWaitTime = 60 29 rebootMaxWaitTime = 300 30 start = datetime.datetime.now() 31 now = datetime.datetime.now() 32 abilitySuccess = "start ability successfully" 33 while rebootedTime < rebootLoop: 34 cmdRet = exec_cmd(hdcPath + " list targets", waitOut=True) 35 print("cmdRet is " + str(cmdRet)) 36 if str(cmdRet).find(DeviceKey) != -1: 37 cmdRet = exec_cmd(hdcPath + " -t " + DeviceKey + " shell " + 38 "aa start -d 123456 -a com.ohos.photos.MainAbility -b com.ohos.photos", waitOut=True) 39 print("cmdRet is " + str(cmdRet)) 40 if str(cmdRet).find(abilitySuccess) != -1: 41 print("Current Time is:" + str(datetime.datetime.now())) 42 print("Will reboot round " + str(rebootedTime) + ", total time is " + str(rebootLoop)) 43 cmdRet = exec_cmd(hdcPath + " -t " + DeviceKey + " shell reboot") 44 rebootedTime = rebootedTime + 1 45 start = datetime.datetime.now() 46 time.sleep(rebootWaitTime) 47 else: 48 print("The device " + DeviceKey + "can not start APP after reboot") 49 print("The test will stop.") 50 raise "The device " + DeviceKey + "can not start APP after reboot" 51 else: 52 now = datetime.datetime.now() 53 if (now - start).seconds > int(rebootMaxWaitTime): 54 print("The device " + DeviceKey + "is not ready after reboot for 300 seconds.") 55 print("The test will stop.") 56 raise "The device " + DeviceKey + "is not ready after reboot for 300 seconds." 57 58 59if __name__ == "__main__": 60 rebootTest() 61