lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABVgOSn+03ACbVUQgRPZxLSB5ujU7qVCReP-UsGXrZC+i0C_UQ@mail.gmail.com>
Date:   Fri, 2 Sep 2022 15:52:11 +0800
From:   David Gow <davidgow@...gle.com>
To:     Maíra Canal <mairacanal@...eup.net>
Cc:     Isabella Basso <isabbasso@...eup.net>, magalilemes00@...il.com,
        Tales Aparecida <tales.aparecida@...il.com>, mwen@...lia.com,
        andrealmeid@...eup.net, siqueirajordao@...eup.net,
        Trevor Woerner <twoerner@...il.com>,
        Daniel Vetter <daniel@...ll.ch>,
        David Airlie <airlied@...ux.ie>,
        Javier Martinez Canillas <javierm@...hat.com>,
        Brendan Higgins <brendanhiggins@...gle.com>,
        Arthur Grillo <arthur.grillo@....br>,
        michal.winiarski@...el.com,
        José Expósito <jose.exposito89@...il.com>,
        Jani Nikula <jani.nikula@...ux.intel.com>,
        KUnit Development <kunit-dev@...glegroups.com>,
        dri-devel@...ts.freedesktop.org,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 1/2] drm/tests: Split drm_framebuffer_create_test into
 parameterized tests

On Thu, Sep 1, 2022 at 8:44 PM Maíra Canal <mairacanal@...eup.net> wrote:
>
> 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: Maíra Canal <mairacanal@...eup.net>
> Reviewed-by: Michał Winiarski <michal.winiarski@...el.com>
> ---
> v1 -> v2: https://lore.kernel.org/dri-devel/20220830211603.191734-1-mairacanal@riseup.net/
> - Use .init for mock_drm_device instead of a global variable. (Michał Winiarski)
> ---

This looks good to me, and worked well here.

Reviewed-by: David Gow <davidgow@...gle.com>

Cheers,
-- David

>  drivers/gpu/drm/tests/drm_framebuffer_test.c | 45 ++++++++++++--------
>  1 file changed, 27 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c
> index ec7a08ba4056..564794917784 100644
> --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
> +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
> @@ -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[] = {

FYI: It shouldn't be _necessary_ to namespace this, though I quite
like it personally. I definitely approve of the const, though.

>  { .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,52 @@ static struct drm_mode_config_funcs mock_config_funcs = {
>         .fb_create = fb_create_mock,
>  };
>
> -static struct drm_device mock_drm_device = {
> -       .mode_config = {
> +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);
> +
> +       mock->mode_config = (struct drm_mode_config) {
>                 .min_width = MIN_WIDTH,
>                 .max_width = MAX_WIDTH,
>                 .min_height = MIN_HEIGHT,
>                 .max_height = MAX_HEIGHT,
>                 .funcs = &mock_config_funcs,
> -       },
> -};
> +       };
>
> -static int execute_drm_mode_fb_cmd2(struct drm_mode_fb_cmd2 *r)
> +       test->priv = mock;
> +       return 0;
> +}
> +
> +static void test_drm_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(test_drm_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,
>  };
>
> --
> 2.37.2
>
> --
> You received this message because you are subscribed to the Google Groups "KUnit Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+unsubscribe@...glegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20220901124210.591994-1-mairacanal%40riseup.net.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ