| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2016 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 |
| 5 """Script that helps run the fuzzer locally and in ClusterFuzz. |
| 6 |
| 7 To prepare to run the fuzzer locally, this script copies the necessary |
| 8 resources. |
| 9 |
| 10 To prepare to run the fuzzer in ClusterFuzz this script generates two zip |
| 11 files: web_bluetooth_fuzzer.tar.bz2. This zip file can then be directly |
| 12 uploaded to ClusterFuzz. |
| 13 """ |
| 14 |
| 15 import argparse |
| 16 import glob |
| 17 import os |
| 18 import shutil |
| 19 import sys |
| 20 |
| 21 # src path from this file's path. |
| 22 SRC_PATH = os.path.join( |
| 23 os.pardir, os.pardir, os.pardir, os.pardir, os.pardir, os.pardir, os.pardir) |
| 24 LAYOUT_TESTS_RESOURCES_PATH = os.path.join( |
| 25 SRC_PATH, 'third_party', 'WebKit', 'LayoutTests', 'resources') |
| 26 RESOURCES = [ |
| 27 os.path.join(LAYOUT_TESTS_RESOURCES_PATH, 'testharness.js'), |
| 28 os.path.join(LAYOUT_TESTS_RESOURCES_PATH, 'testharnessreport.js'), |
| 29 os.path.join(LAYOUT_TESTS_RESOURCES_PATH, 'bluetooth', |
| 30 'bluetooth-helpers.js'), |
| 31 ] |
| 32 |
| 33 |
| 34 def _GetCurrentPath(): |
| 35 """Returns this file's directory path""" |
| 36 return os.path.dirname(os.path.realpath(__file__)) |
| 37 |
| 38 |
| 39 def RetrieveResources(): |
| 40 # Create resources directory if it doesn't exist. Clear it otherwise. |
| 41 current_path = _GetCurrentPath() |
| 42 resources_path = os.path.join(current_path, 'resources') |
| 43 if not os.path.exists(resources_path): |
| 44 print '\'resources\' folder doesn\'t exist. Creating one...' |
| 45 os.makedirs(resources_path) |
| 46 else: |
| 47 print '\'resources\' folder already exists. Clearing it...' |
| 48 filelist = glob.glob(os.path.join(resources_path, '*')) |
| 49 for f in filelist: |
| 50 os.remove(f) |
| 51 |
| 52 # Copy necessary files. |
| 53 for r in RESOURCES: |
| 54 print 'Copying: ' + os.path.abspath(os.path.join(current_path, r)) |
| 55 shutil.copy(os.path.join(current_path, r), resources_path) |
| 56 |
| 57 return resources_path |
| 58 |
| 59 |
| 60 def main(): |
| 61 |
| 62 # Get arguments. |
| 63 parser = argparse.ArgumentParser() |
| 64 |
| 65 parser.add_argument('-c', '--cluster_fuzz', action='store_true', |
| 66 help='If present, this script generates tar.bz2 file ' |
| 67 'containing the fuzzer. This file can be uploaded ' |
| 68 'and run on ClusterFuzz.') |
| 69 parser.add_argument('-l', '--local', action='store_true', |
| 70 help='If present, this script retrieves the files ' |
| 71 'necessary to run the fuzzer locally.') |
| 72 |
| 73 args = parser.parse_args() |
| 74 |
| 75 if not (args.cluster_fuzz or args.local): |
| 76 print 'No action requested.' |
| 77 return |
| 78 |
| 79 RetrieveResources() |
| 80 |
| 81 # To run locally we only need to copy the files. |
| 82 if args.local: |
| 83 print 'Ready to run locally!' |
| 84 |
| 85 # To run on ClusterFuzz we create a tar.bz2 file. |
| 86 if args.cluster_fuzz: |
| 87 # Clean directory |
| 88 current_path = _GetCurrentPath() |
| 89 filelist = glob.glob(os.path.join(current_path, '*.pyc')) |
| 90 for f in filelist: |
| 91 os.remove(f) |
| 92 |
| 93 # Compress folder to upload |
| 94 compressed_file_path = os.path.join(current_path, |
| 95 'web_bluetooth_fuzzer') |
| 96 shutil.make_archive( |
| 97 compressed_file_path, |
| 98 format='bztar', |
| 99 root_dir=os.path.join(current_path, os.pardir), |
| 100 base_dir='web_bluetooth_fuzzer') |
| 101 print 'File wrote to: ' + compressed_file_path + '.tar.bz2' |
| 102 |
| 103 if __name__ == '__main__': |
| 104 sys.exit(main()) |
| OLD | NEW |