test: test sandbox sound driver more rigorously

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>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Heinrich Schuchardt
2022-12-04 17:11:41 +01:00
parent d0e8777bee
commit 968eaaeaa7
3 changed files with 30 additions and 0 deletions

View File

@@ -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));