From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (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 0F5AF3C7E1D for ; Thu, 18 Jun 2026 09:22:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781774537; cv=none; b=pTbcqriH4X2gH+q90bld8xNTfLkUSa7iLlNt4l1rYYLEmcVNKENKuirbFqdQR2rmO27g48wPCfd6MYRfJVVl+FnATjplltM5jRMkdkO4VumRnCqV2YKaBFfIGY8EtQ8j2NT+Vo0R3kVOW9cTsTQydLeJn8LDE2uRyeX1DKlqQzA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781774537; c=relaxed/simple; bh=l80JMrZvKIdg03nDV1WCZ4cNqsOWz914uM3ZW31AYoQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AEbNutWsVb6vGvbRLeSOqqu/KoY8uqeQ7DanSwASm1OdRpJ9aMpMarTADjGl6ULlWGgCK/ZPcFsuAJRKHYeUHpOy2a3X2NJhZkxj8QojV3+g5j+gMYA8nrIzf5R78Pxb+81bbF64i/BGCcrIakIRGfWmq+KLeSqvjSeexY/Mcqs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=DSBZIv+5; arc=none smtp.client-ip=115.124.30.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="DSBZIv+5" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1781774534; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=kx58UzGJ5PzxcjTsuUEJwFleVBmeQq5F4w9/tyaV6pU=; b=DSBZIv+5kKiJ1ab9YSR23H+n0IE8iP3XAfkjsmErU0z4KgWplebxibcmuHRBhXu4XOV8aa8btMw0ycCd72TjMKTV25aTLsQUOQJpAq4iRRwkYINydCumV+E2kFNq1wiEJZ7hGs4Ftjenqt9xB0NxnLixVX6GgJceJag0JtwXzwc= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=tianruidong@linux.alibaba.com;NM=1;PH=DS;RN=28;SR=0;TI=SMTPD_---0X56UT.A_1781774529; Received: from localhost(mailfrom:tianruidong@linux.alibaba.com fp:SMTPD_---0X56UT.A_1781774529 cluster:ay36) by smtp.aliyun-inc.com; Thu, 18 Jun 2026 17:22:12 +0800 From: Ruidong Tian To: catalin.marinas@arm.com, will@kernel.org, rafael@kernel.org, tony.luck@intel.com, guohanjun@huawei.com, mchehab@kernel.org, xueshuai@linux.alibaba.com, tongtiangen@huawei.com, james.morse@arm.com, robin.murphy@arm.com, andreyknvl@gmail.com, dvyukov@google.com, vincenzo.frascino@arm.com, mpe@ellerman.id.au, npiggin@gmail.com, ryabinin.a.a@gmail.com, glider@google.com, christophe.leroy@csgroup.eu, aneesh.kumar@kernel.org, naveen.n.rao@linux.ibm.com, tglx@linutronix.de, mingo@redhat.com Cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, tianruidong@linux.alibaba.com Subject: [PATCH v15 8/9] lib/test: memcpy_kunit: add copy_page() and copy_mc_page() tests Date: Thu, 18 Jun 2026 17:21:22 +0800 Message-ID: <20260618092124.3901230-9-tianruidong@linux.alibaba.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260618092124.3901230-1-tianruidong@linux.alibaba.com> References: <20260618092124.3901230-1-tianruidong@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add KUnit tests for copy_page() and copy_mc_page(), modeled after the existing memcpy_test() style: a static page-aligned src and a two-page dst, filled with random bytes plus non-zero edges, then verify byte-for-byte equality and that the adjacent page is untouched. Signed-off-by: Ruidong Tian --- lib/tests/memcpy_kunit.c | 67 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/lib/tests/memcpy_kunit.c b/lib/tests/memcpy_kunit.c index d36933554e46..812c1fa20fd9 100644 --- a/lib/tests/memcpy_kunit.c +++ b/lib/tests/memcpy_kunit.c @@ -493,6 +493,67 @@ static void memmove_overlap_test(struct kunit *test) } } +/* --- Page-sized copy tests --- */ + +static u8 page_src[PAGE_SIZE] __aligned(PAGE_SIZE); +static u8 page_dst[PAGE_SIZE * 2] __aligned(PAGE_SIZE); +static const u8 page_pattern[PAGE_SIZE] __aligned(PAGE_SIZE); + +static void init_page(struct kunit *test) +{ + /* Get many bit patterns. */ + get_random_bytes(page_src, PAGE_SIZE); + + /* Make sure we have non-zero edges. */ + set_random_nonzero(test, &page_src[0]); + set_random_nonzero(test, &page_src[PAGE_SIZE - 1]); + + memset(page_dst, 0xA5, ARRAY_SIZE(page_dst)); + memset(page_pattern, 0xA5, PAGE_SIZE); +} + +static void copy_page_test(struct kunit *test) +{ + init_page(test); + + /* Copy. */ + copy_page(page_dst, page_src); + + /* Verify byte-for-byte exact. */ + KUNIT_ASSERT_EQ_MSG(test, + memcmp(page_dst, page_src, PAGE_SIZE), 0, + "copy_page content mismatch with random data"); + + /* Verify no overflow into second page. */ + KUNIT_ASSERT_EQ_MSG(test, + memcmp(page_dst + PAGE_SIZE, page_pattern, PAGE_SIZE), 0, + "copy_page overflow into adjacent page"); +} + +#ifdef __HAVE_ARCH_COPY_MC_PAGE +static void copy_mc_page_test(struct kunit *test) +{ + int ret; + + init_page(test); + + /* Copy and check return value. */ + ret = copy_mc_page(page_dst, page_src); + KUNIT_ASSERT_EQ_MSG(test, ret, 0, + "copy_mc_page returned %d on clean memory", ret); + + /* Verify byte-for-byte exact. */ + KUNIT_ASSERT_EQ_MSG(test, + memcmp(page_dst, page_src, PAGE_SIZE), 0, + "copy_mc_page content mismatch with random data"); + + /* Verify no overflow into second page. */ + KUNIT_ASSERT_EQ_MSG(test, + memcmp(page_dst + PAGE_SIZE, page_pattern, PAGE_SIZE), 0, + "copy_mc_page overflow into adjacent page"); +} +#endif /* __HAVE_ARCH_COPY_MC_PAGE */ + static struct kunit_case memcpy_test_cases[] = { KUNIT_CASE(memset_test), KUNIT_CASE(memcpy_test), @@ -500,6 +561,10 @@ static struct kunit_case memcpy_test_cases[] = { KUNIT_CASE_SLOW(memmove_test), KUNIT_CASE_SLOW(memmove_large_test), KUNIT_CASE_SLOW(memmove_overlap_test), + KUNIT_CASE(copy_page_test), +#ifdef __HAVE_ARCH_COPY_MC_PAGE + KUNIT_CASE(copy_mc_page_test), +#endif {} }; @@ -510,5 +575,5 @@ static struct kunit_suite memcpy_test_suite = { kunit_test_suite(memcpy_test_suite); -MODULE_DESCRIPTION("test cases for memcpy(), memmove(), and memset()"); +MODULE_DESCRIPTION("test cases for memcpy(), memmove(), memset() and copy_page()"); MODULE_LICENSE("GPL"); -- 2.39.3