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 28 29def GetDirSize(dir_path): 30 if not os.path.exists(dir_path): 31 PrintToLog("\n\nERROR: %s, dir are not exist!!!\n" % dir_path) 32 PrintToLog("End of check, test failed!") 33 sys.exit(99) 34 size = 0 35 for root, dirs, files in os.walk(dir_path): 36 for name in files: 37 sz = os.path.getsize(os.path.join(root, name)) 38 print('{} : {}byte'.format(os.path.join(root, name), sz)) 39 size += sz 40 PrintToLog('total size: {:.2f}M'.format(size/1024/1024)) 41 return size 42 43 44def PrintToLog(str): 45 time = datetime.datetime.now() 46 str = "[{}] {}".format(time, str) 47 print(str) 48 with open(os.path.join(args.save_path, 'L0_mini_test.log'), 49 mode='a', 50 encoding='utf-8') as log_file: 51 console = sys.stdout 52 sys.stdout = log_file 53 print(str) 54 sys.stdout = console 55 log_file.close() 56 57 58def WriteToComPort(com_port, cmd): 59 len = com_port.write(cmd.encode('utf-8')) 60 print('{}'.format(len)) 61 return 62 63 64def ReadFromComPort(com_port, timeout): 65 time_start = datetime.datetime.now() 66 time_end = time_start 67 global com_output 68 com_output = '' 69 while (time_end - time_start).seconds < timeout: 70 com_output_once = '' 71 while com_port.inWaiting() > 0: 72 com_output_once += com_port.read(com_port.inWaiting()).decode('ISO-8859-1') 73 if com_output_once != '': 74 com_output += com_output_once 75 print('{}'.format(com_output_once), end='') 76 time_end = datetime.datetime.now() 77 return com_output 78 79 80if __name__ == "__main__": 81 parser = argparse.ArgumentParser(description='manual to this script') 82 parser.add_argument('--com_port', type=str, default='COM5') 83 parser.add_argument('--com_baudrate', type=int, default=115200) 84 parser.add_argument('--save_path', type=str, 85 default='D:\\DeviceTestTools\\screenshot') 86 parser.add_argument( 87 '--archive_path', 88 type=str, 89 default=r'Z:\workspace\ohos_L2\ohos\out\hispark_pegasus\hispark_pegasus_mini_system') 90 args = parser.parse_args() 91 92 com_port = serial.Serial(args.com_port, args.com_baudrate) 93 if com_port.isOpen(): 94 PrintToLog("{} is open successed".format(com_port)) 95 else: 96 PrintToLog("{} is open failed".format(com_port)) 97 PrintToLog("End of check, test failed!") 98 sys.exit(99) 99 100 read_com_thread = threading.Thread(target=ReadFromComPort, 101 args=(com_port, 10)) 102 read_com_thread.setDaemon(True) 103 print('read wait:') 104 read_com_thread.start() 105 time.sleep(1) 106 WriteToComPort(com_port, '\r\n\r\n') 107 WriteToComPort(com_port, 'AT+SYSINFO\r\n') 108 print('enter AT+SYSINFO') 109 time.sleep(3) 110 hivew_proc_find = re.findall( 111 'hiview,id=\d{1,3},status=\d{1,10},pri=\d{1,3},size=', com_output) 112 print(hivew_proc_find) 113 if type(hivew_proc_find) == list and len(hivew_proc_find) > 0: 114 PrintToLog('hivew_proc found') 115 else: 116 PrintToLog('hivew_proc not found') 117 PrintToLog("End of check, test failed!") 118 sys.exit(99) 119 120 target_file = os.path.normpath(os.path.join(args.archive_path, 121 "OHOS_image.bin")) 122 ret_size = os.path.getsize(target_file)/1024/1024 123 PrintToLog('Size of OHOS_image.bin : {:.2f}M'.format(ret_size)) 124 if ret_size > 1: 125 PrintToLog('ERROR: Size of OHOS_image.bin ({:.2f}M) is over the upper limit(1M)'.format(ret_size)) 126 target_dir = os.path.normpath(os.path.join(args.archive_path, "libs")) 127 GetDirSize(target_dir) 128 PrintToLog("End of check, test failed!") 129 sys.exit(99) 130 131 PrintToLog("End of check, test succeeded!") 132 sys.exit(0) 133