-
Notifications
You must be signed in to change notification settings - Fork 16
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
test: add JS fuzz/invariant integration tests #658
test: add JS fuzz/invariant integration tests #658
Conversation
|
c848179
to
4da1eb1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One concern w.r.t. the leaking of static strings. Otherwise LGTM!
.into_string() | ||
.expect("path should be valid UTF-8"); | ||
|
||
// HACK: We need to leak the path as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For correctness, I believe we should still drop the leaked strings upon static deinitialization. That can be achieved by adding a local struct SomeName { inner: HashSet<&'static str> }
which has a impl Drop
. This destructor would be called when the static FAILURE_PATHS
is dropped, guaranteeing that our application doesn't report any memory leaks in tooling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I tried this out with LLVM leak sanitizer and it reports errors in the base branch, but not in this one, so I think it's ok as is.
Test command (tried on ARM linux in Docker): RUSTFLAGS="-Z sanitizer=leak" cargo +nightly test -p forge test_fuzz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I couldn't get Miri working on the forge
integration tests)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for validating with leak sanitizer.
This is the reason why Leak Sanitizer would not be able to detect a "memory leak" of this kind. It depends on your definition of memory leak, though. Leak sanitizer doesn't consider it a leak because a static variable is still referring to the address of the originally allocated strings.
I pushed a commit removing The previous version wasn't bad or anything, but I've had so many bad experiences with |
// One test as steps should be sequential | ||
it("FailingInvariant", async function () { | ||
const failureDir = testContext.invariantFailuresPersistDir; | ||
const defaultConfig = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename this to invariantConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed in ab94d0b
// The invariant failure directory should still be there | ||
assert.isTrue(existsSync(failureDir)); | ||
// The second run should be faster than the first because it should use the persisted failure. | ||
assert.isBelow(secondDuration, firstDuration * 0.25); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a more robust way to check this. The TestResult
objects have a kind.runs
number for invariant tests which will be 1 when there is a cached seed, and it will almost surely be above 1 when there's not (and this can be done even more unlikely by changing the % 13
part of the solidity test to a bigger value).
The problem is that runTestsWithStats
only returns the number of tests and failures. Maybe we can just add a testResults
property to its returned value, that way there's no need to refactor all the existing usages of that helper.
This is just a suggestion btw, feel free to keep it as is if you think that this approach won't have frequent false positives or negatives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good idea, switched to checking runs. The assertion is that there are more than 1 runs on an uncached run and there is 1 run on a cached one. I didn't want to increase the 13
to a larger value to reduce the chance of the invariant testing not catching the bug.
cc57a6d
to
5b22ff3
Compare
Co-authored-by: Franco Victorio <victorio.franco@gmail.com>
We can use fs.existsSync to check if a directory exists
020af16
to
7fe8315
Compare
Add JS fuzz/invariant integration tests and fix the following issues:
FuzzConfig::failure_persist_file
. Instead reflect in the type system that it's not optional.