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 ['crowd1080.webm', 'crowd720.webm', 'crowd480.webm', 'crowd360.webm']] | |
32 | |
33 # Constraints to run tests on. | |
34 _TESTS_TO_RUN = [ | |
35 cns_test_base.Cable, | |
36 cns_test_base.Wifi, | |
37 cns_test_base.NoConstraints] | |
38 | |
39 | |
40 class SeekWorkerThread(worker_thread.WorkerThread): | |
41 """Worker thread. Runs a test for each task in the queue.""" | |
42 | |
43 Seek_Test_Case = { | |
DaleCurtis
2012/04/19 19:42:10
No_Naming_Please. :) SEEK_TEST_CASES and CACHED_ST
shadi
2012/04/20 00:17:47
It is tricky! Plus the names here are used for gra
DaleCurtis
2012/04/20 22:37:06
How about instead of constants you have the follow
shadi
2012/04/21 00:32:46
I think I got what you are saying, but how can the
| |
44 'short_seek': 0, | |
45 'long_seek': 1, | |
46 'buffered_seek': 2 | |
47 } | |
48 Cached_State = { | |
49 'un_cached': 0, | |
50 'cached': 1 | |
51 } | |
52 | |
53 def RunTask(self, unique_url, task): | |
54 """Runs the specific task on the url given. | |
55 | |
56 It is assumed that a tab with the unique_url is already loaded. | |
57 Args: | |
58 unique_url: A unique identifier of the test page. | |
59 task: A (series_name, settings, file_name) tuple to run the test on. | |
60 """ | |
61 series_name, settings, file_name = task | |
62 | |
63 video_url = cns_test_base.GetFileURL( | |
64 file_name, bandwidth=settings[0], latency=settings[1], | |
65 loss=settings[2]) | |
66 | |
67 # Start the test! | |
68 self.CallJavascriptFunc('startTest', [video_url], unique_url) | |
69 | |
70 logging.debug('Running perf test for %s.', video_url) | |
71 self.WaitUntil(self.GetDOMValue, args=['endTest', unique_url], | |
72 retry_sleep=5, timeout=180, debug=False) | |
73 error_msg = self.GetDOMValue('errorMsg', unique_url) | |
74 | |
75 if error_msg: | |
76 logging.error('Error while running the tests: %s.', error_msg) | |
77 else: | |
78 graph_name = series_name + '_' + os.path.basename(file_name) | |
79 for state, state_num in SeekWorkerThread.Cached_State.iteritems(): | |
80 for seek_case, seek_num in SeekWorkerThread.Seek_Test_Case.iteritems(): | |
81 results = [float(value) for value in self.GetDOMValue( | |
82 "seekRecords[%s][%s].join(',')" % (state_num, seek_num), | |
83 unique_url).split(',')] | |
84 pyauto_utils.PrintPerfResult('seek', '%s_%s_%s' % | |
85 (state, seek_case, graph_name), | |
86 results, 'ms') | |
87 | |
88 | |
89 class MediaSeekPerfTest(cns_test_base.CNSTestBase): | |
90 """PyAuto test container. See file doc string for more information.""" | |
91 | |
92 def testMediaSeekPerformance(self): | |
93 """Launches HTML test which plays each video and records seek stats.""" | |
94 tasks = cns_test_base.CreateCNSPerfTasks(_TESTS_TO_RUN, _TEST_VIDEOS) | |
95 worker_thread.RunWorkerThreads(self, SeekWorkerThread, tasks, _TEST_THREADS, | |
96 _TEST_HTML_PATH) | |
97 | |
98 | |
99 if __name__ == '__main__': | |
100 pyauto_media.Main() | |
OLD | NEW |