1# -*- coding: utf-8 -*- 2# Copyright (c) 2022 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15from ast import parse 16import json 17import sys 18import os 19import time 20import argparse 21import re 22import subprocess 23import shlex 24import datetime 25import serial 26import threading 27 28def GetDirSize(dir_path): 29 if not os.path.exists(dir_path): 30 PrintToLog("\n\nERROR: %s, dir are not exist!!!\n" % dir_path) 31 PrintToLog("End of check, test failed!") 32 sys.exit(99) 33 size = 0 34 for root, dirs, files in os.walk(dir_path): 35 for name in files: 36 sz = os.path.getsize(os.path.join(root, name)) 37 print('{} : {}byte'.format(os.path.join(root, name), sz)) 38 size += sz 39 PrintToLog('total size: {:.2f}M'.format(size/1024/1024)) 40 return size 41 42def PrintToLog(str): 43 time = datetime.datetime.now() 44 str = "[{}] {}".format(time, str) 45 print(str) 46 with open(os.path.join(args.save_path, 'L0_mini_test.log'), mode='a', encoding='utf-8') as log_file: 47 console = sys.stdout 48 sys.stdout = log_file 49 print(str) 50 sys.stdout = console 51 log_file.close() 52 53def WriteToComPort(com_port, cmd): 54 len = com_port.write(cmd.encode('utf-8')) 55 print('{}'.format(len)) 56 return 57 58def ReadFromComPort(com_port, timeout): 59 time_start = datetime.datetime.now() 60 time_end = time_start 61 global com_output 62 com_output = '' 63 while (time_end - time_start).seconds < timeout: 64 com_output_once = '' 65 while com_port.inWaiting() > 0: 66 com_output_once += com_port.read(com_port.inWaiting()).decode() 67 if com_output_once != '': 68 com_output += com_output_once 69 print('{}'.format(com_output_once), end='') 70 time_end = datetime.datetime.now() 71 return com_output 72 73if __name__ == "__main__": 74 parser = argparse.ArgumentParser(description='manual to this script') 75 parser.add_argument('--com_port', type=str, default = 'COM5') 76 parser.add_argument('--com_baudrate', type=int, default = 115200) 77 parser.add_argument('--save_path', type=str, default = 'D:\\DeviceTestTools\\screenshot') 78 parser.add_argument('--archive_path', type=str, default = 'Z:\workspace\ohos_L2\ohos\out\hispark_pegasus\hispark_pegasus_mini_system') 79 args = parser.parse_args() 80 81 com_port = serial.Serial(args.com_port, args.com_baudrate) 82 if com_port.isOpen(): 83 PrintToLog("{} is open successed".format(com_port)) 84 else: 85 PrintToLog("{} is open failed".format(com_port)) 86 PrintToLog("End of check, test failed!") 87 sys.exit(99) 88 89 read_com_thread = threading.Thread(target=ReadFromComPort, args=(com_port, 10)) 90 read_com_thread.setDaemon(True) 91 print('read wait:') 92 read_com_thread.start() 93 time.sleep(1) 94 WriteToComPort(com_port, '\r\n\r\n') 95 WriteToComPort(com_port, 'AT+SYSINFO\r\n') 96 print('enter AT+SYSINFO') 97 time.sleep(3) 98 hivew_proc_find = re.findall('hiview,id=\d{1,3},status=\d{1,10},pri=\d{1,3},size=', com_output) 99 print(hivew_proc_find) 100 if type(hivew_proc_find) == list and len(hivew_proc_find) > 0: 101 PrintToLog('hivew_proc found') 102 else: 103 PrintToLog('hivew_proc not found') 104 PrintToLog("End of check, test failed!") 105 sys.exit(99) 106 107 target_file = os.path.normpath(os.path.join(args.archive_path, "OHOS_image.bin")) 108 ret_size = os.path.getsize(target_file)/1024/1024 109 PrintToLog('Size of OHOS_image.bin : {:.2f}M'.format(ret_size)) 110 if ret_size > 1: 111 PrintToLog('ERROR: Size of OHOS_image.bin ({:.2f}M) is over the upper limit(1M)'.format(ret_size)) 112 target_dir = os.path.normpath(os.path.join(args.archive_path, "libs")) 113 GetDirSize(target_dir) 114 PrintToLog("End of check, test failed!") 115 sys.exit(99) 116 117 PrintToLog("End of check, test succeeded!") 118 sys.exit(0) 119 120