• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import errno
6import hashlib
7import logging
8import os
9
10from autotest_lib.client.bin import utils
11from autotest_lib.client.common_lib import error
12from autotest_lib.client.common_lib import file_utils
13from autotest_lib.client.cros import chrome_binary_test
14
15from contextlib import closing
16
17DOWNLOAD_BASE = 'http://commondatastorage.googleapis.com/chromiumos-test-assets-public/'
18BINARY = 'video_encode_accelerator_unittest'
19
20def _remove_if_exists(filepath):
21    try:
22        os.remove(filepath)
23    except OSError, e:
24        if e.errno != errno.ENOENT: # no such file
25            raise
26
27
28def _download_video(download_path, local_file):
29    url = '%s%s' % (DOWNLOAD_BASE, download_path)
30    logging.info('download "%s" to "%s"', url, local_file)
31
32    file_utils.download_file(url, local_file)
33
34    with open(local_file, 'r') as r:
35        md5sum = hashlib.md5(r.read()).hexdigest()
36        if md5sum not in download_path:
37            raise error.TestError('unmatched md5 sum: %s' % md5sum)
38
39
40class video_VideoEncodeAccelerator(chrome_binary_test.ChromeBinaryTest):
41    """
42    This test is a wrapper of the chrome unittest binary:
43    video_encode_accelerator_unittest.
44    """
45
46    version = 1
47
48
49    @chrome_binary_test.nuke_chrome
50    def run_once(self, in_cloud, streams, profile):
51        """Runs video_encode_accelerator_unittest on the streams.
52
53        @param streams: The test streams for video_encode_accelerator_unittest.
54        @param profile: The profile to encode into.
55
56        @raises error.TestFail for video_encode_accelerator_unittest failures.
57        """
58
59        last_test_failure = None
60        for path, width, height, bit_rate in streams:
61            if in_cloud:
62                input_path = os.path.join(self.tmpdir, path.split('/')[-1])
63                _download_video(path, input_path)
64            else:
65                input_path = os.path.join(self.cr_source_dir, path)
66
67            output_path = os.path.join(self.tmpdir,
68                    '%s.out' % input_path.split('/')[-1])
69
70            cmd_line = '--test_stream_data="%s:%s:%s:%s:%s:%s"' % (
71                    input_path, width, height, profile, output_path, bit_rate)
72            if utils.is_freon():
73                cmd_line += ' --ozone-platform=gbm'
74            try:
75                self.run_chrome_test_binary(BINARY, cmd_line, as_chronos=False)
76            except error.TestFail as test_failure:
77                # Continue to run the remaining test streams and raise
78                # the last failure after finishing all streams.
79                logging.exception('error while encoding %s', input_path)
80                last_test_failure = test_failure
81            finally:
82                # Remove the downloaded video
83                if in_cloud:
84                    _remove_if_exists(input_path)
85
86        if last_test_failure:
87            raise last_test_failure
88