summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-12-10 10:37:36 -0700
committerSimon Glass <sjg@chromium.org>2018-12-13 16:32:49 -0700
commitd4901898654b664c41d8a03afc0e0fbf531b5812 (patch)
treee757add0074c0f4c193a97157abaa70e7e56ec2e /test
parente625b68b04a400ba377ec0a5b958bde0bc6244ff (diff)
dm: sound: Create a uclass for sound
The sound driver pulls together the audio codec and i2s drivers in order to actually make sounds. It supports setup() and play() methods. The sound_find_codec_i2s() function allows locating the linked codec and i2s devices. They can be referred to from uclass-private data. Add a uclass and a test for sound. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/dm/Makefile1
-rw-r--r--test/dm/sound.c34
2 files changed, 35 insertions, 0 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 28ede9a669..73f5dcf739 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -55,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_DM_SOUND) += sound.o
obj-$(CONFIG_TEE) += tee.o
obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o
obj-$(CONFIG_DMA) += dma.o
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);