From nobody Fri Dec 19 13:23:12 2025 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C4913B8D76 for ; Mon, 8 Dec 2025 06:23:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765174983; cv=none; b=QKPquAtPZB7e1/Eo+Tl21/2n1RviSXiOP9xJIGU10I8EvxTtCDUThzJkLkLt7JIQz6ZDMlhoHYMPMhT2EuL9xL0j6Bk5MqoEv1ZkQB5RaY8j8fWN7v8HT4FZmtdCbOqTjEc9Jo9S3nVOYyR8Ag5uTC3kigSqd9FWlepskJAZ52w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765174983; c=relaxed/simple; bh=w0nNCAawtWga2Wz7UljYjaZNJs1R7DG4IhmvbN7y/hw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uazy9q2DGmMiYsZgOMd9vqkDjqg1BY/GwHeavmu7+L7NVX+at5NoiR1iPF226hItPj3VXEqsGkjAP3CAbz9cxUoJYExfqyJCh8Fn3a4NDMw/9eGJETZfI6fBwr/n8EA4kTI25+XZ7Yl1tsD0xMtit2J3S7CAK7SCGS1q9tstN/4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=F7fMAAhL; arc=none smtp.client-ip=95.215.58.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="F7fMAAhL" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1765174978; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K1lLUuJbzKaoVowgzOVVnSVe2ltCt18Z1gofNbgQXKI=; b=F7fMAAhLT/QEFhI6YEI7tE1VkGZB4ujNJJgejYJHLjKYIiKnGcpb/ewcqVkODhvDyLM+Sd Yv2uGZutBdzUKGva4E7p5t4acF5aB7d7e+rZOawB5kJ7Xyn3Jo7prvSPuSX1THypP3hYgZ gCF4JphhFmTZO3qZnPSlgtJxI/8IrR8= From: chenxiaosong.chenxiaosong@linux.dev To: sfrench@samba.org, smfrench@gmail.com, linkinjeon@kernel.org, linkinjeon@samba.org Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, liuzhengyuan@kylinos.cn, huhai@kylinos.cn, liuyun01@kylinos.cn, ChenXiaoSong Subject: [PATCH 09/30] smb/client: create netmisc_test.c and introduce DEFINE_CHECK_SORT_FUNC() Date: Mon, 8 Dec 2025 14:20:39 +0800 Message-ID: <20251208062100.3268777-10-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251208062100.3268777-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251208062100.3268777-1-chenxiaosong.chenxiaosong@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: ChenXiaoSong 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 --- 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 + * + */ + +#include + +#define DEFINE_CHECK_SORT_FUNC(__array, __num, __field) \ +static void __array ## _check_sort(struct kunit *test) \ +{ \ + bool is_sorted =3D true; \ + unsigned int i; \ + \ + for (i =3D 1; i < __num; i++) { \ + if (__array[i].__field >=3D __array[i - 1].__field) \ + continue; \ + \ + pr_err("%s array order is incorrect\n", #__array); \ + is_sorted =3D 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[] =3D { + {} +}; + +static struct kunit_suite maperror_suite =3D { + .name =3D "smb1_maperror", + .test_cases =3D maperror_test_cases, +}; + +kunit_test_suite(maperror_suite); + +MODULE_LICENSE("GPL"); --=20 2.43.0