smb/client: make SMB2 maperror KUnit tests a separate module

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>
Acked-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
Signed-off-by: Steve French <stfrench@microsoft.com>
This commit is contained in:
ChenXiaoSong
2026-02-21 08:07:12 +00:00
committed by Steve French
parent 11439c4635
commit 7d0bf050a5
4 changed files with 38 additions and 16 deletions

View File

@@ -56,4 +56,6 @@ $(obj)/smb2maperror.o: $(obj)/smb2_mapping_table.c
quiet_cmd_gen_smb2_mapping = GEN $@ quiet_cmd_gen_smb2_mapping = GEN $@
cmd_gen_smb2_mapping = perl $(src)/gen_smb2_mapping $< $@ cmd_gen_smb2_mapping = perl $(src)/gen_smb2_mapping $< $@
obj-$(CONFIG_SMB_KUNIT_TESTS) += smb2maperror_test.o
clean-files += smb2_mapping_table.c clean-files += smb2_mapping_table.c

View File

@@ -46,4 +46,16 @@ enum smb2_compound_ops {
#define END_OF_CHAIN 4 #define END_OF_CHAIN 4
#define RELATED_REQUEST 8 #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 */ #endif /* _SMB2_GLOB_H */

View File

@@ -8,7 +8,6 @@
* *
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include "cifsglob.h"
#include "cifsproto.h" #include "cifsproto.h"
#include "cifs_debug.h" #include "cifs_debug.h"
#include "smb2proto.h" #include "smb2proto.h"
@@ -16,12 +15,6 @@
#include "../common/smb2status.h" #include "../common/smb2status.h"
#include "trace.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[] = { static const struct status_to_posix_error smb2_error_map_table[] = {
/* /*
* Automatically generated by the `gen_smb2_mapping` script, * Automatically generated by the `gen_smb2_mapping` script,
@@ -115,10 +108,19 @@ int __init smb2_init_maperror(void)
return 0; return 0;
} }
#define SMB_CLIENT_KUNIT_AVAILABLE \ #if IS_ENABLED(CONFIG_SMB_KUNIT_TESTS)
((IS_MODULE(CONFIG_CIFS) && IS_ENABLED(CONFIG_KUNIT)) || \ /* Previous prototype for eliminating the build warning. */
(IS_BUILTIN(CONFIG_CIFS) && IS_BUILTIN(CONFIG_KUNIT))) const struct status_to_posix_error *smb2_get_err_map_test(__u32 smb2_status);
#if SMB_CLIENT_KUNIT_AVAILABLE && IS_ENABLED(CONFIG_SMB_KUNIT_TESTS) const struct status_to_posix_error *smb2_get_err_map_test(__u32 smb2_status)
#include "smb2maperror_test.c" {
#endif /* CONFIG_SMB_KUNIT_TESTS */ 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);
unsigned int smb2_error_map_num = ARRAY_SIZE(smb2_error_map_table);
EXPORT_SYMBOL_GPL(smb2_error_map_num);
#endif

View File

@@ -9,13 +9,18 @@
*/ */
#include <kunit/test.h> #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 static void
test_cmp_map(struct kunit *test, const struct status_to_posix_error *expect) test_cmp_map(struct kunit *test, const struct status_to_posix_error *expect)
{ {
const struct status_to_posix_error *result; 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_PTR_NE(test, NULL, result);
KUNIT_EXPECT_EQ(test, expect->smb2_status, result->smb2_status); KUNIT_EXPECT_EQ(test, expect->smb2_status, result->smb2_status);
KUNIT_EXPECT_EQ(test, expect->posix_error, result->posix_error); 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; unsigned int i;
for (i = 0; i < ARRAY_SIZE(smb2_error_map_table); i++) for (i = 0; i < smb2_error_map_num; i++)
test_cmp_map(test, &smb2_error_map_table[i]); test_cmp_map(test, &smb2_error_map_table_test[i]);
} }
static struct kunit_case maperror_test_cases[] = { static struct kunit_case maperror_test_cases[] = {
@@ -43,3 +48,4 @@ static struct kunit_suite maperror_suite = {
kunit_test_suite(maperror_suite); kunit_test_suite(maperror_suite);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("KUnit tests of SMB2 maperror");