From nobody Tue Apr 28 02:28:35 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01832C433EF for ; Wed, 8 Jun 2022 03:58:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230047AbiFHD6a (ORCPT ); Tue, 7 Jun 2022 23:58:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231790AbiFHD6C (ORCPT ); Tue, 7 Jun 2022 23:58:02 -0400 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE54524F95B for ; Tue, 7 Jun 2022 18:09:20 -0700 (PDT) Received: by mail-oi1-x232.google.com with SMTP id h188so26226454oia.2 for ; Tue, 07 Jun 2022 18:09:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rjjg1a3nWCUoP0yEvGEXGikIUB9NR8vRANik7NG4UXI=; b=M/5hSOXxs30Bh27FoPJftTlLbh0zsD2U4j9E0JkOZaWL68YlZjHZAlOmgDN8bmY9H0 l+0tBHR2RCNjLc85FvowWeunqAhN6ingu5slKNpIyY6fUQ57Y3HQRKcBQOE239xyQFzO jEJbF62TATxUeDJFxo5Zs+vXa58fB3SxdCaIuGEJmCxMFr1moSC7y+5v3cL1Wkm8seBQ fzeiEZtouveHyoSZN/SBq405rpSfggY0amcDFNfI6WjckGFbM3Rk1I4tkckGDMMYT1gx +cSwwMjG+rSwWBo0hIWekFv78YYAih7iOKYsJDapLnBstWeSpViekMTdBGSyGcYKBWJ9 UYmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rjjg1a3nWCUoP0yEvGEXGikIUB9NR8vRANik7NG4UXI=; b=qOUqPVuYGmyk4ZaTX2InUfbrDWDNHdTGj7mfuqr2zW8PNwl2ofzWUuiyWidNuKJta7 LmwJCe8xzAXaZUrlpThv9x6mMItfKpkm/Teprqj28aJ9dOhJLKxWz2KDEdEgDvu3nGwl kSlYtPyct+7OVoyuhWgBbjx/cgei6uxbfyR9j56ZC/U+e2qFsbdz0srtm21C35puSP7Q oyGck+IYTujhKif8qZbtXqWHFeOdLToRGosGIvJcCPbh1ZFLDoGPy85AUrudEEPENebT yDuQ4LG7Yvmn8Bp0Cp/AcoJRxu8KRpvGIk66NzZS7ZDRZ/hJUwyUI4uO/cD2VhEum8nX TtNA== X-Gm-Message-State: AOAM532ncxCsG1I7nd84oPgJ90rdZ/MzbYlSYMeodeJ4osPZfxghykT8 JnsgT3xgCX16828oNgPROndF0w== X-Google-Smtp-Source: ABdhPJz7MM4T3UHdHhZ8nXaORar5QOfh6c85WGMix2iX+xg4uj7QGHtyCtuOK4vUQnlV0KPqklOlRg== X-Received: by 2002:a05:6808:1189:b0:32b:7fb5:f443 with SMTP id j9-20020a056808118900b0032b7fb5f443mr1044217oil.269.1654650539203; Tue, 07 Jun 2022 18:08:59 -0700 (PDT) Received: from fedora.. ([2804:14d:8084:84c6:fe26:c42d:aab9:fa8a]) by smtp.gmail.com with ESMTPSA id c16-20020a544e90000000b0032b1b84f4e3sm10343057oiy.22.2022.06.07.18.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 18:08:58 -0700 (PDT) From: =?UTF-8?q?Ma=C3=ADra=20Canal?= To: Harry Wentland , Leo Li , Rodrigo Siqueira , Alex Deucher , christian.koenig@amd.com, Dmytro Laktyushkin , Jun Lei , Nicholas Choi , Harrison Chiu , Mark Yacoub , Sean Paul , Daniel Vetter , Javier Martinez Canillas , Isabella Basso , magalilemes00@gmail.com, tales.aparecida@gmail.com, mwen@igalia.com, andrealmeid@riseup.net, David Gow , Daniel Latypov , brendanhiggins@google.com Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, =?UTF-8?q?Ma=C3=ADra=20Canal?= Subject: [RFC 1/3] drm/amd/display: Introduce KUnit to DML Date: Tue, 7 Jun 2022 22:07:08 -0300 Message-Id: <20220608010709.272962-2-maira.canal@usp.br> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220608010709.272962-1-maira.canal@usp.br> References: <20220608010709.272962-1-maira.canal@usp.br> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org KUnit unifies the test structure and provides helper tools that simplify the development. Basic use case allows running tests as regular processes, which makes easier to run unit tests on a development machine and to integrate the tests in a CI system. This commit introduce a basic unit test to one part of the Display Mode Library: display_mode_lib, in order to introduce the basic structure of the tests on the DML. Signed-off-by: Ma=C3=ADra Canal --- drivers/gpu/drm/amd/display/Kconfig | 1 + .../gpu/drm/amd/display/amdgpu_dm/Makefile | 5 ++ .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 + .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 3 + .../drm/amd/display/amdgpu_dm/tests/Kconfig | 29 +++++++ .../drm/amd/display/amdgpu_dm/tests/Makefile | 14 ++++ .../amdgpu_dm/tests/display_mode_lib_test.c | 83 +++++++++++++++++++ .../amd/display/amdgpu_dm/tests/dml_test.c | 23 +++++ .../amd/display/amdgpu_dm/tests/dml_test.h | 13 +++ 9 files changed, 174 insertions(+) create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/tests/Kconfig create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/tests/Makefile create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/tests/display_mod= e_lib_test.c create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.c create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.h diff --git a/drivers/gpu/drm/amd/display/Kconfig b/drivers/gpu/drm/amd/disp= lay/Kconfig index 127667e549c1..83042e2e4d22 100644 --- a/drivers/gpu/drm/amd/display/Kconfig +++ b/drivers/gpu/drm/amd/display/Kconfig @@ -53,5 +53,6 @@ config DRM_AMD_SECURE_DISPLAY of crc of specific region via debugfs. Cooperate with specific DMCU FW. =20 +source "drivers/gpu/drm/amd/display/amdgpu_dm/tests/Kconfig" =20 endmenu diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/Makefile b/drivers/gpu/d= rm/amd/display/amdgpu_dm/Makefile index 718e123a3230..d25b63566640 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/Makefile +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/Makefile @@ -24,6 +24,11 @@ # It provides the control and status of dm blocks. =20 =20 +AMDGPU_DM_LIBS =3D tests + +AMD_DM =3D $(addsuffix /Makefile, $(addprefix $(FULL_AMD_DISPLAY_PATH)/amd= gpu_dm/,$(AMDGPU_DM_LIBS))) + +include $(AMD_DM) =20 AMDGPUDM =3D amdgpu_dm.o amdgpu_dm_irq.o amdgpu_dm_mst_types.o amdgpu_dm_c= olor.o =20 diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gp= u/drm/amd/display/amdgpu_dm/amdgpu_dm.c index cb1e9bb60db2..f73da1e0088f 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -1655,6 +1655,7 @@ static int amdgpu_dm_init(struct amdgpu_device *adev) goto error; } =20 + amdgpu_dml_test_init(); =20 DRM_DEBUG_DRIVER("KMS initialized.\n"); =20 @@ -1678,6 +1679,8 @@ static void amdgpu_dm_fini(struct amdgpu_device *adev) { int i; =20 + amdgpu_dml_test_exit(); + if (adev->dm.vblank_control_workqueue) { destroy_workqueue(adev->dm.vblank_control_workqueue); adev->dm.vblank_control_workqueue =3D NULL; diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gp= u/drm/amd/display/amdgpu_dm/amdgpu_dm.h index 3cc5c15303e6..e586d3a3d2f0 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h @@ -749,4 +749,7 @@ int dm_atomic_get_state(struct drm_atomic_state *state, struct amdgpu_dm_connector * amdgpu_dm_find_first_crtc_matching_connector(struct drm_atomic_state *stat= e, struct drm_crtc *crtc); + +int amdgpu_dml_test_init(void); +void amdgpu_dml_test_exit(void); #endif /* __AMDGPU_DM_H__ */ diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/Kconfig b/drivers/= gpu/drm/amd/display/amdgpu_dm/tests/Kconfig new file mode 100644 index 000000000000..bd1d971d4452 --- /dev/null +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/Kconfig @@ -0,0 +1,29 @@ +# SPDX-License-Identifier: MIT +menu "DML Unit Tests" + depends on DRM_AMD_DC && KUNIT=3Dm + +config DISPLAY_MODE_LIB_KUNIT_TEST + bool "Enable unit tests for dml/display_mode_lib" if !DML_KUNIT_TEST + default y if DML_KUNIT_TEST + help + Enables unit tests for the dml/display_mode_lib. 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 DML_KUNIT_TEST + bool "Run all unit tests for DML" if !KUNIT_ALL_TESTS + default KUNIT_ALL_TESTS + help + Enables unit tests for the Display Mode Library. 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. + +endmenu diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/Makefile b/drivers= /gpu/drm/amd/display/amdgpu_dm/tests/Makefile new file mode 100644 index 000000000000..53b38e340564 --- /dev/null +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/Makefile @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for the KUnit Tests for DML +# + +DML_TESTS =3D dml_test.o + +ifdef CONFIG_DISPLAY_MODE_LIB_KUNIT_TEST +DML_TESTS +=3D display_mode_lib_test.o +endif + +AMD_DAL_DML_TESTS =3D $(addprefix $(AMDDALPATH)/amdgpu_dm/tests/,$(DML_TES= TS)) + +AMD_DISPLAY_FILES +=3D $(AMD_DAL_DML_TESTS) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/display_mode_lib_t= est.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/display_mode_lib_test.c new file mode 100644 index 000000000000..3ea0e7fb13e3 --- /dev/null +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/display_mode_lib_test.c @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: MIT +/* + * KUnit tests for dml/display_mode_lib.h + * + * Copyright (C) 2022, Ma=C3=ADra Canal + */ + +#include +#include "../../dc/dml/display_mode_lib.h" +#include "../../dc/dml/display_mode_enums.h" +#include "dml_test.h" + +/** + * DOC: Unit tests for AMDGPU DML display_mode_lib.h + * + * The display_mode_lib.h holds the functions responsible for the instanti= ation + * and logging of the Display Mode Library (DML). + * + * These KUnit tests were implemented with the intention of assuring the p= roper + * logging of the DML. + * + */ + +static void dml_get_status_message_test(struct kunit *test) +{ + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_VALIDATION_OK), "Vali= dation OK"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_SCALE_RATIO_TAP)= , "Scale ratio/tap"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_SOURCE_PIXEL_FOR= MAT), "Source pixel format"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_VIEWPORT_SIZE), = "Viewport size"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_TOTAL_V_ACTIVE_B= W), "Total vertical active bandwidth"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_DIO_SUPPORT), "D= IO support"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_NOT_ENOUGH_DSC),= "Not enough DSC Units"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_DSC_CLK_REQUIRED= ), "DSC clock required"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_URGENT_LATENCY),= "Urgent latency"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_REORDERING_BUFFE= R), "Re-ordering buffer"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_DISPCLK_DPPCLK),= "Dispclk and Dppclk"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_TOTAL_AVAILABLE_= PIPES), "Total available pipes"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_NUM_OTG), "Numbe= r of OTG"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_WRITEBACK_MODE),= "Writeback mode"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_WRITEBACK_LATENC= Y), "Writeback latency"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_WRITEBACK_SCALE_= RATIO_TAP), "Writeback scale ratio/tap"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_CURSOR_SUPPORT),= "Cursor support"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_PITCH_SUPPORT), = "Pitch support"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_PTE_BUFFER_SIZE)= , "PTE buffer size"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_DSC_INPUT_BPC), = "DSC input bpc"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_PREFETCH_SUPPORT= ), "Prefetch support"); + KUNIT_EXPECT_STREQ(test, dml_get_status_message(DML_FAIL_V_RATIO_PREFETCH= ), "Vertical ratio prefetch"); +} + +static struct kunit_case display_mode_library_test_cases[] =3D { + KUNIT_CASE(dml_get_status_message_test), + { } +}; + +static struct kunit_suite display_mode_lib_test_suite =3D { + .name =3D "dml-display-mode-lib", + .test_cases =3D display_mode_library_test_cases, +}; + +static struct kunit_suite *display_mode_lib_test_suites[] =3D { &display_m= ode_lib_test_suite, NULL }; + +int display_mode_lib_test_init(void) +{ + pr_info("=3D=3D=3D> Running display_mode_lib KUnit Tests"); + pr_info("**********************************************************"); + pr_info("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **"); + pr_info("** **"); + pr_info("** display_mode_lib KUnit Tests are being run. This **"); + pr_info("** means that this is a TEST kernel and should not be **"); + pr_info("** used for production. **"); + pr_info("** **"); + pr_info("** If you see this message and you are not debugging **"); + pr_info("** the kernel, report this immediately to your vendor! **"); + pr_info("** **"); + pr_info("**********************************************************"); + + return __kunit_test_suites_init(display_mode_lib_test_suites); +} + +void display_mode_lib_test_exit(void) +{ + return __kunit_test_suites_exit(display_mode_lib_test_suites); +} diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.c b/drive= rs/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.c new file mode 100644 index 000000000000..9a5d47597c10 --- /dev/null +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.c @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include "dml_test.h" + +/** + * amdgpu_dml_test_init() - Initialise KUnit Tests for DML + * + * It aggregates all KUnit Tests related to the Display Mode Library (DML). + * The DML contains multiple modules, and to assure the modularity of the + * tests, the KUnit Tests for a DML module are also gathered in a separated + * module. Each KUnit Tests module is initiated in this function. + * + */ +int amdgpu_dml_test_init(void) +{ + display_mode_lib_test_init(); + return 0; +} + +void amdgpu_dml_test_exit(void) +{ + display_mode_lib_test_exit(); +} diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.h b/drive= rs/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.h new file mode 100644 index 000000000000..2786db9d0e87 --- /dev/null +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef DML_TEST_H_ +#define DML_TEST_H_ + +#if defined (CONFIG_DISPLAY_MODE_LIB_KUNIT_TEST) +int display_mode_lib_test_init(void); +void display_mode_lib_test_exit(void); +#else +static inline int display_mode_lib_test_init(void) { return 0; } +static inline void display_mode_lib_test_exit(void) { } +#endif + +#endif --=20 2.36.1 From nobody Tue Apr 28 02:28:35 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DAEDC433EF for ; Wed, 8 Jun 2022 03:59:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbiFHD7s (ORCPT ); Tue, 7 Jun 2022 23:59:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231666AbiFHD6I (ORCPT ); Tue, 7 Jun 2022 23:58:08 -0400 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 210422509CB for ; Tue, 7 Jun 2022 18:09:47 -0700 (PDT) Received: by mail-ot1-x32d.google.com with SMTP id r12-20020a056830448c00b0060aec7b7a54so14106975otv.5 for ; Tue, 07 Jun 2022 18:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TH0uwVgHZAwq0jKJ2rY7rr0n6nybjWr8m8j939NAcUE=; b=qqCZGsFj3WTgMs3F8eplwxhY8tlcCpyszawL420QxCE1KGOlb2XREx+0YHhA/DXDht y6FTG7VikxjZzWmeWN6N7dhQM6c04xnY1Y9LYsQa0IHup3PFgpYPGjBz949gatfecqpi UTKgVldl/uVChP2nADj5fLDq6mcJx1CAkykZRO+OF6G0E/S+cXNXjIZRZYjb71pMMMQu BR4xCLhM2SA+nS2/WaI7iPZmaNvV1DOWF24hrKmioPRzxxEm7vDUUV1peqgLyn8ZlhgR Hn5h/IxgLHkgxbj9VkurqF+8cQfRShUn2s3hqev+lUZXCEtavv3dWnsflftx7KmbvLnC k0Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TH0uwVgHZAwq0jKJ2rY7rr0n6nybjWr8m8j939NAcUE=; b=BfsZekbHDH0R690zWzmBtR4jbemyDNUJAfVLCEMZblBmiQQwaqScntGFg/CKqbAbA9 AlFFqMvcmV9SlJ/RG4AkHSZ6Qfp1VS1lkAB2x8CksjHOD5rixbbhDTzfahK67t/rSsD2 CrpQRLQKkE4dl8o5x42k+0i5RjYbKYg/bEpIX/U095BP6/NhZpLLEEGxHsixCnjc3wMr UaJA9AlU2iww7rjHSWGhIK6otJ+HOtxX221GqnqdFIdSAYrqC42elUo8xufBpj0LpwPH M/vZImRCUN5UjzOA7X+V3zQj2TPnDXn1HWhELqpVawBOxBlvRBPUoF5Wsmz+mqDwJcDe o3uA== X-Gm-Message-State: AOAM530OtYwW5J+hdOmSBMe6JxCTZ6zblUZ1rsU51oJYVVYadzdIfMk5 oYuya6KQwe1q11YP8JBMvChxLg== X-Google-Smtp-Source: ABdhPJzuiHfBdj/hVttQ2zZajzaYxynowqNPbS/D5BqnB7NeOLdkb2qK7wfnz1fb68HTl5Wobxs8vA== X-Received: by 2002:a05:6830:1456:b0:60b:f7b9:fc49 with SMTP id w22-20020a056830145600b0060bf7b9fc49mr6437094otp.260.1654650560284; Tue, 07 Jun 2022 18:09:20 -0700 (PDT) Received: from fedora.. ([2804:14d:8084:84c6:fe26:c42d:aab9:fa8a]) by smtp.gmail.com with ESMTPSA id c16-20020a544e90000000b0032b1b84f4e3sm10343057oiy.22.2022.06.07.18.09.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 18:09:19 -0700 (PDT) From: =?UTF-8?q?Ma=C3=ADra=20Canal?= To: Harry Wentland , Leo Li , Rodrigo Siqueira , Alex Deucher , christian.koenig@amd.com, Dmytro Laktyushkin , Jun Lei , Nicholas Choi , Harrison Chiu , Mark Yacoub , Sean Paul , Daniel Vetter , Javier Martinez Canillas , Isabella Basso , magalilemes00@gmail.com, tales.aparecida@gmail.com, mwen@igalia.com, andrealmeid@riseup.net, David Gow , Daniel Latypov , brendanhiggins@google.com Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, =?UTF-8?q?Ma=C3=ADra=20Canal?= Subject: [RFC 2/3] drm/amd/display: Move bw_fixed macros to header file Date: Tue, 7 Jun 2022 22:07:10 -0300 Message-Id: <20220608010709.272962-3-maira.canal@usp.br> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220608010709.272962-1-maira.canal@usp.br> References: <20220608010709.272962-1-maira.canal@usp.br> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The macros defined at bw_fixed are important mathematical definitions, specifying masks to get the fractional part and the maximum and minimum values of I64. In order to enable unit tests for bw_fixed, it is relevant to have access to those macros. This commit moves the macros to the header file, making it accessible to future unit tests. Signed-off-by: Ma=C3=ADra Canal --- .../gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c | 14 +------------- drivers/gpu/drm/amd/display/dc/inc/bw_fixed.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c b/drivers/= gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c index 6ca288fb5fb9..d944570e5695 100644 --- a/drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c +++ b/drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c @@ -26,19 +26,7 @@ #include "bw_fixed.h" =20 =20 -#define MIN_I64 \ - (int64_t)(-(1LL << 63)) - -#define MAX_I64 \ - (int64_t)((1ULL << 63) - 1) - -#define FRACTIONAL_PART_MASK \ - ((1ULL << BW_FIXED_BITS_PER_FRACTIONAL_PART) - 1) - -#define GET_FRACTIONAL_PART(x) \ - (FRACTIONAL_PART_MASK & (x)) - -static uint64_t abs_i64(int64_t arg) +uint64_t abs_i64(int64_t arg) { if (arg >=3D 0) return (uint64_t)(arg); diff --git a/drivers/gpu/drm/amd/display/dc/inc/bw_fixed.h b/drivers/gpu/dr= m/amd/display/dc/inc/bw_fixed.h index d1656c9d50df..064839425b96 100644 --- a/drivers/gpu/drm/amd/display/dc/inc/bw_fixed.h +++ b/drivers/gpu/drm/amd/display/dc/inc/bw_fixed.h @@ -33,12 +33,26 @@ struct bw_fixed { int64_t value; }; =20 +#define MIN_I64 \ + (int64_t)(-(1ULL << 63)) + +#define MAX_I64 \ + (int64_t)((1ULL << 63) - 1) + +#define FRACTIONAL_PART_MASK \ + ((1ULL << BW_FIXED_BITS_PER_FRACTIONAL_PART) - 1) + +#define GET_FRACTIONAL_PART(x) \ + (FRACTIONAL_PART_MASK & (x)) + #define BW_FIXED_MIN_I32 \ (int64_t)(-(1LL << (63 - BW_FIXED_BITS_PER_FRACTIONAL_PART))) =20 #define BW_FIXED_MAX_I32 \ (int64_t)((1ULL << (63 - BW_FIXED_BITS_PER_FRACTIONAL_PART)) - 1) =20 +uint64_t abs_i64(int64_t arg); + static inline struct bw_fixed bw_min2(const struct bw_fixed arg1, const struct bw_fixed arg2) { --=20 2.36.1 From nobody Tue Apr 28 02:28:35 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11500C433EF for ; Wed, 8 Jun 2022 04:50:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231361AbiFHEus (ORCPT ); Wed, 8 Jun 2022 00:50:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232052AbiFHEsi (ORCPT ); Wed, 8 Jun 2022 00:48:38 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80F3B23F20A for ; Tue, 7 Jun 2022 18:10:08 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id h188so26227886oia.2 for ; Tue, 07 Jun 2022 18:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5p+YY8gybAKuQcsMVh2MWy7OP9yApdl+Art1AWfbko4=; b=l0vH6uF2Kay4roGyviEB6yUha0FWjErNM5oSVGGa9GYxycj69SewTV4S+exXuVIrld tcD0oVt97q4NnrQ5WUbOxoLgD4uHd7K17nmo5pC4oWCihLwe+aKT9zNj1UfumIkGSOlf rf4sVKhsJk/0rM7laRh6sJCKrmmSak6qTexnX1kIp+46qQTQcoZJcituYmW4kFuZzgmP /B+yOZkotlB2O62UuGVKIqpoUDKLgf8cY2afKSv0a5RoOmHK3DhECgn2ywgfS7dIZQE0 +jkUg+eQ3NZKl2t5LuPU0qgMZnpdm7x8eMxgUAVEuh9MZzLoDuiT90QO8FRB46Ex65fd D9kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5p+YY8gybAKuQcsMVh2MWy7OP9yApdl+Art1AWfbko4=; b=8ADK7+KcNh844EkUA6/nUDkgjlc/QT5TDmyFXZzM7CnEa5MIqjMaU1Tuifn4TJNbTG rdh1KpoIv61TUUaOqgd1qBrY3tum8WLYer+5NhbW8s9Ukz8LCGz7Mc76cDjtOAxJIfKi Q2gagQThWi7N08ipiksL7M8e6RPg2Y7QtG7qoot0HWKmVq+70ZS9apzgTh4oZfrq+g4E NJ5CXHfGj+Lrkjy7R80EbOdOJlxgkUXkWngsEggcdDwADCLmGsqGIV/pWNqrG1xICYm6 2uubVPx6eqiNswtsydtH6166n+NV9z1KtD9HhdNRWDuQvG40NQaBKODC5Tnmq8roNwlw h7aw== X-Gm-Message-State: AOAM532r+M3xWQUQyCnFFtzIuk+f8f8SHPXwGtdZ/uBbAHqBOrJ+2Xts 8OYEhTr+rp2aSJw2lj87FE07zQ== X-Google-Smtp-Source: ABdhPJzAtEy3VpvtGd8JE19u4+8me6FEpwHjaGKdRGUz1fqMacKFsUnOWNFd1Awi6hzS+5tNdeA1Ow== X-Received: by 2002:a05:6808:bc7:b0:32b:1c5a:d8b1 with SMTP id o7-20020a0568080bc700b0032b1c5ad8b1mr1000182oik.185.1654650578632; Tue, 07 Jun 2022 18:09:38 -0700 (PDT) Received: from fedora.. ([2804:14d:8084:84c6:fe26:c42d:aab9:fa8a]) by smtp.gmail.com with ESMTPSA id c16-20020a544e90000000b0032b1b84f4e3sm10343057oiy.22.2022.06.07.18.09.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 18:09:38 -0700 (PDT) From: =?UTF-8?q?Ma=C3=ADra=20Canal?= To: Harry Wentland , Leo Li , Rodrigo Siqueira , Alex Deucher , christian.koenig@amd.com, Dmytro Laktyushkin , Jun Lei , Nicholas Choi , Harrison Chiu , Mark Yacoub , Sean Paul , Daniel Vetter , Javier Martinez Canillas , Isabella Basso , magalilemes00@gmail.com, tales.aparecida@gmail.com, mwen@igalia.com, andrealmeid@riseup.net, David Gow , Daniel Latypov , brendanhiggins@google.com Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, =?UTF-8?q?Ma=C3=ADra=20Canal?= Subject: [RFC 3/3] drm/amd/display: Introduce KUnit tests to the bw_fixed library Date: Tue, 7 Jun 2022 22:07:11 -0300 Message-Id: <20220608010709.272962-4-maira.canal@usp.br> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220608010709.272962-1-maira.canal@usp.br> References: <20220608010709.272962-1-maira.canal@usp.br> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Magali Lemes The bw_fixed library performs a lot of the mathematical operations involving fixed-point arithmetic and the conversion of integers to fixed-point representation. As fixed-point representation is the base foundation of the DML calcs operations, this unit tests intend to assure the proper functioning of the basic mathematical operations of fixed-point arithmetic, such as multiplication, conversion from fractional to fixed-point number, and more. Co-developed-by: Tales Aparecida Signed-off-by: Tales Aparecida Signed-off-by: Magali Lemes Co-developed-by: Ma=C3=ADra Canal Signed-off-by: Ma=C3=ADra Canal --- .../drm/amd/display/amdgpu_dm/tests/Kconfig | 12 + .../drm/amd/display/amdgpu_dm/tests/Makefile | 4 + .../amdgpu_dm/tests/calcs/bw_fixed_test.c | 322 ++++++++++++++++++ .../amd/display/amdgpu_dm/tests/dml_test.c | 3 + .../amd/display/amdgpu_dm/tests/dml_test.h | 8 + 5 files changed, 349 insertions(+) create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/tests/calcs/bw_fi= xed_test.c diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/Kconfig b/drivers/= gpu/drm/amd/display/amdgpu_dm/tests/Kconfig index bd1d971d4452..540b2f79f971 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/Kconfig +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/Kconfig @@ -2,6 +2,18 @@ menu "DML Unit Tests" depends on DRM_AMD_DC && KUNIT=3Dm =20 +config BW_FIXED_KUNIT_TEST + bool "Enable unit tests for dml/calcs/bw_fixed" if !DML_KUNIT_TEST + default y if DML_KUNIT_TEST + help + Enables unit tests for the dml/calcs/bw_fixed. 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 DISPLAY_MODE_LIB_KUNIT_TEST bool "Enable unit tests for dml/display_mode_lib" if !DML_KUNIT_TEST default y if DML_KUNIT_TEST diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/Makefile b/drivers= /gpu/drm/amd/display/amdgpu_dm/tests/Makefile index 53b38e340564..23109e51cf32 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/Makefile +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/Makefile @@ -5,6 +5,10 @@ =20 DML_TESTS =3D dml_test.o =20 +ifdef CONFIG_BW_FIXED_KUNIT_TEST +DML_TESTS +=3D calcs/bw_fixed_test.o +endif + ifdef CONFIG_DISPLAY_MODE_LIB_KUNIT_TEST DML_TESTS +=3D display_mode_lib_test.o endif diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/calcs/bw_fixed_tes= t.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/calcs/bw_fixed_test.c new file mode 100644 index 000000000000..344c1517745e --- /dev/null +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/calcs/bw_fixed_test.c @@ -0,0 +1,322 @@ +// SPDX-License-Identifier: MIT +/* + * KUnit tests for dml/calcs/bw_fixed.h + * + * Copyright (C) 2022, Magali Lemes + * Copyright (C) 2022, Ma=C3=ADra Canal + * Copyright (C) 2022, Tales Aparecida + */ + +#include +#include "../../../dc/inc/bw_fixed.h" +#include "../dml_test.h" + +/** + * DOC: Unit tests for AMDGPU DML calcs/bw_fixed.h + * + * bw_fixed.h performs a lot of the mathematical operations involving + * fixed-point arithmetic and the conversion of integers to fixed-point + * representation. + * + * As fixed-point representation is the base foundation of the DML calcs + * operations, these tests intend to assure the proper functioning of the + * basic mathematical operations of fixed-point arithmetic, such as + * multiplication, conversion from fractional to fixed-point number, and m= ore. + * + */ + +static void abs_i64_test(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, 0ULL, abs_i64(0LL)); + + /* Argument type limits */ + KUNIT_EXPECT_EQ(test, (uint64_t)MAX_I64, abs_i64(MAX_I64)); + KUNIT_EXPECT_EQ(test, (uint64_t)MAX_I64 + 1, abs_i64(MIN_I64)); +} + +static void bw_int_to_fixed_nonconst_test(struct kunit *test) +{ + struct bw_fixed res; + + /* Add BW_FIXED_BITS_PER_FRACTIONAL_PART trailing 0s to binary number */ + res =3D bw_int_to_fixed_nonconst(1000); /* 0x3E8 */ + KUNIT_EXPECT_EQ(test, 16777216000, res.value); /* 0x3E8000000 */ + + res =3D bw_int_to_fixed_nonconst(-1000); /* -0x3E8 */ + KUNIT_EXPECT_EQ(test, -16777216000, res.value); /* -0x3E8000000 */ + + res =3D bw_int_to_fixed_nonconst(0LL); + KUNIT_EXPECT_EQ(test, 0, res.value); + + /** + * Test corner cases, as the function's argument has to be an int64_t + * between BW_FIXED_MIN_I32 and BW_FIXED_MAX_I32. + */ + res =3D bw_int_to_fixed_nonconst(BW_FIXED_MAX_I32 - 1); /* 0x7FFFFFFFFE = */ + KUNIT_EXPECT_EQ(test, 9223372036821221376, res.value); /* 0x7FFFFFFFFE000= 000 */ + + res =3D bw_int_to_fixed_nonconst(BW_FIXED_MIN_I32 + 1); /* -0x7FFFFFFFF= F */ + KUNIT_EXPECT_EQ(test, -9223372036837998592, res.value); /* -0x7FFFFFFFFF0= 00000 */ +} + +static void bw_frc_to_fixed_test(struct kunit *test) +{ + struct bw_fixed res; + + /* Extreme scenarios */ + + /* A fraction of N/N should result in "1.0" */ + res =3D bw_frc_to_fixed(MAX_I64, MAX_I64); + KUNIT_EXPECT_EQ(test, 1LL << BW_FIXED_BITS_PER_FRACTIONAL_PART, res.value= ); + + res =3D bw_frc_to_fixed(1, MAX_I64); + KUNIT_EXPECT_EQ(test, 0LL, res.value); + + res =3D bw_frc_to_fixed(0, MAX_I64); + KUNIT_EXPECT_EQ(test, 0LL, res.value); + + /* Turn a repeating decimal to the fixed-point representation */ + + /* A repeating decimal that doesn't round up the LSB */ + res =3D bw_frc_to_fixed(4, 3); + KUNIT_EXPECT_EQ(test, 22369621LL, res.value); /* 0x1555555 */ + + res =3D bw_frc_to_fixed(-4, 3); + KUNIT_EXPECT_EQ(test, -22369621LL, res.value); /* -0x1555555 */ + + res =3D bw_frc_to_fixed(99999997, 100000000); + KUNIT_EXPECT_EQ(test, 16777215LL, res.value); /* 0x0FFFFFF */ + + /* A repeating decimal that rounds up the MSB */ + res =3D bw_frc_to_fixed(5, 3); + KUNIT_EXPECT_EQ(test, 27962027LL, res.value); /* 0x1AAAAAB */ + + res =3D bw_frc_to_fixed(-5, 3); + KUNIT_EXPECT_EQ(test, -27962027LL, res.value); /* -0x1AAAAAB */ + + res =3D bw_frc_to_fixed(99999998, 100000000); + KUNIT_EXPECT_EQ(test, 1LL << BW_FIXED_BITS_PER_FRACTIONAL_PART, res.value= ); + + /* Turn a terminating decimal to the fixed-point representation */ + res =3D bw_frc_to_fixed(62609, 100); + KUNIT_EXPECT_EQ(test, 10504047165LL, res.value); /* 0X272170A3D */ + + res =3D bw_frc_to_fixed(-62609, 100); + KUNIT_EXPECT_EQ(test, -10504047165LL, res.value); /* -0X272170A3D */ +} + +static void bw_floor2_test(struct kunit *test) +{ + struct bw_fixed arg; + struct bw_fixed significance; + struct bw_fixed res; + + /* Round 10 down to the nearest multiple of 3 */ + arg.value =3D 10; + significance.value =3D 3; + res =3D bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, 9, res.value); + + /* Round 10 down to the nearest multiple of 5 */ + arg.value =3D 10; + significance.value =3D 5; + res =3D bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, 10, res.value); + + /* Round 100 down to the nearest multiple of 7 */ + arg.value =3D 100; + significance.value =3D 7; + res =3D bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, 98, res.value); + + /* Round an integer down to its nearest multiple should return itself */ + arg.value =3D MAX_I64; + significance.value =3D MAX_I64; + res =3D bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, MAX_I64, res.value); + + arg.value =3D MIN_I64; + significance.value =3D MIN_I64; + res =3D bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, MIN_I64, res.value); + + /* Value is a multiple of significance, result should be value */ + arg.value =3D MAX_I64; + significance.value =3D MIN_I64 + 1; + res =3D bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, MAX_I64, res.value); + + /* Round 0 down to the nearest multiple of any number should return 0 */ + arg.value =3D 0; + significance.value =3D MAX_I64; + res =3D bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, 0, res.value); + + arg.value =3D 0; + significance.value =3D MIN_I64; + res =3D bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, 0, res.value); +} + +static void bw_ceil2_test(struct kunit *test) +{ + struct bw_fixed arg; + struct bw_fixed significance; + struct bw_fixed res; + + /* Round 10 up to the nearest multiple of 3 */ + arg.value =3D 10; + significance.value =3D 3; + res =3D bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, 12, res.value); + + /* Round 10 up to the nearest multiple of 5 */ + arg.value =3D 10; + significance.value =3D 5; + res =3D bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, 10, res.value); + + /* Round 100 up to the nearest multiple of 7 */ + arg.value =3D 100; + significance.value =3D 7; + res =3D bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, 105, res.value); + + /* Round an integer up to its nearest multiple should return itself */ + arg.value =3D MAX_I64; + significance.value =3D MAX_I64; + res =3D bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, MAX_I64, res.value); + + arg.value =3D MIN_I64 + 1; + significance.value =3D MIN_I64 + 1; + res =3D bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, MIN_I64 + 1, res.value); + + /* Value is a multiple of significance, result should be value */ + arg.value =3D MAX_I64; + significance.value =3D MIN_I64 + 1; + res =3D bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, MAX_I64, res.value); + + /* Round 0 up to the nearest multiple of any number should return 0 */ + arg.value =3D 0; + significance.value =3D MAX_I64; + res =3D bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, 0, res.value); + + arg.value =3D 0; + significance.value =3D MIN_I64; + res =3D bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, 0, res.value); +} + +static void bw_mul_test(struct kunit *test) +{ + struct bw_fixed arg1; + struct bw_fixed arg2; + struct bw_fixed res; + struct bw_fixed ans; + + /* Extreme scenario */ + arg1.value =3D MAX_I64; + arg2.value =3D MIN_I64; + res =3D bw_mul(arg1, arg2); + KUNIT_EXPECT_EQ(test, BW_FIXED_MAX_I32 + 1, res.value); + + /* Testing multiplication property: x * 1 =3D x */ + arg1.value =3D 1; + arg2.value =3D MAX_I64; + res =3D bw_mul(arg1, arg2); + KUNIT_EXPECT_EQ(test, BW_FIXED_MAX_I32 + 1, res.value); + + arg1.value =3D 1; + arg2.value =3D MIN_I64; + res =3D bw_mul(arg1, arg2); + KUNIT_EXPECT_EQ(test, BW_FIXED_MIN_I32, res.value); + + /* Testing multiplication property: x * 0 =3D 0 */ + arg1.value =3D 0; + arg2.value =3D 0; + res =3D bw_mul(arg1, arg2); + KUNIT_EXPECT_EQ(test, 0, res.value); + + arg1.value =3D 0; + arg2.value =3D MAX_I64; + res =3D bw_mul(arg1, arg2); + KUNIT_EXPECT_EQ(test, 0, res.value); + + arg1.value =3D 0; + arg2.value =3D MIN_I64; + res =3D bw_mul(arg1, arg2); + KUNIT_EXPECT_EQ(test, 0, res.value); + + /* Testing multiplication between integers */ + res =3D bw_mul(bw_int_to_fixed(8), bw_int_to_fixed(10)); + KUNIT_EXPECT_EQ(test, 1342177280LL, res.value); /* 0x50000000 */ + + res =3D bw_mul(bw_int_to_fixed(10), bw_int_to_fixed(5)); + KUNIT_EXPECT_EQ(test, 838860800LL, res.value); /* 0x32000000 */ + + res =3D bw_mul(bw_int_to_fixed(-10), bw_int_to_fixed(7)); + KUNIT_EXPECT_EQ(test, -1174405120LL, res.value); /* -0x46000000 */ + + /* Testing multiplication between fractions and integers */ + res =3D bw_mul(bw_frc_to_fixed(4, 3), bw_int_to_fixed(3)); + ans =3D bw_int_to_fixed(4); + + /** + * As bw_frc_to_fixed(4, 3) didn't round up the fixed-point representatio= n, + * the ans must be subtrated by 1. + */ + KUNIT_EXPECT_EQ(test, ans.value - 1, res.value); + + res =3D bw_mul(bw_frc_to_fixed(5, 3), bw_int_to_fixed(3)); + ans =3D bw_int_to_fixed(5); + + /** + * As bw_frc_to_fixed(5, 3) rounds up the fixed-point representation, + * the ans must be added by 1. + */ + KUNIT_EXPECT_EQ(test, ans.value + 1, res.value); +} + +static struct kunit_case bw_fixed_test_cases[] =3D { + KUNIT_CASE(abs_i64_test), + KUNIT_CASE(bw_int_to_fixed_nonconst_test), + KUNIT_CASE(bw_frc_to_fixed_test), + KUNIT_CASE(bw_floor2_test), + KUNIT_CASE(bw_ceil2_test), + KUNIT_CASE(bw_mul_test), + { } +}; + +static struct kunit_suite bw_fixed_test_suite =3D { + .name =3D "dml-calcs-bw-fixed", + .test_cases =3D bw_fixed_test_cases, +}; + +static struct kunit_suite *bw_fixed_test_suites[] =3D { &bw_fixed_test_sui= te, NULL }; + +int bw_fixed_test_init(void) +{ + pr_info("=3D=3D=3D> Running calcs/bw_fixed KUnit Tests"); + pr_info("**********************************************************"); + pr_info("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **"); + pr_info("** **"); + pr_info("** calcs/bw_fixed KUnit Tests are being run. This means **"); + pr_info("** that this is a TEST kernel and should not be used **"); + pr_info("** for production. **"); + pr_info("** **"); + pr_info("** If you see this message and you are not debugging **"); + pr_info("** the kernel, report this immediately to your vendor! **"); + pr_info("** **"); + pr_info("**********************************************************"); + + return __kunit_test_suites_init(bw_fixed_test_suites); +} + +void bw_fixed_test_exit(void) +{ + return __kunit_test_suites_exit(bw_fixed_test_suites); +} diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.c b/drive= rs/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.c index 9a5d47597c10..98ae4e8cd952 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.c @@ -13,11 +13,14 @@ */ int amdgpu_dml_test_init(void) { + bw_fixed_test_init(); display_mode_lib_test_init(); + return 0; } =20 void amdgpu_dml_test_exit(void) { display_mode_lib_test_exit(); + bw_fixed_test_exit(); } diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.h b/drive= rs/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.h index 2786db9d0e87..d8fe38abd9bc 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.h +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/dml_test.h @@ -2,6 +2,14 @@ #ifndef DML_TEST_H_ #define DML_TEST_H_ =20 +#if defined (CONFIG_BW_FIXED_KUNIT_TEST) +int bw_fixed_test_init(void); +void bw_fixed_test_exit(void); +#else +static inline int bw_fixed_test_init(void) { return 0; } +static inline void bw_fixed_test_exit(void) { } +#endif + #if defined (CONFIG_DISPLAY_MODE_LIB_KUNIT_TEST) int display_mode_lib_test_init(void); void display_mode_lib_test_exit(void); --=20 2.36.1