lkml.org 
[lkml]   [2021]   [Sep]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 4/4] nitro_enclaves: add kunit tests for physical contiguous region merging
Date
Add kunit tests for the physical contiguous memory region merging
functionality.

Signed-off-by: Longpeng(Mike) <longpeng2@huawei.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
\
 
 \ /
  Last update: 2021-09-21 17:11    [W:0.132 / U:3.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site