-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathtest.py
266 lines (189 loc) · 8.35 KB
/
test.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
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
264
265
266
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
/*
* Android media framework fuzzer
* Copyright (c) 2015, Intel Corporation.
* Author: Alexandru Blanda ([email protected])
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
"""
import sys
import subprocess
import re
import time
from utils import *
if sys.argv[1] == '-h':
print 'Usage:\n'
print 'test.py <type> <audio/video> <play/noplay> <seed_number>\n'
print 'type - type of target (stagefright/sf2/stream/codec)'
print 'audio - seed files are of audio type'
print 'video - seed files are of video type'
print 'play/noplay - enable testing of playback capabilities'
print 'seed_number - number of the seed file to start from\n'
print 'Ex: python test.py stagefright video noplay 0\n'
sys.exit()
target_type = sys.argv[1]
format_type = sys.argv[2]
playback = sys.argv[3]
seed_number = sys.argv[4]
# get device ids
cmd = 'adb devices > devices.txt'
run_subproc(cmd)
# parse the device id file to get the device list
f1 = open('devices.txt', 'rw')
devices = f1.readlines()
count_devices = len(devices) - 2
dev = [None] * count_devices
c = 0
for i in range(1, len(devices) - 1):
reg_device = re.compile('\S*\s')
dev[c] = str(reg_device.findall(devices[i])[0])
c = c + 1
# get batches list
f2 = open('batches.txt', 'rw')
batches = f2.readlines()
for i in range(0, len(batches)):
batches[i] = batches[i].rstrip()
count_batches = len(batches)
if (count_batches == 0):
print 'No batches to run'
print 'Edit the batches.txt file!'
sys.exit()
if count_batches < count_devices:
print 'More devices than batches to run...'
print '...quit now to use all available devices'
time.sleep(5)
print 'continuing...'
dev_batch = [str] * count_devices * count_batches
share = int(count_batches / count_devices)
batch_counter = 0
retcode1 = [None] * count_devices
retcode2 = [None] * count_devices
# flush the logcat buffer for each device before starting the campaign
for i in range(0, count_devices):
cmd = 'adb -s ' + dev[i] + ' logcat -c'
r = subprocess.Popen([cmd], shell=True)
r.wait()
if target_type == 'stagefright':
# each device must take their "share" from the total number of batches
for x in range(1, share + 1):
# give each device its batch for the current round
for i in range(0, count_devices):
# give batches[batch_counter] to dev[i] and increment batch_counter
cmd = 'python sp_stagefright.py ' \
+ str(batches[batch_counter]) + ' ' + format_type \
+ ' ' + playback + ' ' + seed_number + ' ' \
+ dev[i]
retcode1[i] = subprocess.Popen([cmd], shell=True)
# start a log for the current device with its given batch
cmd = 'adb -s ' + dev[i] + ' logcat -v time *:F > logs/' \
+ batches[batch_counter] + '_stagefright_' + str(dev[i])
retcode2[i] = subprocess.Popen([cmd], shell=True)
batch_counter = batch_counter + 1
# wait for all devices to finish their round of batches
for c in range(0, count_devices):
retcode1[c].wait()
print ' Device ' + str(c) + ' has finished round: ' + str(x)
print '******* All devices have finished round: ' + str(x)
# kill the logging processes for the current round
cmd = 'kill -9 $(pgrep -f logcat)'
run_subproc(cmd)
# flush the logcat buffer for each device after each round
for i in range(0, count_devices):
flush_log(dev[i])
if target_type == 'codec':
# each device must take their "share" from the total number of batches
for x in range(1, share + 1):
# give each device its batch for the current round
for i in range(0, count_devices):
# give batches[batch_counter] to dev[i] and increment batch_counter
cmd = 'python sp_codec.py ' \
+ str(batches[batch_counter]) + ' ' \
+ format_type + ' ' + playback + ' ' \
+ seed_number + ' ' + dev[i]
retcode1[i] = subprocess.Popen([cmd], shell=True)
# start a log for the current device with its given batch
cmd = 'adb -s ' + dev[i] \
+ ' logcat -v time *:F > logs/' \
+ batches[batch_counter] + '_codec_' + dev[i]
retcode2[i] = subprocess.Popen([cmd], shell=True)
batch_counter = batch_counter + 1
# wait for all devices to finish their round of batches
for c in range(0, count_devices):
retcode1[c].wait()
print ' Device ' + str(c) + ' has finished round: ' + str(x)
print '******* All devices have finished round: ' + str(x)
# kill the logging processes for the current round
cmd = 'kill -9 $(pgrep -f logcat)'
run_subproc(cmd)
# flush the logcat buffer for each device after each round
for i in range(0, count_devices):
flush_log(dev[i])
if target_type == 'sf2':
# each device must take their "share" from the total number of batches
for x in range(1, share + 1):
# give each device its batch for the current round
for i in range(0, count_devices):
# give batches[batch_counter] to dev[i] and increment batch_counter
cmd = 'python sp_sf2.py ' \
+ str(batches[batch_counter]) \
+ ' ' + format_type + ' ' + seed_number \
+ ' ' + dev[i]
retcode1[i] = subprocess.Popen([cmd], shell=True)
batch_counter = batch_counter + 1
# start a log for the current device with its given batch
cmd = 'adb -s ' + dev[i] \
+ ' logcat -v time *:F > logs/' \
+ batches[batch_counter] + '_sf2_' \
+ str(dev[i])
retcode2[i] = subprocess.Popen([cmd], shell=True)
batch_counter = batch_counter + 1
# wait for all devices to finish their round of batches
for c in range(0, count_devices):
retcode1[c].wait()
print ' Device ' + str(c) + ' has finished round: ' + str(x)
print '******* All devices have finished round: ' + str(x)
# kill the logging processes for the current round
cmd = 'kill -9 $(pgrep -f logcat)'
run_subproc(cmd)
# flush the logcat buffer for each device after each round
for i in range(0, count_devices):
flush_log(dev[i])
if target_type == 'stream':
# each device must take their "share" from the total number of batches
for x in range(1, share + 1):
# give each device its batch for the current round
for i in range(0, count_devices):
# give batches[batch_counter] to dev[i] and increment batch_counter
cmd = 'python sp_stream.py ' \
+ str(batches[batch_counter]) + ' ' \
+ seed_number + ' ' + dev[i]
retcode1[i] = subprocess.Popen([cmd], shell=True)
batch_counter = batch_counter + 1
# start a log for the current device with its given batch
cmd = 'adb -s ' + dev[i] \
+ ' logcat -v time *:F > logs/' \
+ batches[batch_counter] + '_stream_' \
+ str(dev[i])
retcode2[i] = subprocess.Popen([cmd], shell=True)
batch_counter = batch_counter + 1
# wait for all devices to finish their round of batches
for c in range(0, count_devices):
retcode1[c].wait()
print ' Device ' + str(c) + ' has finished round: ' + str(x)
print '******* All devices have finished round: ' + str(x)
# kill the logging processes for the current round
cmd = 'kill -9 $(pgrep -f logcat)'
run_subproc(cmd)
# flush the logcat buffer for each device after each round
for i in range(0, count_devices):
flush_log(dev[i])