Debian Codegraph @

test/common

raw symbols SCIP
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright(c) 2019, Intel Corp. All rights reserved.
4
5 # Global variables
6 export SIZE_1=1
7 export SIZE_512=512
8 export SIZE_1K=1024
9 export SIZE_4K=4096
10 export SIZE_64K=65536
11 export SIZE_1M=1048576
12 export SIZE_2M=2097152
13 export EXIT_FAILURE=1
14 export EXIT_SKIP=77
15 TESTDIR=/usr/libexec/accel-config/test
16 BINDIR=/usr/bin
17
18 # ACCFG
19 #
20 if [ -f "../accfg/accel-config" ] && [ -x "../accfg/accel-config" ]; then
21 export ACCFG=../accfg/accel-config
22 elif [ -f "./accfg/accel-config" ] && [ -x "./accfg/accel-config" ]; then
23 export ACCFG=./accfg/accel-config
24 elif [ -f "$BINDIR/accel-config" ] && [ -x "$BINDIR/accel-config" ]; then
25 export ACCFG="$BINDIR"/accel-config
26 else
27 echo "Couldn't find an accel-config binary"
28 exit "$EXIT_FAILURE"
29 fi
30
31 # DSATEST
32 #
33 if [ -f "./dsa_test" ] && [ -x "./dsa_test" ]; then
34 export DSATEST=./dsa_test
35 elif [ -f "$TESTDIR/dsa_test" ] && [ -x "$TESTDIR/dsa_test" ]; then
36 export DSATEST="$TESTDIR"/dsa_test
37 else
38 echo "Couldn't find an dsa_test binary"
39 exit "$EXIT_FAILURE"
40 fi
41
42 # IAATEST
43 #
44 if [ -f "./iaa_test" ] && [ -x "./iaa_test" ]; then
45 export IAATEST=./iaa_test
46 elif [ -f "$TESTDIR/iaa_test" ] && [ -x "$TESTDIR/iaa_test" ]; then
47 export IAATEST="$TESTDIR"/iaa_test
48 else
49 echo "Couldn't find an iaa_test binary"
50 exit "$EXIT_FAILURE"
51 fi
52
53 # CONFIGS
54 #
55 if [ -f "./configs/2g2q_user_1.conf" ]; then
56 export CONFIG1=./configs/2g2q_user_1.conf
57 elif [ -f "$TESTDIR/configs/2g2q_user_1.conf" ]; then
58 export CONFIG1="$TESTDIR"/configs/2g2q_user_1.conf
59 else
60 echo "Can't find config 1 file"
61 exit "$EXIT_FAILURE"
62 fi
63
64 # CONFIGS
65 #
66 if [ -f "./configs/2g2q_user_2.conf" ]; then
67 export CONFIG2=./configs/2g2q_user_2.conf
68 elif [ -f "$TESTDIR/configs/2g2q_user_2.conf" ]; then
69 export CONFIG2="$TESTDIR"/configs/2g2q_user_2.conf
70 else
71 echo "Can't find config 2 file"
72 exit "$EXIT_FAILURE"
73 fi
74
75 # Functions
76
77 # err
78 # $1: line number which error detected
79 # $2: cleanup function (optional)
80 #
81 err()
82 {
83 echo test/"$(basename "$0")": failed at line "$1"
84 [ -n "$2" ] && "$2"
85 # shellcheck disable=SC2154
86 exit "$rc"
87 }
88
89 # check_min_kver
90 # $1: Supported kernel version. format: X.Y
91 #
92 check_min_kver()
93 {
94 local ver="$1"
95 : "${KVER:=$(uname -r)}"
96
97 [ -n "$ver" ] || return 1
98 [[ "$ver" == "$(echo -e "$ver\n$KVER" | sort -V | head -1)" ]]
99 }
100
101 # do_skip
102 # $1: Skip message
103 #
104 do_skip()
105 {
106 echo kernel "$(uname -r)": "$1"
107 exit "$EXIT_SKIP"
108 }
109
110 # check_prereq
111 # $1: command to check
112 #
113 check_prereq()
114 {
115 if ! command -v "$1" >/dev/null; then
116 do_skip "missing $1, skipping..."
117 fi
118 }
119
120 # Disable all active devices dsa/iax and enabled wqs.
121 # Use accel-config tool to disable the device and wq.
122 disable_all() {
123 for device_type in 'dsa' 'iax'; do
124 # Kernel before 5.13 has dsa and iax bus. Because of ABI change, iax
125 # bus is removed. All devices are in /sys/bus/dsa/devices.
126 if [ -d /sys/bus/iax ] && [ $device_type == 'iax' ]; then
127 DSA_DEVICE_PATH="/sys/bus/iax/devices"
128 else
129 DSA_DEVICE_PATH="/sys/bus/dsa/devices"
130 fi
131
132 if ! ls "${DSA_DEVICE_PATH}/" | grep -qE "${device_type}[0-9]*"; then
133 continue
134 fi
135
136 # Get available devices
137 for device_path in ${DSA_DEVICE_PATH}/${device_type}* ; do
138 [[ $(echo "$device_path" | grep -c '!') -eq 0 ]] && {
139 # Get wqs and disable it if the status is enabled
140 for wqp in ${device_path}/wq* ; do
141 [[ $( cat "${wqp}"/state ) == "enabled" ]] && {
142 wq=${wqp##${DSA_DEVICE_PATH}/}
143 accel-config disable-wq "${wq}"
144 echo "-1" > "${wqp}"/group_id
145 }
146 done
147 # Disable device
148 [[ $( cat "${device_path}"/state ) == "enabled" ]] && {
149 accel-config disable-device "${device_path##${DSA_DEVICE_PATH}/}"
150 }
151 # Remove group id of engine
152 for engine in ${device_path}/engine* ; do
153 echo -1 > "$engine"/group_id
154 done
155 }
156 done
157 done
158 }
159
160 # cleanup
161 #
162 _cleanup()
163 {
164 # iaa_crypto will enable iax devices by default after kernel 6.6,
165 # need to disable all enabled devices before unloading the module.
166 disable_all
167
168 lsmod | grep -wq idxd_vdev && {
169 rmmod idxd_vdev
170 }
171 lsmod | grep -wq idxd_uacce && {
172 rmmod idxd_uacce
173 }
174 lsmod | grep -wq iaa_crypto && {
175 rmmod iaa_crypto
176 }
177 lsmod | grep -wq iax_crypto && {
178 rmmod iax_crypto
179 }
180 lsmod | grep -wq idxd && {
181 rmmod idxd
182 }
183 lsmod | grep -wq vfio_pci && {
184 rmmod vfio_pci
185 }
186 sleep 1
187 modprobe idxd
188 sleep 1
189 modprobe vfio_pci
190
191 disable_all
192 lsmod | grep -wq iaa_crypto && {
193 rmmod iaa_crypto
194 }
195 return 0
196 }
197
198 # json2var
199 # stdin: json
200 #
201 json2var()
202 {
203 sed -e "s/[{}\",]//g; s/\[//g; s/\]//g; s/:/=/g"
204 }
205
206 # translate opcode to name
207 # $1 opcode
208 #
209 opcode2name()
210 {
211 local opcode="$1"
212 dec_opcode=$((opcode))
213 case $dec_opcode in
214 "0")
215 echo "NOOP"
216 ;;
217 "2")
218 echo "DRAIN"
219 ;;
220 "3")
221 echo "MEMMOVE"
222 ;;
223 "4")
224 echo "MEMFILL"
225 ;;
226 "5")
227 echo "COMPARE"
228 ;;
229 "6")
230 echo "COMPVAL"
231 ;;
232 "7")
233 echo "CR_DELTA"
234 ;;
235 "8")
236 echo "AP_DELTA"
237 ;;
238 "9")
239 echo "DUALCAST"
240 ;;
241 "16")
242 echo "CRCGEN"
243 ;;
244 "17")
245 echo "COPY_CRC"
246 ;;
247 "18")
248 echo "DIF_CHECK"
249 ;;
250 "19")
251 echo "DIF_INS"
252 ;;
253 "20")
254 echo "DIF_STRP"
255 ;;
256 "21")
257 echo "DIF_UPDT"
258 ;;
259 "32")
260 echo "CFLUSH"
261 ;;
262 *)
263 echo "UNKNOWN"
264 ;;
265 esac
266 }
267
268 # translate WQ mode code to name
269 # $1 Wq mode code
270 #
271 wq_mode2name()
272 {
273 local wq_mode="$1"
274 dec_wq_mode=$((wq_mode))
275 case $dec_wq_mode in
276 "0")
277 echo "dedicated"
278 ;;
279 "1")
280 echo "shared"
281 ;;
282 *)
283 echo "UNKNOWN"
284 ;;
285 esac
286 }