diff mbox series

[v5,35/35] scsi: Add kunit tests for scsi_check_passthrough

Message ID 20221023030403.33845-36-michael.christie@oracle.com
State Superseded
Headers show
Series Allow scsi_execute users to control retries | expand

Commit Message

Mike Christie Oct. 23, 2022, 3:04 a.m. UTC
Add some kunit tests for scsi_check_passthrough so we can easily make sure
we are hitting the cases it's difficult to replicate in hardware or even
scsi_debug.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
 drivers/scsi/Kconfig           |   7 ++
 drivers/scsi/scsi_error.c      |   4 +
 drivers/scsi/scsi_error_test.c | 171 +++++++++++++++++++++++++++++++++
 3 files changed, 182 insertions(+)
 create mode 100644 drivers/scsi/scsi_error_test.c

Comments

kernel test robot Oct. 23, 2022, 6:32 a.m. UTC | #1
Hi Mike,

I love your patch! Yet something to improve:

[auto build test ERROR on jejb-scsi/for-next]
[also build test ERROR on groeck-staging/hwmon-next linus/master v6.1-rc1 next-20221021]
[cannot apply to mkp-scsi/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mike-Christie/Allow-scsi_execute-users-to-control-retries/20221023-111103
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
patch link:    https://lore.kernel.org/r/20221023030403.33845-36-michael.christie%40oracle.com
patch subject: [PATCH v5 35/35] scsi: Add kunit tests for scsi_check_passthrough
config: arc-randconfig-r025-20221023
compiler: arc-elf-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/5c568c0893302315545f701ffe9d0aa2afb276d4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Mike-Christie/Allow-scsi_execute-users-to-control-retries/20221023-111103
        git checkout 5c568c0893302315545f701ffe9d0aa2afb276d4
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arc-elf-ld: drivers/scsi/scsi_error.o: in function `scsi_test_error_check_passthough':
>> drivers/scsi/scsi_error_test.c:139: undefined reference to `kunit_binary_assert_format'
>> arc-elf-ld: drivers/scsi/scsi_error_test.c:139: undefined reference to `kunit_binary_assert_format'
>> arc-elf-ld: drivers/scsi/scsi_error_test.c:139: undefined reference to `kunit_do_failed_assertion'
>> arc-elf-ld: drivers/scsi/scsi_error_test.c:139: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:101: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:101: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:101: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:101: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:104: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:104: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:104: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:104: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:107: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:107: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:107: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:107: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:111: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:111: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:111: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:111: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:115: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:115: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:115: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:115: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:118: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:118: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:118: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:118: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:124: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:124: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:124: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:124: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:125: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:125: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:125: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:125: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:130: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:130: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:130: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:130: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:144: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:144: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:144: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:144: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:148: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:148: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:148: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:148: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:153: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:153: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:153: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:153: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:158: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:158: undefined reference to `kunit_binary_assert_format'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:158: undefined reference to `kunit_do_failed_assertion'
   arc-elf-ld: drivers/scsi/scsi_error_test.c:158: undefined reference to `kunit_do_failed_assertion'
   pahole: .tmp_vmlinux.btf: No such file or directory
   .btf.vmlinux.bin.o: file not recognized: file format not recognized


vim +139 drivers/scsi/scsi_error_test.c

    13	
    14	static void scsi_test_error_check_passthough(struct kunit *test)
    15	{
    16		struct scsi_failure multiple_sense_failures[] = {
    17			{
    18				.sense = DATA_PROTECT,
    19				.asc = 0x1,
    20				.ascq = 0x1,
    21				.allowed = 0,
    22				.result = SAM_STAT_CHECK_CONDITION,
    23			},
    24			{
    25				.sense = UNIT_ATTENTION,
    26				.asc = 0x11,
    27				.ascq = 0x0,
    28				.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
    29				.result = SAM_STAT_CHECK_CONDITION,
    30			},
    31			{
    32				.sense = NOT_READY,
    33				.asc = 0x11,
    34				.ascq = 0x22,
    35				.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
    36				.result = SAM_STAT_CHECK_CONDITION,
    37			},
    38			{
    39				.sense = ABORTED_COMMAND,
    40				.asc = 0x11,
    41				.ascq = SCMD_FAILURE_ASCQ_ANY,
    42				.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
    43				.result = SAM_STAT_CHECK_CONDITION,
    44			},
    45			{
    46				.sense = HARDWARE_ERROR,
    47				.asc = SCMD_FAILURE_ASC_ANY,
    48				.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
    49				.result = SAM_STAT_CHECK_CONDITION,
    50			},
    51			{
    52				.sense = ILLEGAL_REQUEST,
    53				.asc = 0x91,
    54				.ascq = 0x36,
    55				.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
    56				.result = SAM_STAT_CHECK_CONDITION,
    57			},
    58			{},
    59		};
    60		struct scsi_failure retryable_host_failures[] = {
    61			{
    62				.result = DID_TRANSPORT_DISRUPTED << 16,
    63				.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
    64			},
    65			{
    66				.result = DID_TIME_OUT << 16,
    67				.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
    68			},
    69			{},
    70		};
    71		struct scsi_failure any_status_failures[] = {
    72			{
    73				.result = SCMD_FAILURE_STAT_ANY,
    74				.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
    75			},
    76			{},
    77		};
    78		struct scsi_failure any_sense_failures[] = {
    79			{
    80				.result = SCMD_FAILURE_SENSE_ANY,
    81				.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
    82			},
    83			{},
    84		};
    85		struct scsi_failure any_failures[] = {
    86			{
    87				.result = SCMD_FAILURE_RESULT_ANY,
    88				.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
    89			},
    90			{},
    91		};
    92		u8 sense[SCSI_SENSE_BUFFERSIZE] = {};
    93		struct scsi_cmnd sc = {
    94			.sense_buffer = sense,
    95			.failures = multiple_sense_failures,
    96		};
    97		int i;
    98	
    99		/* Match end of array */
   100		scsi_build_sense(&sc, 0, ILLEGAL_REQUEST, 0x91, 0x36);
   101		KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
   102		/* Basic match in array */
   103		scsi_build_sense(&sc, 0, UNIT_ATTENTION, 0x11, 0x0);
   104		KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
   105		/* No matching sense entry */
   106		scsi_build_sense(&sc, 0, MISCOMPARE, 0x11, 0x11);
   107		KUNIT_EXPECT_EQ(test, SCSI_RETURN_NOT_HANDLED,
   108				scsi_check_passthrough(&sc));
   109		/* Match using SCMD_FAILURE_ASCQ_ANY */
   110		scsi_build_sense(&sc, 0, ABORTED_COMMAND, 0x22, 0x22);
   111		KUNIT_EXPECT_EQ(test, SCSI_RETURN_NOT_HANDLED,
   112				scsi_check_passthrough(&sc));
   113		/* Match using SCMD_FAILURE_ASC_ANY */
   114		scsi_build_sense(&sc, 0, HARDWARE_ERROR, 0x11, 0x22);
   115		KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
   116		/* No matching status entry */
   117		sc.result = SAM_STAT_RESERVATION_CONFLICT;
   118		KUNIT_EXPECT_EQ(test, SCSI_RETURN_NOT_HANDLED,
   119				scsi_check_passthrough(&sc));
   120	
   121		/* Test hitting allowed limit */
   122		scsi_build_sense(&sc, 0, NOT_READY, 0x11, 0x22);
   123		for (i = 0; i < SCSI_TEST_ERROR_MAX_ALLOWED; i++)
   124			KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
   125		KUNIT_EXPECT_EQ(test, SUCCESS, scsi_check_passthrough(&sc));
   126	
   127		/* Match using SCMD_FAILURE_SENSE_ANY */
   128		sc.failures = any_sense_failures;
   129		scsi_build_sense(&sc, 0, MEDIUM_ERROR, 0x11, 0x22);
   130		KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
   131	
   132		/* reset retries so we can retest */
   133		for (i = 0; i < ARRAY_SIZE(multiple_sense_failures); i++)
   134			multiple_sense_failures[i].retries = 0;
   135	
   136		/* Test no retries allowed */
   137		sc.failures = multiple_sense_failures;
   138		scsi_build_sense(&sc, 0, DATA_PROTECT, 0x1, 0x1);
 > 139		KUNIT_EXPECT_EQ(test, SUCCESS, scsi_check_passthrough(&sc));
   140	
   141		/* No matching host byte entry */
   142		sc.failures = retryable_host_failures;
   143		sc.result = DID_NO_CONNECT << 16;
   144		KUNIT_EXPECT_EQ(test, SCSI_RETURN_NOT_HANDLED,
   145				scsi_check_passthrough(&sc));
   146		/* Matching host byte entry */
   147		sc.result = DID_TIME_OUT << 16;
   148		KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
   149	
   150		/* Match SCMD_FAILURE_RESULT_ANY */
   151		sc.failures = any_failures;
   152		sc.result = DID_TRANSPORT_FAILFAST << 16;
   153		KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
   154	
   155		/* Test any status handling */
   156		sc.failures = any_status_failures;
   157		sc.result = SAM_STAT_RESERVATION_CONFLICT;
   158		KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
   159	}
   160
Mike Christie Oct. 24, 2022, 6:39 p.m. UTC | #2
On 10/23/22 1:32 AM, kernel test robot wrote:
> Hi Mike,
> 
> I love your patch! Yet something to improve:
> 
> [auto build test ERROR on jejb-scsi/for-next]
> [also build test ERROR on groeck-staging/hwmon-next linus/master v6.1-rc1 next-20221021]
> [cannot apply to mkp-scsi/for-next]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Mike-Christie/Allow-scsi_execute-users-to-control-retries/20221023-111103
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
> patch link:    https://lore.kernel.org/r/20221023030403.33845-36-michael.christie%40oracle.com
> patch subject: [PATCH v5 35/35] scsi: Add kunit tests for scsi_check_passthrough
> config: arc-randconfig-r025-20221023
> compiler: arc-elf-gcc (GCC) 12.1.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/intel-lab-lkp/linux/commit/5c568c0893302315545f701ffe9d0aa2afb276d4
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Mike-Christie/Allow-scsi_execute-users-to-control-retries/20221023-111103
>         git checkout 5c568c0893302315545f701ffe9d0aa2afb276d4
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash
> 
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <lkp@intel.com>
> 
> All errors (new ones prefixed by >>):
> 
>    arc-elf-ld: drivers/scsi/scsi_error.o: in function `scsi_test_error_check_passthough':
>>> drivers/scsi/scsi_error_test.c:139: undefined reference to `kunit_binary_assert_format'
>>> arc-elf-ld: drivers/scsi/scsi_error_test.c:139: undefined reference to `kunit_binary_assert_format'

Looks like I didn't test the case where scsi is built into the kernel but
kunit is built as a module. Will fix in a v6 posting.
diff mbox series

Patch

diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 03e71e3d5e5b..40ddbb691f08 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -67,6 +67,13 @@  config SCSI_PROC_FS
 
 	  If unsure say Y.
 
+config SCSI_KUNIT_TEST
+	bool "KUnit tests for SCSI Mid Layer" if !KUNIT_ALL_TESTS
+	depends on SCSI && KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  Run SCSI Mid Layer's KUnit tests.
+
 comment "SCSI support type (disk, tape, CD-ROM)"
 	depends on SCSI
 
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 19548a1d69c0..87ab763b7b19 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -2616,3 +2616,7 @@  bool scsi_get_sense_info_fld(const u8 *sense_buffer, int sb_len,
 	}
 }
 EXPORT_SYMBOL(scsi_get_sense_info_fld);
+
+#if defined(CONFIG_SCSI_KUNIT_TEST)
+#include "scsi_error_test.c"
+#endif
diff --git a/drivers/scsi/scsi_error_test.c b/drivers/scsi/scsi_error_test.c
new file mode 100644
index 000000000000..23a2e7edc5eb
--- /dev/null
+++ b/drivers/scsi/scsi_error_test.c
@@ -0,0 +1,171 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KUnit tests for scsi_error.c.
+ *
+ * Copyright (C) 2022, Oracle Corporation
+ */
+#include <kunit/test.h>
+
+#include <scsi/scsi_proto.h>
+#include <scsi/scsi_cmnd.h>
+
+#define SCSI_TEST_ERROR_MAX_ALLOWED 3
+
+static void scsi_test_error_check_passthough(struct kunit *test)
+{
+	struct scsi_failure multiple_sense_failures[] = {
+		{
+			.sense = DATA_PROTECT,
+			.asc = 0x1,
+			.ascq = 0x1,
+			.allowed = 0,
+			.result = SAM_STAT_CHECK_CONDITION,
+		},
+		{
+			.sense = UNIT_ATTENTION,
+			.asc = 0x11,
+			.ascq = 0x0,
+			.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
+			.result = SAM_STAT_CHECK_CONDITION,
+		},
+		{
+			.sense = NOT_READY,
+			.asc = 0x11,
+			.ascq = 0x22,
+			.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
+			.result = SAM_STAT_CHECK_CONDITION,
+		},
+		{
+			.sense = ABORTED_COMMAND,
+			.asc = 0x11,
+			.ascq = SCMD_FAILURE_ASCQ_ANY,
+			.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
+			.result = SAM_STAT_CHECK_CONDITION,
+		},
+		{
+			.sense = HARDWARE_ERROR,
+			.asc = SCMD_FAILURE_ASC_ANY,
+			.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
+			.result = SAM_STAT_CHECK_CONDITION,
+		},
+		{
+			.sense = ILLEGAL_REQUEST,
+			.asc = 0x91,
+			.ascq = 0x36,
+			.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
+			.result = SAM_STAT_CHECK_CONDITION,
+		},
+		{},
+	};
+	struct scsi_failure retryable_host_failures[] = {
+		{
+			.result = DID_TRANSPORT_DISRUPTED << 16,
+			.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
+		},
+		{
+			.result = DID_TIME_OUT << 16,
+			.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
+		},
+		{},
+	};
+	struct scsi_failure any_status_failures[] = {
+		{
+			.result = SCMD_FAILURE_STAT_ANY,
+			.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
+		},
+		{},
+	};
+	struct scsi_failure any_sense_failures[] = {
+		{
+			.result = SCMD_FAILURE_SENSE_ANY,
+			.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
+		},
+		{},
+	};
+	struct scsi_failure any_failures[] = {
+		{
+			.result = SCMD_FAILURE_RESULT_ANY,
+			.allowed = SCSI_TEST_ERROR_MAX_ALLOWED,
+		},
+		{},
+	};
+	u8 sense[SCSI_SENSE_BUFFERSIZE] = {};
+	struct scsi_cmnd sc = {
+		.sense_buffer = sense,
+		.failures = multiple_sense_failures,
+	};
+	int i;
+
+	/* Match end of array */
+	scsi_build_sense(&sc, 0, ILLEGAL_REQUEST, 0x91, 0x36);
+	KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
+	/* Basic match in array */
+	scsi_build_sense(&sc, 0, UNIT_ATTENTION, 0x11, 0x0);
+	KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
+	/* No matching sense entry */
+	scsi_build_sense(&sc, 0, MISCOMPARE, 0x11, 0x11);
+	KUNIT_EXPECT_EQ(test, SCSI_RETURN_NOT_HANDLED,
+			scsi_check_passthrough(&sc));
+	/* Match using SCMD_FAILURE_ASCQ_ANY */
+	scsi_build_sense(&sc, 0, ABORTED_COMMAND, 0x22, 0x22);
+	KUNIT_EXPECT_EQ(test, SCSI_RETURN_NOT_HANDLED,
+			scsi_check_passthrough(&sc));
+	/* Match using SCMD_FAILURE_ASC_ANY */
+	scsi_build_sense(&sc, 0, HARDWARE_ERROR, 0x11, 0x22);
+	KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
+	/* No matching status entry */
+	sc.result = SAM_STAT_RESERVATION_CONFLICT;
+	KUNIT_EXPECT_EQ(test, SCSI_RETURN_NOT_HANDLED,
+			scsi_check_passthrough(&sc));
+
+	/* Test hitting allowed limit */
+	scsi_build_sense(&sc, 0, NOT_READY, 0x11, 0x22);
+	for (i = 0; i < SCSI_TEST_ERROR_MAX_ALLOWED; i++)
+		KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
+	KUNIT_EXPECT_EQ(test, SUCCESS, scsi_check_passthrough(&sc));
+
+	/* Match using SCMD_FAILURE_SENSE_ANY */
+	sc.failures = any_sense_failures;
+	scsi_build_sense(&sc, 0, MEDIUM_ERROR, 0x11, 0x22);
+	KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
+
+	/* reset retries so we can retest */
+	for (i = 0; i < ARRAY_SIZE(multiple_sense_failures); i++)
+		multiple_sense_failures[i].retries = 0;
+
+	/* Test no retries allowed */
+	sc.failures = multiple_sense_failures;
+	scsi_build_sense(&sc, 0, DATA_PROTECT, 0x1, 0x1);
+	KUNIT_EXPECT_EQ(test, SUCCESS, scsi_check_passthrough(&sc));
+
+	/* No matching host byte entry */
+	sc.failures = retryable_host_failures;
+	sc.result = DID_NO_CONNECT << 16;
+	KUNIT_EXPECT_EQ(test, SCSI_RETURN_NOT_HANDLED,
+			scsi_check_passthrough(&sc));
+	/* Matching host byte entry */
+	sc.result = DID_TIME_OUT << 16;
+	KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
+
+	/* Match SCMD_FAILURE_RESULT_ANY */
+	sc.failures = any_failures;
+	sc.result = DID_TRANSPORT_FAILFAST << 16;
+	KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
+
+	/* Test any status handling */
+	sc.failures = any_status_failures;
+	sc.result = SAM_STAT_RESERVATION_CONFLICT;
+	KUNIT_EXPECT_EQ(test, NEEDS_RETRY, scsi_check_passthrough(&sc));
+}
+
+static struct kunit_case scsi_test_error_cases[] = {
+	KUNIT_CASE(scsi_test_error_check_passthough),
+	{},
+};
+
+static struct kunit_suite scsi_test_error_suite = {
+	.name = "scsi_error",
+	.test_cases = scsi_test_error_cases,
+};
+
+kunit_test_suite(scsi_test_error_suite);