]>
Commit | Line | Data |
---|---|---|
d4901898 SG |
1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* | |
3 | * Copyright 2018 Google LLC | |
4 | * Written by Simon Glass <[email protected]> | |
5 | */ | |
6 | ||
d678a59d | 7 | #include <common.h> |
d4901898 SG |
8 | #include <dm.h> |
9 | #include <sound.h> | |
10 | #include <dm/test.h> | |
11 | #include <test/ut.h> | |
0e1fad43 | 12 | #include <test/test.h> |
d4901898 SG |
13 | #include <asm/test.h> |
14 | ||
15 | /* Basic test of the sound codec uclass */ | |
16 | static int dm_test_sound(struct unit_test_state *uts) | |
17 | { | |
18 | struct sound_uc_priv *uc_priv; | |
19 | struct udevice *dev; | |
20 | ||
21 | /* check probe success */ | |
22 | ut_assertok(uclass_first_device_err(UCLASS_SOUND, &dev)); | |
23 | uc_priv = dev_get_uclass_priv(dev); | |
24 | ut_asserteq_str("audio-codec", uc_priv->codec->name); | |
25 | ut_asserteq_str("i2s", uc_priv->i2s->name); | |
26 | ut_asserteq(0, sandbox_get_setup_called(dev)); | |
27 | ||
28 | ut_assertok(sound_beep(dev, 1, 100)); | |
968eaaea | 29 | ut_asserteq(48, sandbox_get_sound_count(dev)); |
d4901898 SG |
30 | ut_asserteq(4560, sandbox_get_sound_sum(dev)); |
31 | ut_assertok(sound_beep(dev, 1, 100)); | |
968eaaea HS |
32 | ut_asserteq(96, sandbox_get_sound_count(dev)); |
33 | ut_asserteq(9120, sandbox_get_sound_sum(dev)); | |
34 | ut_assertok(sound_beep(dev, 1, -100)); | |
35 | ut_asserteq(144, sandbox_get_sound_count(dev)); | |
36 | ut_asserteq(9120, sandbox_get_sound_sum(dev)); | |
37 | ut_assertok(sound_beep(dev, 1, 0)); | |
38 | ut_asserteq(192, sandbox_get_sound_count(dev)); | |
39 | ut_asserteq(9120, sandbox_get_sound_sum(dev)); | |
40 | ut_assertok(sound_beep(dev, 1, INT_MAX)); | |
41 | ut_asserteq(240, sandbox_get_sound_count(dev)); | |
d4901898 | 42 | ut_asserteq(9120, sandbox_get_sound_sum(dev)); |
3062cd17 | 43 | ut_asserteq(false, sandbox_get_sound_active(dev)); |
d4901898 SG |
44 | |
45 | return 0; | |
46 | } | |
e180c2b1 | 47 | DM_TEST(dm_test_sound, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
28502669 SG |
48 | |
49 | /* Test of the 'start beep' operations */ | |
50 | static int dm_test_sound_beep(struct unit_test_state *uts) | |
51 | { | |
52 | struct udevice *dev; | |
53 | ||
54 | /* check probe success */ | |
55 | ut_assertok(uclass_first_device_err(UCLASS_SOUND, &dev)); | |
56 | ut_asserteq(-ENOSYS, sound_start_beep(dev, 100)); | |
57 | ut_asserteq(0, sandbox_get_beep_frequency(dev)); | |
58 | ||
59 | sandbox_set_allow_beep(dev, true); | |
60 | ut_asserteq(0, sound_start_beep(dev, 100)); | |
61 | ut_asserteq(100, sandbox_get_beep_frequency(dev)); | |
62 | ||
63 | ut_asserteq(0, sound_stop_beep(dev)); | |
64 | ut_asserteq(0, sandbox_get_beep_frequency(dev)); | |
65 | ||
66 | return 0; | |
67 | } | |
e180c2b1 | 68 | DM_TEST(dm_test_sound_beep, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |