Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp3588933rwn; Sat, 10 Sep 2022 15:33:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR524fqZv8i8C0u8gnW2QByS/TsSGnjakFV/T4RZxAO4cfa4peMh5A78qqijlGPokjYopXKP X-Received: by 2002:a50:9344:0:b0:448:ce76:7c81 with SMTP id n4-20020a509344000000b00448ce767c81mr16852269eda.187.1662849180442; Sat, 10 Sep 2022 15:33:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662849180; cv=none; d=google.com; s=arc-20160816; b=UqJsSU1FXKRCRh2PJK7p1+yE8D/vznucDqzITfWV01Ksf40RdHqDCJlJNxQ6gBkEhM BheZd/1FiesaO4E/MQV4lOsq4S5rnEQez3RuPmcltA17AZzAE6rzZfnC5Lm9Lf6nDlIH 4EPGLvwqnN/gB2WeUzryiZpzZbNTYnMVl99F5+/RRKh2jTB1VPQuSa3A3d1Bus193e3I fhSoQYtfh7jeaQw5mPXIdGmH2eBTNFrNTlQ2j7rWfVyuzfyIjKTuZkwEMXrJHHwW3cKg 9ALGP0cQGn8RC3PEJNLJn/A47tZeuO55UCMNK1kqleXOsyImEdOa4Z1FGEtm4hq/8NMq VwLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=xm4H0G7WwbrQViJEpMuOU+LpCfitC97maiV+CzNKPW4=; b=h8wbVtL8pe0YiEw8huRzapoaHMz4QYuEJHTRAvy2gSQA+D+7ieh2W/6C4EVq+H0KX2 o9gFC2Gz662uWv4G36mfZBNu4ddl2MgpW2Ybz2DCqJCgzh98lY1dFQ8sy125m6cegYyi BZG+fzcZPslTbxcft8QTu1V04noTkCiU/MX/95KmrJ1ObtyV8LRGlWX2o0RWXHY3v39O jAp6ZIRq2qNaW8gT+8ftVscFd8ZDBMw/oFKusoQFYiWvtw1D9g3LZ+Jay73omqr7Bh1B epgfLKa7KvFP6i16yPJpvN+Dm1GvyhYwE/hAewXXRDGWumhtazNmjXMW7grgky2Uw9Hk d7UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@riseup.net header.s=squak header.b=Zfa6QQtz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=riseup.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s25-20020a50d499000000b00450c05d181dsi4046282edi.193.2022.09.10.15.32.36; Sat, 10 Sep 2022 15:33:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@riseup.net header.s=squak header.b=Zfa6QQtz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=riseup.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbiIJVnt (ORCPT + 99 others); Sat, 10 Sep 2022 17:43:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbiIJVnU (ORCPT ); Sat, 10 Sep 2022 17:43:20 -0400 Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84B57DF55 for ; Sat, 10 Sep 2022 14:43:08 -0700 (PDT) Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx0.riseup.net (Postfix) with ESMTPS id 4MQ5vH288sz9s7P; Sat, 10 Sep 2022 21:43:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1662846187; bh=YZ1CV53MgNxyA+1WqttmM414irZhulFneEeEfgK0GIQ=; h=From:To:Cc:Subject:Date:From; b=Zfa6QQtz/nJrucmNJcVpJG4BGH/neZ9ti2BHM8Y4r//J02cbJ/mweZMxpVCN4mTgJ wSdGrzPKcJ/LOlMv+9gFY9vgE5YqQkICVHcsCQc3nwhOluFyVnd8L6ptcqwWrtc86x nCrvHy1abaVFlggKp3si2ZkqeBPROjlaFRkGStzw= X-Riseup-User-ID: 27751C35CCB32B8A0AEEC2461F645C9C9113993094DA06D6853DD8D97990F8ED Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4MQ5v63xHpz5vXJ; Sat, 10 Sep 2022 21:42:58 +0000 (UTC) From: =?UTF-8?q?Ma=C3=ADra=20Canal?= To: Isabella Basso , magalilemes00@gmail.com, tales.aparecida@gmail.com, mwen@igalia.com, andrealmeid@riseup.net, siqueirajordao@riseup.net, Trevor Woerner , Daniel Vetter , David Airlie , Javier Martinez Canillas , David Gow , brendanhiggins@google.com, Arthur Grillo , michal.winiarski@intel.com, =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , Jani Nikula , Maxime Ripard Cc: kunit-dev@googlegroups.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Ma=C3=ADra=20Canal?= Subject: [PATCH v4 1/2] drm/tests: Split drm_framebuffer_create_test into parameterized tests Date: Sat, 10 Sep 2022 18:42:38 -0300 Message-Id: <20220910214239.70432-1-mairacanal@riseup.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Michał Winiarski Reviewed-by: David Gow --- 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) - Add Michał's Reviewed-by tag. v2 -> v3: https://lore.kernel.org/dri-devel/20220901124210.591994-1-mairacanal@riseup.net/ - Add David's Reviewed-by tag. v3 -> v4: https://lore.kernel.org/dri-devel/20220907200247.89679-1-mairacanal@riseup.net/ - No changes. --- 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..6b6f6ff4f591 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[] = { { .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 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, ¶ms->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, }; -- 2.37.3