Content-Type: multipart/mixed; boundary="===============8026727891369159436==" MIME-Version: 1.0 From: Jiang, Dave Subject: [Accel-config] Re: [PATCH v1 07/11] accel-config: Improve management of test cases Date: Sat, 05 Dec 2020 00:03:41 +0000 Message-ID: In-Reply-To: 20201202193057.299615-8-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============8026727891369159436== 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 07/11] accel-config: Improve management of test cases > = > From: Ramesh Thomas Reviewed-by: Dave Jiang > = > Created structure to store test func and description. Array of this > structure will be used to print test case description and results. > This removes the need to name tests with serial numbers. Invidual > tests can be enabled/disabled by setting a flag. > = > Signed-off-by: Ramesh Thomas > --- > test/libaccfg.c | 66 ++++++++++++++++++++++++++++++------------------- > 1 file changed, 40 insertions(+), 26 deletions(-) > = > diff --git a/test/libaccfg.c b/test/libaccfg.c > index aef877a..2494a44 100644 > --- a/test/libaccfg.c > +++ b/test/libaccfg.c > @@ -766,7 +766,7 @@ static int wq_bounds_test(struct accfg_ctx *ctx, const > char *dev_name) > } > = > /* test the set and get libaccfg functions for all components in dsa0 */ > -static int do_test0(struct accfg_ctx *ctx) > +static int test_config(struct accfg_ctx *ctx) > { > int rc =3D 0; > = > @@ -781,22 +781,18 @@ static int do_test0(struct accfg_ctx *ctx) > = > /* get configuration to see if match */ > rc =3D check_config(ctx, "dsa0"); > - if (rc !=3D 0) { > - fprintf(stderr, "test 0: test the set and get libaccfg functions > for components failed\n"); > + if (rc !=3D 0) > return rc; > - } > = > rc =3D device_test_reset(ctx, "dsa0"); > if (rc !=3D 0) > return rc; > = > - fprintf(stderr, "test 0: test the set and get libaccfg functions for > components passed successfully\n"); > - > return 0; > } > = > /* set large wq to exceed max total size in dsa */ > -static int do_test1(struct accfg_ctx *ctx) > +static int test_max_wq_size(struct accfg_ctx *ctx) > { > int rc =3D 0; > = > @@ -805,21 +801,18 @@ static int do_test1(struct accfg_ctx *ctx) > return rc; > = > rc =3D set_exceed_config(ctx, "dsa1"); > - if (rc !=3D 0) { > - fprintf(stderr, "test 1: set large wq to exceed max total size in > dsa failed\n"); > + if (rc !=3D 0) > return rc; > - } > = > rc =3D device_test_reset(ctx, "dsa1"); > if (rc !=3D 0) > return rc; > = > - fprintf(stderr, "test 1: set large wq to exceed max total size in dsa > passed successfully\n"); > - return 0; > + return 0; > } > = > /* test the boundary conditions for wq max_batch_size and > max_transfer_size */ > -static int do_test2(struct accfg_ctx *ctx) > +static int test_wq_boundary_conditions(struct accfg_ctx *ctx) > { > int rc =3D 0; > = > @@ -828,24 +821,39 @@ static int do_test2(struct accfg_ctx *ctx) > return rc; > = > rc =3D wq_bounds_test(ctx, "dsa0"); > - if (rc !=3D 0) { > - fprintf(stderr, "test 2: wq boundary conditions test > failed\n"); > + if (rc !=3D 0) > return rc; > - } > = > rc =3D device_test_reset(ctx, "dsa0"); > if (rc !=3D 0) > return rc; > = > - fprintf(stderr, "test 2: wq boundary conditions test passed > successfully\n"); > - return 0; > + return 0; > } > = > typedef int (*do_test_fn)(struct accfg_ctx *ctx); > -static do_test_fn do_test[] =3D { > - do_test0, > - do_test1, > - do_test2, > +struct _test_case { > + do_test_fn test_fn; > + char *desc; > + bool enabled; > +}; > + > +static struct _test_case test_cases[] =3D { > + { > + .test_fn =3D test_config, > + .desc =3D "set and get configurations", > + .enabled =3D true, > + }, > + { > + .test_fn =3D test_max_wq_size, > + .desc =3D "max wq size", > + .enabled =3D true, > + }, > + { > + .test_fn =3D test_wq_boundary_conditions, > + .desc =3D "wq boundary conditions", > + .enabled =3D true, > + }, > }; > = > static int idxd_kmod_init(struct kmod_ctx **ctx, struct kmod_module > **mod, > @@ -914,15 +922,21 @@ int test_libaccfg(int loglevel, struct accfg_test *= test, > } > } > = > - for (i =3D 0; i < ARRAY_SIZE(do_test); i++) { > - err =3D do_test[i](ctx); > + for (i =3D 0; i < ARRAY_SIZE(test_cases); i++) { > + if (!test_cases[i].enabled) { > + fprintf(stderr, "\naccfg-test%d *disabled*\n", i); > + continue; > + } > + printf("\nRunning accfg-test%d: %s\n", i, test_cases[i].desc); > + err =3D test_cases[i].test_fn(ctx); > if (err < 0) { > - fprintf(stderr, "accfg-test%d failed: %d\n", i, err); > + fprintf(stderr, "accfg-test%d *failed*: %d\n", i, err); > break; > } > + printf("accfg-test%d passed!\n", i); > } > = > - if (i >=3D ARRAY_SIZE(do_test)) > + if (i >=3D ARRAY_SIZE(test_cases)) > result =3D EXIT_SUCCESS; > = > kmod_module_remove_module(mod, 0); > -- > 2.26.2 --===============8026727891369159436==--