~lkcamp/patches

drm: selftest: convert drm_dp_mst_helper selftest to kunit v2 PROPOSED

Rubens Gomes Neto: 1
 drm: selftest: convert drm_dp_mst_helper selftest to kunit

 4 files changed, 57 insertions(+), 73 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~lkcamp/patches/patches/26685/mbox | git am -3
Learn more about email & git

[PATCH v2] drm: selftest: convert drm_dp_mst_helper selftest to kunit Export this patch

Converts the DRM DP MST helper selftest to make use of the KUnit API.

Signed-off-by: Rubens Gomes Neto <rubens.gomes.neto@usp.br>
---
 drivers/gpu/drm/Kconfig                       |  13 ++
 drivers/gpu/drm/Makefile                      |   2 +-
 drivers/gpu/drm/selftests/Makefile            |   4 +-
 .../drm/selftests/test-drm_dp_mst_helper.c    | 111 +++++++-----------
 4 files changed, 57 insertions(+), 73 deletions(-)

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index cea777ae7fb9..bb64203c5294 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -79,6 +79,19 @@ config DRM_DEBUG_SELFTEST

	  If in doubt, say "N".

config DRM_DP_MST_HELPER_KUNIT_TEST
	tristate "KUnit tests for DRM DP MST helper"
	depends on DRM && KUNIT=y
	select DRM_KMS_HELPER
	default KUNIT_ALL_TESTS
	help
	  This option provides a kunit module that can be used to run
	  an unit test on the DRM DP MST helper 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_KMS_HELPER
	tristate
	depends on DRM
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index ad1112154898..e632c43c9b7d 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -58,7 +58,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 484c35c7edd0..994cb0515f85 100644
--- a/drivers/gpu/drm/selftests/Makefile
+++ b/drivers/gpu/drm/selftests/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_cmdline_parser.o \
				    test-drm_format.o test-drm_framebuffer.o test-drm_rect.o \
				    test-drm_plane_helper.o test-drm_dp_mst_helper.o \
				    test-drm_damage_helper.o 
				    test-drm_plane_helper.o test-drm_damage_helper.o
obj-$(CONFIG_DRM_DP_MST_HELPER_KUNIT_TEST) += test-drm_dp_mst_helper.o
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 11deb7e38141..3c1eaf2a9cec 100644
--- a/drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c
+++ b/drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c
@@ -5,31 +5,15 @@

#define PREFIX_STR "[drm_dp_mst_helper]"

#include <linux/module.h>
#include <kunit/test.h>
#include <linux/random.h>

#include <drm/drm_dp_mst_helper.h>
#include <drm/drm_print.h>

#include "../drm_dp_mst_topology_internal.h"
#include "test-drm_modeset_common.h"

#include "drm_selftest.h"
struct drm_selftest tests[] = {
       {
               .enabled = true,
               .name = "dp_mst_calc_pbn_mode",
               .func = igt_dp_mst_calc_pbn_mode,
       },
       {
               .enabled = true,
               .name = "dp_mst_sideband_msg_req_decode",
               .func = igt_dp_mst_sideband_msg_req_decode,
       },
};
#include "drm_selftest.c"

int igt_dp_mst_calc_pbn_mode(void *ignored)
static void igt_dp_mst_calc_pbn_mode(struct kunit *test)
{
	int pbn, i;
	const struct {
@@ -49,13 +33,8 @@ int igt_dp_mst_calc_pbn_mode(void *ignored)
		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);
                KUNIT_EXPECT_EQ(test, pbn, test_params[i].expected);
	}

	return 0;
}

static bool
@@ -190,66 +169,64 @@ sideband_msg_req_encode_decode(struct drm_dp_sideband_msg_req_body *in)
	return result;
}

int igt_dp_mst_sideband_msg_req_decode(void *unused)
static void igt_dp_mst_sideband_msg_req_decode(struct kunit *test)
{
	struct drm_dp_sideband_msg_req_body in = { 0 };
	u8 data[] = { 0xff, 0x0, 0xdd };
	int i;

#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();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));

	in.req_type = DP_POWER_UP_PHY;
	in.u.port_num.port_number = 5;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));

	in.req_type = DP_POWER_DOWN_PHY;
	in.u.port_num.port_number = 5;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));

	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();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.allocate_payload.port_number = 0xf;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.allocate_payload.vcpi = 0x7f;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.allocate_payload.pbn = U16_MAX;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));

	in.req_type = DP_QUERY_PAYLOAD;
	in.u.query_payload.port_number = 0xf;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.query_payload.vcpi = 0x7f;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));

	in.req_type = DP_REMOTE_DPCD_READ;
	in.u.dpcd_read.port_number = 0xf;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.dpcd_read.dpcd_address = 0xfedcb;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.dpcd_read.num_bytes = U8_MAX;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));

	in.req_type = DP_REMOTE_DPCD_WRITE;
	in.u.dpcd_write.port_number = 0xf;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.dpcd_write.dpcd_address = 0xfedcb;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.dpcd_write.num_bytes = ARRAY_SIZE(data);
	in.u.dpcd_write.bytes = data;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));

	in.req_type = DP_REMOTE_I2C_READ;
	in.u.i2c_read.port_number = 0xf;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.i2c_read.read_i2c_device_id = 0x7f;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	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++) {
@@ -258,51 +235,45 @@ int igt_dp_mst_sideband_msg_req_decode(void *unused)
		in.u.i2c_read.transactions[i].i2c_dev_id = 0x7f & ~i;
		in.u.i2c_read.transactions[i].i2c_transaction_delay = 0xf & ~i;
	}
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));

	in.req_type = DP_REMOTE_I2C_WRITE;
	in.u.i2c_write.port_number = 0xf;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.i2c_write.write_i2c_device_id = 0x7f;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.i2c_write.num_bytes = ARRAY_SIZE(data);
	in.u.i2c_write.bytes = data;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));

	in.req_type = DP_QUERY_STREAM_ENC_STATUS;
	in.u.enc_status.stream_id = 1;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	get_random_bytes(in.u.enc_status.client_id,
			 sizeof(in.u.enc_status.client_id));
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.enc_status.stream_event = 3;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.enc_status.valid_stream_event = 0;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.enc_status.stream_behavior = 3;
	DO_TEST();
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
	in.u.enc_status.valid_stream_behavior = 1;
	DO_TEST();

#undef DO_TEST
	return 0;
	KUNIT_EXPECT_TRUE(test, sideband_msg_req_encode_decode(&in));
}

static int __init test_drm_dp_mst_helper_init(void)
{
       int err;

       err = run_selftests(tests, ARRAY_SIZE(tests), NULL);

       return err > 0 ? 0 : err;
}
static struct kunit_case drm_dp_mst_helper_kunit_test[] = {
        KUNIT_CASE(igt_dp_mst_calc_pbn_mode),
        KUNIT_CASE(igt_dp_mst_sideband_msg_req_decode),
        {}
};

static void __exit test_drm_dp_mst_helper_exit(void)
{
}
static struct kunit_suite drm_dp_mst_helper_test_suite = {
        .name = "drm_dp_mst_helper_kunit_test",
        .test_cases = drm_dp_mst_helper_kunit_test,
};

module_init(test_drm_dp_mst_helper_init);
module_exit(test_drm_dp_mst_helper_exit);
kunit_test_suite(drm_dp_mst_helper_test_suite);

MODULE_AUTHOR("Intel");
MODULE_LICENSE("GPL");
-- 
2.32.0