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 7 8from autotest_lib.client.common_lib import error 9from autotest_lib.server import utils 10 11from native_Benchmarks_common import * 12 13class webm(object): 14 """Build and copy the codec to client.""" 15 16 def __init__(self, scratch_srv, scratch_cli, client, flags_additional): 17 self.src = "%s/webm" % scratch_srv 18 19 # unpack 20 cmd = 'tar jxf %s/webm.tar.bz2 -C %s' % (SERVER_TEST_ROOT, scratch_srv) 21 run_check(utils, cmd, 'Error occurred while unpacking webm') 22 23 # build 24 arch = client.get_arch() 25 flags = {} 26 def_flag(flags, 'LDFLAGS', '-static') 27 options = ' --disable-unit_tests' 28 options += ' --disable-docs' 29 options += ' --disable-runtime-cpu-detect' 30 if arch == 'armv7l': 31 def_flag(flags, 'CC', 'armv7a-cros-linux-gnueabihf-gcc') 32 def_flag(flags, 'CXX', 'armv7a-cros-linux-gnueabihf-g++') 33 def_flag(flags, 'LD', 'armv7a-cros-linux-gnueabihf-g++') 34 def_flag(flags, 'AR', 'armv7a-cros-linux-gnueabihf-ar') 35 def_flag(flags, 'AS', 'armv7a-cros-linux-gnueabihf-as') 36 options += ' --target=armv7-linux-gcc' 37 elif arch == 'x86_64': 38 def_flag(flags, 'CC', 'x86_64-cros-linux-gnu-gcc') 39 def_flag(flags, 'CXX', 'x86_64-cros-linux-gnu-g++') 40 def_flag(flags, 'LD', 'x86_64-cros-linux-gnu-g++') 41 def_flag(flags, 'AR', 'x86_64-cros-linux-gnu-ar') 42 options += ' --target=x86_64-linux-gcc' 43 else: 44 raise error.TestFail('Unknown cpu architecture: %s' % arch) 45 for f, v in flags_additional.iteritems(): 46 def_flag(flags, f, v) 47 envs = ' '.join('%s=%s' % (k, v) for k, v in flags.iteritems()) 48 cmd = 'mkdir -p %s/webm/out && ' % scratch_srv 49 cmd += 'cd %s/webm/out && ' % scratch_srv 50 cmd += ' %s ../configure %s && ' % (envs, options) 51 cmd += 'make -j 40' 52 53 run_check(utils, cmd, 'Error occurred building vpxenc') 54 55 files = ['vpxenc', 'vpxdec'] 56 for v in files: 57 if not os.path.isfile('%s/out/%s' % (self.src, v)): 58 raise error.TestFail('Unknown error when building %s' % v) 59 60 # copy 61 for v in files: 62 rcp_check(client, '%s/out/%s' % (self.src, v), 63 '%s/%s' % (scratch_cli, v), 64 'Error occurred while sending %s to client.' % v) 65 self.vpxenc = '%s/vpxenc' % scratch_cli 66 self.vpxdec = '%s/vpxdec' % scratch_cli 67 68 def __del__(self): 69 if os.path.isdir(self.src): 70 shutil.rmtree(self.src) 71