]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - gw-tests/lib.sh
Merge branch 'master' of rtime.felk.cvut.cz:/can-benchmark
[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     # Set can interfaces up
34     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'
35     sshgw 'cangw -F'
36 }
37
38 _plot() {
39     local testname=`basename $0 .sh`
40
41     plot_cmds | sed -e "/set title/ s/[\"']\(.*\)[\"']/\"\1\\\\n($kvers)\"/" > plot.gp
42     if [ -z "$OPT_NO_X11" ]; then
43         echo "set terminal x11 enhanced; $(< plot.gp)" | gnuplot -persist
44     fi
45     I=''
46     echo 'set terminal postscript color eps enhanced size 6cm,4cm lw 1 "Times-Roman" 10;' \
47         'set lmargin 8;' \
48         "$(< plot.gp)" | gnuplot > ${testname}$I.eps
49     echo "set terminal postscript color eps enhanced;" \
50         "$(< plot.gp)" | gnuplot | epstopdf --filter > ${testname}$I.pdf
51     mkdir -p thumb
52     convert -density 30  -gamma 0.5 -quality 90 -type Palette -depth 8 ${testname}$I.pdf thumb/${testname}$I.png
53     convert -density 150 -gamma 0.7 -quality 90 -type Palette -depth 8 ${testname}$I.pdf ${testname}$I.png
54
55 }
56
57 create_dirs_and_links() {
58     local test=$1
59     local kver=$2
60
61     local  d=results/by-kern/$kver/$test
62     mkdir -p $d
63     mkdir -p results/by-test/$test
64     ln -sfT ../../${d#results/} results/by-test/$test/$kver
65     echo $d
66 }
67
68 _run() {
69     if [[ ! "$OPT_PLOT_ONLY" ]]; then
70         kernel_versions=$(sshgw uname -r)
71     else
72         kernel_versions=$(ls results/by-kern)
73     fi
74     for kvers in $kernel_versions; do
75         dir=$(create_dirs_and_links $(basename $0 .sh) $kvers)
76         script=$PWD/$0
77         cd $dir
78         echo "Working directory: $dir"
79         if [[ ! "$OPT_PLOT_ONLY" ]]; then
80             rm -rf *
81             cleanupgw
82             main
83             cp $script .
84         fi
85         _plot
86     done
87 }
88
89 test_end() {
90     test_end_called=t
91     exit_ok=
92     _run
93     exit_ok=t
94 }
95
96 _myexit() {
97     code=$?
98     cmd=$BASH_COMMAND
99     if [[ ! "$test_end_called" ]]; then
100         test_end_called=t
101         error "bug in the test script: No test_end called"
102     fi
103     if ! test -n "$exit_ok"; then
104         error "FATAL: Command '$cmd' exited with code $code"
105     fi
106 }
107
108 trap '_myexit' EXIT