[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZyPNc0VhJUrTGZAq@Asurada-Nvidia>
Date: Thu, 31 Oct 2024 11:33:23 -0700
From: Nicolin Chen <nicolinc@...dia.com>
To: Jason Gunthorpe <jgg@...dia.com>
CC: <kevin.tian@...el.com>, <corbet@....net>, <joro@...tes.org>,
<suravee.suthikulpanit@....com>, <will@...nel.org>, <robin.murphy@....com>,
<dwmw2@...radead.org>, <shuah@...nel.org>, <iommu@...ts.linux.dev>,
<linux-doc@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-kselftest@...r.kernel.org>, <baolu.lu@...ux.intel.com>,
<eric.auger@...hat.com>, <jean-philippe@...aro.org>, <mdf@...nel.org>,
<mshavit@...gle.com>, <shameerali.kolothum.thodi@...wei.com>,
<smostafa@...gle.com>, <yi.l.liu@...el.com>, <aik@....com>,
<zhangfei.gao@...aro.org>, <patches@...ts.linux.dev>
Subject: Re: [PATCH v6 12/13] iommufd/selftest: Add IOMMU_VIOMMU_ALLOC test
coverage
On Thu, Oct 31, 2024 at 09:38:17AM -0700, Nicolin Chen wrote:
> On Thu, Oct 31, 2024 at 10:16:37AM -0300, Jason Gunthorpe wrote:
> > On Wed, Oct 30, 2024 at 02:34:38PM -0700, Nicolin Chen wrote:
> > > +FIXTURE_SETUP(iommufd_viommu)
...
> > > + EXPECT_ERRNO(EBUSY,
> > > + _test_ioctl_destroy(self->fd, self->hwpt_id));
> >
> > There shouldn't be testing in the FIXTURE_SETUP, it should just do
> > enough to setup the fixture. negative tests/etc should be in their own
> > function
>
> OK. I'll make a change by moving all EXPECT_ERRNOs to a TEST_F.
Will squash the followings into this patch in v7:
diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c
index 4fc5185fca0dc..bad11f65b63dd 100644
--- a/tools/testing/selftests/iommu/iommufd.c
+++ b/tools/testing/selftests/iommu/iommufd.c
@@ -2424,42 +2424,21 @@ FIXTURE_SETUP(iommufd_viommu)
test_cmd_mock_domain(self->ioas_id, &self->stdev_id, NULL,
&self->device_id);
- /* Negative test -- invalid hwpt */
- test_err_viommu_alloc(ENOENT, self->device_id, self->hwpt_id,
- IOMMU_VIOMMU_TYPE_SELFTEST, NULL);
-
- /* Negative test -- not a nesting parent hwpt */
- test_cmd_hwpt_alloc(self->device_id, self->ioas_id, 0,
- &self->hwpt_id);
- test_err_viommu_alloc(EINVAL, self->device_id, self->hwpt_id,
- IOMMU_VIOMMU_TYPE_SELFTEST, NULL);
- test_ioctl_destroy(self->hwpt_id);
-
/* Allocate a nesting parent hwpt */
test_cmd_hwpt_alloc(self->device_id, self->ioas_id,
IOMMU_HWPT_ALLOC_NEST_PARENT,
&self->hwpt_id);
- /* Negative test -- unsupported viommu type */
- test_err_viommu_alloc(EOPNOTSUPP, self->device_id,
- self->hwpt_id, 0xdead, NULL);
/* Allocate a vIOMMU taking refcount of the parent hwpt */
test_cmd_viommu_alloc(self->device_id, self->hwpt_id,
IOMMU_VIOMMU_TYPE_SELFTEST,
&self->viommu_id);
- EXPECT_ERRNO(EBUSY,
- _test_ioctl_destroy(self->fd, self->hwpt_id));
/* Allocate a regular nested hwpt */
test_cmd_hwpt_alloc_nested(self->device_id, self->viommu_id, 0,
&self->nested_hwpt_id,
IOMMU_HWPT_DATA_SELFTEST, &data,
sizeof(data));
- EXPECT_ERRNO(EBUSY,
- _test_ioctl_destroy(self->fd, self->viommu_id));
- } else {
- test_err_viommu_alloc(ENOENT, self->device_id, self->hwpt_id,
- IOMMU_VIOMMU_TYPE_SELFTEST, NULL);
}
}
@@ -2482,6 +2461,36 @@ TEST_F(iommufd_viommu, viommu_auto_destroy)
{
}
+TEST_F(iommufd_viommu, viommu_negative_tests)
+{
+ uint32_t device_id = self->device_id;
+ uint32_t ioas_id = self->ioas_id;
+ uint32_t hwpt_id;
+
+ if (self->device_id) {
+ /* Negative test -- invalid hwpt (hwpt_id=0) */
+ test_err_viommu_alloc(ENOENT, device_id, 0,
+ IOMMU_VIOMMU_TYPE_SELFTEST, NULL);
+
+ /* Negative test -- not a nesting parent hwpt */
+ test_cmd_hwpt_alloc(device_id, ioas_id, 0, &hwpt_id);
+ test_err_viommu_alloc(EINVAL, device_id, hwpt_id,
+ IOMMU_VIOMMU_TYPE_SELFTEST, NULL);
+ test_ioctl_destroy(hwpt_id);
+
+ /* Negative test -- unsupported viommu type */
+ test_err_viommu_alloc(EOPNOTSUPP, device_id, self->hwpt_id,
+ 0xdead, NULL);
+ EXPECT_ERRNO(EBUSY,
+ _test_ioctl_destroy(self->fd, self->hwpt_id));
+ EXPECT_ERRNO(EBUSY,
+ _test_ioctl_destroy(self->fd, self->viommu_id));
+ } else {
+ test_err_viommu_alloc(ENOENT, self->device_id, self->hwpt_id,
+ IOMMU_VIOMMU_TYPE_SELFTEST, NULL);
+ }
+}
+
TEST_F(iommufd_viommu, viommu_alloc_nested_iopf)
{
struct iommu_hwpt_selftest data = {
Powered by blists - more mailing lists