blob: a9f8365c8ffbb74de75d20972db6d18c43483353 [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
Wojciech Staszkiewicz176dc642016-09-23 17:41:27 -070029# run_jfuzz_test.py success string.
30SUCCESS_STRING = 'success (no divergences)'
31
32# Constant returned by string find() method when search fails.
33NOT_FOUND = -1
34
35def main(argv):
Aart Bik5618a572017-01-24 10:27:52 -080036 # Set up.
Wojciech Staszkiewicz176dc642016-09-23 17:41:27 -070037 cwd = os.path.dirname(os.path.realpath(__file__))
Aart Bik5618a572017-01-24 10:27:52 -080038 cmd = [cwd + '/run_jfuzz_test.py']
Wojciech Staszkiewicz176dc642016-09-23 17:41:27 -070039 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 Bik5618a572017-01-24 10:27:52 -080044 # Run processes.
45 cmd = cmd + unknown_args
46 print('\n**** Running ****\n\n', cmd, '\n')
Wojciech Staszkiewicz176dc642016-09-23 17:41:27 -070047 output_files = [TemporaryFile('wb+') for _ in range(args.num_proc)]
48 processes = []
Aart Bik5618a572017-01-24 10:27:52 -080049 for i, output_file in enumerate(output_files):
50 print('Tester', i)
51 processes.append(subprocess.Popen(cmd, stdout=output_file,
Wojciech Staszkiewicz176dc642016-09-23 17:41:27 -070052 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 Bik5618a572017-01-24 10:27:52 -080061 print('\n**** Results ****\n')
Wojciech Staszkiewiczf2cad3f2016-09-27 13:09:34 -070062 output_dirs = []
Wojciech Staszkiewicz176dc642016-09-23 17:41:27 -070063 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 Staszkiewiczf2cad3f2016-09-27 13:09:34 -070067 # 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 Staszkiewicz176dc642016-09-23 17:41:27 -070071 if output_str.find(SUCCESS_STRING) == NOT_FOUND:
Aart Bik5618a572017-01-24 10:27:52 -080072 print('Tester', i, output_str)
Wojciech Staszkiewicz176dc642016-09-23 17:41:27 -070073 else:
Aart Bik5618a572017-01-24 10:27:52 -080074 print('Tester', i, SUCCESS_STRING)
Wojciech Staszkiewiczf2cad3f2016-09-27 13:09:34 -070075 # Gather divergences.
76 global_out_dir = mkdtemp('jfuzz_nightly')
Aart Bik5618a572017-01-24 10:27:52 -080077 divergence_nr = 0
Wojciech Staszkiewiczf2cad3f2016-09-27 13:09:34 -070078 for out_dir in output_dirs:
79 for divergence_dir in glob(out_dir + '/divergence*/'):
Aart Bik5618a572017-01-24 10:27:52 -080080 divergence_nr += 1
Wojciech Staszkiewiczf2cad3f2016-09-27 13:09:34 -070081 shutil.copytree(divergence_dir,
82 global_out_dir + '/divergence' + str(divergence_nr))
Aart Bik5618a572017-01-24 10:27:52 -080083 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 Staszkiewicz176dc642016-09-23 17:41:27 -070089
90if __name__ == '__main__':
91 main(sys.argv)