Skip to content

Commit 85274a3

Browse files
tangyoulingsmfrench
authored andcommitted
smb/client: introduce KUnit tests to check DOS/SRV err mapping search
Check whether all elements can be correctly found in the arrays. Signed-off-by: Youling Tang <tangyouling@kylinos.cn> Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 8c028dd commit 85274a3

4 files changed

Lines changed: 59 additions & 5 deletions

File tree

fs/smb/client/smb1maperror.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
#include "nterr.h"
1717
#include "cifs_debug.h"
1818

19-
struct smb_to_posix_error {
20-
__u16 smb_err;
21-
int posix_code;
22-
};
23-
2419
static __always_inline int smb1_posix_error_cmp(const void *_key, const void *_pivot)
2520
{
2621
__u16 key = *(__u16 *)_key;
@@ -260,4 +255,32 @@ EXPORT_SYMBOL_FOR_SMB_TEST(ntstatus_to_dos_map_test);
260255

261256
unsigned int ntstatus_to_dos_num = ARRAY_SIZE(ntstatus_to_dos_map);
262257
EXPORT_SYMBOL_FOR_SMB_TEST(ntstatus_to_dos_num);
258+
259+
const struct smb_to_posix_error *
260+
search_mapping_table_ERRDOS_test(__u16 smb_err)
261+
{
262+
return search_mapping_table_ERRDOS(smb_err);
263+
}
264+
EXPORT_SYMBOL_FOR_SMB_TEST(search_mapping_table_ERRDOS_test);
265+
266+
const struct smb_to_posix_error *
267+
mapping_table_ERRDOS_test = mapping_table_ERRDOS;
268+
EXPORT_SYMBOL_FOR_SMB_TEST(mapping_table_ERRDOS_test);
269+
270+
unsigned int mapping_table_ERRDOS_num = ARRAY_SIZE(mapping_table_ERRDOS);
271+
EXPORT_SYMBOL_FOR_SMB_TEST(mapping_table_ERRDOS_num);
272+
273+
const struct smb_to_posix_error *
274+
search_mapping_table_ERRSRV_test(__u16 smb_err)
275+
{
276+
return search_mapping_table_ERRSRV(smb_err);
277+
}
278+
EXPORT_SYMBOL_FOR_SMB_TEST(search_mapping_table_ERRSRV_test);
279+
280+
const struct smb_to_posix_error *
281+
mapping_table_ERRSRV_test = mapping_table_ERRSRV;
282+
EXPORT_SYMBOL_FOR_SMB_TEST(mapping_table_ERRSRV_test);
283+
284+
unsigned int mapping_table_ERRSRV_num = ARRAY_SIZE(mapping_table_ERRSRV);
285+
EXPORT_SYMBOL_FOR_SMB_TEST(mapping_table_ERRSRV_num);
263286
#endif

fs/smb/client/smb1maperror_test.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <kunit/test.h>
1313
#include "smb1proto.h"
1414
#include "nterr.h"
15+
#include "smberr.h"
1516

1617
#define DEFINE_CHECK_SEARCH_FUNC(__struct_name, __field, \
1718
__array, __num) \
@@ -39,12 +40,29 @@ test_cmp_ntstatus_to_dos_err(struct kunit *test,
3940
KUNIT_EXPECT_STREQ(test, expect->nt_errstr, result->nt_errstr);
4041
}
4142

43+
static void
44+
test_cmp_smb_to_posix_error(struct kunit *test,
45+
const struct smb_to_posix_error *expect,
46+
const struct smb_to_posix_error *result)
47+
{
48+
KUNIT_EXPECT_EQ(test, expect->smb_err, result->smb_err);
49+
KUNIT_EXPECT_EQ(test, expect->posix_code, result->posix_code);
50+
}
51+
4252
/* check_search_ntstatus_to_dos_map */
4353
DEFINE_CHECK_SEARCH_FUNC(ntstatus_to_dos_err, ntstatus, ntstatus_to_dos_map,
4454
ntstatus_to_dos_num);
55+
/* check_search_mapping_table_ERRDOS */
56+
DEFINE_CHECK_SEARCH_FUNC(smb_to_posix_error, smb_err, mapping_table_ERRDOS,
57+
mapping_table_ERRDOS_num);
58+
/* check_search_mapping_table_ERRSRV */
59+
DEFINE_CHECK_SEARCH_FUNC(smb_to_posix_error, smb_err, mapping_table_ERRSRV,
60+
mapping_table_ERRSRV_num);
4561

4662
static struct kunit_case maperror_test_cases[] = {
4763
KUNIT_CASE(check_search_ntstatus_to_dos_map),
64+
KUNIT_CASE(check_search_mapping_table_ERRDOS),
65+
KUNIT_CASE(check_search_mapping_table_ERRSRV),
4866
{}
4967
};
5068

fs/smb/client/smb1proto.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ extern const struct ntstatus_to_dos_err *ntstatus_to_dos_map_test;
242242
extern unsigned int ntstatus_to_dos_num;
243243
const struct ntstatus_to_dos_err *
244244
search_ntstatus_to_dos_map_test(__u32 ntstatus);
245+
extern const struct smb_to_posix_error *mapping_table_ERRDOS_test;
246+
extern unsigned int mapping_table_ERRDOS_num;
247+
const struct smb_to_posix_error *
248+
search_mapping_table_ERRDOS_test(__u16 smb_err);
249+
extern const struct smb_to_posix_error *mapping_table_ERRSRV_test;
250+
extern unsigned int mapping_table_ERRSRV_num;
251+
const struct smb_to_posix_error *
252+
search_mapping_table_ERRSRV_test(__u16 smb_err);
245253
#endif
246254

247255
/*

fs/smb/client/smberr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
*
1010
*/
1111

12+
struct smb_to_posix_error {
13+
__u16 smb_err;
14+
int posix_code;
15+
};
16+
1217
/* The request was successful. */
1318
#define SUCCESS 0x00
1419
/* Error is from the core DOS operating system set */

0 commit comments

Comments
 (0)