-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_fuzzer.py
More file actions
85 lines (70 loc) · 2.82 KB
/
start_fuzzer.py
File metadata and controls
85 lines (70 loc) · 2.82 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import sys
import hydra
from loguru import logger
from omegaconf import DictConfig, OmegaConf
from scenario_runner.config import RunnerConfig
from registry import ENGINE_REGISTRY
from registry.utils import discover_modules
# some fixed configurations
@hydra.main(config_path='.', config_name='config', version_base=None)
def main(cfg: DictConfig):
# CUDA_VISIBLE_DEVICES=2,3 python start_fuzzer.py
fuzzer_dir = cfg.get('fuzzer_dir', None)
if fuzzer_dir is None:
raise ValueError("Please provide the fuzzer directory.")
discover_modules(os.path.dirname(os.path.abspath(__file__)), fuzzer_dir)
scenario_config = cfg.get('scenario', None)
if scenario_config is None:
raise ValueError("Please provide the scenario config.")
fuzzer_config = cfg.get('tester', None)
if fuzzer_config is None:
raise ValueError("Please provide the fuzzer config.")
fuzzer_type = fuzzer_config.get('type', None)
# config parameters
RunnerConfig.use_dreamview = cfg.use_dreamview
RunnerConfig.apollo_tag = cfg.apollo_tag
RunnerConfig.run_tag = cfg.run_tag
RunnerConfig.debug = cfg.debug
RunnerConfig.resume = cfg.resume
RunnerConfig.save_record = cfg.save_record
if cfg.apollo_root.lower() != "default" and os.path.exists(cfg.apollo_root):
RunnerConfig.apollo_root = cfg.apollo_root
RunnerConfig.output_root = os.path.join(cfg.output_root, RunnerConfig.run_tag)
RunnerConfig.sandbox_image = cfg.sandbox_image
RunnerConfig.sandbox_fps = cfg.sandbox_fps
# print global config
RunnerConfig.print()
output_root = RunnerConfig.output_root
if not os.path.exists(output_root):
os.makedirs(output_root)
logger.info(f"Create output root folder: {output_root}")
if RunnerConfig.debug:
level = 'DEBUG'
else:
level = 'INFO'
logger.configure(handlers=[{"sink": sys.stderr, "level": level}])
logger_file = os.path.join(output_root, 'run.log')
_ = logger.add(logger_file, level=level, mode="a") # Use mode="a" for append
# save configs
OmegaConf.save(config=cfg, f=os.path.join(output_root, 'config.yaml'))
# direct to specific method, such as mr, avfuzzer..
logger.info(f'Fuzzer type: {fuzzer_type}')
fuzzer_class = ENGINE_REGISTRY.get(f"fuzzer.{fuzzer_type}")
logger.info(f'Load fuzzer class from: {fuzzer_class}')
fuzzer_instance = fuzzer_class(
fuzzer_config,
scenario_config
)
try:
if not fuzzer_instance.finish_flag:
fuzzer_instance.run()
except KeyboardInterrupt:
fuzzer_instance.close()
finally:
fuzzer_instance.close()
if __name__ == '__main__':
# CUDA_VISIBLE_DEVICES=2,3 python start_fuzzer.py
main()
logger.info('DONE Drivora-ApolloSim @.@!')
sys.exit(0)