Skip to content

Commit

Permalink
use flakey for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaloz committed Sep 11, 2023
1 parent eff9e94 commit 77b6d49
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'povsim',
'compilerex',
'pwntools',
'flakey',
],
package_data={
'rex.scripter.templates': ['*.j2']
Expand Down
30 changes: 4 additions & 26 deletions tests/test_rex.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=line-too-long
import os
import random
import subprocess
Expand All @@ -14,36 +15,13 @@
from angr.state_plugins.trace_additions import FormatInfoStrToInt, FormatInfoDontConstrain
from rex.exploit.cgc.type1.cgc_type1_shellcode_exploit import CGCType1ShellcodeExploit

from flakey import flakey

bin_location = str(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../binaries'))
cache_location = str(os.path.join(bin_location, 'tests_data/rop_gadgets_cache'))
tests_dir = str(os.path.dirname(os.path.realpath(__file__)))


def multiple_attempts(attempt_amt: int):
"""
A wrapper to allow a flakey test to be run attempt_amt number of times.
"""
def _multiple_attempts(func):
@wraps(func)
def inner(*args, **kwargs):
ret_val = None
caught_exception = None
for _ in range(attempt_amt):
try:
ret_val = func(*args, **kwargs)
break
except Exception as e:
caught_exception = e
else:
raise caught_exception

return ret_val

return inner

return _multiple_attempts


def _do_pov_test(pov, enable_randomness=True):
''' Test a POV '''
for _ in range(10):
Expand Down Expand Up @@ -256,7 +234,7 @@ def test_linux_stacksmash_32():
_check_arsenal_has_send(exploit.arsenal)


@multiple_attempts(3)
@flaky(max_runs=3, min_passes=1)
def test_linux_network_stacksmash_64():
# Test exploiting a simple network server with a stack-based buffer overflow.
inp = b'\x00' * 500
Expand Down

0 comments on commit 77b6d49

Please sign in to comment.