[PATCH 20/30] smb/client: introduce KUnit test to check search result of nt_errs array

chenxiaosong.chenxiaosong@linux.dev posted 30 patches 1 week, 4 days ago
[PATCH 20/30] smb/client: introduce KUnit test to check search result of nt_errs array
Posted by chenxiaosong.chenxiaosong@linux.dev 1 week, 4 days ago
From: ChenXiaoSong <chenxiaosong@kylinos.cn>

The KUnit test are executed when cifs.ko is loaded.

The nt_errs_check_search() checks whether all elements can be correctly
found in the nt_errs array.

Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
 fs/smb/client/netmisc_test.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/fs/smb/client/netmisc_test.c b/fs/smb/client/netmisc_test.c
index 796c39b02073..195c889af7be 100644
--- a/fs/smb/client/netmisc_test.c
+++ b/fs/smb/client/netmisc_test.c
@@ -57,8 +57,18 @@ static void test_cmp_ntstatus_to_dos(struct kunit *test,
 	KUNIT_EXPECT_EQ(test, expect->ntstatus, result->ntstatus);
 }
 
+static void test_cmp_nt_err_code_struct(struct kunit *test,
+					struct nt_err_code_struct *expect,
+					struct nt_err_code_struct *result)
+{
+	KUNIT_EXPECT_STREQ(test, expect->nt_errstr, result->nt_errstr);
+	KUNIT_EXPECT_EQ(test, expect->nt_errcode, result->nt_errcode);
+}
+
 /* ntstatus_to_dos_map_check_search */
 DEFINE_CHECK_SEARCH_FUNC(ntstatus_to_dos, ntstatus, ntstatus_to_dos_map, ntstatus_to_dos_num);
+/* nt_errs_check_search */
+DEFINE_CHECK_SEARCH_FUNC(nt_err_code_struct, nt_errcode, nt_errs, nt_err_num);
 
 /*
  * Before running these test cases, the smb_init_maperror()
@@ -70,6 +80,7 @@ static struct kunit_case maperror_test_cases[] = {
 	KUNIT_CASE(nt_errs_check_sort),
 	/* check search */
 	KUNIT_CASE(ntstatus_to_dos_map_check_search),
+	KUNIT_CASE(nt_errs_check_search),
 	{}
 };
 
-- 
2.43.0