| 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 import posixpath | |
| 15 | |
| 16 import pyauto_media | |
| 17 import pyauto_utils | |
| 18 | |
| 19 import cns_test_base | |
| 20 import worker_thread | |
| 21 | |
| 22 # Number of threads to use during testing. | |
| 23 _TEST_THREADS = 3 | |
| 24 | |
| 25 # HTML test path; relative to src/chrome/test/data. | |
| 26 _TEST_HTML_PATH = os.path.join('media', 'html', 'media_seek.html') | |
| 27 | |
| 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']] | |
| 32 | |
| 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']]) | |
| 36 | |
| 37 # Constraints to run tests on. | |
| 38 _TESTS_TO_RUN = [ | |
| 39 cns_test_base.Wifi, | |
| 40 cns_test_base.NoConstraints] | |
| 41 | |
| 42 | |
| 43 class SeekWorkerThread(worker_thread.WorkerThread): | |
| 44 """Worker thread. Runs a test for each task in the queue.""" | |
| 45 | |
| 46 def RunTask(self, unique_url, task): | |
| 47 """Runs the specific task on the url given. | |
| 48 | |
| 49 It is assumed that a tab with the unique_url is already loaded. | |
| 50 Args: | |
| 51 unique_url: A unique identifier of the test page. | |
| 52 task: A (series_name, settings, file_name) tuple to run the test on. | |
| 53 """ | |
| 54 series_name, settings, file_name = task | |
| 55 | |
| 56 video_url = cns_test_base.GetFileURL( | |
| 57 file_name, bandwidth=settings[0], latency=settings[1], | |
| 58 loss=settings[2]) | |
| 59 | |
| 60 # Start the test! | |
| 61 self.CallJavascriptFunc('startTest', [video_url], unique_url) | |
| 62 | |
| 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.' | |
| 71 else: | |
| 72 error_msg = self.GetDOMValue('errorMsg', unique_url) | |
| 73 | |
| 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(',') | |
| 78 | |
| 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) | |
| 85 if values: | |
| 86 results = [float(value) for value in values.split(',')] | |
| 87 else: | |
| 88 results = [] | |
| 89 pyauto_utils.PrintPerfResult('seek_%s_%s' % (state.lower(), | |
| 90 seek_case.lower()), graph_name, | |
| 91 results, 'ms') | |
| 92 | |
| 93 if error_msg: | |
| 94 logging.error('Error while running %s: %s.', graph_name, error_msg) | |
| 95 return False | |
| 96 else: | |
| 97 return True | |
| 98 | |
| 99 | |
| 100 class MediaSeekPerfTest(cns_test_base.CNSTestBase): | |
| 101 """PyAuto test container. See file doc string for more information.""" | |
| 102 | |
| 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', | |
| 106 *args, **kwargs) | |
| 107 | |
| 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.') | |
| 114 | |
| 115 | |
| 116 if __name__ == '__main__': | |
| 117 pyauto_media.Main() | |
| OLD | NEW |