# Testing

## Generating code from DBC files

The `.can-messages/build.rs` will use dbc-codegen to generate Rust code
from a given DBC file in `./dbc-examples` (`example.dbc` when no file is given).

IMPORTANT: The `rust-integration` crate uses the generated code!

## Generate test data using nodejs and socketcan

This small tool can be used to create test data for CAN messages.
Since we have successfully used NodeJS with socketcan to connect CAN devices,
we chose this known-working solution to compare our Rust tooling against.

## Setup

NOTE: This is only known to work on Linux.

- Run `sudo ./setup_virtual_can.sh`
- Launch `candump vcan0 -L` in a seperate terminal window
- In `node-socketcan`, edit `main.js` to your liking and run `node main.js --def=../dbc-examples/example.kcd`

`candump` will output lines like `(1603881557.238509) vcan0 200#0594000000000000`.
These can be used as test cases in the `rust-integration` crate.

## Cantools

https://github.com/eerimoq/cantools[cantools] are used for comparing results of packing and unpacking.
- Install cantools
- Run `./cantools-messages/generate_example_code` in order to regenerate the c source code which is based on the dbc example.
- Run `cargo test` in cantools-messages
