Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- place all coverage-related code in its own sub-directory - allow easy extension with other coverage formats - add some documentation
- Loading branch information
1 parent
8197c33
commit 0be7499
Showing
6 changed files
with
96 additions
and
20 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework | ||
# Built on top of Unicorn emulator (www.unicorn-engine.org) | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
class QlCoverage(ABC): | ||
""" | ||
An abstract base class for concrete code coverage collectors. | ||
To add support for a new coverage format, just derive from this class and implement | ||
all the methods marked with the @abstractmethod decorator. | ||
""" | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
@property | ||
@staticmethod | ||
@abstractmethod | ||
def FORMAT_NAME(): | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def activate(self): | ||
pass | ||
|
||
@abstractmethod | ||
def deactivate(self): | ||
pass | ||
|
||
@abstractmethod | ||
def dump_coverage(self, coverage_file): | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__all__ = ["drcov"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework | ||
# Built on top of Unicorn emulator (www.unicorn-engine.org) | ||
|
||
from .coverage import QlCoverage | ||
from .formats import * | ||
from contextlib import contextmanager | ||
|
||
class CoverageFactory(): | ||
def __init__(self): | ||
self.coverage_collectors = {subcls.FORMAT_NAME:subcls for subcls in QlCoverage.__subclasses__()} | ||
|
||
@property | ||
def formats(self): | ||
return self.coverage_collectors.keys() | ||
|
||
def get_coverage_collector(self, ql, name): | ||
return self.coverage_collectors[name](ql) | ||
|
||
factory = CoverageFactory() | ||
|
||
@contextmanager | ||
def collect_coverage(ql, name, coverage_file): | ||
""" | ||
Context manager for emulating a given piece of code with coverage collection turned on. | ||
Example: | ||
with collect_coverage(ql, 'drcov', 'output.cov'): | ||
ql.run(...) | ||
""" | ||
|
||
cov = factory.get_coverage_collector(ql, name) | ||
cov.activate() | ||
try: | ||
yield | ||
finally: | ||
cov.deactivate() | ||
if coverage_file: | ||
cov.dump_coverage(coverage_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters