aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests
diff options
context:
space:
mode:
authorLogan Gunthorpe <logang@deltatee.com>2016-06-20 15:15:12 -0400
committerJon Mason <jdmason@kudzu.us>2016-08-05 10:21:08 -0400
commita9c59ef77458b27221e71506cdf1bd31a06afb19 (patch)
tree1785a9c0b213a9362e18978700fe4a66a25f2759 /tools/testing/selftests
parent35539b54ac339e2b2dee8c74bc9f0b06f11b11cf (diff)
ntb_test: Add a selftest script for the NTB subsystem
This script automates testing doorbells, scratchpads and memory windows for an NTB device. It can be run locally, with the NTB looped back to the same host or use SSH to remotely control the second host. In the single host case, the script just needs to be passed two arguments: a PCI ID for each side of the link. In the two host case the -r option must be used to specify the remote hostname (which must be SSH accessible and should probably have ssh-keys exchanged). A sample run looks like this: $ sudo ./ntb_test.sh 0000:03:00.1 0000:83:00.1 -p 29 Starting ntb_tool tests... Running link tests on: 0000:03:00.1 / 0000:83:00.1 Passed Running link tests on: 0000:83:00.1 / 0000:03:00.1 Passed Running db tests on: 0000:03:00.1 / 0000:83:00.1 Passed Running db tests on: 0000:83:00.1 / 0000:03:00.1 Passed Running spad tests on: 0000:03:00.1 / 0000:83:00.1 Passed Running spad tests on: 0000:83:00.1 / 0000:03:00.1 Passed Running mw0 tests on: 0000:03:00.1 / 0000:83:00.1 Passed Running mw0 tests on: 0000:83:00.1 / 0000:03:00.1 Passed Running mw1 tests on: 0000:03:00.1 / 0000:83:00.1 Passed Running mw1 tests on: 0000:83:00.1 / 0000:03:00.1 Passed Starting ntb_pingpong tests... Running ping pong tests on: 0000:03:00.1 / 0000:83:00.1 Passed Starting ntb_perf tests... Running local perf test without DMA 0: copied 536870912 bytes in 164453 usecs, 3264 MBytes/s Passed Running remote perf test without DMA 0: copied 536870912 bytes in 164453 usecs, 3264 MBytes/s Passed Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Shuah Khan <shuahkh@osg.samsung.com> Acked-by: Allen Hubbe <Allen.Hubbe@emc.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
Diffstat (limited to 'tools/testing/selftests')
-rwxr-xr-xtools/testing/selftests/ntb/ntb_test.sh422
1 files changed, 422 insertions, 0 deletions
diff --git a/tools/testing/selftests/ntb/ntb_test.sh b/tools/testing/selftests/ntb/ntb_test.sh
new file mode 100755
index 000000000000..a676d3eefefb
--- /dev/null
+++ b/tools/testing/selftests/ntb/ntb_test.sh
@@ -0,0 +1,422 @@
1#!/bin/bash
2# Copyright (c) 2016 Microsemi. All Rights Reserved.
3#
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.
8#
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.
13#
14# Author: Logan Gunthorpe <logang@deltatee.com>
15
16REMOTE_HOST=
17LIST_DEVS=FALSE
18
19DEBUGFS=${DEBUGFS-/sys/kernel/debug}
20
21PERF_RUN_ORDER=32
22MAX_MW_SIZE=0
23RUN_DMA_TESTS=
24DONT_CLEANUP=
25MW_SIZE=65536
26
27function show_help()
28{
29 echo "Usage: $0 [OPTIONS] LOCAL_DEV REMOTE_DEV"
30 echo "Run tests on a pair of NTB endpoints."
31 echo
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."
39 echo
40 echo "Options:"
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"
49 echo
50}
51
52function parse_args()
53{
54 OPTIND=0
55 while getopts "Cdhlm:r:p:w:" opt; do
56 case "$opt" in
57 C) DONT_CLEANUP=1 ;;
58 d) RUN_DMA_TESTS=1 ;;
59 h) show_help; exit 0 ;;
60 l) LIST_DEVS=TRUE ;;
61 m) MW_SIZE=${OPTARG} ;;
62 r) REMOTE_HOST=${OPTARG} ;;
63 p) PERF_RUN_ORDER=${OPTARG} ;;
64 w) MAX_MW_SIZE=${OPTARG} ;;
65 \?)
66 echo "Invalid option: -$OPTARG" >&2
67 exit 1
68 ;;
69 esac
70 done
71}
72
73parse_args "$@"
74shift $((OPTIND-1))
75LOCAL_DEV=$1
76shift
77parse_args "$@"
78shift $((OPTIND-1))
79REMOTE_DEV=$1
80shift
81parse_args "$@"
82
83set -e
84
85function _modprobe()
86{
87 modprobe "$@"
88}
89
90function split_remote()
91{
92 VPATH=$1
93 REMOTE=
94
95 if [[ "$VPATH" == *":/"* ]]; then
96 REMOTE=${VPATH%%:*}
97 VPATH=${VPATH#*:}
98 fi
99}
100
101function read_file()
102{
103 split_remote $1
104 if [[ "$REMOTE" != "" ]]; then
105 ssh "$REMOTE" cat "$VPATH"
106 else
107 cat "$VPATH"
108 fi
109}
110
111function write_file()
112{
113 split_remote $2
114 VALUE=$1
115
116 if [[ "$REMOTE" != "" ]]; then
117 ssh "$REMOTE" "echo \"$VALUE\" > \"$VPATH\""
118 else
119 echo "$VALUE" > "$VPATH"
120 fi
121}
122
123function link_test()
124{
125 LOC=$1
126 REM=$2
127 EXP=0
128
129 echo "Running link tests on: $(basename $LOC) / $(basename $REM)"
130
131 if ! write_file "N" "$LOC/link" 2> /dev/null; then
132 echo " Unsupported"
133 return
134 fi
135
136 write_file "N" "$LOC/link_event"
137
138 if [[ $(read_file "$REM/link") != "N" ]]; then
139 echo "Expected remote link to be down in $REM/link" >&2
140 exit -1
141 fi
142
143 write_file "Y" "$LOC/link"
144 write_file "Y" "$LOC/link_event"
145
146 echo " Passed"
147}
148
149function doorbell_test()
150{
151 LOC=$1
152 REM=$2
153 EXP=0
154
155 echo "Running db tests on: $(basename $LOC) / $(basename $REM)"
156
157 write_file "c 0xFFFFFFFF" "$REM/db"
158
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 " \
163 "in $REM/db" >&2
164 exit -1
165 fi
166
167 let "MASK=1 << ($i-1)" || true
168 let "EXP=$EXP | $MASK" || true
169 write_file "s $MASK" "$LOC/peer_db"
170 done
171
172 echo " Passed"
173}
174
175function read_spad()
176{
177 VPATH=$1
178 IDX=$2
179
180 ROW=($(read_file "$VPATH" | grep -e "^$IDX"))
181 let VAL=${ROW[1]} || true
182 echo $VAL
183}
184
185function scratchpad_test()
186{
187 LOC=$1
188 REM=$2
189 CNT=$(read_file "$LOC/spad" | wc -l)
190
191 echo "Running spad tests on: $(basename $LOC) / $(basename $REM)"
192
193 for ((i = 0; i < $CNT; i++)); do
194 VAL=$RANDOM
195 write_file "$i $VAL" "$LOC/peer_spad"
196 RVAL=$(read_spad "$REM/spad" $i)
197
198 if [[ "$VAL" != "$RVAL" ]]; then
199 echo "Scratchpad doesn't match expected value $VAL " \