summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2016-11-02 11:21:24 -0700
committerNick Fitzgerald <fitzgen@gmail.com>2016-11-02 15:08:28 -0700
commitcd2754c4c75501a6b2f1f0e2a96c70dde39d3433 (patch)
treeda65404086e37b8f340347acda93523a71ad6865
parent58e70a3aae57f3cef4ede3baab65a9cf8fed0fd2 (diff)
Generate dummy uses when running our test suite
This extends the test runner to generate dummy C/C++ uses of the whitelisted types in a test header in the tests/uses/ directory. It does not yet compile the dummy uses into an object file whose DWARF debug info can be compared against our Rust bindings' DWARF debug info. Part of #151.
-rw-r--r--tests/tests.rs80
-rwxr-xr-xtests/tools/run-bindgen.py14
-rw-r--r--tests/uses/.gitignore2
3 files changed, 65 insertions, 31 deletions
diff --git a/tests/tests.rs b/tests/tests.rs
index addaa5ad..4954ac6f 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -12,10 +12,13 @@ use std::process;
const TEST_BATCH_DEFAULT_SIZE: usize = 16;
-fn spawn_run_bindgen<P, Q, R>(run_bindgen: P, bindgen: Q, header: R) -> process::Child
+fn spawn_run_bindgen<P, Q, R>(run_bindgen: P,
+ bindgen: Q,
+ header: R)
+ -> process::Child
where P: AsRef<Path>,
Q: AsRef<Path>,
- R: AsRef<Path>
+ R: AsRef<Path>,
{
let run_bindgen = run_bindgen.as_ref();
let bindgen = bindgen.as_ref();
@@ -36,19 +39,34 @@ fn spawn_run_bindgen<P, Q, R>(run_bindgen: P, bindgen: Q, header: R) -> process:
expected.push(file_name);
expected.set_extension("rs");
- let mut cmd = process::Command::new(run_bindgen);
- cmd.stdout(process::Stdio::piped())
+ // And the same style conversion as above, but for the dummy uses. We assume
+ // that .hpp means we should generate a .cpp uses file, and .h means we
+ // should generate a .c file.
+
+ let mut dummy_uses = PathBuf::from(header);
+ let file_name = dummy_uses.file_name()
+ .expect("Should still have filename")
+ .to_os_string();
+ dummy_uses.pop();
+ dummy_uses.pop();
+ dummy_uses.push("uses");
+ dummy_uses.push(file_name);
+ dummy_uses.set_extension(if header.extension().and_then(|s| s.to_str()) ==
+ Some("hpp") {
+ "cpp"
+ } else {
+ "c"
+ });
+
+ process::Command::new(run_bindgen)
+ .stdout(process::Stdio::piped())
.stderr(process::Stdio::piped())
.arg(bindgen)
.arg(header)
- .arg(expected);
-
- if cfg!(feature = "llvm_stable") {
- cmd.arg("--feature")
- .arg("llvm_stable");
- }
-
- cmd.spawn()
+ .arg(expected)
+ .arg("--dummy-uses")
+ .arg(dummy_uses)
+ .spawn()
.expect("Should be able to spawn run-bindgen.py child process")
}
@@ -84,12 +102,12 @@ fn run_bindgen_tests() {
.map(|result| result.expect("Should read directory entry"));
let tests = entries.filter(|entry| {
- match entry.path().extension().map(|s| s.to_str()) {
- Some(Some("h")) |
- Some(Some("hpp")) => true,
- _ => false,
- }
- }).collect::<Vec<_>>();
+ match entry.path().extension().and_then(|s| s.to_str()) {
+ Some("h") | Some("hpp") => true,
+ _ => false,
+ }
+ })
+ .collect::<Vec<_>>();
let batch_size = env::var("BINDGEN_TEST_BATCH_SIZE")
.ok()
@@ -101,22 +119,26 @@ fn run_bindgen_tests() {
// consumed when testing, so that we don't overload the system.
let children = tests.chunks(batch_size).map(|x| {
- x.iter().map(|entry| {
- let child = spawn_run_bindgen(run_bindgen.clone(), bindgen.clone(), entry.path());
- (entry.path(), child)
- }).collect::<Vec<_>>()
+ x.iter()
+ .map(|entry| {
+ let child = spawn_run_bindgen(run_bindgen.clone(),
+ bindgen.clone(),
+ entry.path());
+ (entry.path(), child)
+ })
+ .collect::<Vec<_>>()
});
let failures: Vec<_> = children.flat_map(|x| {
- x.into_iter().filter_map(|(path, mut child)| {
- let passed = child.wait()
- .expect("Should wait on child process")
- .success();
+ x.into_iter().filter_map(|(path, mut child)| {
+ let passed = child.wait()
+ .expect("Should wait on child process")
+ .success();
- if passed { None } else { Some((path, child)) }
+ if passed { None } else { Some((path, child)) }
+ })
})
- })
- .collect();
+ .collect();
let num_failures = failures.len();
diff --git a/tests/tools/run-bindgen.py b/tests/tools/run-bindgen.py
index bc8b567b..1f5f504e 100755
--- a/tests/tools/run-bindgen.py
+++ b/tests/tools/run-bindgen.py
@@ -41,6 +41,10 @@ def make_parser():
nargs=1,
help="Run tests that depend on bindgen being built with \
the given feature.")
+ parser.add_argument("--dummy-uses",
+ dest="dummy_uses",
+ help="The path to generate dummy C/C++ uses of the \
+ whitelisted types from the input header at.")
return parser
def usage_and_exit(*args):
@@ -117,9 +121,11 @@ def run_cmd(command, **kwargs):
print("run-bindgen.py: running", command)
subprocess.check_call(command, **kwargs)
-def generate_bindings(bindgen, flags, header, output):
+def generate_bindings(bindgen, dummy_uses, flags, header, output):
"""Generate the rust bindings."""
command = [bindgen, "-o", output]
+ if dummy_uses:
+ command.extend(["--dummy-uses", dummy_uses])
command.extend(flags)
command.append(header)
run_cmd(command, cwd=os.getcwd(), env=make_bindgen_env())
@@ -166,7 +172,11 @@ def main():
test_flags = get_bindgen_flags(args.header)
expected_bindings = get_expected_bindings(args.rust_bindings)
- generate_bindings(args.bindgen, test_flags, args.header, args.rust_bindings)
+ generate_bindings(args.bindgen,
+ args.dummy_uses,
+ test_flags,
+ args.header,
+ args.rust_bindings)
test_generated_bindings(args.rust_bindings)
check_actual_vs_expected(expected_bindings, args.rust_bindings)
sys.exit(0)
diff --git a/tests/uses/.gitignore b/tests/uses/.gitignore
new file mode 100644
index 00000000..40d7cb4c
--- /dev/null
+++ b/tests/uses/.gitignore
@@ -0,0 +1,2 @@
+*.c
+*.cpp