All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] test: test sandbox sound driver more rigorously
@ 2022-12-04 16:16 Heinrich Schuchardt
  2022-12-04 21:16 ` Simon Glass
  0 siblings, 1 reply; 2+ messages in thread
From: Heinrich Schuchardt @ 2022-12-04 16:16 UTC (permalink / raw)
  To: Simon Glass; +Cc: u-boot, Heinrich Schuchardt

Consider unexpected values for frequency:

* negative frequency
* zero frequency
* frequency exceeding sampling frequency

As in these cases the sum of the samples is zero also check the count of
the samples.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 arch/sandbox/include/asm/test.h | 10 ++++++++++
 drivers/sound/sandbox.c         |  9 +++++++++
 test/dm/sound.c                 | 11 +++++++++++
 3 files changed, 30 insertions(+)

diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h
index 0406085917..568738c16d 100644
--- a/arch/sandbox/include/asm/test.h
+++ b/arch/sandbox/include/asm/test.h
@@ -188,6 +188,16 @@ int sandbox_get_setup_called(struct udevice *dev);
  */
 int sandbox_get_sound_active(struct udevice *dev);
 
+/**
+ * sandbox_get_sound_count() - Read back the count of the sound data so far
+ *
+ * This data is provided to the sandbox driver by the sound play() method.
+ *
+ * @dev: Device to check
+ * Return: count of audio data
+ */
+int sandbox_get_sound_count(struct udevice *dev);
+
 /**
  * sandbox_get_sound_sum() - Read back the sum of the sound data so far
  *
diff --git a/drivers/sound/sandbox.c b/drivers/sound/sandbox.c
index 4a2c87a84c..c6cbd81fdb 100644
--- a/drivers/sound/sandbox.c
+++ b/drivers/sound/sandbox.c
@@ -29,6 +29,7 @@ struct sandbox_i2s_priv {
 struct sandbox_sound_priv {
 	int setup_called;	/* Incremented when setup() method is called */
 	bool active;		/* TX data is being sent */
+	int count;		/* Use to count the provided audio data */
 	int sum;		/* Use to sum the provided audio data */
 	bool allow_beep;	/* true to allow the start_beep() interface */
 	int frequency_hz;	/* Beep frequency if active, else 0 */
@@ -68,6 +69,13 @@ int sandbox_get_sound_active(struct udevice *dev)
 	return priv->active;
 }
 
+int sandbox_get_sound_count(struct udevice *dev)
+{
+	struct sandbox_sound_priv *priv = dev_get_priv(dev);
+
+	return priv->count;
+}
+
 int sandbox_get_sound_sum(struct udevice *dev)
 {
 	struct sandbox_sound_priv *priv = dev_get_priv(dev);
@@ -168,6 +176,7 @@ static int sandbox_sound_play(struct udevice *dev, void *data, uint data_size)
 
 	for (i = 0; i < data_size; i++)
 		priv->sum += ((uint8_t *)data)[i];
+	priv->count += data_size;
 
 	return i2s_tx_data(uc_priv->i2s, data, data_size);
 }
diff --git a/test/dm/sound.c b/test/dm/sound.c
index b73f6ab111..15d545ab5a 100644
--- a/test/dm/sound.c
+++ b/test/dm/sound.c
@@ -26,8 +26,19 @@ static int dm_test_sound(struct unit_test_state *uts)
 	ut_asserteq(0, sandbox_get_setup_called(dev));
 
 	ut_assertok(sound_beep(dev, 1, 100));
+	ut_asserteq(48, sandbox_get_sound_count(dev));
 	ut_asserteq(4560, sandbox_get_sound_sum(dev));
 	ut_assertok(sound_beep(dev, 1, 100));
+	ut_asserteq(96, sandbox_get_sound_count(dev));
+	ut_asserteq(9120, sandbox_get_sound_sum(dev));
+	ut_assertok(sound_beep(dev, 1, -100));
+	ut_asserteq(144, sandbox_get_sound_count(dev));
+	ut_asserteq(9120, sandbox_get_sound_sum(dev));
+	ut_assertok(sound_beep(dev, 1, 0));
+	ut_asserteq(192, sandbox_get_sound_count(dev));
+	ut_asserteq(9120, sandbox_get_sound_sum(dev));
+	ut_assertok(sound_beep(dev, 1, INT_MAX));
+	ut_asserteq(240, sandbox_get_sound_count(dev));
 	ut_asserteq(9120, sandbox_get_sound_sum(dev));
 	ut_asserteq(false, sandbox_get_sound_active(dev));
 
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] test: test sandbox sound driver more rigorously
  2022-12-04 16:16 [PATCH 1/1] test: test sandbox sound driver more rigorously Heinrich Schuchardt
@ 2022-12-04 21:16 ` Simon Glass
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Glass @ 2022-12-04 21:16 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: u-boot

On Mon, 5 Dec 2022 at 05:16, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> Consider unexpected values for frequency:
>
> * negative frequency
> * zero frequency
> * frequency exceeding sampling frequency
>
> As in these cases the sum of the samples is zero also check the count of
> the samples.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  arch/sandbox/include/asm/test.h | 10 ++++++++++
>  drivers/sound/sandbox.c         |  9 +++++++++
>  test/dm/sound.c                 | 11 +++++++++++
>  3 files changed, 30 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-04 21:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-04 16:16 [PATCH 1/1] test: test sandbox sound driver more rigorously Heinrich Schuchardt
2022-12-04 21:16 ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.