-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
63 lines (49 loc) · 1.8 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# API to interface WebGlitch with Google's ClusterFuzz
import argparse
import os
import shutil
import subprocess
import sys
webglitch_dir = os.path.dirname(os.path.realpath(__file__))
webglitch_jar_path = os.path.join(webglitch_dir, 'app', 'build', 'libs', 'app.jar')
def run_webglitch(args_to_use):
try:
subprocess.run(['java', '-jar', webglitch_jar_path] + args_to_use, check=True)
except subprocess.CalledProcessError as e:
print(f"Error running Java command: {e}")
sys.exit(e.returncode)
arg_parser = argparse.ArgumentParser(
description="WebGlitch WebGPU program generator"
)
arg_parser.add_argument(
"--input_dir",
type=str,
help="Corpus of WebGPU programs to mutate (unsupported)"
)
arg_parser.add_argument(
"--output_dir",
type=str,
help="Output directory WebGlitch writes to"
)
arg_parser.add_argument(
"--no_of_files",
type=int,
help="Number of testcases for WebGlitch to generate"
)
args = arg_parser.parse_args()
input_dir = args.input_dir
output_dir = args.output_dir
no_of_files = args.no_of_files
if no_of_files <= 0:
raise ValueError("Number of files to generate must be greater than 0")
# Output dir must include all dependencies to execute testcase so need copy shaders folder over
shaders_dir = os.path.join(webglitch_dir, "rsrcs", "html", "shaders")
output_dir_shaders_dir = os.path.join(output_dir, "shaders")
try:
shutil.copytree(shaders_dir, output_dir_shaders_dir, dirs_exist_ok=True)
except Exception as e:
print(f"Error occurred while copying shaders folder to output dir: {e}")
for file_no in range(no_of_files):
# Testcases generated by fuzzer must be filename prefix 'fuzz-'
output_file = os.path.join(output_dir, f"fuzz-{file_no}.js").replace("\\", "/")
run_webglitch(["-o", output_file, "-m", "-z"])