xref: /aosp_15_r20/external/sg3_utils/scripts/scsi_mandat (revision 44704f698541f6367e81f991ef8bb54ccbf3fc18)
1#!/bin/bash
2# scsi_mandat
3#
4# Script to test compliance with SCSI mandatory commands.
5# The vintage is SPC-3 and SPC-4 (see www.t10.org).
6#
7# Coverage:
8# Command                Standard/Draft (is mandatory in)
9# -------------------------------------------------------
10# INQUIRY (standard)     SCSI-2, SPC, SPC-2, SPC-3, SPC-4
11# INQUIRY (VPD pages 0, 0x83)     SPC-2, SPC-3, SPC-4
12# REPORT LUNS            SPC-3, SPC-4
13# TEST UNIT READY        SCSI-2, SPC, SPC-2, SPC-3, SPC-4
14# REQUEST SENSE          SCSI-2, SBC, SBC-2,3, MMC-4,5, SSC-2,3
15# SEND DIAGNOSTIC        SBC, SBC-2,3, SSC-2,3
16#
17# This script uses utilities frim sg3_utils package (version
18# 1.21 or later)
19#
20# Douglas Gilbert 20131016
21
22
23log=0
24quiet=0
25verbose=""
26
27file_err=0
28inv_opcode=0
29illeg_req=0
30not_ready=0
31medium=0
32other_err=0
33recovered=0
34sanity=0
35syntax=0
36timeout=0
37unit_attention=0
38aborted_command=0
39
40## total_err=0
41
42usage()
43{
44  echo "Usage: scsi_mandat [-h] [-L] [-q] [-v] <device>"
45  echo "  where:  -h, --help        print usage message"
46  echo "          -L, --log         append stderr to 'scsi_mandat.err'"
47  echo "          -q, --quiet       suppress some output"
48  echo "          -v, --verbose     increase verbosity of output"
49  echo ""
50  echo "Check <device> for mandatory SCSI command support"
51}
52
53
54opt="$1"
55while test ! -z "$opt" -a -z "${opt##-*}"; do
56  opt=${opt#-}
57  case "$opt" in
58    h|-help) usage ; exit 0 ;;
59    L|-log) let log=$log+1 ;;
60    q|-quiet) let quiet=$quiet+1 ;;
61    v|-verbose) verbose="-v" ;;
62    vv) verbose="-vv" ;;
63    vvv) verbose="-vvv" ;;
64    *) echo "Unknown option: -$opt " ; exit 1 ;;
65  esac
66  shift
67  opt="$1"
68done
69
70if [ $# -lt 1 ]
71  then
72    usage
73    exit 1
74fi
75
76for command in "sg_inq" "sg_luns" "sg_turs" "sg_requests" "sg_vpd" \
77                "sg_vpd -i" "sg_senddiag -t"
78do
79  if [ $quiet -eq 0 ]
80    then echo "$command" $verbose "$1"
81  fi
82
83  if [ $verbose ]
84  then
85    if [ $log -eq 0 ]
86    then
87      $command $verbose "$1"
88    else
89      $command $verbose "$1" >> scsi_mandat.err 2>> scsi_mandat.err
90    fi
91  else
92    if [ $log -eq 0 ]
93    then
94      $command "$1" > /dev/null 2>> /dev/null
95    else
96      $command "$1" > /dev/null 2>> scsi_mandat.err
97    fi
98  fi
99  res=$?
100  case "$res" in
101    0) ;;
102    1) echo "  syntax error" ; let syntax=$syntax+1 ;;
103    2) echo "  not ready" ; let not_ready=$not_ready+1 ;;
104    3) echo "  medium error" ; let medium=$medium+1 ;;
105    5) echo "  illegal request, general" ; let illeg_req=$illeg_req+1 ;;
106    6) echo "  unit attention" ; let unit_attention=$unit_attention+1 ;;
107    9) echo "  illegal request, invalid opcode" ; let inv_opcode=$inv_opcode+1 ;;
108    11) echo "  aborted command" ; let aborted_command=$aborted_command+1 ;;
109    15) echo "  file error with $1 " ; let file_err=$file_err+1 ;;
110    20) echo "  no sense" ; let other_err=$other_err+1 ;;
111    21) echo "  recovered error" ; let recovered=$recovered+1 ;;
112    33) echo "  timeout" ; let timeout=$timeout+1 ;;
113    97) echo "  response fails sanity" ; let sanity=$sanity+1 ;;
114    98) echo "  other SCSI error" ; let other_err=$other_err+1 ;;
115    99) echo "  other error" ; let other_err=$other_err+1 ;;
116    *) echo "  unknown exit status for sg_inq: $res" ; let other_err=$other_err+1 ;;
117  esac
118done
119
120echo ""
121let total_bad_err=$file_err+$inv_opcode+$illeg_req+$medium+$aborted_command
122let total_bad_err+=$other_err+$recovered+$sanity+$syntax+$timeout
123
124let total_allow_err=$not_ready+$unit_attention
125
126  echo "total number of bad errors: $total_bad_err "
127
128if [ $total_allow_err -gt 0 ]
129  then
130  echo "total number of allowable errors: $total_allow_err "
131fi
132
133exit $total_bad_err
134