Skip to content

Commit 7d0bf05

Browse files
ChenXiaoSongsmfrench
authored andcommitted
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>
1 parent 11439c4 commit 7d0bf05

4 files changed

Lines changed: 38 additions & 16 deletions

File tree

fs/smb/client/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ $(obj)/smb2maperror.o: $(obj)/smb2_mapping_table.c
5656
quiet_cmd_gen_smb2_mapping = GEN $@
5757
cmd_gen_smb2_mapping = perl $(src)/gen_smb2_mapping $< $@
5858

59+
obj-$(CONFIG_SMB_KUNIT_TESTS) += smb2maperror_test.o
60+
5961
clean-files += smb2_mapping_table.c

fs/smb/client/smb2glob.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,16 @@ enum smb2_compound_ops {
4646
#define END_OF_CHAIN 4
4747
#define RELATED_REQUEST 8
4848

49+
/*
50+
*****************************************************************
51+
* Struct definitions go here
52+
*****************************************************************
53+
*/
54+
55+
struct status_to_posix_error {
56+
__u32 smb2_status;
57+
int posix_error;
58+
char *status_string;
59+
};
60+
4961
#endif /* _SMB2_GLOB_H */

fs/smb/client/smb2maperror.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,13 @@
88
*
99
*/
1010
#include <linux/errno.h>
11-
#include "cifsglob.h"
1211
#include "cifsproto.h"
1312
#include "cifs_debug.h"
1413
#include "smb2proto.h"
1514
#include "smb2glob.h"
1615
#include "../common/smb2status.h"
1716
#include "trace.h"
1817

19-
struct status_to_posix_error {
20-
__u32 smb2_status;
21-
int posix_error;
22-
char *status_string;
23-
};
24-
2518
static const struct status_to_posix_error smb2_error_map_table[] = {
2619
/*
2720
* Automatically generated by the `gen_smb2_mapping` script,
@@ -115,10 +108,19 @@ int __init smb2_init_maperror(void)
115108
return 0;
116109
}
117110

118-
#define SMB_CLIENT_KUNIT_AVAILABLE \
119-
((IS_MODULE(CONFIG_CIFS) && IS_ENABLED(CONFIG_KUNIT)) || \
120-
(IS_BUILTIN(CONFIG_CIFS) && IS_BUILTIN(CONFIG_KUNIT)))
111+
#if IS_ENABLED(CONFIG_SMB_KUNIT_TESTS)
112+
/* Previous prototype for eliminating the build warning. */
113+
const struct status_to_posix_error *smb2_get_err_map_test(__u32 smb2_status);
114+
115+
const struct status_to_posix_error *smb2_get_err_map_test(__u32 smb2_status)
116+
{
117+
return smb2_get_err_map(smb2_status);
118+
}
119+
EXPORT_SYMBOL_GPL(smb2_get_err_map_test);
120+
121+
const struct status_to_posix_error *smb2_error_map_table_test = smb2_error_map_table;
122+
EXPORT_SYMBOL_GPL(smb2_error_map_table_test);
121123

122-
#if SMB_CLIENT_KUNIT_AVAILABLE && IS_ENABLED(CONFIG_SMB_KUNIT_TESTS)
123-
#include "smb2maperror_test.c"
124-
#endif /* CONFIG_SMB_KUNIT_TESTS */
124+
unsigned int smb2_error_map_num = ARRAY_SIZE(smb2_error_map_table);
125+
EXPORT_SYMBOL_GPL(smb2_error_map_num);
126+
#endif

fs/smb/client/smb2maperror_test.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
*/
1010

1111
#include <kunit/test.h>
12+
#include "smb2glob.h"
13+
14+
const struct status_to_posix_error *smb2_get_err_map_test(__u32 smb2_status);
15+
extern const struct status_to_posix_error *smb2_error_map_table_test;
16+
extern unsigned int smb2_error_map_num;
1217

1318
static void
1419
test_cmp_map(struct kunit *test, const struct status_to_posix_error *expect)
1520
{
1621
const struct status_to_posix_error *result;
1722

18-
result = smb2_get_err_map(expect->smb2_status);
23+
result = smb2_get_err_map_test(expect->smb2_status);
1924
KUNIT_EXPECT_PTR_NE(test, NULL, result);
2025
KUNIT_EXPECT_EQ(test, expect->smb2_status, result->smb2_status);
2126
KUNIT_EXPECT_EQ(test, expect->posix_error, result->posix_error);
@@ -26,8 +31,8 @@ static void maperror_test_check_search(struct kunit *test)
2631
{
2732
unsigned int i;
2833

29-
for (i = 0; i < ARRAY_SIZE(smb2_error_map_table); i++)
30-
test_cmp_map(test, &smb2_error_map_table[i]);
34+
for (i = 0; i < smb2_error_map_num; i++)
35+
test_cmp_map(test, &smb2_error_map_table_test[i]);
3136
}
3237

3338
static struct kunit_case maperror_test_cases[] = {
@@ -43,3 +48,4 @@ static struct kunit_suite maperror_suite = {
4348
kunit_test_suite(maperror_suite);
4449

4550
MODULE_LICENSE("GPL");
51+
MODULE_DESCRIPTION("KUnit tests of SMB2 maperror");

0 commit comments

Comments
 (0)