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

chenxiaosong.chenxiaosong@linux.dev posted 30 patches 1 week, 4 days ago
[PATCH 15/30] smb/client: introduce KUnit test to check search result of ntstatus_to_dos_map 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 ntstatus_to_dos_map_check_search() checks whether all elements can be
correctly found in the array.

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

diff --git a/fs/smb/client/netmisc_test.c b/fs/smb/client/netmisc_test.c
index b682098d2fc5..ade5005fecb7 100644
--- a/fs/smb/client/netmisc_test.c
+++ b/fs/smb/client/netmisc_test.c
@@ -46,6 +46,18 @@ static void __array ## _check_search(struct kunit *test)		\
 	}								\
 }
 
+static void test_cmp_ntstatus_to_dos(struct kunit *test,
+				     struct ntstatus_to_dos *expect,
+				     struct ntstatus_to_dos *result)
+{
+	KUNIT_EXPECT_EQ(test, expect->dos_class, result->dos_class);
+	KUNIT_EXPECT_EQ(test, expect->dos_code, result->dos_code);
+	KUNIT_EXPECT_EQ(test, expect->ntstatus, result->ntstatus);
+}
+
+/* ntstatus_to_dos_map_check_search */
+DEFINE_CHECK_SEARCH_FUNC(ntstatus_to_dos, ntstatus, ntstatus_to_dos_map, ntstatus_to_dos_num);
+
 /*
  * Before running these test cases, the smb_init_maperror()
  * function is called first.
@@ -53,6 +65,8 @@ static void __array ## _check_search(struct kunit *test)		\
 static struct kunit_case maperror_test_cases[] = {
 	/* check sort */
 	KUNIT_CASE(ntstatus_to_dos_map_check_sort),
+	/* check search */
+	KUNIT_CASE(ntstatus_to_dos_map_check_search),
 	{}
 };
 
-- 
2.43.0