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 """Utility functions used by Generational and Mutational ClusterFuzz
16 APP_PATH_KEY
= 'APP_PATH'
17 FLAGS_PREFIX
= 'flags-'
19 IPC_REPLAY_APPLICATION
= 'ipc_fuzzer_replay'
20 IPCDUMP_EXTENSION
= '.ipcdump'
24 '--ppapi-plugin-launcher',
25 '--renderer-cmd-prefix',
26 '--utility-cmd-prefix',
29 def application_name_for_platform(application_name
):
30 """Return application name for current platform."""
31 if platform() == 'WINDOWS':
32 return application_name
+ '.exe'
33 return application_name
35 def create_flags_file(ipcdump_testcase_path
, ipc_replay_application_path
):
36 """Create a flags file to add launch prefix to application command line."""
37 random_launch_prefix
= random
.choice(LAUNCH_PREFIXES
)
38 file_content
= '%s=%s' % (random_launch_prefix
, ipc_replay_application_path
)
40 flags_file_path
= ipcdump_testcase_path
.replace(FUZZ_PREFIX
, FLAGS_PREFIX
)
41 file_handle
= open(flags_file_path
, 'w')
42 file_handle
.write(file_content
)
45 def create_temp_file():
46 """Create a temporary file."""
47 temp_file
= tempfile
.NamedTemporaryFile(delete
=False)
51 def parse_arguments():
52 """Parse fuzzer arguments."""
53 parser
= argparse
.ArgumentParser()
54 parser
.add_argument('--input_dir')
55 parser
.add_argument('--output_dir')
56 parser
.add_argument('--no_of_files', type=int)
57 args
= parser
.parse_args();
58 if (not args
.input_dir
or
59 not args
.output_dir
or
60 not args
.no_of_files
):
66 def random_id(size
=16, chars
=string
.ascii_lowercase
):
67 """Return a random id string, default 16 characters long."""
68 return ''.join(random
.choice(chars
) for _
in range(size
))
70 def random_ipcdump_testcase_path(ipcdump_directory
):
71 """Return a random ipc testcase path."""
74 '%s%s%s' % (FUZZ_PREFIX
, random_id(), IPCDUMP_EXTENSION
))
77 """Return running platform."""
78 if sys
.platform
.startswith('win'):
80 if sys
.platform
.startswith('linux'):
82 if sys
.platform
== 'darwin':
85 assert False, 'Unknown platform'
87 def get_application_path():
88 """Return chrome application path."""
89 if APP_PATH_KEY
not in os
.environ
:
91 'Environment variable %s should be set to chrome path.' % APP_PATH_KEY
)
93 return os
.environ
[APP_PATH_KEY
]