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 = [os.path.join('dartmoor', 'dartmoor.ogg')] |
| 30 _TEST_VIDEOS.extend(os.path.join('crowd', name) for name in |
| 31 ['crowd2160.webm', 'crowd1080.webm', 'crowd360.webm', |
| 32 'crowd2160.ogv', 'crowd1080.ogv', 'crowd360.ogv', |
| 33 'crowd.wav']) |
| 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 def RunTask(self, unique_url, task): |
| 46 """Runs the specific task on the url given. |
| 47 |
| 48 It is assumed that a tab with the unique_url is already loaded. |
| 49 Args: |
| 50 unique_url: A unique identifier of the test page. |
| 51 task: A (series_name, settings, file_name) tuple to run the test on. |
| 52 """ |
| 53 series_name, settings, file_name = task |
| 54 |
| 55 video_url = cns_test_base.GetFileURL( |
| 56 file_name, bandwidth=settings[0], latency=settings[1], |
| 57 loss=settings[2]) |
| 58 |
| 59 # Start the test! |
| 60 self.CallJavascriptFunc('startTest', [video_url], unique_url) |
| 61 |
| 62 logging.debug('Running perf test for %s.', video_url) |
| 63 # Time out is dependent on (seeking time * iterations). For 3 iterations |
| 64 # per seek we get total of 18 seeks per test. We expect buffered and |
| 65 # cached seeks to be fast. Through experimentation an average of 10 secs |
| 66 # per seek was found to be adequate. |
| 67 if not self.WaitUntil(self.GetDOMValue, args=['endTest', unique_url], |
| 68 retry_sleep=5, timeout=180, debug=False): |
| 69 error_msg = 'Seek tests timed out.' |
| 70 else: |
| 71 error_msg = self.GetDOMValue('errorMsg', unique_url) |
| 72 |
| 73 if error_msg: |
| 74 logging.error('Error while running the tests: %s.', error_msg) |
| 75 |
| 76 cached_states = self.GetDOMValue( |
| 77 "Object.keys(CachedState).join(',')", unique_url).split(',') |
| 78 seek_test_cases = self.GetDOMValue( |
| 79 "Object.keys(SeekTestCase).join(',')", unique_url).split(',') |
| 80 |
| 81 graph_name = series_name + '_' + os.path.basename(file_name) |
| 82 for state in cached_states: |
| 83 for seek_case in seek_test_cases: |
| 84 if error_msg: |
| 85 results = [-1] |
| 86 else: |
| 87 results = [float(value) for value in self.GetDOMValue( |
| 88 "seekRecords[CachedState.%s][SeekTestCase.%s].join(',')" % |
| 89 (state, seek_case), unique_url).split(',')] |
| 90 pyauto_utils.PrintPerfResult('seek', '%s_%s_%s' % |
| 91 (state, seek_case, graph_name), |
| 92 results, 'ms') |
| 93 |
| 94 |
| 95 class MediaSeekPerfTest(cns_test_base.CNSTestBase): |
| 96 """PyAuto test container. See file doc string for more information.""" |
| 97 |
| 98 def testMediaSeekPerformance(self): |
| 99 """Launches HTML test which plays each video and records seek stats.""" |
| 100 tasks = cns_test_base.CreateCNSPerfTasks(_TESTS_TO_RUN, _TEST_VIDEOS) |
| 101 worker_thread.RunWorkerThreads(self, SeekWorkerThread, tasks, _TEST_THREADS, |
| 102 _TEST_HTML_PATH) |
| 103 |
| 104 |
| 105 if __name__ == '__main__': |
| 106 pyauto_media.Main() |
OLD | NEW |