Re: [RFC v4 10/17] kunit: test: add test managed resource tests
Quoting Brendan Higgins (2019-02-14 13:37:22) > diff --git a/kunit/test-test.c b/kunit/test-test.c > index 0b4ad6690310d..bb34431398526 100644 > --- a/kunit/test-test.c > +++ b/kunit/test-test.c [...] > + > +#define KUNIT_RESOURCE_NUM 5 > +static void kunit_resource_test_cleanup_resources(struct kunit *test) > +{ > + int i; > + struct kunit_test_resource_context *ctx = test->priv; > + struct kunit_resource *resources[KUNIT_RESOURCE_NUM]; > + > + for (i = 0; i < KUNIT_RESOURCE_NUM; i++) { Nitpick: This could use ARRAY_SIZE(resources) and then the #define could be dropped. > + resources[i] = kunit_alloc_resource(&ctx->test, > + fake_resource_init, > + fake_resource_free, > + ctx); > + } > + > + kunit_cleanup(&ctx->test); > + > + KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources)); > +} > + [...] > + > +static struct kunit_case kunit_resource_test_cases[] = { Can these arrays be const? > + KUNIT_CASE(kunit_resource_test_init_resources), > + KUNIT_CASE(kunit_resource_test_alloc_resource), > + KUNIT_CASE(kunit_resource_test_free_resource), > + KUNIT_CASE(kunit_resource_test_cleanup_resources), > + {}, > +}; ___ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC v4 02/17] kunit: test: add test resource management API
Quoting Brendan Higgins (2019-02-14 13:37:14) > @@ -104,6 +167,7 @@ struct kunit { > const char *name; /* Read only after initialization! */ > spinlock_t lock; /* Gaurds all mutable test state. */ > bool success; /* Protected by lock. */ > + struct list_head resources; /* Protected by lock. */ > void (*vprintk)(const struct kunit *test, > const char *level, > struct va_format *vaf); > @@ -127,6 +191,51 @@ int kunit_run_tests(struct kunit_module *module); > } \ > late_initcall(module_kunit_init##module) > > +/** > + * kunit_alloc_resource() - Allocates a *test managed resource*. > + * @test: The test context object. > + * @init: a user supplied function to initialize the resource. > + * @free: a user supplied function to free the resource. > + * @context: for the user to pass in arbitrary data. Nitpick: "pass in arbitrary data to the init function"? Maybe that provides some more clarity. > + * > + * Allocates a *test managed resource*, a resource which will automatically > be > + * cleaned up at the end of a test case. See &struct kunit_resource for an > + * example. > + */ ___ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel