[PATCH v2 4/5] drm/xe/kunit: Update RTP tests with SR-IOV rules

Matt Roper matthew.d.roper at intel.com
Tue Feb 25 03:10:01 UTC 2025


On Tue, Feb 25, 2025 at 12:41:09AM +0100, Michal Wajdeczko wrote:
> 
> 
> On 24.02.2025 23:55, Matt Roper wrote:
> > On Mon, Feb 24, 2025 at 04:06:59PM +0100, Michal Wajdeczko wrote:
> >> Add more test cases that verifies use of RTP SRIOV() rules in
> >> driver running as native, PF and VF mode.
> >>
> >> Signed-off-by: Michal Wajdeczko <michal.wajdeczko at intel.com>
> >> Cc: Lucas De Marchi <lucas.demarchi at intel.com>
> >> ---
> >>  drivers/gpu/drm/xe/tests/xe_rtp_test.c | 112 ++++++++++++++++++++++++-
> >>  1 file changed, 111 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/gpu/drm/xe/tests/xe_rtp_test.c b/drivers/gpu/drm/xe/tests/xe_rtp_test.c
> >> index 36a3b5420fef..b21474df933e 100644
> >> --- a/drivers/gpu/drm/xe/tests/xe_rtp_test.c
> >> +++ b/drivers/gpu/drm/xe/tests/xe_rtp_test.c
> >> @@ -45,6 +45,8 @@ struct rtp_to_sr_test_case {
> >>  struct rtp_test_case {
> >>  	const char *name;
> >>  	unsigned long expected_active;
> >> +	unsigned long expected_active_pf;
> >> +	unsigned long expected_active_vf;
> >>  	const struct xe_rtp_entry *entries;
> >>  };
> >>  
> >> @@ -469,6 +471,89 @@ static const struct rtp_test_case rtp_cases[] = {
> >>  	},
> >>  };
> >>  
> >> +static const struct rtp_test_case sriov_cases[] = {
> >> +	{
> >> +		.name = "non_vf",
> >> +		.expected_active = BIT(0) | BIT(1),
> >> +		.expected_active_pf = BIT(0) | BIT(1),
> >> +		.expected_active_vf = 0,
> >> +		.entries = (const struct xe_rtp_entry[]) {
> >> +			{ XE_RTP_NAME("and"),
> >> +			  XE_RTP_RULES(FUNC(match_yes)),
> >> +			},
> >> +			{ XE_RTP_NAME("or"),
> >> +			  XE_RTP_RULES(FUNC(match_no), OR,
> >> +				       FUNC(match_yes)),
> >> +			},
> >> +			{}
> >> +		},
> >> +	},
> >> +	{
> >> +		.name = "vf_ready",
> >> +		.expected_active = BIT(0) | BIT(1),
> >> +		.expected_active_pf = BIT(0) | BIT(1),
> >> +		.expected_active_vf = BIT(0) | BIT(1),
> >> +		.entries = (const struct xe_rtp_entry[]) {
> >> +			{ XE_RTP_NAME("and"),
> >> +			  XE_RTP_RULES(FUNC(match_yes), SRIOV(VF_READY)),
> >> +			},
> >> +			{ XE_RTP_NAME("or"),
> >> +			  XE_RTP_RULES(FUNC(match_no), OR,
> >> +				       FUNC(match_yes), SRIOV(VF_READY)),
> >> +			},
> >> +			{}
> >> +		},
> >> +	},
> >> +	{
> >> +		.name = "vf_only",
> >> +		.expected_active = 0,
> >> +		.expected_active_pf = 0,
> >> +		.expected_active_vf = BIT(0) | BIT(1),
> >> +		.entries = (const struct xe_rtp_entry[]) {
> >> +			{ XE_RTP_NAME("and"),
> >> +			  XE_RTP_RULES(FUNC(match_yes), SRIOV(VF_ONLY)),
> >> +			},
> >> +			{ XE_RTP_NAME("or"),
> >> +			  XE_RTP_RULES(FUNC(match_no), OR,
> >> +				       FUNC(match_yes), SRIOV(VF_ONLY)),
> >> +			},
> >> +			{}
> >> +		},
> >> +	},
> >> +	{
> >> +		.name = "pf_only",
> >> +		.expected_active = 0,
> >> +		.expected_active_pf = BIT(0) | BIT(1),
> >> +		.expected_active_vf = 0,
> >> +		.entries = (const struct xe_rtp_entry[]) {
> >> +			{ XE_RTP_NAME("and"),
> >> +			  XE_RTP_RULES(FUNC(match_yes), SRIOV(PF_ONLY)),
> >> +			},
> >> +			{ XE_RTP_NAME("or"),
> >> +			  XE_RTP_RULES(FUNC(match_no), OR,
> >> +				       FUNC(match_yes), SRIOV(PF_ONLY)),
> >> +			},
> >> +			{}
> >> +		},
> >> +	},
> >> +	{
> >> +		.name = "sriov_only",
> >> +		.expected_active = 0,
> >> +		.expected_active_pf = BIT(0) | BIT(1),
> >> +		.expected_active_vf = BIT(0) | BIT(1),
> >> +		.entries = (const struct xe_rtp_entry[]) {
> >> +			{ XE_RTP_NAME("and"),
> >> +			  XE_RTP_RULES(FUNC(match_yes), SRIOV(ONLY)),
> >> +			},
> >> +			{ XE_RTP_NAME("or"),
> >> +			  XE_RTP_RULES(FUNC(match_no), OR,
> >> +				       FUNC(match_yes), SRIOV(ONLY)),
> >> +			},
> >> +			{}
> >> +		},
> >> +	},
> >> +};
> >> +
> >>  static void xe_rtp_process_tests(struct kunit *test)
> >>  {
> >>  	const struct rtp_test_case *param = test->param_value;
> >> @@ -483,7 +568,28 @@ static void xe_rtp_process_tests(struct kunit *test)
> >>  	xe_rtp_process_ctx_enable_active_tracking(&ctx, &active, count_rtp_entries);
> >>  	xe_rtp_process(&ctx, param->entries);
> >>  
> >> -	KUNIT_EXPECT_EQ(test, active, param->expected_active);
> >> +	if (IS_SRIOV_PF(xe))
> > 
> > The xe here is a mock device (from drm_kunit_helper_alloc_device).
> > Won't these SRIOV tests require something extra in
> > xe_pci_fake_device_init() to ever be SRIOV-enabled?  Or am I overlooking
> > something?
> 
> yes ;)
> 
> see xe_rtp_process_tests_{pf,vf} below, where we convert mock xe to be
> PF or VF by explicitly altering xe->sriov.__mode

Oops, yeah.  Somehow I completely overlooked that part.

I'm not sure if we'll ever need to add more entries to xe_rtp_tests[],
but should we switch the mode back to native at the end of those
functions to prevent any subsequent tests from inheriting unexpected VF
behavior?


Matt

> 
> > 
> > 
> > Matt
> > 
> > 
> >> +		KUNIT_EXPECT_EQ(test, active, param->expected_active_pf);
> >> +	else if (IS_SRIOV_VF(xe))
> >> +		KUNIT_EXPECT_EQ(test, active, param->expected_active_vf);
> >> +	else
> >> +		KUNIT_EXPECT_EQ(test, active, param->expected_active);
> >> +}
> >> +
> >> +static void xe_rtp_process_tests_pf(struct kunit *test)
> >> +{
> >> +	struct xe_device *xe = test->priv;
> >> +
> >> +	xe->sriov.__mode = XE_SRIOV_MODE_PF;
> >> +	xe_rtp_process_tests(test);
> >> +}
> >> +
> >> +static void xe_rtp_process_tests_vf(struct kunit *test)
> >> +{
> >> +	struct xe_device *xe = test->priv;
> >> +
> >> +	xe->sriov.__mode = XE_SRIOV_MODE_VF;
> >> +	xe_rtp_process_tests(test);
> >>  }
> >>  
> >>  static void rtp_to_sr_desc(const struct rtp_to_sr_test_case *t, char *desc)
> >> @@ -499,6 +605,7 @@ static void rtp_desc(const struct rtp_test_case *t, char *desc)
> >>  }
> >>  
> >>  KUNIT_ARRAY_PARAM(rtp, rtp_cases, rtp_desc);
> >> +KUNIT_ARRAY_PARAM(sriov, sriov_cases, rtp_desc);
> >>  
> >>  static int xe_rtp_test_init(struct kunit *test)
> >>  {
> >> @@ -533,6 +640,9 @@ static void xe_rtp_test_exit(struct kunit *test)
> >>  static struct kunit_case xe_rtp_tests[] = {
> >>  	KUNIT_CASE_PARAM(xe_rtp_process_to_sr_tests, rtp_to_sr_gen_params),
> >>  	KUNIT_CASE_PARAM(xe_rtp_process_tests, rtp_gen_params),
> >> +	KUNIT_CASE_PARAM(xe_rtp_process_tests, sriov_gen_params),
> >> +	KUNIT_CASE_PARAM(xe_rtp_process_tests_pf, sriov_gen_params),
> >> +	KUNIT_CASE_PARAM(xe_rtp_process_tests_vf, sriov_gen_params),
> >>  	{}
> >>  };
> >>  
> >> -- 
> >> 2.47.1
> >>
> > 
> 

-- 
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation


More information about the Intel-xe mailing list