examples/ipsec-secgw: clean up test scripts
[dpdk.git] / examples / ipsec-secgw / test / run_test.sh
1 #! /bin/bash
2 # SPDX-License-Identifier: BSD-3-Clause
3
4 # Usage: /bin/bash run_test.sh [-46miflscph] <ipsec_mode>
5 # Run all defined linux_test.sh test-cases one by one
6 # If <ipsec_mode> is specified, run only that test case
7 # User has to setup properly the following environment variables:
8 #  SGW_PATH     - path to the ipsec-secgw binary to test
9 #  REMOTE_HOST  - ip/hostname of the DUT
10 #  REMOTE_IFACE - iface name for the test-port on DUT
11 #  ETH_DEV      - ethernet device to be used on SUT by DPDK ('-w <pci-id>')
12 # Also user can optionally setup:
13 #  SGW_LCORE    - lcore to run ipsec-secgw on (default value is 0)
14 #  CRYPTO_DEV   - crypto device to be used ('-w <pci-id>')
15 #              if none specified appropriate vdevs will be created by the script
16 #  SGW_MULTI_SEG - ipsec-secgw option to enable reassembly support and
17 #               specify size of reassembly table (i.e. SGW_MULTI_SEG=128)
18 # Refer to linux_test.sh for more information
19
20 # All supported modes to test:
21 #  trs_3descbc_sha1
22 #  trs_aescbc_sha1
23 #  trs_aesctr_sha1
24 #  trs_aesgcm
25 #  tun_3descbc_sha1
26 #  tun_aescbc_sha1
27 #  tun_aesctr_sha1
28 #  tun_aesgcm
29 # Naming convention:
30 # 'tun/trs' refer to tunnel/transport mode respectively
31
32 usage()
33 {
34         echo "Usage:"
35         echo -e "\t$0 -[46miflscph] <ipsec_mode>"
36         echo -e "\t\t-4 Perform Linux IPv4 network tests"
37         echo -e "\t\t-6 Perform Linux IPv6 network tests"
38         echo -e "\t\t-m Add mixed IP protocol tests to IPv4/IPv6 \
39 (only with option [-46])"
40         echo -e "\t\t-i Run inline tests (only with option [-46])"
41         echo -e "\t\t-f Run fallback tests (only with option [-46])"
42         echo -e "\t\t-l Run tests in legacy mode"
43         echo -e "\t\t-s Run all tests with reassembly support \
44 (on default only fallback tests use reassembly support)"
45         echo -e "\t\t-c Run tests with use of cpu-crypto \
46 (on default lookaside-none is used)"
47         echo -e "\t\t-p Perform packet validation tests"
48         echo -e "\t\t-h Display this help"
49         echo -e "\t\t<ipsec_mode> Run only specified test case i.e. tun_aesgcm"
50 }
51
52 LINUX_TEST="trs_3descbc_sha1 \
53 trs_aescbc_sha1 \
54 trs_aesctr_sha1 \
55 trs_aesgcm \
56 tun_3descbc_sha1 \
57 tun_aescbc_sha1 \
58 tun_aesctr_sha1 \
59 tun_aesgcm"
60
61 LINUX_TEST_INLINE_FALLBACK="trs_aesgcm \
62 tun_aesgcm"
63
64 LINUX_TEST_RUN=""
65
66 PKT_TESTS="trs_ipv6opts \
67 tun_null_header_reconstruct"
68
69 DIR=$(dirname $0)
70
71 # get input options
72 run4=0
73 run6=0
74 runpkt=0
75 mixed=0
76 inline=0
77 fallback=0
78 legacy=0
79 multi_seg=0
80 cpu_crypto=0
81 options=""
82 while getopts ":46miflscph" opt
83 do
84         case $opt in
85                 4)
86                         run4=1
87                         ;;
88                 6)
89                         run6=1
90                         ;;
91                 m)
92                         mixed=1
93                         ;;
94                 i)
95                         inline=1
96                         ;;
97                 f)
98                         fallback=1
99                         ;;
100                 l)
101                         legacy=1
102                         options="${options} -l"
103                         ;;
104                 s)
105                         multi_seg=1
106                         options="${options} -s"
107                         ;;
108                 c)
109                         cpu_crypto=1
110                         options="${options} -c"
111                         ;;
112                 p)
113                         runpkt=1
114                         ;;
115                 h)
116                         usage
117                         exit 0
118                         ;;
119                 ?)
120                         echo "Invalid option"
121                         usage
122                         exit 127
123                         ;;
124         esac
125 done
126
127 shift $((OPTIND -1))
128 LINUX_TEST_RUN=$*
129
130 # no test suite has been selected
131 if [[ ${run4} -eq 0 && ${run6} -eq 0 && ${runpkt} -eq 0 ]]; then
132         usage
133         exit 127
134 fi
135
136 # check parameters
137 if [[ ${legacy} -eq 1 ]] && [[ ${multi_seg} -eq 1 || ${fallback} -eq 1 \
138    || ${cpu_crypto} -eq 1 ]]; then
139         echo "Fallback/reassembly/cpu-crypto cannot be used with legacy mode"
140         exit 127
141 fi
142
143 if [[ ${cpu_crypto} -eq 1 && ${inline} -eq 1 && ${fallback} -eq 0 ]]; then
144         echo "cpu-crypto cannot be used with inline mode"
145         exit 127
146 fi
147
148 # perform packet processing validation tests
149 st=0
150 if [ $runpkt -eq 1 ]; then
151         echo "Performing packet validation tests"
152         /bin/bash ${DIR}/pkttest.sh ${PKT_TESTS}
153         st=$?
154
155         echo "pkttests finished with status ${st}"
156         if [[ ${st} -ne 0 ]]; then
157                 echo "ERROR pkttests FAILED"
158                 exit ${st}
159         fi
160 fi
161
162 desc=""
163
164 # set inline/fallback tests if needed
165 if [[ ${inline} -eq 1  || ${fallback} -eq 1 ]]; then
166
167         # add inline option if needed
168         if [[ ${inline} -eq 1 ]]; then
169                 options="${options} -i"
170                 desc="inline"
171         fi
172         # add fallback option if needed
173         if [[ ${fallback} -eq 1 ]]; then
174                 options="${options} -f"
175                 if [[ "${desc}" == "inline" ]]; then
176                         desc="${desc} and fallback"
177                 else
178                         desc="fallback"
179                 fi
180         fi
181
182         # select tests to run
183         if [[ -z "${LINUX_TEST_RUN}" ]]; then
184                 LINUX_TEST_RUN="${LINUX_TEST_INLINE_FALLBACK}"
185         fi
186 else
187         options="${options} -r"
188 fi
189
190 # select tests to run
191 if [[ -z "${LINUX_TEST_RUN}" ]]; then
192         LINUX_TEST_RUN="${LINUX_TEST}"
193 fi
194
195 # perform selected tests
196 if [[ ${run4} -eq 1 || ${run6} -eq 1 ]] ; then
197
198         for i in ${LINUX_TEST_RUN}; do
199
200                 echo "starting ${desc} test ${i}"
201
202                 st4=0
203                 st4m=0
204                 if [[ ${run4} -ne 0 ]]; then
205                         /bin/bash ${DIR}/load_env.sh ${options} ipv4-ipv4 ${i}
206                         st4=$?
207                         echo "${desc} test IPv4 ${i} finished with status \
208 ${st4}"
209                         if [[ ${mixed} -ne 0 ]] && [[ "${i}" == tun* ]]; then
210                                 /bin/bash ${DIR}/load_env.sh ${options} \
211                                 ipv4-ipv6 ${i}
212                                 st4m=$?
213                                 echo "${desc} test IPv4-IPv6 ${i} finished with\
214  status ${st4m}"
215                         fi
216                 fi
217
218                 st6=0
219                 st6m=0
220                 if [[ ${run6} -ne 0 ]]; then
221                         /bin/bash ${DIR}/load_env.sh ${options} ipv6-ipv6 ${i}
222                         st6=$?
223                         echo "${desc} test IPv6 ${i} finished with status \
224 ${st6}"
225                         if [[ ${mixed} -ne 0 ]] && [[ "${i}" == tun* ]]; then
226                                 /bin/bash ${DIR}/load_env.sh ${options} \
227                                 ipv6-ipv4 ${i}
228                                 st6m=$?
229                                 echo "${desc} test IPv6-IPv4 ${i} finished with\
230  status ${st6m}"
231                         fi
232                 fi
233
234                 let "st = st4 + st6 + st4m + st6m"
235                 if [[ $st -ne 0 ]]; then
236                         echo "ERROR ${desc} test ${i} FAILED"
237                         exit $st
238                 fi
239         done
240 fi
241
242 echo "All tests have ended successfully"