Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: tools/ipc_fuzzer/mutate/utils.py

Issue 888603003: Cleanup ipc fuzzer. Add flags to pick random prefix on launch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: description nit Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
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.
5
6 """Utility functions used by Generational and Mutational ClusterFuzz
7 fuzzers."""
8
9 import argparse
10 import os
11 import random
12 import string
13 import sys
14 import tempfile
15
16 APP_PATH_KEY = 'APP_PATH'
17 FLAGS_PREFIX = 'flags-'
18 FUZZ_PREFIX = 'fuzz-'
19 IPC_REPLAY_APPLICATION = 'ipc_fuzzer_replay'
20 IPCDUMP_EXTENSION = '.ipcdump'
21 LAUNCH_PREFIXES = [
22 '--gpu-launcher',
23 '--plugin-launcher',
24 '--ppapi-plugin-launcher',
25 '--renderer-cmd-prefix',
26 '--utility-cmd-prefix',
27 ]
28
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
34
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)
39
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)
43 file_handle.close()
44
45 def create_temp_file():
46 """Create a temporary file."""
47 temp_file = tempfile.NamedTemporaryFile(delete=False)
48 temp_file.close()
49 return temp_file.name
50
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):
61 parser.print_help()
62 sys.exit(1)
63
64 return args
65
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))
69
70 def random_ipcdump_testcase_path(ipcdump_directory):
Martin Barbella 2015/01/29 19:29:46 I'm fine with this either way, but should we bothe
71 """Return a random ipc testcase path."""
72 return os.path.join(
73 ipcdump_directory,
74 '%s%s%s' % (FUZZ_PREFIX, random_id(), IPCDUMP_EXTENSION))
75
76 def platform():
77 """Return running platform."""
78 if sys.platform.startswith('win'):
79 return 'WINDOWS'
80 if sys.platform.startswith('linux'):
81 return 'LINUX'
82 if sys.platform == 'darwin':
83 return 'MAC'
84
85 assert False, 'Unknown platform'
86
87 def get_application_path():
88 """Return chrome application path."""
89 if APP_PATH_KEY not in os.environ:
90 sys.exit(
91 'Environment variable %s should be set to chrome path.' % APP_PATH_KEY)
92
93 return os.environ[APP_PATH_KEY]
OLDNEW
« tools/ipc_fuzzer/mutate/ipc_fuzzer_mut.py ('K') | « tools/ipc_fuzzer/mutate/ipc_fuzzer_mut.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698