summaryrefslogtreecommitdiff
path: root/bindgen-tests/tests
diff options
context:
space:
mode:
authorChristian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com>2023-02-10 12:19:13 -0500
committerGitHub <noreply@github.com>2023-02-10 12:19:13 -0500
commit36937a72e0f50d95f2402e9c3e4316014765c8cc (patch)
treee19387c8f60550a94687460235e71c87e6cfeff7 /bindgen-tests/tests
parentce0ae76899a39a93e7db8f8ad24c5e681a3d7294 (diff)
Update `quickcheck` version (#2411)
This is done to deal with the existing vulnerabilities in older versions of `thread_local` and `regex`
Diffstat (limited to 'bindgen-tests/tests')
-rw-r--r--bindgen-tests/tests/quickchecking/Cargo.toml3
-rw-r--r--bindgen-tests/tests/quickchecking/src/bin.rs3
-rw-r--r--bindgen-tests/tests/quickchecking/src/fuzzers.rs51
-rw-r--r--bindgen-tests/tests/quickchecking/src/lib.rs14
-rw-r--r--bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs33
5 files changed, 50 insertions, 54 deletions
diff --git a/bindgen-tests/tests/quickchecking/Cargo.toml b/bindgen-tests/tests/quickchecking/Cargo.toml
index 455a8240..b579d4ea 100644
--- a/bindgen-tests/tests/quickchecking/Cargo.toml
+++ b/bindgen-tests/tests/quickchecking/Cargo.toml
@@ -15,8 +15,7 @@ path = "src/bin.rs"
[dependencies]
clap = "2.28"
lazy_static = "1.0"
-quickcheck = "0.4"
-rand = "0.3"
+quickcheck = "1.0"
tempdir = "0.3"
[features]
diff --git a/bindgen-tests/tests/quickchecking/src/bin.rs b/bindgen-tests/tests/quickchecking/src/bin.rs
index f2b52e82..7c189ee8 100644
--- a/bindgen-tests/tests/quickchecking/src/bin.rs
+++ b/bindgen-tests/tests/quickchecking/src/bin.rs
@@ -105,8 +105,7 @@ fn main() {
let output_path: Option<&str> = matches.value_of("path");
let generate_range: usize =
matches.value_of("range").unwrap().parse::<usize>().unwrap();
- let tests: usize =
- matches.value_of("count").unwrap().parse::<usize>().unwrap();
+ let tests: u64 = matches.value_of("count").unwrap().parse::<u64>().unwrap();
quickchecking::test_bindgen(generate_range, tests, output_path)
}
diff --git a/bindgen-tests/tests/quickchecking/src/fuzzers.rs b/bindgen-tests/tests/quickchecking/src/fuzzers.rs
index 4188f8f5..003e9bf3 100644
--- a/bindgen-tests/tests/quickchecking/src/fuzzers.rs
+++ b/bindgen-tests/tests/quickchecking/src/fuzzers.rs
@@ -1,5 +1,4 @@
-use quickcheck::{Arbitrary, Gen, StdGen};
-use rand::thread_rng;
+use quickcheck::{Arbitrary, Gen};
use std::fmt;
/// BaseTypeC is used in generation of C headers to represent the C language's
@@ -182,8 +181,8 @@ impl MakeUnique for DeclarationC {
/// A qucickcheck trait for describing how DeclarationC types can be
/// randomly generated and shrunk.
impl Arbitrary for DeclarationC {
- fn arbitrary<G: Gen>(g: &mut G) -> DeclarationC {
- match g.gen_range(0, 5) {
+ fn arbitrary(g: &mut Gen) -> DeclarationC {
+ match gen_range(g, 0, 5) {
0 => DeclarationC::FunctionDecl(FunctionPrototypeC::arbitrary(g)),
1 => DeclarationC::FunctionPtrDecl(
FunctionPointerDeclarationC::arbitrary(g),
@@ -214,7 +213,7 @@ impl fmt::Display for DeclarationC {
/// A qucickcheck trait for describing how DeclarationListC types can be
/// randomly generated and shrunk.
impl Arbitrary for DeclarationListC {
- fn arbitrary<G: Gen>(g: &mut G) -> DeclarationListC {
+ fn arbitrary(g: &mut Gen) -> DeclarationListC {
DeclarationListC {
decls: Arbitrary::arbitrary(g),
}
@@ -235,7 +234,7 @@ impl fmt::Display for DeclarationListC {
/// A qucickcheck trait for describing how BaseTypeC types can be
/// randomly generated and shrunk.
impl Arbitrary for BaseTypeC {
- fn arbitrary<G: Gen>(g: &mut G) -> BaseTypeC {
+ fn arbitrary(g: &mut Gen) -> BaseTypeC {
// Special case `long double` until issue #550 is resolved.
let base_type = vec![
"char",
@@ -286,7 +285,7 @@ impl fmt::Display for BaseTypeC {
/// A qucickcheck trait for describing how TypeQualifierC types can be
/// randomly generated and shrunk.
impl Arbitrary for TypeQualifierC {
- fn arbitrary<G: Gen>(g: &mut G) -> TypeQualifierC {
+ fn arbitrary(g: &mut Gen) -> TypeQualifierC {
let qualifier = vec!["const", ""];
TypeQualifierC {
def: String::from(*g.choose(&qualifier).unwrap()),
@@ -304,10 +303,10 @@ impl fmt::Display for TypeQualifierC {
/// A qucickcheck trait for describing how PointerLevelC types can be
/// randomly generated and shrunk.
impl Arbitrary for PointerLevelC {
- fn arbitrary<G: Gen>(g: &mut G) -> PointerLevelC {
+ fn arbitrary(g: &mut Gen) -> PointerLevelC {
PointerLevelC {
// 16 is an arbitrary "not too big" number for capping pointer level.
- def: (0..g.gen_range(0, 16)).map(|_| "*").collect::<String>(),
+ def: (0..gen_range(g, 0, 16)).map(|_| "*").collect::<String>(),
}
}
}
@@ -322,16 +321,16 @@ impl fmt::Display for PointerLevelC {
/// A qucickcheck trait for describing how ArrayDimensionC types can be
/// randomly generated and shrunk.
impl Arbitrary for ArrayDimensionC {
- fn arbitrary<G: Gen>(g: &mut G) -> ArrayDimensionC {
+ fn arbitrary(g: &mut Gen) -> ArrayDimensionC {
// Keep these small, clang complains when they get too big.
- let dimensions = g.gen_range(0, 5);
+ let dimensions = gen_range(g, 0, 5);
let mut def = String::new();
- let lower_bound = i32::from(cfg!(feature = "zero-sized-arrays"));
+ let lower_bound = u64::from(cfg!(feature = "zero-sized-arrays"));
for _ in 1..dimensions {
// 16 is an arbitrary "not too big" number for capping array size.
- def += &format!("[{}]", g.gen_range(lower_bound, 16));
+ def += &format!("[{}]", gen_range(g, lower_bound, 16));
}
ArrayDimensionC { def }
}
@@ -355,7 +354,7 @@ impl MakeUnique for BasicTypeDeclarationC {
/// A qucickcheck trait for describing how BasicTypeDeclarationC types can be
/// randomly generated and shrunk.
impl Arbitrary for BasicTypeDeclarationC {
- fn arbitrary<G: Gen>(g: &mut G) -> BasicTypeDeclarationC {
+ fn arbitrary(g: &mut Gen) -> BasicTypeDeclarationC {
BasicTypeDeclarationC {
type_qualifier: Arbitrary::arbitrary(g),
type_name: Arbitrary::arbitrary(g),
@@ -392,12 +391,12 @@ impl MakeUnique for StructDeclarationC {
/// A qucickcheck trait for describing how StructDeclarationC types can be
/// randomly generated and shrunk.
impl Arbitrary for StructDeclarationC {
- fn arbitrary<G: Gen>(g: &mut G) -> StructDeclarationC {
+ fn arbitrary(g: &mut Gen) -> StructDeclarationC {
// Reduce generator size as a method of putting a bound on recursion.
// When size < 1 the empty list is generated.
let reduced_size: usize = (g.size() / 2) + 1;
let mut decl_list: DeclarationListC =
- Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size));
+ Arbitrary::arbitrary(&mut Gen::new(reduced_size));
let mut fields: DeclarationListC = DeclarationListC { decls: vec![] };
for (i, decl) in decl_list.decls.iter_mut().enumerate() {
@@ -440,12 +439,12 @@ impl MakeUnique for UnionDeclarationC {
/// A qucickcheck trait for describing how UnionDeclarationC types can be
/// randomly generated and shrunk.
impl Arbitrary for UnionDeclarationC {
- fn arbitrary<G: Gen>(g: &mut G) -> UnionDeclarationC {
+ fn arbitrary(g: &mut Gen) -> UnionDeclarationC {
// Reduce generator size as a method of putting a bound on recursion.
// When size < 1 the empty list is generated.
let reduced_size: usize = (g.size() / 2) + 1;
let mut decl_list: DeclarationListC =
- Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size));
+ Arbitrary::arbitrary(&mut Gen::new(reduced_size));
let mut fields: DeclarationListC = DeclarationListC { decls: vec![] };
for (i, decl) in decl_list.decls.iter_mut().enumerate() {
@@ -488,7 +487,7 @@ impl MakeUnique for FunctionPointerDeclarationC {
/// A qucickcheck trait for describing how FunctionPointerDeclarationC types can
/// be randomly generated and shrunk.
impl Arbitrary for FunctionPointerDeclarationC {
- fn arbitrary<G: Gen>(g: &mut G) -> FunctionPointerDeclarationC {
+ fn arbitrary(g: &mut Gen) -> FunctionPointerDeclarationC {
FunctionPointerDeclarationC {
type_qualifier: Arbitrary::arbitrary(g),
type_name: Arbitrary::arbitrary(g),
@@ -525,7 +524,7 @@ impl MakeUnique for FunctionPrototypeC {
/// A qucickcheck trait for describing how FunctionPrototypeC types can be
/// randomly generated and shrunk.
impl Arbitrary for FunctionPrototypeC {
- fn arbitrary<G: Gen>(g: &mut G) -> FunctionPrototypeC {
+ fn arbitrary(g: &mut Gen) -> FunctionPrototypeC {
FunctionPrototypeC {
type_qualifier: Arbitrary::arbitrary(g),
type_name: Arbitrary::arbitrary(g),
@@ -554,7 +553,7 @@ impl fmt::Display for FunctionPrototypeC {
/// A qucickcheck trait for describing how ParameterC types can be
/// randomly generated and shrunk.
impl Arbitrary for ParameterC {
- fn arbitrary<G: Gen>(g: &mut G) -> ParameterC {
+ fn arbitrary(g: &mut Gen) -> ParameterC {
ParameterC {
type_qualifier: Arbitrary::arbitrary(g),
type_name: Arbitrary::arbitrary(g),
@@ -577,7 +576,7 @@ impl fmt::Display for ParameterC {
/// A qucickcheck trait for describing how ParameterListC types can be
/// randomly generated and shrunk.
impl Arbitrary for ParameterListC {
- fn arbitrary<G: Gen>(g: &mut G) -> ParameterListC {
+ fn arbitrary(g: &mut Gen) -> ParameterListC {
ParameterListC {
params: Arbitrary::arbitrary(g),
}
@@ -601,7 +600,7 @@ impl fmt::Display for ParameterListC {
/// A qucickcheck trait for describing how HeaderC types can be
/// randomly generated and shrunk.
impl Arbitrary for HeaderC {
- fn arbitrary<G: Gen>(g: &mut G) -> HeaderC {
+ fn arbitrary(g: &mut Gen) -> HeaderC {
let mut decl_list: DeclarationListC = Arbitrary::arbitrary(g);
for (i, decl) in decl_list.decls.iter_mut().enumerate() {
decl.make_unique(i);
@@ -628,3 +627,9 @@ impl fmt::Debug for HeaderC {
write!(f, "{}", self)
}
}
+
+/// FIXME: is this actually uniform?
+fn gen_range(gen: &mut Gen, lo: u64, hi: u64) -> u64 {
+ let len = hi - lo;
+ (u64::arbitrary(gen) % len) + lo
+}
diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs
index 75bfc237..e9f3798d 100644
--- a/bindgen-tests/tests/quickchecking/src/lib.rs
+++ b/bindgen-tests/tests/quickchecking/src/lib.rs
@@ -5,16 +5,14 @@
//! ```rust
//! extern crate quickcheck;
//! extern crate quickchecking;
-//! extern crate rand;
-//! use quickcheck::{Arbitrary, Gen, StdGen};
+//! use quickcheck::{Arbitrary, Gen};
//! use quickchecking::fuzzers;
-//! use rand::thread_rng;
//!
//! fn main() {
//! let generate_range: usize = 10; // Determines things like the length of
//! // arbitrary vectors generated.
//! let header = fuzzers::HeaderC::arbitrary(
-//! &mut StdGen::new(thread_rng(), generate_range));
+//! &mut Gen::new(generate_range));
//! println!("{}", header);
//! }
//! ```
@@ -23,11 +21,9 @@
#[macro_use]
extern crate lazy_static;
extern crate quickcheck;
-extern crate rand;
extern crate tempdir;
-use quickcheck::{QuickCheck, StdGen, TestResult};
-use rand::thread_rng;
+use quickcheck::{Gen, QuickCheck, TestResult};
use std::error::Error;
use std::fs::File;
use std::io::Write;
@@ -110,7 +106,7 @@ fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult {
/// to the `csmith-fuzzing/predicate.py` script.
pub fn test_bindgen(
generate_range: usize,
- tests: usize,
+ tests: u64,
output_path: Option<&str>,
) {
if let Some(path) = output_path {
@@ -120,6 +116,6 @@ pub fn test_bindgen(
QuickCheck::new()
.tests(tests)
- .gen(StdGen::new(thread_rng(), generate_range))
+ .gen(Gen::new(generate_range))
.quickcheck(bindgen_prop as fn(fuzzers::HeaderC) -> TestResult)
}
diff --git a/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs
index 0d43f300..e394efe3 100644
--- a/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs
+++ b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs
@@ -1,96 +1,93 @@
extern crate quickcheck;
extern crate quickchecking;
-extern crate rand;
-use quickcheck::{Arbitrary, StdGen};
+use quickcheck::{Arbitrary, Gen};
use quickchecking::fuzzers::{
ArrayDimensionC, BaseTypeC, BasicTypeDeclarationC, DeclarationC,
DeclarationListC, FunctionPointerDeclarationC, FunctionPrototypeC, HeaderC,
ParameterC, ParameterListC, PointerLevelC, StructDeclarationC,
TypeQualifierC, UnionDeclarationC,
};
-use rand::thread_rng;
-
#[test]
fn test_declaraion_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: DeclarationC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_declaraion_list_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: DeclarationListC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_base_type_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: BaseTypeC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_type_qualifier_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: TypeQualifierC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_pointer_level_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: PointerLevelC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_array_dimension_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: ArrayDimensionC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_basic_type_declaration_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: BasicTypeDeclarationC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_struct_declaration_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: StructDeclarationC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_union_declaration_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: UnionDeclarationC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_function_pointer_declaration_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: FunctionPointerDeclarationC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_function_prototype_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: FunctionPrototypeC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_parameter_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: ParameterC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_parameter_list_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: ParameterListC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_header_c_does_not_panic() {
- let gen = &mut StdGen::new(thread_rng(), 50);
+ let gen = &mut Gen::new(50);
let _: HeaderC = Arbitrary::arbitrary(gen);
}