diff options
| -rw-r--r-- | MAINTAINERS | 1 | ||||
| -rwxr-xr-x | tools/testing/selftests/ntb/ntb_test.sh | 422 |
2 files changed, 423 insertions, 0 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index 8c20323d1277..46130feca8a8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
| @@ -8131,6 +8131,7 @@ F: drivers/ntb/ | |||
| 8131 | F: drivers/net/ntb_netdev.c | 8131 | F: drivers/net/ntb_netdev.c |
| 8132 | F: include/linux/ntb.h | 8132 | F: include/linux/ntb.h |
| 8133 | F: include/linux/ntb_transport.h | 8133 | F: include/linux/ntb_transport.h |
| 8134 | F: tools/testing/selftests/ntb/ | ||
| 8134 | 8135 | ||
| 8135 | NTB INTEL DRIVER | 8136 | NTB INTEL DRIVER |
| 8136 | M: Jon Mason <jdmason@kudzu.us> | 8137 | M: Jon Mason <jdmason@kudzu.us> |
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 | |||
| 16 | REMOTE_HOST= | ||
| 17 | LIST_DEVS=FALSE | ||
| 18 | |||
| 19 | DEBUGFS=${DEBUGFS-/sys/kernel/debug} | ||
| 20 | |||
| 21 | PERF_RUN_ORDER=32 | ||
| 22 | MAX_MW_SIZE=0 | ||
| 23 | RUN_DMA_TESTS= | ||
| 24 | DONT_CLEANUP= | ||
| 25 | MW_SIZE=65536 | ||
| 26 | |||
| 27 | function 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 | |||
| 52 | function 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 | |||
| 73 | parse_args "$@" | ||
| 74 | shift $((OPTIND-1)) | ||
| 75 | LOCAL_DEV=$1 | ||
| 76 | shift | ||
| 77 | parse_args "$@" | ||
| 78 | shift $((OPTIND-1)) | ||
| 79 | REMOTE_DEV=$1 | ||
| 80 | shift | ||
| 81 | parse_args "$@" | ||
| 82 | |||
| 83 | set -e | ||
| 84 | |||
| 85 | function _modprobe() | ||
| 86 | { | ||
| 87 | modprobe "$@" | ||
| 88 | } | ||
| 89 | |||
| 90 | function split_remote() | ||
| 91 | { | ||
| 92 | VPATH=$1 | ||
| 93 | REMOTE= | ||
| 94 | |||
| 95 | if [[ "$VPATH" == *":/"* ]]; then | ||
| 96 | REMOTE=${VPATH%%:*} | ||
| 97 | VPATH=${VPATH#*:} | ||
| 98 | fi | ||
| 99 | } | ||
| 100 | |||
| 101 | function 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 | |||
| 111 | function 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 | |||
| 123 | function 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 | |||
| 149 | function 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 | |||
| 175 | function 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 | |||
| 185 | function 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 " \ | ||
| 200 | "in $REM/spad, got $RVAL" >&2 | ||
