2 # Copyright (c) 2016 Microsemi. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 2 of
7 # the License, or (at your option) any later version.
9 # This program is distributed in the hope that it would be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # Author: Logan Gunthorpe <logang@deltatee.com>
19 DEBUGFS
=${DEBUGFS-/sys/kernel/debug}
29 echo "Usage: $0 [OPTIONS] LOCAL_DEV REMOTE_DEV"
30 echo "Run tests on a pair of NTB endpoints."
32 echo "If the NTB device loops back to the same host then,"
33 echo "just specifying the two PCI ids on the command line is"
34 echo "sufficient. Otherwise, if the NTB link spans two hosts"
35 echo "use the -r option to specify the hostname for the remote"
36 echo "device. SSH will then be used to test the remote side."
37 echo "An SSH key between the root users of the host would then"
38 echo "be highly recommended."
41 echo " -C don't cleanup ntb modules on exit"
42 echo " -d run dma tests"
43 echo " -h show this help message"
44 echo " -l list available local and remote PCI ids"
45 echo " -r REMOTE_HOST specify the remote's hostname to connect"
46 echo " to for the test (using ssh)"
47 echo " -p NUM ntb_perf run order (default: $PERF_RUN_ORDER)"
48 echo " -w max_mw_size maxmium memory window size"
55 while getopts "Cdhlm:r:p:w:" opt
; do
59 h
) show_help
; exit 0 ;;
61 m
) MW_SIZE
=${OPTARG} ;;
62 r
) REMOTE_HOST
=${OPTARG} ;;
63 p
) PERF_RUN_ORDER
=${OPTARG} ;;
64 w
) MAX_MW_SIZE
=${OPTARG} ;;
66 echo "Invalid option: -$OPTARG" >&2
90 function split_remote
()
95 if [[ "$VPATH" == *":/"* ]]; then
104 if [[ "$REMOTE" != "" ]]; then
105 ssh "$REMOTE" cat "$VPATH"
111 function write_file
()
116 if [[ "$REMOTE" != "" ]]; then
117 ssh "$REMOTE" "echo \"$VALUE\" > \"$VPATH\""
119 echo "$VALUE" > "$VPATH"
129 echo "Running link tests on: $(basename $LOC) / $(basename $REM)"
131 if ! write_file
"N" "$LOC/link" 2> /dev
/null
; then
136 write_file
"N" "$LOC/link_event"
138 if [[ $
(read_file
"$REM/link") != "N" ]]; then
139 echo "Expected remote link to be down in $REM/link" >&2
143 write_file
"Y" "$LOC/link"
144 write_file
"Y" "$LOC/link_event"
149 function doorbell_test
()
155 echo "Running db tests on: $(basename $LOC) / $(basename $REM)"
157 write_file
"c 0xFFFFFFFF" "$REM/db"
159 for ((i
=1; i
<= 8; i
++)); do
160 let DB
=$
(read_file
"$REM/db") || true
161 if [[ "$DB" != "$EXP" ]]; then
162 echo "Doorbell doesn't match expected value $EXP " \
167 let "MASK=1 << ($i-1)" || true
168 let "EXP=$EXP | $MASK" || true
169 write_file
"s $MASK" "$LOC/peer_db"
180 ROW
=($
(read_file
"$VPATH" |
grep -e "^$IDX"))
181 let VAL
=${ROW[1]} || true
185 function scratchpad_test
()
189 CNT
=$
(read_file
"$LOC/spad" |
wc -l)
191 echo "Running spad tests on: $(basename $LOC) / $(basename $REM)"
193 for ((i
= 0; i
< $CNT; i
++)); do
195 write_file
"$i $VAL" "$LOC/peer_spad"
196 RVAL
=$
(read_spad
"$REM/spad" $i)
198 if [[ "$VAL" != "$RVAL" ]]; then
199 echo "Scratchpad doesn't match expected value $VAL " \
200 "in $REM/spad, got $RVAL" >&2
213 if [[ "$REMOTE" != "" ]]; then
215 dd if=/dev
/urandom
"of=$VPATH" 2> /dev
/null || true
217 dd if=/dev
/urandom
"of=$VPATH" 2> /dev
/null || true
227 echo "Running $IDX tests on: $(basename $LOC) / $(basename $REM)"
231 split_remote
"$LOC/$IDX"
232 if [[ "$REMOTE" == "" ]]; then
236 ssh "$REMOTE" cat "$VPATH" > "$A"
239 split_remote
"$REM/peer_$IDX"
240 if [[ "$REMOTE" == "" ]]; then
244 ssh "$REMOTE" cat "$VPATH" > "$B"
247 cmp -n $MW_SIZE "$A" "$B"
248 if [[ $?
!= 0 ]]; then
249 echo "Memory window $MW did not match!" >&2
252 if [[ "$A" == "/tmp/*" ]]; then
256 if [[ "$B" == "/tmp/*" ]]; then
263 function pingpong_test
()
268 echo "Running ping pong tests on: $(basename $LOC) / $(basename $REM)"
270 LOC_START
=$
(read_file
$LOC/count
)
271 REM_START
=$
(read_file
$REM/count
)
275 LOC_END
=$
(read_file
$LOC/count
)
276 REM_END
=$
(read_file
$REM/count
)
278 if [[ $LOC_START == $LOC_END ]] ||
[[ $REM_START == $REM_END ]]; then
279 echo "Ping pong counter not incrementing!" >&2
290 if [[ $USE_DMA == "1" ]]; then
296 _modprobe ntb_perf run_order
=$PERF_RUN_ORDER \
297 max_mw_size
=$MAX_MW_SIZE use_dma
=$USE_DMA
299 echo "Running local perf test $WITH DMA"
300 write_file
"" $LOCAL_PERF/run
302 read_file
$LOCAL_PERF/run
305 echo "Running remote perf test $WITH DMA"
306 write_file
"" $REMOTE_PERF/run
308 read_file
$REMOTE_PERF/run
311 _modprobe
-r ntb_perf
314 function ntb_tool_tests
()
316 LOCAL_TOOL
=$DEBUGFS/ntb_tool
/$LOCAL_DEV
317 REMOTE_TOOL
=$REMOTE_HOST:$DEBUGFS/ntb_tool
/$REMOTE_DEV
319 echo "Starting ntb_tool tests..."
323 write_file Y
$LOCAL_TOOL/link_event
324 write_file Y
$REMOTE_TOOL/link_event
326 link_test
$LOCAL_TOOL $REMOTE_TOOL
327 link_test
$REMOTE_TOOL $LOCAL_TOOL
329 #Ensure the link is up on both sides before continuing
330 write_file Y
$LOCAL_TOOL/link_event
331 write_file Y
$REMOTE_TOOL/link_event
333 for PEER_TRANS
in $
(ls $LOCAL_TOOL/peer_trans
*); do
334 PT
=$
(basename $PEER_TRANS)
335 write_file
$MW_SIZE $LOCAL_TOOL/$PT
336 write_file
$MW_SIZE $REMOTE_TOOL/$PT
339 doorbell_test
$LOCAL_TOOL $REMOTE_TOOL
340 doorbell_test
$REMOTE_TOOL $LOCAL_TOOL
341 scratchpad_test
$LOCAL_TOOL $REMOTE_TOOL
342 scratchpad_test
$REMOTE_TOOL $LOCAL_TOOL
344 for MW
in $
(ls $LOCAL_TOOL/mw
*); do
347 mw_test
$MW $LOCAL_TOOL $REMOTE_TOOL
348 mw_test
$MW $REMOTE_TOOL $LOCAL_TOOL
351 _modprobe
-r ntb_tool
354 function ntb_pingpong_tests
()
356 LOCAL_PP
=$DEBUGFS/ntb_pingpong
/$LOCAL_DEV
357 REMOTE_PP
=$REMOTE_HOST:$DEBUGFS/ntb_pingpong
/$REMOTE_DEV
359 echo "Starting ntb_pingpong tests..."
361 _modprobe ntb_pingpong
363 pingpong_test
$LOCAL_PP $REMOTE_PP
365 _modprobe
-r ntb_pingpong
368 function ntb_perf_tests
()
370 LOCAL_PERF
=$DEBUGFS/ntb_perf
/$LOCAL_DEV
371 REMOTE_PERF
=$REMOTE_HOST:$DEBUGFS/ntb_perf
/$REMOTE_DEV
373 echo "Starting ntb_perf tests..."
377 if [[ $RUN_DMA_TESTS ]]; then
385 _modprobe
-r ntb_tool
2> /dev
/null
386 _modprobe
-r ntb_perf
2> /dev
/null
387 _modprobe
-r ntb_pingpong
2> /dev
/null
388 _modprobe
-r ntb_transport
2> /dev
/null
394 if ! [[ $
$DONT_CLEANUP ]]; then
398 if [ "$(id -u)" != "0" ]; then
399 echo "This script must be run as root" 1>&2
403 if [[ "$LIST_DEVS" == TRUE
]]; then
404 echo "Local Devices:"
405 ls -1 /sys
/bus
/ntb
/devices
408 if [[ "$REMOTE_HOST" != "" ]]; then
409 echo "Remote Devices:"
410 ssh $REMOTE_HOST ls -1 /sys
/bus
/ntb
/devices
416 if [[ "$LOCAL_DEV" == $
"" ]] ||
[[ "$REMOTE_DEV" == $
"" ]]; then