[PATCH 12/12] drm/xe/tests: Add KUnit tests for VF control GuC messages

Piotr Piórkowski piotr.piorkowski at intel.com
Fri Aug 23 13:18:05 UTC 2024


Michal Wajdeczko <michal.wajdeczko at intel.com> wrote on pią [2024-sie-09 18:51:59 +0200]:
> Add KUnit tests (~50) to cover all possible VF control messages
> that could be seen by the PF, either expected or corrupted.
> 
> Signed-off-by: Michal Wajdeczko <michal.wajdeczko at intel.com>
> Cc: Lucas De Marchi <lucas.demarchi at intel.com>
> ---
>  .../xe/tests/xe_gt_sriov_pf_control_kunit.c   | 194 ++++++++++++++++++
>  1 file changed, 194 insertions(+)
> 
> diff --git a/drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c b/drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c
> index 4252577b4bbd..194fcf5687d1 100644
> --- a/drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c
> +++ b/drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c
> @@ -1358,3 +1358,197 @@ static struct kunit_suite pf_control_suite = {
>  };
>  
>  kunit_test_suite(pf_control_suite);
> +
> +#define PREP_MSG_0_VF_STATE_NOTIFY(mbz)							\
> +	FIELD_PREP_CONST(GUC_HXG_MSG_0_ORIGIN, GUC_HXG_ORIGIN_GUC) |			\
> +	FIELD_PREP_CONST(GUC_HXG_MSG_0_TYPE, GUC_HXG_TYPE_EVENT) |			\
> +	FIELD_PREP_CONST(GUC_HXG_EVENT_MSG_0_DATA0, (mbz)) |				\
> +	FIELD_PREP_CONST(GUC_HXG_EVENT_MSG_0_ACTION, GUC_ACTION_GUC2PF_VF_STATE_NOTIFY)
> +
> +#define PREP_MSG_VF_STATE_NOTIFY(mbz, vfid, e)						\
> +	PREP_MSG_0_VF_STATE_NOTIFY(mbz),						\
> +	FIELD_PREP_CONST(GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_1_VFID, (vfid)),		\
> +	FIELD_PREP_CONST(GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_2_EVENT, (e))
> +
> +static const u32 msg_pf_enable[] = {
> +	PREP_MSG_VF_STATE_NOTIFY(0, 0, GUC_PF_NOTIFY_VF_ENABLE),
> +};
> +
> +static const u32 msg_vf_flr[] = {
> +	PREP_MSG_VF_STATE_NOTIFY(0, VFUT1, GUC_PF_NOTIFY_VF_FLR),
> +};
> +
> +static const u32 msg_vf_flr_done[] = {
> +	PREP_MSG_VF_STATE_NOTIFY(0, VFUT1, GUC_PF_NOTIFY_VF_FLR_DONE),
> +};
> +
> +static const u32 msg_vf_pause_done[] = {
> +	PREP_MSG_VF_STATE_NOTIFY(0, VFUT1, GUC_PF_NOTIFY_VF_PAUSE_DONE),
> +};
> +
> +static const u32 msg_vf_fixup[] = {
> +	PREP_MSG_VF_STATE_NOTIFY(0, VFUT1, GUC_PF_NOTIFY_VF_FIXUP_DONE),
> +};
> +
> +static const u32 msg_pf_bad_mbz[] = {
> +	PREP_MSG_VF_STATE_NOTIFY(1, 0, GUC_PF_NOTIFY_VF_ENABLE),
> +};
> +
> +static const u32 msg_pf_invalid_event[] = {
> +	PREP_MSG_VF_STATE_NOTIFY(0, 0, 0),
> +};
> +
> +static const u32 msg_pf_unknown_event[] = {
> +	PREP_MSG_VF_STATE_NOTIFY(0, 0, GUC_PF_NOTIFY_VF_ENABLE + 1),
> +};
> +
> +static const u32 msg_vf_bad_mbz[] = {
> +	PREP_MSG_VF_STATE_NOTIFY(1, VFUT1, GUC_PF_NOTIFY_VF_FLR),
> +};
> +
> +static const u32 msg_vf_bad_vfid[] = {
> +	PREP_MSG_VF_STATE_NOTIFY(0, VFID(DUT_NUM_VFS + 1), GUC_PF_NOTIFY_VF_FLR),
> +};
> +
> +static const u32 msg_vf_invalid_event[] = {
> +	PREP_MSG_VF_STATE_NOTIFY(0, VFUT1, 0),
> +};
> +
> +static const u32 msg_vf_unknown_event[] = {
> +	PREP_MSG_VF_STATE_NOTIFY(0, VFUT1, GUC_PF_NOTIFY_VF_FIXUP_DONE + 1),
> +};
> +
> +static const u32 msg_no_data[GUC_HXG_EVENT_MSG_MIN_LEN] = {
> +	PREP_MSG_0_VF_STATE_NOTIFY(0),
> +	/* only header, missing both VFID and EVENT data */
> +};
> +
> +static const u32 msg_pf_too_short[GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_LEN - 1] = {
> +	PREP_MSG_0_VF_STATE_NOTIFY(0),
> +	PFID,
> +	/* missing EVENT data */
> +};
> +
> +static const u32 msg_pf_too_long[GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_LEN + 1] = {
> +	PREP_MSG_VF_STATE_NOTIFY(0, 0, GUC_PF_NOTIFY_VF_ENABLE),
> +	0, /* unexpected extra DATA */
> +};
> +
> +static const u32 msg_vf_too_short[GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_LEN - 1] = {
> +	PREP_MSG_0_VF_STATE_NOTIFY(0),
> +	VFUT1,
> +	/* missing EVENT data */
> +};
> +
> +static const u32 msg_vf_too_long[GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_LEN + 1] = {
> +	PREP_MSG_VF_STATE_NOTIFY(0, VFUT1, GUC_PF_NOTIFY_VF_FLR),
> +	0, /* unexpected extra DATA */
> +};
> +
> +struct msg_param {
> +	const char *name;
> +	const u32 *msg;
> +	size_t len;
> +};
> +
> +static void msg_param_get_desc(struct msg_param *p, char *desc)
> +{
> +	snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", p->name);
> +}
> +
> +#define MAKE_MSG_PARAM(X) { .name = #X, .msg = X, .len = ARRAY_SIZE(X) }
> +
> +#define LIST_MSG_PARAM_VALID			\
> +	MAKE_MSG_PARAM(msg_pf_enable),		\
> +	MAKE_MSG_PARAM(msg_vf_flr),		\
> +	MAKE_MSG_PARAM(msg_vf_flr_done),	\
> +	MAKE_MSG_PARAM(msg_vf_pause_done),	\
> +	MAKE_MSG_PARAM(msg_vf_fixup)
> +
> +#define LIST_MSG_PARAM_INVALID			\
> +	MAKE_MSG_PARAM(msg_no_data),		\
> +	MAKE_MSG_PARAM(msg_pf_too_long),	\
> +	MAKE_MSG_PARAM(msg_pf_too_short),	\
> +	MAKE_MSG_PARAM(msg_pf_bad_mbz),		\
> +	MAKE_MSG_PARAM(msg_pf_invalid_event),	\
> +	MAKE_MSG_PARAM(msg_pf_unknown_event),	\
> +	MAKE_MSG_PARAM(msg_vf_too_long),	\
> +	MAKE_MSG_PARAM(msg_vf_too_short),	\
> +	MAKE_MSG_PARAM(msg_vf_bad_mbz),		\
> +	MAKE_MSG_PARAM(msg_vf_bad_vfid),	\
> +	MAKE_MSG_PARAM(msg_vf_invalid_event),	\
> +	MAKE_MSG_PARAM(msg_vf_unknown_event)
> +
> +static struct msg_param valid_messages[] = {
> +	LIST_MSG_PARAM_VALID,
> +};
> +
> +static struct msg_param invalid_messages[] = {
> +	LIST_MSG_PARAM_INVALID,
> +};
> +
> +static struct msg_param all_messages[] = {
> +	LIST_MSG_PARAM_VALID,
> +	LIST_MSG_PARAM_INVALID,
> +};
> +
> +KUNIT_ARRAY_PARAM(valid_messages, valid_messages, msg_param_get_desc);
> +KUNIT_ARRAY_PARAM(invalid_messages, invalid_messages, msg_param_get_desc);
> +KUNIT_ARRAY_PARAM(all_messages, all_messages, msg_param_get_desc);
> +
> +static void xe_rejects_all_g2h(struct kunit *test)
> +{
> +	struct xe_device *xe = (xe_kunit_helper_xe_device_test_init(test), test->priv);
> +	struct xe_gt *gt = xe_device_get_gt(xe, 0);
> +	const struct msg_param *p = test->param_value;
> +
> +	KUNIT_EXPECT_FALSE(test, IS_SRIOV_PF(xe));
> +	KUNIT_EXPECT_EQ(test, -EPROTO, xe_gt_sriov_pf_control_process_guc2pf(gt, p->msg, p->len));
> +}
> +
> +static void vf_rejects_all_g2h(struct kunit *test)
> +{
> +	struct xe_device *xe = (xe_kunit_helper_xe_device_test_init(test), test->priv);
> +	struct xe_gt *gt = xe_device_get_gt(xe, 0);
> +	const struct msg_param *p = test->param_value;
> +
> +	KUNIT_EXPECT_FALSE(test, IS_SRIOV(xe));
> +	xe->sriov.__mode = XE_SRIOV_MODE_VF;
> +
> +	KUNIT_EXPECT_TRUE(test, IS_SRIOV_VF(xe));
> +	KUNIT_EXPECT_EQ(test, -EPROTO, xe_gt_sriov_pf_control_process_guc2pf(gt, p->msg, p->len));
> +}
> +
> +static void pf_rejects_malformed_g2h(struct kunit *test)
> +{
> +	struct xe_gt *gt = (pf_control_test_init(test), test->priv);
> +	const struct msg_param *p = test->param_value;
> +
> +	KUNIT_EXPECT_NE(test, 0, xe_gt_sriov_pf_control_process_guc2pf(gt, p->msg, p->len));
> +}
> +
> +static void pf_accepts_valid_g2h(struct kunit *test)
> +{
> +	struct xe_gt *gt = (pf_control_test_init(test), test->priv);
> +	const struct msg_param *p = test->param_value;
> +
> +	XE_TEST_ACTIVATE_STUB(test, gt->sriov.pf.control.send_vf_control_cmd,
> +			      send_vf_control_cmd_pass_no_reply);
> +
> +	KUNIT_EXPECT_EQ(test, 0, xe_gt_sriov_pf_control_process_guc2pf(gt, p->msg, p->len));
> +}
> +
> +static struct kunit_case pf_control_guc_test_cases[] = {
> +	KUNIT_CASE_PARAM(xe_rejects_all_g2h, all_messages_gen_params),
> +	KUNIT_CASE_PARAM(vf_rejects_all_g2h, all_messages_gen_params),
> +	KUNIT_CASE_PARAM(pf_rejects_malformed_g2h, invalid_messages_gen_params),
> +	KUNIT_CASE_PARAM(pf_accepts_valid_g2h, valid_messages_gen_params),
> +	{}
> +};
> +
> +static struct kunit_suite pf_control_guc_suite = {
> +	.name = "pf_control_guc",
> +	.test_cases = pf_control_guc_test_cases,
> +};
> +
> +kunit_test_suite(pf_control_guc_suite);

LGTM:
Reviewed-by: Piotr Piórkowski <piotr.piorkowski at intel.com>

> -- 
> 2.43.0
> 

-- 


More information about the Intel-xe mailing list