]> rtime.felk.cvut.cz Git - can-benchmark.git/blobdiff - tests/lib.sh
Test infrastructure almost ready
[can-benchmark.git] / tests / lib.sh
index 4fc9fc2df833fc783b17f1e0d7f890248a8037a3..984af0a37d76bcd382aed2bd392ad944bccffddb 100644 (file)
@@ -1,3 +1,10 @@
+
+while [ $# -gt 0 ]; do
+    case "$1" in
+       -p) OPT_PLOT_ONLY=1; shift;;
+    esac
+done
+
 set -x
 set -e
 
@@ -5,20 +12,68 @@ PATH=$PWD/../_compiled/bin/:$PATH
 
 rmmod_can() {
     modprobe -r lincan
+    modprobe -r kvaser_pci
+    modprobe -r vcan
 }
 
-load_lincan_hw() {
+prepare_lincan_hw() {
     rmmod_can
     modprobe -C /dev/null lincan hw=pcican-q io=1 baudrate=1000,1000,1000,1000 processlocal=0
+    CAN0=/dev/can0
+    CAN1=/dev/can1
+    DRIVER=lincan
     sleep 0.1
 }
 
-load_lincan_virtual() {
+prepare_lincan_virtual() {
     rmmod_can
     modprobe -C /dev/null lincan hw=virtual io=0 baudrate=0
+    CAN0=/dev/can0
+    DRIVER=lincan-virtual
     sleep 0.1
 }
 
-load_socketcan() {
+prepare_socketcan_hw() {
+    rmmod_can
+    modprobe kvaser_pci
+    echo 1000000 > /sys/class/net/can0/can_bittiming/bitrate
+    ip link set up dev can0
+    echo 1000000 > /sys/class/net/can1/can_bittiming/bitrate
+    ip link set up dev can1
+    echo 1000000 > /sys/class/net/can2/can_bittiming/bitrate
+    ip link set up dev can2
+    echo 1000000 > /sys/class/net/can3/can_bittiming/bitrate
+    ip link set up dev can3
+    CAN0=socketcan:can0
+    CAN1=socketcan:can1
+    DRIVER=socketcan
+}
+
+prepare_socketcan_virtual() {
     rmmod_can
+    modprobe vcan
+    ip link add dev vcan0 type vcan
+    ip link set up dev vcan0
+    CAN0=socketcan:vcan0
+    DRIVER=socketcan-virtual
 }
+
+run_tests() {
+    [ "$OPT_PLOT_ONLY" -eq 1 ] && return
+       
+    tests=${TESTS:-lincan_hw socketcan_hw}
+    for i in $tests; do
+       prepare_$i
+       t
+    done
+}
+
+plot() {
+    if [ -n "$PLOT_CMD" ]; then
+       echo "set terminal postscript color eps enhanced;
+             set output '`basename $0 .sh`.eps'; $PLOT_CMD" | gnuplot
+       echo "set terminal x11 enhanced; $PLOT_CMD" | gnuplot -persist
+    fi
+}
+
+trap 'run_tests && plot' EXIT