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.
6 """Seek performance testing for <video>.
8 Calculates the short and long seek times for different video formats on
9 different network constraints.
22 # Number of threads to use during testing.
25 # HTML test path; relative to src/chrome/test/data.
26 _TEST_HTML_PATH = os.path.join('media', 'html', 'media_seek.html')
28 # The media files used for testing.
29 # Path under CNS root folder (pyauto_private/media).
30 _TEST_VIDEOS = [posixpath.join('dartmoor', name) for name in
31 ['dartmoor2.mp3', 'dartmoor2.wav']]
33 _TEST_VIDEOS.extend([posixpath.join('crowd', name) for name in
34 ['crowd1080.webm', 'crowd1080.ogv', 'crowd1080.mp4',
35 'crowd360.webm', 'crowd360.ogv', 'crowd360.mp4']])
37 # Constraints to run tests on.
40 cns_test_base.NoConstraints]
43 class SeekWorkerThread(worker_thread.WorkerThread):
44 """Worker thread. Runs a test for each task in the queue."""
46 def RunTask(self, unique_url, task):
47 """Runs the specific task on the url given.
49 It is assumed that a tab with the unique_url is already loaded.
51 unique_url: A unique identifier of the test page.
52 task: A (series_name, settings, file_name) tuple to run the test on.
54 series_name, settings, file_name = task
56 video_url = cns_test_base.GetFileURL(
57 file_name, bandwidth=settings[0], latency=settings[1],
61 self.CallJavascriptFunc('startTest', [video_url], unique_url)
63 logging.debug('Running perf test for %s.', video_url)
64 # Time out is dependent on (seeking time * iterations). For 3 iterations
65 # per seek we get total of 18 seeks per test. We expect buffered and
66 # cached seeks to be fast. Through experimentation an average of 10 secs
67 # per seek was found to be adequate.
68 if not self.WaitUntil(self.GetDOMValue, args=['endTest', unique_url],
69 retry_sleep=5, timeout=300, debug=False):
70 error_msg = 'Seek tests timed out.'
72 error_msg = self.GetDOMValue('errorMsg', unique_url)
74 cached_states = self.GetDOMValue(
75 "Object.keys(CachedState).join(',')", unique_url).split(',')
76 seek_test_cases = self.GetDOMValue(
77 "Object.keys(SeekTestCase).join(',')", unique_url).split(',')
79 graph_name = series_name + '_' + os.path.basename(file_name)
80 for state in cached_states:
81 for seek_case in seek_test_cases:
82 values = self.GetDOMValue(
83 "seekRecords[CachedState.%s][SeekTestCase.%s].join(',')" %
84 (state, seek_case), unique_url)
86 results = [float(value) for value in values.split(',')]
89 pyauto_utils.PrintPerfResult('seek_%s_%s' % (state.lower(),
90 seek_case.lower()), graph_name,
94 logging.error('Error while running %s: %s.', graph_name, error_msg)
100 class MediaSeekPerfTest(cns_test_base.CNSTestBase):
101 """PyAuto test container. See file doc string for more information."""
103 def __init__(self, *args, **kwargs):
104 """Initialize the CNSTestBase with socket_timeout = 60 secs."""
105 cns_test_base.CNSTestBase.__init__(self, socket_timeout='60',
108 def testMediaSeekPerformance(self):
109 """Launches HTML test which plays each video and records seek stats."""
110 tasks = cns_test_base.CreateCNSPerfTasks(_TESTS_TO_RUN, _TEST_VIDEOS)
111 if worker_thread.RunWorkerThreads(self, SeekWorkerThread, tasks,
112 _TEST_THREADS, _TEST_HTML_PATH):
113 self.fail('Some tests failed to run as expected.')
116 if __name__ == '__main__':