• 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 encodings
17import json
18import sys
19import os
20import time
21import argparse
22import re
23import subprocess
24import shlex
25import datetime
26import sqlite3
27import shutil
28
29
30def PrintToLog(str):
31    time = datetime.datetime.now()
32    str = "[{}] {}".format(time, str)
33    print(str)
34    with open(os.path.join(args.save_path, 'test_{}.log'.format(args.device_num)),\
35    mode='a', encoding='utf-8') as log_file:
36        console = sys.stdout
37        sys.stdout = log_file
38        print(str)
39        sys.stdout = console
40    log_file.close()
41
42
43def EnterCmd(mycmd, waittime=0, printresult=1):
44    if mycmd == "":
45        return
46    global CmdRetryCnt
47    CmdRetryCnt = 1
48    EnterCmdRetry = 2
49    while EnterCmdRetry:
50        EnterCmdRetry -= 1
51        try:
52            p = subprocess.Popen(mycmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
53            result, unused_err = p.communicate(timeout=25)
54            try:
55                result=result.decode(encoding="utf-8")
56            except UnicodeDecodeError:
57                result=result.decode('gbk', errors='ignore')
58            break
59        except Exception as e:
60            result = 'retry failed again'
61            PrintToLog(e)
62            CmdRetryCnt += 1
63            p.kill()
64    if printresult == 1:
65        with open(os.path.join(args.save_path, 'test_{}.bat'.format(args.device_num)),\
66        mode='a', encoding='utf-8') as cmd_f:
67            cmd_f.write(mycmd + '\n')
68        cmd_f.close()
69        PrintToLog(mycmd)
70        PrintToLog(result)
71        sys.stdout.flush()
72    if waittime != 0:
73        time.sleep(waittime)
74        if printresult == 1:
75            with open(os.path.join(args.save_path, 'test_{}.bat'.format(args.device_num)),\
76            mode='a', encoding='utf-8') as cmd_f:
77                cmd_f.write("ping -n {} 127.0.0.1>null\n".format(waittime))
78            cmd_f.close()
79    return result
80
81
82def EnterShellCmd(shellcmd, waittime=0, printresult=1):
83    if shellcmd == "":
84        return
85    cmd = "hdc_std -t {} shell \"{}\"".format(args.device_num, shellcmd)
86    return EnterCmd(cmd, waittime, printresult)
87
88
89def SysExit():
90    EnterShellCmd("cd /data/log/faultlog/temp && tar -cf after_test_cppcrash{}.tar cppcrash*".format(args.device_num))
91    GetFileFromDev("/data/log/faultlog/temp/after_test_cppcrash{}.tar".format(args.device_num), \
92    os.path.normpath(args.save_path))
93    EnterShellCmd("cd /data/log/faultlog/faultlogger && tar -cf after_test_jscrash{}.tar jscrash*".format(args.device_num))
94    GetFileFromDev("/data/log/faultlog/faultlogger/after_test_jscrash{}.tar".format(args.device_num), \
95    os.path.normpath(args.save_path))
96    PrintToLog("SmokeTest:: SmokeTest find some key problems!")
97    PrintToLog("SmokeTest:: End of check, test failed!")
98    sys.exit(98)
99
100
101def SendFileToDev(src, dst):
102    cmd = "hdc_std -t {} file send \"{}\" \"{}\"".format(args.device_num, src, dst)
103    return EnterCmd(cmd, 1, 1)
104
105
106def GetFileFromDev(src, dst):
107    cmd = "hdc_std -t {} file recv \"{}\" \"{}\"".format(args.device_num, src, dst)
108    return EnterCmd(cmd, 1, 1)
109
110
111def ImageCheck(str, testnum=1):
112    conn = sqlite3.connect(str)
113    cursor_image = conn.cursor()
114    cursor_video = conn.cursor()
115    PrintToLog("SmokeTest:: start to check media library path")
116    try:
117        PrintToLog("SmokeTest:: select * from  files where mime_type = image/*")
118        cursor_image.execute("""select * from  files where mime_type = "image/*" """)
119    except:
120        PrintToLog("SmokeTest:: error: media_library.db cannot be found, please check media library path")
121        return -1
122    if testnum == 2:
123        try:
124            PrintToLog("SmokeTest:: select * from  files where mime_type = video/mp4")
125            cursor_video.execute("""select * from  files where mime_type = "video/mp4" """)
126        except:
127            PrintToLog("SmokeTest:: error: media_library.db cannot be found, please check media library path")
128            return -1
129    PrintToLog("SmokeTest:: media library is ok")
130    image_result = cursor_image.fetchone()
131    video_result = cursor_video.fetchone()
132    PrintToLog("SmokeTest:: image: {}".format(image_result))
133    PrintToLog("SmokeTest:: video: {}".format(video_result))
134    PrintToLog("SmokeTest:: start to check photos and videos in the album")
135    if image_result is not None and testnum == 1:
136        PrintToLog("SmokeTest:: success: There are some photos in the album!!")
137        return 1
138    elif image_result is not None and video_result is not None and testnum == 2:
139        PrintToLog("SmokeTest:: success: There are some photos and videos in the album!!")
140        return 1
141    else:
142        PrintToLog("SmokeTest:: error: There are no photos or videos in the album!!")
143        return -1
144
145
146def ConnectionJudgment():
147    connection_status = EnterCmd("hdc_std list targets", 2)
148    connection_cnt = 0
149    while args.device_num not in connection_status and connection_cnt < 15:
150        connection_status = EnterCmd("hdc_std list targets", 2)
151        connection_cnt += 1
152    if connection_cnt == 15:
153        PrintToLog("SmokeTest:: Device disconnection!!")
154        PrintToLog("SmokeTest:: End of check, test failed!")
155        sys.exit(101)
156
157
158def sandbox_check(process):
159    PrintToLog("SmokeTest:: start to check sandbox path")
160    medialibrarydata_pidnum = EnterShellCmd("pgrep -f {}".format(process), 1)
161    medialibrarydata_pidnum = medialibrarydata_pidnum.strip()
162    sandboxf = EnterShellCmd("echo \"ls /storage/media/local/\"|nsenter -t {} -m sh".format(medialibrarydata_pidnum), 1)
163    if "files" not in sandboxf:
164        PrintToLog("SmokeTest:: error: can not find sandbox path : /storage/media/local/files")
165        return -1
166    else:
167        PrintToLog("SmokeTest:: success: find sandbox path : /storage/media/local/files")
168        return 1
169
170
171def is_image_file(filename):
172    IMG_EXTENSIONS = ['.png', '.PNG']
173    return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)
174
175def picture_save(pic_path):
176    for root, dirs, files in os.walk(pic_path):
177        for file in files:
178            file_path = os.path.join(root, file)
179            if is_image_file(file_path):
180                shutil.copy2(file_path, args.save_path)
181                PrintToLog("SmokeTest:: send {} to save_path Successfully".format(file_path))
182
183
184def ConnectToWifi(tools_path):
185    EnterShellCmd("mkdir /data/l2tool", 1)
186    SendFileToDev(os.path.normpath(os.path.join(tools_path, "l2tool/busybox")), "/data/l2tool/")
187    SendFileToDev(os.path.normpath(os.path.join(tools_path, "l2tool/dhcpc.sh")), "/data/l2tool/")
188    SendFileToDev(os.path.normpath(os.path.join(tools_path, "l2tool/wpa_supplicant.conf")), "/data/l2tool/")
189    EnterShellCmd("wpa_supplicant -B -d -i wlan0 -c /data/l2tool/wpa_supplicant.conf", 1)
190    EnterShellCmd("chmod 777 ./data/l2tool/busybox", 1)
191    cnt = 2
192    while cnt:
193        try:
194            PrintToLog("SmokeTest:: hdc_std shell ./data/l2tool/busybox udhcpc -i wlan0 -s /data/l2tool/dhcpc.sh")
195            p = subprocess.check_output(shlex.split("hdc_std -t {} shell ./data/l2tool/busybox udhcpc -i wlan0 -s \
196            /data/l2tool/dhcpc.sh".format(args.device_num)), timeout=8)
197            PrintToLog(p.decode(encoding="utf-8"))
198            with open(os.path.join(args.save_path, 'test_{}.bat'.format(args.device_num)),\
199            mode='a', encoding='utf-8') as cmd_f:
200                cmd_f.write('hdc_std shell ./data/l2tool/busybox udhcpc -i wlan0 -s /data/l2tool/dhcpc.sh' + '\n')
201            cmd_f.close()
202            ret_code = 0
203        except subprocess.TimeoutExpired as time_e:
204            PrintToLog(time_e)
205            ret_code = 1
206        if ret_code == 0:
207            ip = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", p.decode(encoding="utf-8"))
208            PrintToLog(ip)
209            if len(ip) <= 0:
210                break
211            if len(re.findall(r'(?<!\d)\d{1,3}\.\d{1,3}\.\d{1,3}(?=\.\d)', ip[0])) <= 0:
212                break
213            gate = str(re.findall(r'(?<!\d)\d{1,3}\.\d{1,3}\.\d{1,3}(?=\.\d)', ip[0])[0]) + ".1"
214            PrintToLog(gate)
215            ifconfig="ifconfig wlan0 {}".format(ip[0])
216            EnterShellCmd(ifconfig)
217            routeconfig="./data/l2tool/busybox route add default gw {} dev wlan0".format(gate)
218            EnterShellCmd(routeconfig)
219            break
220        PrintToLog("try {}".format(cnt))
221        cnt -= 1
222        time.sleep(5)
223
224
225if __name__ == "__main__":
226    parser = argparse.ArgumentParser(description='manual to this script')
227    parser.add_argument('--config', type=str, default = './app_capture_screen_test_config.json')
228    parser.add_argument('--test_num', type=str, default = '1/1')
229    parser.add_argument('--tools_path', type=str, default = 'D:\\DeviceTestTools\\screenshot\\')
230    parser.add_argument('--anwser_path', type=str, default = 'D:\\DeviceTestTools\\screenshot\\resource')
231    parser.add_argument('--save_path', type=str, default = 'D:\\DeviceTestTools\\screenshot')
232    parser.add_argument('--device_num', type=str, default = 'null')
233    parser.add_argument('--pr_url', type=str, default = 'https://gitee.com/openharmony/applications_sample_wifi_iot/')
234    args = parser.parse_args()
235
236    if args.device_num == 'null':
237        result = EnterCmd("hdc_std list targets", 1, 0)
238        print(result)
239        args.device_num = result.split()[0]
240    with open(args.config) as f:
241        all_app = json.load(f)
242    cmp_status = 0
243    global_pos = all_app[0]
244
245    rebootcnt = 2
246    while rebootcnt:
247        rebootcnt -= 1
248        EnterCmd("hdc_std list targets", 1)
249        EnterShellCmd("mkdir -p /data/screen_test/train_set")
250        SendFileToDev(os.path.normpath(os.path.join(args.tools_path, "resource/printscreen")), "/data/screen_test/")
251        EnterShellCmd("chmod 777 /data/screen_test/printscreen")
252        rmlockcnt = 3
253        while rmlockcnt:
254            EnterShellCmd("uinput -T -m 425 1000 425 400;power-shell wakeup;uinput -T -m 425 400 425 1000;\
255            power-shell setmode 602;uinput -T -m 425 1000 425 400;", 1)
256            rmlockcnt -= 1
257        EnterShellCmd("hilog -w stop", 1)
258        EnterShellCmd("cd /data/log/hilog && tar -cf system_start_log_{}.tar *".format(args.device_num), 1)
259        GetFileFromDev("/data/log/hilog/system_start_log_{}.tar".format(args.device_num), args.save_path)
260        SendFileToDev(os.path.normpath(os.path.join(args.anwser_path, "launcher.pngraw")),\
261        "/data/screen_test/train_set")
262        EnterShellCmd("/data/screen_test/printscreen -f /data/screen_test/launcher_{}.png".format(args.device_num), 1)
263        GetFileFromDev("/data/screen_test/launcher_{}.pngraw".format(args.device_num), args.save_path)
264        GetFileFromDev("/data/screen_test/launcher_{}.png".format(args.device_num), args.save_path)
265        ConnectionJudgment()
266        cmp_launcher = "cmp -l /data/screen_test/launcher_{}.pngraw \
267        /data/screen_test/train_set/launcher.pngraw | wc -l".format(args.device_num)
268        p = EnterShellCmd(cmp_launcher, 1)
269        num = re.findall(r'[-+]?\d+', p)
270        PrintToLog(num)
271        if type(num) == list and len(num) > 0 and int(num[0]) < 147456 and\
272        p.find('No such file or directory', 0, len(p)) == -1:
273            PrintToLog("SmokeTest:: launcher screenshot comparison is ok!")
274            break
275        elif rebootcnt >= 1:
276            PrintToLog("SmokeTest:: launcher screenshot comparison failed, reboot and try!!!")
277            EnterShellCmd("rm -rf /data/*;reboot")
278            for i in range(5):
279                EnterCmd("hdc_std list targets", 10)
280        else:
281            PrintToLog("SmokeTest:: launcher screenshot comparison failed")
282            SysExit()
283
284    PrintToLog("\nSmokeTest:: ########## First check key processes start ##############")
285    lose_process = []
286    process_pid = {}
287    with open(os.path.normpath(os.path.join(args.tools_path, "resource/process.txt")), "r+") as f:
288        text = f.read()
289        two_check_process_list = text.split('#####')[1].split()[0:-1]
290        other_process_list = text.split('#####')[2].split()
291        for pname in two_check_process_list:
292            pids = EnterCmd("hdc_std -t {} shell pidof {}".format(args.device_num, pname), 0, 1)
293            try:
294                pidlist = pids.split()
295                int(pidlist[0])
296                for pid in pidlist:
297                    int(pid)
298                process_pid[pname] = pidlist
299            except:
300                lose_process.append(pname)
301        all_p = EnterShellCmd("ps -elf")
302        for pname in other_process_list:
303            findp = all_p.find(pname, 0, len(all_p))
304            if findp == -1:
305                lose_process.append(pname)
306
307    if lose_process:
308        PrintToLog("SmokeTest:: error: %s, These processes are not exist!!!" % lose_process)
309        SysExit()
310    else:
311        PrintToLog("SmokeTest:: first processes check is ok")
312
313    if "1/2" in args.test_num or "2/2" in args.test_num:
314        EnterShellCmd("param set persist.ace.testmode.enabled 1", 1)
315        EnterShellCmd("rm /data/log/hilog/*;hilog -r;hilog -Q pidoff;hilog -Q domainoff;hilog -G 512M;hilog -b D", 1)
316        picture_path = os.path.normpath(os.path.join(args.tools_path, "DistributedTest\\testcases"))
317        report_path = os.path.normpath(os.path.join(args.tools_path, "DistributedTest\\testcases\\report.txt"))
318        if args.test_num == "2/2":
319            EnterShellCmd("ifconfig eth0 192.168.0.1", 1)
320            ping_result = EnterShellCmd("ping 192.168.0.2 -i 1 -c 2", 3)
321            file_is_exist = EnterShellCmd("cd /data; find . -name report.txt")
322            ping_cnt = 0
323            wait_cnt = 0
324            while "2 packets transmitted, 2 received" not in ping_result and ping_cnt < 60:
325                ping_result = EnterShellCmd("ping 192.168.0.2 -i 1 -c 2", 3)
326                ping_cnt += 1
327            if ping_cnt == 60:
328                PrintToLog("SmokeTest:: Ping failed, timeout of 3 minutes")
329                SysExit()
330            while "report.txt" not in file_is_exist and wait_cnt < 60:
331                PrintToLog("SmokeTest:: waiting for the distributed test to end ")
332                file_is_exist = EnterShellCmd("cd /data; find . -name report.txt", 3)
333                wait_cnt += 1
334        elif args.test_num == "1/2":
335            EnterShellCmd("ifconfig eth0 192.168.0.2", 1)
336            ping_result = EnterShellCmd("ping 192.168.0.1 -i 1 -c 2", 3)
337            ping_cnt = 0
338            while "2 packets transmitted, 2 received" not in ping_result and ping_cnt < 60:
339                ping_result = EnterShellCmd("ping 192.168.0.1 -i 1 -c 2", 3)
340                ping_cnt += 1
341            if ping_cnt == 60:
342                PrintToLog("SmokeTest:: Ping failed, timeout of 3 minutes")
343            PrintToLog("SmokeTest:: ##### case 0 : distributed test start #####")
344            execute_path = os.path.normpath(os.path.join(args.tools_path, "DistributedTest"))
345            PrintToLog("SmokeTest:: execute_path {}".format(execute_path))
346            os.system("cd {} && python main.py run -l DistributedTest".format(execute_path))
347            distributed_result = ""
348            try:
349                with open(report_path, mode='r', encoding='utf-8', errors='ignore') as f:
350                    f.seek(0)
351                    distributed_result = f.read()
352                f.close()
353            except Exception as reason:
354                PrintToLog("SmokeTest:: report.txt is not exist!")
355            if "distributedcalc" in distributed_result:
356                picture_save(picture_path)
357                PrintToLog("SmokeTest:: testcase 0, distributed is ok!")
358            else:
359                picture_save(picture_path)
360                PrintToLog("SmokeTest:: error:testcase 0, distributed failed!")
361        EnterShellCmd("ifconfig eth0 down", 1)
362
363    try:
364        args.test_num.index('/')
365        idx_total = args.test_num.split('/')
366        if len(idx_total) != 2:
367            PrintToLog("SmokeTest:: test_num is invaild !!!")
368            SysExit()
369        elif idx_total[1] == '1':
370            idx_list = list(range(1, len(all_app)))
371        else:
372            idx_list = global_pos['DEVICE_{}'.format(idx_total[0])]
373    except ValueError as e:
374        PrintToLog(e)
375        idx_list = list(map(eval, args.test_num.split()))
376    PrintToLog("SmokeTest:: start to carry out the following testcases: ")
377    PrintToLog("SmokeTest:: testcase number: {} ".format(idx_list))
378
379    fail_idx_list = []
380    fail_name_list = []
381    smoke_first_failed = ''
382    for idx in idx_list:
383        single_app = all_app[idx]
384        sys.stdout.flush()
385        call_app_cmd = single_app['entry']
386        capture_screen_cmd = "/data/screen_test/printscreen -f /data/screen_test/{}_{}"
387        cmp_cmd = "cmp -l /data/screen_test/{}_{} /data/screen_test/train_set/{} | wc -l"
388        PrintToLog("\nSmokeTest:: ##### case {} : {} test start #####".format(idx, single_app['app_name']))
389        with open(os.path.join(args.save_path, 'test_{}.bat'.format(args.device_num)),\
390        mode='a', encoding='utf-8') as cmd_f:
391            cmd_f.write("\nSmokeTest::::::case {} --- {} test start \n".format(idx, single_app['app_name']))
392        cmd_f.close()
393        testcnt = 3
394        while testcnt:
395            testok = 0
396            if testcnt != 3:
397                PrintToLog("SmokeTest:: this testcase try again >>>>>>:\n")
398                with open(os.path.join(args.save_path, 'test_{}.bat'.format(args.device_num)),\
399                mode='a', encoding='utf-8') as cmd_f:
400                    cmd_f.write("\nSmokeTest::::::Last failed, try again \n")
401                cmd_f.close()
402            if idx == 2 or idx == 8:
403                testcnt = 1
404            if single_app['entry'] != "":
405                EnterShellCmd(call_app_cmd, 5)
406            PrintToLog("SmokeTest:: execute command {}".format(single_app['all_actions']))
407            raw_pic_name = ''
408            pic_name = ''
409            for single_action in single_app['all_actions']:
410                if type(single_action[1]) == str and single_action[1] == 'shot_cmd':
411                    if len(single_action) == 3:
412                        pic_name = "{}{}".format(single_action[2], ".png")
413                        raw_pic_name = single_action[2] + ".pngraw"
414                    else:
415                        pic_name = "{}{}".format(single_app['app_name'], ".png")
416                        raw_pic_name = single_app['app_name'] + ".pngraw"
417                    EnterShellCmd("rm /data/screen_test/{}_{}*".format(4 - testcnt, pic_name), 1)
418                    EnterShellCmd(capture_screen_cmd.format(4 - testcnt, pic_name), 1)
419                    GetFileFromDev("/data/screen_test/{}_{}".format(4 - testcnt, pic_name), args.save_path)
420                    next_cmd = ""
421                elif type(single_action[1]) == str and single_action[1] == 'cmp_cmd-level':
422                    next_cmd = ""
423                    sys.stdout.flush()
424                    EnterShellCmd("rm /data/train_set/{}".format(raw_pic_name), 1)
425                    SendFileToDev(os.path.normpath(os.path.join(args.anwser_path, raw_pic_name)),\
426                    "/data/screen_test/train_set")
427                    new_cmp_cmd = cmp_cmd.format(4 - testcnt, raw_pic_name, raw_pic_name)
428                    if len(single_action) == 3:
429                        tolerance = single_action[2]
430                    else:
431                        tolerance = global_pos['cmp_cmd-level'][1]
432                    PrintToLog("SmokeTest:: start to contrast screenshot")
433                    p = EnterShellCmd(new_cmp_cmd, single_action[0])
434                    num = re.findall(r'[-+]?\d+', p)
435                    PrintToLog("SmokeTest:: contrast pixel difference {}".format(num))
436                    if type(num) == list and len(num) > 0 and int(num[0]) < tolerance and\
437                    p.find('No such file or directory', 0, len(p)) == -1:
438                        if testok == 0:
439                            testok = 1
440                        PrintToLog("SmokeTest:: {} screenshot check is ok!".format(raw_pic_name))
441                    else:
442                        testok = -1
443                        PrintToLog("SmokeTest:: {} screenshot check is abnarmal!".format(raw_pic_name))
444                    sys.stdout.flush()
445                    if testok == 1 or testcnt == 1 or smoke_first_failed != '':
446                        old_name = os.path.normpath(os.path.join(args.save_path, "{}_{}".format(4 - testcnt, pic_name)))
447                        GetFileFromDev("/data/screen_test/{}_{}".format(4 - testcnt, raw_pic_name), args.save_path)
448                        os.system("rename {} {}".format(old_name, pic_name))
449                        os.system("rename {}raw {}raw".format(old_name, pic_name))
450                    raw_pic_name = ''
451                elif type(single_action[1]) == str and single_action[1] == 'install_hap':
452                    next_cmd = ""
453                    if len(single_action) == 3:
454                        EnterCmd("hdc_std -t {} install \"{}\"".format(args.device_num,\
455                        os.path.normpath(os.path.join(args.tools_path, single_action[2]))))
456                elif type(single_action[1]) == str and single_action[1] == 'get_file_from_dev':
457                    next_cmd = ""
458                    if len(single_action) == 3:
459                        EnterCmd("hdc_std -t {} file recv \"{}\" \"{}\"".format(args.device_num,\
460                        single_action[2], os.path.normpath(args.save_path)))
461                elif type(single_action[1]) == str and single_action[1] == 'send_file_to_dev':
462                    next_cmd = ""
463                    if len(single_action) == 4:
464                        EnterCmd("hdc_std -t {} file send \"{}\" \"{}\"".format(args.device_num,\
465                        os.path.normpath(os.path.join(args.tools_path, single_action[2])), single_action[3]))
466                elif type(single_action[1]) == str and single_action[1] == 'connect_wifi':
467                    next_cmd = ""
468                    ConnectToWifi(args.tools_path)
469                elif type(single_action[1]) == str and single_action[1] == 'sandbox_path_check':
470                    next_cmd = ""
471                    if sandbox_check("com.ohos.medialibrary.medialibrarydata") == 1 and testok == 1:
472                        testok = 1
473                    else:
474                        testok = -1
475                elif type(single_action[1]) == str and single_action[1] == 'photo_check':
476                    next_cmd = ""
477                    if ImageCheck("{}\\media_library.db".format(os.path.normpath(args.save_path)), 1) == 1 and testok == 1:
478                        testok = 1
479                    else:
480                        testok = -1
481                elif type(single_action[1]) == str and single_action[1] == 'process_check':
482                    next_cmd = ""
483                    if len(single_action) == 3:
484                        p = EnterShellCmd("ps -elf", single_action[0])
485                        result = "".join(p)
486                        findsome = result.find(single_action[2], 0, len(result))
487                        if findsome != -1 and testok == 1:
488                            testok = 1
489                            PrintToLog("SmokeTest:: \"{}\" is ok, find process \"{}\"!".format(single_action[1],\
490                            single_action[2]))
491                        else:
492                            testok = -1
493                            PrintToLog("SmokeTest:: \"{}\" failed, not find process \"{}\"!".format(single_action[1],\
494                            single_action[2]))
495                        sys.stdout.flush()
496                elif type(single_action[1]) == str and single_action[1] == 'process_crash_check':
497                    next_cmd = ""
498                    if len(single_action) == 3:
499                        p = EnterShellCmd("cd /data/log/faultlog/temp && grep \"Process name\" -rnw ./",\
500                        single_action[0])
501                        result = "".join(p)
502                        findsome = result.find(single_action[2], 0, len(result))
503                        if findsome != -1:
504                            testok = -1
505                            PrintToLog("SmokeTest:: \"{}\" error:find fatal crash \"{}\"!".format(single_action[1],\
506                            single_action[2]))
507                            SysExit()
508                        else:
509                            testok = 1
510                            PrintToLog("SmokeTest:: \"{}\" result is ok, not find fatal\
511                            crash \"{}\"!".format(single_action[1], single_action[2]))
512                        sys.stdout.flush()
513                elif type(single_action[1]) == str:
514                    if single_action[1] not in single_app.keys():
515                        target_ = global_pos[single_action[1]]
516                    else:
517                        target_ = single_app[single_action[1]]
518                    if type(target_[0]) == str:
519                        next_cmd = ""
520                        p = EnterShellCmd(target_[0], single_action[0])
521                        result = "".join(p)
522                        if len(target_) > 1:
523                            findsome = result.find(target_[1], 0, len(result))
524                            if findsome != -1:
525                                testok = 1
526                                PrintToLog("SmokeTest:: \"{}\" check result is ok, find \"{}\"!".format(target_[0],\
527                                target_[1]))
528                            else:
529                                testok = -1
530                                PrintToLog("SmokeTest:: \"{}\" result is not ok, not find \"{}\"!".format(target_[0],\
531                                target_[1]))
532                            sys.stdout.flush()
533                    else:
534                        next_cmd = "uinput -M -m {} {} -c 0".format(target_[0], target_[1])
535                else:
536                    next_cmd = "uinput -M -m {} {} -c 0".format(single_action[1], single_action[2])
537                EnterShellCmd(next_cmd, single_action[0])
538
539            if testok == 1:
540                PrintToLog("SmokeTest:: testcase {}, {} is ok!".format(idx, single_app['app_name']))
541                testcnt = 0
542            elif testok == -1 and smoke_first_failed == '':
543                if testcnt == 1:
544                    fail_idx_list.append(idx)
545                    fail_name_list.append(single_app['app_name'])
546                    smoke_first_failed = single_app['app_name']
547                    PrintToLog("SmokeTest:: error:testcase {}, {} is failed!".format(idx, single_app['app_name']))
548                testcnt -= 1
549            elif testok == -1 and smoke_first_failed != '':
550                fail_idx_list.append(idx)
551                fail_name_list.append(single_app['app_name'])
552                PrintToLog("SmokeTest:: error:testcase {}, {} is failed!".format(idx, single_app['app_name']))
553                testcnt = 0
554            else:
555                testcnt = 0
556            ConnectionJudgment()
557
558    PrintToLog("\nSmokeTest:: ########## Second check key processes start ##############")
559    second_check_lose_process = []
560    for pname in two_check_process_list:
561        pids = EnterCmd("hdc_std -t {} shell pidof {}".format(args.device_num, pname), 0, 1)
562        try:
563            pidlist = pids.split()
564            if process_pid[pname] != pidlist:
565                if pname in two_check_process_list:
566                    PrintToLog("SmokeTest:: error: pid of %s is different the first check" % pname)
567                else:
568                    PrintToLog("SmokeTest:: warnning: pid of %s is different the first check" % pname)
569            elif len(pidlist) != 1:
570                if pname in two_check_process_list:
571                    PrintToLog("SmokeTest:: error: pid of %s is not only one" % pname)
572                else:
573                    PrintToLog("SmokeTest:: warnning: pid of %s is not only one" % pname)
574        except:
575            second_check_lose_process.append(pname)
576
577    if second_check_lose_process:
578        PrintToLog("SmokeTest:: error: pid of %s is not exist" % pname)
579    else:
580        PrintToLog("SmokeTest:: second processes check is ok")
581
582    EnterShellCmd("cd /data/log/faultlog/temp && grep \"Process name\" -rnw ./", 1)
583    EnterShellCmd("cd /data/log/faultlog/faultlogger && grep \"Process name\" -rnw ./", 1)
584
585    fail_str_list = [str(x) for x in fail_idx_list]
586    reboot_test_num = " ".join(fail_str_list)
587    if len(fail_idx_list) != 0:
588        PrintToLog("SmokeTest:: failed testcase number: {} ".format(fail_str_list))
589        PrintToLog("SmokeTest:: check \"reboot\" in reboot.txt".format(args.save_path))
590        with open(os.path.normpath(os.path.join(args.tools_path, "reboot.txt")), mode='a+') as f:
591            f.seek(0)
592            reboot_result = f.read()
593        f.close()
594        if len(reboot_result) < 1 and rebootcnt >= 1:
595            PrintToLog("SmokeTest:: \"reboot\" is not found in the reboot.txt")
596            PrintToLog("SmokeTest:: the device will reboot and try the failed testcase")
597            PrintToLog("SmokeTest:: mkdir {}\\reboot".format(args.save_path))
598            os.system("mkdir {}\\reboot".format(args.save_path))
599            PrintToLog("SmokeTest:: write \"reboot\" into reboot.txt".format(args.save_path))
600            with open(os.path.normpath(os.path.join(args.tools_path, "reboot.txt")), mode='w') as f:
601                f.write("reboot")
602            f.close()
603            PrintToLog("SmokeTest:: error: name {}, index {}, failed, rm /data/* and reboot".format(fail_name_list,\
604            fail_idx_list))
605            EnterShellCmd("rm -rf /data/* && reboot")
606            reboot_result_list = EnterCmd("hdc_std list targets", 2)
607            number = 0
608            while args.device_num not in reboot_result_list and number < 15:
609                reboot_result_list = EnterCmd("hdc_std list targets", 2)
610                number += 1
611            EnterShellCmd("rm /data/log/hilog/*;hilog -r;hilog -w start -l 400000000 -m none", 1)
612            py_cmd = os.system("python {}\\resource\\capturescreentest.py --config \
613            {}\\resource\\app_capture_screen_test_config.json --anwser_path {} \
614            --save_path {}\\reboot --tools_path {} --device_num {} --test_num \"{}\"".format(args.tools_path, \
615            args.tools_path, args.anwser_path, args.save_path, args.tools_path, args.device_num, reboot_test_num))
616            if py_cmd == 0:
617                sys.exit(0)
618            elif py_cmd == 98:
619                sys.exit(98)
620            elif py_cmd == 99:
621                sys.exit(99)
622            else:
623                sys.exit(101)
624        else:
625            PrintToLog("SmokeTest:: error: name {}, index {}, these testcase is failed".format(fail_name_list,\
626            fail_idx_list))
627            SysExit()
628    else:
629        PrintToLog("SmokeTest:: all testcase is ok")
630        PrintToLog("SmokeTest:: End of check, test succeeded!")
631        sys.exit(0)