Skip to content

Commit

Permalink
Merge pull request #326 from trailofbits/frontend_sync_resume
Browse files Browse the repository at this point in the history
[WIP] Frontends synchronization, resuming and statistics
  • Loading branch information
GrosQuildu authored Feb 19, 2020
2 parents f0176f9 + eb7c9e6 commit 67e98f5
Show file tree
Hide file tree
Showing 25 changed files with 1,872 additions and 1,007 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,10 @@ jobs:
image_tag: latest
context: .
dockerfile: docker/Dockerfile
# pull_image_and_stages: false # if OOM error
push_image_and_stages: true # because we run workflow on PRs
build_extra_args: "--cache-from=deepstate-base"
build_extra_args: "--cache-from=deepstate-base --build-arg=make_j=2"
- name: Test fuzzers
run: |
echo core | sudo tee /proc/sys/kernel/core_pattern
docker run docker.pkg.github.com/trailofbits/deepstate/deepstate sh -c 'sudo pip3 install nose && nosetests tests/test_fuzzers.py'
511 changes: 24 additions & 487 deletions README.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion bin/deepstate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ def __init__(self, name: str) -> None:
logging.Logger.__init__(self, name=name)
self.trace = functools.partial(self.log, 15) # type: ignore
self.external = functools.partial(self.log, 45) # type: ignore
self.fuzz_stats = functools.partial(self.log, 46) # type: ignore


logging.basicConfig()
logging.addLevelName(15, "TRACE")
logging.addLevelName(45, "EXTERNAL")
logging.addLevelName(46, "FUZZ_STATS")
logging.setLoggerClass(DeepStateLogger)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,7 +50,9 @@ def __init__(self, name: str) -> None:

log_level_from_env: str = os.environ.get("DEEPSTATE_LOG", "2")
try:
logger.setLevel(LOG_LEVEL_INT_TO_STR[int(log_level_from_env)])
log_level_from_env_int: int = int(log_level_from_env)
logger.setLevel(LOG_LEVEL_INT_TO_STR[log_level_from_env_int])
logger.info("Setting log level from DEEPSTATE_LOG: %d", log_level_from_env_int)
except ValueError:
print("$DEEPSTATE_LOG contains invalid value `%s`, "
"should be int in 0-6 (debug, trace, info, warning, error, external, critical).",
Expand Down
22 changes: 10 additions & 12 deletions bin/deepstate/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ def __init__(self):
AnalysisBackend.compiler_exe = self.EXECUTABLES.pop("COMPILER", None)

# parsed argument attributes
self.binary: str = None
self.output_test_dir: str = f"{self}_out"
self.binary: Optional[str] = None
self.output_test_dir: str
self.timeout: int = 0
self.num_workers: int = 1
self.mem_limit: int = 50
self.min_log_level: int = 2

Expand Down Expand Up @@ -124,7 +123,8 @@ def parse_args(cls) -> Optional[argparse.Namespace]:
help="Linker flags (space seperated) to include for external libraries.")

compile_group.add_argument("--out_test_name", type=str,
help="Set name of generated instrumented binary.")
help=("Set name of generated instrumented binary. Default is `out`. "
"Automatically adds `.frontend_name_lowercase` suffix."))

compile_group.add_argument("--no_exit_compile", action="store_true",
help="Continue execution after compiling a harness (set as default if `--config` is set).")
Expand All @@ -135,8 +135,8 @@ def parse_args(cls) -> Optional[argparse.Namespace]:

# Analysis-related configurations
parser.add_argument(
"-o", "--output_test_dir", type=str, default="out",
help="Output directory where tests will be saved (default is `out`).")
"-o", "--output_test_dir", type=str,
help="Output directory where tests will be saved. Required. If not empty, will try to resume.")

parser.add_argument(
"-c", "--config", type=str,
Expand All @@ -146,10 +146,6 @@ def parse_args(cls) -> Optional[argparse.Namespace]:
"-t", "--timeout", default=0, type=int,
help="Time to kill analysis worker processes, in seconds (default is 0 for none).")

parser.add_argument(
"-w", "--num_workers", default=1, type=int,
help="Number of worker jobs to spawn for analysis (default is 1).")

parser.add_argument("--mem_limit", type=int, default=50,
help="Child process memory limit in MiB (default is 50). 0 for unlimited.")

Expand Down Expand Up @@ -183,6 +179,7 @@ def parse_args(cls) -> Optional[argparse.Namespace]:
target_args_parsed.append((key, val))
_args['target_args'] = target_args_parsed


# if configuration is specified, parse and replace argument instantiations
if args.config:
_args.update(cls.build_from_config(args.config)) # type: ignore
Expand All @@ -193,15 +190,16 @@ def parse_args(cls) -> Optional[argparse.Namespace]:
del _args["config"]

# log level fixing
if os.environ.get("DEEPSTATE_LOG", None) is None:
if not os.environ.get("DEEPSTATE_LOG"):
if _args["min_log_level"] < 0 or _args["min_log_level"] > 6:
raise AnalysisBackendError(f"`--min_log_level` is in invalid range, should be in 0-6 "
"(debug, trace, info, warning, error, external, critical).")

L.info("Setting log level from --min_log_level: %d", _args["min_log_level"])
logger = logging.getLogger("deepstate")
logger.setLevel(LOG_LEVEL_INT_TO_STR[_args["min_log_level"]])
else:
L.info("Using log level from $DEEPSTATE_LOG.")
L.debug("Using log level from $DEEPSTATE_LOG.")

cls._ARGS = args
return cls._ARGS
Expand Down
Loading

0 comments on commit 67e98f5

Please sign in to comment.