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