From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============2611074577278804306==" MIME-Version: 1.0 From: Jiang, Dave Subject: [Accel-config] Re: [PATCH v1 08/11] accel-config: Unit tests for mdev support Date: Sat, 05 Dec 2020 00:05:15 +0000 Message-ID: In-Reply-To: 20201202193057.299615-9-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============2611074577278804306== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: ramesh.thomas(a)intel.com > Sent: Wednesday, December 2, 2020 12:31 PM > To: accel-config(a)lists.01.org > Cc: Thomas, Ramesh ; Luck, Tony > ; Jiang, Dave > Subject: [PATCH v1 08/11] accel-config: Unit tests for mdev support > = > From: Ramesh Thomas > = > Tests for create/remove mdev 1swq amd 1dwq > = > Signed-off-by: Ramesh Thomas Reviewed-by: Dave Jiang > --- > test/libaccfg.c | 158 > +++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 157 insertions(+), 1 deletion(-) > = > diff --git a/test/libaccfg.c b/test/libaccfg.c > index 2494a44..b8f6522 100644 > --- a/test/libaccfg.c > +++ b/test/libaccfg.c > @@ -492,7 +492,6 @@ static int device_test_reset(struct accfg_ctx *ctx, > const char *dev_name) > = > if (wq_state =3D=3D ACCFG_WQ_DISABLED || > wq_state =3D=3D > ACCFG_WQ_QUIESCING) { > - fprintf(stderr, "%s is disabled already\n", > accfg_wq_get_devname(wq)); > continue; > } > = > @@ -762,6 +761,15 @@ static int wq_bounds_test(struct accfg_ctx *ctx, > const char *dev_name) > return rc; > } > = > + /* reset to valid values for following tests */ > + wq00_param.max_batch_size =3D 1; > + wq00_param.max_transfer_size =3D 1; > + rc =3D config_wq(ctx, 0, 0, wq00_param, dev_name); > + if (rc !=3D 0) { > + fprintf(stderr, "config wq wq0.0 failed\n"); > + return rc; > + } > + > return 0; > } > = > @@ -831,6 +839,144 @@ static int test_wq_boundary_conditions(struct > accfg_ctx *ctx) > return 0; > } > = > +static int mdev_test(struct accfg_ctx *ctx, const char *dev_name, > + char *mdev_type_str, int num_mdevs) > +{ > + struct accfg_device *device; > + enum accfg_mdev_type type; > + int rc, i; > + char **m; > + uuid_t uuid; > + > + device =3D accfg_ctx_device_get_by_name(ctx, dev_name); > + if (!device) { > + fprintf(stderr, "Device %s not found\n", dev_name); > + return -EINVAL; > + } > + > + for (m =3D accfg_mdev_basenames, type =3D 0; *m; m++, type++) > + if (!strcmp(*m, mdev_type_str)) > + break; > + > + if (!*m) { > + fprintf(stderr, "Invalid mdev type\n"); > + return -EINVAL; > + } > + > + for (i =3D 0; i < num_mdevs; i++) { > + rc =3D accfg_create_mdev(device, type, uuid); > + if (rc) { > + fprintf(stderr, "mdev creation failed\n"); > + return rc; > + } > + } > + > + /* Remove all mdevs */ > + uuid_clear(uuid); > + rc =3D accfg_remove_mdev(device, uuid); > + if (rc) { > + fprintf(stderr, "mdev removal failed\n"); > + return rc; > + } > + > + return rc; > +} > + > +static int enable_wq(struct accfg_ctx *ctx, const char *dev_name, int > wq_id) > +{ > + struct accfg_device *device; > + struct accfg_wq *wq; > + int rc; > + > + device =3D accfg_ctx_device_get_by_name(ctx, dev_name); > + if (!device) { > + fprintf(stderr, "Device %s not found\n", dev_name); > + return -EINVAL; > + } > + if (!accfg_device_is_active(device)) { > + rc =3D accfg_device_enable(device); > + if (rc < 0) { > + fprintf(stderr, "device enable of %s failed\n", > + dev_name); > + return rc; > + } > + } > + > + wq =3D accfg_device_wq_get_by_id(device, wq_id); > + if (!wq) { > + fprintf(stderr, "wq with id %d not found for device %s\n", > + wq_id, dev_name); > + return -EINVAL; > + } > + > + if (accfg_wq_get_state(wq) =3D=3D ACCFG_WQ_ENABLED) > + return 0; > + > + return accfg_wq_enable(wq); > +} > + > +/* test 1swq type mdev creation and removal */ > +static int test_mdev_1swq(struct accfg_ctx *ctx) > +{ > + int rc =3D 0; > + > + rc =3D device_test_reset(ctx, "dsa0"); > + if (rc) > + return rc; > + > + rc =3D set_config(ctx, "dsa0"); > + if (rc !=3D 0) > + return rc; > + > + rc =3D enable_wq(ctx, "dsa0", 2); > + if (rc) { > + fprintf(stderr, "enable wq wq0.2 failed"); > + return rc; > + } > + > + /* create and remove 5 1swq mdevs */ > + rc =3D mdev_test(ctx, "dsa0", "1swq", 5); > + if (rc) > + return rc; > + > + rc =3D device_test_reset(ctx, "dsa0"); > + if (rc) > + return rc; > + > + return 0; > +} > + > +/* test 1dwq type mdev creation and removal */ > +static int test_mdev_1dwq(struct accfg_ctx *ctx) > +{ > + int rc =3D 0; > + > + rc =3D device_test_reset(ctx, "dsa0"); > + if (rc) > + return rc; > + > + rc =3D set_config(ctx, "dsa0"); > + if (rc !=3D 0) > + return rc; > + > + rc =3D enable_wq(ctx, "dsa0", 3); > + if (rc) { > + fprintf(stderr, "enable wq wq0.3 failed"); > + return rc; > + } > + > + /* create and remove 1 1dwq mdev */ > + rc =3D mdev_test(ctx, "dsa0", "1dwq", 1); > + if (rc) > + return rc; > + > + rc =3D device_test_reset(ctx, "dsa0"); > + if (rc) > + return rc; > + > + return 0; > +} > + > typedef int (*do_test_fn)(struct accfg_ctx *ctx); > struct _test_case { > do_test_fn test_fn; > @@ -854,6 +1000,16 @@ static struct _test_case test_cases[] =3D { > .desc =3D "wq boundary conditions", > .enabled =3D true, > }, > + { > + .test_fn =3D test_mdev_1swq, > + .desc =3D "1swq type mdev creation and removal", > + .enabled =3D true, > + }, > + { > + .test_fn =3D test_mdev_1dwq, > + .desc =3D "1dwq type mdev creation and removal", > + .enabled =3D true, > + }, > }; > = > static int idxd_kmod_init(struct kmod_ctx **ctx, struct kmod_module > **mod, > -- > 2.26.2 --===============2611074577278804306==--