forked from electricbubble/gidevice
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
device_test.go
263 lines (219 loc) · 4.73 KB
/
device_test.go
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package giDevice
import (
"fmt"
"log"
"os"
"os/signal"
"testing"
"time"
)
var dev Device
func setupDevice(t *testing.T) {
setupUsbmux(t)
devices, err := um.Devices()
if err != nil {
t.Fatal(err)
}
if len(devices) == 0 {
t.Fatal("No Device")
}
dev = devices[0]
}
func Test_device_ReadPairRecord(t *testing.T) {
setupDevice(t)
pairRecord, err := dev.ReadPairRecord()
if err != nil {
t.Fatal(err)
}
t.Log(pairRecord.HostID, pairRecord.SystemBUID, pairRecord.WiFiMACAddress)
}
func Test_device_NewConnect(t *testing.T) {
setupDevice(t)
if _, err := dev.NewConnect(LockdownPort); err != nil {
t.Fatal(err)
}
}
func Test_device_DeletePairRecord(t *testing.T) {
setupDevice(t)
if err := dev.DeletePairRecord(); err != nil {
t.Fatal(err)
}
}
func Test_device_SavePairRecord(t *testing.T) {
setupLockdownSrv(t)
pairRecord, err := lockdownSrv.Pair()
if err != nil {
t.Fatal(err)
}
err = dev.SavePairRecord(pairRecord)
if err != nil {
t.Fatal(err)
}
}
func Test_device_XCTest(t *testing.T) {
setupLockdownSrv(t)
bundleID = "com.DataMesh.CheckList"
out, cancel, err := dev.XCTest(bundleID)
// out, cancel, err := dev.XCTest(bundleID, WithXCTestEnv(map[string]interface{}{"USE_PORT": 8222, "MJPEG_SERVER_PORT": 8333}))
if err != nil {
t.Fatal(err)
}
done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt)
go func() {
for s := range out {
fmt.Print(s)
}
done <- os.Interrupt
}()
for {
select {
case <-done:
cancel()
fmt.Println()
t.Log("DONE")
return
}
}
}
func Test_device_AppInstall(t *testing.T) {
setupLockdownSrv(t)
ipaPath := "/private/tmp/derivedDataPath/Build/Products/Release-iphoneos/WebDriverAgentRunner-Runner.ipa"
err := dev.AppInstall(ipaPath)
if err != nil {
t.Fatal(err)
}
}
func Test_device_AppUninstall(t *testing.T) {
setupLockdownSrv(t)
bundleID = "com.leixipaopao.WebDriverAgentRunner.xctrunner"
err := dev.AppUninstall(bundleID)
if err != nil {
t.Fatal(err)
}
}
func Test_device_Syslog(t *testing.T) {
setupLockdownSrv(t)
dev.SyslogStop()
lines, err := dev.Syslog()
if err != nil {
t.Fatal(err)
}
done := make(chan os.Signal, 1)
go func() {
for line := range lines {
fmt.Println(line)
}
done <- os.Interrupt
t.Log("DONE!!!")
}()
signal.Notify(done, os.Interrupt, os.Kill)
// <-done
time.Sleep(3 * time.Second)
dev.SyslogStop()
time.Sleep(200 * time.Millisecond)
}
func Test_device_Reboot(t *testing.T) {
setupDevice(t)
dev.Reboot()
}
func Test_device_Shutdown(t *testing.T) {
setupDevice(t)
dev.Shutdown()
}
func Test_device_PowerInfo(t *testing.T) {
setupDevice(t)
data, err := dev.PowerSource()
if err != nil {
panic(err)
}
log.Println(data)
}
func Test_device_InstallationProxyBrowse(t *testing.T) {
setupDevice(t)
list, err := dev.InstallationProxyBrowse(
WithApplicationType(ApplicationTypeUser),
WithReturnAttributes("CFBundleDisplayName", "CFBundleIdentifier", "SequenceNumber", "SequenceNumber"),
)
// list, err := dev.InstallationProxyBrowse()
if err != nil {
t.Fatal(err)
}
t.Log(len(list))
for _, l := range list {
t.Logf("%#v", l)
}
}
func Test_device_share(t *testing.T) {
setupDevice(t)
SetDebug(true, true)
err := dev.Share(9123)
if err != nil {
log.Panic(err)
}
}
func Test_device_connect(t *testing.T) {
SetDebug(true, true)
remoteDev, _ := NewRemoteConnect("127.0.0.1", 9123, 30)
data, err := remoteDev.GetValue("", "ProductVersion")
if err != nil {
log.Panic(err)
}
log.Println(data)
}
func TestMockPerfdUser1(t *testing.T) {
//SetDebug(true, true)
remoteDev, _ := NewRemoteConnect("127.0.0.1", 9123, 30)
data, err := remoteDev.PerfStart(
WithPerfSystemCPU(true),
WithPerfSystemMem(true),
WithPerfSystemDisk(true),
WithPerfSystemNetwork(true),
WithPerfNetwork(true),
WithPerfFPS(true),
WithPerfGPU(true),
//WithPerfProcessAttributes("cpuUsage", "memAnon"),
//WithPerfBundleID("com.apple.mobilesafari"),
)
if err != nil {
t.Fatal(err)
}
timer := time.NewTimer(time.Duration(time.Second * 20))
for {
select {
case <-timer.C:
dev.PerfStop()
return
case d := <-data:
fmt.Println(string(d))
}
}
}
func TestMockPerfdUser2(t *testing.T) {
//SetDebug(true, true)
remoteDev, _ := NewRemoteConnect("127.0.0.1", 9123, 30)
data, err := remoteDev.PerfStart(
WithPerfSystemCPU(true),
WithPerfSystemMem(true),
WithPerfSystemDisk(true),
WithPerfSystemNetwork(true),
WithPerfNetwork(true),
WithPerfFPS(true),
WithPerfGPU(true),
//WithPerfProcessAttributes("cpuUsage", "memAnon"),
//WithPerfBundleID("com.apple.mobilesafari"),
)
if err != nil {
t.Fatal(err)
}
timer := time.NewTimer(time.Duration(time.Second * 10))
for {
select {
case <-timer.C:
dev.PerfStop()
return
case d := <-data:
fmt.Println(string(d))
}
}
}