Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test timeout by forcing recompilation before the validation run #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eth_vertigo/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def run(
click.echo("[-] We couldn't get valid results by running the tests.\n Aborting")
return

click.echo("[+] The project is valid")
click.echo(f"[+] The project is valid (took {round(campaign.base_run_time, 2)} seconds)")
click.echo("[*] Storing compilation results")
campaign.store_compilation_results()
click.echo("[*] Running analysis on {} mutants".format(len(campaign.mutations)))
Expand Down
13 changes: 8 additions & 5 deletions eth_vertigo/interfaces/common/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,15 @@ def run_tests(

if mutation:
apply_mutation(mutation, temp_dir)

# only force recompilation when validating the project to get a baseline
force_recompile = False if mutation else True

try:
if original_bytecode is not None and original_bytecode != {}:
if self.compiler.check_bytecodes(temp_dir, original_bytecode):
raise EquivalentMutant
test_command = self.build_test_command(network)
test_command = self.build_test_command(network, force_recompile=force_recompile)
result = self.run_test_command(test_command, temp_dir, timeout=timeout)
finally:
rm_temp_directory(temp_dir)
Expand All @@ -122,21 +126,20 @@ def instrument_configuration(self, directory, keep_test_names):
pass

@abstractmethod
def build_test_command(self, network: str):
def build_test_command(self, network: str, force_recompile: bool = False):
pass

@staticmethod
def run_test_command(
command: str,
working_directory: str,
timeout=None
timeout: int = 600
) -> Union[Dict[str, TestResult], None]:
with TemporaryFile() as stdin, TemporaryFile() as stdout:
stdin.seek(0)
proc = Popen(command, stdin=stdin, stdout=stdout, stderr=stdout, cwd=working_directory)
try:
#TODO: timeout defaults to zero for some reason
proc.wait(timeout=1000000)
proc.wait(timeout=timeout)
except TimeoutExpired:
proc.kill()
raise TimedOut
Expand Down
4 changes: 3 additions & 1 deletion eth_vertigo/interfaces/foundry/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def instrument_configuration(self, directory, keep_test_names: Optional[List[str
if keep_test_names:
_set_include_tests(self.directory, keep_test_names)

def build_test_command(self, network: Optional[str]) -> List[str]:
def build_test_command(self, network: Optional[str], force_recompile: bool = False) -> List[str]:
result = self.foundry_command + ['test', '--json']
# if network:
# result.extend(['--network', network])
if force_recompile:
result.append('--force')
return result
3 changes: 2 additions & 1 deletion eth_vertigo/interfaces/hardhat/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def instrument_configuration(self, directory, keep_test_names: Optional[List[str
if keep_test_names:
_set_include_tests(self.directory, keep_test_names)

def build_test_command(self, network: Optional[str]) -> List[str]:
def build_test_command(self, network: Optional[str], force_recompile: bool = False) -> List[str]:
# todo - support `force_recompile`
result = self.hardhat_command + ['test']
# if network:
# result.extend(['--network', network])
Expand Down
3 changes: 2 additions & 1 deletion eth_vertigo/interfaces/truffle/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def instrument_configuration(self, working_directory, keep_test_names: Optional[
if keep_test_names:
_set_include_tests(working_directory, keep_test_names)

def build_test_command(self, network: Optional[str]) -> List[str]:
def build_test_command(self, network: Optional[str], force_recompile: bool = False) -> List[str]:
# todo - support `force_recompile`
result = [self.truffle_location, 'test']
if network:
result.extend(['--network', network])
Expand Down