Debian Codegraph @

scripts/regress

raw
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 #
4 # Copyright 2015 PMC-Sierra, Inc.
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21 # Author: Stephen Bates <[email protected]>
22 #
23 # Description:
24 # Regression test-suite for the NVM Express CLI.
25 #
26
27 DEVICE=
28 WRITE=false
29 LIST=false
30
31 RAND_BASE=temp.rand
32 RAND_WFILE=${RAND_BASE}.write
33 RAND_RFILE=${RAND_BASE}.read
34 RAND_SIZE=4k
35
36 green=$(tput bold)$(tput setaf 2)
37 red=$(tput bold)$(tput setaf 1)
38 rst=$(tput sgr0)
39
40 while getopts ":d:wl" opt; do
41 case $opt in
42 d)
43 DEVICE=${OPTARG}
44 ;;
45 w)
46 echo "WARNING: Write mode enabled, this might trash your drive!"
47 WRITE=true
48 ;;
49 l)
50 LIST=true
51 ;;
52 \?)
53 echo "Invalid option: -$OPTARG" >&2
54 exit 1
55 ;;
56 :)
57 echo "Option -$OPTARG requires an argument." >&2
58 exit 1
59 ;;
60 esac
61 done
62
63 if [ -z "$DEVICE" ]; then
64 echo "regress: You must specify a NVMe device using -d"
65 exit 1
66 fi
67
68 function print_pass_fail {
69 $* > /dev/null 2>&1
70 if (( $? )); then
71 echo ${red}"FAILED!"${rst}
72 echo "Failed running command: "
73 echo " $*"
74 exit 1
75 else
76 echo ${green}"PASSED!"${rst}
77 fi
78 }
79
80 function run_test {
81 LINE="$*"
82 printf " %-3s %-68s : " "RUN" "${LINE::67}"
83 print_pass_fail $*
84 }
85
86 make clean > /dev/null || exit -1
87 make install > /dev/null || exit -1
88
89 if $LIST ; then
90 run_test nvme list
91 fi
92 run_test nvme id-ctrl ${DEVICE}
93 run_test nvme id-ns -raw-binary ${DEVICE}
94 run_test nvme list-ns -n 1 ${DEVICE}
95 run_test nvme get-ns-id ${DEVICE}
96 run_test nvme get-log ${DEVICE} --log-id=2 --log-len=512
97 run_test nvme fw-log ${DEVICE}
98 run_test nvme fw-log ${DEVICE} -b
99 run_test nvme smart-log ${DEVICE}
100 run_test nvme error-log ${DEVICE}
101 run_test nvme get-feature ${DEVICE} -f 7
102 run_test nvme flush ${DEVICE}
103
104 if $WRITE ; then
105 run_test dd if=/dev/urandom of=${RAND_WFILE} bs=${RAND_SIZE} count=1
106 run_test nvme write ${DEVICE} --start-block=0 --block-count=0 --data-size=${RAND_SIZE} --data ${RAND_WFILE}
107 fi
108 run_test nvme read ${DEVICE} --start-block=0 --block-count=0 --data-size=${RAND_SIZE} --data ${RAND_RFILE} --latency
109 if $WRITE ; then
110 run_test diff ${RAND_RFILE} ${RAND_WFILE}
111 rm ${RAND_WFILE} > /dev/null
112 fi
113 rm ${RAND_RFILE} > /dev/null