Commit b167259a authored by Maíra Canal's avatar Maíra Canal

drm/tests: Split drm_framebuffer_create_test into parameterized tests

The igt_check_drm_framebuffer_create is based on a loop that executes
tests for all createbuffer_tests test cases. This could be better
represented by parameterized tests, provided by KUnit.

So, convert the igt_check_drm_framebuffer_create into parameterized tests.
Signed-off-by: default avatarMaíra Canal <mairacanal@riseup.net>
Reviewed-by: default avatarMichał Winiarski <michal.winiarski@intel.com>
Reviewed-by: default avatarDavid Gow <davidgow@google.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220911191756.203118-1-mairacanal@riseup.net
parent 3f1a3a28
......@@ -25,7 +25,7 @@ struct drm_framebuffer_test {
const char *name;
};
static struct drm_framebuffer_test createbuffer_tests[] = {
static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = {
{ .buffer_created = 1, .name = "ABGR8888 normal sizes",
.cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_ABGR8888,
.handles = { 1, 0, 0 }, .pitches = { 4 * 600, 0, 0 },
......@@ -330,43 +330,50 @@ static struct drm_mode_config_funcs mock_config_funcs = {
.fb_create = fb_create_mock,
};
static struct drm_device mock_drm_device = {
.mode_config = {
.min_width = MIN_WIDTH,
.max_width = MAX_WIDTH,
.min_height = MIN_HEIGHT,
.max_height = MAX_HEIGHT,
.funcs = &mock_config_funcs,
},
};
static int drm_framebuffer_test_init(struct kunit *test)
{
struct drm_device *mock;
mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock);
static int execute_drm_mode_fb_cmd2(struct drm_mode_fb_cmd2 *r)
mock->mode_config.min_width = MIN_WIDTH;
mock->mode_config.max_width = MAX_WIDTH;
mock->mode_config.min_height = MIN_HEIGHT;
mock->mode_config.max_height = MAX_HEIGHT;
mock->mode_config.funcs = &mock_config_funcs;
test->priv = mock;
return 0;
}
static void drm_test_framebuffer_create(struct kunit *test)
{
const struct drm_framebuffer_test *params = test->param_value;
struct drm_device *mock = test->priv;
int buffer_created = 0;
mock_drm_device.dev_private = &buffer_created;
drm_internal_framebuffer_create(&mock_drm_device, r, NULL);
return buffer_created;
mock->dev_private = &buffer_created;
drm_internal_framebuffer_create(mock, &params->cmd, NULL);
KUNIT_EXPECT_EQ(test, params->buffer_created, buffer_created);
}
static void igt_check_drm_framebuffer_create(struct kunit *test)
static void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, char *desc)
{
int i = 0;
for (i = 0; i < ARRAY_SIZE(createbuffer_tests); i++) {
KUNIT_EXPECT_EQ_MSG(test, createbuffer_tests[i].buffer_created,
execute_drm_mode_fb_cmd2(&createbuffer_tests[i].cmd),
"Test %d: \"%s\" failed\n", i, createbuffer_tests[i].name);
}
strcpy(desc, t->name);
}
KUNIT_ARRAY_PARAM(drm_framebuffer_create, drm_framebuffer_create_cases,
drm_framebuffer_test_to_desc);
static struct kunit_case drm_framebuffer_tests[] = {
KUNIT_CASE(igt_check_drm_framebuffer_create),
KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params),
{ }
};
static struct kunit_suite drm_framebuffer_test_suite = {
.name = "drm_framebuffer",
.init = drm_framebuffer_test_init,
.test_cases = drm_framebuffer_tests,
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment