From patchwork Mon Jan 17 23:22:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 12715727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9071FC433EF for ; Mon, 17 Jan 2022 23:24:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8A7C311253E; Mon, 17 Jan 2022 23:24:14 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id F142D11253E for ; Mon, 17 Jan 2022 23:24:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642461853; x=1673997853; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=iUbQko9k7Ou5nk3pDqzZkkT1Itgenl5Tkzsne6VbKX4=; b=bae0gK7hSMA4kUEGmx3rFALkIudDUywdgliGtuMc4x1A8Du3uD8904wA sq91XgiesaBD/XsJ8TpS0QLeXZPW8K2UmKiR5lNFyPhK0yvoQZIfmyubG olpDLGPNzg/vZ83BFmuosHlrccFSpTqp4KZI3J4XDPp1hqd9w654UScAz ly+jW9A11/qitwsqoN2inZ+GlSdmHj0ZXjlmp7JXbZz7FEgi1rdeZdKzu hF8ht5WFP+r1Ta/aBVca29FafRA9sjv9LeTrLc4S00A9WjuBdiSQORnI6 x6wL+fi4zRvS+R2jUfXTlAODim6gMARTwaG2EfoL7U9pUtIz9hn4XITLp A==; X-IronPort-AV: E=McAfee;i="6200,9189,10230"; a="232063113" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="232063113" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 15:24:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="492487605" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by orsmga002.jf.intel.com with ESMTP; 17 Jan 2022 15:24:10 -0800 Received: from fmsmsx605.amr.corp.intel.com (10.18.126.85) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:10 -0800 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Mon, 17 Jan 2022 15:24:10 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.168) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:09 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nzfqnOm0OPLQRpUR/hpTZvLjCdt3oyIKCsEeBdRQYEXKT9Z1ylJ6nbpYwuZef3793TMTcpaZH8xjmI8dn52ytfpOOzmh+IK0LQtWuAZ6RJmhQAMx7Pg/0a4OIDm4NzDN6vpVfngFbZpR4/Y3RcVLKpLwvfPCW2B0eQtQRaFSlyp5ImngOwLkZ/81C3PGqcOxaQLTMjsgtck/nIRieXTV2tDJ/run8i7662DOslhB861x2g4drvkenSvv2oIaGhw6k10eFDqr9WIQB5Jbr0AZtmCgz1njt7E9J9xfc1IsrjxrEl80smJOCn6FdEvUeg9bl06t6K1ESbPYEjF6acB1MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8OsWuxDS+hItVI7fUSlP8MuloHfRQnuixvGZj/X7cbc=; b=GrQ4ioBRO7VIWdWdRXGyTO6i0eYMfh6YV2Axva16HTNLS5EbYJzsdOUEgVivymUy4ddTQ8AgjJYQJYMRELCMoRRAV5pIXGmLOI4751nO9mLoJuUKfZyxNGpglUzYBm2/ONW5CSSfybP1XGkjvPGYgiE7eAwXR5Jzi6lGdjjArJ3hwR5BUYQK05DaKnby09h0FbU3eRJRrZAx6qh1A7twfwfrxsPjjNpY3ZF41sKbUIimDJsq0i2j6qk09VeUMiXzBasWV54aBhhPhLZHI6zlxBuRAlkKiU/qlQth3DX7WtC7d4R9UBKrIZEUuA4H1KSwODVjWIzIf7RXJ8O/WZ4l/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by DM6PR11MB4140.namprd11.prod.outlook.com (2603:10b6:5:19f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Mon, 17 Jan 2022 23:24:05 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5%8]) with mapi id 15.20.4888.014; Mon, 17 Jan 2022 23:24:05 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , Subject: [RFC 01/10] drm: test-drm_cmdline_parser: Convert to KUnit Date: Tue, 18 Jan 2022 00:22:50 +0100 Message-ID: <20220117232259.180459-2-michal.winiarski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220117232259.180459-1-michal.winiarski@intel.com> References: <20220117232259.180459-1-michal.winiarski@intel.com> X-ClientProxiedBy: AS8PR04CA0008.eurprd04.prod.outlook.com (2603:10a6:20b:310::13) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 65f7d81c-1bc6-4b9e-25fe-08d9da1073e5 X-MS-TrafficTypeDiagnostic: DM6PR11MB4140:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2582; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HMjWSyNnENcWuopiEIm0EM0gwdwGXu2qIGHa6zIzFKXgst6SiYQfD6rvGlq5f9WpofTsTtYZE1BxfXcv1RbJxIAZ3oRJpL4vI7SLYg/YjpLPPIiIECXu6Tah+mQjR6oj8ff0gPW6vuHBX4gMnwqkr6/Hpi9XhDAYU3aS+IG+Xi/4LVNpr+cSWCDcCrVp4v2/AViTzOTfBgtZrqMLT4v1EMHsb2EVeivnadpGdChMc/3JQE3GjSFVvv5JlUOX96Eq7YqwV5XJHcsTxzWXqz6jn4sFciKzurrtlumB8Dff3uNuqJqYEPhk74kk0f87WOWbb64YdRH3tyYOOCnAf46EmFwIiEZjwOZ8cLWItbaQiE+LYOle3/NsauJRKQrJRAtJhy2EayRlRaSHWolIv0/RP/6CBmRd/Js92Io1d1X6HGqKK4UZsQ3EICFQfo8fUh/QbTF9NJqKqT444Znl3DLanY3pd18igEdGK3s48xboIz0ZAvLarAGHJ3GAXAUWN7IK0f6VFwAJEjdQJ8Zqfg2Vrinl3xNOvGJ04BNqasnaGNxOszOUqoIm/9ditjgH3uqe/+8P8MK/Q3QP8OH8nkfd4mCO8oqtxD+QtNm6IcT0P3+fex5vtSKpWgbD00s6fWBkwzuIVhaWRRChmQCNT/Q2vw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(508600001)(7416002)(186003)(6506007)(82960400001)(86362001)(8676002)(6512007)(6666004)(83380400001)(38100700002)(8936002)(66556008)(30864003)(54906003)(5660300002)(2906002)(6486002)(316002)(36756003)(2616005)(66946007)(26005)(1076003)(4326008)(66476007)(579004)(559001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?R3wRJU0mQDd72s4su0CLPp97Okit?= =?utf-8?q?vCzJM6D2JM5pXrMPFMem+VgXHE2Gmhkv+PhJa5T+9pY5GOEUTy4t+X96WPjjZXZcg?= =?utf-8?q?J/zGM3YE00tIpqNnUE1jPQGCkWMRRNtOcC122M8aMvZY/V20DciHoI7lgU6gwvLro?= =?utf-8?q?oEfSBknmBWMZyotlzxQf8Sc6tL4C2U2W9xsrh208eSwBHPQi8kjNj3mDQJoGmZ7XM?= =?utf-8?q?pjxlF1L5VhudrThNqR5YIHucaaf+fEG+NxLE0EyL5H0MBvOTf0yyY7sG/VtWQCYHj?= =?utf-8?q?1+CFl6Wml9fWGMmDAzCsjqUzeOJTIMvOzH/PvpfCpde0v1nxCBbVih6SGvNcj5tQg?= =?utf-8?q?Ql4WfpxvynOIXBy/n7oroX/UvGz9HsNdo7FWHbwdbfXRSDXkh3hbaZO0kNRhPsL+C?= =?utf-8?q?XdDN4AE8pGf2RepcELxYIVSOSpkun0+EZR3leoPl2xbVjwPTMM+m+BrWWOBoh/bji?= =?utf-8?q?lSsAsfzpNYB6y7WjRSIyFStmtuM8o7cQNijjWJF7bPilcHOBWA5nHaB6YW6VO06Aa?= =?utf-8?q?yqONQI0V0cYbHb8zUtvdLdnC5XwDnD5QaFd08sk1Zz+E5F2W0qKXgIxL3IJRhdqe1?= =?utf-8?q?erD85qAvtzMEIBq13AgSPOpCcqwAhvG8qEZ78BHyoF0zFhofQeJkNPeXajy4aVb0l?= =?utf-8?q?8TSsR7BtGGU0dd+7R1AfnXhhM+EEsxGKCYFcxPWsl6uCtPpu5MlvUnzY87fRSgOwd?= =?utf-8?q?v8Hi2s+ENafkcxAZUUQDyYGbPBWrRaMrybCwhV//1yjCO3hwILwCr1Q8Om1GKGpJC?= =?utf-8?q?/crxI7eIDnWPHGHz9JNUuCBRLqEe9yG5vp3KMMGuj3ng9npGtII3FeGMFbEQOggDK?= =?utf-8?q?mRLVVIsfeqQXJKKTqVHij9/4iKYLw07cd8R25T/Y1IOQu5MrN351LiqGcD/J+rSrJ?= =?utf-8?q?Rm25we7IezRngjddpSa6ovt65GAjigE8cIEhob9FFHjgpKh8PM5HGyucZ230I0Zb+?= =?utf-8?q?qpSiCvz2Z0LVuIBpdq7qCj137HAPJwG5toOTuYd/8gWbHSqpWWVI42QHGXr0dKliE?= =?utf-8?q?VSN0dSvw/DL+e9O4bH1hPHwBETEMR5O9zUYXCoxUAsPwmCW+J1UQVtgDmuI2Fs9s3?= =?utf-8?q?h9KjrACmuBjCaG7Afp2aRw59Hkneq8ZkdSAvs5qjJTfw8C4/C+HM7umgCDOktnlzw?= =?utf-8?q?hh+meeOFJ2n5eg72X03sun3F0TaEWghbc3+jOrVzQ5wLqfrpEpp+rj+hvo3xKXe54?= =?utf-8?q?ctNXW2DGa8TqCci84oLMJwdJh+NG7NrOcwII0O6SFYi8W7LUUms968A872JxCqMGe?= =?utf-8?q?QckPnQ+VXxvI3x/wCPBcRjQ8eAWGl7CGAThjDdGyVDVat5OAWUfDFsoR3P8Cq4Jkr?= =?utf-8?q?jem96ePmy6z8Fkxl0YIZyOqtPTWiUci3CG/8wdjB0Mmk1vsK5xvFCAzfWg8GFj5Cg?= =?utf-8?q?ICh90iEhJi+tCo8MhGSGicFThblukIwk/WLGxmJTH0oXgJM4eXT6BIRR/xcekgvpz?= =?utf-8?q?WUfzWSezWKnb64XngTZvNO/uTBkK7NFgKJ5Vd9NqKcSyiBDCI3JGMEo80rpAnk8HD?= =?utf-8?q?KluJOqD/UayhWMJDgXRrrKKTEcKKds+F4tlxwKKIxYMeGdHpYvgR5MY+lalRh4mRx?= =?utf-8?q?ZfVsCh71LdSnVby0JzIcig/ANn4hBZptQ=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 65f7d81c-1bc6-4b9e-25fe-08d9da1073e5 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2022 23:24:05.1802 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DTay2zN7gRuQpTq8XSC9hIlMB1WkFGhZlL+81Uf2oJtipGyUXY635L4OVq90VgWOhLwk/Ggf++6jbAXSMbTfcT1J3FoY+1gJko+vN/+wzEY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4140 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , Thomas Zimmermann , David Airlie , Brendan Higgins , Daniel Latypov , Arkadiusz Hiler , Petri Latvala Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" One-to-one conversion, no functional changes. Negative tests were merged into single parameterized test case. Signed-off-by: Michał Winiarski --- drivers/gpu/drm/Kconfig | 12 + drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/selftests/Makefile | 8 +- .../gpu/drm/selftests/drm_cmdline_selftests.h | 68 - .../drm/selftests/test-drm_cmdline_parser.c | 1680 ++++++++--------- 5 files changed, 802 insertions(+), 968 deletions(-) delete mode 100644 drivers/gpu/drm/selftests/drm_cmdline_selftests.h diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index b1f22e457fd0..21e329f32997 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -80,6 +80,18 @@ config DRM_DEBUG_SELFTEST If in doubt, say "N". +config DRM_KUNIT_TEST + bool "DRM tests" if !KUNIT_ALL_TESTS + depends on DRM=y && KUNIT=y + default KUNIT_ALL_TESTS + help + Enables unit tests for DRM. Only useful for kernel devs running KUnit. + + For more information on KUnit and unit tests in general please refer + to the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N. + config DRM_KMS_HELPER tristate depends on DRM diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 301a44dc18e3..550800e81836 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -65,7 +65,7 @@ drm_kms_helper-$(CONFIG_DRM_DP_AUX_CHARDEV) += drm_dp_aux_dev.o drm_kms_helper-$(CONFIG_DRM_DP_CEC) += drm_dp_cec.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o -obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/ +obj-y += selftests/ obj-$(CONFIG_DRM) += drm.o obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile index 0856e4b12f70..6411c9a957b3 100644 --- a/drivers/gpu/drm/selftests/Makefile +++ b/drivers/gpu/drm/selftests/Makefile @@ -1,7 +1,11 @@ # SPDX-License-Identifier: GPL-2.0-only -test-drm_modeset-y := test-drm_modeset_common.o test-drm_plane_helper.o \ +test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ + test-drm_modeset_common.o test-drm_plane_helper.o \ test-drm_format.o test-drm_framebuffer.o \ test-drm_damage_helper.o test-drm_dp_mst_helper.o \ test-drm_rect.o -obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o test-drm_cmdline_parser.o +obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o + +obj-$(CONFIG_DRM_KUNIT_TEST) := \ + test-drm_cmdline_parser.o diff --git a/drivers/gpu/drm/selftests/drm_cmdline_selftests.h b/drivers/gpu/drm/selftests/drm_cmdline_selftests.h deleted file mode 100644 index 29e367db6118..000000000000 --- a/drivers/gpu/drm/selftests/drm_cmdline_selftests.h +++ /dev/null @@ -1,68 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* List each unit test as selftest(function) - * - * The name is used as both an enum and expanded as igt__name to create - * a module parameter. It must be unique and legal for a C identifier. - * - * Tests are executed in order by igt/drm_mm - */ - -#define cmdline_test(test) selftest(test, test) - -cmdline_test(drm_cmdline_test_force_d_only) -cmdline_test(drm_cmdline_test_force_D_only_dvi) -cmdline_test(drm_cmdline_test_force_D_only_hdmi) -cmdline_test(drm_cmdline_test_force_D_only_not_digital) -cmdline_test(drm_cmdline_test_force_e_only) -cmdline_test(drm_cmdline_test_margin_only) -cmdline_test(drm_cmdline_test_interlace_only) -cmdline_test(drm_cmdline_test_res) -cmdline_test(drm_cmdline_test_res_missing_x) -cmdline_test(drm_cmdline_test_res_missing_y) -cmdline_test(drm_cmdline_test_res_bad_y) -cmdline_test(drm_cmdline_test_res_missing_y_bpp) -cmdline_test(drm_cmdline_test_res_vesa) -cmdline_test(drm_cmdline_test_res_vesa_rblank) -cmdline_test(drm_cmdline_test_res_rblank) -cmdline_test(drm_cmdline_test_res_bpp) -cmdline_test(drm_cmdline_test_res_bad_bpp) -cmdline_test(drm_cmdline_test_res_refresh) -cmdline_test(drm_cmdline_test_res_bad_refresh) -cmdline_test(drm_cmdline_test_res_bpp_refresh) -cmdline_test(drm_cmdline_test_res_bpp_refresh_interlaced) -cmdline_test(drm_cmdline_test_res_bpp_refresh_margins) -cmdline_test(drm_cmdline_test_res_bpp_refresh_force_off) -cmdline_test(drm_cmdline_test_res_bpp_refresh_force_on_off) -cmdline_test(drm_cmdline_test_res_bpp_refresh_force_on) -cmdline_test(drm_cmdline_test_res_bpp_refresh_force_on_analog) -cmdline_test(drm_cmdline_test_res_bpp_refresh_force_on_digital) -cmdline_test(drm_cmdline_test_res_bpp_refresh_interlaced_margins_force_on) -cmdline_test(drm_cmdline_test_res_margins_force_on) -cmdline_test(drm_cmdline_test_res_vesa_margins) -cmdline_test(drm_cmdline_test_res_invalid_mode) -cmdline_test(drm_cmdline_test_res_bpp_wrong_place_mode) -cmdline_test(drm_cmdline_test_name) -cmdline_test(drm_cmdline_test_name_bpp) -cmdline_test(drm_cmdline_test_name_refresh) -cmdline_test(drm_cmdline_test_name_bpp_refresh) -cmdline_test(drm_cmdline_test_name_refresh_wrong_mode) -cmdline_test(drm_cmdline_test_name_refresh_invalid_mode) -cmdline_test(drm_cmdline_test_name_option) -cmdline_test(drm_cmdline_test_name_bpp_option) -cmdline_test(drm_cmdline_test_rotate_0) -cmdline_test(drm_cmdline_test_rotate_90) -cmdline_test(drm_cmdline_test_rotate_180) -cmdline_test(drm_cmdline_test_rotate_270) -cmdline_test(drm_cmdline_test_rotate_multiple) -cmdline_test(drm_cmdline_test_rotate_invalid_val) -cmdline_test(drm_cmdline_test_rotate_truncated) -cmdline_test(drm_cmdline_test_hmirror) -cmdline_test(drm_cmdline_test_vmirror) -cmdline_test(drm_cmdline_test_margin_options) -cmdline_test(drm_cmdline_test_multiple_options) -cmdline_test(drm_cmdline_test_invalid_option) -cmdline_test(drm_cmdline_test_bpp_extra_and_option) -cmdline_test(drm_cmdline_test_extra_and_option) -cmdline_test(drm_cmdline_test_freestanding_options) -cmdline_test(drm_cmdline_test_freestanding_force_e_and_options) -cmdline_test(drm_cmdline_test_panel_orientation) diff --git a/drivers/gpu/drm/selftests/test-drm_cmdline_parser.c b/drivers/gpu/drm/selftests/test-drm_cmdline_parser.c index d96cd890def6..ffe5a483320a 100644 --- a/drivers/gpu/drm/selftests/test-drm_cmdline_parser.c +++ b/drivers/gpu/drm/selftests/test-drm_cmdline_parser.c @@ -3,1139 +3,1025 @@ * Copyright (c) 2019 Bootlin */ -#define pr_fmt(fmt) "drm_cmdline: " fmt - -#include -#include +#include #include #include -#define TESTS "drm_cmdline_selftests.h" -#include "drm_selftest.h" -#include "test-drm_modeset_common.h" - static const struct drm_connector no_connector = {}; -static int drm_cmdline_test_force_e_only(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("e", - &no_connector, - &mode)); - FAIL_ON(mode.specified); - FAIL_ON(mode.refresh_specified); - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_ON); - - return 0; -} - -static int drm_cmdline_test_force_D_only_not_digital(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("D", - &no_connector, - &mode)); - FAIL_ON(mode.specified); - FAIL_ON(mode.refresh_specified); - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_ON); - - return 0; -} - -static const struct drm_connector connector_hdmi = { - .connector_type = DRM_MODE_CONNECTOR_HDMIB, -}; - -static int drm_cmdline_test_force_D_only_hdmi(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("D", - &connector_hdmi, - &mode)); - FAIL_ON(mode.specified); - FAIL_ON(mode.refresh_specified); - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_ON_DIGITAL); - - return 0; -} - -static const struct drm_connector connector_dvi = { - .connector_type = DRM_MODE_CONNECTOR_DVII, -}; - -static int drm_cmdline_test_force_D_only_dvi(void *ignored) +static void drm_cmdline_test_force_e_only(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("D", - &connector_dvi, - &mode)); - FAIL_ON(mode.specified); - FAIL_ON(mode.refresh_specified); - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_ON_DIGITAL); - - return 0; -} - -static int drm_cmdline_test_force_d_only(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("d", - &no_connector, - &mode)); - FAIL_ON(mode.specified); - FAIL_ON(mode.refresh_specified); - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_OFF); - - return 0; + const char *cmdline = "e"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_FALSE(test, mode.specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON); } -static int drm_cmdline_test_margin_only(void *ignored) +static void drm_cmdline_test_force_D_only_not_digital(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(drm_mode_parse_command_line_for_connector("m", - &no_connector, - &mode)); - - return 0; -} - -static int drm_cmdline_test_interlace_only(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - - FAIL_ON(drm_mode_parse_command_line_for_connector("i", - &no_connector, - &mode)); - - return 0; -} - -static int drm_cmdline_test_res(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(mode.refresh_specified); - - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); - - return 0; + const char *cmdline = "D"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_FALSE(test, mode.specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON); } -static int drm_cmdline_test_res_missing_x(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - FAIL_ON(drm_mode_parse_command_line_for_connector("x480", - &no_connector, - &mode)); - - return 0; -} - -static int drm_cmdline_test_res_missing_y(void *ignored) +static void drm_cmdline_test_force_D_only_hdmi(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(drm_mode_parse_command_line_for_connector("1024x", - &no_connector, - &mode)); - - return 0; + const struct drm_connector connector_hdmi = { + .connector_type = DRM_MODE_CONNECTOR_HDMIB, + }; + const char *cmdline = "D"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &connector_hdmi, + &mode)); + KUNIT_EXPECT_FALSE(test, mode.specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON_DIGITAL); } -static int drm_cmdline_test_res_bad_y(void *ignored) +static void drm_cmdline_test_force_D_only_dvi(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(drm_mode_parse_command_line_for_connector("1024xtest", - &no_connector, - &mode)); - - return 0; + const struct drm_connector connector_dvi = { + .connector_type = DRM_MODE_CONNECTOR_DVII, + }; + const char *cmdline = "D"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &connector_dvi, + &mode)); + KUNIT_EXPECT_FALSE(test, mode.specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON_DIGITAL); } -static int drm_cmdline_test_res_missing_y_bpp(void *ignored) +static void drm_cmdline_test_force_d_only(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(drm_mode_parse_command_line_for_connector("1024x-24", - &no_connector, - &mode)); - - return 0; + const char *cmdline = "d"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_FALSE(test, mode.specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_OFF); } -static int drm_cmdline_test_res_vesa(void *ignored) +static void drm_cmdline_test_res(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480"; - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480M", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); - FAIL_ON(mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(mode.bpp_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - FAIL_ON(mode.rb); - FAIL_ON(!mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); - - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_res_vesa_rblank(void *ignored) +static void drm_cmdline_test_res_vesa(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480M"; - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480MR", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(mode.refresh_specified); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); - FAIL_ON(mode.bpp_specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(!mode.rb); - FAIL_ON(!mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_TRUE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_res_rblank(void *ignored) +static void drm_cmdline_test_res_vesa_rblank(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480MR"; - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480R", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); - FAIL_ON(mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(mode.bpp_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - FAIL_ON(!mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); - - return 0; + KUNIT_EXPECT_TRUE(test, mode.rb); + KUNIT_EXPECT_TRUE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_res_bpp(void *ignored) +static void drm_cmdline_test_res_rblank(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480R"; - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(mode.refresh_specified); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); - FAIL_ON(!mode.bpp_specified); - FAIL_ON(mode.bpp != 24); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - return 0; + KUNIT_EXPECT_TRUE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_res_bad_bpp(void *ignored) +static void drm_cmdline_test_res_bpp(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480-24"; - FAIL_ON(drm_mode_parse_command_line_for_connector("720x480-test", - &no_connector, - &mode)); - - return 0; -} - -static int drm_cmdline_test_res_refresh(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480@60", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(!mode.refresh_specified); - FAIL_ON(mode.refresh != 60); - - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); - return 0; -} - -static int drm_cmdline_test_res_bad_refresh(void *ignored) -{ - struct drm_cmdline_mode mode = { }; + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(drm_mode_parse_command_line_for_connector("720x480@refresh", - &no_connector, - &mode)); + KUNIT_EXPECT_TRUE(test, mode.bpp_specified); + KUNIT_EXPECT_EQ(test, mode.bpp, 24); - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_res_bpp_refresh(void *ignored) +static void drm_cmdline_test_res_refresh(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480@60"; - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24@60", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); - FAIL_ON(!mode.refresh_specified); - FAIL_ON(mode.refresh != 60); + KUNIT_EXPECT_TRUE(test, mode.refresh_specified); + KUNIT_EXPECT_EQ(test, mode.refresh, 60); - FAIL_ON(!mode.bpp_specified); - FAIL_ON(mode.bpp != 24); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); - - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_res_bpp_refresh_interlaced(void *ignored) +static void drm_cmdline_test_res_bpp_refresh(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24@60i", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(!mode.refresh_specified); - FAIL_ON(mode.refresh != 60); - - FAIL_ON(!mode.bpp_specified); - FAIL_ON(mode.bpp != 24); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(!mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); - - return 0; + const char *cmdline = "720x480-24@60"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + + KUNIT_EXPECT_TRUE(test, mode.refresh_specified); + KUNIT_EXPECT_EQ(test, mode.refresh, 60); + + KUNIT_EXPECT_TRUE(test, mode.bpp_specified); + KUNIT_EXPECT_EQ(test, mode.bpp, 24); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_res_bpp_refresh_margins(void *ignored) +static void drm_cmdline_test_res_bpp_refresh_interlaced(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24@60m", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(!mode.refresh_specified); - FAIL_ON(mode.refresh != 60); - - FAIL_ON(!mode.bpp_specified); - FAIL_ON(mode.bpp != 24); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(!mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); - - return 0; + const char *cmdline = "720x480-24@60i"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + + KUNIT_EXPECT_TRUE(test, mode.refresh_specified); + KUNIT_EXPECT_EQ(test, mode.refresh, 60); + + KUNIT_EXPECT_TRUE(test, mode.bpp_specified); + KUNIT_EXPECT_EQ(test, mode.bpp, 24); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_TRUE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_res_bpp_refresh_force_off(void *ignored) +static void drm_cmdline_test_res_bpp_refresh_margins(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24@60d", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(!mode.refresh_specified); - FAIL_ON(mode.refresh != 60); - - FAIL_ON(!mode.bpp_specified); - FAIL_ON(mode.bpp != 24); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_OFF); - - return 0; + const char *cmdline = "720x480-24@60m"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + + KUNIT_EXPECT_TRUE(test, mode.refresh_specified); + KUNIT_EXPECT_EQ(test, mode.refresh, 60); + + KUNIT_EXPECT_TRUE(test, mode.bpp_specified); + KUNIT_EXPECT_EQ(test, mode.bpp, 24); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_TRUE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_res_bpp_refresh_force_on_off(void *ignored) +static void drm_cmdline_test_res_bpp_refresh_force_off(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(drm_mode_parse_command_line_for_connector("720x480-24@60de", - &no_connector, - &mode)); - - return 0; + const char *cmdline = "720x480-24@60d"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + + KUNIT_EXPECT_TRUE(test, mode.refresh_specified); + KUNIT_EXPECT_EQ(test, mode.refresh, 60); + + KUNIT_EXPECT_TRUE(test, mode.bpp_specified); + KUNIT_EXPECT_EQ(test, mode.bpp, 24); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_OFF); } -static int drm_cmdline_test_res_bpp_refresh_force_on(void *ignored) +static void drm_cmdline_test_res_bpp_refresh_force_on(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24@60e", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(!mode.refresh_specified); - FAIL_ON(mode.refresh != 60); - - FAIL_ON(!mode.bpp_specified); - FAIL_ON(mode.bpp != 24); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_ON); - - return 0; + const char *cmdline = "720x480-24@60e"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + + KUNIT_EXPECT_TRUE(test, mode.refresh_specified); + KUNIT_EXPECT_EQ(test, mode.refresh, 60); + + KUNIT_EXPECT_TRUE(test, mode.bpp_specified); + KUNIT_EXPECT_EQ(test, mode.bpp, 24); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON); } -static int drm_cmdline_test_res_bpp_refresh_force_on_analog(void *ignored) +static void drm_cmdline_test_res_bpp_refresh_force_on_analog(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24@60D", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(!mode.refresh_specified); - FAIL_ON(mode.refresh != 60); - - FAIL_ON(!mode.bpp_specified); - FAIL_ON(mode.bpp != 24); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_ON); - - return 0; + const char *cmdline = "720x480-24@60D"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + + KUNIT_EXPECT_TRUE(test, mode.refresh_specified); + KUNIT_EXPECT_EQ(test, mode.refresh, 60); + + KUNIT_EXPECT_TRUE(test, mode.bpp_specified); + KUNIT_EXPECT_EQ(test, mode.bpp, 24); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON); } -static int drm_cmdline_test_res_bpp_refresh_force_on_digital(void *ignored) +static void drm_cmdline_test_res_bpp_refresh_force_on_digital(struct kunit *test) { struct drm_cmdline_mode mode = { }; - static const struct drm_connector connector = { + const struct drm_connector connector = { .connector_type = DRM_MODE_CONNECTOR_DVII, }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24@60D", - &connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(!mode.refresh_specified); - FAIL_ON(mode.refresh != 60); - - FAIL_ON(!mode.bpp_specified); - FAIL_ON(mode.bpp != 24); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_ON_DIGITAL); - - return 0; + const char *cmdline = "720x480-24@60D"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + + KUNIT_EXPECT_TRUE(test, mode.refresh_specified); + KUNIT_EXPECT_EQ(test, mode.refresh, 60); + + KUNIT_EXPECT_TRUE(test, mode.bpp_specified); + KUNIT_EXPECT_EQ(test, mode.bpp, 24); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON_DIGITAL); } -static int drm_cmdline_test_res_bpp_refresh_interlaced_margins_force_on(void *ignored) +static void drm_cmdline_test_res_bpp_refresh_interlaced_margins_force_on(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24@60ime", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(!mode.refresh_specified); - FAIL_ON(mode.refresh != 60); - - FAIL_ON(!mode.bpp_specified); - FAIL_ON(mode.bpp != 24); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(!mode.interlace); - FAIL_ON(!mode.margins); - FAIL_ON(mode.force != DRM_FORCE_ON); - - return 0; + const char *cmdline = "720x480-24@60ime"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + + KUNIT_EXPECT_TRUE(test, mode.refresh_specified); + KUNIT_EXPECT_EQ(test, mode.refresh, 60); + + KUNIT_EXPECT_TRUE(test, mode.bpp_specified); + KUNIT_EXPECT_EQ(test, mode.bpp, 24); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_TRUE(test, mode.interlace); + KUNIT_EXPECT_TRUE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON); } -static int drm_cmdline_test_res_margins_force_on(void *ignored) +static void drm_cmdline_test_res_margins_force_on(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480me"; - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480me", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(mode.refresh_specified); - - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(!mode.margins); - FAIL_ON(mode.force != DRM_FORCE_ON); - - return 0; -} - -static int drm_cmdline_test_res_vesa_margins(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480Mm", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - - FAIL_ON(mode.refresh_specified); - - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(!mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(!mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); - return 0; -} - -static int drm_cmdline_test_res_invalid_mode(void *ignored) -{ - struct drm_cmdline_mode mode = { }; + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(drm_mode_parse_command_line_for_connector("720x480f", - &no_connector, - &mode)); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_TRUE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON); } -static int drm_cmdline_test_res_bpp_wrong_place_mode(void *ignored) +static void drm_cmdline_test_res_vesa_margins(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480Mm"; - FAIL_ON(drm_mode_parse_command_line_for_connector("720x480e-24", - &no_connector, - &mode)); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); - return 0; -} - -static int drm_cmdline_test_name(void *ignored) -{ - struct drm_cmdline_mode mode = { }; + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(!drm_mode_parse_command_line_for_connector("NTSC", - &no_connector, - &mode)); - FAIL_ON(strcmp(mode.name, "NTSC")); - FAIL_ON(mode.refresh_specified); - FAIL_ON(mode.bpp_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_TRUE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_TRUE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_name_bpp(void *ignored) +static void drm_cmdline_test_name(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("NTSC-24", - &no_connector, - &mode)); - FAIL_ON(strcmp(mode.name, "NTSC")); - - FAIL_ON(mode.refresh_specified); - - FAIL_ON(!mode.bpp_specified); - FAIL_ON(mode.bpp != 24); - - return 0; + const char *cmdline = "NTSC"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_STREQ(test, mode.name, "NTSC"); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); } -static int drm_cmdline_test_name_bpp_refresh(void *ignored) +static void drm_cmdline_test_name_bpp(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "NTSC-24"; - FAIL_ON(drm_mode_parse_command_line_for_connector("NTSC-24@60", - &no_connector, - &mode)); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_STREQ(test, mode.name, "NTSC"); - return 0; -} + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); -static int drm_cmdline_test_name_refresh(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - - FAIL_ON(drm_mode_parse_command_line_for_connector("NTSC@60", - &no_connector, - &mode)); - - return 0; + KUNIT_EXPECT_TRUE(test, mode.bpp_specified); + KUNIT_EXPECT_EQ(test, mode.bpp, 24); } -static int drm_cmdline_test_name_refresh_wrong_mode(void *ignored) +static void drm_cmdline_test_name_option(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(drm_mode_parse_command_line_for_connector("NTSC@60m", - &no_connector, - &mode)); - - return 0; + const char *cmdline = "NTSC,rotate=180"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_STREQ(test, mode.name, "NTSC"); + KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180); } -static int drm_cmdline_test_name_refresh_invalid_mode(void *ignored) +static void drm_cmdline_test_name_bpp_option(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(drm_mode_parse_command_line_for_connector("NTSC@60f", - &no_connector, - &mode)); - - return 0; + const char *cmdline = "NTSC-24,rotate=180"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_STREQ(test, mode.name, "NTSC"); + KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180); + KUNIT_EXPECT_TRUE(test, mode.bpp_specified); + KUNIT_EXPECT_EQ(test, mode.bpp, 24); } -static int drm_cmdline_test_name_option(void *ignored) +static void drm_cmdline_test_rotate_0(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480,rotate=0"; - FAIL_ON(!drm_mode_parse_command_line_for_connector("NTSC,rotate=180", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(strcmp(mode.name, "NTSC")); - FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_180); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_0); - return 0; -} - -static int drm_cmdline_test_name_bpp_option(void *ignored) -{ - struct drm_cmdline_mode mode = { }; + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(!drm_mode_parse_command_line_for_connector("NTSC-24,rotate=180", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(strcmp(mode.name, "NTSC")); - FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_180); - FAIL_ON(!mode.bpp_specified); - FAIL_ON(mode.bpp != 24); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_rotate_0(void *ignored) +static void drm_cmdline_test_rotate_90(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480,rotate=90"; - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480,rotate=0", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_0); - - FAIL_ON(mode.refresh_specified); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_90); - FAIL_ON(mode.bpp_specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_rotate_90(void *ignored) +static void drm_cmdline_test_rotate_180(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480,rotate=180"; - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480,rotate=90", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_90); - - FAIL_ON(mode.refresh_specified); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180); - FAIL_ON(mode.bpp_specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_rotate_180(void *ignored) +static void drm_cmdline_test_rotate_270(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480,rotate=270"; - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480,rotate=180", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_180); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_270); - FAIL_ON(mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(mode.bpp_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); - - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_rotate_270(void *ignored) +static void drm_cmdline_test_hmirror(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480,reflect_x"; - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480,rotate=270", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_270); - - FAIL_ON(mode.refresh_specified); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + KUNIT_EXPECT_EQ(test, mode.rotation_reflection, (DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_X)); - FAIL_ON(mode.bpp_specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_rotate_multiple(void *ignored) +static void drm_cmdline_test_vmirror(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480,reflect_y"; - FAIL_ON(drm_mode_parse_command_line_for_connector("720x480,rotate=0,rotate=90", - &no_connector, - &mode)); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + KUNIT_EXPECT_EQ(test, mode.rotation_reflection, (DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_Y)); - return 0; -} + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); -static int drm_cmdline_test_rotate_invalid_val(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - - FAIL_ON(drm_mode_parse_command_line_for_connector("720x480,rotate=42", - &no_connector, - &mode)); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_rotate_truncated(void *ignored) +static void drm_cmdline_test_margin_options(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(drm_mode_parse_command_line_for_connector("720x480,rotate=", - &no_connector, - &mode)); - - return 0; + const char *cmdline = + "720x480,margin_right=14,margin_left=24,margin_bottom=36,margin_top=42"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + KUNIT_EXPECT_EQ(test, mode.tv_margins.right, 14); + KUNIT_EXPECT_EQ(test, mode.tv_margins.left, 24); + KUNIT_EXPECT_EQ(test, mode.tv_margins.bottom, 36); + KUNIT_EXPECT_EQ(test, mode.tv_margins.top, 42); + + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); + + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_hmirror(void *ignored) +static void drm_cmdline_test_multiple_options(struct kunit *test) { struct drm_cmdline_mode mode = { }; + const char *cmdline = "720x480,rotate=270,reflect_x"; - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480,reflect_x", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - FAIL_ON(mode.rotation_reflection != (DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_X)); - - FAIL_ON(mode.refresh_specified); + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + KUNIT_EXPECT_EQ(test, mode.rotation_reflection, (DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X)); - FAIL_ON(mode.bpp_specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); - return 0; + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_vmirror(void *ignored) +static void drm_cmdline_test_bpp_extra_and_option(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480,reflect_y", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - FAIL_ON(mode.rotation_reflection != (DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_Y)); - - FAIL_ON(mode.refresh_specified); - - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); - - return 0; + const char *cmdline = "720x480-24e,rotate=180"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180); + + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); + + KUNIT_EXPECT_TRUE(test, mode.bpp_specified); + KUNIT_EXPECT_EQ(test, mode.bpp, 24); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON); } -static int drm_cmdline_test_margin_options(void *ignored) +static void drm_cmdline_test_extra_and_option(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480,margin_right=14,margin_left=24,margin_bottom=36,margin_top=42", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - FAIL_ON(mode.tv_margins.right != 14); - FAIL_ON(mode.tv_margins.left != 24); - FAIL_ON(mode.tv_margins.bottom != 36); - FAIL_ON(mode.tv_margins.top != 42); - - FAIL_ON(mode.refresh_specified); - - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); - - return 0; + const char *cmdline = "720x480e,rotate=180"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_TRUE(test, mode.specified); + KUNIT_EXPECT_EQ(test, mode.xres, 720); + KUNIT_EXPECT_EQ(test, mode.yres, 480); + KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180); + + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON); } -static int drm_cmdline_test_multiple_options(void *ignored) +static void drm_cmdline_test_freestanding_options(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480,rotate=270,reflect_x", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - FAIL_ON(mode.rotation_reflection != (DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X)); - - FAIL_ON(mode.refresh_specified); - - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); - - return 0; + const char *cmdline = "margin_right=14,margin_left=24,margin_bottom=36,margin_top=42"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_FALSE(test, mode.specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); + + KUNIT_EXPECT_EQ(test, mode.tv_margins.right, 14); + KUNIT_EXPECT_EQ(test, mode.tv_margins.left, 24); + KUNIT_EXPECT_EQ(test, mode.tv_margins.bottom, 36); + KUNIT_EXPECT_EQ(test, mode.tv_margins.top, 42); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_invalid_option(void *ignored) +static void drm_cmdline_test_freestanding_force_e_and_options(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(drm_mode_parse_command_line_for_connector("720x480,test=42", - &no_connector, - &mode)); - - return 0; + const char *cmdline = "e,margin_right=14,margin_left=24,margin_bottom=36,margin_top=42"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_FALSE(test, mode.specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); + + KUNIT_EXPECT_EQ(test, mode.tv_margins.right, 14); + KUNIT_EXPECT_EQ(test, mode.tv_margins.left, 24); + KUNIT_EXPECT_EQ(test, mode.tv_margins.bottom, 36); + KUNIT_EXPECT_EQ(test, mode.tv_margins.top, 42); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON); } -static int drm_cmdline_test_bpp_extra_and_option(void *ignored) +static void drm_cmdline_test_panel_orientation(struct kunit *test) { struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24e,rotate=180", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_180); - - FAIL_ON(mode.refresh_specified); - - FAIL_ON(!mode.bpp_specified); - FAIL_ON(mode.bpp != 24); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_ON); - - return 0; + const char *cmdline = "panel_orientation=upside_down"; + + KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline, + &no_connector, + &mode)); + KUNIT_EXPECT_FALSE(test, mode.specified); + KUNIT_EXPECT_FALSE(test, mode.refresh_specified); + KUNIT_EXPECT_FALSE(test, mode.bpp_specified); + + KUNIT_EXPECT_EQ(test, mode.panel_orientation, DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP); + + KUNIT_EXPECT_FALSE(test, mode.rb); + KUNIT_EXPECT_FALSE(test, mode.cvt); + KUNIT_EXPECT_FALSE(test, mode.interlace); + KUNIT_EXPECT_FALSE(test, mode.margins); + KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED); } -static int drm_cmdline_test_extra_and_option(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480e,rotate=180", - &no_connector, - &mode)); - FAIL_ON(!mode.specified); - FAIL_ON(mode.xres != 720); - FAIL_ON(mode.yres != 480); - FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_180); - - FAIL_ON(mode.refresh_specified); - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_ON); - - return 0; -} +struct drm_cmdline_negative_test { + const char *name; + const char *cmdline; +}; -static int drm_cmdline_test_freestanding_options(void *ignored) +static void drm_cmdline_test_negative(struct kunit *test) { + const struct drm_cmdline_negative_test *params = test->param_value; struct drm_cmdline_mode mode = { }; - FAIL_ON(!drm_mode_parse_command_line_for_connector("margin_right=14,margin_left=24,margin_bottom=36,margin_top=42", - &no_connector, - &mode)); - FAIL_ON(mode.specified); - FAIL_ON(mode.refresh_specified); - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.tv_margins.right != 14); - FAIL_ON(mode.tv_margins.left != 24); - FAIL_ON(mode.tv_margins.bottom != 36); - FAIL_ON(mode.tv_margins.top != 42); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); - - return 0; + KUNIT_EXPECT_FALSE(test, drm_mode_parse_command_line_for_connector(params->cmdline, + &no_connector, + &mode)); } -static int drm_cmdline_test_freestanding_force_e_and_options(void *ignored) -{ - struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("e,margin_right=14,margin_left=24,margin_bottom=36,margin_top=42", - &no_connector, - &mode)); - FAIL_ON(mode.specified); - FAIL_ON(mode.refresh_specified); - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.tv_margins.right != 14); - FAIL_ON(mode.tv_margins.left != 24); - FAIL_ON(mode.tv_margins.bottom != 36); - FAIL_ON(mode.tv_margins.top != 42); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_ON); - - return 0; -} +static const struct drm_cmdline_negative_test drm_cmdline_negative_tests[] = { + { + .name = "margin_only", + .cmdline = "m", + }, + { + .name = "interlace_only", + .cmdline = "i", + }, + { + .name = "res_missing_x", + .cmdline = "x480", + }, + { + .name = "res_missing_y", + .cmdline = "1024x", + }, + { + .name = "res_bad_y", + .cmdline = "1024xtest", + }, + { + .name = "res_missing_y_bpp", + .cmdline = "1024x-24", + }, + { + .name = "res_bad_bpp", + .cmdline = "720x480-test", + }, + { + .name = "res_bad_refresh", + .cmdline = "720x480@refresh", + }, + { + .name = "res_bpp_refresh_force_on_off", + .cmdline = "720x480-24@60de", + }, + { + .name = "res_invalid_mode", + .cmdline = "720x480f", + }, + { + .name = "res_bpp_wrong_place_mode", + .cmdline = "720x480e-24", + }, + { + .name = "name_bpp_refresh", + .cmdline = "NTSC-24@60", + }, + { + .name = "name_refresh", + .cmdline = "NTSC@60", + }, + { + .name = "name_refresh_wrong_mode", + .cmdline = "NTSC@60m", + }, + { + .name = "name_refresh_invalid_mode", + .cmdline = "NTSC@60f", + }, + { + .name = "rotate_multiple", + .cmdline = "720x480,rotate=0,rotate=90", + }, + { + .name = "rotate_invalid_val", + .cmdline = "720x480,rotate=42", + }, + { + .name = "rotate_truncated", + .cmdline = "720x480,rotate=", + }, + { + .name = "invalid_option", + .cmdline = "720x480,test=42", + }, +}; -static int drm_cmdline_test_panel_orientation(void *ignored) +static void drm_cmdline_negative_desc(const struct drm_cmdline_negative_test *t, + char *desc) { - struct drm_cmdline_mode mode = { }; - - FAIL_ON(!drm_mode_parse_command_line_for_connector("panel_orientation=upside_down", - &no_connector, - &mode)); - FAIL_ON(mode.specified); - FAIL_ON(mode.refresh_specified); - FAIL_ON(mode.bpp_specified); - - FAIL_ON(mode.panel_orientation != DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP); - - FAIL_ON(mode.rb); - FAIL_ON(mode.cvt); - FAIL_ON(mode.interlace); - FAIL_ON(mode.margins); - FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED); - - return 0; + sprintf(desc, "%s", t->name); } -#include "drm_selftest.c" - -static int __init test_drm_cmdline_init(void) -{ - int err; +KUNIT_ARRAY_PARAM(drm_cmdline_negative, drm_cmdline_negative_tests, drm_cmdline_negative_desc); + +static struct kunit_case drm_cmdline_tests[] = { + KUNIT_CASE(drm_cmdline_test_force_d_only), + KUNIT_CASE(drm_cmdline_test_force_D_only_dvi), + KUNIT_CASE(drm_cmdline_test_force_D_only_hdmi), + KUNIT_CASE(drm_cmdline_test_force_D_only_not_digital), + KUNIT_CASE(drm_cmdline_test_force_e_only), + KUNIT_CASE(drm_cmdline_test_res), + KUNIT_CASE(drm_cmdline_test_res_vesa), + KUNIT_CASE(drm_cmdline_test_res_vesa_rblank), + KUNIT_CASE(drm_cmdline_test_res_rblank), + KUNIT_CASE(drm_cmdline_test_res_bpp), + KUNIT_CASE(drm_cmdline_test_res_refresh), + KUNIT_CASE(drm_cmdline_test_res_bpp_refresh), + KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_interlaced), + KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_margins), + KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_force_off), + KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_force_on), + KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_force_on_analog), + KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_force_on_digital), + KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_interlaced_margins_force_on), + KUNIT_CASE(drm_cmdline_test_res_margins_force_on), + KUNIT_CASE(drm_cmdline_test_res_vesa_margins), + KUNIT_CASE(drm_cmdline_test_name), + KUNIT_CASE(drm_cmdline_test_name_bpp), + KUNIT_CASE(drm_cmdline_test_name_option), + KUNIT_CASE(drm_cmdline_test_name_bpp_option), + KUNIT_CASE(drm_cmdline_test_rotate_0), + KUNIT_CASE(drm_cmdline_test_rotate_90), + KUNIT_CASE(drm_cmdline_test_rotate_180), + KUNIT_CASE(drm_cmdline_test_rotate_270), + KUNIT_CASE(drm_cmdline_test_hmirror), + KUNIT_CASE(drm_cmdline_test_vmirror), + KUNIT_CASE(drm_cmdline_test_margin_options), + KUNIT_CASE(drm_cmdline_test_multiple_options), + KUNIT_CASE(drm_cmdline_test_bpp_extra_and_option), + KUNIT_CASE(drm_cmdline_test_extra_and_option), + KUNIT_CASE(drm_cmdline_test_freestanding_options), + KUNIT_CASE(drm_cmdline_test_freestanding_force_e_and_options), + KUNIT_CASE(drm_cmdline_test_panel_orientation), + KUNIT_CASE_PARAM(drm_cmdline_test_negative, drm_cmdline_negative_gen_params), + {} +}; - err = run_selftests(selftests, ARRAY_SIZE(selftests), NULL); +static struct kunit_suite drm_cmdline_test_suite = { + .name = "drm_cmdline_tests", + .test_cases = drm_cmdline_tests, +}; - return err > 0 ? 0 : err; -} -module_init(test_drm_cmdline_init); +kunit_test_suite(drm_cmdline_test_suite); MODULE_AUTHOR("Maxime Ripard "); MODULE_LICENSE("GPL"); From patchwork Mon Jan 17 23:22:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 12715728 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5FC41C433EF for ; Mon, 17 Jan 2022 23:24:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 59CF3112540; Mon, 17 Jan 2022 23:24:19 +0000 (UTC) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id B482111253F for ; Mon, 17 Jan 2022 23:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642461857; x=1673997857; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=3hUWtiKXjg3cJE6CMKMTkwKwRYB2s1i3CV4QtKLxeyw=; b=Rv54X/cvosusqB7OftykPQn3PsYv5eMad9NOndyHmc8p0x88QJruEyPn iirWsHkY0N9599QRKyHeTH2naEWmmXFvUetILdaPUNeDxaMtBRF0LCH2I A26kNIk+a7nz43BW6rMDgO5DHREnXcyd4TdHMShmX1vARxLqNo9dpwcfP wgQw5c7PSxhTTjpP1Wieu2r84BoNm27Uf1iM2qIa9sML7XVdkTchX+Nag O64A54n0N12B0V6I44rw6t6GypFgAGz4joLjP/b/tmdX1MGwjJDpQiOqu W2MM1Gc2OPhRwMqdLBzvP2qGhbPxqv2iJg83mE4LRUKFq2SAXw8oIBtJG Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10230"; a="224683757" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="224683757" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 15:24:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="474580633" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orsmga003.jf.intel.com with ESMTP; 17 Jan 2022 15:24:16 -0800 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:16 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Mon, 17 Jan 2022 15:24:16 -0800 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.105) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:15 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T3vll1c83sRjeoBdhEWuvzGjYVWjYIgnS1g5PpALLCcWSlsmHouL14VDcqF7AhbYQA2tajPajzTC/cfrDYq+uUw8PIM0obA3ijUdOIl7i/VUXyfKNbrm3IaOKAahtKQCXEDA0yd5XGnF9RhJzcKKzgAzPp8l11B++pjSZab3zpDIjjVvTWlbYUyhBtfqGYj52/++7UQ94MZLw3HSr54OMRUun+Zwl7VtF1on2MmFT6dci5/lRC+MBTEBkw/DwwaqIecxB2u34WgmaqFjLe2oE1TSjq5j7x78tRGpV0gZVDkcr4PnEWhH9GuJ3yLg7RRLmfVT3QC7j8Jgx6SuK5V95g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ejnFkLnjeyaluKXsi+Sc4X3UbMwkT8iuOVvEia2FWvo=; b=RvW8NzDPSykHVjDhUcldnfYsxmwWaIVSqFjaCLpsS0RlolnM2bj4zOPOosZ96TLBC+OXMKR0CR+sbk0wWV4AEnFgHMNaNeNhxTeV5/GBJuDbQeQhNRuRyRKnJCX6gLvE3bQoqodYTDk+SnkpyPgbRFsyxOS0/BlKmmHAmRzUdvnsfs7pkQbwLjZzX1uDiD/EP4E8itMq5KsFw1q7Gs/LhZiSfOCIGvtH+CjaM4Vyp8ULPlTHO5lwDVOfhwRXAgLBhZfglujf1WTp14Uga12So2J+9FoFStZEAhikBuMF3XLinbucwongYmI/1GHodPb2TEbgtkDf8nPk52WxAXyHFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by DM6PR11MB4140.namprd11.prod.outlook.com (2603:10b6:5:19f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Mon, 17 Jan 2022 23:24:11 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5%8]) with mapi id 15.20.4888.014; Mon, 17 Jan 2022 23:24:11 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , Subject: [RFC 02/10] drm: test-drm_plane_helper: Convert to KUnit Date: Tue, 18 Jan 2022 00:22:51 +0100 Message-ID: <20220117232259.180459-3-michal.winiarski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220117232259.180459-1-michal.winiarski@intel.com> References: <20220117232259.180459-1-michal.winiarski@intel.com> X-ClientProxiedBy: AS9PR06CA0014.eurprd06.prod.outlook.com (2603:10a6:20b:462::8) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bb2fc346-6551-4805-3bfb-08d9da1077ca X-MS-TrafficTypeDiagnostic: DM6PR11MB4140:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eyEw58PhmdEnu4PRdmSwoiUtiiGNUOe5fBBjIodulWfISVWqvkCo6yzeaW07Q52BcMJgIFAbbBdfOVE8zadbDxuVQO6v1PpYlWA1ZujY9brvvSmOGEzd5vVGFLLDE8DqRRq1NkWdvCDG4YtZZv+PbjQYOSJ+62nyl7fq23Wvd+Yr1TWT+Ku90kdqlaTz/07HgFK2Bh2M38hO6oaay53JKSZAnX8pK+L5WmPt3sVp5u2vk9PZZiZs1QCFLUmncHFkwwzwxH5wlgjuYxngbBtNMwt43wuADtjOft+6409/AOWAEtQNfh0uKP4XGDVrjDPnenctLpHgOZHyipX0OkMu92uB6jsxdgv61YP/SxQK85HkDx9rqgcEkbjf3CVHPGr4RNa+RvmV2viOeEoNdBqxuYEWoNiTbm52bsV6BHl61iakU82JQ9A4HAgT+9+Q4xYdpHl6ZbJ2utbxqy0NBIl29URjZ34GnO7btAsT1RYNuqiUC8jz25+ByLjJTc2NC+9fgxgmSvuf83nZB4My9OX/jG3Jiag75xyfKiDlDHrI9uvpXwrBT0HYr1Uj0tc/qjhkpIO7sqwkarP0tDHE2+nb9jxFhYJOcyBBgbV7QAWePzShlEJe0RPB8XcmXDym0EyuX1Qa4gwyjRdF+DLGKwRzGQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(508600001)(7416002)(186003)(6506007)(82960400001)(86362001)(8676002)(6512007)(6666004)(83380400001)(38100700002)(8936002)(66556008)(30864003)(54906003)(5660300002)(2906002)(6486002)(316002)(36756003)(2616005)(66946007)(26005)(1076003)(4326008)(66476007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?74dxfr8ENZanjDAVbQ/a+AMqEuF1?= =?utf-8?q?Fe74hXekR3eqPqAqkdBRq6DqXoXNJ4+PMQLCrmRF6uomRQIvcboGiTMZLqJbe00Pr?= =?utf-8?q?/KlGjhL9bWvGF/VwHb2WJgRApXKhJaAOA09RPEBWkUPkk34NBaKSEnV/StPSflJEt?= =?utf-8?q?TA3DCkoYnXqkWtNVhDjcAVHcXUmyTgnSeftl4N22+RBSnucTSj6F3uBnCzWDSROIT?= =?utf-8?q?Hsty1Myhp+KL1eTlunj6xJ7TL4yONE+dXXlU1wqeK6SoM5b3yzedtX5JNzYjJFOc1?= =?utf-8?q?wPb/GB7IsyZLXcLJ05Fl/1lbiEGw8TWAQWaSSas7RCvKL2B2lZ2lhsMmk7ZWFZA4h?= =?utf-8?q?6WGQccePzqrsHvxRhXFSRP2I9YrXigsugzYuMjCvXICq3ApNriBzVB0GUywTGSb2F?= =?utf-8?q?xALQ/BbyUzU9tgXBex7HjsGMx/7m+Cr4fn250j2MX3e+TJ+KVUUT8qahBsO/Egwpr?= =?utf-8?q?tegcONyLYdIssEN+idZLGwzP4WKBvGDY92eO9vM0C3Sub4tG5r8Ve1qHMuw7x8+06?= =?utf-8?q?E+dKuO8JHnzIELO0smltOLz0RHfnLxPzQS/4djP3KY+AKpCX18eObAAJi4i+65PPL?= =?utf-8?q?+szh+ziCbjnBvnEpkks3FX5vI4XREf7TyLNQRg0WOxp0zFMUYtyA5LuKcC4Ii6cRU?= =?utf-8?q?aAnO2F+btFzr7F2H2zgEzSMCMvAu0wTSilhCRJfyuWOL+ItkVtSWn0lOceyzfcSWR?= =?utf-8?q?oMbhr+SFyJWc/S7o945Gnau3b6m01VgNoiYkSfLeEdrjEnn++lLSxHc8ey3UNgb5T?= =?utf-8?q?HPJl/1ROSieaxLkwcu8WKAohjaNCCdUooR3/qMQspp3UHvqOldaP+jZ/dtBgCEXr2?= =?utf-8?q?AD+gdkl785dbGVOEg59r3cWLttT7CV2DoVv6N/CJ0Mu7Y7ZQtkO5P3jPMESMNQGpl?= =?utf-8?q?bFpLs6Hbo4gn/lAsrB0R/ecLP9otMR8vyJkLg6uny1f+2+zn9d2ijFIosTUq+ThX1?= =?utf-8?q?Ip86Se5sIc37hTaCB1SQxwdaGtW1Lzwb9K5HpK7seLWTruvfLp4vI1g1kjA/w41RK?= =?utf-8?q?11d/MOJ2E+A+c8p9abSAi3axnAnzv7D8f7byCKcQ4Xg47sv36i2/NwU3hlDZCR+ch?= =?utf-8?q?rKCSgA4Fm8dJtVUBPI8tBP4JmB4Ce2ubA/g5NWCyp0OWi4X9roBaEBeB2kOOdcQYI?= =?utf-8?q?0scyCRfi8iEeIEcSOLdgfsEa39WI28JQbWzfVf9PUBUXSfZ3JVrVZgj52fr1Rj1UE?= =?utf-8?q?HFTo4ADNDeDIwCTeBlPLlwOqYCV13zF7VO/GMjsuC1nHN392vF7oM7Gr3Q/sHwKsi?= =?utf-8?q?EKWv+bD/5Gk5I1UiZtXKOaqsKn1w6agjtcJ56ctMTiP14AQ0ZJm7AoJG476FpGSYr?= =?utf-8?q?EpQJF+ArSQp+k3TJPAok0NZL4Uf+nNZmr/JUljViVxVpu1BoTPqgsZX/BRFj7uIqf?= =?utf-8?q?wW+zilJFhAcxh7yrygyH9Y/f1U3IVFfNXRoe4v/MR9vmElDM4XnuLaiWn6mftTQaB?= =?utf-8?q?HAlIgQT/Bz80BhgSHMeBYgOfcV+tUo5fDgpGp/FTyB60rALqxjXaiKE2k4q9QoRb1?= =?utf-8?q?6vw7w1bVzugAmmVC/jZaEywvHoCpNy9DdaHTOsprFVhBaMyiXiLSGUFKu1PC2njhT?= =?utf-8?q?VhZ96iORKZT2anIif/Srho+elCpRMfumg=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: bb2fc346-6551-4805-3bfb-08d9da1077ca X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2022 23:24:11.5741 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1nYBgYqBITnPlsBI8YPsfkye92+RW18dVR0ZhyTDA+TZmXA4lbU0g47/BXs8sLqihIkCL4QjvO1Ee15izePK8+QTzIom4smq8mjPHtiZPXs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4140 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , Thomas Zimmermann , David Airlie , Brendan Higgins , Daniel Latypov , Arkadiusz Hiler , Petri Latvala Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Tests were converted into parameterized test cases. Negative tests were separated. Mocking was moved to test->init(). No functional changes. Signed-off-by: Michał Winiarski --- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/selftests/Makefile | 4 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 1 - .../drm/selftests/test-drm_modeset_common.h | 1 - .../gpu/drm/selftests/test-drm_plane_helper.c | 483 +++++++++++------- 5 files changed, 289 insertions(+), 201 deletions(-) diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 21e329f32997..89be0df7b0e9 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -83,6 +83,7 @@ config DRM_DEBUG_SELFTEST config DRM_KUNIT_TEST bool "DRM tests" if !KUNIT_ALL_TESTS depends on DRM=y && KUNIT=y + select DRM_KMS_HELPER default KUNIT_ALL_TESTS help Enables unit tests for DRM. Only useful for kernel devs running KUnit. diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile index 6411c9a957b3..82e568665ace 100644 --- a/drivers/gpu/drm/selftests/Makefile +++ b/drivers/gpu/drm/selftests/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ - test-drm_modeset_common.o test-drm_plane_helper.o \ + test-drm_modeset_common.o \ test-drm_format.o test-drm_framebuffer.o \ test-drm_damage_helper.o test-drm_dp_mst_helper.o \ test-drm_rect.o @@ -8,4 +8,4 @@ test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ - test-drm_cmdline_parser.o + test-drm_cmdline_parser.o test-drm_plane_helper.o diff --git a/drivers/gpu/drm/selftests/drm_modeset_selftests.h b/drivers/gpu/drm/selftests/drm_modeset_selftests.h index 782e285ca383..19d1142725c6 100644 --- a/drivers/gpu/drm/selftests/drm_modeset_selftests.h +++ b/drivers/gpu/drm/selftests/drm_modeset_selftests.h @@ -10,7 +10,6 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped) selftest(drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) -selftest(check_plane_state, igt_check_plane_state) selftest(check_drm_format_block_width, igt_check_drm_format_block_width) selftest(check_drm_format_block_height, igt_check_drm_format_block_height) selftest(check_drm_format_min_pitch, igt_check_drm_format_min_pitch) diff --git a/drivers/gpu/drm/selftests/test-drm_modeset_common.h b/drivers/gpu/drm/selftests/test-drm_modeset_common.h index cfb51d8da2bc..8744fd840406 100644 --- a/drivers/gpu/drm/selftests/test-drm_modeset_common.h +++ b/drivers/gpu/drm/selftests/test-drm_modeset_common.h @@ -20,7 +20,6 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored); int igt_drm_rect_clip_scaled_not_clipped(void *ignored); int igt_drm_rect_clip_scaled_clipped(void *ignored); int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored); -int igt_check_plane_state(void *ignored); int igt_check_drm_format_block_width(void *ignored); int igt_check_drm_format_block_height(void *ignored); int igt_check_drm_format_min_pitch(void *ignored); diff --git a/drivers/gpu/drm/selftests/test-drm_plane_helper.c b/drivers/gpu/drm/selftests/test-drm_plane_helper.c index ceebeede55ea..f2c0cd37a949 100644 --- a/drivers/gpu/drm/selftests/test-drm_plane_helper.c +++ b/drivers/gpu/drm/selftests/test-drm_plane_helper.c @@ -3,221 +3,310 @@ * Test cases for the drm_plane_helper functions */ -#define pr_fmt(fmt) "drm_plane_helper: " fmt +#include #include #include #include -#include "test-drm_modeset_common.h" - -static void set_src(struct drm_plane_state *plane_state, - unsigned src_x, unsigned src_y, - unsigned src_w, unsigned src_h) +static void expect_src_eq(struct kunit *test, struct drm_plane_state *plane_state, + unsigned int src_x, unsigned int src_y, + unsigned int src_w, unsigned int src_h) { - plane_state->src_x = src_x; - plane_state->src_y = src_y; - plane_state->src_w = src_w; - plane_state->src_h = src_h; + KUNIT_EXPECT_GE_MSG(test, plane_state->src.x1, 0, + "src x coordinate %x should never be below 0, src: " DRM_RECT_FP_FMT, + plane_state->src.x1, DRM_RECT_FP_ARG(&plane_state->src)); + KUNIT_EXPECT_GE_MSG(test, plane_state->src.y1, 0, + "src y coordinate %x should never be below 0, src: " DRM_RECT_FP_FMT, + plane_state->src.y1, DRM_RECT_FP_ARG(&plane_state->src)); + + KUNIT_EXPECT_TRUE_MSG(test, + plane_state->src.x1 == src_x && + plane_state->src.y1 == src_y && + drm_rect_width(&plane_state->src) == src_w && + drm_rect_height(&plane_state->src) == src_h, + "src: " DRM_RECT_FP_FMT, DRM_RECT_FP_ARG(&plane_state->src)); } -static bool check_src_eq(struct drm_plane_state *plane_state, - unsigned src_x, unsigned src_y, - unsigned src_w, unsigned src_h) +static void expect_crtc_eq(struct kunit *test, struct drm_plane_state *plane_state, + int crtc_x, int crtc_y, + unsigned int crtc_w, unsigned int crtc_h) { - if (plane_state->src.x1 < 0) { - pr_err("src x coordinate %x should never be below 0.\n", plane_state->src.x1); - drm_rect_debug_print("src: ", &plane_state->src, true); - return false; - } - if (plane_state->src.y1 < 0) { - pr_err("src y coordinate %x should never be below 0.\n", plane_state->src.y1); - drm_rect_debug_print("src: ", &plane_state->src, true); - return false; - } - - if (plane_state->src.x1 != src_x || - plane_state->src.y1 != src_y || - drm_rect_width(&plane_state->src) != src_w || - drm_rect_height(&plane_state->src) != src_h) { - drm_rect_debug_print("src: ", &plane_state->src, true); - return false; - } - - return true; + KUNIT_EXPECT_TRUE_MSG(test, + plane_state->dst.x1 == crtc_x && + plane_state->dst.y1 == crtc_y && + drm_rect_width(&plane_state->dst) == crtc_w && + drm_rect_height(&plane_state->dst) == crtc_h, + "dst: " DRM_RECT_FMT, DRM_RECT_ARG(&plane_state->dst)); } -static void set_crtc(struct drm_plane_state *plane_state, - int crtc_x, int crtc_y, - unsigned crtc_w, unsigned crtc_h) +const struct drm_crtc_state crtc_state = { + .crtc = ZERO_SIZE_PTR, + .enable = true, + .active = true, + .mode = { + DRM_MODE("1024x768", 0, 65000, 1024, 1048, + 1184, 1344, 0, 768, 771, 777, 806, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) + }, +}; + +struct drm_check_plane_state_test { + const char *name; + const char *msg; + struct { + unsigned int x; + unsigned int y; + unsigned int w; + unsigned int h; + } src, src_expected; + struct { + int x; + int y; + unsigned int w; + unsigned int h; + } crtc, crtc_expected; + unsigned int rotation; + int min_scale; + int max_scale; + bool can_position; +}; + +static int drm_plane_helper_init(struct kunit *test) { - plane_state->crtc_x = crtc_x; - plane_state->crtc_y = crtc_y; - plane_state->crtc_w = crtc_w; - plane_state->crtc_h = crtc_h; + const struct drm_check_plane_state_test *params = test->param_value; + struct drm_plane *plane; + struct drm_framebuffer *fb; + struct drm_plane_state *mock; + + plane = kunit_kzalloc(test, sizeof(*plane), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, plane); + + fb = kunit_kzalloc(test, sizeof(*fb), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fb); + fb->width = 2048; + fb->height = 2048; + + mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); + mock->plane = plane; + mock->crtc = ZERO_SIZE_PTR; + mock->fb = fb; + mock->rotation = params->rotation; + mock->src_x = params->src.x; + mock->src_y = params->src.y; + mock->src_w = params->src.w; + mock->src_h = params->src.h; + mock->crtc_x = params->crtc.x; + mock->crtc_y = params->crtc.y; + mock->crtc_w = params->crtc.w; + mock->crtc_h = params->crtc.h; + + test->priv = mock; + + return 0; } -static bool check_crtc_eq(struct drm_plane_state *plane_state, - int crtc_x, int crtc_y, - unsigned crtc_w, unsigned crtc_h) +void drm_check_plane_state(struct kunit *test) { - if (plane_state->dst.x1 != crtc_x || - plane_state->dst.y1 != crtc_y || - drm_rect_width(&plane_state->dst) != crtc_w || - drm_rect_height(&plane_state->dst) != crtc_h) { - drm_rect_debug_print("dst: ", &plane_state->dst, false); - - return false; - } + const struct drm_check_plane_state_test *params = test->param_value; + struct drm_plane_state *plane_state = test->priv; - return true; + KUNIT_ASSERT_EQ_MSG(test, + drm_atomic_helper_check_plane_state(plane_state, &crtc_state, + params->min_scale, + params->max_scale, + params->can_position, false), + 0, params->msg); + KUNIT_EXPECT_TRUE(test, plane_state->visible); + expect_src_eq(test, plane_state, params->src_expected.x, params->src_expected.y, + params->src_expected.w, params->src_expected.h); + expect_crtc_eq(test, plane_state, params->crtc_expected.x, params->crtc_expected.y, + params->crtc_expected.w, params->crtc_expected.h); } -int igt_check_plane_state(void *ignored) +void drm_check_invalid_plane_state(struct kunit *test) { - int ret; - - const struct drm_crtc_state crtc_state = { - .crtc = ZERO_SIZE_PTR, - .enable = true, - .active = true, - .mode = { - DRM_MODE("1024x768", 0, 65000, 1024, 1048, - 1184, 1344, 0, 768, 771, 777, 806, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) - }, - }; - struct drm_plane plane = { - .dev = NULL - }; - struct drm_framebuffer fb = { - .width = 2048, - .height = 2048 - }; - struct drm_plane_state plane_state = { - .plane = &plane, - .crtc = ZERO_SIZE_PTR, - .fb = &fb, - .rotation = DRM_MODE_ROTATE_0 - }; - - /* Simple clipping, no scaling. */ - set_src(&plane_state, 0, 0, fb.width << 16, fb.height << 16); - set_crtc(&plane_state, 0, 0, fb.width, fb.height); - ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, - DRM_PLANE_HELPER_NO_SCALING, - DRM_PLANE_HELPER_NO_SCALING, - false, false); - FAIL(ret < 0, "Simple clipping check should pass\n"); - FAIL_ON(!plane_state.visible); - FAIL_ON(!check_src_eq(&plane_state, 0, 0, 1024 << 16, 768 << 16)); - FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768)); - - /* Rotated clipping + reflection, no scaling. */ - plane_state.rotation = DRM_MODE_ROTATE_90 | DRM_MODE_REFLECT_X; - ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, - DRM_PLANE_HELPER_NO_SCALING, - DRM_PLANE_HELPER_NO_SCALING, - false, false); - FAIL(ret < 0, "Rotated clipping check should pass\n"); - FAIL_ON(!plane_state.visible); - FAIL_ON(!check_src_eq(&plane_state, 0, 0, 768 << 16, 1024 << 16)); - FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768)); - plane_state.rotation = DRM_MODE_ROTATE_0; - - /* Check whether positioning works correctly. */ - set_src(&plane_state, 0, 0, 1023 << 16, 767 << 16); - set_crtc(&plane_state, 0, 0, 1023, 767); - ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, - DRM_PLANE_HELPER_NO_SCALING, - DRM_PLANE_HELPER_NO_SCALING, - false, false); - FAIL(!ret, "Should not be able to position on the crtc with can_position=false\n"); - - ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, - DRM_PLANE_HELPER_NO_SCALING, - DRM_PLANE_HELPER_NO_SCALING, - true, false); - FAIL(ret < 0, "Simple positioning should work\n"); - FAIL_ON(!plane_state.visible); - FAIL_ON(!check_src_eq(&plane_state, 0, 0, 1023 << 16, 767 << 16)); - FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1023, 767)); - - /* Simple scaling tests. */ - set_src(&plane_state, 0, 0, 512 << 16, 384 << 16); - set_crtc(&plane_state, 0, 0, 1024, 768); - ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, - 0x8001, - DRM_PLANE_HELPER_NO_SCALING, - false, false); - FAIL(!ret, "Upscaling out of range should fail.\n"); - ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, - 0x8000, - DRM_PLANE_HELPER_NO_SCALING, - false, false); - FAIL(ret < 0, "Upscaling exactly 2x should work\n"); - FAIL_ON(!plane_state.visible); - FAIL_ON(!check_src_eq(&plane_state, 0, 0, 512 << 16, 384 << 16)); - FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768)); - - set_src(&plane_state, 0, 0, 2048 << 16, 1536 << 16); - ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, - DRM_PLANE_HELPER_NO_SCALING, - 0x1ffff, false, false); - FAIL(!ret, "Downscaling out of range should fail.\n"); - ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, - DRM_PLANE_HELPER_NO_SCALING, - 0x20000, false, false); - FAIL(ret < 0, "Should succeed with exact scaling limit\n"); - FAIL_ON(!plane_state.visible); - FAIL_ON(!check_src_eq(&plane_state, 0, 0, 2048 << 16, 1536 << 16)); - FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768)); - - /* Testing rounding errors. */ - set_src(&plane_state, 0, 0, 0x40001, 0x40001); - set_crtc(&plane_state, 1022, 766, 4, 4); - ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, - DRM_PLANE_HELPER_NO_SCALING, - 0x10001, - true, false); - FAIL(ret < 0, "Should succeed by clipping to exact multiple"); - FAIL_ON(!plane_state.visible); - FAIL_ON(!check_src_eq(&plane_state, 0, 0, 2 << 16, 2 << 16)); - FAIL_ON(!check_crtc_eq(&plane_state, 1022, 766, 2, 2)); - - set_src(&plane_state, 0x20001, 0x20001, 0x4040001, 0x3040001); - set_crtc(&plane_state, -2, -2, 1028, 772); - ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, - DRM_PLANE_HELPER_NO_SCALING, - 0x10001, - false, false); - FAIL(ret < 0, "Should succeed by clipping to exact multiple"); - FAIL_ON(!plane_state.visible); - FAIL_ON(!check_src_eq(&plane_state, 0x40002, 0x40002, 1024 << 16, 768 << 16)); - FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768)); - - set_src(&plane_state, 0, 0, 0x3ffff, 0x3ffff); - set_crtc(&plane_state, 1022, 766, 4, 4); - ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, - 0xffff, - DRM_PLANE_HELPER_NO_SCALING, - true, false); - FAIL(ret < 0, "Should succeed by clipping to exact multiple"); - FAIL_ON(!plane_state.visible); - /* Should not be rounded to 0x20001, which would be upscaling. */ - FAIL_ON(!check_src_eq(&plane_state, 0, 0, 2 << 16, 2 << 16)); - FAIL_ON(!check_crtc_eq(&plane_state, 1022, 766, 2, 2)); - - set_src(&plane_state, 0x1ffff, 0x1ffff, 0x403ffff, 0x303ffff); - set_crtc(&plane_state, -2, -2, 1028, 772); - ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, - 0xffff, - DRM_PLANE_HELPER_NO_SCALING, - false, false); - FAIL(ret < 0, "Should succeed by clipping to exact multiple"); - FAIL_ON(!plane_state.visible); - FAIL_ON(!check_src_eq(&plane_state, 0x3fffe, 0x3fffe, 1024 << 16, 768 << 16)); - FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768)); + const struct drm_check_plane_state_test *params = test->param_value; + struct drm_plane_state *plane_state = test->priv; - return 0; + KUNIT_ASSERT_LT_MSG(test, + drm_atomic_helper_check_plane_state(plane_state, &crtc_state, + params->min_scale, + params->max_scale, + params->can_position, false), + 0, params->msg); +} + +static const struct drm_check_plane_state_test drm_check_plane_state_tests[] = { + { + .name = "clipping_simple", + .msg = "Simple clipping check should pass", + .src = { 0, 0, + 2048 << 16, + 2048 << 16 }, + .crtc = { 0, 0, 2048, 2048 }, + .rotation = DRM_MODE_ROTATE_0, + .min_scale = DRM_PLANE_HELPER_NO_SCALING, + .max_scale = DRM_PLANE_HELPER_NO_SCALING, + .can_position = false, + .src_expected = { 0, 0, 1024 << 16, 768 << 16 }, + .crtc_expected = { 0, 0, 1024, 768 }, + }, + { + .name = "clipping_rotate_reflect", + .msg = "Rotated clipping check should pass", + .src = { 0, 0, + 2048 << 16, + 2048 << 16 }, + .crtc = { 0, 0, 2048, 2048 }, + .rotation = DRM_MODE_ROTATE_90 | DRM_MODE_REFLECT_X, + .min_scale = DRM_PLANE_HELPER_NO_SCALING, + .max_scale = DRM_PLANE_HELPER_NO_SCALING, + .can_position = false, + .src_expected = { 0, 0, 768 << 16, 1024 << 16 }, + .crtc_expected = { 0, 0, 1024, 768 }, + }, + { + .name = "positioning_simple", + .msg = "Simple positioning should work", + .src = { 0, 0, 1023 << 16, 767 << 16 }, + .crtc = { 0, 0, 1023, 767 }, + .rotation = DRM_MODE_ROTATE_0, + .min_scale = DRM_PLANE_HELPER_NO_SCALING, + .max_scale = DRM_PLANE_HELPER_NO_SCALING, + .can_position = true, + .src_expected = { 0, 0, 1023 << 16, 767 << 16 }, + .crtc_expected = { 0, 0, 1023, 767 }, + }, + { + .name = "upscaling", + .msg = "Upscaling exactly 2x should work", + .src = { 0, 0, 512 << 16, 384 << 16 }, + .crtc = { 0, 0, 1024, 768 }, + .rotation = DRM_MODE_ROTATE_0, + .min_scale = 0x8000, + .max_scale = DRM_PLANE_HELPER_NO_SCALING, + .can_position = false, + .src_expected = { 0, 0, 512 << 16, 384 << 16 }, + .crtc_expected = { 0, 0, 1024, 768 }, + }, + { + .name = "downscaling", + .msg = "Should succeed with exact scaling limit", + .src = { 0, 0, 2048 << 16, 1536 << 16 }, + .crtc = { 0, 0, 1024, 768 }, + .rotation = DRM_MODE_ROTATE_0, + .min_scale = DRM_PLANE_HELPER_NO_SCALING, + .max_scale = 0x20000, + .can_position = false, + .src_expected = { 0, 0, 2048 << 16, 1536 << 16 }, + .crtc_expected = { 0, 0, 1024, 768 }, + }, + { + .name = "rounding1", + .msg = "Should succeed by clipping to exact multiple", + .src = { 0, 0, 0x40001, 0x40001 }, + .crtc = { 1022, 766, 4, 4 }, + .rotation = DRM_MODE_ROTATE_0, + .min_scale = DRM_PLANE_HELPER_NO_SCALING, + .max_scale = 0x10001, + .can_position = true, + .src_expected = { 0, 0, 2 << 16, 2 << 16 }, + .crtc_expected = { 1022, 766, 2, 2 }, + }, + { + .name = "rounding2", + .msg = "Should succeed by clipping to exact multiple", + .src = { 0x20001, 0x20001, 0x4040001, 0x3040001 }, + .crtc = { -2, -2, 1028, 772 }, + .rotation = DRM_MODE_ROTATE_0, + .min_scale = DRM_PLANE_HELPER_NO_SCALING, + .max_scale = 0x10001, + .can_position = false, + .src_expected = { 0x40002, 0x40002, 1024 << 16, 768 << 16 }, + .crtc_expected = { 0, 0, 1024, 768 }, + }, + { + .name = "rounding3", + .msg = "Should succeed by clipping to exact multiple", + .src = { 0, 0, 0x3ffff, 0x3ffff }, + .crtc = { 1022, 766, 4, 4 }, + .rotation = DRM_MODE_ROTATE_0, + .min_scale = 0xffff, + .max_scale = DRM_PLANE_HELPER_NO_SCALING, + .can_position = true, + /* Should not be rounded to 0x20001, which would be upscaling. */ + .src_expected = { 0, 0, 2 << 16, 2 << 16 }, + .crtc_expected = { 1022, 766, 2, 2 }, + }, + { + .name = "rounding4", + .msg = "Should succeed by clipping to exact multiple", + .src = { 0x1ffff, 0x1ffff, 0x403ffff, 0x303ffff }, + .crtc = { -2, -2, 1028, 772 }, + .rotation = DRM_MODE_ROTATE_0, + .min_scale = 0xffff, + .max_scale = DRM_PLANE_HELPER_NO_SCALING, + .can_position = false, + .src_expected = { 0x3fffe, 0x3fffe, 1024 << 16, 768 << 16 }, + .crtc_expected = { 0, 0, 1024, 768 }, + }, +}; + +static const struct drm_check_plane_state_test drm_check_invalid_plane_state_tests[] = { + { + .name = "positioning_invalid", + .msg = "Should not be able to position on the crtc with can_position=false", + .src = { 0, 0, 1023 << 16, 767 << 16 }, + .crtc = { 0, 0, 1023, 767 }, + .rotation = DRM_MODE_ROTATE_0, + .min_scale = DRM_PLANE_HELPER_NO_SCALING, + .max_scale = DRM_PLANE_HELPER_NO_SCALING, + .can_position = false, + }, + { + .name = "upscaling_invalid", + .msg = "Upscaling out of range should fail", + .src = { 0, 0, 512 << 16, 384 << 16 }, + .crtc = { 0, 0, 1024, 768 }, + .rotation = DRM_MODE_ROTATE_0, + .min_scale = 0x8001, + .max_scale = DRM_PLANE_HELPER_NO_SCALING, + .can_position = false, + }, + { + .name = "downscaling_invalid", + .msg = "Downscaling out of range should fail", + .src = { 0, 0, 2048 << 16, 1536 << 16 }, + .crtc = { 0, 0, 1024, 768 }, + .rotation = DRM_MODE_ROTATE_0, + .min_scale = DRM_PLANE_HELPER_NO_SCALING, + .max_scale = 0x1ffff, + .can_position = false, + }, +}; + +static void drm_check_plane_state_desc(const struct drm_check_plane_state_test *t, + char *desc) +{ + sprintf(desc, "%s", t->name); } + +KUNIT_ARRAY_PARAM(drm_check_plane_state, drm_check_plane_state_tests, drm_check_plane_state_desc); +KUNIT_ARRAY_PARAM(drm_check_invalid_plane_state, drm_check_invalid_plane_state_tests, + drm_check_plane_state_desc); + +static struct kunit_case drm_plane_helper_tests[] = { + KUNIT_CASE_PARAM(drm_check_plane_state, drm_check_plane_state_gen_params), + KUNIT_CASE_PARAM(drm_check_invalid_plane_state, drm_check_invalid_plane_state_gen_params), + {} +}; + +static struct kunit_suite drm_plane_helper_test_suite = { + .name = "drm_plane_helper_tests", + .init = drm_plane_helper_init, + .test_cases = drm_plane_helper_tests, +}; + +kunit_test_suite(drm_plane_helper_test_suite); From patchwork Mon Jan 17 23:22:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 12715729 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 590B3C433FE for ; Mon, 17 Jan 2022 23:24:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 233F7112543; Mon, 17 Jan 2022 23:24:24 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id A7C73112543 for ; Mon, 17 Jan 2022 23:24:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642461862; x=1673997862; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=swnG8/c7DsJ5oPG4e35lbHo5YFh8MnajcJlYvRMPnv8=; b=QV+VKvNjVtD6o5Pd1NEj/99ntGDbmjSDMIhEJ/16AymqwOs2VITImc+6 TPDrDBMMdI9nGbrDJhdh7pzeSp5weeI5roATopfTKHhn0UPm7SZVAGGTi Ewr+ZhetJNzCLXKc3BoSZy3z/iOessmdmzluCJU8M4mgokn0tcacZOmz/ heCWRtzU47Ob4VjvriuYFERR5nfb4BaOUCyvImjHY/lqZh1m7rLNesYNw fPdMR8DulW8Htxzk+CB0+Mh8ilddkYi0y+D7WnGboTww7Vj1XQwrvvXor ZUkZIg0OfOTM9rRTvXpHQSQt5ceLLIl+JV1YvgZ5IQdJVDj6g58kQ6QXa g==; X-IronPort-AV: E=McAfee;i="6200,9189,10230"; a="269082568" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="269082568" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 15:24:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="517554371" Received: from fmsmsx605.amr.corp.intel.com ([10.18.126.85]) by orsmga007.jf.intel.com with ESMTP; 17 Jan 2022 15:24:21 -0800 Received: from fmsmsx604.amr.corp.intel.com (10.18.126.84) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:21 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Mon, 17 Jan 2022 15:24:21 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.177) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:20 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FFrNGfu0Ak55TZwGFO2W89o0G4XRxXbUFeTtpiPPcAbW4/5n/XBuMbJ2jh53HlUbktpYSibr0+rXGNKXzRmmwCnRkZdN6CXyC5BzkZ6jGJ4aRJZ76q170wlo8ef4hDNTJVXsm8AX33aQNW5kKSuRkNpTa+Ny2x3VUZVxSC9DUcMD/GqzZP+Bl4ueLRsKbyRUtyE95fPEmg9yN82/241OQoa3bhVam7ZPoWlOfCmic/AKH4aHJEe0rofWN5ePzQku0mZ12j3z4qbhJXo9cJvklhCnYnsYXWq6ZempnreRGcoQhvs8DOytrtd0WGc5lUBMgRmGsMxXCH9c5zG9E/dU4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NHyPfEys4IQHHru+dAQdDzI2mIXlV376xQC14vdPoSk=; b=O6mwV5DlTzMNwJsefk3ZkWMoe0dN5bN1FgDQHsgV6nKPov3LvmyOrI5qzB1v5PG3j2AJJQ5c+m/m8h02OS7gFZFjcy8F1KC+AV5AnL3yEVLLBsITjiwJmZ/LDwNcvRVIqiJhr+C0fzQd7sl8/wOoe9y3hJssToYm4LuzK8VVMy1kDH1SGDBBaamP77nzeb0iLGRQfn3djVqqWwX7GCVXliCEWMGGNIQr/w2GHGDXSwU70NTbbK782OelF/85o9ciwjSjOBn4pndpNg+UEQiLuYb7Z6ZP4A94GEbbo4K9bPo0VhwKpTrd/7Cc1JZfXNnGhV0Qf+Dj1h6OqB+K5PoJ2Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by DM6PR11MB4140.namprd11.prod.outlook.com (2603:10b6:5:19f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Mon, 17 Jan 2022 23:24:17 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5%8]) with mapi id 15.20.4888.014; Mon, 17 Jan 2022 23:24:17 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , Subject: [RFC 03/10] drm: test-drm_format: Convert to KUnit Date: Tue, 18 Jan 2022 00:22:52 +0100 Message-ID: <20220117232259.180459-4-michal.winiarski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220117232259.180459-1-michal.winiarski@intel.com> References: <20220117232259.180459-1-michal.winiarski@intel.com> X-ClientProxiedBy: AS9PR06CA0003.eurprd06.prod.outlook.com (2603:10a6:20b:462::9) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7e99b73e-ca08-43ee-a9e3-08d9da107b3c X-MS-TrafficTypeDiagnostic: DM6PR11MB4140:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8ywP3NHXO5Qk9wFnAmhSuGl5sAbtFQGEHIqiT3tBRiGOI0gVeFJa2pK5w1Pwz/v4+TVVkRiy2z6y4pQDXL9SpewsVpCbLiM341zw++hD1NDmUUFo+vbVKAjxP2eBPHDieIPoXsJu+x69XJBcFRflaM7XyqCBHb/vJrJHlGoPIVcgTYjqBH7cMwhG6a2ciQbXTY6gY4OFYzix0l4/fpl8Cn682MI5eqs2DJA21m29QYxGj8r6xRgCmdW9DKbGD+BpZv7i3d5ISlGo7hdvDVO9mSslpVNJI6/OShuWzJ53d7yr6ervQjQXpwxXbiIlGjx+t2wurFNCHM9cHbSYlsVIYooMCYTxkuu1qm5EKBdnLw2nJpNX+0enEvOswuguFbPedVLTYiwJYOKAHvBX2oXYhZ7Vd2c3XyGflUmi0lCwFxVxTlfpwxZjNMsyaCqriIBpy6dQSwg9huzDadpTuH9G3Pztgi9HzrGoRgLOuxbU9b0xg2zaE53HgpVIDEikVfhLrJKSl8lGqDWZ/oDFjrj1LSSYgwYruqML+xedBQdjTM1ZDT6BZkHk+rvy7p9gb/cb9Vuso1g/ch8Q62lIppdove2UGssp4Gh9wzOp+RGw8VnkdwMAMF75/7QMJzN04NImVjFPfEmxXlxcgTeMNkBT/Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(508600001)(7416002)(186003)(6506007)(82960400001)(86362001)(8676002)(6512007)(6666004)(83380400001)(38100700002)(8936002)(66556008)(30864003)(54906003)(5660300002)(2906002)(6486002)(316002)(36756003)(2616005)(66946007)(26005)(1076003)(4326008)(66476007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?aOWLw6wZolEJ9dAEQtWyI0o0kJIn?= =?utf-8?q?i20lbLIiJASGu+jiq55EPlyooxhDAmiU5xw1oBU4Oz5nbIwwnkfrwGZal6DnwnvbE?= =?utf-8?q?OobxxYXWYyouS032an4AmBnXofF+bGhpeoQtOy7/gFPqLychGXV3igrKArN83hilN?= =?utf-8?q?G54o8y5fzmgz2oiKI6Bre8gzlojpWFZCOM4q+kK51KSl3HWu/LyttQYhOJnCnSMm7?= =?utf-8?q?Tfscz+z/QG7OCkmaQBBrJ8mnZiLwBeNkn1k5UXYwqxTIpKf79ysGtqOnW9D9C5zzO?= =?utf-8?q?aFBd6Uj6BdIT7nDRpJN1aRj6z7D5fF8yl9/eBQjxSy+sI/ah9EdJEJLRdiFQ1sLGS?= =?utf-8?q?vCPpISfxXQLj9Bmnb+fbK/VecOdYwGsHsOnrkUDTPi9/UBALg4YxTCIffcZ4SXCJX?= =?utf-8?q?3k/z4ZDYTkfUOUDMj3cawkWHkE4lQhPwi8C7ZEV2zLR6NFng6jrQhs3yFCaadVTyl?= =?utf-8?q?cbmjieb7XLyIyC4VbiPdmMzl5/nnLtUCHd+87dwm6QGU6Nv0C5/CkweQ5ZdNWVXgQ?= =?utf-8?q?5tWSk3RRs5N6dJrKYLLSZPCNw9pIe2SEkCRmqFGTho0rxKUkecKv6iThb/1iOX4l/?= =?utf-8?q?IlDNzeXCtMpzO8cXLXhGicUbAePE8p1oLENpDX4Na+WnXVvJQYml2te3c3CtAEpYC?= =?utf-8?q?0mN/qkkvsG9XFm24WOuSGKt1mOW0m8Owt7eI1Up5IYn2QMyZu81QPMDXkzErrwIlh?= =?utf-8?q?/EquVrWkY/U2hPCo6hU8bEtDNxEu4+kujXaAopQn0NFAKmxw5rmKPwUR+i3GdwQzP?= =?utf-8?q?RrHUcw+uHPLIiJwxeVLkF0wPmPY+Mp0Ssus2aKEnHj/cRyNsNW8o/gWqdaxmGXCin?= =?utf-8?q?nlf/5EyM8TA7lHYI/RdxEOxS62ho+ZRUcNMgraeNSlW6trQEDr1zAK3etY4kNrW4/?= =?utf-8?q?nuf8WYHWMhASeQ6qi59UGMGpT0l7zQ6juYxEOXy/Fo/jUd7hft9aE7PFXNdFb3MJW?= =?utf-8?q?kM4HyRanumQjjLW1bT0rnscPn4KwdL+Wp4/RoqPaFrzvn885Q7NQKZRKOEwy8bVht?= =?utf-8?q?jkjpPClnQIo3yZuc1BnQnSFcwhR2AUP6VYk2Qvb11dyIOwY5kHLXFNgwmwW754nTU?= =?utf-8?q?MHP7Cgg2PGjM8+BSgmTihgquEClDy1GpiwAqY9XbfTX2quqLdjC8GwkvPQ+lJala9?= =?utf-8?q?ZW/iTGC3pkPgFxcp+3qX+QrLGn/zPd6QoSq7ucollBF018vsKbssJKG+CfYkBGEgs?= =?utf-8?q?qJ25zeVVR/zFPqwx4O8VK6W8BGZf9HUysUiVKPyRfUvoDQjutG/M9FE7AzW8dydkG?= =?utf-8?q?safWHS9CGkEqlscnijnVpun7Pe2i2BMNUxGJt6/ZWu5NdFFNaTLjFiB7z6XmMlp3y?= =?utf-8?q?vzDq2iMLTTIBdD53ftOcKnaEO08bCeWBv/rfy3VoG25SU4gQADNvgUjoanNvvGxIH?= =?utf-8?q?IROAbDvgJtxP56XbduzTQmdqbgR1whhD8kgzALw94Ia29vz+b1q1JZxMYn5F+7u5C?= =?utf-8?q?pyNkd4O5HdZcTToHL/GqgUFPIZYbWoYuADHM5t2W6PbG7hgvZr5rSboWcK7rs4//9?= =?utf-8?q?olIiTdYklKg+RKly90ZKPk30ahBoU2krKNPczMaJOiZXKsq1UX0R2OoLDGzX+kxzb?= =?utf-8?q?2S0THncvIL2o4Ovf+T7e8bMBzra1QJDPw=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 7e99b73e-ca08-43ee-a9e3-08d9da107b3c X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2022 23:24:17.4509 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Mlu3DtV/Tu+n7zTZCxbthkfzgUqTYE359N2J2FBxTdGKamZ4CVVkfaWcao7OKNt2zhM+F41yvFd7BAxKM7Fv2dcb34BFSyn++bU2LswIZRg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4140 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , Thomas Zimmermann , David Airlie , Brendan Higgins , Daniel Latypov , Arkadiusz Hiler , Petri Latvala Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" One-to-one conversion, no functional changes. Signed-off-by: Michał Winiarski --- drivers/gpu/drm/selftests/Makefile | 5 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 3 - drivers/gpu/drm/selftests/test-drm_format.c | 538 ++++++++++-------- .../drm/selftests/test-drm_modeset_common.h | 3 - 4 files changed, 310 insertions(+), 239 deletions(-) diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile index 82e568665ace..76c127613d1a 100644 --- a/drivers/gpu/drm/selftests/Makefile +++ b/drivers/gpu/drm/selftests/Makefile @@ -1,11 +1,12 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ test-drm_modeset_common.o \ - test-drm_format.o test-drm_framebuffer.o \ + test-drm_framebuffer.o \ test-drm_damage_helper.o test-drm_dp_mst_helper.o \ test-drm_rect.o obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ - test-drm_cmdline_parser.o test-drm_plane_helper.o + test-drm_cmdline_parser.o test-drm_plane_helper.o \ + test-drm_format.o diff --git a/drivers/gpu/drm/selftests/drm_modeset_selftests.h b/drivers/gpu/drm/selftests/drm_modeset_selftests.h index 19d1142725c6..5f253d9e573c 100644 --- a/drivers/gpu/drm/selftests/drm_modeset_selftests.h +++ b/drivers/gpu/drm/selftests/drm_modeset_selftests.h @@ -10,9 +10,6 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped) selftest(drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) -selftest(check_drm_format_block_width, igt_check_drm_format_block_width) -selftest(check_drm_format_block_height, igt_check_drm_format_block_height) -selftest(check_drm_format_min_pitch, igt_check_drm_format_min_pitch) selftest(check_drm_framebuffer_create, igt_check_drm_framebuffer_create) selftest(damage_iter_no_damage, igt_damage_iter_no_damage) selftest(damage_iter_no_damage_fractional_src, igt_damage_iter_no_damage_fractional_src) diff --git a/drivers/gpu/drm/selftests/test-drm_format.c b/drivers/gpu/drm/selftests/test-drm_format.c index c5e212afa27a..2774990768a7 100644 --- a/drivers/gpu/drm/selftests/test-drm_format.c +++ b/drivers/gpu/drm/selftests/test-drm_format.c @@ -3,278 +3,354 @@ * Test cases for the drm_format functions */ -#define pr_fmt(fmt) "drm_format: " fmt - -#include -#include +#include #include -#include "test-drm_modeset_common.h" - -int igt_check_drm_format_block_width(void *ignored) +static void drm_format_block_width_invalid(struct kunit *test) { const struct drm_format_info *info = NULL; /* Test invalid arguments */ - FAIL_ON(drm_format_info_block_width(info, 0) != 0); - FAIL_ON(drm_format_info_block_width(info, -1) != 0); - FAIL_ON(drm_format_info_block_width(info, 1) != 0); - - /* Test 1 plane format */ - info = drm_format_info(DRM_FORMAT_XRGB4444); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_width(info, 0) != 1); - FAIL_ON(drm_format_info_block_width(info, 1) != 0); - FAIL_ON(drm_format_info_block_width(info, -1) != 0); - - /* Test 2 planes format */ - info = drm_format_info(DRM_FORMAT_NV12); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_width(info, 0) != 1); - FAIL_ON(drm_format_info_block_width(info, 1) != 1); - FAIL_ON(drm_format_info_block_width(info, 2) != 0); - FAIL_ON(drm_format_info_block_width(info, -1) != 0); - - /* Test 3 planes format */ - info = drm_format_info(DRM_FORMAT_YUV422); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_width(info, 0) != 1); - FAIL_ON(drm_format_info_block_width(info, 1) != 1); - FAIL_ON(drm_format_info_block_width(info, 2) != 1); - FAIL_ON(drm_format_info_block_width(info, 3) != 0); - FAIL_ON(drm_format_info_block_width(info, -1) != 0); - - /* Test a tiled format */ - info = drm_format_info(DRM_FORMAT_X0L0); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_width(info, 0) != 2); - FAIL_ON(drm_format_info_block_width(info, 1) != 0); - FAIL_ON(drm_format_info_block_width(info, -1) != 0); - - return 0; + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, -1), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 1), 0); +} + +static void drm_format_block_width_one_plane(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_XRGB4444); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 0), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 1), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, -1), 0); +} + +static void drm_format_block_width_two_plane(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_NV12); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 0), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 1), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 2), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, -1), 0); } -int igt_check_drm_format_block_height(void *ignored) +static void drm_format_block_width_three_plane(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_YUV422); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 0), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 1), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 2), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 3), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, -1), 0); +} + +static void drm_format_block_width_tiled(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_X0L0); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 0), 2); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, 1), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_block_width(info, -1), 0); +} + +static void drm_format_block_height_invalid(struct kunit *test) { const struct drm_format_info *info = NULL; - /* Test invalid arguments */ - FAIL_ON(drm_format_info_block_height(info, 0) != 0); - FAIL_ON(drm_format_info_block_height(info, -1) != 0); - FAIL_ON(drm_format_info_block_height(info, 1) != 0); - - /* Test 1 plane format */ - info = drm_format_info(DRM_FORMAT_XRGB4444); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_height(info, 0) != 1); - FAIL_ON(drm_format_info_block_height(info, 1) != 0); - FAIL_ON(drm_format_info_block_height(info, -1) != 0); - - /* Test 2 planes format */ - info = drm_format_info(DRM_FORMAT_NV12); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_height(info, 0) != 1); - FAIL_ON(drm_format_info_block_height(info, 1) != 1); - FAIL_ON(drm_format_info_block_height(info, 2) != 0); - FAIL_ON(drm_format_info_block_height(info, -1) != 0); - - /* Test 3 planes format */ - info = drm_format_info(DRM_FORMAT_YUV422); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_height(info, 0) != 1); - FAIL_ON(drm_format_info_block_height(info, 1) != 1); - FAIL_ON(drm_format_info_block_height(info, 2) != 1); - FAIL_ON(drm_format_info_block_height(info, 3) != 0); - FAIL_ON(drm_format_info_block_height(info, -1) != 0); - - /* Test a tiled format */ - info = drm_format_info(DRM_FORMAT_X0L0); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_height(info, 0) != 2); - FAIL_ON(drm_format_info_block_height(info, 1) != 0); - FAIL_ON(drm_format_info_block_height(info, -1) != 0); - - return 0; + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, -1), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 1), 0); } -int igt_check_drm_format_min_pitch(void *ignored) +static void drm_format_block_height_one_plane(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_XRGB4444); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 0), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 1), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, -1), 0); +} + +static void drm_format_block_height_two_plane(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_NV12); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 0), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 1), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 2), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, -1), 0); +} + +static void drm_format_block_height_three_plane(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_YUV422); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 0), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 1), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 2), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 3), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, -1), 0); +} + +static void drm_format_block_height_tiled(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_X0L0); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 0), 2); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, 1), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_block_height(info, -1), 0); +} + +static void drm_format_min_pitch_invalid(struct kunit *test) { const struct drm_format_info *info = NULL; - /* Test invalid arguments */ - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - - /* Test 1 plane 8 bits per pixel format */ - info = drm_format_info(DRM_FORMAT_RGB332); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 1); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 640); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 1024); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 1920); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 4096); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 671); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, -1, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 0), 0); +} + +static void drm_format_min_pitch_one_plane_8bpp(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_RGB332); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, -1, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 0), 0); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 2), 2); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 640), 640); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1024), 1024); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1920), 1920); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 4096), 4096); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 671), 671); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, UINT_MAX), (uint64_t)UINT_MAX); - FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)), (uint64_t)(UINT_MAX - 1)); +} - /* Test 1 plane 16 bits per pixel format */ - info = drm_format_info(DRM_FORMAT_XRGB4444); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 4); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 1280); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 2048); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 3840); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 8192); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 1342); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != +static void drm_format_min_pitch_one_plane_16bpp(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_XRGB4444); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, -1, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 0), 0); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1), 2); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 2), 4); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 640), 1280); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1024), 2048); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1920), 3840); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 4096), 8192); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 671), 1342); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, UINT_MAX), (uint64_t)UINT_MAX * 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)), (uint64_t)(UINT_MAX - 1) * 2); +} - /* Test 1 plane 24 bits per pixel format */ - info = drm_format_info(DRM_FORMAT_RGB888); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 3); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 6); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 1920); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 3072); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 5760); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 12288); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 2013); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != +static void drm_format_min_pitch_one_plane_24bpp(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_RGB888); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, -1, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 0), 0); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1), 3); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 2), 6); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 640), 1920); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1024), 3072); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1920), 5760); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 4096), 12288); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 671), 2013); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, UINT_MAX), (uint64_t)UINT_MAX * 3); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX - 1) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, UINT_MAX - 1), (uint64_t)(UINT_MAX - 1) * 3); +} - /* Test 1 plane 32 bits per pixel format */ - info = drm_format_info(DRM_FORMAT_ABGR8888); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 4); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 8); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 2560); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 4096); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 7680); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 16384); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 2684); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != +static void drm_format_min_pitch_one_plane_32bpp(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_ABGR8888); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, -1, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 0), 0); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1), 4); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 2), 8); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 640), 2560); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1024), 4096); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1920), 7680); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 4096), 16384); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 671), 2684); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, UINT_MAX), (uint64_t)UINT_MAX * 4); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX - 1) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, UINT_MAX - 1), (uint64_t)(UINT_MAX - 1) * 4); +} - /* Test 2 planes format */ - info = drm_format_info(DRM_FORMAT_NV12); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 2, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 1); - FAIL_ON(drm_format_info_min_pitch(info, 1, 1) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 1, 1) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 640); - FAIL_ON(drm_format_info_min_pitch(info, 1, 320) != 640); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 1024); - FAIL_ON(drm_format_info_min_pitch(info, 1, 512) != 1024); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 1920); - FAIL_ON(drm_format_info_min_pitch(info, 1, 960) != 1920); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 4096); - FAIL_ON(drm_format_info_min_pitch(info, 1, 2048) != 4096); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 671); - FAIL_ON(drm_format_info_min_pitch(info, 1, 336) != 672); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != +static void drm_format_min_pitch_two_plane(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_NV12); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, -1, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 2, 0), 0); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 1), 2); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 2), 2); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 1), 2); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 640), 640); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 320), 640); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1024), 1024); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 512), 1024); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1920), 1920); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 960), 1920); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 4096), 4096); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 2048), 4096); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 671), 671); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 336), 672); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, UINT_MAX), (uint64_t)UINT_MAX); - FAIL_ON(drm_format_info_min_pitch(info, 1, UINT_MAX / 2 + 1) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, UINT_MAX / 2 + 1), (uint64_t)UINT_MAX + 1); - FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)), (uint64_t)(UINT_MAX - 1)); - FAIL_ON(drm_format_info_min_pitch(info, 1, (UINT_MAX - 1) / 2) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, (UINT_MAX - 1) / 2), (uint64_t)(UINT_MAX - 1)); +} - /* Test 3 planes 8 bits per pixel format */ - info = drm_format_info(DRM_FORMAT_YUV422); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 2, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 3, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 1); - FAIL_ON(drm_format_info_min_pitch(info, 1, 1) != 1); - FAIL_ON(drm_format_info_min_pitch(info, 2, 1) != 1); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 1, 2) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 2, 2) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 640); - FAIL_ON(drm_format_info_min_pitch(info, 1, 320) != 320); - FAIL_ON(drm_format_info_min_pitch(info, 2, 320) != 320); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 1024); - FAIL_ON(drm_format_info_min_pitch(info, 1, 512) != 512); - FAIL_ON(drm_format_info_min_pitch(info, 2, 512) != 512); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 1920); - FAIL_ON(drm_format_info_min_pitch(info, 1, 960) != 960); - FAIL_ON(drm_format_info_min_pitch(info, 2, 960) != 960); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 4096); - FAIL_ON(drm_format_info_min_pitch(info, 1, 2048) != 2048); - FAIL_ON(drm_format_info_min_pitch(info, 2, 2048) != 2048); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 671); - FAIL_ON(drm_format_info_min_pitch(info, 1, 336) != 336); - FAIL_ON(drm_format_info_min_pitch(info, 2, 336) != 336); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != +static void drm_format_min_pitch_three_plane_8bpp(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_YUV422); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 2, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, -1, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 3, 0), 0); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 1), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 2, 1), 1); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 2), 2); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 2), 2); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 2, 2), 2); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 640), 640); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 320), 320); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 2, 320), 320); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1024), 1024); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 512), 512); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 2, 512), 512); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1920), 1920); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 960), 960); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 2, 960), 960); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 4096), 4096); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 2048), 2048); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 2, 2048), 2048); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 671), 671); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 336), 336); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 2, 336), 336); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, UINT_MAX), (uint64_t)UINT_MAX); - FAIL_ON(drm_format_info_min_pitch(info, 1, UINT_MAX / 2 + 1) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, UINT_MAX / 2 + 1), (uint64_t)UINT_MAX / 2 + 1); - FAIL_ON(drm_format_info_min_pitch(info, 2, UINT_MAX / 2 + 1) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 2, UINT_MAX / 2 + 1), (uint64_t)UINT_MAX / 2 + 1); - FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1) / 2) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, (UINT_MAX - 1) / 2), (uint64_t)(UINT_MAX - 1) / 2); - FAIL_ON(drm_format_info_min_pitch(info, 1, (UINT_MAX - 1) / 2) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, (UINT_MAX - 1) / 2), (uint64_t)(UINT_MAX - 1) / 2); - FAIL_ON(drm_format_info_min_pitch(info, 2, (UINT_MAX - 1) / 2) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 2, (UINT_MAX - 1) / 2), (uint64_t)(UINT_MAX - 1) / 2); +} - /* Test tiled format */ - info = drm_format_info(DRM_FORMAT_X0L2); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 4); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 1280); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 2048); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 3840); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 8192); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 1342); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != +static void drm_format_min_pitch_tiled(struct kunit *test) +{ + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_X0L2); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, info); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, -1, 0), 0); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, 0), 0); + + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1), 2); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 2), 4); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 640), 1280); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1024), 2048); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 1920), 3840); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 4096), 8192); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, 671), 1342); + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, UINT_MAX), (uint64_t)UINT_MAX * 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX - 1) != + KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, UINT_MAX - 1), (uint64_t)(UINT_MAX - 1) * 2); - - return 0; } + +static struct kunit_case drm_format_tests[] = { + KUNIT_CASE(drm_format_block_width_invalid), + KUNIT_CASE(drm_format_block_width_one_plane), + KUNIT_CASE(drm_format_block_width_two_plane), + KUNIT_CASE(drm_format_block_width_three_plane), + KUNIT_CASE(drm_format_block_width_tiled), + KUNIT_CASE(drm_format_block_height_invalid), + KUNIT_CASE(drm_format_block_height_one_plane), + KUNIT_CASE(drm_format_block_height_two_plane), + KUNIT_CASE(drm_format_block_height_three_plane), + KUNIT_CASE(drm_format_block_height_tiled), + KUNIT_CASE(drm_format_min_pitch_invalid), + KUNIT_CASE(drm_format_min_pitch_one_plane_8bpp), + KUNIT_CASE(drm_format_min_pitch_one_plane_16bpp), + KUNIT_CASE(drm_format_min_pitch_one_plane_24bpp), + KUNIT_CASE(drm_format_min_pitch_one_plane_32bpp), + KUNIT_CASE(drm_format_min_pitch_two_plane), + KUNIT_CASE(drm_format_min_pitch_three_plane_8bpp), + KUNIT_CASE(drm_format_min_pitch_tiled), + {} +}; + +static struct kunit_suite drm_format_test_suite = { + .name = "drm_format_tests", + .test_cases = drm_format_tests, +}; + +kunit_test_suite(drm_format_test_suite); diff --git a/drivers/gpu/drm/selftests/test-drm_modeset_common.h b/drivers/gpu/drm/selftests/test-drm_modeset_common.h index 8744fd840406..f6cfce2a5863 100644 --- a/drivers/gpu/drm/selftests/test-drm_modeset_common.h +++ b/drivers/gpu/drm/selftests/test-drm_modeset_common.h @@ -20,9 +20,6 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored); int igt_drm_rect_clip_scaled_not_clipped(void *ignored); int igt_drm_rect_clip_scaled_clipped(void *ignored); int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored); -int igt_check_drm_format_block_width(void *ignored); -int igt_check_drm_format_block_height(void *ignored); -int igt_check_drm_format_min_pitch(void *ignored); int igt_check_drm_framebuffer_create(void *ignored); int igt_damage_iter_no_damage(void *ignored); int igt_damage_iter_no_damage_fractional_src(void *ignored); From patchwork Mon Jan 17 23:22:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 12715730 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8FBA3C433FE for ; Mon, 17 Jan 2022 23:24:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 019E1112546; Mon, 17 Jan 2022 23:24:33 +0000 (UTC) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id E53CB112546 for ; Mon, 17 Jan 2022 23:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642461871; x=1673997871; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=6ro2lSA7hpfMrYO7xKE+6JLlzdljkSfgu8tKCG0dnro=; b=A4GR9rxxkMMJzHGqNG2bKgkrLVM9/zXkloUUUhzzWfhhk65uFvISbBBc rmWL3WJmyHRmVy3FWJdrECBJFQWKuz+RQrDFXNF7Gl+oJA6A2j8tiau6M hN0ZQm4sBjTkZwKt2EfNdFpASLoLdSr9p23iJR016B3+BY25UtSp6XsZI CQpacD+aw+yuKHcfItpG70M0uiQ91nd1gIpARV64SsRurG00XiTUhQNHq CK/CcZUtSeKk3GWLGgtx62DGkdjsMJS18mVd7hTnPeyXam2mH1UNmF8eT Xqhxs36js4cX0hP94s6kZBIWdkz+PQZkiXXmXCO2aD0lixnNNAAj6GBJr g==; X-IronPort-AV: E=McAfee;i="6200,9189,10230"; a="244901097" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="244901097" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 15:24:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="474580654" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orsmga003.jf.intel.com with ESMTP; 17 Jan 2022 15:24:31 -0800 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:30 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Mon, 17 Jan 2022 15:24:30 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.169) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:30 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a8yZPYS3WG7uNRk02IKjRfwdiS+ZWO6J1i9K7CeljYYlY1x3OsLFnl0+sodVkFCEm59F2vb2+FpjkO0qdMiZknlyJT2vC2GAqDzvAP7IQfrsAckhLAC9Nu2eVifRRngXzXxk+lRctYHbMGxCznL1cG8cJjiivG85wOoasIMR5yO4UXakMY/PRHA6gbn9FXc3Av7KHZQap8MPHmnt08IiU6bokJ5FwYqbtJE4I+PNWJcgsBdeKnd2xA1kt8Bk/7WFwYhP5JoAReFjIYTkGGNIbhqBcD3ATeRXPvncT9VKyiUtWwiL02EAPpU03CnCfJlawDdmQTFB5dYvsfIb+j+lvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=X+0w12oZdbhV960T8HqB6zptTXT0vzEbEfPf+5/egbs=; b=Iwff3E1mPDtZIgHiOYclZo3FTiA8BSrzWPSi2dq2Gwp5Vpnfu0Lvl+UyKoAn3/wFrE9p3/k5hjM0yuButX3wG6SpvLJIBvy2uQI7mgVcD7zq1Ef4k60ZfgKn2ftG0nK9mfGpLV5JPhF/2dMZxLrjBXE7VkAw26fKQUvb3LKL5P4Z31VgkM6rHLm83Lxrkgjq8MDUVSZSHFr5wSjNOy/umo7NScDfOYYfGv5XMiPVpUsFEOFfoFfdtfoam3UYQC9nVOhSkZvXuxJkUfcdISSmicANBup4x7syMWcRJ3YfYYG+9ycXjaDLVzPkApxPpstwsvWZy4qqNFkBqiwTgMSaBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by DM4PR11MB5550.namprd11.prod.outlook.com (2603:10b6:5:38b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Mon, 17 Jan 2022 23:24:22 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5%8]) with mapi id 15.20.4888.014; Mon, 17 Jan 2022 23:24:22 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , Subject: [RFC 04/10] drm: test-drm_framebuffer: Convert to KUnit Date: Tue, 18 Jan 2022 00:22:53 +0100 Message-ID: <20220117232259.180459-5-michal.winiarski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220117232259.180459-1-michal.winiarski@intel.com> References: <20220117232259.180459-1-michal.winiarski@intel.com> X-ClientProxiedBy: LO2P265CA0310.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a5::34) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7ac34f83-9d29-44ee-cc29-08d9da107e5b X-MS-TrafficTypeDiagnostic: DM4PR11MB5550:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:381; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mGywa6Xq6oLHE1NwBCYhYAtMGzFUbt0liYVDTMxDyTwaDDohBmEUw1CAVT+jWqiBzJey2CD6drSXk4NfukSZCqAcwcBaMp9zSATI4wkSEc1rcUMgH4/sFJbbLR17w46Y7iexDTldQAR0hsSX1nd81EY1v6iasnQ8/dLeEOTkvixbXOhuo+sh5QdT3zKuux+sNK+hf7gflrxsD1Ap9lyUr9Nc1Cp0Jf5FezH7LSQhY7Egxyxsp6gx7a+DDXYAvH3y1ZA+IirdAA5YtbIwEebnBeaprr8/9PCs4w1+mCbVetvDdBLEphfWMTTxqdmSieGeI/OqpOH6OnfqA1P0VCFGtiZR9tcAvXaVJfU1iD3DvSJDYcNWEXkW+UcSFJ0+fP1lc71q6338t8bWwBg1zwdunCjFpLWq8qHBq3m+H/lFQAWvl/f5AICG0XkUfhdhqiB044Rqrwgu2zzqHl3yHBU3ZqCzlFBotMRCRdiadFjNSAivJeSe1lmxPokZ0JcaZ57fSTC/GytHOFS9HRxvxn7GJ7KHdILXT2MttBgbrStCNF+mhoVHwLyUc+kh+oNtpWfs+GtajyKne/gEz/6oNV8Wz43OTp2cVLuxNJxwZrQWGphBZuZbJXLOxcJRFQNcYrFrGGJUYOax0L3iMBagFOXsPw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(82960400001)(4326008)(5660300002)(36756003)(186003)(6506007)(7416002)(1076003)(54906003)(6512007)(83380400001)(26005)(66946007)(66476007)(66556008)(316002)(6486002)(38100700002)(8936002)(508600001)(2906002)(6666004)(8676002)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?FFP/1IU3vymFREFZ5J4XPaLd8sIS?= =?utf-8?q?5/9WKOlgSzPSE8gFTkxKH8nwyefo9T55j3+a1yDB9c4EMKv10mUBM+6Mtpvp+rpBT?= =?utf-8?q?ocDUkxyQlSpH1hlTkVzbuW9HtkEWqvCQ4iKGWvNmHoIdgu3rijyi2vaLShbNqfThJ?= =?utf-8?q?99xKq1mch2v3pvyCfPvXQjjCL6zKDATDUnBmQ62rJqRlA8ltlCv8qJbtLKO3uy2bi?= =?utf-8?q?LUVp1wmcudMcQoYmXEzi5bZMRcR14HM5lqWh/5l+XWYWSK+I1UBGPKL5l0mTcE1vH?= =?utf-8?q?krVPWJFeZR4lGWsyEfYPdAe/XiNQEGzY40ZBOsOXUqKesSKOQxsMitIXny5gH0Umy?= =?utf-8?q?K9tgYTiztesUlJyqmOymbVmOfcA5wp16jwq/sYXOQ0N9C8aqzWzO1+rKqd5PCOpMy?= =?utf-8?q?AMy+JLhiA5RkXio/96pASZesF77PLEpTaEW7EuNDsDXxm+4jMpHDPZBYnnI5egSKd?= =?utf-8?q?NfdrACcDiScLzuAQU1OWPtseVdPfbuvy/fC2r0OUktTAhAYADinuUqhQCawJ6fRko?= =?utf-8?q?sfdUm6ZEkBy+Udr1Umo4phGKIZSgurav53GQz/uo8V4BA7WL/4d0wiVp1iPwKmdj3?= =?utf-8?q?5jQuvkOBmshHx84lAHT3JJxhIbR5IYw83eQmXEL43iPvj/DSZ5d4d1qqRVJfhUhDy?= =?utf-8?q?24RV/CZuX8z9VdRyImnb4W0pBvXszrZ0eXtbeOhkl/y52AUZHSOTuW4TWKTHF++aZ?= =?utf-8?q?kbu26jF3oHfwjEnqrg2xNmGVQ+nz2aUVpjR+XT5J5HPwQlkaKxDjdj0GnFfPeENNQ?= =?utf-8?q?4c8p/jMADLIcoeGx5Z2VBgnBsVykcYQW9Hm8zeRh8NPIgxDaBxJF8T1L2PmGWJf0Q?= =?utf-8?q?fy7wGZ5he9LMNlI17fTLHuG68bk/a6VAgYGG3VhV/Vfn9h5+DjiPBmuL87gkcLdeP?= =?utf-8?q?t0mku1xhq8nfk6m2dRQMGNcrVO7FfJZZO6EfXKY2bKpzeBcjN5z+ziRYFKONY099f?= =?utf-8?q?dorcYO+dLrm3IueMfbOCWPcUoc+5FzC/rMmw6HXPzhnvzxVc5YLNmtBG16vCczA26?= =?utf-8?q?wLBZzp23sa9oqZOT8fWCr+wQoK4N4Atijtp/bjlWRjhAb5xp+EFBj7t61ZPODiaO4?= =?utf-8?q?GCJYR1tsNNwwvr0/wrb4yCgDdzBwuvd7NIkbhyqaGRNW5WVUOaREOEkLCiAsqOW52?= =?utf-8?q?X3/DQ3BrGYbDfSQIsP/iRt8cvMnaO6G479uT9U2niEx+BDdYOqFaCy8JnVXQYL1Tz?= =?utf-8?q?yzopsLSUn+vrlSJ+u4z+wNsu0oGFtOINR1o8uwJHRPKF9wfXbwsHGmanCxlyvUWMn?= =?utf-8?q?AQ532A2THNTLqeiCRqNjqdiCI+jrkviDPr1KYcri6yd7puioyWjIRkyibiRVe4C6S?= =?utf-8?q?WoSGsm7P0nEe41Li4iXC8POpKGiNWI8x18Lpr0omBk+8/xMeMYQenEGCUL/ghAWAY?= =?utf-8?q?he11s57f21DaQAxQ1ddHBPYsZZzEEdQ2SQEk6ewc3yaDJGm3bf/7fAdWrmSOt8uTb?= =?utf-8?q?pKGmXvW5cQ2KkT14lpct1ITZewQz5bmceweHgpPAF0CIhFWM6wmjZDUL6JR5VEOyG?= =?utf-8?q?Cqcb9nKJZZMlFFC5whcDs6iKLNQ5JbrlKK4ltlXWmX5BQo1AHO0N5gLdB2fc11Mjv?= =?utf-8?q?KT8pwayOaFlON6zsW8nhvFdslptH8zMaA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 7ac34f83-9d29-44ee-cc29-08d9da107e5b X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2022 23:24:22.5318 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: epdm6xJikI54BwTdZLdyQzokKsPOXjBUiENGvyopAn/4Kf/rKe5NdIs5rN6uYt3QpRXAn4inHhH6ohZA8beIJx+OwF1kNaZI4/WqknERXnA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5550 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , Thomas Zimmermann , David Airlie , Brendan Higgins , Daniel Latypov , Arkadiusz Hiler , Petri Latvala Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Mocking was moved to .init() in order to separate it from test logic. No functional changes. Signed-off-by: Michał Winiarski --- drivers/gpu/drm/selftests/Makefile | 3 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 1 - .../gpu/drm/selftests/test-drm_framebuffer.c | 109 +++++++++++------- .../drm/selftests/test-drm_modeset_common.h | 1 - 4 files changed, 68 insertions(+), 46 deletions(-) diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile index 76c127613d1a..1235eadca884 100644 --- a/drivers/gpu/drm/selftests/Makefile +++ b/drivers/gpu/drm/selftests/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ test-drm_modeset_common.o \ - test-drm_framebuffer.o \ test-drm_damage_helper.o test-drm_dp_mst_helper.o \ test-drm_rect.o @@ -9,4 +8,4 @@ obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ test-drm_cmdline_parser.o test-drm_plane_helper.o \ - test-drm_format.o + test-drm_format.o test-drm_framebuffer.o diff --git a/drivers/gpu/drm/selftests/drm_modeset_selftests.h b/drivers/gpu/drm/selftests/drm_modeset_selftests.h index 5f253d9e573c..66f6b31e1a7f 100644 --- a/drivers/gpu/drm/selftests/drm_modeset_selftests.h +++ b/drivers/gpu/drm/selftests/drm_modeset_selftests.h @@ -10,7 +10,6 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped) selftest(drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) -selftest(check_drm_framebuffer_create, igt_check_drm_framebuffer_create) selftest(damage_iter_no_damage, igt_damage_iter_no_damage) selftest(damage_iter_no_damage_fractional_src, igt_damage_iter_no_damage_fractional_src) selftest(damage_iter_no_damage_src_moved, igt_damage_iter_no_damage_src_moved) diff --git a/drivers/gpu/drm/selftests/test-drm_framebuffer.c b/drivers/gpu/drm/selftests/test-drm_framebuffer.c index 61b44d3a6a61..faa01cefe4e5 100644 --- a/drivers/gpu/drm/selftests/test-drm_framebuffer.c +++ b/drivers/gpu/drm/selftests/test-drm_framebuffer.c @@ -3,6 +3,7 @@ * Test cases for the drm_framebuffer functions */ +#include #include #include @@ -12,20 +13,67 @@ #include "../drm_crtc_internal.h" -#include "test-drm_modeset_common.h" - #define MIN_WIDTH 4 #define MAX_WIDTH 4096 #define MIN_HEIGHT 4 #define MAX_HEIGHT 4096 -struct drm_framebuffer_test { +static struct drm_framebuffer *fb_create_mock(struct drm_device *dev, + struct drm_file *file_priv, + const struct drm_mode_fb_cmd2 *mode_cmd) +{ + int *buffer_created = dev->dev_private; + + *buffer_created = 1; + + return ERR_PTR(-EINVAL); +} + +static const struct drm_mode_config_funcs mock_config_funcs = { + .fb_create = fb_create_mock, +}; + +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, + .allow_fb_modifiers = true, + .funcs = &mock_config_funcs, + }; + + test->priv = mock; + + return 0; +} + +struct drm_framebuffer_create_test { int buffer_created; struct drm_mode_fb_cmd2 cmd; const char *name; }; -static struct drm_framebuffer_test createbuffer_tests[] = { +static void test_drm_framebuffer_create(struct kunit *test) +{ + const struct drm_framebuffer_create_test *params = test->param_value; + struct drm_device *mock = test->priv; + int buffer_created = 0; + + mock->dev_private = &buffer_created; + + drm_internal_framebuffer_create(mock, ¶ms->cmd, NULL); + + KUNIT_EXPECT_EQ(test, buffer_created, params->buffer_created); +} + +static const struct drm_framebuffer_create_test drm_framebuffer_create_tests[] = { { .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 }, @@ -304,48 +352,25 @@ static struct drm_framebuffer_test createbuffer_tests[] = { }, }; -static struct drm_framebuffer *fb_create_mock(struct drm_device *dev, - struct drm_file *file_priv, - const struct drm_mode_fb_cmd2 *mode_cmd) +static void drm_framebuffer_create_desc(const struct drm_framebuffer_create_test *t, + char *desc) { - int *buffer_created = dev->dev_private; - *buffer_created = 1; - return ERR_PTR(-EINVAL); + sprintf(desc, "%s", t->name); } -static struct drm_mode_config_funcs mock_config_funcs = { - .fb_create = fb_create_mock, -}; +KUNIT_ARRAY_PARAM(drm_framebuffer_create, + drm_framebuffer_create_tests, + drm_framebuffer_create_desc); -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, - .allow_fb_modifiers = true, - .funcs = &mock_config_funcs, - }, +static struct kunit_case drm_framebuffer_tests[] = { + KUNIT_CASE_PARAM(test_drm_framebuffer_create, drm_framebuffer_create_gen_params), + {} }; -static int execute_drm_mode_fb_cmd2(struct drm_mode_fb_cmd2 *r) -{ - int buffer_created = 0; - - mock_drm_device.dev_private = &buffer_created; - drm_internal_framebuffer_create(&mock_drm_device, r, NULL); - return buffer_created; -} - -int igt_check_drm_framebuffer_create(void *ignored) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(createbuffer_tests); i++) { - FAIL(createbuffer_tests[i].buffer_created != - execute_drm_mode_fb_cmd2(&createbuffer_tests[i].cmd), - "Test %d: \"%s\" failed\n", i, createbuffer_tests[i].name); - } +static struct kunit_suite drm_framebuffer_test_suite = { + .name = "drm_framebuffer_tests", + .init = drm_framebuffer_test_init, + .test_cases = drm_framebuffer_tests, +}; - return 0; -} +kunit_test_suite(drm_framebuffer_test_suite); diff --git a/drivers/gpu/drm/selftests/test-drm_modeset_common.h b/drivers/gpu/drm/selftests/test-drm_modeset_common.h index f6cfce2a5863..c09f38b791ad 100644 --- a/drivers/gpu/drm/selftests/test-drm_modeset_common.h +++ b/drivers/gpu/drm/selftests/test-drm_modeset_common.h @@ -20,7 +20,6 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored); int igt_drm_rect_clip_scaled_not_clipped(void *ignored); int igt_drm_rect_clip_scaled_clipped(void *ignored); int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored); -int igt_check_drm_framebuffer_create(void *ignored); int igt_damage_iter_no_damage(void *ignored); int igt_damage_iter_no_damage_fractional_src(void *ignored); int igt_damage_iter_no_damage_src_moved(void *ignored); From patchwork Mon Jan 17 23:22:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 12715731 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 96D2BC433F5 for ; Mon, 17 Jan 2022 23:24:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 66776112549; Mon, 17 Jan 2022 23:24:36 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 49C38112548 for ; Mon, 17 Jan 2022 23:24:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642461874; x=1673997874; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=oYnI6gON5CS6yEm312AIdaVVPuYUAG9qPC59+khH82E=; b=aPKN/YNmlPoJtojL4QQ1NThv2Ki66FlChpaqcfHU9UxjbXeMHJ19u10j kPlCdoRl1yVxHcSDpD7+IfialrCpzAJp6bYUUmR99CqFIkwNjjAw79zYg ie/M33QfmE+hewwxnV/W41BxfYpSGEF9X9fsVLSH6uIVyICspcD+VP35B TQsI47y4lUL9sZvp+xDlkUz+iHw/HS+Xz/GZJVQi49kb5TzAYFk2WwI7E wSWZ47efVouCtWpf+km0BhprIKb4EsdtWRCYAA2W0hW5jlFR1gXcYpry8 iiqL4+EPhXVbbAqbQ9W8GSNYY5jS4+yL3q7+7/J1wgS5iuZq7BfIRy6pl g==; X-IronPort-AV: E=McAfee;i="6200,9189,10230"; a="243529021" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="243529021" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 15:24:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="625325314" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga004.jf.intel.com with ESMTP; 17 Jan 2022 15:24:33 -0800 Received: from fmsmsx605.amr.corp.intel.com (10.18.126.85) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:32 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Mon, 17 Jan 2022 15:24:32 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.169) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:32 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WUBIr3Xd2I7jxkbDhGr2i4QXt0kTq/K07mTgnJVoy14MMIZrPTZpwvmqv0QovcRRu1xvt/6oYWk55AbCgnMsKMvO6ek3/u/SKyMlxyYxk9XF3bXk2J3r9RJjLWx1uJmcNt3t7WdcgCcKTFX1pdQIhKxNRFfJtzqMiIFlQ5POOTb82ltxkyBoRuUe2cSTqEfHNrqpn4noPRhPxqfKd0IxlkLvfVU35dDS24fM7LVHbuFqvMkSKYxlXKc9RLRii6bduIFEv5L7Zw26UuvYFNIIxG6My2Nq2F4n3ORFsXy5s+RbHwm3Ww4Br+zAlXDISyW8M5WHi/HjTt7BrAq0Gr08Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=N2PuRVqATPEecC6JGnykRvb2bjxi/0Gls7O7GDI7+2c=; b=YcMKscNRjlSHuinSp4pClvLcJqrQp4Y9FWYBCU8D7/L8VvabFPKDPqyh4GwybYxVi4rD3ByWJ+7V7iLnKhRVLAWDP4ZsRY58sF1mmexDy9ptRgJmWuFV02sCmMBNen8XMTGTunGZpi7GtHE6Q28AINOPn01cXVREb3M852M+dcUTuM6vL7WSlBCoawJhF/lzldUJVZC78sDKoGWB970vQY0ltRD6hptmYKLa5YbRJtXPO5R1PSehBhdL1n6c9LGyEL/SWKdu0Ryqb2XUz7KcKuT4i30eiVT7KOYkRb+YX0tEWD0y7TPsv65pYQhSRbJ9Z5hf8rlNkaEqXPGyYTEX+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by DM4PR11MB5550.namprd11.prod.outlook.com (2603:10b6:5:38b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Mon, 17 Jan 2022 23:24:28 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5%8]) with mapi id 15.20.4888.014; Mon, 17 Jan 2022 23:24:28 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , Subject: [RFC 05/10] drm: test-drm_damage_helper: Convert to KUnit Date: Tue, 18 Jan 2022 00:22:54 +0100 Message-ID: <20220117232259.180459-6-michal.winiarski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220117232259.180459-1-michal.winiarski@intel.com> References: <20220117232259.180459-1-michal.winiarski@intel.com> X-ClientProxiedBy: LNXP265CA0079.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:76::19) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5bbc1bf1-fd8d-49b4-b16a-08d9da1081fd X-MS-TrafficTypeDiagnostic: DM4PR11MB5550:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Tk7wE5COz5pWTCvRV92fq7EGYYSAvOpglnauX8LIoR0egvUPUAvxR8GmryVvQblQN8BtU+72OgUlVSlsvbP5F7QxIlavc4em8ERhq6MRnb9Z/C2aUaAMijRBkzFHNOVz97fWYZ0h8grVcKnm9oUwv+BsjFgdRM63AQOv7TjgQLdNYlczSOZ+B6pvAsdN0o/5/cOAw1LofwEjtx4+3j4KlrqBzSOddEPa5VVbXYTEDW3m8i7HVypjTqvRQ8mbVG5mYVy8UGUwsGoDxHGNBe688Ejz/jQ0yfFY+x2twleRnl1kzVT/410ZXsbZLC1i59BhUZCam2AhG8EI3Y4LymBdHDkuIE+RVlmpiD5ln4nHccpLvYClg1yAf0A6mAh+YRG7u199Pb3C5x0y+InmwXhekj1IJgj2gX4vW3gc+oT2raUA+j55ahYP05GLcZuEh2KlTcG7gYfdN8guqlts9MT/WP3jDil9xC1pu6iJwHAsV+nDww16LoKSzSTTkMimWQKaNBtdG5zunh4Ya9SrMeo5D+XFSCuCXFQbIc5KBqRb9Dk8PS3PuTrh3Jnoo6tbijseoalljVE6gQfXs4MKfSMsvnplaGDvOxn9Sk/s9rl80/ZiVBXUVOUd9dMh9FByrtCjQHuJS9ncxXoHLwwqArWJeg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(82960400001)(4326008)(5660300002)(36756003)(186003)(6506007)(7416002)(40140700001)(1076003)(54906003)(6512007)(83380400001)(26005)(66946007)(66476007)(66556008)(316002)(6486002)(38100700002)(8936002)(508600001)(2906002)(30864003)(6666004)(8676002)(2616005)(579004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?3X84AAZlbaFRCLMs8VzlyTW7YQJH?= =?utf-8?q?IskikKdJWHgkceo5GPtChPs//3roRRR8OSL3u3F/DKoJ3B4n38Kwos7HNtsX1qVeq?= =?utf-8?q?u8Zfdyj2KZBWyNQ5w3K2h7Avz8Zq7cQUE9VwAT3NqtNl/EJvIy/rLaXmdXxwPTlsR?= =?utf-8?q?7lMmmNDiMuRtSFwkHoKCHsZpQmgItmzKj6a+Cvl58da8nXxzzi3bt4GtvTnifNm/g?= =?utf-8?q?+gRHSjFCTSlck0/HgyTzswQeGbQK5tfSmaCbBo3wac+LIIt4RYbCB6TrAGqvBPoyc?= =?utf-8?q?onOWwtMJqNkBc0AAxDjpAXhg5ArzDHv7bhwlBLQiBXp3PSExtzKwv6lakWpCPfXDx?= =?utf-8?q?ur/fGdF41hUm7SGtza9BzbncLLUTQyFyJX9GILX37ez1kYJFddjvW8MVCprnT2zvG?= =?utf-8?q?I2/afqm7MDWyC/Ulm3eL3dASCamXBaglbne8gQWd3xk3DGofj2GHYPeJhf/ceLuZI?= =?utf-8?q?dssdb0Vqe8q1SJyVLIOw3b5ZtLa3tUsE4EFHT2lOAm3j6o4G3JKLHO/kw02AksuD7?= =?utf-8?q?Kx6v6+sbV1wPcertNSV5JnJWl5ZEp3tYhuqDIh16a192n6s07D3Q/uJGB6e/vqdoF?= =?utf-8?q?kUP8g0+DMPqj/QjmQVbtVi7irpSEvywtzQgSmCV3RXp3V4y059zU7HFMs/l6/yuih?= =?utf-8?q?of60YfM6rcz8ijiWSatN2b2VOKl44dI2niGPTpkQmqF1GNK/rslUXDFkBP/tQCt+3?= =?utf-8?q?f9qq6ILmSDFHunoONH3ml4qtnTVPnqJ0nSo9WyPp3uGeYs1TGHFn/IVajSk6ESnWS?= =?utf-8?q?ELwfIdGR5/8WvTM7zxcZuLiCg/veyY5UoYiUgr/mYGAO86h4wqt3Q4Y8cTj4xP3Cs?= =?utf-8?q?XxK98HKj7j+dQUYHVVoLJh9Y3Qdq5h6XTz/EA9so2DOJ53zvStZLVa+rdJEhFiiZY?= =?utf-8?q?wymie1Zhahhi7pmPDJVQqhQ8mcwCrbRhuqAK5/XCRqGo7gKHahh7fwHjN/ywTRj2m?= =?utf-8?q?ZgWjDCiiulQsH9BAIV9Zl/eWV1s2Y9e7zi7tBnYAU92unnf007gefH3T9pAe5hJue?= =?utf-8?q?DkJBK0+lXx630zAcrjFydaW4/HUruskrfkCOXYo993rO3hPn62c9OLYQMZVE4SQSU?= =?utf-8?q?bZFp+Jqg+RI7OdoxbZ3+4d++nabqIbVP45TDWD6n8yHVW6pEdqWZKDrhRhS4sowyp?= =?utf-8?q?14nph14UnSq7wxgJqbT3EUsfQCzlU1WE8uSp7xuhKg0wTrW/gi+tHAjQCLDCNldle?= =?utf-8?q?bseTeAw+rpu17nu5f7i7NbqNNbmb9XTjUucEWFiYchMYszA0qykIefGQtip5kjg6P?= =?utf-8?q?SONECU4IfNML0v1Mvw+xWP1yaHPz/sqLp4lygl0Q6xnkCnnp9uuKOeQZwxat6yi5w?= =?utf-8?q?4PQWfngyzUdrGXjYCPRM7LUcxDCrdc9YRCLcJp6eNJ5bJhxYPwiYBibBMdf7llqET?= =?utf-8?q?IbVdphFfqOVpMMFRGAHFNfZUKoruIfRmHBcTyUDVr2c9S63G2YnlJkNMWMh8buN4x?= =?utf-8?q?HnK0YNINWA44akXWWRpbbFQBNoWWfNM5eG3ssrIKgFZFfkO8hNKT1J7UxMKqpX6y2?= =?utf-8?q?yE8wJg1UduFiNr4CiE2g0SNbfI4xrx9QTWMD+D/qyvw/8NgMZSogcKQJMXS0VXFPn?= =?utf-8?q?Llwp1tdN83tUNSXxobB4RDVlesqOTDEcQ=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 5bbc1bf1-fd8d-49b4-b16a-08d9da1081fd X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2022 23:24:28.7197 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3DbasW3cf+ht8s2e6G59HJqAOsDhAHkV1RsmHRHcmLOT0IoHNOj5Z34iIOTaWHn9GeLWIkQJ2qzI/HfbIfLpd98bGVdBuBCUvYyyNDIKWng= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5550 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , Thomas Zimmermann , David Airlie , Brendan Higgins , Daniel Latypov , Arkadiusz Hiler , Petri Latvala Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Mocking was moved to .init() in order to separate it from test logic. No functional changes. Signed-off-by: Michał Winiarski --- drivers/gpu/drm/selftests/Makefile | 5 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 21 - .../drm/selftests/test-drm_damage_helper.c | 570 +++++++++--------- .../drm/selftests/test-drm_modeset_common.h | 21 - 4 files changed, 288 insertions(+), 329 deletions(-) diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile index 1235eadca884..35f2f40dbaf3 100644 --- a/drivers/gpu/drm/selftests/Makefile +++ b/drivers/gpu/drm/selftests/Makefile @@ -1,11 +1,12 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ test-drm_modeset_common.o \ - test-drm_damage_helper.o test-drm_dp_mst_helper.o \ + test-drm_dp_mst_helper.o \ test-drm_rect.o obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ test-drm_cmdline_parser.o test-drm_plane_helper.o \ - test-drm_format.o test-drm_framebuffer.o + test-drm_format.o test-drm_framebuffer.o \ + test-drm_damage_helper.o diff --git a/drivers/gpu/drm/selftests/drm_modeset_selftests.h b/drivers/gpu/drm/selftests/drm_modeset_selftests.h index 66f6b31e1a7f..b6a6dba66b64 100644 --- a/drivers/gpu/drm/selftests/drm_modeset_selftests.h +++ b/drivers/gpu/drm/selftests/drm_modeset_selftests.h @@ -10,26 +10,5 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped) selftest(drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) -selftest(damage_iter_no_damage, igt_damage_iter_no_damage) -selftest(damage_iter_no_damage_fractional_src, igt_damage_iter_no_damage_fractional_src) -selftest(damage_iter_no_damage_src_moved, igt_damage_iter_no_damage_src_moved) -selftest(damage_iter_no_damage_fractional_src_moved, igt_damage_iter_no_damage_fractional_src_moved) -selftest(damage_iter_no_damage_not_visible, igt_damage_iter_no_damage_not_visible) -selftest(damage_iter_no_damage_no_crtc, igt_damage_iter_no_damage_no_crtc) -selftest(damage_iter_no_damage_no_fb, igt_damage_iter_no_damage_no_fb) -selftest(damage_iter_simple_damage, igt_damage_iter_simple_damage) -selftest(damage_iter_single_damage, igt_damage_iter_single_damage) -selftest(damage_iter_single_damage_intersect_src, igt_damage_iter_single_damage_intersect_src) -selftest(damage_iter_single_damage_outside_src, igt_damage_iter_single_damage_outside_src) -selftest(damage_iter_single_damage_fractional_src, igt_damage_iter_single_damage_fractional_src) -selftest(damage_iter_single_damage_intersect_fractional_src, igt_damage_iter_single_damage_intersect_fractional_src) -selftest(damage_iter_single_damage_outside_fractional_src, igt_damage_iter_single_damage_outside_fractional_src) -selftest(damage_iter_single_damage_src_moved, igt_damage_iter_single_damage_src_moved) -selftest(damage_iter_single_damage_fractional_src_moved, igt_damage_iter_single_damage_fractional_src_moved) -selftest(damage_iter_damage, igt_damage_iter_damage) -selftest(damage_iter_damage_one_intersect, igt_damage_iter_damage_one_intersect) -selftest(damage_iter_damage_one_outside, igt_damage_iter_damage_one_outside) -selftest(damage_iter_damage_src_moved, igt_damage_iter_damage_src_moved) -selftest(damage_iter_damage_not_visible, igt_damage_iter_damage_not_visible) selftest(dp_mst_calc_pbn_mode, igt_dp_mst_calc_pbn_mode) selftest(dp_mst_sideband_msg_req_decode, igt_dp_mst_sideband_msg_req_decode) diff --git a/drivers/gpu/drm/selftests/test-drm_damage_helper.c b/drivers/gpu/drm/selftests/test-drm_damage_helper.c index 8d8d8e214c28..685d87575c3a 100644 --- a/drivers/gpu/drm/selftests/test-drm_damage_helper.c +++ b/drivers/gpu/drm/selftests/test-drm_damage_helper.c @@ -3,39 +3,55 @@ * Test case for drm_damage_helper functions */ -#define pr_fmt(fmt) "drm_damage_helper: " fmt +#include #include #include #include -#include "test-drm_modeset_common.h" - -struct drm_driver mock_driver; -static struct drm_device mock_device; -static struct drm_object_properties mock_obj_props; -static struct drm_plane mock_plane; -static struct drm_property mock_prop; +/* common mocked structs many tests need */ +struct drm_damage_mock { + struct drm_framebuffer fb; + struct drm_driver driver; + struct drm_device device; + struct drm_object_properties obj_props; + struct drm_plane plane; + struct drm_property prop; + struct drm_plane_state state; + struct drm_plane_state old_state; +}; -static void mock_setup(struct drm_plane_state *state) +static int drm_damage_test_init(struct kunit *test) { - static bool setup_done = false; + struct drm_damage_mock *mock; - state->plane = &mock_plane; + mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); - if (setup_done) - return; + mock->fb.width = 2048; + mock->fb.height = 2048; /* just enough so that drm_plane_enable_fb_damage_clips() works */ - mock_device.driver = &mock_driver; - mock_device.mode_config.prop_fb_damage_clips = &mock_prop; - mock_plane.dev = &mock_device; - mock_obj_props.count = 0; - mock_plane.base.properties = &mock_obj_props; - mock_prop.base.id = 1; /* 0 is an invalid id */ - mock_prop.dev = &mock_device; - - drm_plane_enable_fb_damage_clips(&mock_plane); + mock->device.driver = &mock->driver; + mock->device.mode_config.prop_fb_damage_clips = &mock->prop; + mock->plane.dev = &mock->device; + mock->obj_props.count = 0; + mock->plane.base.properties = &mock->obj_props; + mock->prop.base.id = 1; /* 0 is an invalid id */ + mock->prop.dev = &mock->device; + + drm_plane_enable_fb_damage_clips(&mock->plane); + + mock->state.crtc = ZERO_SIZE_PTR; + mock->state.fb = &mock->fb; + mock->state.visible = true; + mock->state.plane = &mock->plane; + + mock->old_state.plane = &mock->plane; + + test->priv = mock; + + return 0; } static void set_plane_src(struct drm_plane_state *state, int x1, int y1, int x2, @@ -69,8 +85,8 @@ static void set_plane_damage(struct drm_plane_state *state, state->fb_damage_clips = damage_blob; } -static bool check_damage_clip(struct drm_plane_state *state, struct drm_rect *r, - int x1, int y1, int x2, int y2) +static void check_damage_clip(struct kunit *test, struct drm_plane_state *state, + struct drm_rect *r, int x1, int y1, int x2, int y2) { /* * Round down x1/y1 and round up x2/y2. This is because damage is not in @@ -81,587 +97,571 @@ static bool check_damage_clip(struct drm_plane_state *state, struct drm_rect *r, int src_x2 = (state->src.x2 >> 16) + !!(state->src.x2 & 0xFFFF); int src_y2 = (state->src.y2 >> 16) + !!(state->src.y2 & 0xFFFF); - if (x1 >= x2 || y1 >= y2) { - pr_err("Cannot have damage clip with no dimension.\n"); - return false; - } - - if (x1 < src_x1 || y1 < src_y1 || x2 > src_x2 || y2 > src_y2) { - pr_err("Damage cannot be outside rounded plane src.\n"); - return false; - } - - if (r->x1 != x1 || r->y1 != y1 || r->x2 != x2 || r->y2 != y2) { - pr_err("Damage = %d %d %d %d\n", r->x1, r->y1, r->x2, r->y2); - return false; - } + KUNIT_EXPECT_FALSE_MSG(test, x1 >= x2 || y1 >= y2, + "Cannot have damage clip with no dimension."); + KUNIT_EXPECT_FALSE_MSG(test, x1 < src_x1 || y1 < src_y1 || x2 > src_x2 || y2 > src_y2, + "Damage cannot be outside rounded plane src."); - return true; + KUNIT_EXPECT_TRUE_MSG(test, r->x1 == x1 && r->y1 == y1 && r->x2 == x2 && r->y2 == y2, + "Damage = %d %d %d %d, expected = %d %d %d %d", + r->x1, r->y1, r->x2, r->y2, + x1, y1, x2, y2); } -const struct drm_framebuffer fb = { - .width = 2048, - .height = 2048 -}; - -/* common mocked structs many tests need */ -#define MOCK_VARIABLES() \ - struct drm_plane_state old_state; \ - struct drm_plane_state state = { \ - .crtc = ZERO_SIZE_PTR, \ - .fb = (struct drm_framebuffer *) &fb, \ - .visible = true, \ - }; \ - mock_setup(&old_state); \ - mock_setup(&state); - -int igt_damage_iter_no_damage(void *ignored) +static void drm_damage_iter_no_damage(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; + struct drm_framebuffer *fb = &mock->fb; struct drm_atomic_helper_damage_iter iter; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - /* Plane src same as fb size. */ - set_plane_src(&old_state, 0, 0, fb.width << 16, fb.height << 16); - set_plane_src(&state, 0, 0, fb.width << 16, fb.height << 16); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_src(old_state, 0, 0, fb->width << 16, fb->height << 16); + set_plane_src(state, 0, 0, fb->width << 16, fb->height << 16); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return plane src as damage."); - FAIL_ON(!check_damage_clip(&state, &clip, 0, 0, 2048, 2048)); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 1, "Should return plane src as damage."); + check_damage_clip(test, state, &clip, 0, 0, 2048, 2048); } -int igt_damage_iter_no_damage_fractional_src(void *ignored) +static void drm_damage_iter_no_damage_fractional_src(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - /* Plane src has fractional part. */ - set_plane_src(&old_state, 0x3fffe, 0x3fffe, + set_plane_src(old_state, 0x3fffe, 0x3fffe, 0x3fffe + (1024 << 16), 0x3fffe + (768 << 16)); - set_plane_src(&state, 0x3fffe, 0x3fffe, + set_plane_src(state, 0x3fffe, 0x3fffe, 0x3fffe + (1024 << 16), 0x3fffe + (768 << 16)); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return rounded off plane src as damage."); - FAIL_ON(!check_damage_clip(&state, &clip, 3, 3, 1028, 772)); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 1, "Should return rounded off plane src as damage."); + check_damage_clip(test, state, &clip, 3, 3, 1028, 772); } -int igt_damage_iter_no_damage_src_moved(void *ignored) +static void drm_damage_iter_no_damage_src_moved(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - /* Plane src moved since old plane state. */ - set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); - set_plane_src(&state, 10 << 16, 10 << 16, + set_plane_src(old_state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(state, 10 << 16, 10 << 16, (10 + 1024) << 16, (10 + 768) << 16); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return plane src as damage."); - FAIL_ON(!check_damage_clip(&state, &clip, 10, 10, 1034, 778)); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 1, "Should return plane src as damage."); + check_damage_clip(test, state, &clip, 10, 10, 1034, 778); } -int igt_damage_iter_no_damage_fractional_src_moved(void *ignored) +static void drm_damage_iter_no_damage_fractional_src_moved(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - /* Plane src has fractional part and it moved since old plane state. */ - set_plane_src(&old_state, 0x3fffe, 0x3fffe, + set_plane_src(old_state, 0x3fffe, 0x3fffe, 0x3fffe + (1024 << 16), 0x3fffe + (768 << 16)); - set_plane_src(&state, 0x40002, 0x40002, + set_plane_src(state, 0x40002, 0x40002, 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return plane src as damage."); - FAIL_ON(!check_damage_clip(&state, &clip, 4, 4, 1029, 773)); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 1, "Should return plane src as damage."); + check_damage_clip(test, state, &clip, 4, 4, 1029, 773); } -int igt_damage_iter_no_damage_not_visible(void *ignored) +static void drm_damage_iter_no_damage_not_visible(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - - state.visible = false; + state->visible = false; - mock_setup(&old_state); - - set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); - set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_src(old_state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(state, 0, 0, 1024 << 16, 768 << 16); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 0, "Should have no damage."); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 0, "Should have no damage."); } -int igt_damage_iter_no_damage_no_crtc(void *ignored) +static void drm_damage_iter_no_damage_no_crtc(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - - state.crtc = NULL; + state->crtc = NULL; - set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); - set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_src(old_state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(state, 0, 0, 1024 << 16, 768 << 16); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 0, "Should have no damage."); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 0, "Should have no damage."); } -int igt_damage_iter_no_damage_no_fb(void *ignored) +static void drm_damage_iter_no_damage_no_fb(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; - struct drm_plane_state old_state; struct drm_rect clip; uint32_t num_hits = 0; - struct drm_plane_state state = { - .crtc = ZERO_SIZE_PTR, - .fb = 0, - }; - - mock_setup(&old_state); + state->fb = NULL; - set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); - set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_src(old_state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(state, 0, 0, 1024 << 16, 768 << 16); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 0, "Should have no damage."); - - return 0; + KUNIT_EXPECT_EQ(test, num_hits, 0); } -int igt_damage_iter_simple_damage(void *ignored) +static void drm_damage_iter_simple_damage(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - - set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); - set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(old_state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(state, 0, 0, 1024 << 16, 768 << 16); /* Damage set to plane src */ set_damage_clip(&damage, 0, 0, 1024, 768); set_damage_blob(&damage_blob, &damage, sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return damage when set."); - FAIL_ON(!check_damage_clip(&state, &clip, 0, 0, 1024, 768)); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 1, "Should return damage when set."); + check_damage_clip(test, state, &clip, 0, 0, 1024, 768); } -int igt_damage_iter_single_damage(void *ignored) +static void drm_damage_iter_single_damage(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - - set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); - set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(old_state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(state, 0, 0, 1024 << 16, 768 << 16); set_damage_clip(&damage, 256, 192, 768, 576); set_damage_blob(&damage_blob, &damage, sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return damage when set."); - FAIL_ON(!check_damage_clip(&state, &clip, 256, 192, 768, 576)); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 1, "Should return damage when set."); + check_damage_clip(test, state, &clip, 256, 192, 768, 576); } -int igt_damage_iter_single_damage_intersect_src(void *ignored) +static void drm_damage_iter_single_damage_intersect_src(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - - set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); - set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(old_state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(state, 0, 0, 1024 << 16, 768 << 16); /* Damage intersect with plane src. */ set_damage_clip(&damage, 256, 192, 1360, 768); set_damage_blob(&damage_blob, &damage, sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return damage clipped to src."); - FAIL_ON(!check_damage_clip(&state, &clip, 256, 192, 1024, 768)); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 1, "Should return damage clipped to src."); + check_damage_clip(test, state, &clip, 256, 192, 1024, 768); } -int igt_damage_iter_single_damage_outside_src(void *ignored) +static void drm_damage_iter_single_damage_outside_src(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - - set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); - set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(old_state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(state, 0, 0, 1024 << 16, 768 << 16); /* Damage clip outside plane src */ set_damage_clip(&damage, 1360, 1360, 1380, 1380); set_damage_blob(&damage_blob, &damage, sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 0, "Should have no damage."); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 0, "Should have no damage."); } -int igt_damage_iter_single_damage_fractional_src(void *ignored) +static void drm_damage_iter_single_damage_fractional_src(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - /* Plane src has fractional part. */ - set_plane_src(&old_state, 0x40002, 0x40002, + set_plane_src(old_state, 0x40002, 0x40002, 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); - set_plane_src(&state, 0x40002, 0x40002, + set_plane_src(state, 0x40002, 0x40002, 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); set_damage_clip(&damage, 10, 10, 256, 330); set_damage_blob(&damage_blob, &damage, sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return damage when set."); - FAIL_ON(!check_damage_clip(&state, &clip, 10, 10, 256, 330)); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 1, "Should return damage when set."); + check_damage_clip(test, state, &clip, 10, 10, 256, 330); } -int igt_damage_iter_single_damage_intersect_fractional_src(void *ignored) +static void drm_damage_iter_single_damage_intersect_fractional_src(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - /* Plane src has fractional part. */ - set_plane_src(&old_state, 0x40002, 0x40002, + set_plane_src(old_state, 0x40002, 0x40002, 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); - set_plane_src(&state, 0x40002, 0x40002, + set_plane_src(state, 0x40002, 0x40002, 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); /* Damage intersect with plane src. */ set_damage_clip(&damage, 10, 1, 1360, 330); set_damage_blob(&damage_blob, &damage, sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return damage clipped to rounded off src."); - FAIL_ON(!check_damage_clip(&state, &clip, 10, 4, 1029, 330)); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 1, "Should return damage clipped to rounded off src."); + check_damage_clip(test, state, &clip, 10, 4, 1029, 330); } -int igt_damage_iter_single_damage_outside_fractional_src(void *ignored) +static void drm_damage_iter_single_damage_outside_fractional_src(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - /* Plane src has fractional part. */ - set_plane_src(&old_state, 0x40002, 0x40002, + set_plane_src(old_state, 0x40002, 0x40002, 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); - set_plane_src(&state, 0x40002, 0x40002, + set_plane_src(state, 0x40002, 0x40002, 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); /* Damage clip outside plane src */ set_damage_clip(&damage, 1360, 1360, 1380, 1380); set_damage_blob(&damage_blob, &damage, sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 0, "Should have no damage."); - - return 0; + KUNIT_EXPECT_EQ(test, num_hits, 0); } -int igt_damage_iter_single_damage_src_moved(void *ignored) +static void drm_damage_iter_single_damage_src_moved(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - /* Plane src moved since old plane state. */ - set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); - set_plane_src(&state, 10 << 16, 10 << 16, + set_plane_src(old_state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(state, 10 << 16, 10 << 16, (10 + 1024) << 16, (10 + 768) << 16); set_damage_clip(&damage, 20, 30, 256, 256); set_damage_blob(&damage_blob, &damage, sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return plane src as damage."); - FAIL_ON(!check_damage_clip(&state, &clip, 10, 10, 1034, 778)); - - return 0; + KUNIT_EXPECT_EQ(test, num_hits, 1); + check_damage_clip(test, state, &clip, 10, 10, 1034, 778); } -int igt_damage_iter_single_damage_fractional_src_moved(void *ignored) +static void drm_damage_iter_single_damage_fractional_src_moved(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - /* Plane src with fractional part moved since old plane state. */ - set_plane_src(&old_state, 0x3fffe, 0x3fffe, + set_plane_src(old_state, 0x3fffe, 0x3fffe, 0x3fffe + (1024 << 16), 0x3fffe + (768 << 16)); - set_plane_src(&state, 0x40002, 0x40002, + set_plane_src(state, 0x40002, 0x40002, 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); /* Damage intersect with plane src. */ set_damage_clip(&damage, 20, 30, 1360, 256); set_damage_blob(&damage_blob, &damage, sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return rounded off plane src as damage."); - FAIL_ON(!check_damage_clip(&state, &clip, 4, 4, 1029, 773)); - - return 0; + KUNIT_EXPECT_EQ(test, num_hits, 1); + check_damage_clip(test, state, &clip, 4, 4, 1029, 773); } -int igt_damage_iter_damage(void *ignored) +static void drm_damage_iter_damage(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage[2]; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - - set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); - set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(old_state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(state, 0, 0, 1024 << 16, 768 << 16); /* 2 damage clips. */ set_damage_clip(&damage[0], 20, 30, 200, 180); set_damage_clip(&damage[1], 240, 200, 280, 250); set_damage_blob(&damage_blob, &damage[0], sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) { if (num_hits == 0) - FAIL_ON(!check_damage_clip(&state, &clip, 20, 30, 200, 180)); + check_damage_clip(test, state, &clip, 20, 30, 200, 180); if (num_hits == 1) - FAIL_ON(!check_damage_clip(&state, &clip, 240, 200, 280, 250)); + check_damage_clip(test, state, &clip, 240, 200, 280, 250); num_hits++; } - FAIL(num_hits != 2, "Should return damage when set."); - - return 0; + KUNIT_EXPECT_EQ(test, num_hits, 2); } -int igt_damage_iter_damage_one_intersect(void *ignored) +static void drm_damage_iter_damage_one_intersect(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage[2]; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - - set_plane_src(&old_state, 0x40002, 0x40002, + set_plane_src(old_state, 0x40002, 0x40002, 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); - set_plane_src(&state, 0x40002, 0x40002, + set_plane_src(state, 0x40002, 0x40002, 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); /* 2 damage clips, one intersect plane src. */ set_damage_clip(&damage[0], 20, 30, 200, 180); set_damage_clip(&damage[1], 2, 2, 1360, 1360); set_damage_blob(&damage_blob, &damage[0], sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) { if (num_hits == 0) - FAIL_ON(!check_damage_clip(&state, &clip, 20, 30, 200, 180)); + check_damage_clip(test, state, &clip, 20, 30, 200, 180); if (num_hits == 1) - FAIL_ON(!check_damage_clip(&state, &clip, 4, 4, 1029, 773)); + check_damage_clip(test, state, &clip, 4, 4, 1029, 773); num_hits++; } - FAIL(num_hits != 2, "Should return damage when set."); - - return 0; + KUNIT_EXPECT_EQ(test, num_hits, 2); } -int igt_damage_iter_damage_one_outside(void *ignored) +static void drm_damage_iter_damage_one_outside(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage[2]; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - - set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); - set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(old_state, 0, 0, 1024 << 16, 768 << 16); + set_plane_src(state, 0, 0, 1024 << 16, 768 << 16); /* 2 damage clips, one outside plane src. */ set_damage_clip(&damage[0], 1360, 1360, 1380, 1380); set_damage_clip(&damage[1], 240, 200, 280, 250); set_damage_blob(&damage_blob, &damage[0], sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return damage when set."); - FAIL_ON(!check_damage_clip(&state, &clip, 240, 200, 280, 250)); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 1, "Should return damage when set."); + check_damage_clip(test, state, &clip, 240, 200, 280, 250); } -int igt_damage_iter_damage_src_moved(void *ignored) +static void drm_damage_iter_damage_src_moved(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage[2]; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); - - set_plane_src(&old_state, 0x40002, 0x40002, + set_plane_src(old_state, 0x40002, 0x40002, 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); - set_plane_src(&state, 0x3fffe, 0x3fffe, + set_plane_src(state, 0x3fffe, 0x3fffe, 0x3fffe + (1024 << 16), 0x3fffe + (768 << 16)); /* 2 damage clips, one outside plane src. */ set_damage_clip(&damage[0], 1360, 1360, 1380, 1380); set_damage_clip(&damage[1], 240, 200, 280, 250); set_damage_blob(&damage_blob, &damage[0], sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 1, "Should return round off plane src as damage."); - FAIL_ON(!check_damage_clip(&state, &clip, 3, 3, 1028, 772)); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 1, "Should return round off plane src as damage."); + check_damage_clip(test, state, &clip, 3, 3, 1028, 772); } -int igt_damage_iter_damage_not_visible(void *ignored) +static void drm_damage_iter_damage_not_visible(struct kunit *test) { + struct drm_damage_mock *mock = test->priv; + struct drm_plane_state *old_state = &mock->old_state; + struct drm_plane_state *state = &mock->state; struct drm_atomic_helper_damage_iter iter; struct drm_property_blob damage_blob; struct drm_mode_rect damage[2]; struct drm_rect clip; uint32_t num_hits = 0; - MOCK_VARIABLES(); + state->visible = false; - state.visible = false; - - set_plane_src(&old_state, 0x40002, 0x40002, + set_plane_src(old_state, 0x40002, 0x40002, 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); - set_plane_src(&state, 0x3fffe, 0x3fffe, + set_plane_src(state, 0x3fffe, 0x3fffe, 0x3fffe + (1024 << 16), 0x3fffe + (768 << 16)); /* 2 damage clips, one outside plane src. */ set_damage_clip(&damage[0], 1360, 1360, 1380, 1380); set_damage_clip(&damage[1], 240, 200, 280, 250); set_damage_blob(&damage_blob, &damage[0], sizeof(damage)); - set_plane_damage(&state, &damage_blob); - drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); + set_plane_damage(state, &damage_blob); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &clip) num_hits++; - FAIL(num_hits != 0, "Should not return any damage."); - - return 0; + KUNIT_EXPECT_EQ_MSG(test, num_hits, 0, "Should not return any damage."); } + +static struct kunit_case drm_damage_helper_tests[] = { + KUNIT_CASE(drm_damage_iter_no_damage), + KUNIT_CASE(drm_damage_iter_no_damage_fractional_src), + KUNIT_CASE(drm_damage_iter_no_damage_src_moved), + KUNIT_CASE(drm_damage_iter_no_damage_fractional_src_moved), + KUNIT_CASE(drm_damage_iter_no_damage_not_visible), + KUNIT_CASE(drm_damage_iter_no_damage_no_crtc), + KUNIT_CASE(drm_damage_iter_no_damage_no_fb), + KUNIT_CASE(drm_damage_iter_simple_damage), + KUNIT_CASE(drm_damage_iter_single_damage), + KUNIT_CASE(drm_damage_iter_single_damage_intersect_src), + KUNIT_CASE(drm_damage_iter_single_damage_outside_src), + KUNIT_CASE(drm_damage_iter_single_damage_fractional_src), + KUNIT_CASE(drm_damage_iter_single_damage_intersect_fractional_src), + KUNIT_CASE(drm_damage_iter_single_damage_outside_fractional_src), + KUNIT_CASE(drm_damage_iter_single_damage_src_moved), + KUNIT_CASE(drm_damage_iter_single_damage_fractional_src_moved), + KUNIT_CASE(drm_damage_iter_damage), + KUNIT_CASE(drm_damage_iter_damage_one_intersect), + KUNIT_CASE(drm_damage_iter_damage_one_outside), + KUNIT_CASE(drm_damage_iter_damage_src_moved), + KUNIT_CASE(drm_damage_iter_damage_not_visible), + {} +}; + +static struct kunit_suite drm_damage_helper_test_suite = { + .name = "drm_damage_helper_tests", + .init = drm_damage_test_init, + .test_cases = drm_damage_helper_tests, +}; + +kunit_test_suite(drm_damage_helper_test_suite); diff --git a/drivers/gpu/drm/selftests/test-drm_modeset_common.h b/drivers/gpu/drm/selftests/test-drm_modeset_common.h index c09f38b791ad..1501d99aee2f 100644 --- a/drivers/gpu/drm/selftests/test-drm_modeset_common.h +++ b/drivers/gpu/drm/selftests/test-drm_modeset_common.h @@ -20,27 +20,6 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored); int igt_drm_rect_clip_scaled_not_clipped(void *ignored); int igt_drm_rect_clip_scaled_clipped(void *ignored); int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored); -int igt_damage_iter_no_damage(void *ignored); -int igt_damage_iter_no_damage_fractional_src(void *ignored); -int igt_damage_iter_no_damage_src_moved(void *ignored); -int igt_damage_iter_no_damage_fractional_src_moved(void *ignored); -int igt_damage_iter_no_damage_not_visible(void *ignored); -int igt_damage_iter_no_damage_no_crtc(void *ignored); -int igt_damage_iter_no_damage_no_fb(void *ignored); -int igt_damage_iter_simple_damage(void *ignored); -int igt_damage_iter_single_damage(void *ignored); -int igt_damage_iter_single_damage_intersect_src(void *ignored); -int igt_damage_iter_single_damage_outside_src(void *ignored); -int igt_damage_iter_single_damage_fractional_src(void *ignored); -int igt_damage_iter_single_damage_intersect_fractional_src(void *ignored); -int igt_damage_iter_single_damage_outside_fractional_src(void *ignored); -int igt_damage_iter_single_damage_src_moved(void *ignored); -int igt_damage_iter_single_damage_fractional_src_moved(void *ignored); -int igt_damage_iter_damage(void *ignored); -int igt_damage_iter_damage_one_intersect(void *ignored); -int igt_damage_iter_damage_one_outside(void *ignored); -int igt_damage_iter_damage_src_moved(void *ignored); -int igt_damage_iter_damage_not_visible(void *ignored); int igt_dp_mst_calc_pbn_mode(void *ignored); int igt_dp_mst_sideband_msg_req_decode(void *ignored); From patchwork Mon Jan 17 23:22:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 12715732 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A794DC433F5 for ; Mon, 17 Jan 2022 23:24:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CE0ED11254C; Mon, 17 Jan 2022 23:24:51 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4E03A11254C for ; Mon, 17 Jan 2022 23:24:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642461890; x=1673997890; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=GcWP1LRMN7SxSYJ3pSTe8V2ey5lZyLVzDF6iV8Uf3kU=; b=kWK6hgWnYYstCENJR4axTGagZU5xNwwTVJTl+7PaZ51dX25GMhvx1P5y r5tSv2M4Pg4l1HlgSN/qXvt4jyCmtWXEsWGTQFQA9dRU8sq1VMeJ6LUw4 OamLxrX4m4rD1TJNG0zuUrLy2ok5aMdjaGKaGKfjINEmli1ScUhfX12KR DQU8zwuVnqEQK0cxXxJi2Z5P6/WnMayHbPfRMeyAVpdvuzMO44tyQozqE u5SvPe/sgGFvdv1EVD50irF/iSbQKK2Tli5axup3GUjNHeKtJk1MmDmLg uSlHSS1+K6cu06C7UvK5oJDHY/JW0TUrrdcayTSVg/kn8MzJ5IToPjbzY Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10230"; a="244501844" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="244501844" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 15:24:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="517554411" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga007.jf.intel.com with ESMTP; 17 Jan 2022 15:24:41 -0800 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:40 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX609.amr.corp.intel.com (10.22.229.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:40 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Mon, 17 Jan 2022 15:24:40 -0800 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.171) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:40 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V/ypTEqIjI5qLpdPy4LDBxwrPbLrip+xUz4uUm6gIVzDsGXK+GQTdhuMIeEptzOHstzA7d6rhOkJOieB0QMnFPGQt+UfOTAt42WUVXu5jZjgrJ525shE3uw0XT7qNUKQ6Wmh2zbDfSy5oVlifcWGhV5MPUPeIPaPvnS7c0HpOApmYehBEUq7bJ9lzCsbe8L6M1pInvH2wVdEUiWcx21q7vNHWoGwl2nQ2aoyH6Lm4JoJOd51+4RO4T8VaQw+yQyVHreX9aEKUFvhuFaGSBL+4hlKkqLuHbqlTUA1GhVe3E6V7JyZQHG5rgcf9kkx7R31KsBwVHaN/eubxkq+4MoTdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bhPMBEpU7fSd99CDkUXlfjakSYRMf0JwjL0TEAu1GOU=; b=h3FOo9bebJvnzqGJdzoQHMN8DMhc+5i4sg8rX0n1VUYx/h/kKOBpcYPRaXSg2UjsE2YO3YyKhhqNqSKmHa6wMN4aqvUTNAye429uJffCk8jb39j5tyR2yMDapOdUgrsnE0oP+xL7uKv6/dcHXAntp2OUjdFJtN9eIk7yAY8XzQm5nEUD/SuJ1U/zXyW0nDPgMYza23lVFgq01pU5utAN9/gEpg1xyt6T7ABGHvxTbw9PlbH+63l8iGKMFfnOH9YVYJWZXHxKoBniZyPcX7aULNc9hlZc5LZHvx15SAEl8gKMUiSBwPEzLJUYaOj5eFEPFYJFG6Bay60PVpUfWfGYRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by DM4PR11MB5550.namprd11.prod.outlook.com (2603:10b6:5:38b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Mon, 17 Jan 2022 23:24:36 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5%8]) with mapi id 15.20.4888.014; Mon, 17 Jan 2022 23:24:36 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , Subject: [RFC 06/10] drm: test-drm_dp_mst_helper: Convert to KUnit Date: Tue, 18 Jan 2022 00:22:55 +0100 Message-ID: <20220117232259.180459-7-michal.winiarski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220117232259.180459-1-michal.winiarski@intel.com> References: <20220117232259.180459-1-michal.winiarski@intel.com> X-ClientProxiedBy: LO2P265CA0056.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:60::20) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c6f0c31c-b6e4-4d26-4f1a-08d9da1086a8 X-MS-TrafficTypeDiagnostic: DM4PR11MB5550:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:773; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MMH3H+zODFnfLnkgrcVVhwPO8dhv0wVelBCByc4e3XMtvVKH5TZnlb5Vk/reg4GwsQ5tILrzdBPsyDIXXBUGqk91qyREbly6qfB56GkhhiFkdBiqR6ldue8pqO82zDaCmq4B3nmTBlYlpAvpJkD1tr0B6j2Dsjo8ThYXPiG9lTQDHkfBDzSrhJ08zPXciwFeculN0dAq9wDxMKKNNr3J+5KOOKjsBo4Iuq13sTl7btZDmLDD/hBFv56m+iw3e2krtvo274yK61QoDSvv58XJc6U1LxvamoYxUNAWtq32TWVHtK3erPlDIrWSz2AryuDZKyttl8dJJD2NGkS2KPBIh0Oai1y3DdmGD3qaRpJ7dDwKUPhASovOG+wtABANixyQY0X5HZ2N7/v8rKyK/6pvMslvuaVM9Ilm5cI9iroCPxtcrS1Rn1XrWKBvjcuwYrTRYyZXoAP1CN/4q/ljfkGPbRtNj3hrq1pFIKkcMZFTsAzTz3tOk9NlkbTVDGD7SqcaQ/A8tRVKkiFo7J4S25SvSdJg3L1Zzp+rR904KUsHWVIUiR1nCRVEyltM1uAHhP2pYDHoPvJ8+ahrsAEDM+GzyVGbPJYp1lyUN2/4OouF7Z1WKyOpt8Sj8CNSU9MgsdcmlyyBF2BQ7TKHB7gMJ5vUKw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(82960400001)(4326008)(5660300002)(36756003)(186003)(6506007)(7416002)(1076003)(54906003)(6512007)(83380400001)(26005)(66946007)(66476007)(66556008)(316002)(6486002)(38100700002)(8936002)(508600001)(2906002)(30864003)(6666004)(8676002)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?x0kLleus8I8qhBRTQKfbr74CjRCJ?= =?utf-8?q?xW2WCXHtftSMywoZ329/4kprWQzZrqT/vHGMYUW5pvk4/RUQfVhr7AP/Bh8AGbC3M?= =?utf-8?q?cJ5vTsjfn3gd6u/tUawt7ZYuUVAEThqJ+TKLA/B1+RfuWFGxIipsQVbO8N0Jyd0It?= =?utf-8?q?kdsEXutLofXRn5UrWl/eTAJxlHXy7LZX8mbSgHc84fUhI6HvY/z1BKrgOJr3N7cqV?= =?utf-8?q?+HmdpzEQlRUIKY5fZl1B4rt1aDtpXHQFM2AodtEGe93jf2+XK3SAnWqkE4sSefvw/?= =?utf-8?q?Dx1No3wxCeJtLkuAuhKBdj1lR2mlW0EaME/CJCDT4mUiIBr9gtwrjxLj3jrMg3Sm4?= =?utf-8?q?RqVMRxyfufX+TFmq3R7aI/NLnag74RXEpZXP+TDljxQWQKfBiQJf16TyI0viaNK7f?= =?utf-8?q?GyTee3JMUwto8i5ioSZ0l7i7cMdoZcy76tFo/1YMYAmrW2gq37dl/NR2BaJMu+3TW?= =?utf-8?q?ky/IZ9WqV2i5ywYjVTshQSqNFURahR4SliboRu4ogCHrMRyxWnmTfYuAUIgRhVGa7?= =?utf-8?q?rj5VxB9bkzCx2Gl/KvXQBmDh1ny9Y7ERfIkO7TQHq9GjxpmDakNMdz4OdECekRGOM?= =?utf-8?q?32l7H7u3YuWsvutWMyh71VwHNjLB9+KfZX1HkLzBtwLHljT3iewYpuP2TKdShRggw?= =?utf-8?q?jGBDQzkDGawcwJTEZubK7o7y31sTRTyTLE2hO4fD13VVfMJi9NGRx8cAW+YhuGLCV?= =?utf-8?q?ZJFUCxiPO5QCziNe+chSQEKt5rS9FEXwlQaJPlhwpjbxU8S2HC0IwjSOgWj9XYCdS?= =?utf-8?q?kdtrQc2UAw6xu/N+sahUbDCU0CEWaxx7CrPyY/kIzk7ZYLzSSkJpeSIU/eAXabcOV?= =?utf-8?q?utVKKqsj6cJbOYjxX5JpsA7TFoYhVviOosMN9KhSRQ9FVvQNPufEVYPQFedcqfjhZ?= =?utf-8?q?ZVA4OzL/cSWDi14Ne4n6Kriv3gnsLm+01pcpCnhYAKlPYXxFsB/jpo42SgrTJ9FqT?= =?utf-8?q?IYF7vO9NaNsXrEc7Sf1nBui47U4KyP9MOBDzkeAFIPwnxvCB45dYEKpWX9xRFUl0z?= =?utf-8?q?TLhkWxjw/VvDZr34BCViUO86X8yAED3Xs5IHwcu4XGvw6JTAo+wetBS3ywLoUS4IO?= =?utf-8?q?EiruXPlVkfZuHJBQM11RbH8YdVROxhCzvL/GCxzAICwbdKhaegdzQlFlggKPnbmL2?= =?utf-8?q?tNI8XVFbhVi41uDtiAwt+N7VaTDpg95nhrkXPPNfxyNAAzAz78yqRaS62fLehItK/?= =?utf-8?q?KeqebbmGcE21tEdLiwwUAdDW6h1L2RJ4IawY4CQC++XTjD+Y1QIqNUzH98Sl/0VlS?= =?utf-8?q?9Td4A5rwVbGqoKm29U4Pgb8ijH7Uy090T1m49kkeTK+5h0wkXKywbr27Ir3O7qtyR?= =?utf-8?q?8oc9bIVap1SbCQiAeElV3joJ4yEe2bZpa8D9f/I0QwWDUV+99RORngHnUJV7O+Zlx?= =?utf-8?q?SQBzOCBFXJ3z2A1/B8JPSek4gljQ9eHmSjv7id43xtMcpj6H1UVfCzUo/MjOqisHQ?= =?utf-8?q?bbvjrjP2wRtWFbRk2rH/MyUb0bg+ND30dwjGgMcMUS1Praf7DWMXOMVH+y+rEC13W?= =?utf-8?q?Zh4qYd4/J/KHJC1s2D7PjZd5XKz1d8PTN6jrFc8DJJqF8iRIme1Gx9FSGWdD8eOW6?= =?utf-8?q?N3ucaDs/w4ke11XBw1bLqMnRI2fUdFQdg=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: c6f0c31c-b6e4-4d26-4f1a-08d9da1086a8 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2022 23:24:36.5010 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BSwUeou16kHll76Z9u25crM6JAydeUjriX5t0N+BIJo+ErS8UxKcIUsVVQrIU3ILa2cGP1lPbv5nCG9YnTXPG7yv/j3+qp2Iwm/FA0dYNYc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5550 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , Thomas Zimmermann , David Airlie , Brendan Higgins , Daniel Latypov , Arkadiusz Hiler , Petri Latvala Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" igt_dp_mst_calc_pbn_mode was converted one-to-one, igt_dp_mst_sideband_msg_req_decode was refactored to parameterized test. Signed-off-by: Michał Winiarski --- drivers/gpu/drm/selftests/Makefile | 3 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 2 - .../drm/selftests/test-drm_dp_mst_helper.c | 502 ++++++++++++------ .../drm/selftests/test-drm_modeset_common.h | 2 - 4 files changed, 330 insertions(+), 179 deletions(-) diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile index 35f2f40dbaf3..77e37eebf099 100644 --- a/drivers/gpu/drm/selftests/Makefile +++ b/drivers/gpu/drm/selftests/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ test-drm_modeset_common.o \ - test-drm_dp_mst_helper.o \ test-drm_rect.o obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o @@ -9,4 +8,4 @@ obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ test-drm_cmdline_parser.o test-drm_plane_helper.o \ test-drm_format.o test-drm_framebuffer.o \ - test-drm_damage_helper.o + test-drm_damage_helper.o test-drm_dp_mst_helper.o diff --git a/drivers/gpu/drm/selftests/drm_modeset_selftests.h b/drivers/gpu/drm/selftests/drm_modeset_selftests.h index b6a6dba66b64..630770d30aba 100644 --- a/drivers/gpu/drm/selftests/drm_modeset_selftests.h +++ b/drivers/gpu/drm/selftests/drm_modeset_selftests.h @@ -10,5 +10,3 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped) selftest(drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) -selftest(dp_mst_calc_pbn_mode, igt_dp_mst_calc_pbn_mode) -selftest(dp_mst_sideband_msg_req_decode, igt_dp_mst_sideband_msg_req_decode) diff --git a/drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c b/drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c index 6b4759ed6bfd..d0719f3c5a42 100644 --- a/drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c +++ b/drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c @@ -3,54 +3,97 @@ * Test cases for for the DRM DP MST helpers */ -#define PREFIX_STR "[drm_dp_mst_helper]" - +#include #include #include #include #include "../drm_dp_mst_topology_internal.h" -#include "test-drm_modeset_common.h" -int igt_dp_mst_calc_pbn_mode(void *ignored) +struct dp_mst_calc_pbn_mode_test { + int rate; + int bpp; + int expected; + bool dsc; +}; + +static void dp_mst_calc_pbn_mode(struct kunit *test) { - int pbn, i; - const struct { - int rate; - int bpp; - int expected; - bool dsc; - } test_params[] = { - { 154000, 30, 689, false }, - { 234000, 30, 1047, false }, - { 297000, 24, 1063, false }, - { 332880, 24, 50, true }, - { 324540, 24, 49, true }, - }; + const struct dp_mst_calc_pbn_mode_test *params = test->param_value; + int pbn; - for (i = 0; i < ARRAY_SIZE(test_params); i++) { - pbn = drm_dp_calc_pbn_mode(test_params[i].rate, - test_params[i].bpp, - test_params[i].dsc); - FAIL(pbn != test_params[i].expected, - "Expected PBN %d for clock %d bpp %d, got %d\n", - test_params[i].expected, test_params[i].rate, - test_params[i].bpp, pbn); - } + pbn = drm_dp_calc_pbn_mode(params->rate, + params->bpp, + params->dsc); + + KUNIT_EXPECT_EQ(test, pbn, params->expected); +} - return 0; +static const struct dp_mst_calc_pbn_mode_test dp_mst_calc_pbn_mode_tests[] = { + { + .rate = 154000, + .bpp = 30, + .expected = 689, + .dsc = false, + }, + { + .rate = 234000, + .bpp = 30, + .expected = 1047, + .dsc = false, + }, + { + .rate = 297000, + .bpp = 24, + .expected = 1063, + .dsc = false, + }, + { + .rate = 332880, + .bpp = 24, + .expected = 50, + .dsc = true, + }, + { + .rate = 324540, + .bpp = 24, + .expected = 49, + .dsc = true, + }, +}; + +static void dp_mst_calc_pbn_mode_desc(const struct dp_mst_calc_pbn_mode_test *t, + char *desc) +{ + sprintf(desc, "rate = %d, bpp = %d, dsc = %s", + t->rate, t->bpp, t->dsc ? "true" : "false"); } -static bool -sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in, - const struct drm_dp_sideband_msg_req_body *out) +KUNIT_ARRAY_PARAM(dp_mst_calc_pbn_mode, dp_mst_calc_pbn_mode_tests, dp_mst_calc_pbn_mode_desc); + +static void +drm_dp_mst_helper_printfn(struct drm_printer *p, struct va_format *vaf) +{ + struct kunit *test = p->arg; + + kunit_err(test, "%pV", vaf); +} + +static void +expect_sideband_msg_req_equal(struct kunit *test, + const struct drm_dp_sideband_msg_req_body *in, + const struct drm_dp_sideband_msg_req_body *out) { const struct drm_dp_remote_i2c_read_tx *txin, *txout; + struct drm_printer p = { + .printfn = drm_dp_mst_helper_printfn, + .arg = test + }; int i; if (in->req_type != out->req_type) - return false; + goto fail; switch (in->req_type) { /* @@ -65,7 +108,7 @@ sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in, IN.num_transactions != OUT.num_transactions || IN.port_number != OUT.port_number || IN.read_i2c_device_id != OUT.read_i2c_device_id) - return false; + goto fail; for (i = 0; i < IN.num_transactions; i++) { txin = &IN.transactions[i]; @@ -76,11 +119,11 @@ sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in, txin->num_bytes != txout->num_bytes || txin->i2c_transaction_delay != txout->i2c_transaction_delay) - return false; + goto fail; if (memcmp(txin->bytes, txout->bytes, txin->num_bytes) != 0) - return false; + goto fail; } break; #undef IN @@ -92,9 +135,12 @@ sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in, if (IN.dpcd_address != OUT.dpcd_address || IN.num_bytes != OUT.num_bytes || IN.port_number != OUT.port_number) - return false; + goto fail; - return memcmp(IN.bytes, OUT.bytes, IN.num_bytes) == 0; + if (memcmp(IN.bytes, OUT.bytes, IN.num_bytes) != 0) + goto fail; + + break; #undef IN #undef OUT @@ -104,55 +150,65 @@ sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in, if (IN.port_number != OUT.port_number || IN.write_i2c_device_id != OUT.write_i2c_device_id || IN.num_bytes != OUT.num_bytes) - return false; + goto fail; - return memcmp(IN.bytes, OUT.bytes, IN.num_bytes) == 0; + if (memcmp(IN.bytes, OUT.bytes, IN.num_bytes) != 0) + goto fail; + + break; #undef IN #undef OUT default: - return memcmp(in, out, sizeof(*in)) == 0; + if (memcmp(in, out, sizeof(*in)) != 0) + goto fail; } - return true; + return; + +fail: + drm_printf(&p, "Expected:\n"); + drm_dp_dump_sideband_msg_req_body(in, 1, &p); + drm_printf(&p, "Got:\n"); + drm_dp_dump_sideband_msg_req_body(out, 1, &p); + KUNIT_FAIL(test, "Encode/decode failed"); +} + +struct dp_mst_sideband_msg_req_decode_test { + const struct drm_dp_sideband_msg_req_body req; + const struct drm_dp_sideband_msg_req_body + (*f)(const struct drm_dp_sideband_msg_req_body *in); +}; + +const struct drm_dp_sideband_msg_req_body +param_to_dp_mst_sideband_msg_req_body(const struct dp_mst_sideband_msg_req_decode_test *t) +{ + if (t->f) + return t->f(&t->req); + + return t->req; } -static bool -sideband_msg_req_encode_decode(struct drm_dp_sideband_msg_req_body *in) +static void dp_mst_sideband_msg_req_decode(struct kunit *test) { + const struct drm_dp_sideband_msg_req_body in = + param_to_dp_mst_sideband_msg_req_body(test->param_value); struct drm_dp_sideband_msg_req_body *out; - struct drm_printer p = drm_err_printer(PREFIX_STR); struct drm_dp_sideband_msg_tx *txmsg; - int i, ret; - bool result = true; - - out = kzalloc(sizeof(*out), GFP_KERNEL); - if (!out) - return false; - - txmsg = kzalloc(sizeof(*txmsg), GFP_KERNEL); - if (!txmsg) - return false; - - drm_dp_encode_sideband_req(in, txmsg); - ret = drm_dp_decode_sideband_req(txmsg, out); - if (ret < 0) { - drm_printf(&p, "Failed to decode sideband request: %d\n", - ret); - result = false; - goto out; - } + int i; - if (!sideband_msg_req_equal(in, out)) { - drm_printf(&p, "Encode/decode failed, expected:\n"); - drm_dp_dump_sideband_msg_req_body(in, 1, &p); - drm_printf(&p, "Got:\n"); - drm_dp_dump_sideband_msg_req_body(out, 1, &p); - result = false; - goto out; - } + out = kunit_kzalloc(test, sizeof(*out), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, out); - switch (in->req_type) { + txmsg = kunit_kzalloc(test, sizeof(*txmsg), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, txmsg); + + drm_dp_encode_sideband_req(&in, txmsg); + KUNIT_ASSERT_EQ(test, drm_dp_decode_sideband_req(txmsg, out), 0); + + expect_sideband_msg_req_equal(test, &in, out); + + switch (in.req_type) { case DP_REMOTE_DPCD_WRITE: kfree(out->u.dpcd_write.bytes); break; @@ -164,110 +220,210 @@ sideband_msg_req_encode_decode(struct drm_dp_sideband_msg_req_body *in) kfree(out->u.i2c_write.bytes); break; } - - /* Clear everything but the req_type for the input */ - memset(&in->u, 0, sizeof(in->u)); - -out: - kfree(out); - kfree(txmsg); - return result; } -int igt_dp_mst_sideband_msg_req_decode(void *unused) +static u8 data[] = { 0xff, 0x0, 0xdd }; + +const struct drm_dp_sideband_msg_req_body +random_dp_query_enc_client_id(const struct drm_dp_sideband_msg_req_body *in) { - struct drm_dp_sideband_msg_req_body in = { 0 }; - u8 data[] = { 0xff, 0x0, 0xdd }; - int i; + struct drm_dp_query_stream_enc_status enc_status = { }; -#define DO_TEST() FAIL_ON(!sideband_msg_req_encode_decode(&in)) - - in.req_type = DP_ENUM_PATH_RESOURCES; - in.u.port_num.port_number = 5; - DO_TEST(); - - in.req_type = DP_POWER_UP_PHY; - in.u.port_num.port_number = 5; - DO_TEST(); - - in.req_type = DP_POWER_DOWN_PHY; - in.u.port_num.port_number = 5; - DO_TEST(); - - in.req_type = DP_ALLOCATE_PAYLOAD; - in.u.allocate_payload.number_sdp_streams = 3; - for (i = 0; i < in.u.allocate_payload.number_sdp_streams; i++) - in.u.allocate_payload.sdp_stream_sink[i] = i + 1; - DO_TEST(); - in.u.allocate_payload.port_number = 0xf; - DO_TEST(); - in.u.allocate_payload.vcpi = 0x7f; - DO_TEST(); - in.u.allocate_payload.pbn = U16_MAX; - DO_TEST(); - - in.req_type = DP_QUERY_PAYLOAD; - in.u.query_payload.port_number = 0xf; - DO_TEST(); - in.u.query_payload.vcpi = 0x7f; - DO_TEST(); - - in.req_type = DP_REMOTE_DPCD_READ; - in.u.dpcd_read.port_number = 0xf; - DO_TEST(); - in.u.dpcd_read.dpcd_address = 0xfedcb; - DO_TEST(); - in.u.dpcd_read.num_bytes = U8_MAX; - DO_TEST(); - - in.req_type = DP_REMOTE_DPCD_WRITE; - in.u.dpcd_write.port_number = 0xf; - DO_TEST(); - in.u.dpcd_write.dpcd_address = 0xfedcb; - DO_TEST(); - in.u.dpcd_write.num_bytes = ARRAY_SIZE(data); - in.u.dpcd_write.bytes = data; - DO_TEST(); - - in.req_type = DP_REMOTE_I2C_READ; - in.u.i2c_read.port_number = 0xf; - DO_TEST(); - in.u.i2c_read.read_i2c_device_id = 0x7f; - DO_TEST(); - in.u.i2c_read.num_transactions = 3; - in.u.i2c_read.num_bytes_read = ARRAY_SIZE(data) * 3; - for (i = 0; i < in.u.i2c_read.num_transactions; i++) { - in.u.i2c_read.transactions[i].bytes = data; - in.u.i2c_read.transactions[i].num_bytes = ARRAY_SIZE(data); - in.u.i2c_read.transactions[i].i2c_dev_id = 0x7f & ~i; - in.u.i2c_read.transactions[i].i2c_transaction_delay = 0xf & ~i; - } - DO_TEST(); - - in.req_type = DP_REMOTE_I2C_WRITE; - in.u.i2c_write.port_number = 0xf; - DO_TEST(); - in.u.i2c_write.write_i2c_device_id = 0x7f; - DO_TEST(); - in.u.i2c_write.num_bytes = ARRAY_SIZE(data); - in.u.i2c_write.bytes = data; - DO_TEST(); - - in.req_type = DP_QUERY_STREAM_ENC_STATUS; - in.u.enc_status.stream_id = 1; - DO_TEST(); - get_random_bytes(in.u.enc_status.client_id, - sizeof(in.u.enc_status.client_id)); - DO_TEST(); - in.u.enc_status.stream_event = 3; - DO_TEST(); - in.u.enc_status.valid_stream_event = 0; - DO_TEST(); - in.u.enc_status.stream_behavior = 3; - DO_TEST(); - in.u.enc_status.valid_stream_behavior = 1; - DO_TEST(); - -#undef DO_TEST - return 0; + get_random_bytes(enc_status.client_id, sizeof(enc_status.client_id)); + + return (const struct drm_dp_sideband_msg_req_body) { .req_type = in->req_type, + .u.enc_status = enc_status + }; } + +static const struct dp_mst_sideband_msg_req_decode_test dp_msg_sideband_msg_req_decode_tests[] = { + { + .req = { + .req_type = DP_ENUM_PATH_RESOURCES, + .u.port_num.port_number = 5, + }, + }, + { + .req = { + .req_type = DP_POWER_UP_PHY, + .u.port_num.port_number = 5, + }, + }, + { + .req = { + .req_type = DP_POWER_DOWN_PHY, + .u.port_num.port_number = 5, + }, + }, + { + .req = { + .req_type = DP_ALLOCATE_PAYLOAD, + .u.allocate_payload.number_sdp_streams = 3, + .u.allocate_payload.sdp_stream_sink = { 1, 2, 3 }, + }, + }, + { + .req = { + .req_type = DP_ALLOCATE_PAYLOAD, + .u.allocate_payload.port_number = 0xf, + }, + }, + { + .req = { + .req_type = DP_ALLOCATE_PAYLOAD, + .u.allocate_payload.vcpi = 0x7f, + }, + }, + { + .req = { + .req_type = DP_ALLOCATE_PAYLOAD, + .u.allocate_payload.pbn = U16_MAX, + }, + }, + { + .req = { + .req_type = DP_QUERY_PAYLOAD, + .u.query_payload.port_number = 0xf, + }, + }, + { + .req = { + .req_type = DP_QUERY_PAYLOAD, + .u.query_payload.vcpi = 0x7f, + }, + }, + { + .req = { + .req_type = DP_REMOTE_DPCD_READ, + .u.dpcd_read.port_number = 0xf, + }, + }, + { + .req = { + .req_type = DP_REMOTE_DPCD_READ, + .u.dpcd_read.dpcd_address = 0xfedcb, + }, + }, + { + .req = { + .req_type = DP_REMOTE_DPCD_READ, + .u.dpcd_read.num_bytes = U8_MAX, + }, + }, + { + .req = { + .req_type = DP_REMOTE_DPCD_WRITE, + .u.dpcd_write.port_number = 0xf, + }, + }, + { + .req = { + .req_type = DP_REMOTE_DPCD_WRITE, + .u.dpcd_write.dpcd_address = 0xfedcb, + }, + }, + { + .req = { + .req_type = DP_REMOTE_DPCD_WRITE, + .u.dpcd_write.num_bytes = ARRAY_SIZE(data), + .u.dpcd_write.bytes = data, + }, + }, + { + .req = { + .req_type = DP_REMOTE_I2C_READ, + .u.i2c_read.port_number = 0xf, + }, + }, + { + .req = { + .req_type = DP_REMOTE_I2C_READ, + .u.i2c_read.read_i2c_device_id = 0x7f, + }, + }, + { + .req = { + .req_type = DP_REMOTE_I2C_READ, + .u.i2c_read.num_transactions = 3, + .u.i2c_read.num_bytes_read = ARRAY_SIZE(data) * 3, + .u.i2c_read.transactions = { + { .bytes = data, .num_bytes = ARRAY_SIZE(data), + .i2c_dev_id = 0x7f, .i2c_transaction_delay = 0xf, }, + { .bytes = data, .num_bytes = ARRAY_SIZE(data), + .i2c_dev_id = 0x7e, .i2c_transaction_delay = 0xe, }, + { .bytes = data, .num_bytes = ARRAY_SIZE(data), + .i2c_dev_id = 0x7d, .i2c_transaction_delay = 0xd, }, + }, + }, + }, + { + .req = { + .req_type = DP_REMOTE_I2C_WRITE, + .u.i2c_write.port_number = 0xf, + }, + }, + { + .req = { + .req_type = DP_REMOTE_I2C_WRITE, + .u.i2c_write.write_i2c_device_id = 0x7f, + }, + }, + { + .req = { + .req_type = DP_REMOTE_I2C_WRITE, + .u.i2c_write.num_bytes = ARRAY_SIZE(data), + .u.i2c_write.bytes = data, + }, + }, + { + .req = { + .req_type = DP_QUERY_STREAM_ENC_STATUS, + .u.enc_status.stream_id = 1, + }, + }, + { + .req = { + .req_type = DP_QUERY_STREAM_ENC_STATUS, + }, + .f = random_dp_query_enc_client_id, + }, + { + .req = { + .req_type = DP_QUERY_STREAM_ENC_STATUS, + .u.enc_status.stream_event = 3, + }, + }, + { + .req = { + .req_type = DP_QUERY_STREAM_ENC_STATUS, + .u.enc_status.valid_stream_event = 0, + }, + }, + { + .req = { + .req_type = DP_QUERY_STREAM_ENC_STATUS, + .u.enc_status.stream_behavior = 3, + }, + }, + { + .req = { + .req_type = DP_QUERY_STREAM_ENC_STATUS, + .u.enc_status.valid_stream_behavior = 1, + }, + }, +}; + +KUNIT_ARRAY_PARAM(dp_mst_sideband_msg_req, dp_msg_sideband_msg_req_decode_tests, NULL); + +static struct kunit_case drm_dp_mst_helper_tests[] = { + KUNIT_CASE_PARAM(dp_mst_calc_pbn_mode, dp_mst_calc_pbn_mode_gen_params), + KUNIT_CASE_PARAM(dp_mst_sideband_msg_req_decode, dp_mst_sideband_msg_req_gen_params), + {} +}; + +static struct kunit_suite drm_dp_mst_helper_test_suite = { + .name = "drm_dp_mst_helper_tests", + .test_cases = drm_dp_mst_helper_tests, +}; + +kunit_test_suite(drm_dp_mst_helper_test_suite); diff --git a/drivers/gpu/drm/selftests/test-drm_modeset_common.h b/drivers/gpu/drm/selftests/test-drm_modeset_common.h index 1501d99aee2f..c7cc5edc65f1 100644 --- a/drivers/gpu/drm/selftests/test-drm_modeset_common.h +++ b/drivers/gpu/drm/selftests/test-drm_modeset_common.h @@ -20,7 +20,5 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored); int igt_drm_rect_clip_scaled_not_clipped(void *ignored); int igt_drm_rect_clip_scaled_clipped(void *ignored); int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored); -int igt_dp_mst_calc_pbn_mode(void *ignored); -int igt_dp_mst_sideband_msg_req_decode(void *ignored); #endif From patchwork Mon Jan 17 23:22:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 12715733 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 05772C433F5 for ; Mon, 17 Jan 2022 23:24:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BCCBB11254D; Mon, 17 Jan 2022 23:24:54 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3095611254C for ; Mon, 17 Jan 2022 23:24:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642461891; x=1673997891; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=quUmjOVA9Wz2OOMMVV+W8akBlwHVso4xSDK0aYlLTGI=; b=WdNiymqljBk+xjh+DvLZlx/In4j58uuEO+C5XjE5bL8dxDuABwB12aO5 JEpWqBAgdOffCcZuA24faKNEZrc6cQ9jjeK7w+2vVPA9hbwjnuvLnkN10 PUU3IScTTJ+Sz8ZfdHSWoFV88aS3MBdEEZDIaV724pfyJVjrsy5+6M+vi f8sMajMlldVEMKydThYJZF67Ybza5HTzT46VyJrZkLMzXq0hIfQT8qWpB bDyAUrRgSY0PckFVoIFxRIGf66jdNGv7fLl25bhFNIvLoMpWeTys0X8r+ m8wriTLBYoLY0AxeKAPP63OUnmH+Zf9SvEeXIzkGXXZJAvuixwi7TbO/x A==; X-IronPort-AV: E=McAfee;i="6200,9189,10230"; a="244501849" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="244501849" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 15:24:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="517554427" Received: from fmsmsx605.amr.corp.intel.com ([10.18.126.85]) by orsmga007.jf.intel.com with ESMTP; 17 Jan 2022 15:24:48 -0800 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:47 -0800 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:47 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Mon, 17 Jan 2022 15:24:47 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.168) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:46 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MLLmztMb7BhOJ6vS30/zz6+faR0H7kzaMMWcF1czJOB8w75pRCMAY2y5SEoOgJv9O5koyyj9V7tRepLgkY8NFmJgUxQ9LdxH0ZLvnwRZhjDfW/tVf0yDa3wcT1kufx0aYXgqarVcINx7RFDxySiAYdFl+OlQH+84At5z7xl/tt5tPQ3t5EQ6WQLc9E+YIx1OGn1XefMDGK2BdWyvy5s4of01kvGZCqQ3KZRlhNCYhSxC1/37LZjatR9h/AYLFoX7R/CseLsidSozwU2uF58MeW8fNP/QDpn6dk/+Uh/Lut7VTlhcDvu7Rki7WJB2EYjHKGwTVGBTCirbSbH9NGYHdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZeXNZdnDA2vS/Z+sC48PAkzUL7vTuZlZ96DW0e/2av4=; b=D8DQdm5mwQeBRThi4vUacMTekNH4f8vCaBTNqE/pEKe2Oae7g6UXxOSuEDArDgd6hFGhFaNrE48ae/lUINiippDSLv2F5mIFuHqZjSv38jx1EjbE/FDNx5S3cUfveHye+BHonXeb2vw7clTP+ytDU2fFx1KOD37awNxNcoyfPpuIVP7hlDgxiseGqhVpTWedT1ld3bocTgapf/PTknRDYC+bYm1su0bRTDw8s9WH38ga4sRAjRoFdr0yVrWUKCEWaRl1mHdmFjdDZxKkpWynciNfR/p/SFgxnmCbOTO3B3TSwlPGEpfymcjXWfkiVDinGVNsZO5QDiFhXTdakNkCGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by DM4PR11MB5550.namprd11.prod.outlook.com (2603:10b6:5:38b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Mon, 17 Jan 2022 23:24:43 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5%8]) with mapi id 15.20.4888.014; Mon, 17 Jan 2022 23:24:43 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , Subject: [RFC 07/10] drm: test-drm_rect: Convert to KUnit Date: Tue, 18 Jan 2022 00:22:56 +0100 Message-ID: <20220117232259.180459-8-michal.winiarski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220117232259.180459-1-michal.winiarski@intel.com> References: <20220117232259.180459-1-michal.winiarski@intel.com> X-ClientProxiedBy: AS8P251CA0016.EURP251.PROD.OUTLOOK.COM (2603:10a6:20b:2f2::11) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fcea89ac-3b72-43c0-3401-08d9da108adf X-MS-TrafficTypeDiagnostic: DM4PR11MB5550:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:549; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u5Hzi/IG4KCGfvStsW6TLkay3yvPHjzUXKvjo942EBv7/21VSEHSsmUqLkrDE7C+cR32Sip359MHEvySdnKf1/AUz/sR9kE2MycDTU22C0VJ7gbifXVkVmqQuHd9640tsV/0nI4oCLQZVhvZvgQ7VfNxDlqTy9BNsgLMVcyCojE2aONsgHGamwnXEPh4u9LgAM5hqrqTDt+wKsZXNypQr4EGRiaNb5l4NVNU2UMh7PEFbYi+LK4V/Q57/L1cFrfmcfgEMjphkJXUievR923WS2KMjnr4cRBVGPUPE80654W9WZLuraOUSPBfstavStcpswp+Cy463BqzBMVA2z/00ayp+VW0gIh0etvBGxxkR6j//IyOoo36exn8iucU+RoCymbhcRQurodcLcoFuq2Sn3b7b9XluIZADFNQOWD3aNOJO/BfW1SHNhvTBXObOfTT9aohSEvXPKUjkTpZJ0p+HR9eTpfPLRfo38znrDxzb57tF5+Fo46NcLOHAnsPhz0vASfyvDDK9gjFxb89XEe1T00dhTF/sUpWYdnVdaRZO1BYPUebGCTBhnKMDe2ix5SooSBTEp7wczIgZLau83u2FzXN7GzG1i6XpF1o0hlb9KMH6VNU8Pu9BQz0QR3FAeI8IXG1pjVstOBJmuWpcmKFlQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(82960400001)(4326008)(5660300002)(36756003)(186003)(6506007)(7416002)(1076003)(54906003)(6512007)(83380400001)(26005)(66946007)(66476007)(66556008)(316002)(6486002)(38100700002)(8936002)(508600001)(2906002)(30864003)(6666004)(8676002)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?wkDdnZsAC4ojgAlljgXLYAcShcAt?= =?utf-8?q?g1NXh8ujtIEU7Ag11zsuI9kBE/yY4bE0VXKLNiDtC9ZEgQeaIGbj748EXa0eh9E/X?= =?utf-8?q?yXz9m2g32qSzOK74MzijiVsD8yZGLxVBCGyWkl1Nxsl3ngP2BjrC8v7V32UzGSRPi?= =?utf-8?q?6BcUcrLEtvskj86A8l2A0FiLGOLwgP52qqO0Y9vPLEeIhBp6QLDh2ZAcrmvdoEJWl?= =?utf-8?q?rBnrrhoe9hKgM7kjPtJj1RGbRRmS979hhmODN6zZ/kAa8WzKMA+D+KYaTtiMkETKD?= =?utf-8?q?/FMXPLdKr+fGFXg0efX2nSOSHPoCNYjpVafHPqQDRQFFgq5E0UXH8Oxk9QucXDF9i?= =?utf-8?q?b9msxWKAYAy4TG1WcoFrGuNgRWI/lvUHcH/l6eLyxg7jNUPBFHddNebRF0qnPHzu1?= =?utf-8?q?ifv+BmeI6bJBSM6gbRkRoYgVeRaNuqLV0YRBl4MJzt/AnJdSGoA0r7tyaOPkLG5pO?= =?utf-8?q?pCKiBPErvAuBTfQuijbp5IDq3kxqFw0EBq6xnRQqe/s+akZjmeUuogXXlfgsK+jO9?= =?utf-8?q?yDTvK6hGT3qmoYRLR8ABlYixBlGLI5P0ec0odBEqyagbBQTaIlPgnEst6YwSbffMm?= =?utf-8?q?d5peac7YBdUuenwYhi2ieKNd3PWHsclHWZp2ekxhN6HmQvFFwu+40HVR3ZIs4/hP7?= =?utf-8?q?Ejq9vQqB0vR6Guph81uFFr4gnEXpRyktfSchIBUNA9HlgthHWu2w8krxkYrluiJCP?= =?utf-8?q?ANlzqE7gIzM1zdHISPpYxr5XMVL3gmaAatBovu5O8tG+VG/YanieuA67RrrtL0oJd?= =?utf-8?q?QkRJWZBdnbbbvOU4U5IGQa2VqhoEPNT0yl+Jyp/WwlAZGwd2jrCZn3jdl9QBRl50p?= =?utf-8?q?kFwHD2TEVPV7cRnUFZSuCv1YgL9cqLq0uszGBgBv+yxKi+In6GpazaJZ/S8rAlrAs?= =?utf-8?q?fmK50Z8YAq9NUC3XGcdD4RAkt3akbdGwFrm9vEnLqRU0oXoWPw2ynra21C/GLmTHc?= =?utf-8?q?1ufTwResbIzT/QGfCGP7XRHv7ckv6cnociK6Yzqt5Iy9Pk4ywQcCW11O44txSFMJh?= =?utf-8?q?Yd2y2BIvoFJwiuhFzADjxwOhi+f+XP9TQsVg1XN34VXG6zcs3J68tb0miMA6RxNSf?= =?utf-8?q?BDdiGsDKY/Rb8vKIB+zdPTQlVgKjRstIF7glGZaQx8Mhq2tNVx6COfxquCNJqCBPq?= =?utf-8?q?V661iIaCOjgX4SLlMvAi4MGZHxx0gt2+wbXiiUZuZNczHa/qivyxsxGkmLrdRz8d3?= =?utf-8?q?mbxoIa/MShxEl81V8aRRsyjtwVINW9/2hWLBlrRzKKfMVY4LxDBGnd0F86ssH8czB?= =?utf-8?q?Riw8y9d0iVNs8meshlDTbJuxUv2sMWRHss92WVL2ZJgUbmRJSeP4aSRxx9ATBjSds?= =?utf-8?q?7BKde/0aSX/xXLPXJF93HSA9xjluQYa/qwXHSQidfEpT/XF403kiCtIkYsmjeBSmc?= =?utf-8?q?guaQRbHSuvvR/iBtL3Hm6IqbuwSsNVfC01ebQn0aTfykwTngfKAIaoLYGyucIWPVb?= =?utf-8?q?pQJgwiJbsEvIySj8KG/6SwnR+EHhc1v2xbli3w3NEoUrJ2LEfAYC5jPEiqrPJljwN?= =?utf-8?q?PfUkBURoln/sRVU03ds2egwHYF4X5kkjdJJakbuJPTZcA6yLBNt7rrnQksg3YxcyO?= =?utf-8?q?H7rqJIxAOqAb/Q1u52vzWY72l5IWSTVfw=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: fcea89ac-3b72-43c0-3401-08d9da108adf X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2022 23:24:43.5709 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GE/y6zwZdaXuLHlwAa8iKXkyV71L7OOH+bLXHYya68FHAjeAmMjghZI47+VoHN8EOrzpszJ1TBfXIkZ5P0BzK3iIHbnbIT02Nug26ULEjrI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5550 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , Thomas Zimmermann , David Airlie , Brendan Higgins , Daniel Latypov , Arkadiusz Hiler , Petri Latvala Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" One-to-one conversion, no functional changes. Now that all of the modeset selftests were converted, remove the helpers that are no longer used. Signed-off-by: Michał Winiarski --- drivers/gpu/drm/selftests/Makefile | 8 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 12 - .../drm/selftests/test-drm_modeset_common.c | 32 --- .../drm/selftests/test-drm_modeset_common.h | 24 -- drivers/gpu/drm/selftests/test-drm_rect.c | 212 ++++++++++-------- 5 files changed, 122 insertions(+), 166 deletions(-) delete mode 100644 drivers/gpu/drm/selftests/drm_modeset_selftests.h delete mode 100644 drivers/gpu/drm/selftests/test-drm_modeset_common.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_modeset_common.h diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile index 77e37eebf099..2d524eddb4e3 100644 --- a/drivers/gpu/drm/selftests/Makefile +++ b/drivers/gpu/drm/selftests/Makefile @@ -1,11 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only -test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ - test-drm_modeset_common.o \ - test-drm_rect.o -obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o +obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ test-drm_cmdline_parser.o test-drm_plane_helper.o \ test-drm_format.o test-drm_framebuffer.o \ - test-drm_damage_helper.o test-drm_dp_mst_helper.o + test-drm_damage_helper.o test-drm_dp_mst_helper.o \ + test-drm_rect.o diff --git a/drivers/gpu/drm/selftests/drm_modeset_selftests.h b/drivers/gpu/drm/selftests/drm_modeset_selftests.h deleted file mode 100644 index 630770d30aba..000000000000 --- a/drivers/gpu/drm/selftests/drm_modeset_selftests.h +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* List each unit test as selftest(name, function) - * - * The name is used as both an enum and expanded as igt__name to create - * a module parameter. It must be unique and legal for a C identifier. - * - * Tests are executed in order by igt/drm_selftests_helper - */ -selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) -selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) -selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped) -selftest(drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) diff --git a/drivers/gpu/drm/selftests/test-drm_modeset_common.c b/drivers/gpu/drm/selftests/test-drm_modeset_common.c deleted file mode 100644 index 2a7f93774006..000000000000 --- a/drivers/gpu/drm/selftests/test-drm_modeset_common.c +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Common file for modeset selftests. - */ - -#include - -#include "test-drm_modeset_common.h" - -#define TESTS "drm_modeset_selftests.h" -#include "drm_selftest.h" - -#include "drm_selftest.c" - -static int __init test_drm_modeset_init(void) -{ - int err; - - err = run_selftests(selftests, ARRAY_SIZE(selftests), NULL); - - return err > 0 ? 0 : err; -} - -static void __exit test_drm_modeset_exit(void) -{ -} - -module_init(test_drm_modeset_init); -module_exit(test_drm_modeset_exit); - -MODULE_AUTHOR("Intel Corporation"); -MODULE_LICENSE("GPL"); diff --git a/drivers/gpu/drm/selftests/test-drm_modeset_common.h b/drivers/gpu/drm/selftests/test-drm_modeset_common.h deleted file mode 100644 index c7cc5edc65f1..000000000000 --- a/drivers/gpu/drm/selftests/test-drm_modeset_common.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ - -#ifndef __TEST_DRM_MODESET_COMMON_H__ -#define __TEST_DRM_MODESET_COMMON_H__ - -#include -#include - -#define FAIL(test, msg, ...) \ - do { \ - if (test) { \ - pr_err("%s/%u: " msg, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ - return -EINVAL; \ - } \ - } while (0) - -#define FAIL_ON(x) FAIL((x), "%s", "FAIL_ON(" __stringify(x) ")\n") - -int igt_drm_rect_clip_scaled_div_by_zero(void *ignored); -int igt_drm_rect_clip_scaled_not_clipped(void *ignored); -int igt_drm_rect_clip_scaled_clipped(void *ignored); -int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored); - -#endif diff --git a/drivers/gpu/drm/selftests/test-drm_rect.c b/drivers/gpu/drm/selftests/test-drm_rect.c index 3a5ff38321f4..f3d26c31ee66 100644 --- a/drivers/gpu/drm/selftests/test-drm_rect.c +++ b/drivers/gpu/drm/selftests/test-drm_rect.c @@ -3,15 +3,12 @@ * Test cases for the drm_rect functions */ -#define pr_fmt(fmt) "drm_rect: " fmt - +#include #include #include -#include "test-drm_modeset_common.h" - -int igt_drm_rect_clip_scaled_div_by_zero(void *ignored) +static void drm_rect_clip_scaled_div_by_zero(struct kunit *test) { struct drm_rect src, dst, clip; bool visible; @@ -23,21 +20,23 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored) drm_rect_init(&src, 0, 0, 0, 0); drm_rect_init(&dst, 0, 0, 0, 0); drm_rect_init(&clip, 1, 1, 1, 1); + visible = drm_rect_clip_scaled(&src, &dst, &clip); - FAIL(visible, "Destination not be visible\n"); - FAIL(drm_rect_visible(&src), "Source should not be visible\n"); + + KUNIT_EXPECT_FALSE_MSG(test, visible, "Destination not be visible"); + KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible"); drm_rect_init(&src, 0, 0, 0, 0); drm_rect_init(&dst, 3, 3, 0, 0); drm_rect_init(&clip, 1, 1, 1, 1); + visible = drm_rect_clip_scaled(&src, &dst, &clip); - FAIL(visible, "Destination not be visible\n"); - FAIL(drm_rect_visible(&src), "Source should not be visible\n"); - return 0; + KUNIT_EXPECT_FALSE_MSG(test, visible, "Destination not be visible"); + KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible"); } -int igt_drm_rect_clip_scaled_not_clipped(void *ignored) +static void drm_rect_clip_scaled_not_clipped(struct kunit *test) { struct drm_rect src, dst, clip; bool visible; @@ -49,14 +48,16 @@ int igt_drm_rect_clip_scaled_not_clipped(void *ignored) visible = drm_rect_clip_scaled(&src, &dst, &clip); - FAIL(src.x1 != 0 || src.x2 != 1 << 16 || - src.y1 != 0 || src.y2 != 1 << 16, - "Source badly clipped\n"); - FAIL(dst.x1 != 0 || dst.x2 != 1 || - dst.y1 != 0 || dst.y2 != 1, - "Destination badly clipped\n"); - FAIL(!visible, "Destination should be visible\n"); - FAIL(!drm_rect_visible(&src), "Source should be visible\n"); + KUNIT_EXPECT_TRUE_MSG(test, + src.x1 == 0 && src.x2 == 1 << 16 && + src.y1 == 0 && src.y2 == 1 << 16, + "Source badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, + dst.x1 == 0 && dst.x2 == 1 && + dst.y1 == 0 && dst.y2 == 1, + "Destination badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible"); + KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible"); /* 2:1 scaling */ drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16); @@ -65,14 +66,16 @@ int igt_drm_rect_clip_scaled_not_clipped(void *ignored) visible = drm_rect_clip_scaled(&src, &dst, &clip); - FAIL(src.x1 != 0 || src.x2 != 2 << 16 || - src.y1 != 0 || src.y2 != 2 << 16, - "Source badly clipped\n"); - FAIL(dst.x1 != 0 || dst.x2 != 1 || - dst.y1 != 0 || dst.y2 != 1, - "Destination badly clipped\n"); - FAIL(!visible, "Destination should be visible\n"); - FAIL(!drm_rect_visible(&src), "Source should be visible\n"); + KUNIT_EXPECT_TRUE_MSG(test, + src.x1 == 0 && src.x2 == 2 << 16 && + src.y1 == 0 && src.y2 == 2 << 16, + "Source badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, + dst.x1 == 0 && dst.x2 == 1 && + dst.y1 == 0 && dst.y2 == 1, + "Destination badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible"); + KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible"); /* 1:2 scaling */ drm_rect_init(&src, 0, 0, 1 << 16, 1 << 16); @@ -81,19 +84,19 @@ int igt_drm_rect_clip_scaled_not_clipped(void *ignored) visible = drm_rect_clip_scaled(&src, &dst, &clip); - FAIL(src.x1 != 0 || src.x2 != 1 << 16 || - src.y1 != 0 || src.y2 != 1 << 16, - "Source badly clipped\n"); - FAIL(dst.x1 != 0 || dst.x2 != 2 || - dst.y1 != 0 || dst.y2 != 2, - "Destination badly clipped\n"); - FAIL(!visible, "Destination should be visible\n"); - FAIL(!drm_rect_visible(&src), "Source should be visible\n"); - - return 0; + KUNIT_EXPECT_TRUE_MSG(test, + src.x1 == 0 && src.x2 == 1 << 16 && + src.y1 == 0 && src.y2 == 1 << 16, + "Source badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, + dst.x1 == 0 && dst.x2 == 2 && + dst.y1 == 0 && dst.y2 == 2, + "Destination badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible"); + KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible"); } -int igt_drm_rect_clip_scaled_clipped(void *ignored) +static void drm_rect_clip_scaled_clipped(struct kunit *test) { struct drm_rect src, dst, clip; bool visible; @@ -105,14 +108,16 @@ int igt_drm_rect_clip_scaled_clipped(void *ignored) visible = drm_rect_clip_scaled(&src, &dst, &clip); - FAIL(src.x1 != 0 || src.x2 != 1 << 16 || - src.y1 != 0 || src.y2 != 1 << 16, - "Source badly clipped\n"); - FAIL(dst.x1 != 0 || dst.x2 != 1 || - dst.y1 != 0 || dst.y2 != 1, - "Destination badly clipped\n"); - FAIL(!visible, "Destination should be visible\n"); - FAIL(!drm_rect_visible(&src), "Source should be visible\n"); + KUNIT_EXPECT_TRUE_MSG(test, + src.x1 == 0 && src.x2 == 1 << 16 && + src.y1 == 0 && src.y2 == 1 << 16, + "Source badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, + dst.x1 == 0 && dst.x2 == 1 && + dst.y1 == 0 && dst.y2 == 1, + "Destination badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible"); + KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible"); /* 1:1 scaling bottom/right clip */ drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16); @@ -121,14 +126,16 @@ int igt_drm_rect_clip_scaled_clipped(void *ignored) visible = drm_rect_clip_scaled(&src, &dst, &clip); - FAIL(src.x1 != 1 << 16 || src.x2 != 2 << 16 || - src.y1 != 1 << 16 || src.y2 != 2 << 16, - "Source badly clipped\n"); - FAIL(dst.x1 != 1 || dst.x2 != 2 || - dst.y1 != 1 || dst.y2 != 2, - "Destination badly clipped\n"); - FAIL(!visible, "Destination should be visible\n"); - FAIL(!drm_rect_visible(&src), "Source should be visible\n"); + KUNIT_EXPECT_TRUE_MSG(test, + src.x1 == 1 << 16 && src.x2 == 2 << 16 && + src.y1 == 1 << 16 && src.y2 == 2 << 16, + "Source badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, + dst.x1 == 1 && dst.x2 == 2 && + dst.y1 == 1 && dst.y2 == 2, + "Destination badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible"); + KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible"); /* 2:1 scaling top/left clip */ drm_rect_init(&src, 0, 0, 4 << 16, 4 << 16); @@ -137,14 +144,16 @@ int igt_drm_rect_clip_scaled_clipped(void *ignored) visible = drm_rect_clip_scaled(&src, &dst, &clip); - FAIL(src.x1 != 0 || src.x2 != 2 << 16 || - src.y1 != 0 || src.y2 != 2 << 16, - "Source badly clipped\n"); - FAIL(dst.x1 != 0 || dst.x2 != 1 || - dst.y1 != 0 || dst.y2 != 1, - "Destination badly clipped\n"); - FAIL(!visible, "Destination should be visible\n"); - FAIL(!drm_rect_visible(&src), "Source should be visible\n"); + KUNIT_EXPECT_TRUE_MSG(test, + src.x1 == 0 && src.x2 == 2 << 16 && + src.y1 == 0 && src.y2 == 2 << 16, + "Source badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, + dst.x1 == 0 && dst.x2 == 1 && + dst.y1 == 0 && dst.y2 == 1, + "Destination badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible"); + KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible"); /* 2:1 scaling bottom/right clip */ drm_rect_init(&src, 0, 0, 4 << 16, 4 << 16); @@ -153,14 +162,16 @@ int igt_drm_rect_clip_scaled_clipped(void *ignored) visible = drm_rect_clip_scaled(&src, &dst, &clip); - FAIL(src.x1 != 2 << 16 || src.x2 != 4 << 16 || - src.y1 != 2 << 16 || src.y2 != 4 << 16, - "Source badly clipped\n"); - FAIL(dst.x1 != 1 || dst.x2 != 2 || - dst.y1 != 1 || dst.y2 != 2, - "Destination badly clipped\n"); - FAIL(!visible, "Destination should be visible\n"); - FAIL(!drm_rect_visible(&src), "Source should be visible\n"); + KUNIT_EXPECT_TRUE_MSG(test, + src.x1 == 2 << 16 && src.x2 == 4 << 16 && + src.y1 == 2 << 16 && src.y2 == 4 << 16, + "Source badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, + dst.x1 == 1 && dst.x2 == 2 && + dst.y1 == 1 && dst.y2 == 2, + "Destination badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible"); + KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible"); /* 1:2 scaling top/left clip */ drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16); @@ -169,14 +180,16 @@ int igt_drm_rect_clip_scaled_clipped(void *ignored) visible = drm_rect_clip_scaled(&src, &dst, &clip); - FAIL(src.x1 != 0 || src.x2 != 1 << 16 || - src.y1 != 0 || src.y2 != 1 << 16, - "Source badly clipped\n"); - FAIL(dst.x1 != 0 || dst.x2 != 2 || - dst.y1 != 0 || dst.y2 != 2, - "Destination badly clipped\n"); - FAIL(!visible, "Destination should be visible\n"); - FAIL(!drm_rect_visible(&src), "Source should be visible\n"); + KUNIT_EXPECT_TRUE_MSG(test, + src.x1 == 0 && src.x2 == 1 << 16 && + src.y1 == 0 && src.y2 == 1 << 16, + "Source badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, + dst.x1 == 0 && dst.x2 == 2 && + dst.y1 == 0 && dst.y2 == 2, + "Destination badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible"); + KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible"); /* 1:2 scaling bottom/right clip */ drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16); @@ -185,19 +198,19 @@ int igt_drm_rect_clip_scaled_clipped(void *ignored) visible = drm_rect_clip_scaled(&src, &dst, &clip); - FAIL(src.x1 != 1 << 16 || src.x2 != 2 << 16 || - src.y1 != 1 << 16 || src.y2 != 2 << 16, - "Source badly clipped\n"); - FAIL(dst.x1 != 2 || dst.x2 != 4 || - dst.y1 != 2 || dst.y2 != 4, - "Destination badly clipped\n"); - FAIL(!visible, "Destination should be visible\n"); - FAIL(!drm_rect_visible(&src), "Source should be visible\n"); - - return 0; + KUNIT_EXPECT_TRUE_MSG(test, + src.x1 == 1 << 16 && src.x2 == 2 << 16 && + src.y1 == 1 << 16 && src.y2 == 2 << 16, + "Source badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, + dst.x1 == 2 && dst.x2 == 4 && + dst.y1 == 2 && dst.y2 == 4, + "Destination badly clipped"); + KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible"); + KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible"); } -int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored) +static void drm_rect_clip_scaled_signed_vs_unsigned(struct kunit *test) { struct drm_rect src, dst, clip; bool visible; @@ -216,8 +229,21 @@ int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored) visible = drm_rect_clip_scaled(&src, &dst, &clip); - FAIL(visible, "Destination should not be visible\n"); - FAIL(drm_rect_visible(&src), "Source should not be visible\n"); - - return 0; + KUNIT_EXPECT_FALSE_MSG(test, visible, "Destination should not be visible"); + KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible"); } + +static struct kunit_case drm_rect_tests[] = { + KUNIT_CASE(drm_rect_clip_scaled_div_by_zero), + KUNIT_CASE(drm_rect_clip_scaled_not_clipped), + KUNIT_CASE(drm_rect_clip_scaled_clipped), + KUNIT_CASE(drm_rect_clip_scaled_signed_vs_unsigned), + {} +}; + +static struct kunit_suite drm_rect_test_suite = { + .name = "drm_rect_tests", + .test_cases = drm_rect_tests, +}; + +kunit_test_suite(drm_rect_test_suite); From patchwork Mon Jan 17 23:22:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 12715735 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0667C433F5 for ; Mon, 17 Jan 2022 23:24:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AC74811254E; Mon, 17 Jan 2022 23:24:58 +0000 (UTC) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8BC79112550 for ; Mon, 17 Jan 2022 23:24:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642461896; x=1673997896; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=jEPKgMh3k4IVfr7/FQbu0bJJzFHjNDfFfVVOAqwByDM=; b=U3fxly/gxDnysX0Q9xE5NRdVU8YNQf717fxOvF4Jj+7RL264yXf9VQl/ O43bItqIab9H1zP1vuX1MibgBWS/m04Y32B7pL6JQ6jK+IlfUZZiRG/wN 0FeT0EF+kXEazbgKiqo6fUNgiw4mpqrbpYnsrAjH+OAKK/IIlqYWX3h/5 /frWXoox59AZ6ybL1Rwc8gtqS5xBLWRd9T69yvu+vLQnZCsbR9pcNa6F6 jj6CJveCLgNgPBnj6L+Km60CGKUHXPpB6SxZ656npQyve05YAjVx4fSSQ MaDIgj7jq6laXbtqWlz25UGvMOWUnel7bhqj29MIkxaHh76nZBGK7U2wL A==; X-IronPort-AV: E=McAfee;i="6200,9189,10230"; a="308043724" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="308043724" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 15:24:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="474580704" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orsmga003.jf.intel.com with ESMTP; 17 Jan 2022 15:24:55 -0800 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:55 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:54 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Mon, 17 Jan 2022 15:24:54 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.171) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Mon, 17 Jan 2022 15:24:54 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jcwXeGD69pTEQCGRRUejjydXUzDE6HvVbv2TpxdFY+eMCK/krUnuz8vjwGjdvre/DF02i4GhFpZMY3t0oQRo9qpBFqg8QBYOrrM+jOGCV7jOZgv/SGYJ2RZyEIURb6fjeXd0p71g3aSaom6cAcpyd97CXREv5QY/3ybQR9P6vxjk4RoRrWqMydDA1KMljxYVHevYSQy4Fe5AS7Y3/hkv4GwSP3Uey93hNB9dxaTh4ParWHd05lQuLB2C2EfsPMn6/mMf+rDRajYGkW9FFGJSlvpLl5rOCuwGWTgGeXCa2jjxVsBgtXLydrIrGxqxS1GlCrZlNawGvrP1kyTtz0+3ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=po5keolcRjxsUkhoyTRHmzxZIdvLaBhoA/+mtn7L90Q=; b=W11etkxKUh0+8k7xumsvLKouV+j7Poy9fAOF3lx4OmJXzLzGw9MKwqs+Cs4eiyD2izqDY294OZpYE6mIsamFCEwabuGftU/dS/H8Hf0SsJ4N6tsemcJljSMSgCA/9pQQPIYDBIZMzPbAN3l8fyCZMBzcUPvb2U1kGpbOsa/+FpjQvtFhpYCDprkcWWOQW9XCUFfns9C9YI6Hfwl4qCWp0fG5G9GcuUm6YdFHhvfhymN/Ruy6EWOPH/FWHP2sKlWGpNrUTzOhqQ9IT9DsykKjObGvaAsT9kuuWKx0pu8TVh0TN66OjvRRyg+V1/NeNls8aKc6aaIK71naGbwagH3/gA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by DM4PR11MB5550.namprd11.prod.outlook.com (2603:10b6:5:38b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Mon, 17 Jan 2022 23:24:49 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5%8]) with mapi id 15.20.4888.014; Mon, 17 Jan 2022 23:24:49 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , Subject: [RFC 08/10] drm: test-drm_mm: Convert to KUnit Date: Tue, 18 Jan 2022 00:22:57 +0100 Message-ID: <20220117232259.180459-9-michal.winiarski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220117232259.180459-1-michal.winiarski@intel.com> References: <20220117232259.180459-1-michal.winiarski@intel.com> X-ClientProxiedBy: LO2P123CA0089.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:138::22) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 65f001e8-663c-406b-ed7e-08d9da108e6b X-MS-TrafficTypeDiagnostic: DM4PR11MB5550:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:826; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: plL73FbcA93G4G5U565WTSVPlftHvGt8Ec8QAENOve5/QFGVo/vECLx/15dBJ9wvk6WeIl1HwfzKSwfcvZmQjrdMABLcDb+mO7/hvloIs/NQO3cjwSqH06Lq01ucS+UKoFlTbZEYkLbDe9Y+WnUU4BPKEjAsYsxtPs6Rps97sIZdLXr7KQcNKhQWRCofaCzSiwNzhmSj8fJdEq4Rx+Q+xEJc1SmyYwit44euQCb+6RGN5MVLhZNOKNAzTRb9wLQoUc9BEaLhGy8/PrID0TewoWdE3Vtjqy6DeOrybnNgQltyTrQ7JXsQZklIM23MuecJODMygLKpQlwfIvdr7JvJJqzxdt635jCCQqfgn7C9hzPkMIzz1z+y1akUJeI0em9erfmimbRK6pZYdFqGwDXprlg4OQOZpRyBcKNRlGXId0ueyFXC36e39lHZSRK6sm6V6utgiatKdEtdKevEN/ljcsB4dpLfv9UgDcqCJqxE7rs8uFZFI8LE7b3IMT1TrsnMhfrVeof4AJ7CP4xSagVAXmjA2y0jvK21/Fq8C/ZevibgU8ndAAZMZ1w/+9h0e/z2JnBnGlGDOLohhv0q2pmc5kPJr6Y5AFYMWuLb91KUy61GJ2sE5I+HozbDULjfYG/JN1sWEeD914maf/p/vXxKtQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(82960400001)(4326008)(5660300002)(36756003)(186003)(6506007)(7416002)(40140700001)(1076003)(54906003)(6512007)(83380400001)(26005)(66946007)(66476007)(66556008)(316002)(6486002)(38100700002)(8936002)(508600001)(2906002)(30864003)(6666004)(8676002)(2616005)(559001)(579004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?VKFB2y1C65Tn3/WqCorjCJHlKU30?= =?utf-8?q?3/aWfoOY/DYFUXoqAfQ6511QUSwqHeGJteJQeXb1uv1DM3Gbkz0W5fe3oGdZRydKj?= =?utf-8?q?D84gWNKM5HckBMjjIJPc2O6CtXqadESpa/IPDTU2VZnxM2QPz2vy3wQTM+BYbrXwO?= =?utf-8?q?amYBZ2ruRbi1Go/ndn6SOUHwIECOZRiP702bTF0k6cSjBNsfqWj1YQyHZHIfyfWgX?= =?utf-8?q?6okR09fDF9tjgdi6MawBKty8YeH1KiGmcYC70pt3UeuK+7kppxer5Wi0yyaSKzNH+?= =?utf-8?q?uJFXVJYcwFAa4H2wDI/ia/SVkjhWCNBy/3zJZ7AGisqPaFwtOGyA7zVtRPavIZuZ1?= =?utf-8?q?Z5xIToqhYnkZ1ykwdnKjoAuEiLQKqZ7Y9h7+wH5W0J/iLAMqDZRvCc+Pc50oaXfrR?= =?utf-8?q?ZhT6fHUzUKdmF80xM2yBoz4Mg3fqFV6gFQp3X7VjMAfgHJXqH62TXJljZ4KosE8pg?= =?utf-8?q?+4wIVXC8UjqYMXEzCgjnPWaLJDT8WKGpaux/sRdDYcliRrHxLA648Rhn0TtT2XE/e?= =?utf-8?q?ICGGLcRmblbHDfsxqRfS/MpiYgpaARaJIIhB10Hb0Dqfc4gY6AoP/VmbD/nDlmmka?= =?utf-8?q?lLbR4qbGfMGgnnuCCis1nPMzrizEnSGvWTc/L0AEpqLL5XWnSWg3Hpk9cZYiHw6x7?= =?utf-8?q?1TSfBpiGY3ERVqxt1mqQrKGANmsfQZ+WtifPA+NxmpqN6pL1U+/UBVnOj51bXN9He?= =?utf-8?q?3bb+N9IdLGJ4BEpJs1u1aFt6LcY0xDaXxe0ZCKl55nKGcSgLeGlBbi514F0JRFJTz?= =?utf-8?q?7XZfSlhgxdZ4u4AYjwZlfbJEc6buHCWtUk2aHDKCpHbOykFTUVjRdvpXmPm5+esSP?= =?utf-8?q?zEMFbbB4wHjr0P0o1VwCDYB83y8Gsy23SKxhPSuvvAKmX4enAPhP1CBNXwrhum08p?= =?utf-8?q?Fe5y9rXtxVwMzrcW4FwU+Le1P3A3VeU+O20xYZ4drX1D67mOMaGGmqXixUA2XEuDz?= =?utf-8?q?Yt6XTbSKn+SJWlFqolmEN5VOfsfgWKfjTV6eRkkB9sixvVJjYQLDPnoGAILG2SnIv?= =?utf-8?q?pBWsOhmnlZ9zAulxDfFX2yf3ZobJW9hNSXAPdA70oIEafIPZcIZZMkiNYU5yuODFI?= =?utf-8?q?y1v002HLfmYcEjFBIAmOQmdJgvkIb08gu5x+QKBaLrdCYW8TIMIdYykpISKR3UTfQ?= =?utf-8?q?CajI+uf4Lns3EdIQFaiPFuybCBjhaua9QnIMUZZHSUlu+6M+qFPdYnmc/ug/JjyT6?= =?utf-8?q?ueRImDnz2tmXHyIYqcUjQ+klQXneflbu+UDxJ+FnMUrVJOUBD+dJNSAQYcFQWhI/b?= =?utf-8?q?sXGdQXWkh06rEmirbqZrc3KWg4SeaWCVWkKM7qNXMraYgjcFjEWMG12Bq/Djq8ma+?= =?utf-8?q?IGicFrWRJbTwihwBkktl/8sQX1QawTbpuvz6ixfzOYsjc3BCcK2ndu3o2Gukz+baI?= =?utf-8?q?N6oRFGKsrpaTT9CHHybQqRldvjhWs4xKeU96G6vC9mceepIOuftaWuHhW5jdF7Mwr?= =?utf-8?q?E9McXz2ifE6RTZhkPq/qQszVMTksLLVAijx0Z0d1ANDxUxxOlPukHJV3//vv/+FNR?= =?utf-8?q?L/pU9WsRfQkOGCg8Tcsjx13WH/uiSj0Ru56z9hP2jXIkHFjjp18y+nu9761aD+xfD?= =?utf-8?q?AJi2Kfc4DX+F7Zy2p2ALwcMXFr26lFa4w=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 65f001e8-663c-406b-ed7e-08d9da108e6b X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2022 23:24:49.6999 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4Si/O7/ldwS1sLn/TgbiZS2JS930x9enfbLQem1A/wjiQ64l5vPGfTn/cl7F2k5K0W2MgzNjz4uVmcIbHsiWPk2ngktR5f2IhMzNlyctw1M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5550 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , Thomas Zimmermann , David Airlie , Brendan Higgins , Daniel Latypov , Arkadiusz Hiler , Petri Latvala Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Tests that were looping over param (or combination of params) were converted to parameterized test cases. While the conversion should be roughly functionally equivalent, there are changes in the test content and organization: * sanitycheck was dropped (as it was only testing the test framework) * both evict and color got a "sanitycheck" extracted as a separate test * insert_outside_range was extracted as a separate test * evict_range and color_evict_range were removed and expressed as input parameters to evict and color_evict It's still possible to use modparams to change the number of iterations, or force specific seed e.g. by passing the following to kunit.py: --kernel_args 'test_drm_mm.random_seed=X' Signed-off-by: Michał Winiarski --- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/selftests/Makefile | 4 +- drivers/gpu/drm/selftests/drm_mm_selftests.h | 28 - drivers/gpu/drm/selftests/test-drm_mm.c | 3187 +++++++++--------- 4 files changed, 1566 insertions(+), 1655 deletions(-) delete mode 100644 drivers/gpu/drm/selftests/drm_mm_selftests.h diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 89be0df7b0e9..c567324c96b9 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -84,6 +84,8 @@ config DRM_KUNIT_TEST bool "DRM tests" if !KUNIT_ALL_TESTS depends on DRM=y && KUNIT=y select DRM_KMS_HELPER + select PRIME_NUMBERS + select DRM_LIB_RANDOM default KUNIT_ALL_TESTS help Enables unit tests for DRM. Only useful for kernel devs running KUnit. diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile index 2d524eddb4e3..3bc89b71f9f9 100644 --- a/drivers/gpu/drm/selftests/Makefile +++ b/drivers/gpu/drm/selftests/Makefile @@ -1,9 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o - obj-$(CONFIG_DRM_KUNIT_TEST) := \ test-drm_cmdline_parser.o test-drm_plane_helper.o \ test-drm_format.o test-drm_framebuffer.o \ test-drm_damage_helper.o test-drm_dp_mst_helper.o \ - test-drm_rect.o + test-drm_rect.o test-drm_mm.o diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h deleted file mode 100644 index 8c87c964176b..000000000000 --- a/drivers/gpu/drm/selftests/drm_mm_selftests.h +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* List each unit test as selftest(name, function) - * - * The name is used as both an enum and expanded as igt__name to create - * a module parameter. It must be unique and legal for a C identifier. - * - * Tests are executed in order by igt/drm_mm - */ -selftest(sanitycheck, igt_sanitycheck) /* keep first (selfcheck for igt) */ -selftest(init, igt_init) -selftest(debug, igt_debug) -selftest(reserve, igt_reserve) -selftest(insert, igt_insert) -selftest(replace, igt_replace) -selftest(insert_range, igt_insert_range) -selftest(align, igt_align) -selftest(frag, igt_frag) -selftest(align32, igt_align32) -selftest(align64, igt_align64) -selftest(evict, igt_evict) -selftest(evict_range, igt_evict_range) -selftest(bottomup, igt_bottomup) -selftest(lowest, igt_lowest) -selftest(topdown, igt_topdown) -selftest(highest, igt_highest) -selftest(color, igt_color) -selftest(color_evict, igt_color_evict) -selftest(color_evict_range, igt_color_evict_range) diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c index b768b53c4aee..66eca33c8e2f 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -3,8 +3,8 @@ * Test cases for the drm_mm range manager */ -#define pr_fmt(fmt) "drm_mm: " fmt - +#include +#include #include #include #include @@ -16,13 +16,152 @@ #include "../lib/drm_random.h" -#define TESTS "drm_mm_selftests.h" -#include "drm_selftest.h" - static unsigned int random_seed; static unsigned int max_iterations = 8192; static unsigned int max_prime = 128; +static struct kunit_suite drm_mm_test_suite; + +#define DRM_MM_PARAM0_MASK GENMASK(7, 0) +#define DRM_MM_PARAM1_MASK GENMASK(15, 8) +#define DRM_MM_PARAM2_MASK GENMASK(23, 16) +#define DRM_MM_PARAM_VALID BIT(31) + +static bool param_valid(const unsigned long param) +{ + return param & DRM_MM_PARAM_VALID; +} + +#define DRM_MM_PRIME_MASK (DRM_MM_PARAM0_MASK) +static const unsigned long prime_gen_param(const unsigned long param, + const unsigned long prime_limit) +{ + unsigned int prime = FIELD_GET(DRM_MM_PRIME_MASK, param); + + BUILD_BUG_ON(prime_limit > FIELD_MAX(DRM_MM_PRIME_MASK)); + + if (!param_valid(param)) + prime = 1; + else + prime = next_prime_number(prime); + + if (prime > min_t(unsigned int, prime_limit, max_prime)) + return 0; + + return FIELD_PREP(DRM_MM_PRIME_MASK, prime) | DRM_MM_PARAM_VALID; +} + +#define DRM_MM_OP_MASK (DRM_MM_PARAM1_MASK) +static const unsigned long ops_gen_param(const unsigned long param, + const unsigned long ops_limit) +{ + unsigned int index = FIELD_GET(DRM_MM_OP_MASK, param); + + BUILD_BUG_ON(ops_limit > FIELD_MAX(DRM_MM_OP_MASK)); + + if (!param_valid(param)) + index = 0; + else + index++; + + if (index >= ops_limit) + return 0; + + return FIELD_PREP(DRM_MM_OP_MASK, index) | DRM_MM_PARAM_VALID; +} + +#define DRM_MM_MODE_MASK (DRM_MM_PARAM2_MASK) +static const unsigned long mode_gen_param(const unsigned long param, + const unsigned int mode_limit) +{ + unsigned int mode = FIELD_GET(DRM_MM_MODE_MASK, param); + + BUILD_BUG_ON(mode_limit > FIELD_MAX(DRM_MM_MODE_MASK)); + + if (!param_valid(param)) + mode = 0; + else + mode++; + + if (mode >= mode_limit) + return 0; + + return FIELD_PREP(DRM_MM_MODE_MASK, mode) | DRM_MM_PARAM_VALID; +} + +static const unsigned long prime_ops_gen_param(const unsigned long param, + const unsigned int prime_limit, + const unsigned int ops_limit) +{ + unsigned int prime_param; + unsigned int ops_param; + + if (!param_valid(param)) + prime_param = prime_gen_param(param, prime_limit); + else + prime_param = (param & DRM_MM_PRIME_MASK) | DRM_MM_PARAM_VALID; + + ops_param = ops_gen_param(param, ops_limit); + if (!param_valid(ops_param)) { + prime_param = prime_gen_param(param, prime_limit); + ops_param = ops_gen_param(ops_param, ops_limit); + } + + if (!param_valid(prime_param)) + return 0; + + return prime_param | ops_param; +} + +static const unsigned long mode_ops_gen_param(const unsigned long param, + const unsigned int mode_limit, + const unsigned int ops_limit) +{ + unsigned int mode_param; + unsigned int ops_param; + + if (!param_valid(param)) + mode_param = mode_gen_param(param, mode_limit); + else + mode_param = (param & DRM_MM_MODE_MASK) | DRM_MM_PARAM_VALID; + + ops_param = ops_gen_param(param, ops_limit); + if (!param_valid(ops_param)) { + mode_param = mode_gen_param(param, mode_limit); + ops_param = ops_gen_param(ops_param, ops_limit); + } + + if (!param_valid(mode_param)) + return 0; + + return mode_param | ops_param; +} + +static const unsigned long mode_prime_ops_gen_param(const unsigned long param, + const unsigned int mode_limit, + const unsigned int prime_limit, + const unsigned int ops_limit) +{ + unsigned int mode_param; + unsigned int prime_ops_param; + + if (!param_valid(param)) + mode_param = mode_gen_param(param, mode_limit); + else + mode_param = (param & DRM_MM_MODE_MASK) | DRM_MM_PARAM_VALID; + + prime_ops_param = prime_ops_gen_param(param, prime_limit, ops_limit); + if (!param_valid(prime_ops_param)) { + mode_param = mode_gen_param(param, mode_limit); + prime_ops_param = prime_ops_gen_param(prime_ops_param, prime_limit, ops_limit); + } + + if (!param_valid(mode_param)) + return 0; + + return mode_param | prime_ops_param; +} + enum { BEST, BOTTOMUP, @@ -38,20 +177,34 @@ static const struct insert_mode { [BOTTOMUP] = { "bottom-up", DRM_MM_INSERT_LOW }, [TOPDOWN] = { "top-down", DRM_MM_INSERT_HIGH }, [EVICT] = { "evict", DRM_MM_INSERT_EVICT }, - {} }, evict_modes[] = { { "bottom-up", DRM_MM_INSERT_LOW }, { "top-down", DRM_MM_INSERT_HIGH }, - {} }; -static int igt_sanitycheck(void *ignored) +static void kunit_drm_mm_print_params(void) { - pr_info("%s - ok!\n", __func__); - return 0; + kunit_log(KERN_INFO, &drm_mm_test_suite, + "Testing DRM range manager (struct drm_mm), with random_seed=%#x max_iterations=%u max_prime=%u", + random_seed, max_iterations, max_prime); +} + +static void +drm_mm_printfn(struct drm_printer *p, struct va_format *vaf) +{ + struct kunit *test = p->arg; + + kunit_info(test, "%pV", vaf); } -static bool assert_no_holes(const struct drm_mm *mm) +#define show_mm(test, mm) \ + do { \ + struct drm_printer __p = { .printfn = drm_mm_printfn, .arg = (test) }; \ + drm_mm_print((mm), &__p); \ + } while (0) + +static bool +has_no_holes(struct kunit *test, const struct drm_mm *mm) { struct drm_mm_node *hole; u64 hole_start, __always_unused hole_end; @@ -61,13 +214,17 @@ static bool assert_no_holes(const struct drm_mm *mm) drm_mm_for_each_hole(hole, mm, hole_start, hole_end) count++; if (count) { - pr_err("Expected to find no holes (after reserve), found %lu instead\n", count); + show_mm(test, mm); + kunit_err(test, + "Expected to find no holes (after reserve), found %lu instead\n", + count); return false; } drm_mm_for_each_node(hole, mm) { if (drm_mm_hole_follows(hole)) { - pr_err("Hole follows node, expected none!\n"); + show_mm(test, mm); + kunit_err(test, "Hole follows node, expected none!\n"); return false; } } @@ -75,7 +232,8 @@ static bool assert_no_holes(const struct drm_mm *mm) return true; } -static bool assert_one_hole(const struct drm_mm *mm, u64 start, u64 end) +static bool +has_one_hole(struct kunit *test, const struct drm_mm *mm, u64 start, u64 end) { struct drm_mm_node *hole; u64 hole_start, hole_end; @@ -89,62 +247,64 @@ static bool assert_one_hole(const struct drm_mm *mm, u64 start, u64 end) drm_mm_for_each_hole(hole, mm, hole_start, hole_end) { if (start != hole_start || end != hole_end) { if (ok) - pr_err("empty mm has incorrect hole, found (%llx, %llx), expect (%llx, %llx)\n", - hole_start, hole_end, - start, end); + kunit_err(test, + "incorrect hole, found (%#llx, %#llx), expect (%#llx, %#llx)\n", + hole_start, hole_end, start, end); ok = false; } count++; } if (count != 1) { - pr_err("Expected to find one hole, found %lu instead\n", count); + show_mm(test, mm); + kunit_err(test, "Expected to find one hole, found %lu instead\n", count); ok = false; } return ok; } -static bool assert_continuous(const struct drm_mm *mm, u64 size) +static bool is_continuous(struct kunit *test, const struct drm_mm *mm, u64 size) { struct drm_mm_node *node, *check, *found; unsigned long n; u64 addr; - if (!assert_no_holes(mm)) + if (!has_no_holes(test, mm)) return false; n = 0; addr = 0; drm_mm_for_each_node(node, mm) { if (node->start != addr) { - pr_err("node[%ld] list out of order, expected %llx found %llx\n", - n, addr, node->start); + kunit_err(test, "node[%ld] list out of order, expected %#llx found %#llx\n", + n, addr, node->start); return false; } if (node->size != size) { - pr_err("node[%ld].size incorrect, expected %llx, found %llx\n", - n, size, node->size); + kunit_err(test, "node[%ld].size incorrect, expected %llu, found %llu\n", + n, size, node->size); return false; } if (drm_mm_hole_follows(node)) { - pr_err("node[%ld] is followed by a hole!\n", n); + kunit_err(test, "node[%ld] is followed by a hole!\n", n); return false; } found = NULL; drm_mm_for_each_node_in_range(check, mm, addr, addr + size) { if (node != check) { - pr_err("lookup return wrong node, expected start %llx, found %llx\n", - node->start, check->start); + kunit_err(test, + "lookup return wrong node, expected start %#llx, found %#llx\n", + node->start, check->start); return false; } found = check; } if (!found) { - pr_err("lookup failed for node %llx + %llx\n", - addr, size); + kunit_err(test, "lookup failed for node %#llx + %llu\n", + addr, size); return false; } @@ -166,107 +326,199 @@ static u64 misalignment(struct drm_mm_node *node, u64 alignment) return rem; } -static bool assert_node(struct drm_mm_node *node, struct drm_mm *mm, - u64 size, u64 alignment, unsigned long color) +static bool check_node(struct kunit *test, struct drm_mm_node *node, struct drm_mm *mm, + u64 size, u64 alignment, unsigned long color) { bool ok = true; if (!drm_mm_node_allocated(node) || node->mm != mm) { - pr_err("node not allocated\n"); + kunit_err(test, "node not allocated\n"); ok = false; } if (node->size != size) { - pr_err("node has wrong size, found %llu, expected %llu\n", - node->size, size); + kunit_err(test, "node has wrong size, found %llu, expected %llu\n", + node->size, size); ok = false; } if (misalignment(node, alignment)) { - pr_err("node is misaligned, start %llx rem %llu, expected alignment %llu\n", - node->start, misalignment(node, alignment), alignment); + kunit_err(test, "node is misaligned, start %#llx rem %llu, expected alignment %llu\n", + node->start, misalignment(node, alignment), alignment); ok = false; } if (node->color != color) { - pr_err("node has wrong color, found %lu, expected %lu\n", - node->color, color); + kunit_err(test, "node has wrong color, found %lu, expected %lu\n", + node->color, color); ok = false; } return ok; } -#define show_mm(mm) do { \ - struct drm_printer __p = drm_debug_printer(__func__); \ - drm_mm_print((mm), &__p); } while (0) +struct kunit_drm_mm_context { + u64 start; + u64 size; +}; + +static int __drm_mm_init(struct kunit_resource *res, void *context) +{ + struct kunit_drm_mm_context *ctx = context; + struct drm_mm *mm = kzalloc(sizeof(*mm), GFP_KERNEL); + + drm_mm_init(mm, ctx->start, ctx->size); + res->data = mm; + + return 0; +} + +static void __drm_mm_destroy(struct kunit_resource *res) +{ + struct drm_mm *mm = res->data; + struct drm_mm_node *node, *next; + + drm_mm_for_each_node_safe(node, next, mm) + drm_mm_remove_node(node); + + drm_mm_takedown(mm); +} + +static struct drm_mm *kunit_drm_mm(struct kunit *test, u64 start, u64 size) +{ + struct kunit_drm_mm_context context = { + .start = start, + .size = size + }; + + return kunit_alloc_resource(test, __drm_mm_init, __drm_mm_destroy, GFP_KERNEL, &context); +} + +struct kunit_drm_random_order_context { + unsigned int count; + struct rnd_state *state; +}; + +static int __drm_random_order_init(struct kunit_resource *res, void *context) +{ + struct kunit_drm_random_order_context *ctx = context; + + res->data = drm_random_order(ctx->count, ctx->state); + + return 0; +} + +static void __drm_random_order_destroy(struct kunit_resource *res) +{ + kfree(res->data); +} + +static unsigned int * +kunit_drm_random_order(struct kunit *test, unsigned int count, struct rnd_state *state) +{ + struct kunit_drm_random_order_context context = { + .count = count, + .state = state + }; + + return kunit_alloc_resource(test, __drm_random_order_init, __drm_random_order_destroy, + GFP_KERNEL, &context); +} + +struct kunit_vmalloc_params { + unsigned long size; + gfp_t gfp; +}; + +static int __kunit_vmalloc_init(struct kunit_resource *res, void *context) +{ + struct kunit_vmalloc_params *params = context; + + res->data = __vmalloc(params->size, params->gfp); + if (!res->data) + return -ENOMEM; + + return 0; +} + +static void __kunit_vmalloc_destroy(struct kunit_resource *res) +{ + vfree(res->data); +} + +static void * +__kunit_vmalloc(struct kunit *test, unsigned long size, gfp_t gfp) +{ + struct kunit_vmalloc_params params = { + .size = size, + .gfp = gfp + }; + + return kunit_alloc_resource(test, __kunit_vmalloc_init, __kunit_vmalloc_destroy, + GFP_KERNEL, ¶ms); +} + +static void * +kunit_vmalloc(struct kunit *test, unsigned long size) +{ + return __kunit_vmalloc(test, size, GFP_KERNEL); +} + +static void * +kunit_vzalloc(struct kunit *test, unsigned long size) +{ + return __kunit_vmalloc(test, size, GFP_KERNEL | __GFP_ZERO); +} + +static unsigned long * +kunit_bitmap_alloc(struct kunit *test, unsigned int nbits, gfp_t flags) +{ + return kunit_kmalloc_array(test, BITS_TO_LONGS(nbits), sizeof(unsigned long), + flags); +} + +static unsigned long * +kunit_bitmap_zalloc(struct kunit *test, unsigned int nbits, gfp_t flags) +{ + return kunit_bitmap_alloc(test, nbits, flags | __GFP_ZERO); +} -static int igt_init(void *ignored) +static void test_init(struct kunit *test) { const unsigned int size = 4096; struct drm_mm mm; struct drm_mm_node tmp; - int ret = -EINVAL; /* Start with some simple checks on initialising the struct drm_mm */ memset(&mm, 0, sizeof(mm)); - if (drm_mm_initialized(&mm)) { - pr_err("zeroed mm claims to be initialized\n"); - return ret; - } + KUNIT_EXPECT_FALSE_MSG(test, drm_mm_initialized(&mm), "zeroed mm claims to be initialized"); memset(&mm, 0xff, sizeof(mm)); drm_mm_init(&mm, 0, size); - if (!drm_mm_initialized(&mm)) { - pr_err("mm claims not to be initialized\n"); - goto out; - } - - if (!drm_mm_clean(&mm)) { - pr_err("mm not empty on creation\n"); - goto out; - } - - /* After creation, it should all be one massive hole */ - if (!assert_one_hole(&mm, 0, size)) { - ret = -EINVAL; - goto out; - } + KUNIT_EXPECT_TRUE_MSG(test, drm_mm_initialized(&mm), "mm claims not to be initialized"); + KUNIT_EXPECT_TRUE_MSG(test, drm_mm_clean(&mm), "mm not empty on creation"); + KUNIT_EXPECT_TRUE_MSG(test, has_one_hole(test, &mm, 0, size), + "after creation, it should all be one massive hole"); memset(&tmp, 0, sizeof(tmp)); tmp.start = 0; tmp.size = size; - ret = drm_mm_reserve_node(&mm, &tmp); - if (ret) { - pr_err("failed to reserve whole drm_mm\n"); - goto out; - } - - /* After filling the range entirely, there should be no holes */ - if (!assert_no_holes(&mm)) { - ret = -EINVAL; - goto out; - } + KUNIT_ASSERT_EQ_MSG(test, drm_mm_reserve_node(&mm, &tmp), 0, + "failed to reserve whole drm_mm"); + KUNIT_EXPECT_TRUE_MSG(test, has_no_holes(test, &mm), + "after filling the range entirely, there should be no holes"); - /* And then after emptying it again, the massive hole should be back */ drm_mm_remove_node(&tmp); - if (!assert_one_hole(&mm, 0, size)) { - ret = -EINVAL; - goto out; - } + KUNIT_EXPECT_TRUE_MSG(test, has_one_hole(test, &mm, 0, size), + "after emptying it again, the massive hole should be back"); -out: - if (ret) - show_mm(&mm); drm_mm_takedown(&mm); - return ret; } -static int igt_debug(void *ignored) +static void test_debug(struct kunit *test) { struct drm_mm mm; struct drm_mm_node nodes[2]; - int ret; /* Create a small drm_mm with a couple of nodes and a few holes, and * check that the debug iterator doesn't explode over a trivial drm_mm. @@ -277,24 +529,17 @@ static int igt_debug(void *ignored) memset(nodes, 0, sizeof(nodes)); nodes[0].start = 512; nodes[0].size = 1024; - ret = drm_mm_reserve_node(&mm, &nodes[0]); - if (ret) { - pr_err("failed to reserve node[0] {start=%lld, size=%lld)\n", - nodes[0].start, nodes[0].size); - return ret; - } + KUNIT_ASSERT_EQ_MSG(test, drm_mm_reserve_node(&mm, &nodes[0]), 0, + "failed to reserve node[0] {start=%lld, size=%lld)", + nodes[0].start, nodes[0].size); nodes[1].size = 1024; nodes[1].start = 4096 - 512 - nodes[1].size; - ret = drm_mm_reserve_node(&mm, &nodes[1]); - if (ret) { - pr_err("failed to reserve node[1] {start=%lld, size=%lld)\n", - nodes[1].start, nodes[1].size); - return ret; - } + KUNIT_ASSERT_EQ_MSG(test, drm_mm_reserve_node(&mm, &nodes[1]), 0, + "failed to reserve node[1] {start=%lld, size=%lld)", + nodes[1].start, nodes[1].size); - show_mm(&mm); - return 0; + show_mm(test, &mm); } static struct drm_mm_node *set_node(struct drm_mm_node *node, @@ -305,7 +550,8 @@ static struct drm_mm_node *set_node(struct drm_mm_node *node, return node; } -static bool expect_reserve_fail(struct drm_mm *mm, struct drm_mm_node *node) +static bool +check_reserve_fail(struct kunit *test, struct drm_mm *mm, struct drm_mm_node *node) { int err; @@ -314,19 +560,18 @@ static bool expect_reserve_fail(struct drm_mm *mm, struct drm_mm_node *node) return true; if (!err) { - pr_err("impossible reserve succeeded, node %llu + %llu\n", - node->start, node->size); + kunit_err(test, "impossible reserve succeeded, node %llu + %llu\n", + node->start, node->size); drm_mm_remove_node(node); } else { - pr_err("impossible reserve failed with wrong error %d [expected %d], node %llu + %llu\n", - err, -ENOSPC, node->start, node->size); + kunit_err(test, "impossible reserve failed with wrong error %d [expected %d], node %llu + %llu\n", + err, -ENOSPC, node->start, node->size); } return false; } -static bool check_reserve_boundaries(struct drm_mm *mm, - unsigned int count, - u64 size) +static bool +check_reserve_boundaries(struct kunit *test, struct drm_mm *mm, unsigned int count, u64 size) { const struct boundary { u64 start, size; @@ -339,29 +584,29 @@ static bool check_reserve_boundaries(struct drm_mm *mm, B(size * count, 0), B(-size, size), B(-size, -size), - B(-size, 2*size), + B(-size, 2 * size), B(0, -size), B(size, -size), - B(count*size, size), - B(count*size, -size), - B(count*size, count*size), - B(count*size, -count*size), - B(count*size, -(count+1)*size), - B((count+1)*size, size), - B((count+1)*size, -size), - B((count+1)*size, -2*size), + B(count * size, size), + B(count * size, -size), + B(count * size, count * size), + B(count * size, -count * size), + B(count * size, -(count + 1) * size), + B((count + 1) * size, size), + B((count + 1) * size, -size), + B((count + 1) * size, -2 * size), #undef B }; struct drm_mm_node tmp = {}; int n; for (n = 0; n < ARRAY_SIZE(boundaries); n++) { - if (!expect_reserve_fail(mm, - set_node(&tmp, - boundaries[n].start, - boundaries[n].size))) { - pr_err("boundary[%d:%s] failed, count=%u, size=%lld\n", - n, boundaries[n].name, count, size); + if (!check_reserve_fail(test, mm, + set_node(&tmp, + boundaries[n].start, + boundaries[n].size))) { + kunit_err(test, "boundary[%d:%s] failed, count=%u, size=%lld\n", + n, boundaries[n].name, count, size); return false; } } @@ -369,13 +614,48 @@ static bool check_reserve_boundaries(struct drm_mm *mm, return true; } -static int __igt_reserve(unsigned int count, u64 size) +static const u64 simple_size_less(const unsigned int prime) +{ + return BIT_ULL(prime) - 1; +} + +static const u64 simple_size_equal(const unsigned int prime) +{ + return BIT_ULL(prime); +} + +static const u64 simple_size_more(const unsigned int prime) +{ + return BIT_ULL(prime) + 1; +} + +static const u64 (*simple_size_ops[])(const unsigned int) = { + simple_size_less, + simple_size_equal, + simple_size_more, +}; + +struct reserve_test { + const u64 size; +}; + +static const struct reserve_test param_to_reserve_test(const unsigned long param) +{ + unsigned int prime = FIELD_GET(DRM_MM_PRIME_MASK, param); + const u64 (*op)(const unsigned int) = simple_size_ops[FIELD_GET(DRM_MM_OP_MASK, param)]; + + return (const struct reserve_test) { .size = op(prime) }; +} + +static void test_reserve(struct kunit *test) { + const struct reserve_test t = param_to_reserve_test((unsigned long)test->param_value); + const unsigned int count = min_t(unsigned int, BIT(10), max_iterations); + const u64 size = t.size; DRM_RND_STATE(prng, random_seed); - struct drm_mm mm; - struct drm_mm_node tmp, *nodes, *node, *next; + struct drm_mm *mm; + struct drm_mm_node tmp, *nodes, *node; unsigned int *order, n, m, o = 0; - int ret, err; /* For exercising drm_mm_reserve_node(), we want to check that * reservations outside of the drm_mm range are rejected, and to @@ -383,83 +663,59 @@ static int __igt_reserve(unsigned int count, u64 size) * the tree and nodes should be intact. */ - DRM_MM_BUG_ON(!count); - DRM_MM_BUG_ON(!size); + KUNIT_ASSERT_GT(test, count, 0); + KUNIT_ASSERT_GT(test, size, 0); - ret = -ENOMEM; - order = drm_random_order(count, &prng); - if (!order) - goto err; + order = kunit_drm_random_order(test, count, &prng); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, order); - nodes = vzalloc(array_size(count, sizeof(*nodes))); - if (!nodes) - goto err_order; + nodes = kunit_vzalloc(test, array_size(count, sizeof(*nodes))); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); - ret = -EINVAL; - drm_mm_init(&mm, 0, count * size); + mm = kunit_drm_mm(test, 0, count * size); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); - if (!check_reserve_boundaries(&mm, count, size)) - goto out; + KUNIT_EXPECT_TRUE(test, check_reserve_boundaries(test, mm, count, size)); for (n = 0; n < count; n++) { nodes[n].start = order[n] * size; nodes[n].size = size; - err = drm_mm_reserve_node(&mm, &nodes[n]); - if (err) { - pr_err("reserve failed, step %d, start %llu\n", - n, nodes[n].start); - ret = err; - goto out; - } - - if (!drm_mm_node_allocated(&nodes[n])) { - pr_err("reserved node not allocated! step %d, start %llu\n", - n, nodes[n].start); - goto out; - } - - if (!expect_reserve_fail(&mm, &nodes[n])) - goto out; + KUNIT_ASSERT_EQ_MSG(test, drm_mm_reserve_node(mm, &nodes[n]), 0, + "reserve failed, step %d, start %llu", + n, nodes[n].start); + KUNIT_EXPECT_TRUE_MSG(test, drm_mm_node_allocated(&nodes[n]), + "reserved node not allocated! step %d, start %llu", + n, nodes[n].start); + KUNIT_EXPECT_TRUE(test, check_reserve_fail(test, mm, &nodes[n])); } /* After random insertion the nodes should be in order */ - if (!assert_continuous(&mm, size)) - goto out; + KUNIT_EXPECT_TRUE(test, is_continuous(test, mm, size)); /* Repeated use should then fail */ drm_random_reorder(order, count, &prng); for (n = 0; n < count; n++) { - if (!expect_reserve_fail(&mm, - set_node(&tmp, order[n] * size, 1))) - goto out; + KUNIT_EXPECT_TRUE(test, + check_reserve_fail(test, mm, set_node(&tmp, order[n] * size, 1))); /* Remove and reinsert should work */ drm_mm_remove_node(&nodes[order[n]]); - err = drm_mm_reserve_node(&mm, &nodes[order[n]]); - if (err) { - pr_err("reserve failed, step %d, start %llu\n", - n, nodes[n].start); - ret = err; - goto out; - } + KUNIT_ASSERT_EQ_MSG(test, drm_mm_reserve_node(mm, &nodes[order[n]]), 0, + "reserve failed, step %d, start %llu", + n, nodes[n].start); } - if (!assert_continuous(&mm, size)) - goto out; + KUNIT_EXPECT_TRUE(test, is_continuous(test, mm, size)); /* Overlapping use should then fail */ - for (n = 0; n < count; n++) { - if (!expect_reserve_fail(&mm, set_node(&tmp, 0, size*count))) - goto out; - } - for (n = 0; n < count; n++) { - if (!expect_reserve_fail(&mm, - set_node(&tmp, - size * n, - size * (count - n)))) - goto out; - } + for (n = 0; n < count; n++) + KUNIT_EXPECT_TRUE(test, + check_reserve_fail(test, mm, set_node(&tmp, 0, size * count))); + for (n = 0; n < count; n++) + KUNIT_EXPECT_TRUE(test, + check_reserve_fail(test, mm, set_node(&tmp, size * n, + size * (count - n)))); /* Remove several, reinsert, check full */ for_each_prime_number(n, min(max_prime, count)) { @@ -470,62 +726,38 @@ static int __igt_reserve(unsigned int count, u64 size) for (m = 0; m < n; m++) { node = &nodes[order[(o + m) % count]]; - err = drm_mm_reserve_node(&mm, node); - if (err) { - pr_err("reserve failed, step %d/%d, start %llu\n", - m, n, node->start); - ret = err; - goto out; - } + KUNIT_ASSERT_EQ_MSG(test, drm_mm_reserve_node(mm, node), 0, + "reserve failed, step %d/%d, start %llu", + m, n, node->start); } o += n; - if (!assert_continuous(&mm, size)) - goto out; + KUNIT_EXPECT_TRUE(test, is_continuous(test, mm, size)); } - - ret = 0; -out: - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - drm_mm_takedown(&mm); - vfree(nodes); -err_order: - kfree(order); -err: - return ret; } -static int igt_reserve(void *ignored) +#define IGT_RESERVE_MAX_PRIME 54 +static const void *reserve_gen_params(const void *prev, char *desc) { - const unsigned int count = min_t(unsigned int, BIT(10), max_iterations); - int n, ret; - - for_each_prime_number_from(n, 1, 54) { - u64 size = BIT_ULL(n); - - ret = __igt_reserve(count, size - 1); - if (ret) - return ret; + unsigned long param = (unsigned long)prev; - ret = __igt_reserve(count, size); - if (ret) - return ret; + if (!prev) + kunit_drm_mm_print_params(); - ret = __igt_reserve(count, size + 1); - if (ret) - return ret; + param = prime_ops_gen_param(param, + IGT_RESERVE_MAX_PRIME, + ARRAY_SIZE(simple_size_ops)); - cond_resched(); - } + if (param_valid(param)) + sprintf(desc, "size = %llu", param_to_reserve_test(param).size); - return 0; + return (void *)param; } -static bool expect_insert(struct drm_mm *mm, struct drm_mm_node *node, - u64 size, u64 alignment, unsigned long color, - const struct insert_mode *mode) +static bool check_insert(struct kunit *test, struct drm_mm *mm, struct drm_mm_node *node, + u64 size, u64 alignment, unsigned long color, + const struct insert_mode *mode) { int err; @@ -533,12 +765,12 @@ static bool expect_insert(struct drm_mm *mm, struct drm_mm_node *node, size, alignment, color, mode->mode); if (err) { - pr_err("insert (size=%llu, alignment=%llu, color=%lu, mode=%s) failed with err=%d\n", - size, alignment, color, mode->name, err); + kunit_err(test, "insert (size=%llu, alignment=%llu, color=%lu, mode=%s) failed with err=%d\n", + size, alignment, color, mode->name, err); return false; } - if (!assert_node(node, mm, size, alignment, color)) { + if (!check_node(test, node, mm, size, alignment, color)) { drm_mm_remove_node(node); return false; } @@ -546,7 +778,7 @@ static bool expect_insert(struct drm_mm *mm, struct drm_mm_node *node, return true; } -static bool expect_insert_fail(struct drm_mm *mm, u64 size) +static bool check_insert_fail(struct kunit *test, struct drm_mm *mm, u64 size) { struct drm_mm_node tmp = {}; int err; @@ -556,214 +788,158 @@ static bool expect_insert_fail(struct drm_mm *mm, u64 size) return true; if (!err) { - pr_err("impossible insert succeeded, node %llu + %llu\n", - tmp.start, tmp.size); + kunit_err(test, "impossible insert succeeded, node %llu + %llu\n", + tmp.start, tmp.size); drm_mm_remove_node(&tmp); } else { - pr_err("impossible insert failed with wrong error %d [expected %d], size %llu\n", - err, -ENOSPC, size); + kunit_err(test, "impossible insert failed with wrong error %d [expected %d], size %llu\n", + err, -ENOSPC, size); } return false; } -static int __igt_insert(unsigned int count, u64 size, bool replace) +struct insert_replace_test { + const u64 size; + const struct insert_mode *mode; +}; + +static const struct insert_replace_test param_to_insert_replace_test(unsigned long param) +{ + unsigned int prime = FIELD_GET(DRM_MM_PRIME_MASK, param); + unsigned int mode = FIELD_GET(DRM_MM_MODE_MASK, param); + const u64 (*op)(const unsigned int) = simple_size_ops[FIELD_GET(DRM_MM_OP_MASK, param)]; + + return (const struct insert_replace_test) { .size = op(prime), + .mode = &insert_modes[mode] }; +} + +static void __test_insert(struct kunit *test, bool replace) { + const struct insert_replace_test t = + param_to_insert_replace_test((unsigned long)test->param_value); + const unsigned int count = min_t(unsigned int, BIT(10), max_iterations); + const struct insert_mode *mode = t.mode; + const u64 size = t.size; DRM_RND_STATE(prng, random_seed); - const struct insert_mode *mode; - struct drm_mm mm; + struct drm_mm *mm; struct drm_mm_node *nodes, *node, *next; unsigned int *order, n, m, o = 0; - int ret; /* Fill a range with lots of nodes, check it doesn't fail too early */ - DRM_MM_BUG_ON(!count); - DRM_MM_BUG_ON(!size); + KUNIT_ASSERT_GT(test, count, 0); + KUNIT_ASSERT_GT(test, size, 0); - ret = -ENOMEM; - nodes = vmalloc(array_size(count, sizeof(*nodes))); - if (!nodes) - goto err; + nodes = kunit_vmalloc(test, array_size(count, sizeof(*nodes))); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); - order = drm_random_order(count, &prng); - if (!order) - goto err_nodes; + order = kunit_drm_random_order(test, count, &prng); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, order); - ret = -EINVAL; - drm_mm_init(&mm, 0, count * size); + mm = kunit_drm_mm(test, 0, count * size); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); - for (mode = insert_modes; mode->name; mode++) { - for (n = 0; n < count; n++) { - struct drm_mm_node tmp; + for (n = 0; n < count; n++) { + struct drm_mm_node tmp; - node = replace ? &tmp : &nodes[n]; - memset(node, 0, sizeof(*node)); - if (!expect_insert(&mm, node, size, 0, n, mode)) { - pr_err("%s insert failed, size %llu step %d\n", - mode->name, size, n); - goto out; - } + node = replace ? &tmp : &nodes[n]; + memset(node, 0, sizeof(*node)); + KUNIT_ASSERT_TRUE_MSG(test, + check_insert(test, mm, node, size, 0, n, mode), + "insert failed, size %llu step %d", size, n); - if (replace) { - drm_mm_replace_node(&tmp, &nodes[n]); - if (drm_mm_node_allocated(&tmp)) { - pr_err("replaced old-node still allocated! step %d\n", - n); - goto out; - } - - if (!assert_node(&nodes[n], &mm, size, 0, n)) { - pr_err("replaced node did not inherit parameters, size %llu step %d\n", - size, n); - goto out; - } - - if (tmp.start != nodes[n].start) { - pr_err("replaced node mismatch location expected [%llx + %llx], found [%llx + %llx]\n", - tmp.start, size, - nodes[n].start, nodes[n].size); - goto out; - } - } + if (replace) { + drm_mm_replace_node(&tmp, &nodes[n]); + KUNIT_EXPECT_FALSE_MSG(test, drm_mm_node_allocated(&tmp), + "replaced old-node still allocated! step %d", n); + KUNIT_EXPECT_TRUE_MSG(test, check_node(test, &nodes[n], mm, size, 0, n), + "replaced node did not inherit parameters, size %llu step %d", + size, n); + KUNIT_EXPECT_EQ_MSG(test, tmp.start, nodes[n].start, + "replaced node mismatch location expected [%#llx + %#llx], found [%#llx + %#llx]", + tmp.start, size, nodes[n].start, nodes[n].size); } + } - /* After random insertion the nodes should be in order */ - if (!assert_continuous(&mm, size)) - goto out; - - /* Repeated use should then fail */ - if (!expect_insert_fail(&mm, size)) - goto out; - - /* Remove one and reinsert, as the only hole it should refill itself */ - for (n = 0; n < count; n++) { - u64 addr = nodes[n].start; + KUNIT_EXPECT_TRUE_MSG(test, is_continuous(test, mm, size), + "After random insertion the nodes should be in order"); + KUNIT_EXPECT_TRUE_MSG(test, check_insert_fail(test, mm, size), + "After random insertion, repeated use should fail"); - drm_mm_remove_node(&nodes[n]); - if (!expect_insert(&mm, &nodes[n], size, 0, n, mode)) { - pr_err("%s reinsert failed, size %llu step %d\n", - mode->name, size, n); - goto out; - } + /* Remove one and reinsert, as the only hole it should refill itself */ + for (n = 0; n < count; n++) { + u64 addr = nodes[n].start; - if (nodes[n].start != addr) { - pr_err("%s reinsert node moved, step %d, expected %llx, found %llx\n", - mode->name, n, addr, nodes[n].start); - goto out; - } + drm_mm_remove_node(&nodes[n]); + KUNIT_ASSERT_TRUE_MSG(test, check_insert(test, mm, &nodes[n], size, 0, n, mode), + "reinsert failed, size %llu step %d", size, n); + KUNIT_EXPECT_EQ_MSG(test, nodes[n].start, addr, + "reinsert node moved, step %d, expected %#llx, found %#llx", + n, addr, nodes[n].start); + KUNIT_EXPECT_TRUE(test, is_continuous(test, mm, size)); + } - if (!assert_continuous(&mm, size)) - goto out; + /* Remove several, reinsert, check full */ + for_each_prime_number(n, min(max_prime, count)) { + for (m = 0; m < n; m++) { + node = &nodes[order[(o + m) % count]]; + drm_mm_remove_node(node); } - /* Remove several, reinsert, check full */ - for_each_prime_number(n, min(max_prime, count)) { - for (m = 0; m < n; m++) { - node = &nodes[order[(o + m) % count]]; - drm_mm_remove_node(node); - } - - for (m = 0; m < n; m++) { - node = &nodes[order[(o + m) % count]]; - if (!expect_insert(&mm, node, size, 0, n, mode)) { - pr_err("%s multiple reinsert failed, size %llu step %d\n", - mode->name, size, n); - goto out; - } - } - - o += n; - - if (!assert_continuous(&mm, size)) - goto out; - - if (!expect_insert_fail(&mm, size)) - goto out; + for (m = 0; m < n; m++) { + node = &nodes[order[(o + m) % count]]; + KUNIT_ASSERT_TRUE_MSG(test, check_insert(test, mm, node, size, 0, n, mode), + "multiple reinsert failed, size %llu step %d", + size, n); } - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - DRM_MM_BUG_ON(!drm_mm_clean(&mm)); + o += n; - cond_resched(); + KUNIT_EXPECT_TRUE(test, is_continuous(test, mm, size)); + KUNIT_EXPECT_TRUE(test, check_insert_fail(test, mm, size)); } - ret = 0; -out: - drm_mm_for_each_node_safe(node, next, &mm) + drm_mm_for_each_node_safe(node, next, mm) drm_mm_remove_node(node); - drm_mm_takedown(&mm); - kfree(order); -err_nodes: - vfree(nodes); -err: - return ret; + KUNIT_ASSERT_TRUE(test, drm_mm_clean(mm)); } -static int igt_insert(void *ignored) +static void test_insert(struct kunit *test) { - const unsigned int count = min_t(unsigned int, BIT(10), max_iterations); - unsigned int n; - int ret; - - for_each_prime_number_from(n, 1, 54) { - u64 size = BIT_ULL(n); - - ret = __igt_insert(count, size - 1, false); - if (ret) - return ret; - - ret = __igt_insert(count, size, false); - if (ret) - return ret; - - ret = __igt_insert(count, size + 1, false); - if (ret) - return ret; - - cond_resched(); - } - - return 0; + __test_insert(test, false); } -static int igt_replace(void *ignored) +static void test_replace(struct kunit *test) { - const unsigned int count = min_t(unsigned int, BIT(10), max_iterations); - unsigned int n; - int ret; - - /* Reuse igt_insert to exercise replacement by inserting a dummy node, - * then replacing it with the intended node. We want to check that - * the tree is intact and all the information we need is carried - * across to the target node. - */ + __test_insert(test, true); +} - for_each_prime_number_from(n, 1, 54) { - u64 size = BIT_ULL(n); +#define IGT_INSERT_REPLACE_MAX_PRIME 54 +static const void *insert_replace_gen_params(const void *prev, char *desc) +{ + unsigned long param = (unsigned long)prev; - ret = __igt_insert(count, size - 1, true); - if (ret) - return ret; + if (!prev) + kunit_drm_mm_print_params(); - ret = __igt_insert(count, size, true); - if (ret) - return ret; + param = mode_prime_ops_gen_param(param, + ARRAY_SIZE(insert_modes), + IGT_INSERT_REPLACE_MAX_PRIME, + ARRAY_SIZE(simple_size_ops)); - ret = __igt_insert(count, size + 1, true); - if (ret) - return ret; + if (param_valid(param)) { + const struct insert_replace_test t = param_to_insert_replace_test(param); - cond_resched(); + sprintf(desc, "size = %llu %s", t.size, t.mode->name); } - return 0; + return (void *)param; } -static bool expect_insert_in_range(struct drm_mm *mm, struct drm_mm_node *node, - u64 size, u64 alignment, unsigned long color, - u64 range_start, u64 range_end, - const struct insert_mode *mode) +static bool check_insert_in_range(struct kunit *test, struct drm_mm *mm, struct drm_mm_node *node, + u64 size, u64 alignment, unsigned long color, + u64 range_start, u64 range_end, + const struct insert_mode *mode) { int err; @@ -772,13 +948,13 @@ static bool expect_insert_in_range(struct drm_mm *mm, struct drm_mm_node *node, range_start, range_end, mode->mode); if (err) { - pr_err("insert (size=%llu, alignment=%llu, color=%lu, mode=%s) nto range [%llx, %llx] failed with err=%d\n", - size, alignment, color, mode->name, - range_start, range_end, err); + kunit_err(test, "insert (size=%llu, alignment=%llu, color=%lu, mode=%s) into range [%#llx, %#llx] failed with err=%d\n", + size, alignment, color, mode->name, + range_start, range_end, err); return false; } - if (!assert_node(node, mm, size, alignment, color)) { + if (!check_node(test, node, mm, size, alignment, color)) { drm_mm_remove_node(node); return false; } @@ -786,10 +962,11 @@ static bool expect_insert_in_range(struct drm_mm *mm, struct drm_mm_node *node, return true; } -static bool expect_insert_in_range_fail(struct drm_mm *mm, - u64 size, - u64 range_start, - u64 range_end) +static bool check_insert_in_range_fail(struct kunit *test, + struct drm_mm *mm, + u64 size, + u64 range_start, + u64 range_end) { struct drm_mm_node tmp = {}; int err; @@ -802,51 +979,53 @@ static bool expect_insert_in_range_fail(struct drm_mm *mm, return true; if (!err) { - pr_err("impossible insert succeeded, node %llx + %llu, range [%llx, %llx]\n", - tmp.start, tmp.size, range_start, range_end); + kunit_err(test, "impossible insert succeeded, node %#llx + %llu, range [%#llx, %#llx]\n", + tmp.start, tmp.size, range_start, range_end); drm_mm_remove_node(&tmp); } else { - pr_err("impossible insert failed with wrong error %d [expected %d], size %llu, range [%llx, %llx]\n", - err, -ENOSPC, size, range_start, range_end); + kunit_err(test, + "impossible insert failed with wrong error %d [expected %d], size %llu, range [%#llx, %#llx]\n", + err, -ENOSPC, size, range_start, range_end); } return false; } -static bool assert_contiguous_in_range(struct drm_mm *mm, - u64 size, - u64 start, - u64 end) +static bool check_contiguous_in_range(struct kunit *test, + struct drm_mm *mm, + u64 size, + u64 start, + u64 end) { struct drm_mm_node *node; unsigned int n; - if (!expect_insert_in_range_fail(mm, size, start, end)) + if (!check_insert_in_range_fail(test, mm, size, start, end)) return false; n = div64_u64(start + size - 1, size); drm_mm_for_each_node(node, mm) { if (node->start < start || node->start + node->size > end) { - pr_err("node %d out of range, address [%llx + %llu], range [%llx, %llx]\n", - n, node->start, node->start + node->size, start, end); + kunit_err(test, "node %d out of range, address [%#llx + %llu], range [%#llx, %#llx]\n", + n, node->start, node->start + node->size, start, end); return false; } if (node->start != n * size) { - pr_err("node %d out of order, expected start %llx, found %llx\n", - n, n * size, node->start); + kunit_err(test, "node %d out of order, expected start %#llx, found %#llx\n", + n, n * size, node->start); return false; } if (node->size != size) { - pr_err("node %d has wrong size, expected size %llx, found %llx\n", - n, size, node->size); + kunit_err(test, "node %d has wrong size, expected size %#llx, found %#llx\n", + n, size, node->size); return false; } if (drm_mm_hole_follows(node) && drm_mm_hole_node_end(node) < end) { - pr_err("node %d is followed by a hole!\n", n); + kunit_err(test, "node %d is followed by a hole!\n", n); return false; } @@ -856,8 +1035,8 @@ static bool assert_contiguous_in_range(struct drm_mm *mm, if (start > 0) { node = __drm_mm_interval_first(mm, 0, start - 1); if (drm_mm_node_allocated(node)) { - pr_err("node before start: node=%llx+%llu, start=%llx\n", - node->start, node->size, start); + kunit_err(test, "node before start: node=%#llx+%llu, start=%#llx\n", + node->start, node->size, start); return false; } } @@ -865,8 +1044,8 @@ static bool assert_contiguous_in_range(struct drm_mm *mm, if (end < U64_MAX) { node = __drm_mm_interval_first(mm, end, U64_MAX); if (drm_mm_node_allocated(node)) { - pr_err("node after end: node=%llx+%llu, end=%llx\n", - node->start, node->size, end); + kunit_err(test, "node after end: node=%#llx+%llu, end=%#llx\n", + node->start, node->size, end); return false; } } @@ -874,181 +1053,183 @@ static bool assert_contiguous_in_range(struct drm_mm *mm, return true; } -static int __igt_insert_range(unsigned int count, u64 size, u64 start, u64 end) -{ +struct insert_range_test { + const unsigned int count; + const u64 size; + const u64 start; + const u64 end; const struct insert_mode *mode; - struct drm_mm mm; +}; + +#define __insert_range_test(name, __start, __end) \ +const struct insert_range_test insert_range_test##name(const unsigned int prime, \ + const unsigned int mode) \ +{ \ + const unsigned int count = min_t(unsigned int, BIT(13), max_iterations); \ + const u64 size = BIT_ULL(prime); \ + const u64 max = count * size; \ + return (const struct insert_range_test) { \ + .count = count, \ + .size = size, \ + .start = (__start), \ + .end = (__end), \ + .mode = &insert_modes[mode] \ + }; \ +} + +__insert_range_test(0, 0, max); +__insert_range_test(1, 1, max); +__insert_range_test(2, 0, max - 1); +__insert_range_test(3, 0, max / 2); +__insert_range_test(4, max / 2, max); +__insert_range_test(5, max / 4 + 1, 3 * max / 4 - 1); + +static const struct insert_range_test +(*insert_range_tests[])(const unsigned int, const unsigned int) = { + insert_range_test0, + insert_range_test1, + insert_range_test2, + insert_range_test3, + insert_range_test4, + insert_range_test5, +}; + +static const struct insert_range_test param_to_insert_range_test(const unsigned long param) +{ + unsigned int prime = FIELD_GET(DRM_MM_PRIME_MASK, param); + unsigned int mode = FIELD_GET(DRM_MM_MODE_MASK, param); + const struct insert_range_test (*op)(const unsigned int, const unsigned int) = + insert_range_tests[FIELD_GET(DRM_MM_OP_MASK, param)]; + + return op(prime, mode); +} + +static void test_insert_range(struct kunit *test) +{ + const struct insert_range_test t = + param_to_insert_range_test((unsigned long)test->param_value); + const unsigned int count = t.count; + const u64 size = t.size; + const u64 start = t.start; + const u64 end = t.end; + const struct insert_mode *mode = t.mode; + struct drm_mm *mm; struct drm_mm_node *nodes, *node, *next; unsigned int n, start_n, end_n; - int ret; - DRM_MM_BUG_ON(!count); - DRM_MM_BUG_ON(!size); - DRM_MM_BUG_ON(end <= start); + KUNIT_ASSERT_GT(test, count, 0); + KUNIT_ASSERT_GT(test, size, 0); + KUNIT_ASSERT_GT(test, end, start); - /* Very similar to __igt_insert(), but now instead of populating the + /* Very similar to test_insert(), but now instead of populating the * full range of the drm_mm, we try to fill a small portion of it. */ - ret = -ENOMEM; - nodes = vzalloc(array_size(count, sizeof(*nodes))); - if (!nodes) - goto err; + nodes = kunit_vzalloc(test, array_size(count, sizeof(*nodes))); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); - ret = -EINVAL; - drm_mm_init(&mm, 0, count * size); + mm = kunit_drm_mm(test, 0, count * size); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); start_n = div64_u64(start + size - 1, size); end_n = div64_u64(end - size, size); - for (mode = insert_modes; mode->name; mode++) { - for (n = start_n; n <= end_n; n++) { - if (!expect_insert_in_range(&mm, &nodes[n], - size, size, n, - start, end, mode)) { - pr_err("%s insert failed, size %llu, step %d [%d, %d], range [%llx, %llx]\n", - mode->name, size, n, - start_n, end_n, - start, end); - goto out; - } - } + for (n = start_n; n <= end_n; n++) + KUNIT_EXPECT_TRUE_MSG(test, + check_insert_in_range(test, mm, &nodes[n], + size, size, n, start, end, mode), + "insert failed, size %llu, step %d [%d, %d], range [%#llx, %#llx]", + size, n, start_n, end_n, start, end); - if (!assert_contiguous_in_range(&mm, size, start, end)) { - pr_err("%s: range [%llx, %llx] not full after initialisation, size=%llu\n", - mode->name, start, end, size); - goto out; - } - /* Remove one and reinsert, it should refill itself */ - for (n = start_n; n <= end_n; n++) { - u64 addr = nodes[n].start; + KUNIT_EXPECT_TRUE_MSG(test, check_contiguous_in_range(test, mm, size, start, end), + "range [%#llx, %#llx] not full after initialisation, size=%llu", + start, end, size); - drm_mm_remove_node(&nodes[n]); - if (!expect_insert_in_range(&mm, &nodes[n], - size, size, n, - start, end, mode)) { - pr_err("%s reinsert failed, step %d\n", mode->name, n); - goto out; - } + /* Remove one and reinsert, it should refill itself */ + for (n = start_n; n <= end_n; n++) { + u64 addr = nodes[n].start; - if (nodes[n].start != addr) { - pr_err("%s reinsert node moved, step %d, expected %llx, found %llx\n", - mode->name, n, addr, nodes[n].start); - goto out; - } - } + drm_mm_remove_node(&nodes[n]); + KUNIT_EXPECT_TRUE_MSG(test, + check_insert_in_range(test, mm, &nodes[n], + size, size, n, start, end, mode), + "reinsert failed, step %d", n); - if (!assert_contiguous_in_range(&mm, size, start, end)) { - pr_err("%s: range [%llx, %llx] not full after reinsertion, size=%llu\n", - mode->name, start, end, size); - goto out; - } - - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - DRM_MM_BUG_ON(!drm_mm_clean(&mm)); - - cond_resched(); + KUNIT_EXPECT_EQ_MSG(test, nodes[n].start, addr, + "reinsert node moved, step %d, expected %#llx, found %#llx", + n, addr, nodes[n].start); } - ret = 0; -out: - drm_mm_for_each_node_safe(node, next, &mm) + KUNIT_EXPECT_TRUE_MSG(test, check_contiguous_in_range(test, mm, size, start, end), + "range [%#llx, %#llx] not full after reinsertion, size=%llu", + start, end, size); + + drm_mm_for_each_node_safe(node, next, mm) drm_mm_remove_node(node); - drm_mm_takedown(&mm); - vfree(nodes); -err: - return ret; + KUNIT_ASSERT_TRUE(test, drm_mm_clean(mm)); } -static int insert_outside_range(void) +#define IGT_INSERT_RANGE_MAX_PRIME 50 +static const void *insert_range_gen_params(const void *prev, char *desc) { - struct drm_mm mm; - const unsigned int start = 1024; - const unsigned int end = 2048; - const unsigned int size = end - start; - - drm_mm_init(&mm, start, size); + unsigned long param = (unsigned long)prev; - if (!expect_insert_in_range_fail(&mm, 1, 0, start)) - return -EINVAL; + if (!prev) + kunit_drm_mm_print_params(); - if (!expect_insert_in_range_fail(&mm, size, - start - size/2, start + (size+1)/2)) - return -EINVAL; + param = mode_prime_ops_gen_param(param, + ARRAY_SIZE(insert_modes), + IGT_INSERT_RANGE_MAX_PRIME, + ARRAY_SIZE(insert_range_tests)); - if (!expect_insert_in_range_fail(&mm, size, - end - (size+1)/2, end + size/2)) - return -EINVAL; + if (param_valid(param)) { + const struct insert_range_test t = param_to_insert_range_test(param); - if (!expect_insert_in_range_fail(&mm, 1, end, end + size)) - return -EINVAL; + sprintf(desc, "count = %d, size = %llu, start = %#llx, end = %#llx %s", + t.count, t.size, t.start, t.end, t.mode->name); + } - drm_mm_takedown(&mm); - return 0; + return (void *)param; } -static int igt_insert_range(void *ignored) +static void test_insert_outside_range(struct kunit *test) { - const unsigned int count = min_t(unsigned int, BIT(13), max_iterations); - unsigned int n; - int ret; - - /* Check that requests outside the bounds of drm_mm are rejected. */ - ret = insert_outside_range(); - if (ret) - return ret; - - for_each_prime_number_from(n, 1, 50) { - const u64 size = BIT_ULL(n); - const u64 max = count * size; - - ret = __igt_insert_range(count, size, 0, max); - if (ret) - return ret; + struct drm_mm mm; + const unsigned int start = 1024; + const unsigned int end = 2048; + const unsigned int size = end - start; - ret = __igt_insert_range(count, size, 1, max); - if (ret) - return ret; + drm_mm_init(&mm, start, size); - ret = __igt_insert_range(count, size, 0, max - 1); - if (ret) - return ret; + /* Check that requests outside the bounds of drm_mm are rejected. */ - ret = __igt_insert_range(count, size, 0, max/2); - if (ret) - return ret; + KUNIT_EXPECT_TRUE(test, check_insert_in_range_fail(test, &mm, 1, 0, start)); - ret = __igt_insert_range(count, size, max/2, max); - if (ret) - return ret; + KUNIT_EXPECT_TRUE(test, check_insert_in_range_fail(test, &mm, size, + start - size / 2, + start + (size + 1) / 2)); - ret = __igt_insert_range(count, size, max/4+1, 3*max/4-1); - if (ret) - return ret; + KUNIT_EXPECT_TRUE(test, check_insert_in_range_fail(test, &mm, size, + end - (size + 1) / 2, + end + size / 2)); - cond_resched(); - } + KUNIT_EXPECT_TRUE(test, check_insert_in_range_fail(test, &mm, 1, end, end + size)); - return 0; + drm_mm_takedown(&mm); } -static int prepare_igt_frag(struct drm_mm *mm, - struct drm_mm_node *nodes, - unsigned int num_insert, - const struct insert_mode *mode) +static void prepare_test_frag(struct kunit *test, + struct drm_mm *mm, + struct drm_mm_node *nodes, + unsigned int num_insert, + const struct insert_mode *mode) { unsigned int size = 4096; unsigned int i; - for (i = 0; i < num_insert; i++) { - if (!expect_insert(mm, &nodes[i], size, 0, i, - mode) != 0) { - pr_err("%s insert failed\n", mode->name); - return -EINVAL; - } - } + for (i = 0; i < num_insert; i++) + KUNIT_ASSERT_TRUE(test, check_insert(test, mm, &nodes[i], size, 0, i, mode)); /* introduce fragmentation by freeing every other node */ for (i = 0; i < num_insert; i++) { @@ -1056,11 +1237,10 @@ static int prepare_igt_frag(struct drm_mm *mm, drm_mm_remove_node(&nodes[i]); } - return 0; - } -static u64 get_insert_time(struct drm_mm *mm, +static u64 get_insert_time(struct kunit *test, + struct drm_mm *mm, unsigned int num_insert, struct drm_mm_node *nodes, const struct insert_mode *mode) @@ -1070,201 +1250,193 @@ static u64 get_insert_time(struct drm_mm *mm, unsigned int i; start = ktime_get(); - for (i = 0; i < num_insert; i++) { - if (!expect_insert(mm, &nodes[i], size, 0, i, mode) != 0) { - pr_err("%s insert failed\n", mode->name); - return 0; - } - } + for (i = 0; i < num_insert; i++) + KUNIT_ASSERT_TRUE(test, check_insert(test, mm, &nodes[i], size, 0, i, mode)); return ktime_to_ns(ktime_sub(ktime_get(), start)); } -static int igt_frag(void *ignored) -{ - struct drm_mm mm; +struct frag_test { const struct insert_mode *mode; - struct drm_mm_node *nodes, *node, *next; +}; + +static const struct frag_test param_to_frag_test(const unsigned long param) +{ + unsigned int mode = FIELD_GET(DRM_MM_MODE_MASK, param); + + return (const struct frag_test) { .mode = &insert_modes[mode] }; +} + +static void test_frag(struct kunit *test) +{ + const struct frag_test t = param_to_frag_test((unsigned long)test->param_value); + const struct insert_mode *mode = t.mode; unsigned int insert_size = 10000; unsigned int scale_factor = 4; - int ret = -EINVAL; + struct drm_mm_node *nodes; + struct drm_mm *mm; + u64 insert_time1, insert_time2; /* We need 4 * insert_size nodes to hold intermediate allocated * drm_mm nodes. - * 1 times for prepare_igt_frag() + * 1 times for prepare_test_frag() * 1 times for get_insert_time() * 2 times for get_insert_time() */ - nodes = vzalloc(array_size(insert_size * 4, sizeof(*nodes))); - if (!nodes) - return -ENOMEM; + nodes = kunit_vzalloc(test, array_size(insert_size * 4, sizeof(*nodes))); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); /* For BOTTOMUP and TOPDOWN, we first fragment the - * address space using prepare_igt_frag() and then try to verify + * address space using prepare_test_frag() and then try to verify * that that insertions scale quadratically from 10k to 20k insertions */ - drm_mm_init(&mm, 1, U64_MAX - 2); - for (mode = insert_modes; mode->name; mode++) { - u64 insert_time1, insert_time2; - - if (mode->mode != DRM_MM_INSERT_LOW && - mode->mode != DRM_MM_INSERT_HIGH) - continue; - - ret = prepare_igt_frag(&mm, nodes, insert_size, mode); - if (ret) - goto err; - - insert_time1 = get_insert_time(&mm, insert_size, - nodes + insert_size, mode); - if (insert_time1 == 0) - goto err; - - insert_time2 = get_insert_time(&mm, (insert_size * 2), - nodes + insert_size * 2, mode); - if (insert_time2 == 0) - goto err; - - pr_info("%s fragmented insert of %u and %u insertions took %llu and %llu nsecs\n", - mode->name, insert_size, insert_size * 2, - insert_time1, insert_time2); - - if (insert_time2 > (scale_factor * insert_time1)) { - pr_err("%s fragmented insert took %llu nsecs more\n", - mode->name, - insert_time2 - (scale_factor * insert_time1)); - goto err; - } + mm = kunit_drm_mm(test, 1, U64_MAX - 2); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - } + prepare_test_frag(test, mm, nodes, insert_size, mode); - ret = 0; -err: - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - drm_mm_takedown(&mm); - vfree(nodes); + insert_time1 = get_insert_time(test, mm, insert_size, + nodes + insert_size, mode); + KUNIT_EXPECT_NE(test, insert_time1, 0); + + insert_time2 = get_insert_time(test, mm, (insert_size * 2), + nodes + insert_size * 2, mode); + KUNIT_EXPECT_NE(test, insert_time2, 0); - return ret; + kunit_info(test, "fragmented insert of %u and %u insertions took %llu and %llu nsecs\n", + insert_size, insert_size * 2, insert_time1, insert_time2); + + KUNIT_EXPECT_LE_MSG(test, insert_time2, scale_factor * insert_time1, + "fragmented insert took %llu nsecs more", + insert_time2 - (scale_factor * insert_time1)); } -static int igt_align(void *ignored) +static const void *frag_gen_params(const void *prev, char *desc) { + unsigned long param = (unsigned long)prev; + struct frag_test t; + + param = mode_gen_param(param, ARRAY_SIZE(insert_modes)); + while (param_valid(param)) { + t = param_to_frag_test(param); + if (t.mode->mode != DRM_MM_INSERT_LOW && t.mode->mode != DRM_MM_INSERT_HIGH) + param = mode_gen_param(param, ARRAY_SIZE(insert_modes)); + else + break; + } + + if (param_valid(param)) + sprintf(desc, "%s", param_to_frag_test(param).mode->name); + + return (void *)param; +} + +struct align_test { const struct insert_mode *mode; +}; + +static const struct align_test param_to_align_test(const unsigned long param) +{ + unsigned int mode = FIELD_GET(DRM_MM_MODE_MASK, param); + + return (const struct align_test) { .mode = &insert_modes[mode] }; +} + +static void test_align(struct kunit *test) +{ + const struct align_test t = param_to_align_test((unsigned long)test->param_value); + const struct insert_mode *mode = t.mode; const unsigned int max_count = min(8192u, max_prime); - struct drm_mm mm; - struct drm_mm_node *nodes, *node, *next; + unsigned int i = 0; + struct drm_mm_node *nodes; unsigned int prime; - int ret = -EINVAL; + struct drm_mm *mm; /* For each of the possible insertion modes, we pick a few * arbitrary alignments and check that the inserted node * meets our requirements. */ - nodes = vzalloc(array_size(max_count, sizeof(*nodes))); - if (!nodes) - goto err; + nodes = kunit_vzalloc(test, array_size(max_count, sizeof(*nodes))); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); - drm_mm_init(&mm, 1, U64_MAX - 2); + mm = kunit_drm_mm(test, 1, U64_MAX - 2); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); - for (mode = insert_modes; mode->name; mode++) { - unsigned int i = 0; + for_each_prime_number_from(prime, 1, max_count) { + u64 size = next_prime_number(prime); - for_each_prime_number_from(prime, 1, max_count) { - u64 size = next_prime_number(prime); + KUNIT_EXPECT_TRUE_MSG(test, check_insert(test, mm, &nodes[i], size, prime, i, mode), + "insert failed with alignment=%d", prime); - if (!expect_insert(&mm, &nodes[i], - size, prime, i, - mode)) { - pr_err("%s insert failed with alignment=%d", - mode->name, prime); - goto out; - } + i++; + } +} - i++; - } +static const void *align_gen_params(const void *prev, char *desc) +{ + unsigned long param = (unsigned long)prev; - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - DRM_MM_BUG_ON(!drm_mm_clean(&mm)); + param = mode_gen_param(param, ARRAY_SIZE(insert_modes)); - cond_resched(); - } + if (param_valid(param)) + sprintf(desc, "%s", param_to_align_test(param).mode->name); - ret = 0; -out: - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - drm_mm_takedown(&mm); - vfree(nodes); -err: - return ret; + return (void *)param; } -static int igt_align_pot(int max) +struct align_pot_test { + const unsigned int max; +}; + +static const struct align_pot_test align_pot_tests[] = { + { .max = 32 }, + { .max = 64 }, +}; + +static void test_align_pot(struct kunit *test) { - struct drm_mm mm; - struct drm_mm_node *node, *next; + const struct align_pot_test *t = test->param_value; + unsigned int max = t->max; + struct drm_mm *mm; + struct drm_mm_node *nodes; int bit; - int ret = -EINVAL; /* Check that we can align to the full u64 address space */ - drm_mm_init(&mm, 1, U64_MAX - 2); + nodes = kunit_kzalloc(test, array_size(max, sizeof(*nodes)), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); + + mm = kunit_drm_mm(test, 1, U64_MAX - 2); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); for (bit = max - 1; bit; bit--) { u64 align, size; - node = kzalloc(sizeof(*node), GFP_KERNEL); - if (!node) { - ret = -ENOMEM; - goto out; - } - align = BIT_ULL(bit); size = BIT_ULL(bit-1) + 1; - if (!expect_insert(&mm, node, - size, align, bit, - &insert_modes[0])) { - pr_err("insert failed with alignment=%llx [%d]", - align, bit); - goto out; - } - - cond_resched(); - } - - ret = 0; -out: - drm_mm_for_each_node_safe(node, next, &mm) { - drm_mm_remove_node(node); - kfree(node); + KUNIT_EXPECT_TRUE_MSG(test, + check_insert(test, mm, &nodes[bit], + size, align, bit, &insert_modes[0]), + "insert failed with alignment=%#llx [%d]", align, bit); } - drm_mm_takedown(&mm); - return ret; } -static int igt_align32(void *ignored) +static void align_pot_desc(const struct align_pot_test *t, char *desc) { - return igt_align_pot(32); + sprintf(desc, "%d", t->max); } -static int igt_align64(void *ignored) -{ - return igt_align_pot(64); -} +KUNIT_ARRAY_PARAM(align_pot, align_pot_tests, align_pot_desc); -static void show_scan(const struct drm_mm_scan *scan) +static void show_scan(struct kunit *test, const struct drm_mm_scan *scan) { - pr_info("scan: hit [%llx, %llx], size=%lld, align=%lld, color=%ld\n", - scan->hit_start, scan->hit_end, - scan->size, scan->alignment, scan->color); + kunit_info(test, "scan: hit [%#llx, %#llx], size=%lld, align=%lld, color=%ld\n", + scan->hit_start, scan->hit_end, + scan->size, scan->alignment, scan->color); } -static void show_holes(const struct drm_mm *mm, int count) +static void show_holes(struct kunit *test, const struct drm_mm *mm, int count) { u64 hole_start, hole_end; struct drm_mm_node *hole; @@ -1275,15 +1447,15 @@ static void show_holes(const struct drm_mm *mm, int count) if (drm_mm_node_allocated(hole)) node1 = kasprintf(GFP_KERNEL, - "[%llx + %lld, color=%ld], ", + "[%#llx + %lld, color=%ld], ", hole->start, hole->size, hole->color); if (drm_mm_node_allocated(next)) node2 = kasprintf(GFP_KERNEL, - ", [%llx + %lld, color=%ld]", + ", [%#llx + %lld, color=%ld]", next->start, next->size, next->color); - pr_info("%sHole [%llx - %llx, size %lld]%s\n", + pr_info("%sHole [%#llx - %#llx, size %lld]%s\n", node1, hole_start, hole_end, hole_end - hole_start, node2); @@ -1296,897 +1468,749 @@ static void show_holes(const struct drm_mm *mm, int count) } } -struct evict_node { - struct drm_mm_node node; - struct list_head link; -}; +static unsigned int node_index(const struct drm_mm_node *node) +{ + return div64_u64(node->start, node->size); +} -static bool evict_nodes(struct drm_mm_scan *scan, - struct evict_node *nodes, - unsigned int *order, - unsigned int count, - bool use_color, - struct list_head *evict_list) +static void test_topdown(struct kunit *test) { - struct evict_node *e, *en; - unsigned int i; + const unsigned long size = (unsigned long)test->param_value; + const struct insert_mode *topdown = &insert_modes[TOPDOWN]; + const unsigned int count = 8192; + unsigned long *bitmap; + struct drm_mm *mm; + struct drm_mm_node *nodes, *node; + unsigned int *order, n, m, o = 0; - for (i = 0; i < count; i++) { - e = &nodes[order ? order[i] : i]; - list_add(&e->link, evict_list); - if (drm_mm_scan_add_block(scan, &e->node)) - break; - } - list_for_each_entry_safe(e, en, evict_list, link) { - if (!drm_mm_scan_remove_block(scan, &e->node)) - list_del(&e->link); - } - if (list_empty(evict_list)) { - pr_err("Failed to find eviction: size=%lld [avail=%d], align=%lld (color=%lu)\n", - scan->size, count, scan->alignment, scan->color); - return false; - } + DRM_RND_STATE(prng, random_seed); - list_for_each_entry(e, evict_list, link) - drm_mm_remove_node(&e->node); + /* When allocating top-down, we expect to be returned a node + * from a suitable hole at the top of the drm_mm. We check that + * the returned node does match the highest available slot. + */ - if (use_color) { - struct drm_mm_node *node; + nodes = kunit_vzalloc(test, array_size(count, sizeof(*nodes))); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); - while ((node = drm_mm_scan_color_evict(scan))) { - e = container_of(node, typeof(*e), node); - drm_mm_remove_node(&e->node); - list_add(&e->link, evict_list); - } - } else { - if (drm_mm_scan_color_evict(scan)) { - pr_err("drm_mm_scan_color_evict unexpectedly reported overlapping nodes!\n"); - return false; - } - } + bitmap = kunit_bitmap_zalloc(test, count, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bitmap); - return true; -} + order = kunit_drm_random_order(test, count, &prng); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, order); -static bool evict_nothing(struct drm_mm *mm, - unsigned int total_size, - struct evict_node *nodes) -{ - struct drm_mm_scan scan; - LIST_HEAD(evict_list); - struct evict_node *e; - struct drm_mm_node *node; - unsigned int n; + mm = kunit_drm_mm(test, 0, size * count); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); - drm_mm_scan_init(&scan, mm, 1, 0, 0, 0); - for (n = 0; n < total_size; n++) { - e = &nodes[n]; - list_add(&e->link, &evict_list); - drm_mm_scan_add_block(&scan, &e->node); + for (n = 0; n < count; n++) { + KUNIT_ASSERT_TRUE_MSG(test, check_insert(test, mm, &nodes[n], size, 0, n, topdown), + "insert failed, size %u step %d", size, n); + + KUNIT_EXPECT_FALSE_MSG(test, drm_mm_hole_follows(&nodes[n]), + "hole after topdown insert %d, start=%#llx, size=%u", + n, nodes[n].start, size); + KUNIT_EXPECT_TRUE(test, has_one_hole(test, mm, 0, size * (count - n - 1))); } - list_for_each_entry(e, &evict_list, link) - drm_mm_scan_remove_block(&scan, &e->node); - for (n = 0; n < total_size; n++) { - e = &nodes[n]; + KUNIT_EXPECT_TRUE(test, is_continuous(test, mm, size)); - if (!drm_mm_node_allocated(&e->node)) { - pr_err("node[%d] no longer allocated!\n", n); - return false; + drm_random_reorder(order, count, &prng); + + for_each_prime_number_from(n, 1, min(count, max_prime)) { + for (m = 0; m < n; m++) { + node = &nodes[order[(o + m) % count]]; + drm_mm_remove_node(node); + __set_bit(node_index(node), bitmap); } - e->link.next = NULL; - } + for (m = 0; m < n; m++) { + unsigned int last; - drm_mm_for_each_node(node, mm) { - e = container_of(node, typeof(*e), node); - e->link.next = &e->link; - } + node = &nodes[order[(o + m) % count]]; + KUNIT_ASSERT_TRUE_MSG(test, + check_insert(test, mm, node, size, 0, 0, topdown), + "insert failed, step %d/%d", m, n); - for (n = 0; n < total_size; n++) { - e = &nodes[n]; + KUNIT_EXPECT_FALSE_MSG(test, drm_mm_hole_follows(node), + "hole after topdown insert %d/%d, start=%#llx", + m, n, node->start); - if (!e->link.next) { - pr_err("node[%d] no longer connected!\n", n); - return false; + last = find_last_bit(bitmap, count); + KUNIT_EXPECT_EQ_MSG(test, node_index(node), last, + "node %d/%d, size %d, not inserted into upmost hole, expected %d, found %d", + m, n, size, last, node_index(node)); + __clear_bit(last, bitmap); } - } - return assert_continuous(mm, nodes[0].node.size); + KUNIT_ASSERT_EQ(test, find_first_bit(bitmap, count), count); + + o += n; + } } -static bool evict_everything(struct drm_mm *mm, - unsigned int total_size, - struct evict_node *nodes) +static void test_bottomup(struct kunit *test) { - struct drm_mm_scan scan; - LIST_HEAD(evict_list); - struct evict_node *e; - unsigned int n; - int err; + const unsigned long size = (unsigned long)test->param_value; + const struct insert_mode *bottomup = &insert_modes[BOTTOMUP]; + const unsigned int count = 8192; + unsigned long *bitmap; + struct drm_mm *mm; + struct drm_mm_node *nodes, *node; + unsigned int *order, n, m, o = 0; - drm_mm_scan_init(&scan, mm, total_size, 0, 0, 0); - for (n = 0; n < total_size; n++) { - e = &nodes[n]; - list_add(&e->link, &evict_list); - if (drm_mm_scan_add_block(&scan, &e->node)) - break; + DRM_RND_STATE(prng, random_seed); + + /* Like test_topdown, but instead of searching for the last hole, + * we search for the first. + */ + + nodes = kunit_vzalloc(test, array_size(count, sizeof(*nodes))); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); + + bitmap = kunit_bitmap_zalloc(test, count, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bitmap); + + order = kunit_drm_random_order(test, count, &prng); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, order); + + mm = kunit_drm_mm(test, 0, size * count); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); + + for (n = 0; n < count; n++) { + KUNIT_ASSERT_TRUE_MSG(test, check_insert(test, mm, &nodes[n], size, 0, n, bottomup), + "bottomup insert failed, size %u step %d", size, n); + + KUNIT_EXPECT_TRUE(test, has_one_hole(test, mm, size * (n + 1), size * count)); } - err = 0; - list_for_each_entry(e, &evict_list, link) { - if (!drm_mm_scan_remove_block(&scan, &e->node)) { - if (!err) { - pr_err("Node %lld not marked for eviction!\n", - e->node.start); - err = -EINVAL; - } + KUNIT_EXPECT_TRUE(test, is_continuous(test, mm, size)); + + drm_random_reorder(order, count, &prng); + for_each_prime_number_from(n, 1, min(count, max_prime)) { + for (m = 0; m < n; m++) { + node = &nodes[order[(o + m) % count]]; + drm_mm_remove_node(node); + __set_bit(node_index(node), bitmap); } - } - if (err) - return false; - list_for_each_entry(e, &evict_list, link) - drm_mm_remove_node(&e->node); + for (m = 0; m < n; m++) { + unsigned int first; - if (!assert_one_hole(mm, 0, total_size)) - return false; + node = &nodes[order[(o + m) % count]]; + KUNIT_ASSERT_TRUE_MSG(test, + check_insert(test, mm, node, size, 0, 0, bottomup), + "insert failed, step %d/%d", m, n); - list_for_each_entry(e, &evict_list, link) { - err = drm_mm_reserve_node(mm, &e->node); - if (err) { - pr_err("Failed to reinsert node after eviction: start=%llx\n", - e->node.start); - return false; + first = find_first_bit(bitmap, count); + KUNIT_EXPECT_EQ_MSG(test, node_index(node), first, + "node %d/%d not inserted into bottom hole, expected %d, found %d", + m, n, first, node_index(node)); + __clear_bit(first, bitmap); } + + KUNIT_ASSERT_EQ(test, find_first_bit(bitmap, count), count); + + o += n; } +} + +static const void *topdown_bottomup_gen_params(const void *prev, char *desc) +{ + unsigned long param = (unsigned long)prev; + + if (param == 0) + param = 1; + else if (param <= 64) + param <<= 1; + else + param = 0; + + sprintf(desc, "size = %ld", param); - return assert_continuous(mm, nodes[0].node.size); + return (void *)param; } -static int evict_something(struct drm_mm *mm, - u64 range_start, u64 range_end, - struct evict_node *nodes, - unsigned int *order, - unsigned int count, - unsigned int size, - unsigned int alignment, - const struct insert_mode *mode) +static void __once(struct kunit *test, unsigned int mode) { - struct drm_mm_scan scan; - LIST_HEAD(evict_list); - struct evict_node *e; - struct drm_mm_node tmp; + struct drm_mm *mm; + struct drm_mm_node *nodes, *rsvd_lo, *rsvd_hi, *node; int err; - drm_mm_scan_init_with_range(&scan, mm, - size, alignment, 0, - range_start, range_end, - mode->mode); - if (!evict_nodes(&scan, - nodes, order, count, false, - &evict_list)) - return -EINVAL; + nodes = kunit_kzalloc(test, array_size(3, sizeof(*nodes)), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); - memset(&tmp, 0, sizeof(tmp)); - err = drm_mm_insert_node_generic(mm, &tmp, size, alignment, 0, - DRM_MM_INSERT_EVICT); - if (err) { - pr_err("Failed to insert into eviction hole: size=%d, align=%d\n", - size, alignment); - show_scan(&scan); - show_holes(mm, 3); - return err; - } + mm = kunit_drm_mm(test, 0, 7); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); - if (tmp.start < range_start || tmp.start + tmp.size > range_end) { - pr_err("Inserted [address=%llu + %llu] did not fit into the request range [%llu, %llu]\n", - tmp.start, tmp.size, range_start, range_end); - err = -EINVAL; - } + rsvd_lo = &nodes[0]; + rsvd_hi = &nodes[1]; + node = &nodes[2]; - if (!assert_node(&tmp, mm, size, alignment, 0) || - drm_mm_hole_follows(&tmp)) { - pr_err("Inserted did not fill the eviction hole: size=%lld [%d], align=%d [rem=%lld], start=%llx, hole-follows?=%d\n", - tmp.size, size, - alignment, misalignment(&tmp, alignment), - tmp.start, drm_mm_hole_follows(&tmp)); - err = -EINVAL; - } + rsvd_lo->start = 1; + rsvd_lo->size = 1; + err = drm_mm_reserve_node(mm, rsvd_lo); + KUNIT_ASSERT_EQ_MSG(test, err, 0, "Could not reserve low node"); - drm_mm_remove_node(&tmp); - if (err) - return err; + rsvd_hi->start = 5; + rsvd_hi->size = 1; + err = drm_mm_reserve_node(mm, rsvd_hi); + KUNIT_ASSERT_EQ_MSG(test, err, 0, "Could not reserve high node"); - list_for_each_entry(e, &evict_list, link) { - err = drm_mm_reserve_node(mm, &e->node); - if (err) { - pr_err("Failed to reinsert node after eviction: start=%llx\n", - e->node.start); - return err; - } - } + KUNIT_EXPECT_TRUE_MSG(test, drm_mm_hole_follows(rsvd_lo), + "Expected a hole after low node"); + KUNIT_EXPECT_TRUE_MSG(test, drm_mm_hole_follows(rsvd_hi), + "Expected a hole after high node"); - if (!assert_continuous(mm, nodes[0].node.size)) { - pr_err("range is no longer continuous\n"); - return -EINVAL; - } - - return 0; + err = drm_mm_insert_node_generic(mm, node, 2, 0, 0, mode); + KUNIT_ASSERT_EQ_MSG(test, err, 0, "Could not insert the node into the available hole!"); } -static int igt_evict(void *ignored) +static void test_lowest(struct kunit *test) { - DRM_RND_STATE(prng, random_seed); - const unsigned int size = 8192; - const struct insert_mode *mode; - struct drm_mm mm; - struct evict_node *nodes; - struct drm_mm_node *node, *next; - unsigned int *order, n; - int ret, err; + __once(test, DRM_MM_INSERT_LOW); +} - /* Here we populate a full drm_mm and then try and insert a new node - * by evicting other nodes in a random order. The drm_mm_scan should - * pick the first matching hole it finds from the random list. We - * repeat that for different allocation strategies, alignments and - * sizes to try and stress the hole finder. - */ +static void test_highest(struct kunit *test) +{ + __once(test, DRM_MM_INSERT_HIGH); +} - ret = -ENOMEM; - nodes = vzalloc(array_size(size, sizeof(*nodes))); - if (!nodes) - goto err; +static void separate_adjacent_colors(const struct drm_mm_node *node, + unsigned long color, + u64 *start, + u64 *end) +{ + if (drm_mm_node_allocated(node) && node->color != color) + ++*start; - order = drm_random_order(size, &prng); - if (!order) - goto err_nodes; + node = list_next_entry(node, node_list); + if (drm_mm_node_allocated(node) && node->color != color) + --*end; +} - ret = -EINVAL; - drm_mm_init(&mm, 0, size); - for (n = 0; n < size; n++) { - err = drm_mm_insert_node(&mm, &nodes[n].node, 1); - if (err) { - pr_err("insert failed, step %d\n", n); - ret = err; - goto out; - } +static bool colors_abutt(struct kunit *test, const struct drm_mm_node *node) +{ + if (!drm_mm_hole_follows(node) && + drm_mm_node_allocated(list_next_entry(node, node_list))) { + kunit_err(test, "colors abutt; %ld [%#llx + %#llx] is next to %ld [%#llx + %#llx]!\n", + node->color, node->start, node->size, + list_next_entry(node, node_list)->color, + list_next_entry(node, node_list)->start, + list_next_entry(node, node_list)->size); + return true; } - /* First check that using the scanner doesn't break the mm */ - if (!evict_nothing(&mm, size, nodes)) { - pr_err("evict_nothing() failed\n"); - goto out; - } - if (!evict_everything(&mm, size, nodes)) { - pr_err("evict_everything() failed\n"); - goto out; - } - - for (mode = evict_modes; mode->name; mode++) { - for (n = 1; n <= size; n <<= 1) { - drm_random_reorder(order, size, &prng); - err = evict_something(&mm, 0, U64_MAX, - nodes, order, size, - n, 1, - mode); - if (err) { - pr_err("%s evict_something(size=%u) failed\n", - mode->name, n); - ret = err; - goto out; - } - } + return false; +} - for (n = 1; n < size; n <<= 1) { - drm_random_reorder(order, size, &prng); - err = evict_something(&mm, 0, U64_MAX, - nodes, order, size, - size/2, n, - mode); - if (err) { - pr_err("%s evict_something(size=%u, alignment=%u) failed\n", - mode->name, size/2, n); - ret = err; - goto out; - } - } +static void test_color_sanity(struct kunit *test) +{ + const unsigned int count = min(4096u, max_iterations); + struct drm_mm_node *nodes, *node, *nn; + struct drm_mm *mm; + unsigned int n; - for_each_prime_number_from(n, 1, min(size, max_prime)) { - unsigned int nsize = (size - n + 1) / 2; - - DRM_MM_BUG_ON(!nsize); - - drm_random_reorder(order, size, &prng); - err = evict_something(&mm, 0, U64_MAX, - nodes, order, size, - nsize, n, - mode); - if (err) { - pr_err("%s evict_something(size=%u, alignment=%u) failed\n", - mode->name, nsize, n); - ret = err; - goto out; - } - } + nodes = kunit_vzalloc(test, array_size(count, sizeof(*nodes))); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); - cond_resched(); - } + mm = kunit_drm_mm(test, 0, U64_MAX); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); - ret = 0; -out: - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - drm_mm_takedown(&mm); - kfree(order); -err_nodes: - vfree(nodes); -err: - return ret; + for (n = 1; n <= count; n++) + KUNIT_ASSERT_TRUE_MSG(test, + check_insert(test, mm, &nodes[n - 1], + n, 0, n, &insert_modes[0]), + "insert failed, step %d", n); + + drm_mm_for_each_node_safe(node, nn, mm) + KUNIT_EXPECT_EQ_MSG(test, node->color, node->size, + "invalid color stored: expected %lld, found %ld", + node->size, node->color); } -static int igt_evict_range(void *ignored) -{ - DRM_RND_STATE(prng, random_seed); - const unsigned int size = 8192; - const unsigned int range_size = size / 2; - const unsigned int range_start = size / 4; - const unsigned int range_end = range_start + range_size; +struct color_test { const struct insert_mode *mode; - struct drm_mm mm; - struct evict_node *nodes; - struct drm_mm_node *node, *next; - unsigned int *order, n; - int ret, err; - - /* Like igt_evict() but now we are limiting the search to a - * small portion of the full drm_mm. - */ - - ret = -ENOMEM; - nodes = vzalloc(array_size(size, sizeof(*nodes))); - if (!nodes) - goto err; - - order = drm_random_order(size, &prng); - if (!order) - goto err_nodes; +}; - ret = -EINVAL; - drm_mm_init(&mm, 0, size); - for (n = 0; n < size; n++) { - err = drm_mm_insert_node(&mm, &nodes[n].node, 1); - if (err) { - pr_err("insert failed, step %d\n", n); - ret = err; - goto out; - } - } +static const struct color_test param_to_color_test(const unsigned long param) +{ + unsigned int mode = FIELD_GET(DRM_MM_MODE_MASK, param); - for (mode = evict_modes; mode->name; mode++) { - for (n = 1; n <= range_size; n <<= 1) { - drm_random_reorder(order, size, &prng); - err = evict_something(&mm, range_start, range_end, - nodes, order, size, - n, 1, - mode); - if (err) { - pr_err("%s evict_something(size=%u) failed with range [%u, %u]\n", - mode->name, n, range_start, range_end); - goto out; - } - } + return (const struct color_test) { .mode = &evict_modes[mode] }; +} - for (n = 1; n <= range_size; n <<= 1) { - drm_random_reorder(order, size, &prng); - err = evict_something(&mm, range_start, range_end, - nodes, order, size, - range_size/2, n, - mode); - if (err) { - pr_err("%s evict_something(size=%u, alignment=%u) failed with range [%u, %u]\n", - mode->name, range_size/2, n, range_start, range_end); - goto out; - } - } +static void test_color(struct kunit *test) +{ + const struct color_test t = param_to_color_test((unsigned long)test->param_value); + const struct insert_mode *mode = t.mode; + const unsigned int count = min(4096u, max_iterations); + struct drm_mm_node *nodes, *node, *nn; + struct drm_mm *mm; + unsigned int n; + u64 last; + int err; - for_each_prime_number_from(n, 1, min(range_size, max_prime)) { - unsigned int nsize = (range_size - n + 1) / 2; + /* Color adjustment complicates everything. First we just check + * that when we insert a node we apply any color_adjustment callback. + * The callback we use should ensure that there is a gap between + * any two nodes, and so after each insertion we check that those + * holes are inserted and that they are preserved. + */ - DRM_MM_BUG_ON(!nsize); + nodes = kunit_vzalloc(test, array_size(count * 2, sizeof(*nodes))); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); - drm_random_reorder(order, size, &prng); - err = evict_something(&mm, range_start, range_end, - nodes, order, size, - nsize, n, - mode); - if (err) { - pr_err("%s evict_something(size=%u, alignment=%u) failed with range [%u, %u]\n", - mode->name, nsize, n, range_start, range_end); - goto out; - } - } + node = kunit_kzalloc(test, sizeof(*node), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node); - cond_resched(); - } + mm = kunit_drm_mm(test, 0, U64_MAX); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); - ret = 0; -out: - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - drm_mm_takedown(&mm); - kfree(order); -err_nodes: - vfree(nodes); -err: - return ret; -} + /* Now, let's start experimenting with applying a color callback */ + mm->color_adjust = separate_adjacent_colors; -static unsigned int node_index(const struct drm_mm_node *node) -{ - return div64_u64(node->start, node->size); -} + node->size = 1 + 2 * count; + node->color = node->size; -static int igt_topdown(void *ignored) -{ - const struct insert_mode *topdown = &insert_modes[TOPDOWN]; - DRM_RND_STATE(prng, random_seed); - const unsigned int count = 8192; - unsigned int size; - unsigned long *bitmap; - struct drm_mm mm; - struct drm_mm_node *nodes, *node, *next; - unsigned int *order, n, m, o = 0; - int ret; + err = drm_mm_reserve_node(mm, node); + KUNIT_EXPECT_EQ_MSG(test, err, 0, "initial reserve failed!"); - /* When allocating top-down, we expect to be returned a node - * from a suitable hole at the top of the drm_mm. We check that - * the returned node does match the highest available slot. - */ + last = node->start + node->size; - ret = -ENOMEM; - nodes = vzalloc(array_size(count, sizeof(*nodes))); - if (!nodes) - goto err; - - bitmap = bitmap_zalloc(count, GFP_KERNEL); - if (!bitmap) - goto err_nodes; - - order = drm_random_order(count, &prng); - if (!order) - goto err_bitmap; - - ret = -EINVAL; - for (size = 1; size <= 64; size <<= 1) { - drm_mm_init(&mm, 0, size*count); - for (n = 0; n < count; n++) { - if (!expect_insert(&mm, &nodes[n], - size, 0, n, - topdown)) { - pr_err("insert failed, size %u step %d\n", size, n); - goto out; - } + for (n = 1; n <= count; n++) { + int rem; - if (drm_mm_hole_follows(&nodes[n])) { - pr_err("hole after topdown insert %d, start=%llx\n, size=%u", - n, nodes[n].start, size); - goto out; - } + node = &nodes[n - 1]; - if (!assert_one_hole(&mm, 0, size*(count - n - 1))) - goto out; - } + node->start = last; + node->size = n + count; + node->color = node->size; - if (!assert_continuous(&mm, size)) - goto out; + err = drm_mm_reserve_node(mm, node); + KUNIT_ASSERT_EQ_MSG(test, err, -ENOSPC, + "reserve %d did not report color overlap! err=%d", n, err); - drm_random_reorder(order, count, &prng); - for_each_prime_number_from(n, 1, min(count, max_prime)) { - for (m = 0; m < n; m++) { - node = &nodes[order[(o + m) % count]]; - drm_mm_remove_node(node); - __set_bit(node_index(node), bitmap); - } + node->start += n + 1; + rem = misalignment(node, n + count); + node->start += n + count - rem; - for (m = 0; m < n; m++) { - unsigned int last; + err = drm_mm_reserve_node(mm, node); + KUNIT_ASSERT_EQ_MSG(test, err, 0, "reserve %d failed, err=%d", n, err); - node = &nodes[order[(o + m) % count]]; - if (!expect_insert(&mm, node, - size, 0, 0, - topdown)) { - pr_err("insert failed, step %d/%d\n", m, n); - goto out; - } + last = node->start + node->size; + } - if (drm_mm_hole_follows(node)) { - pr_err("hole after topdown insert %d/%d, start=%llx\n", - m, n, node->start); - goto out; - } + for (n = 1; n <= count; n++) { + node = &nodes[count + n - 1]; - last = find_last_bit(bitmap, count); - if (node_index(node) != last) { - pr_err("node %d/%d, size %d, not inserted into upmost hole, expected %d, found %d\n", - m, n, size, last, node_index(node)); - goto out; - } + KUNIT_ASSERT_TRUE_MSG(test, check_insert(test, mm, node, n, n, n, mode), + "insert failed, step %d", n); + } - __clear_bit(last, bitmap); - } + drm_mm_for_each_node_safe(node, nn, mm) { + u64 rem; - DRM_MM_BUG_ON(find_first_bit(bitmap, count) != count); + KUNIT_EXPECT_EQ_MSG(test, node->color, node->size, + "invalid color stored: expected %lld, found %ld", + node->size, node->color); - o += n; - } + KUNIT_EXPECT_FALSE(test, colors_abutt(test, node)); - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - DRM_MM_BUG_ON(!drm_mm_clean(&mm)); - cond_resched(); + div64_u64_rem(node->start, node->size, &rem); + KUNIT_EXPECT_EQ_MSG(test, rem, 0, + "colored node misaligned, start=%#llx expected alignment=%lld [rem=%lld]", + node->start, node->size, rem); } - - ret = 0; -out: - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - drm_mm_takedown(&mm); - kfree(order); -err_bitmap: - bitmap_free(bitmap); -err_nodes: - vfree(nodes); -err: - return ret; } -static int igt_bottomup(void *ignored) +static const void *color_gen_params(const void *prev, char *desc) { - const struct insert_mode *bottomup = &insert_modes[BOTTOMUP]; - DRM_RND_STATE(prng, random_seed); - const unsigned int count = 8192; - unsigned int size; - unsigned long *bitmap; - struct drm_mm mm; - struct drm_mm_node *nodes, *node, *next; - unsigned int *order, n, m, o = 0; - int ret; + unsigned long param = (unsigned long)prev; - /* Like igt_topdown, but instead of searching for the last hole, - * we search for the first. - */ + param = mode_gen_param(param, ARRAY_SIZE(evict_modes)); + if (param_valid(param)) + sprintf(desc, "%s", param_to_color_test(param).mode->name); - ret = -ENOMEM; - nodes = vzalloc(array_size(count, sizeof(*nodes))); - if (!nodes) - goto err; - - bitmap = bitmap_zalloc(count, GFP_KERNEL); - if (!bitmap) - goto err_nodes; - - order = drm_random_order(count, &prng); - if (!order) - goto err_bitmap; - - ret = -EINVAL; - for (size = 1; size <= 64; size <<= 1) { - drm_mm_init(&mm, 0, size*count); - for (n = 0; n < count; n++) { - if (!expect_insert(&mm, &nodes[n], - size, 0, n, - bottomup)) { - pr_err("bottomup insert failed, size %u step %d\n", size, n); - goto out; - } + return (void *)param; +} - if (!assert_one_hole(&mm, size*(n + 1), size*count)) - goto out; - } +struct evict_node { + struct drm_mm_node node; + struct list_head link; +}; - if (!assert_continuous(&mm, size)) - goto out; +static bool evict_nodes(struct kunit *test, + struct drm_mm_scan *scan, + struct evict_node *nodes, + unsigned int *order, + unsigned int count, + bool use_color, + struct list_head *evict_list) +{ + struct evict_node *e, *en; + unsigned int i; - drm_random_reorder(order, count, &prng); - for_each_prime_number_from(n, 1, min(count, max_prime)) { - for (m = 0; m < n; m++) { - node = &nodes[order[(o + m) % count]]; - drm_mm_remove_node(node); - __set_bit(node_index(node), bitmap); - } + for (i = 0; i < count; i++) { + e = &nodes[order ? order[i] : i]; + list_add(&e->link, evict_list); + if (drm_mm_scan_add_block(scan, &e->node)) + break; + } + list_for_each_entry_safe(e, en, evict_list, link) { + if (!drm_mm_scan_remove_block(scan, &e->node)) + list_del(&e->link); + } + if (list_empty(evict_list)) { + kunit_err(test, "Failed to find eviction: size=%lld [avail=%d], align=%lld (color=%lu)\n", + scan->size, count, scan->alignment, scan->color); + return false; + } - for (m = 0; m < n; m++) { - unsigned int first; - - node = &nodes[order[(o + m) % count]]; - if (!expect_insert(&mm, node, - size, 0, 0, - bottomup)) { - pr_err("insert failed, step %d/%d\n", m, n); - goto out; - } - - first = find_first_bit(bitmap, count); - if (node_index(node) != first) { - pr_err("node %d/%d not inserted into bottom hole, expected %d, found %d\n", - m, n, first, node_index(node)); - goto out; - } - __clear_bit(first, bitmap); - } + list_for_each_entry(e, evict_list, link) + drm_mm_remove_node(&e->node); - DRM_MM_BUG_ON(find_first_bit(bitmap, count) != count); + if (use_color) { + struct drm_mm_node *node; - o += n; + while ((node = drm_mm_scan_color_evict(scan))) { + e = container_of(node, typeof(*e), node); + drm_mm_remove_node(&e->node); + list_add(&e->link, evict_list); + } + } else { + if (drm_mm_scan_color_evict(scan)) { + kunit_err(test, "drm_mm_scan_color_evict unexpectedly reported overlapping nodes!\n"); + return false; } - - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - DRM_MM_BUG_ON(!drm_mm_clean(&mm)); - cond_resched(); } - ret = 0; -out: - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - drm_mm_takedown(&mm); - kfree(order); -err_bitmap: - bitmap_free(bitmap); -err_nodes: - vfree(nodes); -err: - return ret; + return true; } -static int __igt_once(unsigned int mode) +static bool evict_nothing(struct kunit *test, + struct drm_mm *mm, + unsigned int total_size, + struct evict_node *nodes) { - struct drm_mm mm; - struct drm_mm_node rsvd_lo, rsvd_hi, node; - int err; - - drm_mm_init(&mm, 0, 7); + struct drm_mm_scan scan; + LIST_HEAD(evict_list); + struct evict_node *e; + struct drm_mm_node *node; + unsigned int n; - memset(&rsvd_lo, 0, sizeof(rsvd_lo)); - rsvd_lo.start = 1; - rsvd_lo.size = 1; - err = drm_mm_reserve_node(&mm, &rsvd_lo); - if (err) { - pr_err("Could not reserve low node\n"); - goto err; + drm_mm_scan_init(&scan, mm, 1, 0, 0, 0); + for (n = 0; n < total_size; n++) { + e = &nodes[n]; + list_add(&e->link, &evict_list); + drm_mm_scan_add_block(&scan, &e->node); } + list_for_each_entry(e, &evict_list, link) + drm_mm_scan_remove_block(&scan, &e->node); - memset(&rsvd_hi, 0, sizeof(rsvd_hi)); - rsvd_hi.start = 5; - rsvd_hi.size = 1; - err = drm_mm_reserve_node(&mm, &rsvd_hi); - if (err) { - pr_err("Could not reserve low node\n"); - goto err_lo; + for (n = 0; n < total_size; n++) { + e = &nodes[n]; + + if (!drm_mm_node_allocated(&e->node)) { + kunit_err(test, "node[%d] no longer allocated!\n", n); + return false; + } + + e->link.next = NULL; } - if (!drm_mm_hole_follows(&rsvd_lo) || !drm_mm_hole_follows(&rsvd_hi)) { - pr_err("Expected a hole after lo and high nodes!\n"); - err = -EINVAL; - goto err_hi; + drm_mm_for_each_node(node, mm) { + e = container_of(node, typeof(*e), node); + e->link.next = &e->link; } - memset(&node, 0, sizeof(node)); - err = drm_mm_insert_node_generic(&mm, &node, 2, 0, 0, mode); - if (err) { - pr_err("Could not insert the node into the available hole!\n"); - err = -EINVAL; - goto err_hi; + for (n = 0; n < total_size; n++) { + e = &nodes[n]; + + if (!e->link.next) { + kunit_err(test, "node[%d] no longer connected!\n", n); + return false; + } } - drm_mm_remove_node(&node); -err_hi: - drm_mm_remove_node(&rsvd_hi); -err_lo: - drm_mm_remove_node(&rsvd_lo); -err: - drm_mm_takedown(&mm); - return err; + return is_continuous(test, mm, nodes[0].node.size); } -static int igt_lowest(void *ignored) +static bool evict_everything(struct kunit *test, + struct drm_mm *mm, + unsigned int total_size, + struct evict_node *nodes) { - return __igt_once(DRM_MM_INSERT_LOW); -} + struct drm_mm_scan scan; + LIST_HEAD(evict_list); + struct evict_node *e; + unsigned int n; + int err; -static int igt_highest(void *ignored) -{ - return __igt_once(DRM_MM_INSERT_HIGH); -} + drm_mm_scan_init(&scan, mm, total_size, 0, 0, 0); + for (n = 0; n < total_size; n++) { + e = &nodes[n]; + list_add(&e->link, &evict_list); + if (drm_mm_scan_add_block(&scan, &e->node)) + break; + } -static void separate_adjacent_colors(const struct drm_mm_node *node, - unsigned long color, - u64 *start, - u64 *end) -{ - if (drm_mm_node_allocated(node) && node->color != color) - ++*start; + err = 0; + list_for_each_entry(e, &evict_list, link) { + if (!drm_mm_scan_remove_block(&scan, &e->node)) { + if (!err) { + kunit_err(test, "Node %lld not marked for eviction!\n", + e->node.start); + err = -EINVAL; + } + } + } + if (err) + return false; - node = list_next_entry(node, node_list); - if (drm_mm_node_allocated(node) && node->color != color) - --*end; -} + list_for_each_entry(e, &evict_list, link) + drm_mm_remove_node(&e->node); -static bool colors_abutt(const struct drm_mm_node *node) -{ - if (!drm_mm_hole_follows(node) && - drm_mm_node_allocated(list_next_entry(node, node_list))) { - pr_err("colors abutt; %ld [%llx + %llx] is next to %ld [%llx + %llx]!\n", - node->color, node->start, node->size, - list_next_entry(node, node_list)->color, - list_next_entry(node, node_list)->start, - list_next_entry(node, node_list)->size); - return true; + if (!has_one_hole(test, mm, 0, total_size)) + return false; + + list_for_each_entry(e, &evict_list, link) { + err = drm_mm_reserve_node(mm, &e->node); + if (err) { + kunit_err(test, "Failed to reinsert node after eviction: start=%#llx\n", + e->node.start); + return false; + } } - return false; + return is_continuous(test, mm, nodes[0].node.size); } -static int igt_color(void *ignored) +static int evict_something(struct kunit *test, + struct drm_mm *mm, + u64 range_start, u64 range_end, + struct evict_node *nodes, + unsigned int *order, + unsigned int count, + unsigned int size, + unsigned int alignment, + const struct insert_mode *mode) { - const unsigned int count = min(4096u, max_iterations); - const struct insert_mode *mode; - struct drm_mm mm; - struct drm_mm_node *node, *nn; - unsigned int n; - int ret = -EINVAL, err; + struct drm_mm_scan scan; + LIST_HEAD(evict_list); + struct evict_node *e; + struct drm_mm_node tmp; + int err; - /* Color adjustment complicates everything. First we just check - * that when we insert a node we apply any color_adjustment callback. - * The callback we use should ensure that there is a gap between - * any two nodes, and so after each insertion we check that those - * holes are inserted and that they are preserved. - */ + drm_mm_scan_init_with_range(&scan, mm, + size, alignment, 0, + range_start, range_end, + mode->mode); + if (!evict_nodes(test, &scan, + nodes, order, count, false, + &evict_list)) + return -EINVAL; - drm_mm_init(&mm, 0, U64_MAX); + memset(&tmp, 0, sizeof(tmp)); + err = drm_mm_insert_node_generic(mm, &tmp, size, alignment, 0, + DRM_MM_INSERT_EVICT); + if (err) { + kunit_err(test, "Failed to insert into eviction hole: size=%d, align=%d\n", + size, alignment); + show_scan(test, &scan); + show_holes(test, mm, 3); + return err; + } - for (n = 1; n <= count; n++) { - node = kzalloc(sizeof(*node), GFP_KERNEL); - if (!node) { - ret = -ENOMEM; - goto out; - } + if (tmp.start < range_start || tmp.start + tmp.size > range_end) { + kunit_err(test, "Inserted [address=%llu + %llu] did not fit into the request range [%llu, %llu]\n", + tmp.start, tmp.size, range_start, range_end); + err = -EINVAL; + } - if (!expect_insert(&mm, node, - n, 0, n, - &insert_modes[0])) { - pr_err("insert failed, step %d\n", n); - kfree(node); - goto out; - } + if (!check_node(test, &tmp, mm, size, alignment, 0) || + drm_mm_hole_follows(&tmp)) { + kunit_err(test, "Inserted did not fill the eviction hole: size=%lld [%d], align=%d [rem=%lld], start=%#llx, hole-follows?=%d\n", + tmp.size, size, + alignment, misalignment(&tmp, alignment), + tmp.start, drm_mm_hole_follows(&tmp)); + err = -EINVAL; } - drm_mm_for_each_node_safe(node, nn, &mm) { - if (node->color != node->size) { - pr_err("invalid color stored: expected %lld, found %ld\n", - node->size, node->color); + drm_mm_remove_node(&tmp); + if (err) + return err; - goto out; + list_for_each_entry(e, &evict_list, link) { + err = drm_mm_reserve_node(mm, &e->node); + if (err) { + kunit_err(test, "Failed to reinsert node after eviction: start=%#llx\n", + e->node.start); + return err; } - - drm_mm_remove_node(node); - kfree(node); } - /* Now, let's start experimenting with applying a color callback */ - mm.color_adjust = separate_adjacent_colors; - for (mode = insert_modes; mode->name; mode++) { - u64 last; - - node = kzalloc(sizeof(*node), GFP_KERNEL); - if (!node) { - ret = -ENOMEM; - goto out; - } - - node->size = 1 + 2*count; - node->color = node->size; + if (!is_continuous(test, mm, nodes[0].node.size)) { + kunit_err(test, "range is no longer continuous\n"); + return -EINVAL; + } - err = drm_mm_reserve_node(&mm, node); - if (err) { - pr_err("initial reserve failed!\n"); - ret = err; - goto out; - } + return 0; +} - last = node->start + node->size; +static void test_evict_sanity(struct kunit *test) +{ + const unsigned int size = 8192; + struct drm_mm *mm; + struct evict_node *nodes; + unsigned int n; + int err; - for (n = 1; n <= count; n++) { - int rem; + nodes = kunit_vzalloc(test, array_size(size, sizeof(*nodes))); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); - node = kzalloc(sizeof(*node), GFP_KERNEL); - if (!node) { - ret = -ENOMEM; - goto out; - } + mm = kunit_drm_mm(test, 0, size); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); - node->start = last; - node->size = n + count; - node->color = node->size; + for (n = 0; n < size; n++) { + err = drm_mm_insert_node(mm, &nodes[n].node, 1); + KUNIT_ASSERT_EQ_MSG(test, err, 0, "insert failed, step %d", n); + } - err = drm_mm_reserve_node(&mm, node); - if (err != -ENOSPC) { - pr_err("reserve %d did not report color overlap! err=%d\n", - n, err); - goto out; - } + /* Check that using the scanner doesn't break the mm */ + KUNIT_EXPECT_TRUE(test, evict_nothing(test, mm, size, nodes)); + KUNIT_EXPECT_TRUE(test, evict_everything(test, mm, size, nodes)); +} - node->start += n + 1; - rem = misalignment(node, n + count); - node->start += n + count - rem; +struct evict_test { + const u64 size; + const u64 range_start; + const u64 range_end; + const u64 range_size; + const struct insert_mode *mode; +}; - err = drm_mm_reserve_node(&mm, node); - if (err) { - pr_err("reserve %d failed, err=%d\n", n, err); - ret = err; - goto out; - } +static const struct evict_test evict(const unsigned int mode) +{ + const u64 size = 8192; + const u64 range_size = size; + const u64 range_start = 0; + const u64 range_end = U64_MAX; + + return (const struct evict_test) { + .size = size, + .range_start = range_start, + .range_end = range_end, + .range_size = range_size, + .mode = &evict_modes[mode], + }; +} - last = node->start + node->size; - } +static const struct evict_test evict_range(const unsigned int mode) +{ + const u64 size = 8192; + const u64 range_size = size / 2; + const u64 range_start = size / 4; + const u64 range_end = range_start + range_size; + + return (const struct evict_test) { + .size = size, + .range_start = range_start, + .range_end = range_end, + .range_size = range_size, + .mode = &evict_modes[mode], + }; +} - for (n = 1; n <= count; n++) { - node = kzalloc(sizeof(*node), GFP_KERNEL); - if (!node) { - ret = -ENOMEM; - goto out; - } +static const struct evict_test (*evict_tests[])(const unsigned int) = { + evict, + evict_range, +}; - if (!expect_insert(&mm, node, - n, n, n, - mode)) { - pr_err("%s insert failed, step %d\n", - mode->name, n); - kfree(node); - goto out; - } - } +static const struct evict_test param_to_evict_test(const unsigned long param) +{ + unsigned int mode = FIELD_GET(DRM_MM_MODE_MASK, param); + const struct evict_test (*op)(const unsigned int) = + evict_tests[FIELD_GET(DRM_MM_OP_MASK, param)]; - drm_mm_for_each_node_safe(node, nn, &mm) { - u64 rem; + return op(mode); +} - if (node->color != node->size) { - pr_err("%s invalid color stored: expected %lld, found %ld\n", - mode->name, node->size, node->color); +static void test_evict(struct kunit *test) +{ + const struct evict_test t = param_to_evict_test((unsigned long)test->param_value); + const unsigned int size = t.size; + const unsigned int range_size = t.range_size; + const unsigned int range_start = t.range_start; + const unsigned int range_end = t.range_end; + const struct insert_mode *mode = t.mode; + struct drm_mm *mm; + struct evict_node *nodes; + unsigned int *order, n; + int err; - goto out; - } + /* + * Here we populate a full drm_mm and then try and insert a new node + * by evicting other nodes in a random order. The drm_mm_scan should + * pick the first matching hole it finds from the random list. We + * repeat that for different allocation strategies, alignments and + * sizes to try and stress the hole finder. + */ - if (colors_abutt(node)) - goto out; + DRM_RND_STATE(prng, random_seed); - div64_u64_rem(node->start, node->size, &rem); - if (rem) { - pr_err("%s colored node misaligned, start=%llx expected alignment=%lld [rem=%lld]\n", - mode->name, node->start, node->size, rem); - goto out; - } + nodes = kunit_vzalloc(test, array_size(size, sizeof(*nodes))); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); - drm_mm_remove_node(node); - kfree(node); - } + order = kunit_drm_random_order(test, size, &prng); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, order); - cond_resched(); - } + mm = kunit_drm_mm(test, 0, size); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); - ret = 0; -out: - drm_mm_for_each_node_safe(node, nn, &mm) { - drm_mm_remove_node(node); - kfree(node); + for (n = 0; n < size; n++) { + err = drm_mm_insert_node(mm, &nodes[n].node, 1); + KUNIT_ASSERT_EQ_MSG(test, err, 0, "insert failed, step %d", n); + } + + for (n = 1; n <= range_size; n <<= 1) { + drm_random_reorder(order, size, &prng); + err = evict_something(test, mm, range_start, range_end, + nodes, order, size, + n, 1, + mode); + KUNIT_EXPECT_EQ_MSG(test, err, 0, + "evict_something(size=%u) failed with range [%u, %u]", + n, range_start, range_end); + } + + for (n = 1; n <= range_size; n <<= 1) { + drm_random_reorder(order, size, &prng); + err = evict_something(test, mm, range_start, range_end, + nodes, order, size, + range_size / 2, n, + mode); + KUNIT_EXPECT_EQ_MSG(test, err, 0, + "evict_something(size=%u, alignment=%u) failed with range [%u, %u]", + range_size / 2, n, range_start, range_end); + } + + for_each_prime_number_from(n, 1, min(range_size, max_prime)) { + unsigned int nsize = (range_size - n + 1) / 2; + + KUNIT_ASSERT_GT(test, nsize, 0); + + drm_random_reorder(order, size, &prng); + err = evict_something(test, mm, range_start, range_end, + nodes, order, size, + nsize, n, + mode); + KUNIT_EXPECT_EQ_MSG(test, err, 0, + "evict_something(size=%u, alignment=%u) failed with range [%u, %u]", + nsize, n, range_start, range_end); } - drm_mm_takedown(&mm); - return ret; } -static int evict_color(struct drm_mm *mm, +static int evict_color(struct kunit *test, struct drm_mm *mm, u64 range_start, u64 range_end, struct evict_node *nodes, unsigned int *order, @@ -2206,7 +2230,7 @@ static int evict_color(struct drm_mm *mm, size, alignment, color, range_start, range_end, mode->mode); - if (!evict_nodes(&scan, + if (!evict_nodes(test, &scan, nodes, order, count, true, &evict_list)) return -EINVAL; @@ -2215,26 +2239,28 @@ static int evict_color(struct drm_mm *mm, err = drm_mm_insert_node_generic(mm, &tmp, size, alignment, color, DRM_MM_INSERT_EVICT); if (err) { - pr_err("Failed to insert into eviction hole: size=%d, align=%d, color=%lu, err=%d\n", - size, alignment, color, err); - show_scan(&scan); - show_holes(mm, 3); + kunit_err(test, + "Failed to insert into eviction hole: size=%d, align=%d, color=%lu, err=%d\n", + size, alignment, color, err); + show_scan(test, &scan); + show_holes(test, mm, 3); return err; } if (tmp.start < range_start || tmp.start + tmp.size > range_end) { - pr_err("Inserted [address=%llu + %llu] did not fit into the request range [%llu, %llu]\n", - tmp.start, tmp.size, range_start, range_end); + kunit_err(test, + "Inserted [address=%llu + %llu] did not fit into the request range [%llu, %llu]\n", + tmp.start, tmp.size, range_start, range_end); err = -EINVAL; } - if (colors_abutt(&tmp)) + if (colors_abutt(test, &tmp)) err = -EINVAL; - if (!assert_node(&tmp, mm, size, alignment, color)) { - pr_err("Inserted did not fit the eviction hole: size=%lld [%d], align=%d [rem=%lld], start=%llx\n", - tmp.size, size, - alignment, misalignment(&tmp, alignment), tmp.start); + if (!check_node(test, &tmp, mm, size, alignment, color)) { + kunit_err(test, + "Inserted did not fit the eviction hole: size=%lld [%d], align=%d [rem=%lld], start=%#llx\n", + tmp.size, size, alignment, misalignment(&tmp, alignment), tmp.start); err = -EINVAL; } @@ -2245,239 +2271,152 @@ static int evict_color(struct drm_mm *mm, list_for_each_entry(e, &evict_list, link) { err = drm_mm_reserve_node(mm, &e->node); if (err) { - pr_err("Failed to reinsert node after eviction: start=%llx\n", - e->node.start); + kunit_err(test, "Failed to reinsert node after eviction: start=%#llx\n", + e->node.start); return err; } } - cond_resched(); return 0; } -static int igt_color_evict(void *ignored) +static void test_color_evict(struct kunit *test) { + const struct evict_test t = param_to_evict_test((unsigned long)test->param_value); + const unsigned int size = t.size; + const unsigned int range_size = t.range_size; + const unsigned int range_start = t.range_start; + const unsigned int range_end = t.range_end; + const struct insert_mode *mode = t.mode; DRM_RND_STATE(prng, random_seed); - const unsigned int total_size = min(8192u, max_iterations); - const struct insert_mode *mode; unsigned long color = 0; - struct drm_mm mm; + struct drm_mm *mm; struct evict_node *nodes; - struct drm_mm_node *node, *next; unsigned int *order, n; - int ret, err; + int err; - /* Check that the drm_mm_scan also honours color adjustment when + /* + * Check that the drm_mm_scan also honours color adjustment when * choosing its victims to create a hole. Our color_adjust does not * allow two nodes to be placed together without an intervening hole * enlarging the set of victims that must be evicted. */ - ret = -ENOMEM; - nodes = vzalloc(array_size(total_size, sizeof(*nodes))); - if (!nodes) - goto err; - - order = drm_random_order(total_size, &prng); - if (!order) - goto err_nodes; - - ret = -EINVAL; - drm_mm_init(&mm, 0, 2*total_size - 1); - mm.color_adjust = separate_adjacent_colors; - for (n = 0; n < total_size; n++) { - if (!expect_insert(&mm, &nodes[n].node, - 1, 0, color++, - &insert_modes[0])) { - pr_err("insert failed, step %d\n", n); - goto out; - } - } - - for (mode = evict_modes; mode->name; mode++) { - for (n = 1; n <= total_size; n <<= 1) { - drm_random_reorder(order, total_size, &prng); - err = evict_color(&mm, 0, U64_MAX, - nodes, order, total_size, - n, 1, color++, - mode); - if (err) { - pr_err("%s evict_color(size=%u) failed\n", - mode->name, n); - goto out; - } - } - - for (n = 1; n < total_size; n <<= 1) { - drm_random_reorder(order, total_size, &prng); - err = evict_color(&mm, 0, U64_MAX, - nodes, order, total_size, - total_size/2, n, color++, - mode); - if (err) { - pr_err("%s evict_color(size=%u, alignment=%u) failed\n", - mode->name, total_size/2, n); - goto out; - } - } - - for_each_prime_number_from(n, 1, min(total_size, max_prime)) { - unsigned int nsize = (total_size - n + 1) / 2; - - DRM_MM_BUG_ON(!nsize); - - drm_random_reorder(order, total_size, &prng); - err = evict_color(&mm, 0, U64_MAX, - nodes, order, total_size, - nsize, n, color++, - mode); - if (err) { - pr_err("%s evict_color(size=%u, alignment=%u) failed\n", - mode->name, nsize, n); - goto out; - } - } - - cond_resched(); + nodes = kunit_vzalloc(test, array_size(size, sizeof(*nodes))); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, nodes); + + order = kunit_drm_random_order(test, size, &prng); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, order); + + mm = kunit_drm_mm(test, 0, 2 * size - 1); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mm); + + mm->color_adjust = separate_adjacent_colors; + for (n = 0; n < size; n++) + KUNIT_ASSERT_TRUE_MSG(test, + check_insert(test, mm, &nodes[n].node, 1, 0, + color++, &insert_modes[0]), + "insert failed, step %d", n); + + for (n = 1; n <= range_size; n <<= 1) { + drm_random_reorder(order, range_size, &prng); + err = evict_color(test, mm, range_start, range_end, + nodes, order, size, + n, 1, color++, + mode); + KUNIT_EXPECT_EQ_MSG(test, err, 0, "evict_color(size=%u) failed for range [%x, %x]", + n, range_start, range_end); + } + + for (n = 1; n < range_size; n <<= 1) { + drm_random_reorder(order, size, &prng); + err = evict_color(test, mm, range_start, range_end, + nodes, order, size, + range_size / 2, n, color++, + mode); + KUNIT_EXPECT_EQ_MSG(test, err, 0, + "evict_color(size=%u, alignment=%u) failed for range [%x, %x]", + size / 2, n, range_start, range_end); + } + + for_each_prime_number_from(n, 1, min(range_size, max_prime)) { + unsigned int nsize = (range_size - n + 1) / 2; + + KUNIT_ASSERT_GT(test, nsize, 0); + + drm_random_reorder(order, size, &prng); + err = evict_color(test, mm, range_start, range_end, + nodes, order, size, + nsize, n, color++, + mode); + KUNIT_EXPECT_EQ_MSG(test, err, 0, + "evict_color(size=%u, alignment=%u) failed for range [%x, %x]", + nsize, n, range_start, range_end); } - - ret = 0; -out: - if (ret) - show_mm(&mm); - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - drm_mm_takedown(&mm); - kfree(order); -err_nodes: - vfree(nodes); -err: - return ret; } -static int igt_color_evict_range(void *ignored) +static const void *evict_gen_params(const void *prev, char *desc) { - DRM_RND_STATE(prng, random_seed); - const unsigned int total_size = 8192; - const unsigned int range_size = total_size / 2; - const unsigned int range_start = total_size / 4; - const unsigned int range_end = range_start + range_size; - const struct insert_mode *mode; - unsigned long color = 0; - struct drm_mm mm; - struct evict_node *nodes; - struct drm_mm_node *node, *next; - unsigned int *order, n; - int ret, err; + unsigned long param = (unsigned long)prev; - /* Like igt_color_evict(), but limited to small portion of the full - * drm_mm range. - */ + if (!prev) + kunit_drm_mm_print_params(); - ret = -ENOMEM; - nodes = vzalloc(array_size(total_size, sizeof(*nodes))); - if (!nodes) - goto err; + param = mode_ops_gen_param(param, + ARRAY_SIZE(evict_modes), + ARRAY_SIZE(evict_tests)); - order = drm_random_order(total_size, &prng); - if (!order) - goto err_nodes; + if (param_valid(param)) { + const struct evict_test t = param_to_evict_test(param); - ret = -EINVAL; - drm_mm_init(&mm, 0, 2*total_size - 1); - mm.color_adjust = separate_adjacent_colors; - for (n = 0; n < total_size; n++) { - if (!expect_insert(&mm, &nodes[n].node, - 1, 0, color++, - &insert_modes[0])) { - pr_err("insert failed, step %d\n", n); - goto out; - } + sprintf(desc, "size = %llu, [%#llx, %#llx] range_size = %llu, %s", + t.size, t.range_start, t.range_end, t.range_size, t.mode->name); } - for (mode = evict_modes; mode->name; mode++) { - for (n = 1; n <= range_size; n <<= 1) { - drm_random_reorder(order, range_size, &prng); - err = evict_color(&mm, range_start, range_end, - nodes, order, total_size, - n, 1, color++, - mode); - if (err) { - pr_err("%s evict_color(size=%u) failed for range [%x, %x]\n", - mode->name, n, range_start, range_end); - goto out; - } - } - - for (n = 1; n < range_size; n <<= 1) { - drm_random_reorder(order, total_size, &prng); - err = evict_color(&mm, range_start, range_end, - nodes, order, total_size, - range_size/2, n, color++, - mode); - if (err) { - pr_err("%s evict_color(size=%u, alignment=%u) failed for range [%x, %x]\n", - mode->name, total_size/2, n, range_start, range_end); - goto out; - } - } - - for_each_prime_number_from(n, 1, min(range_size, max_prime)) { - unsigned int nsize = (range_size - n + 1) / 2; - - DRM_MM_BUG_ON(!nsize); + return (void *)param; +} - drm_random_reorder(order, total_size, &prng); - err = evict_color(&mm, range_start, range_end, - nodes, order, total_size, - nsize, n, color++, - mode); - if (err) { - pr_err("%s evict_color(size=%u, alignment=%u) failed for range [%x, %x]\n", - mode->name, nsize, n, range_start, range_end); - goto out; - } - } +static struct kunit_case drm_mm_tests[] = { + KUNIT_CASE(test_init), + KUNIT_CASE(test_debug), + KUNIT_CASE_PARAM(test_reserve, reserve_gen_params), + KUNIT_CASE_PARAM(test_insert, insert_replace_gen_params), + KUNIT_CASE_PARAM(test_replace, insert_replace_gen_params), + KUNIT_CASE_PARAM(test_insert_range, insert_range_gen_params), + KUNIT_CASE(test_insert_outside_range), + KUNIT_CASE_PARAM(test_frag, frag_gen_params), + KUNIT_CASE_PARAM(test_align, align_gen_params), + KUNIT_CASE_PARAM(test_align_pot, align_pot_gen_params), + KUNIT_CASE_PARAM(test_topdown, topdown_bottomup_gen_params), + KUNIT_CASE_PARAM(test_bottomup, topdown_bottomup_gen_params), + KUNIT_CASE(test_lowest), + KUNIT_CASE(test_highest), + KUNIT_CASE(test_color_sanity), + KUNIT_CASE_PARAM(test_color, color_gen_params), + KUNIT_CASE(test_evict_sanity), + KUNIT_CASE_PARAM(test_evict, evict_gen_params), + KUNIT_CASE_PARAM(test_color_evict, evict_gen_params), + {} +}; - cond_resched(); - } +static struct kunit_suite drm_mm_test_suite = { + .name = "drm_mm_tests", + .test_cases = drm_mm_tests, +}; - ret = 0; -out: - if (ret) - show_mm(&mm); - drm_mm_for_each_node_safe(node, next, &mm) - drm_mm_remove_node(node); - drm_mm_takedown(&mm); - kfree(order); -err_nodes: - vfree(nodes); -err: - return ret; -} +static struct kunit_suite *drm_mm_test_suite_array[] = { &drm_mm_test_suite, NULL }; -#include "drm_selftest.c" +static struct kunit_suite **drm_mm_test_suites + __used __section(".kunit_test_suites") = drm_mm_test_suite_array; static int __init test_drm_mm_init(void) { - int err; - while (!random_seed) random_seed = get_random_int(); - pr_info("Testing DRM range manager (struct drm_mm), with random_seed=0x%x max_iterations=%u max_prime=%u\n", - random_seed, max_iterations, max_prime); - err = run_selftests(selftests, ARRAY_SIZE(selftests), NULL); - - return err > 0 ? 0 : err; -} - -static void __exit test_drm_mm_exit(void) -{ + return 0; } - module_init(test_drm_mm_init); -module_exit(test_drm_mm_exit); module_param(random_seed, uint, 0400); module_param(max_iterations, uint, 0400); From patchwork Mon Jan 17 23:22:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 12715734 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC0CAC433EF for ; Mon, 17 Jan 2022 23:25:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 150F7112551; Mon, 17 Jan 2022 23:25:03 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id A9A1F112553 for ; Mon, 17 Jan 2022 23:25:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642461901; x=1673997901; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=7SZ5FkscuxR8Fu6Dmn9NNsNOTopG57Z6VqpuNtW5J8E=; b=R77yLJfNyp0l0U4uO602QR+xH8NBmAhccHtgZAkTH0PvmBoS89DivVMU Q6YE4p9dHLAUsY3zhmlcyOlQVATbPANwRQrecX83Q8RPiGQ9cdrCO99yK gqMoL4J2aiWyjwreQH9BdFwOaKvbUHk+dM0YzdwqNKTvP0unRUxqyHt2A Aqq7Emd3biSbYcNNPBMAgzWVAAPXC6evlyJoBKdU8FZzHOqHmMMOF49hz kO229CRCGkWPnF4aAdZXP/zkULiH+HOF6RidRfljJOo1bwhzRCPB5i/7R 1FQUCJWVh51E6GO/mVtRYv/Ql+5SjjCdFz+VfOPUCsEOBn0Z3+KxGKOXq w==; X-IronPort-AV: E=McAfee;i="6200,9189,10230"; a="269082595" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="269082595" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 15:25:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="517554470" Received: from orsmsx605.amr.corp.intel.com ([10.22.229.18]) by orsmga007.jf.intel.com with ESMTP; 17 Jan 2022 15:25:01 -0800 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX605.amr.corp.intel.com (10.22.229.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:25:00 -0800 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX609.amr.corp.intel.com (10.22.229.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:25:00 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx609.amr.corp.intel.com (10.22.229.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Mon, 17 Jan 2022 15:25:00 -0800 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.169) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Mon, 17 Jan 2022 15:25:00 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j0Ghs3ihrHzAChHBnIY0YYjHuaKG6n5NvPim9I7wbZ/v4fs2qdxmuJrn1J3x0Q0RC2uZZDsXwXrNcZ+lj2TIN5FmBl1saXdM5vLur2n2h5hTolHZROmkhIs0C1oN7yoAOPFzuyEC7tNSel9Y+tFL0VN1dMGQ/Dc30sBlyzab3gib64IOQCxV32u8B3j+E5whi3XHMkXPfx/fhXEngKVdc/tQzD4oDJnwGl89QXl81hMJxXqDmC5TJp+EmPxdaQeRGbnBGOl73TcPjx7NF9MOjjc1r+/wnPDpCm5DmrQ0TTZzB3Uvn/L9Q07YJP+6Zp4i1NbpTON3UVJ2ENezT96Niw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lKlHknuBE7WK6xRv+9R+AldWiYg3irUWS2IbYi9xaQo=; b=P3gUgdf5GkRE2Dr8VEaSXbKoVD7/OYNP45OWKMO25sjthP2QoC9nocb/mdHG+ayrcfKLeCO0Qu+m3NNY0hF72L67h4563s9JEp85EPouFepjV4Ds6uu0BTRm5MklncLSXZLkGHLPCcGJ4ugYJlFdyK4rdRIcWrWNdpMHUM1HdUxTMiDsOFSvUjkqA9WDm1igyW/fJQnwK/XPDGcUPz5YLA8ZfADlqjKGMpwelX7JknrimK7wA932gycrJXj+fvQPwO54i7eZMFglDe/s8EhvwpWImQejznOeyyxJvhYYZnKNTBdZ712FFkNUnA3sJjxFWoEygNmBIM76QpTy2BIWKQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by DM4PR11MB5550.namprd11.prod.outlook.com (2603:10b6:5:38b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Mon, 17 Jan 2022 23:24:58 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5%8]) with mapi id 15.20.4888.014; Mon, 17 Jan 2022 23:24:58 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , Subject: [RFC 09/10] drm: selftests: Convert to KUnit Date: Tue, 18 Jan 2022 00:22:58 +0100 Message-ID: <20220117232259.180459-10-michal.winiarski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220117232259.180459-1-michal.winiarski@intel.com> References: <20220117232259.180459-1-michal.winiarski@intel.com> X-ClientProxiedBy: AS9PR06CA0409.eurprd06.prod.outlook.com (2603:10a6:20b:461::18) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8064ead1-3a13-439f-570f-08d9da109389 X-MS-TrafficTypeDiagnostic: DM4PR11MB5550:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ktiPXdK1Yd1LWonUumMbng9XDIEiz9nVmFya20gGVrcPoEEUE98vKbmQfxpeSt/F4XOSzRaEySCmkBHd6LW2csWrHObh3vF/Su1AtRlVHYJcUBxOxuvpOBHM0LPmRw2Fq6ETYLvVP1UAQR/dFIfIcGe4tQM8phJ+dzJH3191DBjjqT3Z7n46Iv75FeNvXkpMGPVlZMHQFdlzxoN406k69K5cCxtODeBkecafL5Tsb8Fqsd+ScxhMX090UGzQc2SEwNc6sHnQNNmOOJGHTGHySz287bVQYub4lGJmyt1JSmZkmGo7Ag4eR5JEdHddOG3hTL6zaj6ErUnsn1hZ+ugxBQmMJJf9pS4VIRdCv05R+GxFiP+Vxpg6xVOT4q/99DSR+eHNAVNZ2QzOnSGs77wGrEc6jRPWt5+U9SH3n/r4lIcIzbWwq3wDrCpzADdAzJ7/mYHmdswXFKlvaZWrslz8frD0Cnke/1GCFCpBKrfbqRrMckqlkunZiURVVQbsj45WQrFENnMdY+1Owdpf22iHYVxEN4aeqlxiA1nj4qAhLMrcEt8/F+boFuBSE6tYZMKTXncbwPbMXx0ZbPLjM8K22BULnmuPzFjhcUvLpeyfPIKHE3Dyd5JZ8OwEtRUBsIuM9I0Lr9W6zk3CfKZo22Dddg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(82960400001)(4326008)(5660300002)(36756003)(186003)(6506007)(7416002)(1076003)(54906003)(6512007)(83380400001)(26005)(66946007)(66476007)(66556008)(316002)(6486002)(38100700002)(8936002)(508600001)(2906002)(30864003)(8676002)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?HXEReh4osXyfhzeWQ7zqZkGHwChE?= =?utf-8?q?b4PeIz0Z9ldjCYiut+2jFuQUt/wfUjH54mzX8aEz2Zc8pxXfC7diPVYPWeHIJ5X84?= =?utf-8?q?4vEoXjsQtleQk9zRnpuBw+VF2TNon0ergCg2/orNZrE6r+Wt9htJM8V5bL0RczTZP?= =?utf-8?q?HbcbQgtxwIn//PR4TZgNy/SiyAbXzvmG6XrL9wgt1Q0RQBrrlOBr+uJIWU6W6XcDl?= =?utf-8?q?PfJeEMlPgCf0Vt+LHqkRbAcRd4EWmHkXDkE7f4XaXuFboII8ke6HdL3uMFT5kpDwq?= =?utf-8?q?hFFhxR9xrpGHxsfHI6Ko+wMJAuEEIBq+iRHHBragri/SYZ314cQCjVwy/NzYIwG1z?= =?utf-8?q?yFqDRFUui1KAD3ZL31Q8L+5wwNZwuemYiKcXC8vqimKPEVzlH2OajC2tU5xWdYtKM?= =?utf-8?q?qH8oF0mfivmCMMXDq2A/e6HQCm7ljgNeibGE0CMGy/U8XY8b8Efl3RsL+rOdSgBZC?= =?utf-8?q?BeF6oWRJ6Cr/ImVE2HaEM/9u1/ouJFgK2B7Eh0J9M5maCvG1XAx697eMmfv2TCCrK?= =?utf-8?q?JJBbClU1YtaS6AxbF553NEnNtKrYnKUYQOmfcRUzkZxfrCZ5fkuof+IlHYk08vEq+?= =?utf-8?q?L7E+zgg1tDc4Pc1z67yHDlWP8gg5V3ScJJATNQ+EnSgj2A5NpXuPqfGbqFG+vWT8A?= =?utf-8?q?zuzaV2Gw/E41UpqgPJhKOfWXnryX8BeVX4NzuiFofQ/mQc+/J4ik7aoj89EbR5XKp?= =?utf-8?q?XYi189FiFjX2RCm8YhIxUJSGevEJap1ZXoONN0rPaoOiMWpzVd0nFx1sSiN9CqsRA?= =?utf-8?q?Ln25uNVwbi+BwSNm5/lSGt3wi08wPc4hJIg1w9Ff84sLHdC2hol9HZ9q5m9LY6PCS?= =?utf-8?q?WTReVciUbHba/laBRKIlSdNfqyzZ8UyhvGspS1Jgyw7kGd1cg5cTtoVuFok7+lYlw?= =?utf-8?q?GQuXXcnnUHhqfOZGjmC+9DSvVLQQggOCCl/gwthxt2U6/99rBIiw+AdeO65ubNN3/?= =?utf-8?q?D+LCFg+oQs4zp402mkq/V5IxVKpQa5QlKTHKjhCnsk6Y0gkjBcbtLFRtoQV9Ka1tG?= =?utf-8?q?6xiclDrjwKiyT21rQqlz+WK7LGz3jZQCkqYpRGKU65kp0Wt4fXeihbnCcSvYporZA?= =?utf-8?q?fTahpNm0iEmGjBC58/CJh4/sLLDFWkig9K4jMy+OoLkokBgYOy43OIPX+qrH+35Yb?= =?utf-8?q?fkrtuuVnCX5p+WZuIe3Lt84d84o5HaG6R15tdJkzUw03h75Q2CPxLtirgUDhwb+u3?= =?utf-8?q?e7nMIqi7uHQQuagwYz9yPzPeY+w/RhB5myELz60eoYbPf9HIG1mYscm1np7LQACJR?= =?utf-8?q?zmlscxwkV5If6U7Oyb9tqi3Iz9DkWH5ja+zygJ2eaw2DWSoL7YZFqH+a/EKbHi8qx?= =?utf-8?q?o2AQSLzT1VRPTE5OVs07zO/iJQ+W/YG/BwZNxPjz09E6MgFDBYX7N85LnjNsp85Dj?= =?utf-8?q?aKmBh1jkTmoPT2J2oFPKXXIVhg/DGniz1h7dUZu/9WQwVvdwf51s2TUEHIKEFNsi2?= =?utf-8?q?rW9OU8lSe2BGcTlXb+dcHMqSTdopQ2WOlzDeKWFct+oXjg/tWd1Lji6WtGCdc3bVH?= =?utf-8?q?gNWnB0m7SRUjDP0CC3+zU5urV/Ct7CLThyhiQdGR8CGWHFrU/IJ6vO7+G99VuDQH+?= =?utf-8?q?A+ZJdCZXCrnJdojODXI4QCBQ8QGOgFj8g=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 8064ead1-3a13-439f-570f-08d9da109389 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2022 23:24:58.0312 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XawDAc8gBKZyQBAIVbzg2W7e80Pi4Z4h/OMPtQf5cRaPbqTIPOO98iOctAZtM0LoYDDGlh5tYAbtOQoVtzX0axqWyGmwODyeovrzW3MfKD4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5550 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , Thomas Zimmermann , David Airlie , Brendan Higgins , Daniel Latypov , Arkadiusz Hiler , Petri Latvala Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Now that all tests were converted, remove the content that's no longer used and rename the directory to "test". Signed-off-by: Michał Winiarski --- drivers/gpu/drm/Kconfig | 17 --- drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/i915/Kconfig.debug | 1 - drivers/gpu/drm/selftests/drm_selftest.c | 109 ------------------ drivers/gpu/drm/selftests/drm_selftest.h | 41 ------- drivers/gpu/drm/{selftests => test}/Makefile | 0 .../test-drm_cmdline_parser.c | 0 .../test-drm_damage_helper.c | 0 .../test-drm_dp_mst_helper.c | 0 .../drm/{selftests => test}/test-drm_format.c | 0 .../test-drm_framebuffer.c | 0 .../gpu/drm/{selftests => test}/test-drm_mm.c | 0 .../test-drm_plane_helper.c | 0 .../drm/{selftests => test}/test-drm_rect.c | 0 14 files changed, 1 insertion(+), 169 deletions(-) delete mode 100644 drivers/gpu/drm/selftests/drm_selftest.c delete mode 100644 drivers/gpu/drm/selftests/drm_selftest.h rename drivers/gpu/drm/{selftests => test}/Makefile (100%) rename drivers/gpu/drm/{selftests => test}/test-drm_cmdline_parser.c (100%) rename drivers/gpu/drm/{selftests => test}/test-drm_damage_helper.c (100%) rename drivers/gpu/drm/{selftests => test}/test-drm_dp_mst_helper.c (100%) rename drivers/gpu/drm/{selftests => test}/test-drm_format.c (100%) rename drivers/gpu/drm/{selftests => test}/test-drm_framebuffer.c (100%) rename drivers/gpu/drm/{selftests => test}/test-drm_mm.c (100%) rename drivers/gpu/drm/{selftests => test}/test-drm_plane_helper.c (100%) rename drivers/gpu/drm/{selftests => test}/test-drm_rect.c (100%) diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index c567324c96b9..7b18540a1b8a 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -63,23 +63,6 @@ config DRM_DEBUG_MM If in doubt, say "N". -config DRM_DEBUG_SELFTEST - tristate "kselftests for DRM" - depends on DRM - depends on DEBUG_KERNEL - select PRIME_NUMBERS - select DRM_LIB_RANDOM - select DRM_KMS_HELPER - select DRM_EXPORT_FOR_TESTS if m - default n - help - This option provides kernel modules that can be used to run - various selftests on parts of the DRM api. This option is not - useful for distributions or general kernels, but only for kernel - developers working on DRM and associated drivers. - - If in doubt, say "N". - config DRM_KUNIT_TEST bool "DRM tests" if !KUNIT_ALL_TESTS depends on DRM=y && KUNIT=y diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 550800e81836..6fe8143c43e7 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -65,7 +65,7 @@ drm_kms_helper-$(CONFIG_DRM_DP_AUX_CHARDEV) += drm_dp_aux_dev.o drm_kms_helper-$(CONFIG_DRM_DP_CEC) += drm_dp_cec.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o -obj-y += selftests/ +obj-y += test/ obj-$(CONFIG_DRM) += drm.o obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o diff --git a/drivers/gpu/drm/i915/Kconfig.debug b/drivers/gpu/drm/i915/Kconfig.debug index e7fd3e76f8a2..425189f55d37 100644 --- a/drivers/gpu/drm/i915/Kconfig.debug +++ b/drivers/gpu/drm/i915/Kconfig.debug @@ -38,7 +38,6 @@ config DRM_I915_DEBUG select DRM_VGEM # used by igt/prime_vgem (dmabuf interop checks) select DRM_DEBUG_MM if DRM=y select DRM_EXPORT_FOR_TESTS if m - select DRM_DEBUG_SELFTEST select DMABUF_SELFTESTS select SW_SYNC # signaling validation framework (igt/syncobj*) select DRM_I915_WERROR diff --git a/drivers/gpu/drm/selftests/drm_selftest.c b/drivers/gpu/drm/selftests/drm_selftest.c deleted file mode 100644 index e29ed9faef5b..000000000000 --- a/drivers/gpu/drm/selftests/drm_selftest.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright © 2016 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#include - -#define selftest(name, func) __idx_##name, -enum { -#include TESTS -}; -#undef selftest - -#define selftest(n, f) [__idx_##n] = { .name = #n, .func = f }, -static struct drm_selftest { - bool enabled; - const char *name; - int (*func)(void *); -} selftests[] = { -#include TESTS -}; -#undef selftest - -/* Embed the line number into the parameter name so that we can order tests */ -#define param(n) __PASTE(igt__, __PASTE(__PASTE(__LINE__, __), n)) -#define selftest_0(n, func, id) \ -module_param_named(id, selftests[__idx_##n].enabled, bool, 0400); -#define selftest(n, func) selftest_0(n, func, param(n)) -#include TESTS -#undef selftest - -static void set_default_test_all(struct drm_selftest *st, unsigned long count) -{ - unsigned long i; - - for (i = 0; i < count; i++) - if (st[i].enabled) - return; - - for (i = 0; i < count; i++) - st[i].enabled = true; -} - -static int run_selftests(struct drm_selftest *st, - unsigned long count, - void *data) -{ - int err = 0; - - set_default_test_all(st, count); - - /* Tests are listed in natural order in drm_*_selftests.h */ - for (; count--; st++) { - if (!st->enabled) - continue; - - pr_debug("drm: Running %s\n", st->name); - err = st->func(data); - if (err) - break; - } - - if (WARN(err > 0 || err == -ENOTTY, - "%s returned %d, conflicting with selftest's magic values!\n", - st->name, err)) - err = -1; - - rcu_barrier(); - return err; -} - -static int __maybe_unused -__drm_subtests(const char *caller, - const struct drm_subtest *st, - int count, - void *data) -{ - int err; - - for (; count--; st++) { - pr_debug("Running %s/%s\n", caller, st->name); - err = st->func(data); - if (err) { - pr_err("%s: %s failed with error %d\n", - caller, st->name, err); - return err; - } - } - - return 0; -} diff --git a/drivers/gpu/drm/selftests/drm_selftest.h b/drivers/gpu/drm/selftests/drm_selftest.h deleted file mode 100644 index c784ec02ff53..000000000000 --- a/drivers/gpu/drm/selftests/drm_selftest.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright © 2016 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#ifndef __DRM_SELFTEST_H__ -#define __DRM_SELFTEST_H__ - -struct drm_subtest { - int (*func)(void *data); - const char *name; -}; - -static int __drm_subtests(const char *caller, - const struct drm_subtest *st, - int count, - void *data); -#define drm_subtests(T, data) \ - __drm_subtests(__func__, T, ARRAY_SIZE(T), data) - -#define SUBTEST(x) { x, #x } - -#endif /* __DRM_SELFTEST_H__ */ diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/test/Makefile similarity index 100% rename from drivers/gpu/drm/selftests/Makefile rename to drivers/gpu/drm/test/Makefile diff --git a/drivers/gpu/drm/selftests/test-drm_cmdline_parser.c b/drivers/gpu/drm/test/test-drm_cmdline_parser.c similarity index 100% rename from drivers/gpu/drm/selftests/test-drm_cmdline_parser.c rename to drivers/gpu/drm/test/test-drm_cmdline_parser.c diff --git a/drivers/gpu/drm/selftests/test-drm_damage_helper.c b/drivers/gpu/drm/test/test-drm_damage_helper.c similarity index 100% rename from drivers/gpu/drm/selftests/test-drm_damage_helper.c rename to drivers/gpu/drm/test/test-drm_damage_helper.c diff --git a/drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c b/drivers/gpu/drm/test/test-drm_dp_mst_helper.c similarity index 100% rename from drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c rename to drivers/gpu/drm/test/test-drm_dp_mst_helper.c diff --git a/drivers/gpu/drm/selftests/test-drm_format.c b/drivers/gpu/drm/test/test-drm_format.c similarity index 100% rename from drivers/gpu/drm/selftests/test-drm_format.c rename to drivers/gpu/drm/test/test-drm_format.c diff --git a/drivers/gpu/drm/selftests/test-drm_framebuffer.c b/drivers/gpu/drm/test/test-drm_framebuffer.c similarity index 100% rename from drivers/gpu/drm/selftests/test-drm_framebuffer.c rename to drivers/gpu/drm/test/test-drm_framebuffer.c diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/test/test-drm_mm.c similarity index 100% rename from drivers/gpu/drm/selftests/test-drm_mm.c rename to drivers/gpu/drm/test/test-drm_mm.c diff --git a/drivers/gpu/drm/selftests/test-drm_plane_helper.c b/drivers/gpu/drm/test/test-drm_plane_helper.c similarity index 100% rename from drivers/gpu/drm/selftests/test-drm_plane_helper.c rename to drivers/gpu/drm/test/test-drm_plane_helper.c diff --git a/drivers/gpu/drm/selftests/test-drm_rect.c b/drivers/gpu/drm/test/test-drm_rect.c similarity index 100% rename from drivers/gpu/drm/selftests/test-drm_rect.c rename to drivers/gpu/drm/test/test-drm_rect.c From patchwork Mon Jan 17 23:22:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 12715736 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FBFBC433FE for ; Mon, 17 Jan 2022 23:25:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EA4CF112552; Mon, 17 Jan 2022 23:25:10 +0000 (UTC) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2EE53112552 for ; Mon, 17 Jan 2022 23:25:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642461910; x=1673997910; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Jt8teGclXTWX5oTZQ7V9oXxpvPlu8NnFH5sJhhX0uEs=; b=MTfHNOKTvg9KyI8K2kVeieBCiKF3qhaleaELltdOWGRPuwtMHJGwJQAl RSaI2Jpaya/lcwmXKv78/BkUpcxYg1lppv3O0P8wycgPEpQD7JbAR3qyf vnT8udxcdHIAtbOO5eh/226yFZAXLLsHLrwUCub/kj7uBKpwaOTYV052O R9mGQIFd6oITHqZi+wfhqj6On6MP1HdigUIQO0zCUK+LEgFIIDh5ZpV0c 9PeIsDNVUJCeXNRNdmgTfLxnJzQA80Imrr5kwmoUGyPoymXuIgRv4n+Ln mMS8y7g0EcKHGHLwejG5rrcFny4BVwH9dHvlOKneP1P/ekcBMSMyeAijm Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10230"; a="305438216" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="305438216" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 15:25:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="625325455" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga004.jf.intel.com with ESMTP; 17 Jan 2022 15:25:09 -0800 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 17 Jan 2022 15:25:09 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Mon, 17 Jan 2022 15:25:09 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.169) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Mon, 17 Jan 2022 15:25:08 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rnvaxf/Doxy9L1u0W781iICAJEGt5eI8LuDUCNG06T2ku6EHyFnFQBEhzjLQlRxApG+95izfMAawyFPsrYQfmdC8M3QpujzL5ZfmSTxDwwKO88M8IJ0B668AFeDwNlUgCLbewG3NG1/qH7nsMFv9rYhBMS7eZjZ7kOVybp1+UxnqEzf1Jpty6JGe4Zq0LpUh3cFCWRV9qDDqrzOZ1cImuYQhrzV4kYmRDeuWVxvW/yepLySU+jMiDzOKtM25/b7Fi/xdb++Bo0cDHa9TIA7w9fDHgI+wdQ8NIGbfJ/yc2KatK6CCRX6HYXnf87ekVNn+dCooysV6UeX1w9c9hLtO8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9MX5FQiSWbnqIeMSJ7Sc8zY0Jc5rSneCC7mu/8gKVV4=; b=F56HfRTnoqxzTOE5fHtxwRLJ7szeiT/lCo/dFfXoqwM0CpTY6+PHaoH7RQ4SwsWriQQqAQbUSbNI0Yh1ph5umEs/zVJqzUYO4g3etwypwbNEbAMUmsmosAmfs5VD5RyQBCajIQ6AWx6pY2je/GBV6wii4CJrEm53LExpLTh/vDSUehJ45AUD8RJ8JJ3cb+2IK4wZVEMUXeWvDmoezM+cpen0T0/tzxhsHa3CtkA/tVGmMQ7aRfDgs+mELhoxs+Gbwgcj1M3OgtObTueZb6IRsVVsfJdCeyfskCwG2/lrMA3LXXc5ZKSjHiwujrqygGysw7oghgoMxerZJd4oJmqgWA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by DM6PR11MB4140.namprd11.prod.outlook.com (2603:10b6:5:19f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Mon, 17 Jan 2022 23:25:05 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::fc15:bd26:128a:f5f5%8]) with mapi id 15.20.4888.014; Mon, 17 Jan 2022 23:25:05 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , Subject: [RFC 10/10] drm: test: Simplify testing on UML with kunit.py Date: Tue, 18 Jan 2022 00:22:59 +0100 Message-ID: <20220117232259.180459-11-michal.winiarski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220117232259.180459-1-michal.winiarski@intel.com> References: <20220117232259.180459-1-michal.winiarski@intel.com> X-ClientProxiedBy: LO4P123CA0377.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18e::22) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 72fc8e1a-5aaa-4d55-bef9-08d9da1097ad X-MS-TrafficTypeDiagnostic: DM6PR11MB4140:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2150; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LvmuZM26OvJZY3g4MScEkibXR/nzOYE36E+kGt3s21iS+Pp2bw8j2TIOB98ejmjVwyAgEtaXieMw3Mt4rqyuQhoLOCeFQkUX7ltzdMhbmz4bJX+XIymILFPqkT16TQeltnQJMlJMMmdCVSMTaCehnItUiwmFaolm9kHOm9njq4wlCFk29y8/cPDHkiYEAfcA46hh+wsEswZVx1G+0DPH3hcmn+122MgZDRqZXsaXIrYF050AdyW0TstcLEOV9zIW8aYFq0ZnLoiQGlgvLwH9q/ZUGPuK5upuq0CP8dM1W4KAg1r+A4XoIvlcjSst4aI0oOvkNzr63DKASWwxrDzG65vTRv5TC9MmWARXvF7CZo5zY85LGTg+83jV8kELd3qAdy9qFuvKHzjqzC/2CXPlnVc8xiwroZT0zaGA5HFNEsbiw0prfZ4/K+L3VVUN+T9Y4dh/uVxipyq/QaEyuH40cclGCnkxD1lm95zcB4vKDEXDsw3/mvT/YhfMZ2hg8fukmoLmvUJEVgX7PE24kGnU5fVnuEGziwujyO93DKJreklJI38oIWrpUzgWX2TfISuJaOFQbnsySub3shsUPTnhx7TXib4FLCDcYmMDwvyWWcYqBrnL156E0RuV3e0iUe5tLupQkgR6fQhBWS2vvU0BUQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(508600001)(7416002)(186003)(6506007)(82960400001)(86362001)(8676002)(6512007)(6666004)(38100700002)(8936002)(66556008)(54906003)(5660300002)(2906002)(6486002)(316002)(36756003)(2616005)(66946007)(26005)(1076003)(4326008)(66476007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?kuHH2J5tg8G+AhhhK8LIQRv47310?= =?utf-8?q?5Hkr/4VgJtp4bYAiNMDZjLomZX2iRIPd1FEE12JFbi06WNU1jwbvv/6L6qvZcFbHF?= =?utf-8?q?UzofbRQlMw13lqVfcUyV1xKpaY9wthQeYS+bixLsrNt+zqT34/fJsM4fAwLfEsd8d?= =?utf-8?q?1mHG/HtWlQDZB+gB2K9twZPEM2LCE8iV2OVKJWh3MjS47b4HXRjYsXYFILF7lk6mw?= =?utf-8?q?946/dSCwZgbIW227Y7fk3Elc1UySHGZLgke/zyiUvXH1n7BoiHEszCzRbsveFCw37?= =?utf-8?q?tweYRkGO1IV/ULp8wK/rPD7r35euWZ4a/fu6Z2ZPY2CpoumojehISxKc0KQDMiu+F?= =?utf-8?q?gB3AdasRUtwXrMRaau5vr1ihkM2SGKB21BurCfJUAIWiXZI/2lJUqdB+p9slNNZYn?= =?utf-8?q?xk/swP16yKuYn58w9yGCx4IPsce9B7wKUthb1g38cj4dmsIGdZ3s7OYWE5JnzdKS7?= =?utf-8?q?WiFruHCyh1iipfDovRd52AzJxOa2GQpk0SZqLY2Wl+keqDH4Tl4Wx8+Xj6RwImSWD?= =?utf-8?q?BuQubmJgFEn6xAC0Ey3zADgNVTYByzsCkFirdQ8R8hwXegwVtkR56IzixMqMGDerO?= =?utf-8?q?z7amgiSKQc0OBZAuxwC1ECqYwPaJDjmPGCkE2QREKUeHWyU74Bw1v6caRqG6r1KpG?= =?utf-8?q?Y14PB0QhuhMDBICOx5c4ONTk2Dm1PeHarSsucwNqvIRA127tnhwbI+i0aIbj5gn3/?= =?utf-8?q?A8llqHvMRyrVwD3sWfEk2fjM2ZrIE+keNE/Kw+pWv4/2dz4X/WiMVyQ3RZIbdTw8c?= =?utf-8?q?5CUErmvdkRhRdaM0wVGUKN1OPJuqbUHaCW+NED+NXi6RyKw87O9SCXcNgDiXenFHb?= =?utf-8?q?aqY/bavFXthDdGW656Uecn70VVnNat4/DAQJYdo+rjEUEVMQ8zzHdThf6v98mSa8X?= =?utf-8?q?Vhm++Sld6p/QrKcKmb0CFDMBFtyH7SDed0fLKjVDm7nrdPjEgmX0xQY2/aroOSl+z?= =?utf-8?q?7+TmRABBbmvqSYTFZ7C2cudkBuiyOPp4CDAMHQ8AEzMv96UvnGGBdSXNKIsBTJ09n?= =?utf-8?q?P4MjucXF9ysgqSTpbeLYz8UX5ZboAnBwxEhqMzctURdt4m/HzujDX1Y/C93jSu2/N?= =?utf-8?q?fnpD93envVDJP2HC0sEv+ha7Ytz2746I/qqH9sFvZAqISZjcPG1KpE4auZa0LjBH1?= =?utf-8?q?KMnxPTy+GbXvZLfp+PatK9Zg+TIRZRvMCtSszRmzDNNws7qIC25R3oI4XcUw4bv1Z?= =?utf-8?q?YaAhS5TWmihAETiqFSFJW/2l26/oCswnd2MEJYnplvuOBblbbl91A0v6op9+m/GRz?= =?utf-8?q?y1SyR7sLyQ7YlRZW0HJAs2Y/abWja7IRcPwd34oKI3JWE0a2gcUekRVSL7LCxw/jV?= =?utf-8?q?zGFgX2LsDO9rveunexO7Culm7RXNbm54Tfxza5G09EppU18mZEBOCrUqqavo1Tbq/?= =?utf-8?q?r1Ne2+0Pjgesd+noDWgr3VdU9itbvxEFHjbBjVL0J3xO6elh4y+X0QTFhrMQ7CsKv?= =?utf-8?q?dDKqTbxoOW7IWBPb72TH0ImjjKWIPXWeIhlQLfEbFknKwnE0OnFuBuTDE3XLSjW/K?= =?utf-8?q?HyTOPWgod6LelF8RFTsv61R/KLuCFmHKQK0ECb5j7SPWxEV/sqkx6oYc3RKteG/F/?= =?utf-8?q?7GrJIpIeYU5rfJThWhJLXOdGvnZSxZ+spAEbFK3S1A54uC49pF58yQ=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 72fc8e1a-5aaa-4d55-bef9-08d9da1097ad X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2022 23:25:05.0431 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dP/dmuA+t0eUJZ723cqyePaB+n36W7J89FkvDgMpg6GrAMx+VNiqru2xA+wTmgWqdS0I1Fi02pXBvMCS2TZurtFIMthXGLYZTkJV3Zai0nU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4140 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , Thomas Zimmermann , David Airlie , Brendan Higgins , Daniel Latypov , Arkadiusz Hiler , Petri Latvala Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" DRM depends on IOMEM and DMA, introduce an additional Kconfig to pull in IOMEM and DMA emulation on UML. Also, add .kunitconfig to simplify running DRM tests with: ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm Signed-off-by: Michał Winiarski --- drivers/gpu/drm/.kunitconfig | 3 +++ drivers/video/Kconfig | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 drivers/gpu/drm/.kunitconfig diff --git a/drivers/gpu/drm/.kunitconfig b/drivers/gpu/drm/.kunitconfig new file mode 100644 index 000000000000..6ec04b4c979d --- /dev/null +++ b/drivers/gpu/drm/.kunitconfig @@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_KUNIT_TEST=y diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 427a993c7f57..0e6028f9b09e 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -46,5 +46,9 @@ if FB || SGI_NEWPORT_CONSOLE endif +config DRM_UML_IO_EMULATION + def_bool y if UML && KUNIT + select UML_DMA_EMULATION + select UML_IOMEM_EMULATION endmenu