/
Stability.py
1410 lines (1233 loc) · 63.1 KB
/
Stability.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import android, time, unittest, sys, datetime, copy,os,re
import re
import os
import traceback
import commands
from threading import Thread #To check heap usage
LOOP_IDLE = 10 #Seconds
MADGPENNYTOSS_INSTALLED = 0
MADGCHICKEN_INSTALLED = 0
MADGHORSE_INSTALLED = 0
MENU_DELAY = 10
SERIAL_INTERFACE = None
def doc(f):
def checkdoc(s):
doc = getattr(f, '__doc__')
if doc is None:
setattr(f, '__doc__', "None|")
elif '|' not in doc:
doc = doc + "|"
setattr(f, '__doc__', doc)
else:pass
return f
return checkdoc
class takeMeminfo():
def __init__(self, id, meminfo_dir):
self.id = id
self.meminfo_dir = meminfo_dir
self.procrank = "procrank.log"
self.dumsys = "dumpsys_meminfo.log"
self.top = "top.log"
def meminfo(self):
if not os.path.isdir(self.meminfo_dir):
print self.meminfo_dir + "is not a directory"
return
fp = open(os.path.join(self.meminfo_dir,self.procrank), "a+")
fd = open(os.path.join(self.meminfo_dir,self.dumsys), "a+")
ft = open(os.path.join(self.meminfo_dir,self.top), "a+")
try:
fp.write(commands.getoutput("adb -s %s shell procrank" %self.id))
fp.write("\n================================\n")
fd.write(commands.getoutput("adb -s %s shell dumpsys meminfo" %self.id))
fp.write("\n================================\n")
ft.write(commands.getoutput("adb -s %s shell busybox top -n 1" %self.id))
fp.write("\n================================\n")
fp.close()
fd.close()
ft.close()
except:
fp.close()
fd.close()
ft.close()
raise Exception
class UiAutomator():
"""run UiAutomator case"""
def __init__(self,id, jarname, casename, argname="none", argvalue="none"):
self.id = id
self.jar = jarname
self.case = casename
self.arg = argname
self.argvalue = argvalue
def runtest(self):
"""return result and info list
eg.
ua = Stability.UiAutomator(self.id, self.jar, self.case)
result, info = ua.runtest()
if result != 'PASS':
print str(info)
raise Exception
"""
pushcmd = "adb -s %s push ../testcases/setup/%s /data/local/tmp" %(self.id, self.jar)
cmd = "adb -s %s shell uiautomator runtest %s --nohup -c %s -e %s %s" %(self.id,self.jar, self.case, self.arg, self.argvalue)
push = commands.getstatusoutput(pushcmd)
if push[0] != 0:
return '',[push[1]]
output = commands.getstatusoutput(cmd)
uilog = []
if output[0]==0:
for line in output[1].split('\r\n'):
l = line.strip()
if l:
uilog.append(l)
else:
return '', [output[1]]
result = ''
for i in range(len(uilog)):
if uilog[i].startswith("Time:"):
if uilog[i+1].startswith("OK"):
result = 'PASS'
else:
result = 'FAIL'
info = []
for line in uilog:
print line
if line.startswith('Result'):
info.append(line.split(':', 1)[1])
if line.startswith('INSTRUMENTATION_STATUS: stack='):
info.append(line)
if line.startswith("INSTRUMENTATION_STATUS: fail file"):
info.append(line)
if line.endswith('KB/s'):
info.append(line)
if line.endswith('MB/s'):
info.append(line)
return result, info
class cloudStatus():
"""detect cloud video status"""
def __init__(self, filename):
self.filename = filename
def playerError(self):
"""return MediaPlayer Error times"""
logcontents = self.openFile()
p = re.compile(r'MediaPlayer: error')
result = 0
if logcontents != []:
for line in logcontents:
if p.search(line):
result += 1
else:
print self.filename + " is null"
print "MediaPlayer: error: %s" %result
return result
def getUtpVersion(self):
"""return utp version"""
logcontents = self.openFile()
p = re.compile(r'\[UTPModule\]\ utp\ status:\ (.*)\ .*')
duration = -1
if logcontents !=[]:
for line in logcontents:
match = p.search(line)
if match:
duration = match.group(1)
return duration
def getPlayDuration(self):
"""return play duration"""
logcontents = self.openFile()
p = re.compile(r'MediaPlayerService.*: \[\d+\] getDuration = (\d+)')
duration = -1
if logcontents !=[]:
for line in logcontents:
match = p.search(line)
if match:
duration = match.group(1)
print "duration: %s" %duration
return duration
def getResolution(self):
"""return resolution"""
logcontents = self.openFile()
#MediaPlayerService( 1232): [42] notify (0x40076db0, 5, 640, 352)
#MediaPlayerService: [33] notify (0x4e4fbe30, 5, 1280, 720)
#MediaPlayerService: [27] notify (0x539209a0, 5, 1280, 720)
p = re.compile(r'.*MediaPlayerService.*:\ \[\d+\]\ notify\ \(\w+,\ 5,\ (\d+),\ (\d+)\)\s*')
resolution = ""
if logcontents !=[]:
for line in logcontents:
match = p.match(line)
if match:
resolution = match.group(1)+"*"+match.group(2)
break
print "Resolution: %s" %resolution
return resolution
def checkVodStopStatus(self):
"""return exit player correct or wrong"""
isExit = False
logcontents = self.openFile()
allstatus = []
stop = r'.*MediaPlayerService.*: \[(\d+)\] stop\s*$'
stop_done = r'.*MediaPlayerService.*: \[\d+\] stop done\s*$'
disconnect = r'.*MediaPlayerService.*: disconnect\(\d+\) from pid \d+\s*$'
disconnect_done= r'.*MediaPlayerService.*: \[\d+\] disconnect done\s*$'
if logcontents != []:
for i in range(len(logcontents)):
if re.compile("|".join([stop,stop_done,disconnect,disconnect_done])).match(logcontents[i]):
allstatus.append(str(i)+" "+logcontents[i])
if allstatus != []:
allstatus.sort()
#for i in allstatus:print i
else:
print "stop progress is null"
return isExit
i=0
while (i < len(allstatus)):
if re.compile(stop).match(allstatus[i]):
flag = 1
pipe = re.compile(stop).match(allstatus[i]).group(1)
for j in range(i+1,len(allstatus)):
if re.compile(r'.*MediaPlayerService.*: \[%s\] stop done\s*$' %pipe).match(allstatus[j]):
flag += 1
i = j+1
for k in range(j+1, len(allstatus)):
if re.compile(r'.*MediaPlayerService.*: disconnect\(%s\) from pid \d+\s*$' %pipe).match(allstatus[k]):
flag += 1
i=k+1
for m in range(k+1, len(allstatus)):
if re.compile(r'.*MediaPlayerService.*: \[%s\] disconnect done\s+$' %pipe).match(allstatus[m]):
flag += 1
i = k+1
break
break
break
else:
i += 1
if flag != 4:
print "exit player error %s" %pipe
isExit = False
else:
isExit = True
print "exit corrected %s" %pipe
else:
i += 1
return isExit
def checkVodPlayStatus(self):
"""return playing is incremental or not"""
incremental = True
logcontents = self.openFile()
positions = []
p = re.compile(r'.*MediaPlayerService.*: \[\d+\] getCurrentPosition = (\d+)\s+$')
if logcontents != []:
for line in logcontents:
match = p.match(line)
if match:
positions.append(int(match.group(1)))
org = copy.copy(positions)
positions.sort()
return org == positions
def checkVodPauseStatus(self):
"""return if player is paused or not"""
logcontents = self.openFile()
pause = []
pause_pattern = r'.*VideoPlayer-VideoPlayer.*: onKeyUp keyCode = 23'
if logcontents != []:
for i in logcontents:
if re.compile(pause_pattern).match(i):
pause.append(i)
else:
print 'logcat is null'
return False
if len(pause) == 0:
print 'not pause'
return False
times = len(pause)/2
print 'pause times: %s' %times
flag = 0
if times == 0:
for j in range(logcontents.index(pause[i-1]), len(logcontents)):
if re.compile(r'.*MediaPlayerService.*: \[\d+\] getCurrentPosition =\d+$').match(j):
flag += 1
break
else:
for i in range(times):
for j in range(logcontents.index(pause[i*2]), logcontents.index(pause[i*2+1])):
if re.compile(r'.*MediaPlayerService.*: \[\d+\] getCurrentPosition =\d+$').match(logcontents[j]):
flag += 1
print 'pause failed'
break
if flag != 0:
print "player cannot pause"
return False
else:
return True
def checkVodHlsSeekStatus(self):
"""return seek status"""
logcontents = self.openFile()
seek = []
pseek = r'.*MediaPlayerService.*: \[(\d+)\] seekTo\((\d+)\)\s*$'
seek_done = r'.*MediaPlayerService.*: \[\d+\] seekTo done\s*$'
seek_notify = r'.*MediaPlayerService.*: \[\d+\] notify \(\w+, 4, 0, 0\)\s*$'
position = r'.*MediaPlayerService.*: \[\d+\] getCurrentPosition = (\d+)\s*$'
if logcontents != []:
for i in range(len(logcontents)):
if re.compile("|".join([pseek,seek_done,seek_notify,position])).match(logcontents[i]):
seek.append(str(i)+" "+logcontents[i])
if seek == []:
print "no seek in %s" %self.filename
seek.sort()
ok = True
i=0
while(i < len(seek)):
matchi = re.compile(pseek).match(seek[i])
if matchi:
pipe = matchi.group(1)
seekto = matchi.group(2)
flag = False
for j in range(i+1,len(seek)):
matchj = re.compile(r'.*MediaPlayerService.*: \[%s\] getCurrentPosition = (\d+)\s*$' %pipe).match(seek[j])
if matchj:
cposition = matchj.group(1)
i = j+1
flag = True
kd = int(seekto) - int(cposition)
# if the src is hls the kd is 25000, if http the kd is 10000
if kd > 25000 or kd < -25000:
print "seekTo(%s), getCurrentPosition = %s" %(seekto,cposition)
ok = False;
break
if not flag:
print "no getCurrentPosition found after seekTo(%s)" %seekto
i = len(seek)
else:
i += 1
return ok
def checkVodHttpSeekStatus(self):
"""return seek status"""
logcontents = self.openFile()
seek = []
pseek = r'.*MediaPlayerService.*: \[(\d+)\] seekTo\((\d+)\)\s*$'
seek_done = r'.*MediaPlayerService.*: \[\d+\] seekTo done\s*$'
seek_notify = r'.*MediaPlayerService.*: \[\d+\] notify \(\w+, 4, 0, 0\)\s*$'
position = r'.*MediaPlayerService.*: \[\d+\] getCurrentPosition = (\d+)\s*$'
if logcontents != []:
for i in range(len(logcontents)):
if re.compile("|".join([pseek,seek_done,seek_notify,position])).match(logcontents[i]):
seek.append(str(i)+" "+logcontents[i])
if seek == []:
print "no seek in %s" %self.filename
seek.sort()
ok = True
i=0
while(i < len(seek)):
matchi = re.compile(pseek).match(seek[i])
if matchi:
pipe = matchi.group(1)
seekto = matchi.group(2)
flag = False
for j in range(i+1,len(seek)):
matchj = re.compile(r'.*MediaPlayerService.*: \[%s\] getCurrentPosition = (\d+)\s*$' %pipe).match(seek[j])
if matchj:
cposition = matchj.group(1)
i = j+1
flag = True
kd = int(seekto) - int(cposition)
# if the src is hls the kd is 25000, if http the kd is 10000
if kd > 10000 or kd < -10000:
print "seekTo(%s), getCurrentPosition = %s" %(seekto,cposition)
ok = False;
break
if not flag:
print "no getCurrentPosition found after seekTo(%s)" %seekto
i = len(seek)
else:
i += 1
return ok
def livePlayProgress(self):
"""return a progress list """
def list_during(re_s, re_e, l):
"""return flag, gap
flag:0: not match any line;1: match start; 2: match end; 3: match start and end"""
r=[]
flag = 0
if l != []:
for i in l:
if re.compile(re_s).match(i):
r.append(i)
flag += 1
break
for i in l:
if re.compile(re_e).match(i):
r.append(i)
flag += 2
break
if flag == 3:
return flag, str(self.calculatorbak(r[0][:18],r[1][:18]))
return flag,'error'
user_press = r'.*Launcher.*:\ T2LauncherActivity\ --\ onKeyDown:\ KeyEvent\ \{\ action=ACTION_DOWN,\ keyCode=KEYCODE_CHANNEL_(UP|DOWN).*'
launcher_get_url = r'.*Launcher.*:\ LivePlayerController\ --\ play\(\)\ -\ uri:(\S+)\ pip:\ false\s*$'
player_get_url = r'.*MediaPlayerService.*:\ \[(\d+)\]\ setDataSource\((\S+)\)'
#player_prepare = r'.*MediaPlayerService.*:\ \[(\d+)\]\ prepareAsync\s*$'
player_post_m3u8 = r'.*DataSource_M3U8.*:\ \[parseURLs\]\ try\ parseURLs=(\S+)'
utp_get_first_request = r'.*\[utp_play_handler\]\ handle_request\ 127\.0\.0\.1:\d+\ \ /play?.*'
utp_request_download_url = r'.*\[downloader\]\ start_download\ http_range:bytes=-\ http://live\.gslb\.letv\.com/gslb.*'
utp_download_first_m3u8 = r'.*\[downloader\]\ start_download\ http_range:bytes=-\ http://.*/desc\.m3u8\?.*'
utp_parser_m3u8_assign_download_task = r'.*\[app\]\ add\ slice.*'
utp_start_download_first_slice = r'.*\[downloader\]\ start_download\ http_range:bytes=0-\d+\ (.*)'
utp_finish_download_first_slice = r'.*\[downloader\]\ on_http_complete.*'
player_finish_parser_m3u8 = r'.*\[init\]\ parseURLs\ Success!\ urlNum\ :\ 3'
player_post_first_ts_slice = r'.*\[init\]\ \[M3u8\]\ post\ cmd\ for\ start\ first\ url:(\S+)'
init_video = r'.*Creating\ Video\ Decoder\ video/avc'
init_video_end = r'.*Video\ Decoder\ instantiante\ end'
init_audio = r'.*Creating\ Audio\ Decoder\ audio.*'
init_audio_end = r'.*Audio\ Decoder\ instantiante\ end'
player_prepared =r'.*MediaPlayerService.*:\ \[(\d+)\]\ notify\ \(\w+,\ 1,\ 0,\ 0\)'
player_start = r'.*MediaPlayerService.*:\ \[(\d+)\]\ start\s*$'
first_frame = r'.*MediaPlayerService.*:\ \[(\d+)\]\ notify\ \(\w+,\ 200,\ 3,\ 0\)'
utp_handle_mirrors = r'.*\[xml_content_parser\]\ handle_mirrors\ http.*'
regex = [user_press,launcher_get_url,player_get_url,player_post_m3u8,utp_request_download_url,player_finish_parser_m3u8, init_video,init_video_end,init_audio,init_audio_end,player_prepared,player_start,first_frame]
regex_first = [utp_download_first_m3u8, utp_parser_m3u8_assign_download_task, utp_start_download_first_slice, player_post_first_ts_slice, utp_handle_mirrors]
#regex_first remove utp_get_first_request
#regex_first remove utp_finish_download_first_slice to match url from utp_start_download_first_slice
len_regex_first = len(regex_first) + 2
rr = "|".join(regex)
progress = []
logcontents = self.openFile()
index = 0
last = index
setDataSourceIndex = 0
if logcontents != []:
for line in logcontents:
if re.compile(user_press).match(line):
index = logcontents.index(line)
break
for line in logcontents[index:]:
if re.compile(first_frame).match(line):
last = logcontents.index(line) + 1
break
for line in logcontents[index:]:
if re.compile(player_get_url).match(line):
setDataSourceIndex = logcontents.index(line)
break
else:
return
for line in logcontents[index:last]:
if re.compile(rr).match(line):
progress.append(line)
first_request = 0
for line in logcontents[setDataSourceIndex:last]:
if re.compile(utp_get_first_request).match(line):
progress.append(line)
first_request = logcontents.index(line)
break
for line in logcontents[first_request:last]:
for i in regex_first:
if re.compile(i).match(line):
progress.append(line)
regex_first.remove(i)
break
#utp_finish_download_first_slice to match url from utp_start_download_first_slice
for line in logcontents[first_request:last]:
match = re.compile(utp_start_download_first_slice).match(line)
if match:
url = match.group(1)
i = logcontents.index(line)
for l in logcontents[i:]:
if url in l and "on_http_complete" in l:
progress.append(l)
break
break
progress.sort()
print "progress:",len(progress)
for i in progress: print i
result = []
if len(progress) != (len(regex) + len_regex_first):
print 'length is not matched'
#return result
# init V/A
av = []
for i in progress:
if re.compile("|".join([init_video,init_video_end,init_audio,init_audio_end])).match(i):
av.append(i)
av.sort()
for i in av: print i
progress.remove(av[1])
progress.remove(av[2])
# end init V/A
for i in progress: print i
result.append("user_press -> first_frame: " + str(list_during(user_press,first_frame,progress)))
result.append("user_press -> launcher_get_url: " + str(list_during(user_press,launcher_get_url,progress)))
result.append("launcher_get_url -> player_get_url: " + str(list_during(launcher_get_url,player_get_url,progress)))
result.append("player_get_url -> player_post_m3u8: " + str(list_during(player_get_url,player_post_m3u8,progress)))
#result.append("player_get_url -> player_prepare: " + str(list_during(player_get_url,player_prepare,progress)))
#result.append("player_prepare -> player_post_m3u8: " + str(list_during(player_prepare,player_post_m3u8,progress)))
result.append("player_post_m3u8 -> utp_get_first_request: " + str(list_during(player_post_m3u8,utp_get_first_request,progress)))
result.append("utp_get_first_request -> utp_request_download_url: " + str(list_during(utp_get_first_request,utp_request_download_url,progress)))
result.append("utp_request_download_url -> utp_download_first_m3u8: " + str(list_during(utp_request_download_url,utp_download_first_m3u8,progress)))
result.append("utp_download_first_m3u8 -> utp_parser_m3u8_assign_download_task: " + str(list_during(utp_download_first_m3u8,utp_parser_m3u8_assign_download_task,progress)))
result.append("utp_parser_m3u8_assign_download_task -> utp_start_download_first_slice: " + str(list_during(utp_download_first_m3u8,utp_start_download_first_slice,progress)))
result.append("utp_start_download_first_slice -> utp_finish_download_first_slice: " + str(list_during(utp_start_download_first_slice,utp_finish_download_first_slice,progress)))
result.append("player_post_m3u8 -> player_finish_parser_m3u8: " + str(list_during(player_post_m3u8,player_finish_parser_m3u8,progress)))
result.append("player_finish_parser_m3u8 -> player_post_first_ts_slice: " + str(list_during(player_finish_parser_m3u8,player_post_first_ts_slice,progress)))
result.append("player_post_first_ts_slice -> init_video/audio: " + str(list_during(player_post_first_ts_slice,"|".join([init_video,init_audio]),progress)))
result.append("init_video/audio -> init_audio/video_end: " + str(list_during("|".join([init_video,init_audio]),"|".join([init_audio_end,init_video_end]),progress)))
result.append("init_audio/video_end -> player_prepared: " + str(list_during("|".join([init_audio_end,init_video_end]),player_prepared,progress)))
result.append("player_prepared -> player_start: " + str(list_during(player_prepared,player_start,progress)))
result.append("player_start -> first_frame: " + str(list_during(player_start,first_frame,progress)))
for i in progress:
if re.compile(utp_handle_mirrors).match(i):
result.append("utp_handle_mirrors: " + str((3, re.search('\[xml_content_parser\]\ handle_mirrors http://[\d\.]+', i).group())))
if re.compile(utp_finish_download_first_slice).match(i):
result.append("utp_finish_download_first_slice_data: " + str((3, re.search('\[downloader\] on_http_complete \(\(\d+,\d+\),\d+\) \(\d+,\d+,\d+\)', i).group())))
if "utp_finish_download_first_slice_data:" not in str(result):
result.append("utp_finish_download_first_slice_data: " + str((0, 'error')))
for i in result: print i
return result
def vodHttpPlayProgress(self):
"""return vod play progress"""
def list_during(re_s, re_e, l):
"""return flag, gap
flag:0: not match any line;1: match start; 2: match end; 3: match start and end"""
r=[]
flag = 0
if l != []:
for i in l:
if re.compile(re_s).match(i):
r.append(i)
flag += 1
break
for i in l:
if re.compile(re_e).match(i):
r.append(i)
flag += 2
break
if flag == 3:
return flag, str(self.calculatorbak(r[0][:18],r[1][:18]))
return flag,'error'
#
user_press = r'.*LETVPlay:\ jumpToPlay\s*$'
tvban_get_url = r'.*LinkShellUtil:\ getURLFromLink\ outPut:(.*$)'
player_get_url = r'.*MediaPlayerService.*:\ \[(\d+)\]\ setDataSource\((\S+)\)'
player_request_download = r'.*HTTPStreamCurl:\ \[HTTPStreamCurl\]\ HTTPStreamCurl Connecting to :.*'
utp_get_first_request = r'.*\[utp_play_handler\] handle_request 127\.0\.0\.1:\d+ bytes=0- /play\?.*'
utp_request_download_url = r'.*\[downloader\]\ start_download\ http_range:bytes=-\ http://g3\.letv\.cn/vod.*'
utp_download_first_data = r'.*\[downloader\]\ start_download\ http_range:bytes=-\ .*'
utp_start_download_first_slice = r'.*\[downloader\]\ start_download\ http_range:bytes=0-\d+ (.*)'
utp_finish_download_first_slice = r'.*\[downloader\]\ on_http_complete.*'
#player_request_success = r'.*StreamContentSource::connect OK !!'
init_video = r'.*Creating\ Video\ Decoder\ video/avc'
init_video_end = r'.*Video\ Decoder\ instantiante\ end'
init_audio = r'.*Creating\ Audio\ Decoder\ audio.*'
init_audio_end = r'.*Audio\ Decoder\ instantiante\ end'
player_prepared =r'.*MediaPlayerService.*:\ \[(\d+)\]\ notify\ \(\w+,\ 1,\ 0,\ 0\)'
player_start = r'.*MediaPlayerService.*:\ \[(\d+)\]\ start\s*$'
first_frame = r'.*MediaPlayerService.*:\ \[(\d+)\]\ notify\ \(\w+,\ 200,\ 3,\ 0\)'
#after user_press
regex = [user_press,tvban_get_url,player_get_url,player_request_download,init_video,init_video_end,init_audio,init_audio_end,player_prepared,player_start,first_frame]
#after utp_get_first_request
#utp_finish_download_first_slice url must match utp_start_download_first_slice
regex_first = [utp_get_first_request,utp_request_download_url,utp_download_first_data, utp_start_download_first_slice]
rr = "|".join(regex)
progress = []
logcontents = self.openFile()
if logcontents == []:
print 'logcat is null'
return []
#find user press
index = 0
for line in logcontents:
if re.compile(user_press).match(line):
index = logcontents.index(line)
break
for line in logcontents[index:]:
if re.compile(rr).match(line):
progress.append(line)
#only one utp_get_first_request after user press
utp_index = 0
for line in logcontents[index:]:
if re.compile(utp_get_first_request).match(line):
utp_index = logcontents.index(line)
break
for line in logcontents[utp_index:]:
for i in regex_first:
if re.compile(i).match(line):
progress.append(line)
regex_first.remove(i)
break
#utp_finish_download_first_slice to match url from utp_start_download_first_slice
for line in logcontents[utp_index:]:
match = re.compile(utp_start_download_first_slice).match(line)
if match:
url = match.group(1)
i = logcontents.index(line)
for l in logcontents[i:]:
if url in l and "on_http_complete" in l:
progress.append(l)
break
break
progress.sort()
print "progress:",len(progress)
#for i in progress: print i
result = []
# init V/A
av = []
for i in progress:
if re.compile("|".join([init_video,init_video_end,init_audio,init_audio_end])).match(i):
av.append(i)
av.sort()
progress.remove(av[1])
progress.remove(av[2])
# end init V/A
for i in progress: print i
result.append("user_press -> first_frame: " + str(list_during(user_press,first_frame,progress)))
result.append("user_press -> tvban_get_url: " + str(list_during(user_press,tvban_get_url,progress)))
result.append("tvban_get_url -> player_get_url: " + str(list_during(tvban_get_url,player_get_url,progress)))
result.append("player_request_download -> utp_get_first_request: " + str(list_during(player_request_download,utp_get_first_request,progress)))
result.append("utp_get_first_request -> utp_request_download_url: " + str(list_during(utp_get_first_request,utp_request_download_url,progress)))
result.append("utp_request_download_url: -> utp_download_first_data: " + str(list_during(utp_request_download_url, utp_download_first_data,progress)))
result.append("utp_start_download_first_slice -> utp_finish_download_first_slice: " + str(list_during(utp_start_download_first_slice,utp_finish_download_first_slice,progress)))
result.append("utp_get_first_request -> init_video/audio: " + str(list_during(utp_get_first_request,"|".join([init_video,init_audio]),progress)))
result.append("init_video/audio -> init_audio/video_end: " + str(list_during("|".join([init_video,init_audio]),"|".join([init_audio_end,init_video_end]),progress)))
result.append("init_audio/video_end -> player_prepared: " + str(list_during("|".join([init_audio_end,init_video_end]),player_prepared,progress)))
result.append("player_prepared -> player_start: " + str(list_during(player_prepared,player_start,progress)))
result.append("player_start -> first_frame: " + str(list_during(player_start,first_frame, progress)))
for i in result: print i
return result
def vodHlsPlayProgress(self):
"""return vod play progress"""
def list_during(re_s, re_e, l):
"""return flag, gap
flag:0: not match any line;1: match start; 2: match end; 3: match start and end"""
r=[]
flag = 0
if l != []:
for i in l:
if re.compile(re_s).match(i):
r.append(i)
flag += 1
break
for i in l:
if re.compile(re_e).match(i):
r.append(i)
flag += 2
break
if flag == 3:
return flag, str(self.calculatorbak(r[0][:18],r[1][:18]))
return flag,'error'
#
key_down = r'.*injectKeyEvent:\ KeyEvent\ \{\ action=ACTION_DOWN,\ keyCode=KEYCODE_DPAD_CENTER.*'
user_press = r'.*LETVPlay:\ jumpToPlay\s*$'
tvban_get_url = r'.*LinkShellUtil:\ getURLFromLink\ outPut:(.*$)'
player_get_url = r'.*MediaPlayerService.*:\ \[(\d+)\]\ setDataSource\((\S+)\)'
player_post_m3u8 = r'.*DataSource_M3U8.*:\ \[parseURLs\]\ try\ parseURLs=(\S+)'
utp_get_first_request = r'.*\[utp_play_handler\]\ handle_request\ 127\.0\.0\.1:\d+\ \ /play?.*'
utp_request_download_url = r'.*\[downloader\]\ start_download\ http_range:bytes=-\ http://g3\.letv\.cn/vod.*'
utp_download_first_m3u8 = r'.*\[downloader\]\ start_download\ http_range:bytes=-\ http://.*/.*\.m3u8\?.*'
utp_start_download_first_slice = r'.*\[downloader\]\ start_download\ http_range:bytes=0-\d+ (.*)'
utp_finish_download_first_slice = r'.*\[downloader\]\ on_http_complete.*'
player_finish_parser_m3u8 = r'.*\[init\]\ parseURLs\ Success!\ urlNum\ :\ 3'
player_post_first_ts_slice = r'.*\[init\]\ \[M3u8\]\ post\ cmd\ for\ start\ first\ url:(\S+)'
init_video = r'.*Creating\ Video\ Decoder\ video/avc'
init_video_end = r'.*Video\ Decoder\ instantiante\ end'
init_audio = r'.*Creating\ Audio\ Decoder\ audio.*'
init_audio_end = r'.*Audio\ Decoder\ instantiante\ end'
player_prepared =r'.*MediaPlayerService.*:\ \[(\d+)\]\ notify\ \(\w+,\ 1,\ 0,\ 0\)'
player_start = r'.*MediaPlayerService.*:\ \[(\d+)\]\ start\s*$'
first_frame = r'.*MediaPlayerService.*:\ \[(\d+)\]\ notify\ \(\w+,\ 200,\ 3,\ 0\)'
#after user_press
regex = [user_press,tvban_get_url,player_get_url,player_post_m3u8,init_video,init_video_end,init_audio,init_audio_end,player_prepared,player_start,first_frame]
#after utp_get_first_request
#utp_finish_download_first_slice url must match utp_start_download_first_slice
regex_first = [utp_get_first_request,utp_request_download_url, utp_download_first_m3u8, utp_start_download_first_slice, player_finish_parser_m3u8, player_post_first_ts_slice]
rr = "|".join(regex)
progress = []
logcontents = self.openFile()
if logcontents == []:
print 'logcat is null'
return []
#find user press
index = 0
for line in logcontents:
if re.compile(user_press).match(line):
index = logcontents.index(line)
break
for line in logcontents[index:]:
if re.compile(rr).match(line):
progress.append(line)
#only one utp_get_first_request after user press
utp_index = 0
for line in logcontents[index:]:
if re.compile(utp_get_first_request).match(line):
utp_index = logcontents.index(line)
break
for line in logcontents[utp_index:]:
for i in regex_first:
if re.compile(i).match(line):
progress.append(line)
regex_first.remove(i)
break
#utp_finish_download_first_slice to match url from utp_start_download_first_slice
for line in logcontents[utp_index:]:
match = re.compile(utp_start_download_first_slice).match(line)
if match:
url = match.group(1)
i = logcontents.index(line)
for l in logcontents[i:]:
if url in l and "on_http_complete" in l:
progress.append(l)
break
break
progress.sort()
print "progress:",len(progress)
#for i in progress: print i
result = []
# init V/A
av = []
for i in progress:
if re.compile("|".join([init_video,init_video_end,init_audio,init_audio_end])).match(i):
av.append(i)
av.sort()
progress.remove(av[1])
progress.remove(av[2])
# end init V/A
for i in progress: print i
result.append("user_press -> first_frame: " + str(list_during(user_press,first_frame,progress)))
result.append("user_press -> tvban_get_url: " + str(list_during(user_press,tvban_get_url,progress)))
result.append("tvban_get_url -> player_get_url: " + str(list_during(tvban_get_url,player_get_url,progress)))
result.append("player_get_url -> player_post_m3u8: " + str(list_during(player_get_url,player_post_m3u8,progress)))
#result.append("player_get_url -> player_prepare: " + str(list_during(player_get_url,player_prepare,progress)))
#result.append("player_prepare -> player_post_m3u8: " + str(list_during(player_prepare,player_post_m3u8,progress)))
result.append("player_post_m3u8 -> utp_get_first_request: " + str(list_during(player_post_m3u8,utp_get_first_request,progress)))
result.append("utp_get_first_request -> utp_request_download_url: " + str(list_during(utp_get_first_request,utp_request_download_url,progress)))
result.append("utp_request_download_url -> utp_download_first_m3u8: " + str(list_during(utp_request_download_url,utp_download_first_m3u8,progress)))
result.append("utp_download_first_m3u8 -> utp_start_download_first_slice: " + str(list_during(utp_download_first_m3u8,utp_start_download_first_slice,progress)))
result.append("utp_start_download_first_slice -> utp_finish_download_first_slice: " + str(list_during(utp_start_download_first_slice,utp_finish_download_first_slice,progress)))
result.append("player_post_m3u8 -> player_finish_parser_m3u8: " + str(list_during(player_post_m3u8,player_finish_parser_m3u8,progress)))
result.append("player_finish_parser_m3u8 -> player_post_first_ts_slice: " + str(list_during(player_finish_parser_m3u8,player_post_first_ts_slice,progress)))
result.append("player_post_first_ts_slice -> init_video/audio: " + str(list_during(player_post_first_ts_slice,"|".join([init_video,init_audio]),progress)))
result.append("init_video/audio -> init_audio/video_end: " + str(list_during("|".join([init_video,init_audio]),"|".join([init_audio_end,init_video_end]),progress)))
result.append("init_audio/video_end -> player_prepared: " + str(list_during("|".join([init_audio_end,init_video_end]),player_prepared,progress)))
result.append("player_prepared -> player_start: " + str(list_during(player_prepared,player_start,progress)))
result.append("player_start -> first_frame: " + str(list_during(player_start,first_frame,progress)))
for i in result: print i
return result
def playerProgress(self):
"""return a list includes switch time and each progress time """
user_press = r'.*Launcher.*:\ T2LauncherActivity\ --\ onKeyDown:\ KeyEvent\ \{\ action=ACTION_DOWN,\ keyCode=KEYCODE_0.*'
launcher_get_url = r'.*Launcher.*:\ LivePlayerController\ --\ play\(\)\ -\ uri:(\S+)\ pip:\ false\s*$'
player_get_url = r'.*MediaPlayerService.*:\ \[(\d+)\]\ setDataSource\((\S+)\)'
player_get_app_init_time = r'.*MediaPlayerService.*:\s+request-time\ :\ (\d+)\s*$'
player_prepare = r'.*MediaPlayerService.*:\ \[(\d+)\]\ prepareAsync\s*$'
post_m3u8 = r'.*DataSource_M3U8.*:\ \[M3U8\]\ try\ parseURLs=(\S+)'
get_first_m3u8 = r'.*DataSource_M3U8.*:\s+mHttpResponseCode\ =\ 200\s*$'
post_first_ts_slice = r'.*DataSource_M3U8.*:\ \[M3U8\]----->post\ cmd\ for\ start\ first\ url:(\S+),\ knowedFileSize:0'
player_prepared =r'.*MediaPlayerService.*:\ \[(\d+)\]\ notify\ \(\w+,\ 1,\ 0,\ 0\)'
player_start = r'.*MediaPlayerService.*:\ \[(\d+)\]\ start\s*$'
player_start_done = r'.*MediaPlayerService.*:\ \[(\d+)\]\ start\ done\s*$'
first_frame = r'.*MediaPlayerService.*:\ \[(\d+)\]\ notify\ \(\w+,\ 200,\ 3,\ 0\)'
start_loading = r'.*MediaPlayerService.*:\ \[(\d+)\]\ notify\ \(\w+,\ 200,\ 701,\ 0\)\s*$'
end_loading = r'.*MediaPlayerService.*:\ \[(\d+)\]\ notify\ \(\w+,\ 200,\ 702,\ 0\)\s*$'
player_stop = r'.*MediaPlayerService.*:\ \[(\d+)\]\ stop\s*$'
player_stop_done = r'.*MediaPlayerService.*:\ \[(\d+)\]\ stop\ done\s*$'
player_release = r'.*MediaPlayerService.*: disconnect\((\d+)\)\ from\ pid\ \d+\s*$'
player_release_done = r'.*MediaPlayerService.*:\ \[(\d+)\]\ disconnect\ done\s*$'
regex = [user_press,launcher_get_url,player_get_url, player_get_app_init_time, player_prepare, post_m3u8,get_first_m3u8, post_first_ts_slice,\
player_prepared, player_start,player_start_done, first_frame, start_loading, end_loading, player_stop,player_stop_done, player_release, player_release_done]
rr = "|".join(regex)
progress = []
logcontents = self.openFile()
index = 0
last = 0
if logcontents != []:
for line in logcontents:
if re.compile(user_press).match(line):
index = logcontents.index(line)
last = index
break
for line in logcontents[index:]:
if re.compile(first_frame).match(line):
last = logcontents.index(line)+1
break
else:
return
for line in logcontents[index:last]:
if re.compile(rr).match(line):
progress.append(line)
during = []
result = []
for line in progress:
#print line
if re.compile("|".join([user_press, first_frame])).match(line):
during.append(line)
if len(during)%2 !=0 or len(during)==0:
print "not start in the end"
else:
i=0
while i < len(during):
countTime = self.calculatorbak(during[i][:18], during[i+1][:18])
result.append("Time:"+str(countTime))
onep = progress[progress.index(during[i]):progress.index(during[i+1])+1]
onesp = []
if len(onep) != len(regex):
for rep in regex:
for each in onep:
if re.compile(rep).match(each):
onesp.append(each)
break
onesp.sort()
else:
onesp = onep
#print exceed time line
if countTime > 2000:
for ll in onesp: print ll
#while the output log grogress is right
if len(onesp) == len(regex):
j=0
while j < len(onesp)-1:
result.append(self.calculatorbak(onesp[j][:18], onesp[j+1][:18]))
j += 1
#while the output log is more then range
else:
result.append("ERROR")
print "ERROR"
i += 2
return result
def openFile(self):
fp = open(self.filename, "r+")
contents=[]
try:
contents = fp.readlines();
fp.close()
except Exception, e:
fp.close()
print e
return contents
def calculatorbak(self, start_str, end_str):
"""
params: time format like 12-19 17:31:34.166
return: int mseconds
"""
def timeToMS(stri):
stri_a = stri.split(' ')[0]
stri_b = stri.split(" ")[1]
M = int(stri_a.split("-")[0].strip())
d = int(stri_a.split("-")[1].strip())
h = int(stri_b.split(":")[0])
m = int(stri_b.split(":")[1])
s = int(stri_b.split(":")[2].split(".")[0])
ms = int(stri_b.split(".")[1])
return ms+s*1000+m*60*1000+h*60*60*1000+d*24*60*60*1000
return timeToMS(end_str) - timeToMS(start_str)
def calculator(self, start_str, end_str):
"""
params: time format like 12-19 17:31:34.166
return: int mseconds
"""
year = datetime.datetime.today().year
start = start_str.split('.')
end = end_str.split('.')
start[0] = str(year) + '-' + start[0]
end [0] = str(year) + '-' + end[0]
toTime_start = time.mktime(time.strptime(start[0], '%Y-%m-%d %H:%M:%S'))
toTime_end = time.mktime(time.strptime(end[0], '%Y-%m-%d %H:%M:%S'))
s = int(toTime_end - toTime_start)
if int(end[1]) < int(start[1]):
s -= 1
end[1] = '1' + end[1]
ms = int(end[1])*0.001 - int(start[1])*0.001
return int(s*1000+ms*1000)
class PlayFiles():
def __init__(self, a, playtime):
self.a = a
self.play_urls=[]
self.error_urls = []
self.start_over = 1
self.i =0
self.outloop = 1
self.playtime = playtime
def getPlayFiles(self, Media_Type):
media_str = self.a.device.sh('busybox find /storage/external_storage/sda1/QA-Streams -name *.' + Media_Type)
#media_str = self.a.device.sh('busybox find /mnt/usb/ -name *.' + Media_Type)
#media_str += self.a.device.sh('find /storage -name *.' + Media_Type)
media_list = media_str.split('\r\n')
l = len(media_list)
for i in range(0, l-1):
self.play_urls.append(media_list[i]) #Add all local videos to list web_urls.
def ifImagePlayOrCompleted(self, displayID):
try:
self.a.input.down()
self.a.input.center()
time.sleep(5)
w = self.a.ui.waitfor( anyof = [
self.a.ui.widgetspec(id='player_error_iv'),
self.a.ui.widgetspec(id=displayID),
self.a.ui.widgetspec( text='Cannot play video'),
self.a.ui.widgetspec( id='alertTitle'),
self.a.ui.widgetspec(id='video'),
self.a.ui.widgetspec(id='app_home'),
self.a.ui.widgetspec(text='Wait'),
self.a.ui.widgetspec(id='message', text=re.compile(r'(^Unfortunately.*stopped\.$)'))
])
w_text=w.text()
w_id = w.id()
if w_id==displayID :
self.a.input.right(5)
time.sleep(1)
self.a.input.left(3)
time.sleep(1)
self.a.input.center(2)
time.sleep(1)
return True
elif w_id=='player_error_iv' :
self.a.input.back(2)
return False
elif w_id=='app_home' :
return False
elif w_id=='alertTitle':
self.a.input.right()
self.a.input.center()
w=self.a.ui.screen()
time.sleep(1)
if "alertTitle" in str(w.ids()):
self.a.input.right()
self.a.input.center()
return False
elif w_text=='Wait':
self.a.input.down()
self.a.input.right() #Choose resumeplaying button
self.a.input.center()
self.error_urls.append('ANR happened while playing ')
self.error_urls.append(self.play_urls[self.i])
raise Exception
elif w_id=='message':
self.a.input.down()