-
Notifications
You must be signed in to change notification settings - Fork 1
/
gtest.py
64 lines (57 loc) · 1.99 KB
/
gtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import sys
import time
import uuid
import subprocess
import re
from subprocess import call
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
runId = str(uuid.uuid4())
packageName = "com.example.harsh.testcpp"
gtestDriverIntentName = "com.example.harsh.testcpp.intent.GTEST_CMD"
def scanLogcat():
adbCmd = "adb logcat | grep APP_STDOUT"
# p = subprocess.Popen(adbCmd, stdout=subprocess.PIPE, bufsize=0, shell=True)
p = subprocess.Popen(["adb", "logcat"], stdout=subprocess.PIPE, bufsize=0, shell=False)
startMark = "GTest_Start:" + runId
endMark = "GTest_End:" + runId
gtestLogMark = "APP_STDOUT"
while True:
line = p.stdout.readline()
if startMark in line:
break
while True:
# print "."
line = p.stdout.readline()
if gtestLogMark not in line:
continue
if endMark in line:
break
if "referenceTable " in line:
continue
# Skip log prefix and newline
line = line[line.index(":") +2 :-1]
# Put term colors
if "[ FAILED ]" in line:
line = line.replace("[ FAILED ]", bcolors.FAIL + "[ FAILED ]" + bcolors.ENDC)
elif ": Failure" in line:
line = bcolors.WARNING + line + bcolors.ENDC
else:
line = re.sub("^\[(.*)\]", bcolors.OKGREEN + r'[\1]' + bcolors.ENDC, line)
print line
sys.stdout.flush()
# call(["adb", "logcat","-c"])
FNULL = open(os.devnull, 'w')
call(["adb","shell", "am", "force-stop", packageName], stdout=FNULL, stderr=subprocess.STDOUT)
call(["adb", "shell", "monkey", "-p",packageName, "1"], stdout=FNULL, stderr=subprocess.STDOUT)
time.sleep(1)
call(["adb","shell", "am", "broadcast", "-a", gtestDriverIntentName, "--es", "cmd", ' '.join(sys.argv) + " " + runId], stdout=FNULL, stderr=subprocess.STDOUT)
scanLogcat()