blob: 29595f2886180c5369a1368ed2d985d2b6d11933 [file] [log] [blame]
Wojciech Staszkiewicz176dc642016-09-23 17:41:27 -07001#!/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
17import argparse
18import os
Wojciech Staszkiewiczf2cad3f2016-09-27 13:09:34 -070019import re
20import shutil
Wojciech Staszkiewicz176dc642016-09-23 17:41:27 -070021import subprocess
22import sys
23
Wojciech Staszkiewiczf2cad3f2016-09-27 13:09:34 -070024from glob import glob
25
26from tempfile import mkdtemp
Wojciech Staszkiewicz176dc642016-09-23 17:41:27 -070027from tempfile import TemporaryFile
28
29# Default arguments for run_jfuzz_test.py.
30DEFAULT_ARGS = ['--num_tests=20000']
31
32# run_jfuzz_test.py success string.
33SUCCESS_STRING = 'success (no divergences)'
34
35# Constant returned by string find() method when search fails.
36NOT_FOUND = -1
37
38def 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 Staszkiewiczf2cad3f2016-09-27 13:09:34 -070059 output_dirs = []
Wojciech Staszkiewicz176dc642016-09-23 17:41:27 -070060 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 Staszkiewiczf2cad3f2016-09-27 13:09:34 -070064 # 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 Staszkiewicz176dc642016-09-23 17:41:27 -070068 print('Tester', i)
69 if output_str.find(SUCCESS_STRING) == NOT_FOUND:
70 print(output_str)
71 else:
72 print(SUCCESS_STRING)
Wojciech Staszkiewiczf2cad3f2016-09-27 13:09:34 -070073 # 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 Staszkiewicz176dc642016-09-23 17:41:27 -070082
83if __name__ == '__main__':
84 main(sys.argv)