2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Generational ClusterFuzz fuzzer. It generates IPC messages using
7 GenerateTraits. Support of GenerateTraits for different types will be gradually
17 IPC_GENERATE_APPLICATION
= 'ipc_fuzzer_generate'
18 IPC_REPLAY_APPLICATION
= 'ipc_fuzzer_replay'
19 MAX_IPC_MESSAGES_PER_TESTCASE
= 1500
22 class GenerationalFuzzer
:
23 def parse_arguments(self
):
24 self
.args
= utils
.parse_arguments()
26 def set_application_paths(self
):
27 chrome_application_path
= utils
.get_application_path()
28 chrome_application_directory
= os
.path
.dirname(chrome_application_path
)
29 self
.ipc_generate_binary
= utils
.application_name_for_platform(
30 IPC_GENERATE_APPLICATION
)
31 self
.ipc_replay_binary
= utils
.application_name_for_platform(
32 IPC_REPLAY_APPLICATION
)
33 self
.ipc_generate_binary_path
= os
.path
.join(
34 chrome_application_directory
, self
.ipc_generate_binary
)
35 self
.ipc_replay_binary_path
= os
.path
.join(
36 chrome_application_directory
, self
.ipc_replay_binary
)
38 def generate_ipcdump_testcase(self
):
39 ipcdump_testcase_path
= (
40 utils
.random_ipcdump_testcase_path(self
.args
.output_dir
))
41 num_ipc_messages
= random
.randint(1, MAX_IPC_MESSAGES_PER_TESTCASE
)
42 count_option
= '--count=%d' % num_ipc_messages
44 cmd
= [self
.ipc_generate_binary_path
, count_option
, ipcdump_testcase_path
]
46 if subprocess
.call(cmd
):
47 sys
.exit('%s failed.' % self
.ipc_generate_binary
)
49 utils
.create_flags_file(ipcdump_testcase_path
, self
.ipc_replay_binary_path
)
52 self
.parse_arguments()
53 self
.set_application_paths()
54 for _
in xrange(self
.args
.no_of_files
):
55 self
.generate_ipcdump_testcase()
59 if __name__
== "__main__":
60 fuzzer
= GenerationalFuzzer()
61 sys
.exit(fuzzer
.main())