Messages in this thread | | | Date | Sun, 3 Oct 2021 17:14:24 +0300 | Subject | Re: [PATCH v2 4/4] nitro_enclaves: add kunit tests for physical contiguous region merging | From | "Paraschiv, Andra-Irina" <> |
| |
On 21/09/2021 18:10, Longpeng(Mike) wrote: > Add kunit tests for the physical contiguous memory region merging > functionality.
nitro_enclaves: Add KUnit tests for contiguous physical memory regions merging
Add KUnit tests for the contiguous physical memory regions merging functionality from the Nitro Enclaves misc device logic.
> > 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;
Please align the fields in the data structure so that's easier to visualize them.
u64 paddr; u64 size; int expect_rc; unsigned long expect_num; ............
> +} phys_regions_testcases[] = {
phys_regions_test_cases
> + {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},
Please add a comment before each of the above test cases, including a brief description of what each of them intends to test. So that it's easier to relate to the numbers.
> +}; > + > +static void ne_misc_test_set_phys_region(struct kunit *test)
ne_misc_dev_test_merge_phys_contig_memory_regions
> +{ > + struct phys_contig_mem_region *regions; > + size_t sz; > + int i, rc;
Please initialize the variables.
Thanks, Andra
> + > + 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), > {} > }; > >
Amazon Development Center (Romania) S.R.L. registered office: 27A Sf. Lazar Street, UBC5, floor 2, Iasi, Iasi County, 700045, Romania. Registered in Romania. Registration number J22/2621/2005.
| |