public inbox for linux-cifs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] smb/client: make SMB2 maperror KUnit tests a separate module
@ 2026-02-21  8:07 chenxiaosong.chenxiaosong
  2026-02-23 21:11 ` Paulo Alcantara
  0 siblings, 1 reply; 3+ messages in thread
From: chenxiaosong.chenxiaosong @ 2026-02-21  8:07 UTC (permalink / raw)
  To: smfrench, linkinjeon, pc, ronniesahlberg, sprasad, tom, bharathsm,
	senozhatsky, dhowells, geert
  Cc: linux-cifs, ChenXiaoSong

From: ChenXiaoSong <chenxiaosong@kylinos.cn>

Build the SMB2 maperror KUnit tests as `smb2maperror_test.ko`.

Link: https://lore.kernel.org/linux-cifs/20260210081040.4156383-1-geert@linux-m68k.org/
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
 fs/smb/client/Makefile            |  2 ++
 fs/smb/client/smb2glob.h          | 12 ++++++++++++
 fs/smb/client/smb2maperror.c      | 28 +++++++++++++++-------------
 fs/smb/client/smb2maperror_test.c | 12 +++++++++---
 4 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/fs/smb/client/Makefile b/fs/smb/client/Makefile
index 3abd357d6df6..26b6105f04d1 100644
--- a/fs/smb/client/Makefile
+++ b/fs/smb/client/Makefile
@@ -56,4 +56,6 @@ $(obj)/smb2maperror.o: $(obj)/smb2_mapping_table.c
 quiet_cmd_gen_smb2_mapping = GEN     $@
       cmd_gen_smb2_mapping = perl $(src)/gen_smb2_mapping $< $@
 
+obj-$(CONFIG_SMB_KUNIT_TESTS) += smb2maperror_test.o
+
 clean-files	+= smb2_mapping_table.c
diff --git a/fs/smb/client/smb2glob.h b/fs/smb/client/smb2glob.h
index e56e4d402f13..19da74b1edab 100644
--- a/fs/smb/client/smb2glob.h
+++ b/fs/smb/client/smb2glob.h
@@ -46,4 +46,16 @@ enum smb2_compound_ops {
 #define END_OF_CHAIN 4
 #define RELATED_REQUEST 8
 
+/*
+ *****************************************************************
+ * Struct definitions go here
+ *****************************************************************
+ */
+
+struct status_to_posix_error {
+	__u32 smb2_status;
+	int posix_error;
+	char *status_string;
+};
+
 #endif	/* _SMB2_GLOB_H */
diff --git a/fs/smb/client/smb2maperror.c b/fs/smb/client/smb2maperror.c
index cd036365201f..f4cff44e2796 100644
--- a/fs/smb/client/smb2maperror.c
+++ b/fs/smb/client/smb2maperror.c
@@ -8,7 +8,6 @@
  *
  */
 #include <linux/errno.h>
-#include "cifsglob.h"
 #include "cifsproto.h"
 #include "cifs_debug.h"
 #include "smb2proto.h"
@@ -16,12 +15,6 @@
 #include "../common/smb2status.h"
 #include "trace.h"
 
-struct status_to_posix_error {
-	__u32 smb2_status;
-	int posix_error;
-	char *status_string;
-};
-
 static const struct status_to_posix_error smb2_error_map_table[] = {
 /*
  * Automatically generated by the `gen_smb2_mapping` script,
@@ -115,10 +108,19 @@ int __init smb2_init_maperror(void)
 	return 0;
 }
 
-#define SMB_CLIENT_KUNIT_AVAILABLE \
-	((IS_MODULE(CONFIG_CIFS) && IS_ENABLED(CONFIG_KUNIT)) || \
-	 (IS_BUILTIN(CONFIG_CIFS) && IS_BUILTIN(CONFIG_KUNIT)))
+#if IS_ENABLED(CONFIG_SMB_KUNIT_TESTS)
+/* Previous prototype for eliminating the build warning. */
+const struct status_to_posix_error *smb2_get_err_map_test(__u32 smb2_status);
+
+const struct status_to_posix_error *smb2_get_err_map_test(__u32 smb2_status)
+{
+	return smb2_get_err_map(smb2_status);
+}
+EXPORT_SYMBOL_GPL(smb2_get_err_map_test);
+
+const struct status_to_posix_error *smb2_error_map_table_test = smb2_error_map_table;
+EXPORT_SYMBOL_GPL(smb2_error_map_table_test);
 
-#if SMB_CLIENT_KUNIT_AVAILABLE && IS_ENABLED(CONFIG_SMB_KUNIT_TESTS)
-#include "smb2maperror_test.c"
-#endif /* CONFIG_SMB_KUNIT_TESTS */
+unsigned int smb2_error_map_num = ARRAY_SIZE(smb2_error_map_table);
+EXPORT_SYMBOL_GPL(smb2_error_map_num);
+#endif
diff --git a/fs/smb/client/smb2maperror_test.c b/fs/smb/client/smb2maperror_test.c
index 38ea6b846a99..8c47dea7a2c1 100644
--- a/fs/smb/client/smb2maperror_test.c
+++ b/fs/smb/client/smb2maperror_test.c
@@ -9,13 +9,18 @@
  */
 
 #include <kunit/test.h>
+#include "smb2glob.h"
+
+const struct status_to_posix_error *smb2_get_err_map_test(__u32 smb2_status);
+extern const struct status_to_posix_error *smb2_error_map_table_test;
+extern unsigned int smb2_error_map_num;
 
 static void
 test_cmp_map(struct kunit *test, const struct status_to_posix_error *expect)
 {
 	const struct status_to_posix_error *result;
 
-	result = smb2_get_err_map(expect->smb2_status);
+	result = smb2_get_err_map_test(expect->smb2_status);
 	KUNIT_EXPECT_PTR_NE(test, NULL, result);
 	KUNIT_EXPECT_EQ(test, expect->smb2_status, result->smb2_status);
 	KUNIT_EXPECT_EQ(test, expect->posix_error, result->posix_error);
@@ -26,8 +31,8 @@ static void maperror_test_check_search(struct kunit *test)
 {
 	unsigned int i;
 
-	for (i = 0; i < ARRAY_SIZE(smb2_error_map_table); i++)
-		test_cmp_map(test, &smb2_error_map_table[i]);
+	for (i = 0; i < smb2_error_map_num; i++)
+		test_cmp_map(test, &smb2_error_map_table_test[i]);
 }
 
 static struct kunit_case maperror_test_cases[] = {
@@ -43,3 +48,4 @@ static struct kunit_suite maperror_suite = {
 kunit_test_suite(maperror_suite);
 
 MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("KUnit tests of SMB2 maperror");
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] smb/client: make SMB2 maperror KUnit tests a separate module
  2026-02-21  8:07 [PATCH] smb/client: make SMB2 maperror KUnit tests a separate module chenxiaosong.chenxiaosong
@ 2026-02-23 21:11 ` Paulo Alcantara
  2026-03-01 17:37   ` Steve French
  0 siblings, 1 reply; 3+ messages in thread
From: Paulo Alcantara @ 2026-02-23 21:11 UTC (permalink / raw)
  To: chenxiaosong.chenxiaosong, smfrench, linkinjeon, ronniesahlberg,
	sprasad, tom, bharathsm, senozhatsky, dhowells, geert
  Cc: linux-cifs, ChenXiaoSong

chenxiaosong.chenxiaosong@linux.dev writes:

> From: ChenXiaoSong <chenxiaosong@kylinos.cn>
>
> Build the SMB2 maperror KUnit tests as `smb2maperror_test.ko`.
>
> Link: https://lore.kernel.org/linux-cifs/20260210081040.4156383-1-geert@linux-m68k.org/
> Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
> ---
>  fs/smb/client/Makefile            |  2 ++
>  fs/smb/client/smb2glob.h          | 12 ++++++++++++
>  fs/smb/client/smb2maperror.c      | 28 +++++++++++++++-------------
>  fs/smb/client/smb2maperror_test.c | 12 +++++++++---
>  4 files changed, 38 insertions(+), 16 deletions(-)

Acked-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] smb/client: make SMB2 maperror KUnit tests a separate module
  2026-02-23 21:11 ` Paulo Alcantara
@ 2026-03-01 17:37   ` Steve French
  0 siblings, 0 replies; 3+ messages in thread
From: Steve French @ 2026-03-01 17:37 UTC (permalink / raw)
  To: Paulo Alcantara
  Cc: chenxiaosong.chenxiaosong, linkinjeon, ronniesahlberg, sprasad,
	tom, bharathsm, senozhatsky, dhowells, geert, linux-cifs,
	ChenXiaoSong

added to cifs-2.6.git for-next

On Mon, Feb 23, 2026 at 3:11 PM Paulo Alcantara <pc@manguebit.org> wrote:
>
> chenxiaosong.chenxiaosong@linux.dev writes:
>
> > From: ChenXiaoSong <chenxiaosong@kylinos.cn>
> >
> > Build the SMB2 maperror KUnit tests as `smb2maperror_test.ko`.
> >
> > Link: https://lore.kernel.org/linux-cifs/20260210081040.4156383-1-geert@linux-m68k.org/
> > Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
> > ---
> >  fs/smb/client/Makefile            |  2 ++
> >  fs/smb/client/smb2glob.h          | 12 ++++++++++++
> >  fs/smb/client/smb2maperror.c      | 28 +++++++++++++++-------------
> >  fs/smb/client/smb2maperror_test.c | 12 +++++++++---
> >  4 files changed, 38 insertions(+), 16 deletions(-)
>
> Acked-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>



-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-01 17:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-21  8:07 [PATCH] smb/client: make SMB2 maperror KUnit tests a separate module chenxiaosong.chenxiaosong
2026-02-23 21:11 ` Paulo Alcantara
2026-03-01 17:37   ` Steve French

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox