summaryrefslogtreecommitdiff
path: root/test/dm
diff options
context:
space:
mode:
Diffstat (limited to 'test/dm')
-rw-r--r--test/dm/Makefile3
-rw-r--r--test/dm/audio.c34
-rw-r--r--test/dm/i2s.c32
-rw-r--r--test/dm/sound.c34
-rw-r--r--test/dm/test-fdt.c35
5 files changed, 138 insertions, 0 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 2c9081e4dd..6b451060d8 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o
# subsystem you must add sandbox tests here.
obj-$(CONFIG_UT_DM) += core.o
ifneq ($(CONFIG_SANDBOX),)
+obj-$(CONFIG_SOUND) += audio.o
obj-$(CONFIG_BLK) += blk.o
obj-$(CONFIG_BOARD) += board.o
obj-$(CONFIG_CLK) += clk.o
@@ -21,6 +22,7 @@ obj-$(CONFIG_FIRMWARE) += firmware.o
obj-$(CONFIG_DM_GPIO) += gpio.o
obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o
obj-$(CONFIG_DM_I2C) += i2c.o
+obj-$(CONFIG_SOUND) += i2s.o
obj-$(CONFIG_LED) += led.o
obj-$(CONFIG_DM_MAILBOX) += mailbox.o
obj-$(CONFIG_DM_MMC) += mmc.o
@@ -53,6 +55,7 @@ obj-$(CONFIG_AXI) += axi.o
obj-$(CONFIG_MISC) += misc.o
obj-$(CONFIG_DM_SERIAL) += serial.o
obj-$(CONFIG_CPU) += cpu.o
+obj-$(CONFIG_SOUND) += sound.o
obj-$(CONFIG_TEE) += tee.o
obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o
obj-$(CONFIG_DMA) += dma.o
diff --git a/test/dm/audio.c b/test/dm/audio.c
new file mode 100644
index 0000000000..77c3a3625b
--- /dev/null
+++ b/test/dm/audio.c
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <audio_codec.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <asm/test.h>
+
+/* Basic test of the audio codec uclass */
+static int dm_test_audio(struct unit_test_state *uts)
+{
+ int interface, rate, mclk_freq, bits_per_sample;
+ struct udevice *dev;
+ uint channels;
+
+ /* check probe success */
+ ut_assertok(uclass_first_device_err(UCLASS_AUDIO_CODEC, &dev));
+ ut_assertok(audio_codec_set_params(dev, 1, 2, 3, 4, 5));
+ sandbox_get_codec_params(dev, &interface, &rate, &mclk_freq,
+ &bits_per_sample, &channels);
+ ut_asserteq(1, interface);
+ ut_asserteq(2, rate);
+ ut_asserteq(3, mclk_freq);
+ ut_asserteq(4, bits_per_sample);
+ ut_asserteq(5, channels);
+
+ return 0;
+}
+DM_TEST(dm_test_audio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/i2s.c b/test/dm/i2s.c
new file mode 100644
index 0000000000..49ebc3523c
--- /dev/null
+++ b/test/dm/i2s.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <i2s.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <asm/test.h>
+
+/* Basic test of the i2s codec uclass */
+static int dm_test_i2s(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ u8 data[3];
+
+ /* check probe success */
+ ut_assertok(uclass_first_device_err(UCLASS_I2S, &dev));
+ data[0] = 1;
+ data[1] = 4;
+ data[2] = 6;
+ ut_assertok(i2s_tx_data(dev, data, ARRAY_SIZE(data)));
+ ut_asserteq(11, sandbox_get_i2s_sum(dev));
+ ut_assertok(i2s_tx_data(dev, data, 1));
+ ut_asserteq(12, sandbox_get_i2s_sum(dev));
+
+ return 0;
+}
+DM_TEST(dm_test_i2s, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/sound.c b/test/dm/sound.c
new file mode 100644
index 0000000000..7d0b36e7a5
--- /dev/null
+++ b/test/dm/sound.c
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <sound.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <asm/test.h>
+
+/* Basic test of the sound codec uclass */
+static int dm_test_sound(struct unit_test_state *uts)
+{
+ struct sound_uc_priv *uc_priv;
+ struct udevice *dev;
+
+ /* check probe success */
+ ut_assertok(uclass_first_device_err(UCLASS_SOUND, &dev));
+ uc_priv = dev_get_uclass_priv(dev);
+ ut_asserteq_str("audio-codec", uc_priv->codec->name);
+ ut_asserteq_str("i2s", uc_priv->i2s->name);
+ ut_asserteq(0, sandbox_get_setup_called(dev));
+
+ ut_assertok(sound_beep(dev, 1, 100));
+ ut_asserteq(4560, sandbox_get_sound_sum(dev));
+ ut_assertok(sound_beep(dev, 1, 100));
+ ut_asserteq(9120, sandbox_get_sound_sum(dev));
+
+ return 0;
+}
+DM_TEST(dm_test_sound, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 96d2528acc..984b80c02c 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -736,3 +736,38 @@ static int dm_test_first_child(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_first_child, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test integer functions in dm_read_...() */
+static int dm_test_read_int(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ u32 val32;
+ s32 sval;
+ uint val;
+
+ ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
+ ut_asserteq_str("a-test", dev->name);
+ ut_assertok(dev_read_u32(dev, "int-value", &val32));
+ ut_asserteq(1234, val32);
+
+ ut_asserteq(-EINVAL, dev_read_u32(dev, "missing", &val32));
+ ut_asserteq(6, dev_read_u32_default(dev, "missing", 6));
+
+ ut_asserteq(1234, dev_read_u32_default(dev, "int-value", 6));
+ ut_asserteq(1234, val32);
+
+ ut_asserteq(-EINVAL, dev_read_s32(dev, "missing", &sval));
+ ut_asserteq(6, dev_read_s32_default(dev, "missing", 6));
+
+ ut_asserteq(-1234, dev_read_s32_default(dev, "uint-value", 6));
+ ut_assertok(dev_read_s32(dev, "uint-value", &sval));
+ ut_asserteq(-1234, sval);
+
+ val = 0;
+ ut_asserteq(-EINVAL, dev_read_u32u(dev, "missing", &val));
+ ut_assertok(dev_read_u32u(dev, "uint-value", &val));
+ ut_asserteq(-1234, val);
+
+ return 0;
+}
+DM_TEST(dm_test_read_int, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);