OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 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 """Seek performance testing for <video>. | |
7 | |
8 Calculates the short and long seek times for different video formats on | |
9 different network constraints. | |
10 """ | |
11 | |
12 import logging | |
13 import os | |
14 | |
15 import pyauto_media | |
16 import pyauto_utils | |
17 | |
18 import cns_test_base | |
19 import worker_thread | |
20 | |
21 # Number of threads to use during testing. | |
22 _TEST_THREADS = 3 | |
23 | |
24 # HTML test path; relative to src/chrome/test/data. | |
25 _TEST_HTML_PATH = os.path.join('media', 'html', 'media_seek.html') | |
26 | |
27 # The media files used for testing. | |
28 # Path under CNS root folder (pyauto_private/media). | |
29 _TEST_VIDEOS = [ | |
30 os.path.join('crowd', name) for name in | |
31 ['crowd2160.webm', 'crowd1080.webm', 'crowd360.webm', 'crowd2160.ogv', | |
32 'crowd.wav'], | |
33 os.path.join('dartmoor', 'dartmoor.ogg')] | |
DaleCurtis
2012/04/20 22:37:06
?
shadi
2012/04/21 00:32:46
Done.
| |
34 | |
35 # Constraints to run tests on. | |
36 _TESTS_TO_RUN = [ | |
37 cns_test_base.Cable, | |
38 cns_test_base.Wifi, | |
39 cns_test_base.NoConstraints] | |
40 | |
41 | |
42 class SeekWorkerThread(worker_thread.WorkerThread): | |
43 """Worker thread. Runs a test for each task in the queue.""" | |
44 | |
45 SEEK_TEST_CASES = { | |
46 'short_seek': 0, | |
47 'long_seek': 1, | |
48 'buffered_seek': 2 | |
49 } | |
50 CACHED_STATE = { | |
51 'uncached': 0, | |
52 'cached': 1 | |
53 } | |
54 | |
55 def RunTask(self, unique_url, task): | |
56 """Runs the specific task on the url given. | |
57 | |
58 It is assumed that a tab with the unique_url is already loaded. | |
59 Args: | |
60 unique_url: A unique identifier of the test page. | |
61 task: A (series_name, settings, file_name) tuple to run the test on. | |
62 """ | |
63 series_name, settings, file_name = task | |
64 | |
65 video_url = cns_test_base.GetFileURL( | |
66 file_name, bandwidth=settings[0], latency=settings[1], | |
67 loss=settings[2]) | |
68 | |
69 # Start the test! | |
70 self.CallJavascriptFunc('startTest', [video_url], unique_url) | |
71 | |
72 logging.debug('Running perf test for %s.', video_url) | |
73 # Time out is dependent on (seeking time * iterations). For 3 iterations per | |
DaleCurtis
2012/04/20 22:37:06
Style in the file is 2 spaces after a period sadly
| |
74 # seek we get total of 18 seeks per test. We expect buffered and | |
75 # cached seeks to be fast. Thus an average of 10secs per seek is chosen. | |
DaleCurtis
2012/04/20 22:37:06
"Thus..." doesn't really follow from what you've s
shadi
2012/04/21 00:32:46
Done.
| |
76 if not self.WaitUntil(self.GetDOMValue, args=['endTest', unique_url], | |
77 retry_sleep=5, timeout=180, debug=False): | |
78 error_msg = 'Seek tests timed out.' | |
79 else: | |
80 error_msg = self.GetDOMValue('errorMsg', unique_url) | |
81 | |
82 if error_msg: | |
83 logging.error('Error while running the tests: %s.', error_msg) | |
84 | |
85 graph_name = series_name + '_' + os.path.basename(file_name) | |
86 for state, state_num in SeekWorkerThread.CACHED_STATE.iteritems(): | |
87 for seek_case, seek_num in SeekWorkerThread.SEEK_TEST_CASES.iteritems(): | |
88 if error_msg: | |
89 results = [-1] | |
90 else: | |
91 results = [float(value) for value in self.GetDOMValue( | |
92 "seekRecords[%s][%s].join(',')" % (state_num, seek_num), | |
93 unique_url).split(',')] | |
94 pyauto_utils.PrintPerfResult('seek', '%s_%s_%s' % | |
95 (state, seek_case, graph_name), | |
96 results, 'ms') | |
97 | |
98 | |
99 class MediaSeekPerfTest(cns_test_base.CNSTestBase): | |
100 """PyAuto test container. See file doc string for more information.""" | |
101 | |
102 def testMediaSeekPerformance(self): | |
103 """Launches HTML test which plays each video and records seek stats.""" | |
104 tasks = cns_test_base.CreateCNSPerfTasks(_TESTS_TO_RUN, _TEST_VIDEOS) | |
105 worker_thread.RunWorkerThreads(self, SeekWorkerThread, tasks, _TEST_THREADS, | |
106 _TEST_HTML_PATH) | |
107 | |
108 | |
109 if __name__ == '__main__': | |
110 pyauto_media.Main() | |
OLD | NEW |