{"id":2219169,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2219169/?format=json","project":{"id":12,"url":"http://patchwork.ozlabs.org/api/1.0/projects/12/?format=json","name":"Linux CIFS Client","link_name":"linux-cifs-client","list_id":"linux-cifs.vger.kernel.org","list_email":"linux-cifs@vger.kernel.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260402141839.461257-8-huiwen.he@linux.dev>","date":"2026-04-02T14:18:33","name":"[v3,07/13] smb/client: introduce KUnit test to check ntstatus_to_dos_map search","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"44d25024d205ab2f670ca8d30d8b340a7dbc6d43","submitter":{"id":93029,"url":"http://patchwork.ozlabs.org/api/1.0/people/93029/?format=json","name":null,"email":"huiwen.he@linux.dev"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260402141839.461257-8-huiwen.he@linux.dev/mbox/","series":[{"id":498490,"url":"http://patchwork.ozlabs.org/api/1.0/series/498490/?format=json","date":"2026-04-02T14:18:28","name":"smb: improve search speed of SMB1 maperror","version":3,"mbox":"http://patchwork.ozlabs.org/series/498490/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219169/checks/","tags":{},"headers":{"Return-Path":"\n <linux-cifs+bounces-10640-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-cifs@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256\n header.s=key1 header.b=w36iFBzC;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c09:e001:a7::12fc:5321; helo=sto.lore.kernel.org;\n envelope-from=linux-cifs+bounces-10640-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev\n header.b=\"w36iFBzC\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=91.218.175.178","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.dev","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=linux.dev"],"Received":["from sto.lore.kernel.org (sto.lore.kernel.org\n [IPv6:2600:3c09:e001:a7::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fmkZQ0Wl1z1xtJ\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 03 Apr 2026 01:22:06 +1100 (AEDT)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sto.lore.kernel.org (Postfix) with ESMTP id AA3EA307BF2A\n\tfor <incoming@patchwork.ozlabs.org>; Thu,  2 Apr 2026 14:20:13 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 3FC2B3ED10D;\n\tThu,  2 Apr 2026 14:20:06 +0000 (UTC)","from out-178.mta0.migadu.com (out-178.mta0.migadu.com\n [91.218.175.178])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 02A1E3EBF34\n\tfor <linux-cifs@vger.kernel.org>; Thu,  2 Apr 2026 14:20:03 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775139606; cv=none;\n b=NauS0W28xtfhScaGht2b9aw/gm97Am0VbT9gbpEjPbbeuyHNQIzDZ0MjXrQYJs1BeUcX4KDPPyNarTpLDVt7RtWmlHLdRz/9GZHOtS0ALd4YMYBPLhA0i0BuI1JzA2nlzZ7RvsBJIfhffFWVCSAWg/kxTFYG6QcMAWQiuVtyGvE=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775139606; c=relaxed/simple;\n\tbh=DCUsEPoSHGz3KZW4w2lZlrX+CpThEUA592tv92yadoo=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=H0c/t8SGNEvgLrDug6hYKg+3w9WLk+6aFOtY6pZ4s0tcwFAQFMZqyjLDJ8IBUKRY4DtbM/QB9dc0KCoX7z5Y18TGYQpAKiPo2iBgtCGF94eyrr1elHe6Xpbqr6oTDlGiASqxAc+8Q6JsGlZ6XBo6/Lb1TP2t/LIyWyYXSS0GjrI=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.dev;\n spf=pass smtp.mailfrom=linux.dev;\n dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev\n header.b=w36iFBzC; arc=none smtp.client-ip=91.218.175.178","X-Report-Abuse":"Please report any abuse attempt to abuse@migadu.com and\n include these headers.","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1;\n\tt=1775139602;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\t to:to:cc:cc:mime-version:mime-version:\n\t content-transfer-encoding:content-transfer-encoding:\n\t in-reply-to:in-reply-to:references:references;\n\tbh=QvkybnxUd5xos7EzrWqUlelewNUK11lK0zjP03X0Zr4=;\n\tb=w36iFBzC257zgoxG/K+FhzCpD6renyX1J/xIUuy2AnTFVuni123cELulLKePVMpwUZyzZ+\n\tSv1UvSihdF58O+AbH5pee4gQBI/I2RVhXcJaKLihShCZ0l8A+YFtEfcL5AE8xs1rpXwO7d\n\t7un4Geux54mjyUBO/2SXC0hOdJrRgTM=","From":"huiwen.he@linux.dev","To":"smfrench@gmail.com,\n\tlinkinjeon@kernel.org,\n\tdhowells@redhat.com,\n\tchenxiaosong@kylinos.cn,\n\tchenxiaosong@chenxiaosong.com,\n\ttangyouling@kylinos.cn","Cc":"linux-cifs@vger.kernel.org","Subject":"[PATCH v3 07/13] smb/client: introduce KUnit test to check\n ntstatus_to_dos_map search","Date":"Thu,  2 Apr 2026 14:18:33 +0000","Message-ID":"<20260402141839.461257-8-huiwen.he@linux.dev>","In-Reply-To":"<20260402141839.461257-1-huiwen.he@linux.dev>","References":"<20260402141839.461257-1-huiwen.he@linux.dev>","Precedence":"bulk","X-Mailing-List":"linux-cifs@vger.kernel.org","List-Id":"<linux-cifs.vger.kernel.org>","List-Subscribe":"<mailto:linux-cifs+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-cifs+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Migadu-Flow":"FLOW_OUT"},"content":"From: Youling Tang <tangyouling@kylinos.cn>\n\nCheck whether all elements can be correctly found in the array.\n\nIntroduce CONFIG_SMB1_KUNIT_TESTS for smb1maperror_test.ko since\nsmb1maperror.o is only built when CONFIG_CIFS_ALLOW_INSECURE_LEGACY\nis enabled.\n\nWe are going to define 3 functions to check the search results, introduce\nthe macro DEFINE_CHECK_SEARCH_FUNC() to reduce duplicate code.\n\nSigned-off-by: Youling Tang <tangyouling@kylinos.cn>\nReviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>\n---\n fs/smb/client/Kconfig             | 11 ++++++\n fs/smb/client/Makefile            |  1 +\n fs/smb/client/smb1maperror.c      | 19 ++++++++++\n fs/smb/client/smb1maperror_test.c | 61 +++++++++++++++++++++++++++++++\n fs/smb/client/smb1proto.h         |  4 ++\n 5 files changed, 96 insertions(+)\n create mode 100644 fs/smb/client/smb1maperror_test.c","diff":"diff --git a/fs/smb/client/Kconfig b/fs/smb/client/Kconfig\nindex 17bd368574e9..2e72d3c8423f 100644\n--- a/fs/smb/client/Kconfig\n+++ b/fs/smb/client/Kconfig\n@@ -217,4 +217,15 @@ config CIFS_COMPRESSION\n \t  Say Y here if you want SMB traffic to be compressed.\n \t  If unsure, say N.\n \n+config SMB1_KUNIT_TESTS\n+\ttristate \"KUnit tests for SMB1\"\n+\tdepends on SMB_KUNIT_TESTS && CIFS_ALLOW_INSECURE_LEGACY\n+\tdefault SMB_KUNIT_TESTS\n+\thelp\n+\t  This builds the SMB1-specific KUnit tests.\n+\n+\t  These tests are only enabled when legacy insecure SMB1 support\n+\t  (CIFS_ALLOW_INSECURE_LEGACY) is enabled.\n+\n+\t  If unsure, say N.\n endif\ndiff --git a/fs/smb/client/Makefile b/fs/smb/client/Makefile\nindex 8560fe99ec2b..220a97c8a488 100644\n--- a/fs/smb/client/Makefile\n+++ b/fs/smb/client/Makefile\n@@ -71,6 +71,7 @@ $(obj)/smb2maperror.o: $(obj)/smb2_mapping_table.c\n quiet_cmd_gen_smb2_mapping = GEN     $@\n       cmd_gen_smb2_mapping = perl $(src)/gen_smb2_mapping $< $@\n \n+obj-$(CONFIG_SMB1_KUNIT_TESTS) += smb1maperror_test.o\n obj-$(CONFIG_SMB_KUNIT_TESTS) += smb2maperror_test.o\n \n # Let Kbuild handle tracking and cleaning\ndiff --git a/fs/smb/client/smb1maperror.c b/fs/smb/client/smb1maperror.c\nindex 66ceebbe535e..419057f296a7 100644\n--- a/fs/smb/client/smb1maperror.c\n+++ b/fs/smb/client/smb1maperror.c\n@@ -288,3 +288,22 @@ int __init smb1_init_maperror(void)\n \n \treturn rc;\n }\n+\n+#if IS_ENABLED(CONFIG_SMB1_KUNIT_TESTS)\n+#define EXPORT_SYMBOL_FOR_SMB_TEST(sym) \\\n+\tEXPORT_SYMBOL_FOR_MODULES(sym, \"smb1maperror_test\")\n+\n+const struct ntstatus_to_dos_err *\n+search_ntstatus_to_dos_map_test(__u32 ntstatus)\n+{\n+\treturn search_ntstatus_to_dos_map(ntstatus);\n+}\n+EXPORT_SYMBOL_FOR_SMB_TEST(search_ntstatus_to_dos_map_test);\n+\n+const struct ntstatus_to_dos_err *\n+ntstatus_to_dos_map_test = ntstatus_to_dos_map;\n+EXPORT_SYMBOL_FOR_SMB_TEST(ntstatus_to_dos_map_test);\n+\n+unsigned int ntstatus_to_dos_num = ARRAY_SIZE(ntstatus_to_dos_map);\n+EXPORT_SYMBOL_FOR_SMB_TEST(ntstatus_to_dos_num);\n+#endif\ndiff --git a/fs/smb/client/smb1maperror_test.c b/fs/smb/client/smb1maperror_test.c\nnew file mode 100644\nindex 000000000000..b38857dc388c\n--- /dev/null\n+++ b/fs/smb/client/smb1maperror_test.c\n@@ -0,0 +1,61 @@\n+// SPDX-License-Identifier: GPL-2.0-or-later\n+/*\n+ *\n+ *   KUnit tests of SMB1 maperror\n+ *\n+ *   Copyright (C) 2026 KylinSoft Co., Ltd. All rights reserved.\n+ *   Author(s): Youling Tang <tangyouling@kylinos.cn>\n+ *              ChenXiaoSong <chenxiaosong@kylinos.cn>\n+ *\n+ */\n+\n+#include <kunit/test.h>\n+#include \"smb1proto.h\"\n+#include \"nterr.h\"\n+\n+extern const struct ntstatus_to_dos_err *ntstatus_to_dos_map_test;\n+extern unsigned int ntstatus_to_dos_num;\n+\n+#define DEFINE_CHECK_SEARCH_FUNC(__struct_name, __field,\t\t\\\n+\t\t\t\t __array, __num)\t\t\t\\\n+static void check_search_ ## __array(struct kunit *test)\t\t\\\n+{\t\t\t\t\t\t\t\t\t\\\n+\tunsigned int i;\t\t\t\t\t\t\t\\\n+\tconst struct __struct_name *expect, *result;\t\t\t\\\n+\t\t\t\t\t\t\t\t\t\\\n+\tfor (i = 0; i < __num; i++) {\t\t\t\t\t\\\n+\t\texpect = &__array ## _test[i];\t\t\t\t\\\n+\t\tresult = search_ ## __array ## _test(expect->__field);\t\\\n+\t\tKUNIT_ASSERT_NOT_NULL(test, result);\t\t\t\\\n+\t\ttest_cmp_ ## __struct_name(test, expect, result);\t\\\n+\t}\t\t\t\t\t\t\t\t\\\n+}\n+\n+static void\n+test_cmp_ntstatus_to_dos_err(struct kunit *test,\n+\t\t\t     const struct ntstatus_to_dos_err *expect,\n+\t\t\t     const struct ntstatus_to_dos_err *result)\n+{\n+\tKUNIT_EXPECT_EQ(test, expect->dos_class, result->dos_class);\n+\tKUNIT_EXPECT_EQ(test, expect->dos_code, result->dos_code);\n+\tKUNIT_EXPECT_EQ(test, expect->ntstatus, result->ntstatus);\n+\tKUNIT_EXPECT_STREQ(test, expect->nt_errstr, result->nt_errstr);\n+}\n+\n+/* check_search_ntstatus_to_dos_map */\n+DEFINE_CHECK_SEARCH_FUNC(ntstatus_to_dos_err, ntstatus, ntstatus_to_dos_map,\n+\t\t\t ntstatus_to_dos_num);\n+\n+static struct kunit_case maperror_test_cases[] = {\n+\tKUNIT_CASE(check_search_ntstatus_to_dos_map),\n+\t{}\n+};\n+\n+static struct kunit_suite maperror_suite = {\n+\t.name = \"smb1_maperror\",\n+\t.test_cases = maperror_test_cases,\n+};\n+\n+kunit_test_suite(maperror_suite);\n+\n+MODULE_LICENSE(\"GPL\");\ndiff --git a/fs/smb/client/smb1proto.h b/fs/smb/client/smb1proto.h\nindex dd98d04e837a..43b773e7964b 100644\n--- a/fs/smb/client/smb1proto.h\n+++ b/fs/smb/client/smb1proto.h\n@@ -237,6 +237,10 @@ int map_smb_to_linux_error(char *buf, bool logErr);\n int smb1_init_maperror(void);\n int map_and_check_smb_error(struct TCP_Server_Info *server,\n \t\t\t    struct mid_q_entry *mid, bool logErr);\n+#if IS_ENABLED(CONFIG_SMB1_KUNIT_TESTS)\n+const struct ntstatus_to_dos_err *\n+search_ntstatus_to_dos_map_test(__u32 ntstatus);\n+#endif\n \n /*\n  * smb1misc.c\n","prefixes":["v3","07/13"]}