OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """Performance test for the HTML5 media tag. | |
7 | |
8 This PyAuto powered script plays media (video or audio) files using the HTML5 | |
9 tag embedded in an HTML file (specified in the GetPlayerHTMLFileName() method) | |
10 and measures decoder's side frames per second (FPS), which is generated by the | |
11 HTML file. The parameters needed to run this test are passed in the form of | |
12 environment variables (such as the number of runs). media_perf_runner.py | |
13 is used for generating these variables (PyAuto does not support direct | |
14 parameters). | |
15 """ | |
16 | |
17 import pyauto_media | |
18 from media_test_base import MediaTestBase | |
19 from ui_perf_test_measure_thread import UIPerfTestMeasureThread | |
20 from ui_perf_test_utils import UIPerfTestUtils | |
21 | |
22 | |
23 class MediaPerformanceTest(MediaTestBase): | |
24 """Tests for basic media performance.""" | |
25 # The following parallel lists specify data type names, their | |
26 # corresponding units, and their corresponding trace names | |
27 # (used in the perf graph legend). | |
28 FPS_NAME_LIST = ['playertime', 'clocktime', 'fps', | |
29 'clockfps', 'droppedframe'] | |
30 FPS_UNIT_LIST = ['sec', 'sec', 'count', 'count', 'count'] | |
31 FPS_TRACE_LIST = ['t', 't', 'c', 'c', 'c'] | |
32 | |
33 # Instance variables that are shared across methods. | |
34 run_counter = 0 | |
35 chrome_renderer_process_infos = [] | |
36 measure_thread = None | |
37 all_fps_infos = [] | |
38 | |
39 def testHTML5MediaTag(self): | |
40 """Test the HTML5 media tag.""" | |
41 MediaTestBase.ExecuteTest(self) | |
42 | |
43 def _GetFPSLog(self): | |
44 """Get the FPS log from the DOM tree that is produced by player.html. | |
45 | |
46 Returns: | |
47 a string FPS log from the DOM tree. | |
48 """ | |
49 log_location = 'document.getElementById(\'history\').innerHTML' | |
50 return self.GetDOMValue(log_location).strip() | |
51 | |
52 def PreAllRunsProcess(self): | |
53 """A method to execute before all runs.""" | |
54 MediaTestBase.PreAllRunsProcess(self) | |
55 self.all_fps_infos = [] | |
56 | |
57 def PostAllRunsProcess(self): | |
58 """A method to execute after all runs.""" | |
59 MediaTestBase.PostAllRunsProcess(self) | |
60 # Print FPS related data. | |
61 if self.all_fps_infos: | |
62 print UIPerfTestUtils.PrintMeasuredData( | |
63 measured_data_list=self.all_fps_infos, | |
64 measured_data_name_list=self.FPS_NAME_LIST, | |
65 measured_data_unit_list=self.FPS_UNIT_LIST, | |
66 remove_first_result=True, parameter_string=self.parameter_str, | |
67 trace_list=self.FPS_TRACE_LIST, | |
68 reference_build=self.reference_build, | |
69 display_filter=['playertime', 'fps', 'droppedframe']) | |
70 | |
71 def PostEachRunProcess(self, run_counter): | |
72 """A method to execute after each run. | |
73 | |
74 Terminates the measuring thread and records the measurement in | |
75 measure_thread.chrome_renderer_process_info. | |
76 | |
77 Args: | |
78 run_counter: one assigned number that is generated at each run. This is | |
79 used to store the results in result list |all_fps_infos|. | |
80 """ | |
81 MediaTestBase.PostEachRunProcess(self, run_counter) | |
82 all_fps_string = self._GetFPSLog() | |
83 fps_string_list = all_fps_string.split('<br>') | |
84 fps_list = [] | |
85 # Do the paring of the FPS string. |fps_string_list| contains multiple | |
86 # rows. | |
87 for fps_string in fps_string_list: | |
88 if fps_string: | |
89 fps_list_element_list = [] | |
90 # Each row has data which is delimited by ' '. | |
91 for elem in fps_string.split(' '): | |
92 # All data is in float-based strings. | |
93 fps_list_element_list.append(float(elem)) | |
94 fps_list.append(fps_list_element_list) | |
95 self.all_fps_infos.append(fps_list) | |
96 | |
97 def GetPlayerHTMLFileName(self): | |
98 """A method to get the player HTML file name.""" | |
99 return 'media_fps.html' | |
100 | |
101 | |
102 if __name__ == '__main__': | |
103 pyauto_media.Main() | |
OLD | NEW |