Skip to content

Commit e01fe59

Browse files
author
Pascal Hertleif
authored
Merge pull request #14 from marcelbuesing/cantool-tests
Add cantools test setup
2 parents 6c7d88b + a37ae77 commit e01fe59

File tree

10 files changed

+965
-1
lines changed

10 files changed

+965
-1
lines changed

Cargo.lock

Lines changed: 198 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ members = [
1818
".",
1919
"testing/rust-integration",
2020
"testing/can-messages",
21+
"testing/cantools-messages",
2122
]

testing/README.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ NOTE: This is only known to work on Linux.
2323
2424
`candump` will output lines like `(1603881557.238509) vcan0 200#0594000000000000`.
2525
These can be used as test cases in the `rust-itegration` crate.
26+
27+
## Cantools
28+
29+
https://github.com/eerimoq/cantools[cantools] are used for comparing results of packing and unpacking.
30+
- Install cantools
31+
- Run `./cantools-messages/generate_example_code` in order to regenerate the c source code which is based on the dbc example.
32+
- Run `cargo test` in cantools-messages
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "cantools-messages"
3+
version = "0.1.0"
4+
authors = ["marcelbuesing <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
can-messages = { path = "../can-messages" }
11+
12+
13+
[build-dependencies]
14+
cc = "1.0"
15+
bindgen = "0.57.0"

testing/cantools-messages/build.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
extern crate bindgen;
2+
3+
use std::env;
4+
use std::path::PathBuf;
5+
6+
fn main() {
7+
// Tell cargo to invalidate the built crate whenever the wrapper changes
8+
println!("cargo:rerun-if-changed=wrapper.h");
9+
10+
cc::Build::new()
11+
.cpp(true)
12+
.file("example.c")
13+
.compile("example");
14+
15+
// The bindgen::Builder is the main entry point
16+
// to bindgen, and lets you build up options for
17+
// the resulting bindings.
18+
let bindings = bindgen::Builder::default()
19+
// The input header we would like to generate
20+
// bindings for.
21+
.header("wrapper.h")
22+
// Tell cargo to invalidate the built crate whenever any of the
23+
// included header files changed.
24+
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
25+
// Finish the builder and generate the bindings.
26+
.generate()
27+
// Unwrap the Result and panic on failure.
28+
.expect("Unable to generate bindings");
29+
30+
// Write the bindings to the $OUT_DIR/bindings.rs file.
31+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
32+
bindings
33+
.write_to_file(out_path.join("bindings.rs"))
34+
.expect("Couldn't write bindings!");
35+
}

0 commit comments

Comments
 (0)