-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateRateTest.py
135 lines (88 loc) · 2.8 KB
/
updateRateTest.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import subprocess
import uiautomator2 as u2
import os
import time
import sys
root_dir = "F:\\javaP\\freqResult"
dir_set = []
lines = []
for root, dirs, files in os.walk(root_dir):
if root in "results":
continue
dir_set.append(root)
packageName=""
activityName=""
id=""
testType=""
list_activiyNames_has_LeaK = []
for d in dir_set:
filess = os.listdir(d)
for file in filess:
with open(d + "\\" + file) as f:
lines.append(f.readlines())
for f in lines:
x_loop_must_break = False
if (f[2].strip().isnumeric()):
continue
packageName = f[0].strip()
activityName=f[1].strip()
id=f[2].strip()
testType=f[3].strip()
apkName = sys.argv[1]
for act in list_activiyNames_has_LeaK:
if activityName in act:
x_loop_must_break = True
break
if x_loop_must_break:
break
import subprocess
import sys
import time
import uiautomator2 as u2
def idClick(appPackageName, id):
d(resourceId=appPackageName + ":id/" + id).click()
def runCommand(adbCommand):
return subprocess.getoutput(adbCommand)
def findResult(start, output):
return (output[output.find(start) + len(start):])
def substring(start, end, output):
return (output[output.find(start) + 1 + len(start):output.rfind(end)])
def startActivity(activityName):
adbCommand = "adb shell am start -n "+packageName+"/"+activityName
return subprocess.getoutput(adbCommand)
def clickId(id):
print("I'm in ID")
if id:
idClick(packageName, id)
# time.sleep(2)
else:
# time.sleep(3) # Sleep for 3 second
print()
# # *---*******************************--------------------*******************************--------------------------
d = u2.connect() # connect to device
print(d.info)
d.screen_on()
adbSensorCommand = "adb shell " + '"dumpsys sensorservice"'
target = 'Previous Registrations:'
ratePackageName = "com.example.updaterate"
res = runCommand(adbSensorCommand)
shortRes = findResult(target, res)
lines = shortRes.splitlines()
def check_updateRate(packageName):
for l in lines:
if packageName in l:
return substring("samplingRate", "us ", l)
res = runCommand("adb install -r -g "+apkName)
runCommand(res)
print(startActivity(activityName))
time.sleep(.4)
before = check_updateRate(packageName)
d.press("home")
d.app_start(ratePackageName)
time.sleep(.4)
d.press("home")
after = check_updateRate(packageName)
diff = int(before) - int(after)
if (diff > 0):
print("Confirmed Rate update change")
# ************************************************************************