From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Mike Christie <michael.christie@oracle.com>,
"James E . J . Bottomley" <jejb@linux.ibm.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
Lukas Bulwahn <lukas.bulwahn@gmail.com>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH] scsi: core: Make scsi_lib KUnit tests modular for real
Date: Tue, 19 Mar 2024 13:02:29 +0100 [thread overview]
Message-ID: <48ca5e827ca420bbdbabb1643e2179dc95c9e0b7.1710849638.git.geert@linux-m68k.org> (raw)
While SCSI_LIB_KUNIT_TEST is a tristate config symbol, configuring a
modular build of this test does not do anything: as the test code is
just included by the mid layer code, it only works in the built-in case.
Fix this by converting the test to a stand-alone module. This requires
exporting scsi_check_passthrough() and adding a MODULE_LICENSE() tag.
Fixes: 25a1f7a0a1fe6fa6 ("scsi: core: Add kunit tests for scsi_check_passthrough()")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
drivers/scsi/Makefile | 1 +
drivers/scsi/scsi_lib.c | 9 +++------
drivers/scsi/scsi_lib_test.c | 4 ++++
drivers/scsi/scsi_priv.h | 2 ++
4 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index f055bfd54a6832b3..396a24aa43486678 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -149,6 +149,7 @@ obj-$(CONFIG_BLK_DEV_SR) += sr_mod.o
obj-$(CONFIG_CHR_DEV_SG) += sg.o
obj-$(CONFIG_CHR_DEV_SCH) += ch.o
obj-$(CONFIG_SCSI_ENCLOSURE) += ses.o
+obj-$(CONFIG_SCSI_LIB_KUNIT_TEST) += scsi_lib_test.o
obj-$(CONFIG_SCSI_HISI_SAS) += hisi_sas/
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 2e28e2360c85740d..23e94e9bf85781a9 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -203,8 +203,8 @@ EXPORT_SYMBOL_GPL(scsi_failures_reset_retries);
*
* Returns -EAGAIN if the caller should retry else 0.
*/
-static int scsi_check_passthrough(struct scsi_cmnd *scmd,
- struct scsi_failures *failures)
+int scsi_check_passthrough(struct scsi_cmnd *scmd,
+ struct scsi_failures *failures)
{
struct scsi_failure *failure;
struct scsi_sense_hdr sshdr;
@@ -269,6 +269,7 @@ static int scsi_check_passthrough(struct scsi_cmnd *scmd,
return 0;
}
+EXPORT_SYMBOL_GPL(scsi_check_passthrough);
/**
* scsi_execute_cmd - insert request and wait for the result
@@ -3436,7 +3437,3 @@ void scsi_build_sense(struct scsi_cmnd *scmd, int desc, u8 key, u8 asc, u8 ascq)
scmd->result = SAM_STAT_CHECK_CONDITION;
}
EXPORT_SYMBOL_GPL(scsi_build_sense);
-
-#ifdef CONFIG_SCSI_LIB_KUNIT_TEST
-#include "scsi_lib_test.c"
-#endif
diff --git a/drivers/scsi/scsi_lib_test.c b/drivers/scsi/scsi_lib_test.c
index 99834426a100a754..13045ac12fa99d24 100644
--- a/drivers/scsi/scsi_lib_test.c
+++ b/drivers/scsi/scsi_lib_test.c
@@ -10,6 +10,8 @@
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_device.h>
+#include "scsi_priv.h"
+
#define SCSI_LIB_TEST_MAX_ALLOWED 3
#define SCSI_LIB_TEST_TOTAL_MAX_ALLOWED 5
@@ -328,3 +330,5 @@ static struct kunit_suite scsi_lib_test_suite = {
};
kunit_test_suite(scsi_lib_test_suite);
+
+MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index 9fc397a9ce7a4f91..7f7e55341192e50e 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -113,6 +113,8 @@ extern int scsi_mq_setup_tags(struct Scsi_Host *shost);
extern void scsi_mq_free_tags(struct kref *kref);
extern void scsi_exit_queue(void);
extern void scsi_evt_thread(struct work_struct *work);
+extern int scsi_check_passthrough(struct scsi_cmnd *scmd,
+ struct scsi_failures *failures);
/* scsi_proc.c */
#ifdef CONFIG_SCSI_PROC_FS
--
2.34.1
next reply other threads:[~2024-03-19 12:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-19 12:02 Geert Uytterhoeven [this message]
2024-03-19 16:03 ` Bart Van Assche
2024-03-19 16:10 ` Geert Uytterhoeven
2024-03-19 17:01 ` Bart Van Assche
2024-03-20 8:08 ` Geert Uytterhoeven
2024-03-20 15:07 ` Bart Van Assche
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48ca5e827ca420bbdbabb1643e2179dc95c9e0b7.1710849638.git.geert@linux-m68k.org \
--to=geert@linux-m68k.org \
--cc=jejb@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=lukas.bulwahn@gmail.com \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®