blob: 7b5556738dc322b29e8b02cb4f4cfc71d0be72a6 [file] [log] [blame]
Simon Glass76072ac2018-12-10 10:37:36 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2018 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
Simon Glass76072ac2018-12-10 10:37:36 -07007#include <dm.h>
8#include <sound.h>
9#include <dm/test.h>
10#include <test/ut.h>
Simon Glass75c4d412020-07-19 10:15:37 -060011#include <test/test.h>
Simon Glass76072ac2018-12-10 10:37:36 -070012#include <asm/test.h>
13
14/* Basic test of the sound codec uclass */
15static int dm_test_sound(struct unit_test_state *uts)
16{
17 struct sound_uc_priv *uc_priv;
18 struct udevice *dev;
19
20 /* check probe success */
21 ut_assertok(uclass_first_device_err(UCLASS_SOUND, &dev));
22 uc_priv = dev_get_uclass_priv(dev);
23 ut_asserteq_str("audio-codec", uc_priv->codec->name);
24 ut_asserteq_str("i2s", uc_priv->i2s->name);
25 ut_asserteq(0, sandbox_get_setup_called(dev));
26
27 ut_assertok(sound_beep(dev, 1, 100));
Heinrich Schuchardt707a6fc2022-12-04 17:11:41 +010028 ut_asserteq(48, sandbox_get_sound_count(dev));
Simon Glass76072ac2018-12-10 10:37:36 -070029 ut_asserteq(4560, sandbox_get_sound_sum(dev));
30 ut_assertok(sound_beep(dev, 1, 100));
Heinrich Schuchardt707a6fc2022-12-04 17:11:41 +010031 ut_asserteq(96, sandbox_get_sound_count(dev));
32 ut_asserteq(9120, sandbox_get_sound_sum(dev));
33 ut_assertok(sound_beep(dev, 1, -100));
34 ut_asserteq(144, sandbox_get_sound_count(dev));
35 ut_asserteq(9120, sandbox_get_sound_sum(dev));
36 ut_assertok(sound_beep(dev, 1, 0));
37 ut_asserteq(192, sandbox_get_sound_count(dev));
38 ut_asserteq(9120, sandbox_get_sound_sum(dev));
39 ut_assertok(sound_beep(dev, 1, INT_MAX));
40 ut_asserteq(240, sandbox_get_sound_count(dev));
Simon Glass76072ac2018-12-10 10:37:36 -070041 ut_asserteq(9120, sandbox_get_sound_sum(dev));
Simon Glass70bc14b2020-02-03 07:36:06 -070042 ut_asserteq(false, sandbox_get_sound_active(dev));
Simon Glass76072ac2018-12-10 10:37:36 -070043
44 return 0;
45}
Simon Glass1a92f832024-08-22 07:57:48 -060046DM_TEST(dm_test_sound, UTF_SCAN_PDATA | UTF_SCAN_FDT);
Simon Glassecd02e72019-02-16 20:24:54 -070047
48/* Test of the 'start beep' operations */
49static int dm_test_sound_beep(struct unit_test_state *uts)
50{
51 struct udevice *dev;
52
53 /* check probe success */
54 ut_assertok(uclass_first_device_err(UCLASS_SOUND, &dev));
55 ut_asserteq(-ENOSYS, sound_start_beep(dev, 100));
56 ut_asserteq(0, sandbox_get_beep_frequency(dev));
57
58 sandbox_set_allow_beep(dev, true);
59 ut_asserteq(0, sound_start_beep(dev, 100));
60 ut_asserteq(100, sandbox_get_beep_frequency(dev));
61
62 ut_asserteq(0, sound_stop_beep(dev));
63 ut_asserteq(0, sandbox_get_beep_frequency(dev));
64
65 return 0;
66}
Simon Glass1a92f832024-08-22 07:57:48 -060067DM_TEST(dm_test_sound_beep, UTF_SCAN_PDATA | UTF_SCAN_FDT);