[PATCH v3 2/3] test: Add tests for the extcon

Svyatoslav Ryhel clamor95 at gmail.com
Fri Apr 21 09:05:03 CEST 2023


Provide tests to the simple extcon device.

Signed-off-by: Svyatoslav Ryhel <clamor95 at gmail.com>
---
 arch/sandbox/dts/test.dts       |  4 ++++
 drivers/extcon/Kconfig          |  7 +++++++
 drivers/extcon/Makefile         |  1 +
 drivers/extcon/extcon-sandbox.c | 17 +++++++++++++++++
 test/dm/Makefile                |  1 +
 test/dm/extcon.c                | 21 +++++++++++++++++++++
 6 files changed, 51 insertions(+)
 create mode 100644 drivers/extcon/extcon-sandbox.c
 create mode 100644 test/dm/extcon.c

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 7c1ee71cb7..731b48459d 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -1802,6 +1802,10 @@
 		compatible = "u-boot,fwu-mdata-gpt";
 		fwu-mdata-store = <&mmc0>;
 	};
+
+	extcon {
+		compatible = "sandbox,extcon";
+	};
 };
 
 #include "sandbox_pmic.dtsi"
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 8a50250d21..6fd3d2b97b 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -12,4 +12,11 @@ config EXTCON
 	  and to host USB ports. Many of 30-pin connectors including PDMI
 	  are also good examples.
 
+config EXTCON_SANDBOX
+	bool "Sandbox extcon"
+	depends on EXTCON
+	help
+	  Enable extcon support for sandbox. This is an emulation of a real
+	  extcon. Currectly all configuration is done in the probe.
+
 endmenu
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
index 2510e91c07..c4223d97d1 100644
--- a/drivers/extcon/Makefile
+++ b/drivers/extcon/Makefile
@@ -3,3 +3,4 @@
 # Copyright (C) 2023 Svyatoslav Ryhel <clamor95 at gmail.com>
 
 obj-$(CONFIG_EXTCON) += extcon-uclass.o
+obj-$(CONFIG_EXTCON_SANDBOX) += extcon-sandbox.o
diff --git a/drivers/extcon/extcon-sandbox.c b/drivers/extcon/extcon-sandbox.c
new file mode 100644
index 0000000000..ab6a6c1cfd
--- /dev/null
+++ b/drivers/extcon/extcon-sandbox.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2022 Svyatoslav Ryhel <clamor95 at gmail.com>
+ */
+
+#include <dm.h>
+
+static const struct udevice_id sandbox_extcon_ids[] = {
+	{ .compatible = "sandbox,extcon" },
+	{ /* sentinel */ }
+};
+
+U_BOOT_DRIVER(extcon_sandbox) = {
+	.name		= "extcon_sandbox",
+	.id		= UCLASS_EXTCON,
+	.of_match	= sandbox_extcon_ids,
+};
diff --git a/test/dm/Makefile b/test/dm/Makefile
index e15bdbf04b..5ada659974 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -44,6 +44,7 @@ obj-$(CONFIG_DM_DSA) += dsa.o
 obj-$(CONFIG_ECDSA_VERIFY) += ecdsa.o
 obj-$(CONFIG_EFI_MEDIA_SANDBOX) += efi_media.o
 obj-$(CONFIG_DM_ETH) += eth.o
+obj-$(CONFIG_EXTCON) += extcon.o
 ifneq ($(CONFIG_EFI_PARTITION),)
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
 endif
diff --git a/test/dm/extcon.c b/test/dm/extcon.c
new file mode 100644
index 0000000000..6a4e22bfdc
--- /dev/null
+++ b/test/dm/extcon.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Svyatoslav Ryhel <clamor95 at gmail.com>
+ */
+
+#include <dm.h>
+#include <dm/test.h>
+#include <extcon.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static int dm_test_extcon(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_EXTCON, "extcon", &dev));
+
+	return 0;
+}
+
+DM_TEST(dm_test_extcon, UT_TESTF_SCAN_FDT);
-- 
2.37.2



More information about the U-Boot mailing list