Re: [Intel-gfx] [PATCH v4 03/11] drm/dp_mst: Add kunit tests for drm_dp_get_vc_payload_bw()

2023-11-17 Thread Ville Syrjälä
On Fri, Nov 17, 2023 at 05:27:37PM +0200, Imre Deak wrote:
> Add kunit test cases for drm_dp_get_vc_payload_bw() with all the DP1.4
> and UHBR link configurations.
> 
> v2:
> - List test cases in decreasing rate,lane count order matching the
>   corresponding DP Standard tables. (Ville)
> - Add references to the DP Standard tables.
> v3:
> - Sort the testcases properly.
> 
> Cc: Ville Syrjälä 
> Cc: Lyude Paul 
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Imre Deak 

Reviewed-by: Ville Syrjälä 

> ---
>  .../gpu/drm/tests/drm_dp_mst_helper_test.c| 147 ++
>  1 file changed, 147 insertions(+)
> 
> diff --git a/drivers/gpu/drm/tests/drm_dp_mst_helper_test.c 
> b/drivers/gpu/drm/tests/drm_dp_mst_helper_test.c
> index e3c818dfc0e6d..98d57d28aab6f 100644
> --- a/drivers/gpu/drm/tests/drm_dp_mst_helper_test.c
> +++ b/drivers/gpu/drm/tests/drm_dp_mst_helper_test.c
> @@ -68,6 +68,152 @@ static void dp_mst_calc_pbn_mode_desc(const struct 
> drm_dp_mst_calc_pbn_mode_test
>  KUNIT_ARRAY_PARAM(drm_dp_mst_calc_pbn_mode, drm_dp_mst_calc_pbn_mode_cases,
> dp_mst_calc_pbn_mode_desc);
>  
> +struct drm_dp_mst_calc_pbn_div_test {
> + int link_rate;
> + int lane_count;
> + fixed20_12 expected;
> +};
> +
> +#define fp_init(__int, __frac) { \
> + .full = (__int) * (1 << 12) + \
> + (__frac) * (1 << 12) / 10 \
> +}
> +
> +static const struct drm_dp_mst_calc_pbn_div_test 
> drm_dp_mst_calc_pbn_div_dp1_4_cases[] = {
> + /*
> +  * UHBR rates (DP Standard v2.1 2.7.6.3, specifying the rounded to
> +  * closest value to 2 decimal places):
> +  * .expected = .link_rate * .lane_count * 0.9671 / 8 / 54 / 100
> +  * DP1.4 rates (DP Standard v2.1 2.6.4.2):
> +  * .expected = .link_rate * .lane_count * 0.8000 / 8 / 54 / 100
> +  *
> +  * truncated to 5 decimal places.
> +  */
> + {
> + .link_rate = 200,
> + .lane_count = 4,
> + .expected = fp_init(179,  9259),  /* 179.09259 */
> + },
> + {
> + .link_rate = 200,
> + .lane_count = 2,
> + .expected = fp_init(89, 54629),
> + },
> + {
> + .link_rate = 200,
> + .lane_count = 1,
> + .expected = fp_init(44, 77314),
> + },
> + {
> + .link_rate = 135,
> + .lane_count = 4,
> + .expected = fp_init(120, 88750),
> + },
> + {
> + .link_rate = 135,
> + .lane_count = 2,
> + .expected = fp_init(60, 44375),
> + },
> + {
> + .link_rate = 135,
> + .lane_count = 1,
> + .expected = fp_init(30, 22187),
> + },
> + {
> + .link_rate = 100,
> + .lane_count = 4,
> + .expected = fp_init(89, 54629),
> + },
> + {
> + .link_rate = 100,
> + .lane_count = 2,
> + .expected = fp_init(44, 77314),
> + },
> + {
> + .link_rate = 100,
> + .lane_count = 1,
> + .expected = fp_init(22, 38657),
> + },
> + {
> + .link_rate = 81,
> + .lane_count = 4,
> + .expected = fp_init(60, 0),
> + },
> + {
> + .link_rate = 81,
> + .lane_count = 2,
> + .expected = fp_init(30, 0),
> + },
> + {
> + .link_rate = 81,
> + .lane_count = 1,
> + .expected = fp_init(15, 0),
> + },
> + {
> + .link_rate = 54,
> + .lane_count = 4,
> + .expected = fp_init(40, 0),
> + },
> + {
> + .link_rate = 54,
> + .lane_count = 2,
> + .expected = fp_init(20, 0),
> + },
> + {
> + .link_rate = 54,
> + .lane_count = 1,
> + .expected = fp_init(10, 0),
> + },
> + {
> + .link_rate = 27,
> + .lane_count = 4,
> + .expected = fp_init(20, 0),
> + },
> + {
> + .link_rate = 27,
> + .lane_count = 2,
> + .expected = fp_init(10, 0),
> + },
> + {
> + .link_rate = 27,
> + .lane_count = 1,
> + .expected = fp_init(5, 0),
> + },
> + {
> + .link_rate = 162000,
> + .lane_count = 4,
> + .expected = fp_init(12, 0),
> + },
> + {
> + .link_rate = 162000,
> + .lane_count = 2,
> + .expected = fp_init(6, 0),
> + },
> + {
> + .link_rate = 162000,
> + .lane_count = 1,
> + .expected = fp_init(3, 0),
> + },
> +};
> +
> +static void drm_test_dp_mst_calc_pbn_div(struct kunit *test)
> +{
> + const struct drm_dp_mst_calc_pbn_div_test *params = test->param_value;
> + /* mgr->dev is only needed by drm_dbg_k

[Intel-gfx] [PATCH v4 03/11] drm/dp_mst: Add kunit tests for drm_dp_get_vc_payload_bw()

2023-11-17 Thread Imre Deak
Add kunit test cases for drm_dp_get_vc_payload_bw() with all the DP1.4
and UHBR link configurations.

v2:
- List test cases in decreasing rate,lane count order matching the
  corresponding DP Standard tables. (Ville)
- Add references to the DP Standard tables.
v3:
- Sort the testcases properly.

Cc: Ville Syrjälä 
Cc: Lyude Paul 
Cc: dri-de...@lists.freedesktop.org
Signed-off-by: Imre Deak 
---
 .../gpu/drm/tests/drm_dp_mst_helper_test.c| 147 ++
 1 file changed, 147 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_dp_mst_helper_test.c 
b/drivers/gpu/drm/tests/drm_dp_mst_helper_test.c
index e3c818dfc0e6d..98d57d28aab6f 100644
--- a/drivers/gpu/drm/tests/drm_dp_mst_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_dp_mst_helper_test.c
@@ -68,6 +68,152 @@ static void dp_mst_calc_pbn_mode_desc(const struct 
drm_dp_mst_calc_pbn_mode_test
 KUNIT_ARRAY_PARAM(drm_dp_mst_calc_pbn_mode, drm_dp_mst_calc_pbn_mode_cases,
  dp_mst_calc_pbn_mode_desc);
 
+struct drm_dp_mst_calc_pbn_div_test {
+   int link_rate;
+   int lane_count;
+   fixed20_12 expected;
+};
+
+#define fp_init(__int, __frac) { \
+   .full = (__int) * (1 << 12) + \
+   (__frac) * (1 << 12) / 10 \
+}
+
+static const struct drm_dp_mst_calc_pbn_div_test 
drm_dp_mst_calc_pbn_div_dp1_4_cases[] = {
+   /*
+* UHBR rates (DP Standard v2.1 2.7.6.3, specifying the rounded to
+* closest value to 2 decimal places):
+* .expected = .link_rate * .lane_count * 0.9671 / 8 / 54 / 100
+* DP1.4 rates (DP Standard v2.1 2.6.4.2):
+* .expected = .link_rate * .lane_count * 0.8000 / 8 / 54 / 100
+*
+* truncated to 5 decimal places.
+*/
+   {
+   .link_rate = 200,
+   .lane_count = 4,
+   .expected = fp_init(179,  9259),  /* 179.09259 */
+   },
+   {
+   .link_rate = 200,
+   .lane_count = 2,
+   .expected = fp_init(89, 54629),
+   },
+   {
+   .link_rate = 200,
+   .lane_count = 1,
+   .expected = fp_init(44, 77314),
+   },
+   {
+   .link_rate = 135,
+   .lane_count = 4,
+   .expected = fp_init(120, 88750),
+   },
+   {
+   .link_rate = 135,
+   .lane_count = 2,
+   .expected = fp_init(60, 44375),
+   },
+   {
+   .link_rate = 135,
+   .lane_count = 1,
+   .expected = fp_init(30, 22187),
+   },
+   {
+   .link_rate = 100,
+   .lane_count = 4,
+   .expected = fp_init(89, 54629),
+   },
+   {
+   .link_rate = 100,
+   .lane_count = 2,
+   .expected = fp_init(44, 77314),
+   },
+   {
+   .link_rate = 100,
+   .lane_count = 1,
+   .expected = fp_init(22, 38657),
+   },
+   {
+   .link_rate = 81,
+   .lane_count = 4,
+   .expected = fp_init(60, 0),
+   },
+   {
+   .link_rate = 81,
+   .lane_count = 2,
+   .expected = fp_init(30, 0),
+   },
+   {
+   .link_rate = 81,
+   .lane_count = 1,
+   .expected = fp_init(15, 0),
+   },
+   {
+   .link_rate = 54,
+   .lane_count = 4,
+   .expected = fp_init(40, 0),
+   },
+   {
+   .link_rate = 54,
+   .lane_count = 2,
+   .expected = fp_init(20, 0),
+   },
+   {
+   .link_rate = 54,
+   .lane_count = 1,
+   .expected = fp_init(10, 0),
+   },
+   {
+   .link_rate = 27,
+   .lane_count = 4,
+   .expected = fp_init(20, 0),
+   },
+   {
+   .link_rate = 27,
+   .lane_count = 2,
+   .expected = fp_init(10, 0),
+   },
+   {
+   .link_rate = 27,
+   .lane_count = 1,
+   .expected = fp_init(5, 0),
+   },
+   {
+   .link_rate = 162000,
+   .lane_count = 4,
+   .expected = fp_init(12, 0),
+   },
+   {
+   .link_rate = 162000,
+   .lane_count = 2,
+   .expected = fp_init(6, 0),
+   },
+   {
+   .link_rate = 162000,
+   .lane_count = 1,
+   .expected = fp_init(3, 0),
+   },
+};
+
+static void drm_test_dp_mst_calc_pbn_div(struct kunit *test)
+{
+   const struct drm_dp_mst_calc_pbn_div_test *params = test->param_value;
+   /* mgr->dev is only needed by drm_dbg_kms(), but it's not called for 
the test cases. */
+   struct drm_dp_mst_topology_mgr mgr = {};
+
+   KUNIT_EXPECT_EQ(test, drm_dp_get_vc_payload_bw(&mgr, param