• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    #print((time_end - time_start).seconds)
62    global com_output
63    com_output = ''
64    while (time_end - time_start).seconds < timeout:
65        com_output_once = ''
66        while com_port.inWaiting() > 0:
67            com_output_once += com_port.read(com_port.inWaiting()).decode()
68        if com_output_once != '':
69            com_output += com_output_once
70            print('{}'.format(com_output_once), end='')
71        time_end = datetime.datetime.now()
72    return com_output
73
74if __name__ == "__main__":
75    parser = argparse.ArgumentParser(description='manual to this script')
76    parser.add_argument('--com_port', type=str, default = 'COM5')
77    parser.add_argument('--com_baudrate', type=int, default = 115200)
78    parser.add_argument('--save_path', type=str, default = 'D:\\DeviceTestTools\\screenshot')
79    parser.add_argument('--archive_path', type=str, default = 'Z:\workspace\ohos_L2\ohos\out\hispark_pegasus\hispark_pegasus_mini_system')
80    args = parser.parse_args()
81
82    com_port = serial.Serial(args.com_port, args.com_baudrate)
83    if com_port.isOpen():
84        PrintToLog("{} is open successed".format(com_port))
85    else:
86        PrintToLog("{} is open failed".format(com_port))
87        PrintToLog("End of check, test failed!")
88        sys.exit(99)
89
90    read_com_thread = threading.Thread(target=ReadFromComPort, args=(com_port, 10))
91    read_com_thread.setDaemon(True)
92    print('read wait:')
93    read_com_thread.start()
94    time.sleep(1)
95    WriteToComPort(com_port, '\r\n\r\n')
96    WriteToComPort(com_port, 'AT+SYSINFO\r\n')
97    print('enter AT+SYSINFO')
98    time.sleep(3)
99    hivew_proc_find = re.findall('hiview,id=\d{1,3},status=\d{1,10},pri=\d{1,3},size=', com_output)
100    #Bootstrap_proc_find = re.findall('Bootstrap,id=\d{1,3},status=\d{1,10},pri=\d{1,3},size=', com_output)
101    print(hivew_proc_find)
102    if type(hivew_proc_find) == list and len(hivew_proc_find) > 0:
103        PrintToLog('hivew_proc found')
104    else:
105        PrintToLog('hivew_proc not found')
106        PrintToLog("End of check, test failed!")
107        sys.exit(99)
108
109    target_file = os.path.normpath(os.path.join(args.archive_path, "Hi3861_wifiiot_app_allinone.bin"))
110    ret_size = os.path.getsize(target_file)/1024/1024
111    PrintToLog('Size of Hi3861_wifiiot_app_allinone.bin : {:.2f}M'.format(ret_size))
112    if ret_size > 1:
113        PrintToLog('ERROR: Size of Hi3861_wifiiot_app_allinone.bin ({:.2f}M) is over the upper limit(1M)'.format(ret_size))
114        target_dir = os.path.normpath(os.path.join(args.archive_path, "libs"))
115        GetDirSize(target_dir)
116        PrintToLog("End of check, test failed!")
117        sys.exit(99)
118
119    PrintToLog("End of check, test succeeded!")
120    sys.exit(0)
121
122