File: etsi_coaptest.sh

package info (click to toggle)
libcoap3 4.3.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,368 kB
  • sloc: ansic: 60,037; makefile: 1,280; sh: 938; python: 6
file content (210 lines) | stat: -rwxr-xr-x 4,905 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash

# test coap implementation for the ETSI CoAP Plugtest in March 2012
# with test cases described in Plugtests Guide First Draft V0.0.16

COAP_CLIENT=./coap-client
tcpdump=/usr/sbin/tcpdump
DEFAULTPORT=5683
CLIENTPORT=61701
# directory for logging
LOGDIR=logs
# set client's verbose level
callopts=" -v 5"
longtimeout=180
clienttimeout=$longtimeout
timeoutcmd=/usr/bin/timeout

#URIREGEX=.*\/.*
# resembles approximately an ip address
IPADDRREGEX="^[1-2]?[0-9]{1,2}\.[1-2]?[0-9]{1,2}\.[1-2]?[0-9]{1,2}\.[1-2]?[0-9]{1,2}"
# FIXME IPV6 address
IP6REGEX=".*:.*:.*"

# Testcase groups
CORE=( TD_COAP_CORE_01 TD_COAP_CORE_02 TD_COAP_CORE_03
TD_COAP_CORE_04 TD_COAP_CORE_05 TD_COAP_CORE_06 TD_COAP_CORE_07
TD_COAP_CORE_08 TD_COAP_CORE_09 TD_COAP_CORE_10 TD_COAP_CORE_11
TD_COAP_CORE_12 TD_COAP_CORE_13 TD_COAP_CORE_14 TD_COAP_CORE_15 )
LINK=( TD_COAP_LINK_01 TD_COAP_LINK_02 )
BLOCK=( TD_COAP_BLOCK_01 TD_COAP_BLOCK_02 TD_COAP_BLOCK_03 TD_COAP_BLOCK_04 )
OBS=( TD_COAP_OBS_01 TD_COAP_OBS_02 TD_COAP_OBS_03 TD_COAP_OBS_04 TD_COAP_OBS_05 )

testgroups=( CORE LINK BLOCK OBS )

# if no test cases are specified, we want to run all tests
testnumber=-1
group=''

source `dirname $0`/etsi_testcases.sh

function usage {
echo "Usage:  `basename $0` [-n testnumber] [-g groupname] [-t timeout] [-P server_port] [-p client port] [-d logdir] [-v] -i interface server_address" 1>&2
echo "-n test case to be accomplished" 1>&2
echo "-g group to be tested" 1>&2
echo "-t time in seconds until timout for single test" 1>&2
echo "-i interface to use for tcpdump" 1>&2
echo "-P port of server" 1>&2
echo "-p port client listens on" 1>&2
echo "-d directory for logfiles" 1>&2
echo "-v verbose level" 1>&2
}

function run_test {
  tn=$1
  clientopts=''
  if [ -z $1 ]; then
    echo "missing argument for run_test"
    exit 1
  fi
  echo -e "running test: $tn"
  if [ $(type -t $tn) ] ; then
    $tn $tn
    echo
  else
    echo "not implemented"
    echo
  fi
}

while getopts "n:g:t:i:P:p:d:v" OPTION;
do
# A missing argument for an option leads getopts to take the next
# option as the parameter. We want to prevent that.
case $OPTARG in
-*) echo "Missing argument for option \"-$OPTION\"."
echo $USAGE
exit 1
;;
esac

case $OPTION in
n) # number of test case
testnumber=$((OPTARG-1))
;;

g) # name of test group
# is there a group with that name?
for i in "${testgroups[@]}"
  do
  # group doesn't have to be case sensitive
  tmpgroup=$(echo $OPTARG | tr '[:lower:]' '[:upper:]')
  if [  $i == $tmpgroup ] ; then
    group=$tmpgroup
    break
  fi
done
if [ -z $group ] ; then
  echo "No such group:" $OPTARG". Available groups are: ${testgroups[@]}"
  exit 1
fi
;;

t)
# add timeout to client parameters
clienttimeout=$((OPTARG))
callopts="$callopts -B $clienttimeout"
;;

i)
# interface tcpdump listens on
INTERFACE=$OPTARG
;;

P)
# port the server listens on
SERVERPORT=$((OPTARG))
;;

p)
# port the client listens on
CLIENTPORT=$((OPTARG))
;;

d)
# directory tcpdump writes the logfiles into
LOGDIR=$OPTARG
;;

v)
verbose=1
;;

?)
# any other option is invalid
echo -e $USAGE 1>&2
exit 1
;;
esac
done

# catch last argument: server address
ARGS=$(($#+1))
SERVERADDRESS=${@: -1}

if [[ ! $((ARGS-OPTIND)) -eq 1 ]]; then
  echo -e "\nno server address specified"
  usage
  exit 1
fi

# if no port number was specified by user, the server address for the
# coap-client is $SERVERADDRESS

if [ -z $SERVERPORT ]; then
  SERVERPORT=$DEFAULTPORT
  if [[ $SERVERADDRESS =~ $IP6REGEX ]]; then
    SERVERTUP=\[$SERVERADDRESS\]
  else
    SERVERTUP=$SERVERADDRESS
  fi
else
   if [[ $SERVERADDRESS =~ $IP6REGEX ]]; then
    SERVERTUP=\[$SERVERADDRESS\]:$SERVERPORT
  else
    SERVERTUP=$SERVERADDRESS:$SERVERPORT
  fi
fi

# create directory for logging, if it's not already there
if [[ ! -e $LOGDIR ]]; then
  mkdir -p $LOGDIR
  if [ $? ]; then
    echo created directory \""$LOGDIR"\" for logging
  fi
fi

# the interface for tcpdump is mandatory
if [ -z $INTERFACE ]; then
  echo -e "\nno interface given"
  exit 1
fi

# determine which tests to run
if [ -n "$group" ] ; then
  echo group: $group
  if [[ ! $testnumber -eq -1 ]] ; then
    groupsize=$(eval "echo \${#$(echo $group)[@]}")
    # is there a testcase with number $testnumber in group $group
    if [ $testnumber -ge $groupsize -o $testnumber -lt 0 ] ; then
      echo "No such testcase number: $OPTARG. Test cases numbers are 1 to" $groupsize
      exit 1
    else
      # run test with group $group and number $testnumber
      run_test $(eval "echo \${$(echo $group)[$testnumber]}")
    fi
  else
    # if no testnumber was specified, we want to run all tests in that group
    for i in $(eval "echo \${$(echo $group)[@]}") ; do
      run_test $i
    done
  fi
else
    # run all tests of all groups
    for j in ${testgroups[@]} ; do
      echo "group: $j"
      for k in $(eval "echo \${$(echo $j)[@]}") ; do
        run_test $k
      done
    done
fi