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