Tests on Running CANopen network are implemented with two CANopenNode devices, by default running on Linux virtual CAN interface. One of them has gateway interface and communicates with program cocomm
.
Tests are run in Linux command line with Bash Automated Testing System - BATS, which is included in CANopenSocket as three git submodules.
Test results are available in test_report.md.
- Get CANopenSocket and all submodules as described in README.md
- make
cocomm
,canopend
andbasicDevice
cd test/running_canopen$
./test_canopend.sh vcan0
This will:
- start
vcan0
interface if not already existed. - run two CANopenNode Linux devices in background (
start_canopen.sh
script):CANopenNode/canopend
with nodeId=1 and gateway interface:local-/tmp/CO_command_socket
examples/basicDevice/basicDevice
with nodeId=4
- run tests and measure time
- cleanup (
tmp/stop_canopen.sh
script, generated bystart_canopen.sh
).
If argument vcan0
or similar is omitted, it is assumed, two CANopen devices are already running in system. In that case steps 1, 2 and 4 are skipped.
start_canopen.sh <CAN device>
script runs two CANopenNode Linux devices in background.
Possible configuration options can configure CANopenNode applications. To override default values run the commands from command line before running test scripts. Default configuration is:
export co_device_1="../../CANopenNode/canopend"
export co_device_4="../../examples/basicDevice/basicDevice"
It is possible to run two CANopen devices without start_canopen.sh
script and then run the tests. Devices can be connected with on real CAN bus and second device can run on any target system. By default this script runs following commands and prepares tmp/stop_canopen.sh
script for cleanup:
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
mkdir tmp
echo "-" > tmp/dev1_lss.persist
echo "-" > tmp/dev1_od_comm.persist
../../CANopenNode/canopend vcan0 -i 1 -s "tmp/dev1_" -c "local-/tmp/CO_command_socket"
echo "-" > tmp/dev4_lss.persist
echo "-" > tmp/dev4_od_comm.persist
echo "-" > tmp/dev4_od_app_auto.persist
echo "-" > tmp/dev4_od_app.persist
../../examples/basicDevice/basicDevice vcan0 -i 4 -s "tmp/dev4_"
# after finish with testing terminate the programs and `rm -r tmp`
There is also a helper script, which runs only canopend and candump on specified interface in terminal:
cd tools
./run_canopend_candump.sh <can device>
Before running the tests, specify cocomm location and CAN device, which will be used for monitoring CAN messages (candump). To override other configuration variables see file config_bats.sh
. Default configuration is:
export can_device=vcan0
export cocomm="../../cocomm/cocomm"
Then simply run the separate tests from the same terminal:
./basic_NMT_SDO_heartbeat.bats
./heartbeat_consumer.bats
./SDO_transfer.bats
Open the *.bats
script file in text editor and examine the contents. Script is quite straightforward, see BATS usage and BATS assert for information on testing commands. Command line program cocomm
is used for running each test. For cocomm
example usage see basicDevice/README.md. Program uses here one additional functionality - it prints dump of actual CAN messages, which occur with each cocomm
command. So BATS can verify the complete result.