Home | History | Annotate | Download | only in android_bench_suite
      1 #!/usr/bin/env python2
      2 #
      3 # Copyright 2017 The Chromium OS Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 """Script to patch Android repo with diffs that are needed by the suite.
      7 
      8 Run this script before running the suite.
      9 """
     10 from __future__ import print_function
     11 
     12 import config
     13 import os
     14 import subprocess
     15 
     16 # The patches to be added to the android repo.
     17 # An error may occur if it is already patched, or meets some error.
     18 # FIXME: Needs to be FIXED in the future.
     19 def try_patch_skia():
     20   skia_dir = os.path.join(config.android_home, config.bench_dict['Skia'])
     21   # You may want to change the file based on aosp or internal
     22   if config.android_type == 'internal':
     23     print('No need to patch skia for internal repo.')
     24     return
     25   elif config.android_type == 'aosp':
     26     skia_patch = os.path.join(
     27         os.path.dirname(os.path.realpath(__file__)), 'skia_aosp.diff')
     28   else:
     29     raise ValueError('Adnroid source type should be either aosp or internal.')
     30   # FIXME: A quick hack, need to handle errors and check whether has been
     31   # applied in the future.
     32   try:
     33     subprocess.check_call(['git', '-C', skia_dir, 'apply', skia_patch])
     34     print('Skia patched successfully!')
     35   except subprocess.CalledProcessError:
     36     print('Skia patch not applied, error or already patched.')
     37 
     38 
     39 def try_patch_autotest():
     40   # Patch autotest, which includes all the testcases on device, setting device,
     41   # and running the benchmarks
     42   autotest_dir = os.path.join(config.android_home, config.autotest_dir)
     43   autotest_patch = os.path.join(
     44       os.path.dirname(os.path.realpath(__file__)), 'autotest.diff')
     45   dex2oat_dir = os.path.join(autotest_dir, 'server/site_tests/android_Dex2oat')
     46   panorama_dir = os.path.join(autotest_dir,
     47                               'server/site_tests/android_Panorama')
     48   # FIXME: A quick hack, need to handle errors and check whether has been
     49   # applied in the future.
     50   try:
     51     subprocess.check_call(['git', '-C', autotest_dir, 'apply', autotest_patch])
     52     subprocess.check_call(['cp', '-rf', 'dex2oat_input', dex2oat_dir])
     53     subprocess.check_call(['cp', '-rf', 'panorama_input', panorama_dir])
     54     print('Autotest patched successfully!')
     55   except subprocess.CalledProcessError:
     56     print('Autotest patch not applied, error or already patched.')
     57 
     58 
     59 def try_patch_panorama():
     60   panorama_dir = os.path.join(config.android_home,
     61                               config.bench_dict['Panorama'])
     62   panorama_patch = os.path.join(
     63       os.path.dirname(os.path.realpath(__file__)), 'panorama.diff')
     64   # FIXME: A quick hack, need to handle errors and check whether has been
     65   # applied in the future.
     66   try:
     67     subprocess.check_call(['git', '-C', panorama_dir, 'apply', panorama_patch])
     68     print('Panorama patched successfully!')
     69   except subprocess.CalledProcessError:
     70     print('Panorama patch not applied, error or already patched.')
     71 
     72 
     73 def try_patch_synthmark():
     74   synthmark_dir = 'devrel/tools/synthmark'
     75   # FIXME: A quick hack, need to handle errors and check whether has been
     76   # applied in the future.
     77   try:
     78     subprocess.check_call([
     79         'bash', '-c', 'mkdir devrel && '
     80         'cd devrel && '
     81         'repo init -u sso://devrel/manifest && '
     82         'repo sync tools/synthmark'
     83     ])
     84     synthmark_patch = os.path.join(
     85         os.path.dirname(os.path.realpath(__file__)), 'synthmark.diff')
     86     subprocess.check_call(['git', '-C', synthmark_dir,
     87                            'apply', synthmark_patch])
     88 
     89     subprocess.check_call(['mv', '-f', synthmark_dir, config.android_home])
     90     subprocess.check_call(['rm', '-rf', 'devrel'])
     91     print('Synthmark patched successfully!')
     92   except subprocess.CalledProcessError:
     93     print('Synthmark patch not applied, error or already patched.')
     94 
     95 
     96 def main():
     97   try_patch_skia()
     98   try_patch_autotest()
     99   try_patch_panorama()
    100   try_patch_synthmark()
    101 
    102 
    103 if __name__ == '__main__':
    104   main()
    105