Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3.4 |
| 2 | # |
| 3 | # Copyright (C) 2016 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import argparse |
| 18 | import os |
Wojciech Staszkiewicz | f2cad3f | 2016-09-27 13:09:34 -0700 | [diff] [blame] | 19 | import re |
| 20 | import shutil |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 21 | import subprocess |
| 22 | import sys |
| 23 | |
Wojciech Staszkiewicz | f2cad3f | 2016-09-27 13:09:34 -0700 | [diff] [blame] | 24 | from glob import glob |
| 25 | |
| 26 | from tempfile import mkdtemp |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 27 | from tempfile import TemporaryFile |
| 28 | |
| 29 | # Default arguments for run_jfuzz_test.py. |
| 30 | DEFAULT_ARGS = ['--num_tests=20000'] |
| 31 | |
| 32 | # run_jfuzz_test.py success string. |
| 33 | SUCCESS_STRING = 'success (no divergences)' |
| 34 | |
| 35 | # Constant returned by string find() method when search fails. |
| 36 | NOT_FOUND = -1 |
| 37 | |
| 38 | def main(argv): |
| 39 | cwd = os.path.dirname(os.path.realpath(__file__)) |
| 40 | cmd = [cwd + '/run_jfuzz_test.py'] + DEFAULT_ARGS |
| 41 | parser = argparse.ArgumentParser() |
| 42 | parser.add_argument('--num_proc', default=8, |
| 43 | type=int, help='number of processes to run') |
| 44 | # Unknown arguments are passed to run_jfuzz_test.py. |
| 45 | (args, unknown_args) = parser.parse_known_args() |
| 46 | output_files = [TemporaryFile('wb+') for _ in range(args.num_proc)] |
| 47 | processes = [] |
| 48 | for output_file in output_files: |
| 49 | processes.append(subprocess.Popen(cmd + unknown_args, stdout=output_file, |
| 50 | stderr=subprocess.STDOUT)) |
| 51 | try: |
| 52 | # Wait for processes to terminate. |
| 53 | for proc in processes: |
| 54 | proc.wait() |
| 55 | except KeyboardInterrupt: |
| 56 | for proc in processes: |
| 57 | proc.kill() |
| 58 | # Output results. |
Wojciech Staszkiewicz | f2cad3f | 2016-09-27 13:09:34 -0700 | [diff] [blame] | 59 | output_dirs = [] |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 60 | for i, output_file in enumerate(output_files): |
| 61 | output_file.seek(0) |
| 62 | output_str = output_file.read().decode('ascii') |
| 63 | output_file.close() |
Wojciech Staszkiewicz | f2cad3f | 2016-09-27 13:09:34 -0700 | [diff] [blame] | 64 | # Extract output directory. Example match: 'Directory : /tmp/tmp8ltpfjng'. |
| 65 | directory_match = re.search(r'Directory[^:]*: ([^\n]+)\n', output_str) |
| 66 | if directory_match: |
| 67 | output_dirs.append(directory_match.group(1)) |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 68 | print('Tester', i) |
| 69 | if output_str.find(SUCCESS_STRING) == NOT_FOUND: |
| 70 | print(output_str) |
| 71 | else: |
| 72 | print(SUCCESS_STRING) |
Wojciech Staszkiewicz | f2cad3f | 2016-09-27 13:09:34 -0700 | [diff] [blame] | 73 | # Gather divergences. |
| 74 | global_out_dir = mkdtemp('jfuzz_nightly') |
| 75 | divergence_nr = 1 |
| 76 | for out_dir in output_dirs: |
| 77 | for divergence_dir in glob(out_dir + '/divergence*/'): |
| 78 | shutil.copytree(divergence_dir, |
| 79 | global_out_dir + '/divergence' + str(divergence_nr)) |
| 80 | divergence_nr += 1 |
| 81 | print('Global output directory:', global_out_dir) |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 82 | |
| 83 | if __name__ == '__main__': |
| 84 | main(sys.argv) |