-
Notifications
You must be signed in to change notification settings - Fork 743
Factor out a general purpose predicate script from the csmith
driver
#1068
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
Conversation
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.
Looks great!
But there is one issue. Docs state that you can run
path/to/rust-bindgen/csmith-fuzzing/predicate.py
but actually you can't. See my comment on predicate.py
csmith-fuzzing/predicate.py
Outdated
|
||
def main(): | ||
args = parser.parse_args() | ||
os.environ["RUST_BACKTRACE"] = "1" |
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.
Wouldn't it be cooler to specify RUST_BACKTRACE=full
?
csmith-fuzzing/predicate.py
Outdated
|
||
def run_bindgen(args, bindings): | ||
child = run( | ||
["cargo", "run", "--", args.input, "-o", bindings] + shlex.split(args.bindgen_args), |
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.
Nice!
csmith-fuzzing/predicate.py
Outdated
def run_bindgen(args, bindings): | ||
child = run( | ||
["cargo", "run", "--", args.input, "-o", bindings] + shlex.split(args.bindgen_args), | ||
cwd=os.path.abspath(os.path.dirname(sys.argv[0])), |
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 don't quite get why do we need this.
If I run this script like this:
~/rust-bindgen $ ./csmith-fuzzing/predicate.py csmith-fuzzing/csmith.h
It wouldn't find csmith.h
, because real path would be ./csmith-fuzzing/csmith-fuzzing/csmith.h
.
If we would run:
~/rust-bindgen/csmith-fuzzing $ ./predicate.py csmith.h
we would be already in csmith-fuzzing
.
Maybe it would be better to drop cwd
and do:
cargo run --manifest-path $(basedir)/../Cargo.toml ...
?
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.
Great catch!
csmith-fuzzing/driver.py
Outdated
output.name, | ||
"-o", test.name, | ||
]) | ||
BINDGEN_ARGS = "--with-derive-partialeq --with-derive-eq --with-derive-partialord --with-derive-ord --with-derive-hash --with-derive-default" |
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.
Wouldn't this be more legible?
BINDGEN_ARGS = "--with-derive-partialeq \
--with-derive-eq \
--with-derive-partialord \
--with-derive-ord \
--with-derive-hash \
--with-derive-default"
As a little bonus: more clear diffs
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.
Yes :)
CONTRIBUTING.md
Outdated
# Invoke the general purpose predicate script that comes in the | ||
# `bindgen` repository. | ||
path/to/rust-bindgen/csmith-fuzzing/predicate.py \ | ||
$PREDICATE_FLAGS \ |
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.
There are no $PREDICATE_FLAGS
and I think it would be nice if we would provide default one, or at least placeholder.
|
||
... | grep "pub _base: MyInvalidBaseTypeThatShouldntBeHere" | ||
And you can always write your own, arbitrary predicate script if you prefer. |
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.
Maybe we should provide a link to the old hand-written predicate script example?
I think it may be very helpful for those who stumbled on lack of predicate.py
functionality. Before extending predicate.py
one might want to do experiments which may be more productive with bare shell scripts.
# Make sure that the reduced test case is valid C/C++ by compiling it. If it | ||
# isn't valid C/C++, this command will exit with a nonzero exit code and cause | ||
# the whole script to do the same. | ||
clang[++ --std=c++14] -c ./pre_processed_header.hpp |
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.
predicate.py
doesn't do this anymore and predicate.sh
doesn't contain this either.
Is it useful?
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.
Ultimately, I don't think so.
…a given header First, `bindgen` is run on the input header. Then the emitted bindings are compiled with `rustc`. Finally, the compiled bindings' layout tests are run. By default, this script will exit zero if all of the above steps are successful, and non-zero if any of them fail. This is appropriate for determining if some test case (perhaps generated with `csmith` or another fuzzer) uncovers any bugs in `bindgen`. However, this script can also be used when reducing (perhaps with `creduce`) a known-bad test case into a new, smaller test case that exhibits the same bad behavior. In this mode, you might expect that the emitted bindings fail to compile with `rustc`, and want to exit non-zero early if that is not the case. See the "reducing arguments" section for details and what knobs are available.
It is a lot more streamlined than writing a big nasty ol' bash script.
7503af3
to
349c1f9
Compare
Nice! |
@bors-servo r+ |
📌 Commit 349c1f9 has been approved by |
Factor out a general purpose predicate script from the `csmith` driver This allows it to be used by both fuzzers and when using `creduce`. See each commit for details. r? @pepyakin
💔 Test failed - status-travis |
Looks like spurious, i've restarted the job |
☀️ Test successful - status-travis |
This allows it to be used by both fuzzers and when using
creduce
. See each commit for details.r? @pepyakin