[PATCH v3 03/10] test/dm: add sandbox test for sysinfo_get_data

Raymond Mao raymond.mao at linaro.org
Fri Dec 6 23:54:20 CET 2024


Adding sysinfo_get_data into sandbox ut test dm_test_sysinfo.

Signed-off-by: Raymond Mao <raymond.mao at linaro.org>
---
Changes in v3
- Initial patch.

 drivers/sysinfo/sandbox.c | 19 +++++++++++++++++++
 drivers/sysinfo/sandbox.h |  1 +
 test/dm/sysinfo.c         |  6 ++++++
 3 files changed, 26 insertions(+)

diff --git a/drivers/sysinfo/sandbox.c b/drivers/sysinfo/sandbox.c
index d39720958f0..af54fe87596 100644
--- a/drivers/sysinfo/sandbox.c
+++ b/drivers/sysinfo/sandbox.c
@@ -13,6 +13,7 @@ struct sysinfo_sandbox_priv {
 	bool called_detect;
 	int test_i1;
 	int test_i2;
+	u32 test_data[2];
 };
 
 char vacation_spots[][64] = {"R'lyeh", "Dreamlands", "Plateau of Leng",
@@ -24,6 +25,8 @@ int sysinfo_sandbox_detect(struct udevice *dev)
 
 	priv->called_detect = true;
 	priv->test_i2 = 100;
+	priv->test_data[0] = 0xabcdabcd;
+	priv->test_data[1] = 0xdeadbeef;
 
 	return 0;
 }
@@ -79,6 +82,21 @@ int sysinfo_sandbox_get_str(struct udevice *dev, int id, size_t size, char *val)
 	return -ENOENT;
 }
 
+int sysinfo_sandbox_get_data(struct udevice *dev, int id, void **buf,
+			     size_t *size)
+{
+	struct sysinfo_sandbox_priv *priv = dev_get_priv(dev);
+
+	switch (id) {
+	case DATA_TEST:
+		*buf = priv->test_data;
+		*size = sizeof(priv->test_data);
+		return 0;
+	}
+
+	return -ENOENT;
+}
+
 static const struct udevice_id sysinfo_sandbox_ids[] = {
 	{ .compatible = "sandbox,sysinfo-sandbox" },
 	{ /* sentinel */ }
@@ -89,6 +107,7 @@ static const struct sysinfo_ops sysinfo_sandbox_ops = {
 	.get_bool = sysinfo_sandbox_get_bool,
 	.get_int = sysinfo_sandbox_get_int,
 	.get_str = sysinfo_sandbox_get_str,
+	.get_data = sysinfo_sandbox_get_data,
 };
 
 int sysinfo_sandbox_probe(struct udevice *dev)
diff --git a/drivers/sysinfo/sandbox.h b/drivers/sysinfo/sandbox.h
index a7cbac0ce18..47b7f5ef9fe 100644
--- a/drivers/sysinfo/sandbox.h
+++ b/drivers/sysinfo/sandbox.h
@@ -9,4 +9,5 @@ enum {
 	INT_TEST1,
 	INT_TEST2,
 	STR_VACATIONSPOT,
+	DATA_TEST,
 };
diff --git a/test/dm/sysinfo.c b/test/dm/sysinfo.c
index 6c0d2d7e4df..14ebe6b42e7 100644
--- a/test/dm/sysinfo.c
+++ b/test/dm/sysinfo.c
@@ -19,6 +19,9 @@ static int dm_test_sysinfo(struct unit_test_state *uts)
 	bool called_detect = false;
 	char str[64];
 	int i;
+	void *data = NULL;
+	size_t data_size = 0;
+	u32 gdata[] = {0xabcdabcd, 0xdeadbeef};
 
 	ut_assertok(sysinfo_get(&sysinfo));
 	ut_assert(sysinfo);
@@ -57,6 +60,9 @@ static int dm_test_sysinfo(struct unit_test_state *uts)
 				    str));
 	ut_assertok(strcmp(str, "Yuggoth"));
 
+	ut_assertok(sysinfo_get_data(sysinfo, DATA_TEST, &data, &data_size));
+	ut_assertok(memcmp(gdata, data, data_size));
+
 	return 0;
 }
 DM_TEST(dm_test_sysinfo, UTF_SCAN_PDATA | UTF_SCAN_FDT);
-- 
2.25.1



More information about the U-Boot mailing list