Skip to content

Commit

Permalink
Added type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jun 1, 2024
1 parent d315034 commit 9127159
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/benchmark/executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
def instrument_func(x):
return x

def instrument_all():
def instrument_all() -> None:
pass

@contextlib.contextmanager
Expand Down
4 changes: 2 additions & 2 deletions src/coverage_g3test.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ class StrProperties:

# Verifying that no tracing happens since startswith is a property
@atheris.instrument_func
def property_starts_with():
def property_starts_with() -> None:
fake_str = StrProperties()
fake_str.startswith = None


# Verifying that no patching happens since endswith is a property
@atheris.instrument_func
def property_ends_with():
def property_ends_with() -> None:
fake_str = StrProperties()
fake_str.endswith = None

Expand Down
4 changes: 2 additions & 2 deletions src/coverage_test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ class StrProperties:


# Verifying that no tracing happens since startswith is a property
def property_starts_with():
def property_starts_with() -> None:
fake_str = StrProperties()
fake_str.startswith = None


# Verifying that no patching happens since endswith is a property
def property_ends_with():
def property_ends_with() -> None:
fake_str = StrProperties()
fake_str.endswith = None
4 changes: 2 additions & 2 deletions src/custom_crossover_fuzz_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def bytes_comparison(data):

class CustomCrossoverTests(unittest.TestCase):

def testBytesComparison(self):
def testBytesComparison(self) -> None:
fuzz_test_lib.run_fuzztest(
bytes_comparison,
setup_kwargs={
Expand All @@ -51,7 +51,7 @@ def testBytesComparison(self):
expected_output=b"Was a|b|c|d|e",
timeout=30)

def testNoOpCrossover(self):
def testNoOpCrossover(self) -> None:
fuzz_test_lib.run_fuzztest(
bytes_comparison,
setup_kwargs={
Expand Down
4 changes: 2 additions & 2 deletions src/custom_mutator_and_crossover_fuzz_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_one_input(data):

class CustomMutatorAndCrossoverTests(unittest.TestCase):

def testMutator(self):
def testMutator(self) -> None:
fuzz_test_lib.run_fuzztest(
test_one_input,
setup_kwargs={
Expand All @@ -50,7 +50,7 @@ def testMutator(self):
},
expected_output=b"Hello from mutator")

def testCrossover(self):
def testCrossover(self) -> None:
fuzz_test_lib.run_fuzztest(
test_one_input,
setup_kwargs={
Expand Down
2 changes: 1 addition & 1 deletion src/custom_mutator_fuzz_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def compressed_data(data):

class CustomMutatorTests(unittest.TestCase):

def testCompressedData(self):
def testCompressedData(self) -> None:
fuzz_test_lib.run_fuzztest(
compressed_data,
setup_kwargs={"custom_mutator": compressed_mutator},
Expand Down
44 changes: 22 additions & 22 deletions src/fuzz_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,34 +224,34 @@ def runtime_instrument_code(data):

class IntegrationTests(unittest.TestCase):

def testFails(self):
def testFails(self) -> None:
fuzz_test_lib.run_fuzztest(
fail_immediately, expected_output=b"Failed immediately")

def testManyBranches(self):
def testManyBranches(self) -> None:
fuzz_test_lib.run_fuzztest(
many_branches, expected_output=b"Many branches", timeout=90)

def testBytesComparison(self):
def testBytesComparison(self) -> None:
fuzz_test_lib.run_fuzztest(
bytes_comparison, expected_output=b"Was foobarbazbiz", timeout=30)

def testStringComparison(self):
def testStringComparison(self) -> None:
fuzz_test_lib.run_fuzztest(
string_comparison, expected_output=b"Was foobarbazbiz", timeout=30)

def testUtf8Comparison(self):
def testUtf8Comparison(self) -> None:
fuzz_test_lib.run_fuzztest(
utf8_comparison, expected_output=b"Was random unicode", timeout=60)

def testNestedUtf8Comparison(self):
def testNestedUtf8Comparison(self) -> None:
fuzz_test_lib.run_fuzztest(
nested_utf8_comparison,
expected_output=b"Was hello",
timeout=60,
)

def testTimeoutPy(self):
def testTimeoutPy(self) -> None:
"""This test verifies that timeout messages are recorded from -timeout."""
fuzz_test_lib.run_fuzztest(
timeout_py,
Expand All @@ -262,101 +262,101 @@ def testTimeoutPy(self):
args=["-timeout=1"],
expected_output=b"ERROR: libFuzzer: timeout after")

def testRegExMatch(self):
def testRegExMatch(self) -> None:
fuzz_test_lib.run_fuzztest(
regex_match,
expected_output=b"Was RegEx Match",
enabled_hooks=["RegEx"])

def testStrStartswith(self):
def testStrStartswith(self) -> None:
fuzz_test_lib.run_fuzztest(
str_startswith,
expected_output=b"Started with foobar",
enabled_hooks=["str"],
timeout=60,
)

def testStrEndswith(self):
def testStrEndswith(self) -> None:
fuzz_test_lib.run_fuzztest(
str_endswith,
expected_output=b"Ended with bazbiz",
enabled_hooks=["str"],
timeout=60,
)

def testStrMethodsCombined(self):
def testStrMethodsCombined(self) -> None:
fuzz_test_lib.run_fuzztest(
str_methods_combined,
expected_output=b"Started with foo and ended with bar",
enabled_hooks=["str"],
timeout=60,
)

def testStrStartswithTuplePrefix(self):
def testStrStartswithTuplePrefix(self) -> None:
fuzz_test_lib.run_fuzztest(
str_startswith_tuple_prefix,
expected_output=b"Started with oneof (foobar, hellohi, supyo)",
enabled_hooks=["str"],
timeout=60,
)

def testStrEndswithTupleSuffix(self):
def testStrEndswithTupleSuffix(self) -> None:
fuzz_test_lib.run_fuzztest(
str_endswith_tuple_suffix,
expected_output=b"Ended with oneof (bazbiz, byebye, cyalater)",
enabled_hooks=["str"],
timeout=60,
)

def testStrStartswithStartEndArgs(self):
def testStrStartswithStartEndArgs(self) -> None:
fuzz_test_lib.run_fuzztest(
str_startswith_with_start_and_end,
expected_output=b"Started with hellohi at index 10",
enabled_hooks=["str"],
timeout=60,
)

def testStrEndswithStartEndArgs(self):
def testStrEndswithStartEndArgs(self) -> None:
fuzz_test_lib.run_fuzztest(
str_endswith_with_start_and_end,
expected_output=b"Ended with supyo at end index 15",
enabled_hooks=["str"],
timeout=60,
)

def testExitsGracefullyOnPyFail(self):
def testExitsGracefullyOnPyFail(self) -> None:
fuzz_test_lib.run_fuzztest(
fail_immediately, expected_output=b"Exiting gracefully.")

def testExitsGracefullyOnRunsOut(self):
def testExitsGracefullyOnRunsOut(self) -> None:
fuzz_test_lib.run_fuzztest(
never_fail,
args=["-atheris_runs=2"],
expected_output=b"Exiting gracefully.")

def testExceptionWithSurrogates(self):
def testExceptionWithSurrogates(self) -> None:
fuzz_test_lib.run_fuzztest(
raise_with_surrogates,
args=["-atheris_runs=1"],
expected_output=b"abc \\ud927 def")

def testRunsOutCount(self):
def testRunsOutCount(self) -> None:
fuzz_test_lib.run_fuzztest(
never_fail, args=["-atheris_runs=3"], expected_output=b"Done 3 in ")

def testCompressedDataWithoutCustomMutator(self):
def testCompressedDataWithoutCustomMutator(self) -> None:
try:
fuzz_test_lib.run_fuzztest(compressed_data)
except TimeoutError: # Expected to timeout without a custom mutator.
pass

def testReserveCounterAfterFuzzStart(self):
def testReserveCounterAfterFuzzStart(self) -> None:
fuzz_test_lib.run_fuzztest(
reserve_counter_after_fuzz_start,
args=["-atheris_runs=2"],
expected_output=b"Exiting gracefully.")

def testInstrumentCodeWhileFuzzing(self):
def testInstrumentCodeWhileFuzzing(self) -> None:
fuzz_test_lib.run_fuzztest(
runtime_instrument_code,
timeout=90,
Expand Down
Loading

0 comments on commit 9127159

Please sign in to comment.