1# Copyright (c) 2015 The Chromium OS 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 os
6import shutil
7import tempfile
8
9from autotest_lib.server import test
10
11from native_Benchmarks_common import CLIENT_TEST_ROOT
12from native_Benchmarks_common import run_check
13
14from octane import octane
15from vp8 import vp8
16
17# Benchmark suites
18suites = {
19    'octane': octane,
20    'vp8': vp8,
21}
22
23class native_Benchmarks(test.test):
24    """Build and run native benchmarks"""
25    version = 1
26
27    def run_once(self, client, name, args):
28        """
29        Build benchmark on the invoking machine and run it on client.
30
31        @param client: The autotest host object representing client.
32        @param name: The name of benchmark to run.
33        """
34
35        # scratch directory on server.
36        scratch_srv = tempfile.mkdtemp()
37        try:
38            # scratch directory on client.
39            cmd = 'mkdir -p %s' % CLIENT_TEST_ROOT
40            err_msg = 'Unable to create %s' % CLIENT_TEST_ROOT
41            run_check(client, cmd, err_msg)
42            scratch_cli = CLIENT_TEST_ROOT
43
44            flags = dict(i.split('=') for i in args)
45            results = suites[name](scratch_srv, scratch_cli, client, flags).run()
46            for r in results:
47                self.output_perf_value(**r)
48        finally:
49            if scratch_srv and os.path.isdir(scratch_srv):
50                shutil.rmtree(scratch_srv)
51