]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - gw-tests/lib.sh
Update plotting -- not finished
[can-benchmark.git] / gw-tests / lib.sh
1 set -e
2
3 COUNT=10000
4
5 OPT_TRAFFIC=oneatatime
6
7 error() {
8     echo $1 >&2
9     exit 1
10 }
11
12 while [ $# -gt 0 ]; do
13     case "$1" in
14         -P|--no-plot) OPT_PLOT_DISABLE=1; shift;;
15         -p|--plot) OPT_PLOT_ONLY=1; shift;;
16         -X|--no-x11-plot) OPT_NO_X11=1; shift;;
17         -t) case "$2" in
18                 all|flood|50|oneatatime) OPT_TRAFFIC=$2;;
19                 *) error "Unknown traffic specification: $2";;
20             esac;
21             shift 2;;
22     esac
23 done
24
25 PATH=$PWD/../_compiled/bin/:$PATH
26
27 sshgw() {
28     local socket="$HOME/.ssh/cangw-connection"
29
30     if [[ ! -S $socket ]] || ! ssh -x -a -S $socket root@192.168.2.3 true; then
31         # Create master connection to speed up subsequenct command.
32         # The ssh is put into background and the connection is closed
33         # after 10 minutes)
34         ssh -f -M -S $socket root@192.168.2.3 sleep 600 > /dev/null 2>&1
35     fi
36     ssh -x -a -S $socket root@192.168.2.3 "$@"
37 }
38
39 cleanupgw() {
40     sshgw 'cangw -F'
41 }
42
43 _plot() {
44     local testname=`basename $0 .sh`
45
46     plot_cmds | sed -e "/set title/ s/[\"']\(.*\)[\"']/\"\1\\\\n($kvers)\"/" > plot.gp
47     if [[ ! -s plot.gp ]]; then return; fi
48     if [ -z "$OPT_NO_X11" ]; then
49         echo "set terminal x11 enhanced; $(< plot.gp)" | gnuplot -persist
50     fi
51     I=''
52     echo 'set terminal postscript color eps enhanced size 6cm,4cm lw 1 "Times-Roman" 10;' \
53         'set lmargin 8;' \
54         "$(< plot.gp)" | gnuplot > ${testname}$I.eps
55     echo "set terminal postscript color eps enhanced;" \
56         "$(< plot.gp)" | gnuplot | epstopdf --filter > ${testname}$I.pdf
57     mkdir -p thumb
58     convert -density 30  -gamma 0.5 -quality 90 -type Palette -depth 8 ${testname}$I.pdf thumb/${testname}$I.png
59     convert -density 150 -gamma 0.7 -quality 90 -type Palette -depth 8 ${testname}$I.pdf ${testname}$I.png
60
61 }
62
63 echo_plot() {
64     plot=$1
65     [[ "$_plot_separator" ]] && echo ", \\"
66     _plot_separator=t
67     echo -n "    " $plot
68 }
69
70 traffic_and_length() {
71     local opts
72     case $traffic in
73         flood) opts='';;
74         50)        opts="-p $((2*(44+$1*8)))";;
75         oneatatime)        opts="-o";;
76         *) error "Unknown traffic specification"
77     esac
78     echo $opts -l $1
79 }
80
81 _run() {
82     if [[ $OPT_TRAFFIC = all ]]
83     then traffics="flood 50 oneatatime"
84     else traffics=$OPT_TRAFFIC
85     fi
86     hostkvers=host-$(uname -r)
87     kvers=$(sshgw uname -r)
88     test=$(basename $0 .sh)
89     for traffic in $traffics; do
90         dir="results/$hostkvers/$kvers/$traffic/$test"
91         mkdir -p $dir
92         script=$(echo $dir | sed -e 's/[^/]*/../g')/${test}.sh
93         cd $dir
94         echo "Working directory: $dir"
95         if [[ ! "$OPT_PLOT_ONLY" ]]; then
96             # Remove data from the last measurement
97             rm -rf *
98             touch .results
99             cat > plot.sh <<-EOF
100                 #!/bin/bash
101                 exec $script --plot
102                 EOF
103             # Set can interfaces up
104             sshgw 'for i in 0 1; do ip link show dev can$i|grep -q UP || ip link set can$i up type can bitrate 1000000; done'
105             # Delete all vcan interfaces
106             sshgw 'for dev in $(ip l|grep -o vcan[^:]\\+); do ip link del dev $dev; done'
107             # Reset priorities
108             sshgw 'if pid=`pidof irq/145-can0`; then chrt -p -f 50 $pid > /dev/null; fi'
109             sshgw 'if pid=`pidof irq/146-can1`; then chrt -p -f 50 $pid > /dev/null; fi'
110             sshgw 'if pid=`pidof sirq-net-rx/0`; then chrt -p -f 49 $pid > /dev/null; fi'
111             sshgw 'if pid=`pidof sirq-net-tx/0`; then chrt -p -f 49 $pid > /dev/null; fi'
112             # Set the length of qdisc queue to avoid ENOBUFS errors
113             ifconfig can0 txqueuelen 200
114             cleanupgw
115
116             main
117
118         fi
119         if [[ ! "$OPT_PLOT_DISABLE" ]]; then
120             ./plot.sh
121         fi
122         cd -
123     done
124 }
125
126 test_end() {
127     test_end_called=t
128     exit_ok=
129     _run
130     exit_ok=t
131 }
132
133 _myexit() {
134     code=$?
135     cmd=$BASH_COMMAND
136     if [[ ! "$test_end_called" ]]; then
137         test_end_called=t
138         error "bug in the test script: No test_end called"
139     fi
140     if ! test -n "$exit_ok"; then
141         error "FATAL: Command '$cmd' exit with code $code"
142     fi
143 }
144
145 trap '_myexit' EXIT