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

Adding python fuzz script that runs rust tests in a loop and logs to rollbar if it fails #9

Merged
merged 4 commits into from
Apr 30, 2024
Merged
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
10 changes: 10 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This directory sets up running rust fuzz tests. We use python as the orchestration language
to (1) gather fuzz testing for rust, (2) run individual tests, and (3) log any errors from tests to
rollbar.

From the `hyperdrive-rs` root directory:

```
pip install -r fuzz/requirements-fuzz.txt
ROLLBAR_API_KEY=<rollbar_api_key> python fuzz/run-rust-fuzz.py
```
1 change: 1 addition & 0 deletions fuzz/requirements-fuzz.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rollbar
37 changes: 37 additions & 0 deletions fuzz/run-rust-fuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import subprocess

import rollbar

# Get rollbar api token from env variables
token = os.environ['ROLLBAR_API_KEY']

# Set up rollbar
rollbar.init(
access_token=token,
environment='rust-fuzz',
)

# Gather all tests using cargo test
tests = subprocess.run(["cargo", "test", "fuzz_", "--", "--list"], stdout=subprocess.PIPE, check=True)
tests = tests.stdout.decode("utf-8").split("\n")

# Remove the final : test from tests
# The cargo test list also has some printouts that are not tests, so we remove those as well
tests = [o.split(": test")[0] for o in tests if "::" in o]

# Run forever
while True:
# Loop through tests and run, while capturing failure output
for test in tests:
print(test)
# We don't throw exception if underlying test fails
output = subprocess.run(["cargo", "test", test], stdout=subprocess.PIPE, check=False)
# If the test failed
if output.returncode != 0:
print(f"{test} failed")
str_output = output.stdout.decode("utf-8")
# Log to rollbar
rollbar.report_message(f'Rust test {test} failed', 'error', extra_data={'output': str_output})


Loading