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 | |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 29 | # run_jfuzz_test.py success string. |
| 30 | SUCCESS_STRING = 'success (no divergences)' |
| 31 | |
| 32 | # Constant returned by string find() method when search fails. |
| 33 | NOT_FOUND = -1 |
| 34 | |
| 35 | def main(argv): |
Aart Bik | 5618a57 | 2017-01-24 10:27:52 -0800 | [diff] [blame] | 36 | # Set up. |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 37 | cwd = os.path.dirname(os.path.realpath(__file__)) |
Aart Bik | 5618a57 | 2017-01-24 10:27:52 -0800 | [diff] [blame] | 38 | cmd = [cwd + '/run_jfuzz_test.py'] |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 39 | parser = argparse.ArgumentParser() |
| 40 | parser.add_argument('--num_proc', default=8, |
| 41 | type=int, help='number of processes to run') |
| 42 | # Unknown arguments are passed to run_jfuzz_test.py. |
| 43 | (args, unknown_args) = parser.parse_known_args() |
Aart Bik | 5618a57 | 2017-01-24 10:27:52 -0800 | [diff] [blame] | 44 | # Run processes. |
| 45 | cmd = cmd + unknown_args |
| 46 | print('\n**** Running ****\n\n', cmd, '\n') |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 47 | output_files = [TemporaryFile('wb+') for _ in range(args.num_proc)] |
| 48 | processes = [] |
Aart Bik | 5618a57 | 2017-01-24 10:27:52 -0800 | [diff] [blame] | 49 | for i, output_file in enumerate(output_files): |
| 50 | print('Tester', i) |
| 51 | processes.append(subprocess.Popen(cmd, stdout=output_file, |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 52 | stderr=subprocess.STDOUT)) |
| 53 | try: |
| 54 | # Wait for processes to terminate. |
| 55 | for proc in processes: |
| 56 | proc.wait() |
| 57 | except KeyboardInterrupt: |
| 58 | for proc in processes: |
| 59 | proc.kill() |
| 60 | # Output results. |
Aart Bik | 5618a57 | 2017-01-24 10:27:52 -0800 | [diff] [blame] | 61 | print('\n**** Results ****\n') |
Wojciech Staszkiewicz | f2cad3f | 2016-09-27 13:09:34 -0700 | [diff] [blame] | 62 | output_dirs = [] |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 63 | for i, output_file in enumerate(output_files): |
| 64 | output_file.seek(0) |
| 65 | output_str = output_file.read().decode('ascii') |
| 66 | output_file.close() |
Wojciech Staszkiewicz | f2cad3f | 2016-09-27 13:09:34 -0700 | [diff] [blame] | 67 | # Extract output directory. Example match: 'Directory : /tmp/tmp8ltpfjng'. |
| 68 | directory_match = re.search(r'Directory[^:]*: ([^\n]+)\n', output_str) |
| 69 | if directory_match: |
| 70 | output_dirs.append(directory_match.group(1)) |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 71 | if output_str.find(SUCCESS_STRING) == NOT_FOUND: |
Aart Bik | 5618a57 | 2017-01-24 10:27:52 -0800 | [diff] [blame] | 72 | print('Tester', i, output_str) |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 73 | else: |
Aart Bik | 5618a57 | 2017-01-24 10:27:52 -0800 | [diff] [blame] | 74 | print('Tester', i, SUCCESS_STRING) |
Wojciech Staszkiewicz | f2cad3f | 2016-09-27 13:09:34 -0700 | [diff] [blame] | 75 | # Gather divergences. |
| 76 | global_out_dir = mkdtemp('jfuzz_nightly') |
Aart Bik | 5618a57 | 2017-01-24 10:27:52 -0800 | [diff] [blame] | 77 | divergence_nr = 0 |
Wojciech Staszkiewicz | f2cad3f | 2016-09-27 13:09:34 -0700 | [diff] [blame] | 78 | for out_dir in output_dirs: |
| 79 | for divergence_dir in glob(out_dir + '/divergence*/'): |
Aart Bik | 5618a57 | 2017-01-24 10:27:52 -0800 | [diff] [blame] | 80 | divergence_nr += 1 |
Wojciech Staszkiewicz | f2cad3f | 2016-09-27 13:09:34 -0700 | [diff] [blame] | 81 | shutil.copytree(divergence_dir, |
| 82 | global_out_dir + '/divergence' + str(divergence_nr)) |
Aart Bik | 5618a57 | 2017-01-24 10:27:52 -0800 | [diff] [blame] | 83 | if divergence_nr > 0: |
| 84 | print('\n!!!! Divergences !!!!', divergence_nr) |
| 85 | else: |
| 86 | print ('\nSuccess') |
| 87 | print('\nGlobal output directory:', global_out_dir) |
| 88 | print() |
Wojciech Staszkiewicz | 176dc64 | 2016-09-23 17:41:27 -0700 | [diff] [blame] | 89 | |
| 90 | if __name__ == '__main__': |
| 91 | main(sys.argv) |