cros_ec: Add a function for the hello message

This is used several times in this file. Put it in a function to avoid
code duplication.

Also add a test for this function. There are no cros_ec tests at present,
so it is time to update the code.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 46e076e..afcabfa 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -24,6 +24,7 @@
 obj-$(CONFIG_BUTTON) += button.o
 obj-$(CONFIG_DM_BOOTCOUNT) += bootcount.o
 obj-$(CONFIG_CLK) += clk.o clk_ccf.o
+obj-$(CONFIG_CROS_EC) += cros_ec.o
 obj-$(CONFIG_DEVRES) += devres.o
 obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o
 obj-$(CONFIG_DM_ETH) += eth.o
diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c
new file mode 100644
index 0000000..823245c
--- /dev/null
+++ b/test/dm/cros_ec.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2021 Google LLC
+ */
+
+#include <common.h>
+#include <cros_ec.h>
+#include <dm.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+static int dm_test_cros_ec_hello(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	uint val;
+
+	ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
+
+	ut_assertok(cros_ec_hello(dev, NULL));
+
+	val = 0xdead1357;
+	ut_assertok(cros_ec_hello(dev, &val));
+	ut_asserteq(0xdead1357, val);
+
+	sandbox_cros_ec_set_test_flags(dev, CROSECT_BREAK_HELLO);
+	ut_asserteq(-ENOTSYNC, cros_ec_hello(dev, &val));
+	ut_asserteq(0x12345678, val);
+
+	return 0;
+}
+DM_TEST(dm_test_cros_ec_hello, UT_TESTF_SCAN_FDT);