lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210921151039.1502-5-longpeng2@huawei.com>
Date:   Tue, 21 Sep 2021 23:10:39 +0800
From:   "Longpeng(Mike)" <longpeng2@...wei.com>
To:     <andraprs@...zon.com>, <lexnv@...zon.com>, <alcioa@...zon.com>
CC:     <linux-kernel@...r.kernel.org>, <arei.gonglei@...wei.com>,
        <gregkh@...uxfoundation.org>, <kamal@...onical.com>,
        <pbonzini@...hat.com>, <sgarzare@...hat.com>,
        <stefanha@...hat.com>, <vkuznets@...hat.com>,
        <ne-devel-upstream@...zon.com>,
        "Longpeng(Mike)" <longpeng2@...wei.com>
Subject: [PATCH v2 4/4] nitro_enclaves: add kunit tests for physical contiguous region merging

Add kunit tests for the physical contiguous memory region merging
functionality.

Signed-off-by: Longpeng(Mike) <longpeng2@...wei.com>
---
 drivers/virt/nitro_enclaves/ne_misc_test.c | 46 ++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/drivers/virt/nitro_enclaves/ne_misc_test.c b/drivers/virt/nitro_enclaves/ne_misc_test.c
index 3426c35..8532bec 100644
--- a/drivers/virt/nitro_enclaves/ne_misc_test.c
+++ b/drivers/virt/nitro_enclaves/ne_misc_test.c
@@ -2,7 +2,53 @@
 
 #include <kunit/test.h>
 
+#define MAX_PHYS_REGIONS	16
+
+struct phys_regions_test {
+	u64 paddr;
+	u64 size;
+	int expect_rc;
+	unsigned long expect_num;
+	u64 expect_last_paddr;
+	u64 expect_last_size;
+} phys_regions_testcases[] = {
+	{0x1000, 0x200000, -EINVAL, 0, ~0, ~0},
+	{0x200000, 0x1000, -EINVAL, 0, ~0, ~0},
+	{0x200000, 0x200000, 0, 1, 0x200000, 0x200000},
+	{0x0, 0x200000, 0, 2, 0x0, 0x200000},
+	{0x600000, 0x400000, 0, 3, 0x600000, 0x400000},
+	{0xa00000, 0x400000, 0, 3, 0x600000, 0x800000},
+	{0x1000, 0x200000, -EINVAL, 3, 0x600000, 0x800000},
+};
+
+static void ne_misc_test_set_phys_region(struct kunit *test)
+{
+	struct phys_contig_mem_region *regions;
+	size_t sz;
+	int i, rc;
+
+	sz = sizeof(*regions) + MAX_PHYS_REGIONS * sizeof(struct phys_mem_region);
+	regions = kunit_kzalloc(test, sz, GFP_KERNEL);
+	KUNIT_ASSERT_TRUE(test, regions != NULL);
+
+	for (i = 0; i < ARRAY_SIZE(phys_regions_testcases); i++) {
+		rc = ne_add_phys_memory_region(regions, phys_regions_testcases[i].paddr,
+					       phys_regions_testcases[i].size);
+		KUNIT_EXPECT_EQ(test, rc, phys_regions_testcases[i].expect_rc);
+		KUNIT_EXPECT_EQ(test, regions->num, phys_regions_testcases[i].expect_num);
+
+		if (phys_regions_testcases[i].expect_last_paddr == ~0ul)
+			continue;
+
+		KUNIT_EXPECT_EQ(test, regions->region[regions->num - 1].paddr,
+				phys_regions_testcases[i].expect_last_paddr);
+		KUNIT_EXPECT_EQ(test, regions->region[regions->num - 1].size,
+				phys_regions_testcases[i].expect_last_size);
+	}
+}
+
 static struct kunit_case ne_misc_test_cases[] = {
+	KUNIT_CASE(ne_misc_test_set_phys_region),
 	{}
 };
 
-- 
1.8.3.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ