Debian Codegraph @

test/common

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/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/testscip-shell filesystem . . `/usr/libexec/accel-config/test`.
16 BINDIR=/usr/binscip-shell filesystem . . `/usr/bin`.
17
18 # ACCFG
19 #
20 if [scip-shell system . . `[`. -f "../accfg/accel-config" ] && [scip-shell system . . `[`. -x "../accfg/accel-config" ]; then
21 export ACCFG=../accfg/accel-config
22 elif [scip-shell system . . `[`. -f "./accfg/accel-config" ] && [scip-shell system . . `[`. -x "./accfg/accel-config" ]; then
23 export ACCFG=./accfg/accel-config
24 elif [scip-shell system . . `[`. -f "$BINDIR/accel-config" ] && [scip-shell system . . `[`. -x "$BINDIR/accel-config" ]; then
25 export ACCFG="$BINDIR"/accel-config
26 else
27 echoscip-shell system . . echo. "Couldn't find an accel-config binary"
28 exit "$EXIT_FAILURE"
29 fi
30
31 # DSATEST
32 #
33 if [scip-shell system . . `[`. -f "./dsa_test" ] && [scip-shell system . . `[`. -x "./dsa_test" ]; then
34 export DSATEST=./dsa_test
35 elif [scip-shell system . . `[`. -f "$TESTDIR/dsa_test" ] && [scip-shell system . . `[`. -x "$TESTDIR/dsa_test" ]; then
36 export DSATEST="$TESTDIR"/dsa_test
37 else
38 echoscip-shell system . . echo. "Couldn't find an dsa_test binary"
39 exit "$EXIT_FAILURE"
40 fi
41
42 # IAATEST
43 #
44 if [scip-shell system . . `[`. -f "./iaa_test" ] && [scip-shell system . . `[`. -x "./iaa_test" ]; then
45 export IAATEST=./iaa_test
46 elif [scip-shell system . . `[`. -f "$TESTDIR/iaa_test" ] && [scip-shell system . . `[`. -x "$TESTDIR/iaa_test" ]; then
47 export IAATEST="$TESTDIR"/iaa_test
48 else
49 echoscip-shell system . . echo. "Couldn't find an iaa_test binary"
50 exit "$EXIT_FAILURE"
51 fi
52
53 # CONFIGS
54 #
55 if [scip-shell system . . `[`. -f "./configs/2g2q_user_1.conf" ]; then
56 export CONFIG1=./configs/2g2q_user_1.conf
57 elif [scip-shell system . . `[`. -f "$TESTDIR/configs/2g2q_user_1.conf" ]; then
58 export CONFIG1="$TESTDIR"/configs/2g2q_user_1.conf
59 else
60 echoscip-shell system . . echo. "Can't find config 1 file"
61 exit "$EXIT_FAILURE"
62 fi
63
64 # CONFIGS
65 #
66 if [scip-shell system . . `[`. -f "./configs/2g2q_user_2.conf" ]; then
67 export CONFIG2=./configs/2g2q_user_2.conf
68 elif [scip-shell system . . `[`. -f "$TESTDIR/configs/2g2q_user_2.conf" ]; then
69 export CONFIG2="$TESTDIR"/configs/2g2q_user_2.conf
70 else
71 echoscip-shell system . . 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 errscip-shell shell accel-config 4.1.9-2 err().()
82 {
83 echoscip-shell system . . echo. test/"$(basenamescip-shell system . . basename. "$0")": failed at line "$1"
84 [scip-shell system . . `[`. -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_kverscip-shell shell accel-config 4.1.9-2 check_min_kver().()
93 {
94 local ver="$1"
95 : "${KVER:=$(unamescip-shell system . . uname. -r)}"
96
97 [scip-shell system . . `[`. -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_skipscip-shell shell accel-config 4.1.9-2 do_skip().()
105 {
106 echoscip-shell system . . echo. kernel "$(unamescip-shell system . . uname. -r)": "$1"
107 exit "$EXIT_SKIP"
108 }
109
110 # check_prereq
111 # $1: command to check
112 #
113 check_prereqscip-shell shell accel-config 4.1.9-2 check_prereq().()
114 {
115 if ! command -v "$1" >/dev/nullscip-shell filesystem . . `/dev/null`.; then
116 do_skipscip-shell shell accel-config 4.1.9-2 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_allscip-shell shell accel-config 4.1.9-2 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 [scip-shell system . . `[`. -d /sys/bus/iaxscip-shell filesystem . . `/sys/bus/iax`. ] && [scip-shell system . . `[`. $device_type == 'iax' ]; then
127 DSA_DEVICE_PATH="/sys/bus/iax/devicesscip-shell filesystem . . `/sys/bus/iax/devices`."
128 else
129 DSA_DEVICE_PATH="/sys/bus/dsa/devicesscip-shell filesystem . . `/sys/bus/dsa/devices`."
130 fi
131
132 if ! lsscip-shell system . . ls. "${DSA_DEVICE_PATH}/" | grepscip-shell system . . 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 echoscip-shell system . . 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 echoscip-shell system . . echo. -1 > "$engine"/group_id
154 done
155 }
156 done
157 done
158 }
159
160 # cleanup
161 #
162 _cleanupscip-shell shell accel-config 4.1.9-2 _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_allscip-shell shell accel-config 4.1.9-2 disable_all().
167
168 lsmod | grepscip-shell system . . grep. -wq idxd_vdev && {
169 rmmod idxd_vdev
170 }
171 lsmod | grepscip-shell system . . grep. -wq idxd_uacce && {
172 rmmod idxd_uacce
173 }
174 lsmod | grepscip-shell system . . grep. -wq iaa_crypto && {
175 rmmod iaa_crypto
176 }
177 lsmod | grepscip-shell system . . grep. -wq iax_crypto && {
178 rmmod iax_crypto
179 }
180 lsmod | grepscip-shell system . . grep. -wq idxd && {
181 rmmod idxd
182 }
183 lsmod | grepscip-shell system . . grep. -wq vfio_pci && {
184 rmmod vfio_pci
185 }
186 sleepscip-shell system . . sleep. 1
187 modprobe idxd
188 sleepscip-shell system . . sleep. 1
189 modprobe vfio_pci
190
191 disable_allscip-shell shell accel-config 4.1.9-2 disable_all().
192 lsmod | grepscip-shell system . . grep. -wq iaa_crypto && {
193 rmmod iaa_crypto
194 }
195 return 0
196 }
197
198 # json2var
199 # stdin: json
200 #
201 json2varscip-shell shell accel-config 4.1.9-2 json2var().()
202 {
203 sedscip-shell system . . sed. -e "s/[{}\",]//g; s/\[//g; s/\]//g; s/:/=/g"
204 }
205
206 # translate opcode to name
207 # $1 opcode
208 #
209 opcode2namescip-shell shell accel-config 4.1.9-2 opcode2name().()
210 {
211 local opcode="$1"
212 dec_opcode=$((opcode))
213 case $dec_opcode in
214 "0")
215 echoscip-shell system . . echo. "NOOP"
216 ;;
217 "2")
218 echoscip-shell system . . echo. "DRAIN"
219 ;;
220 "3")
221 echoscip-shell system . . echo. "MEMMOVE"
222 ;;
223 "4")
224 echoscip-shell system . . echo. "MEMFILL"
225 ;;
226 "5")
227 echoscip-shell system . . echo. "COMPARE"
228 ;;
229 "6")
230 echoscip-shell system . . echo. "COMPVAL"
231 ;;
232 "7")
233 echoscip-shell system . . echo. "CR_DELTA"
234 ;;
235 "8")
236 echoscip-shell system . . echo. "AP_DELTA"
237 ;;
238 "9")
239 echoscip-shell system . . echo. "DUALCAST"
240 ;;
241 "16")
242 echoscip-shell system . . echo. "CRCGEN"
243 ;;
244 "17")
245 echoscip-shell system . . echo. "COPY_CRC"
246 ;;
247 "18")
248 echoscip-shell system . . echo. "DIF_CHECK"
249 ;;
250 "19")
251 echoscip-shell system . . echo. "DIF_INS"
252 ;;
253 "20")
254 echoscip-shell system . . echo. "DIF_STRP"
255 ;;
256 "21")
257 echoscip-shell system . . echo. "DIF_UPDT"
258 ;;
259 "32")
260 echoscip-shell system . . echo. "CFLUSH"
261 ;;
262 *)
263 echoscip-shell system . . echo. "UNKNOWN"
264 ;;
265 esac
266 }
267
268 # translate WQ mode code to name
269 # $1 Wq mode code
270 #
271 wq_mode2namescip-shell shell accel-config 4.1.9-2 wq_mode2name().()
272 {
273 local wq_mode="$1"
274 dec_wq_mode=$((wq_mode))
275 case $dec_wq_mode in
276 "0")
277 echoscip-shell system . . echo. "dedicated"
278 ;;
279 "1")
280 echoscip-shell system . . echo. "shared"
281 ;;
282 *)
283 echoscip-shell system . . echo. "UNKNOWN"
284 ;;
285 esac
286 }