[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251208062100.3268777-10-chenxiaosong.chenxiaosong@linux.dev>
Date: Mon, 8 Dec 2025 14:20:39 +0800
From: chenxiaosong.chenxiaosong@...ux.dev
To: sfrench@...ba.org,
smfrench@...il.com,
linkinjeon@...nel.org,
linkinjeon@...ba.org
Cc: linux-cifs@...r.kernel.org,
linux-kernel@...r.kernel.org,
liuzhengyuan@...inos.cn,
huhai@...inos.cn,
liuyun01@...inos.cn,
ChenXiaoSong <chenxiaosong@...inos.cn>
Subject: [PATCH 09/30] smb/client: create netmisc_test.c and introduce DEFINE_CHECK_SORT_FUNC()
From: ChenXiaoSong <chenxiaosong@...inos.cn>
We are going to define 4 functions to check the sort results, introduce the
macro DEFINE_CHECK_SORT_FUNC() to reduce duplicate code.
Signed-off-by: ChenXiaoSong <chenxiaosong@...inos.cn>
---
fs/smb/client/netmisc.c | 4 ++++
fs/smb/client/netmisc_test.c | 46 ++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+)
create mode 100644 fs/smb/client/netmisc_test.c
diff --git a/fs/smb/client/netmisc.c b/fs/smb/client/netmisc.c
index 54ede1db2c7f..32197a3a4e81 100644
--- a/fs/smb/client/netmisc.c
+++ b/fs/smb/client/netmisc.c
@@ -1056,3 +1056,7 @@ void smb_init_maperror(void)
sort(ntstatus_to_dos_map, ntstatus_to_dos_num,
sizeof(struct ntstatus_to_dos), cmp_ntstatus_to_dos, NULL);
}
+
+#if IS_ENABLED(CONFIG_SMB_KUNIT_TESTS)
+#include "netmisc_test.c"
+#endif /* CONFIG_SMB_KUNIT_TESTS */
diff --git a/fs/smb/client/netmisc_test.c b/fs/smb/client/netmisc_test.c
new file mode 100644
index 000000000000..f937b7b3d3f2
--- /dev/null
+++ b/fs/smb/client/netmisc_test.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: LGPL-2.1
+/*
+ *
+ * KUnit tests of SMB1 maperror
+ *
+ * Copyright (C) 2025 KylinSoft Co., Ltd. All rights reserved.
+ * Author(s): ChenXiaoSong <chenxiaosong@...inos.cn>
+ *
+ */
+
+#include <kunit/test.h>
+
+#define DEFINE_CHECK_SORT_FUNC(__array, __num, __field) \
+static void __array ## _check_sort(struct kunit *test) \
+{ \
+ bool is_sorted = true; \
+ unsigned int i; \
+ \
+ for (i = 1; i < __num; i++) { \
+ if (__array[i].__field >= __array[i - 1].__field) \
+ continue; \
+ \
+ pr_err("%s array order is incorrect\n", #__array); \
+ is_sorted = false; \
+ break; \
+ } \
+ \
+ KUNIT_EXPECT_EQ(test, true, is_sorted); \
+}
+
+/*
+ * Before running these test cases, the smb_init_maperror()
+ * function is called first.
+ */
+static struct kunit_case maperror_test_cases[] = {
+ {}
+};
+
+static struct kunit_suite maperror_suite = {
+ .name = "smb1_maperror",
+ .test_cases = maperror_test_cases,
+};
+
+kunit_test_suite(maperror_suite);
+
+MODULE_LICENSE("GPL");
--
2.43.0
Powered by blists - more mailing lists