Simon Glass | d490189 | 2018-12-10 10:37:36 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2018 Google LLC |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <sound.h> |
| 10 | #include <dm/test.h> |
| 11 | #include <test/ut.h> |
Simon Glass | 0e1fad4 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 12 | #include <test/test.h> |
Simon Glass | d490189 | 2018-12-10 10:37:36 -0700 | [diff] [blame] | 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)); |
| 29 | ut_asserteq(4560, sandbox_get_sound_sum(dev)); |
| 30 | ut_assertok(sound_beep(dev, 1, 100)); |
| 31 | ut_asserteq(9120, sandbox_get_sound_sum(dev)); |
Simon Glass | 3062cd1 | 2020-02-03 07:36:06 -0700 | [diff] [blame] | 32 | ut_asserteq(false, sandbox_get_sound_active(dev)); |
Simon Glass | d490189 | 2018-12-10 10:37:36 -0700 | [diff] [blame] | 33 | |
| 34 | return 0; |
| 35 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 36 | DM_TEST(dm_test_sound, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 2850266 | 2019-02-16 20:24:54 -0700 | [diff] [blame] | 37 | |
| 38 | /* Test of the 'start beep' operations */ |
| 39 | static int dm_test_sound_beep(struct unit_test_state *uts) |
| 40 | { |
| 41 | struct udevice *dev; |
| 42 | |
| 43 | /* check probe success */ |
| 44 | ut_assertok(uclass_first_device_err(UCLASS_SOUND, &dev)); |
| 45 | ut_asserteq(-ENOSYS, sound_start_beep(dev, 100)); |
| 46 | ut_asserteq(0, sandbox_get_beep_frequency(dev)); |
| 47 | |
| 48 | sandbox_set_allow_beep(dev, true); |
| 49 | ut_asserteq(0, sound_start_beep(dev, 100)); |
| 50 | ut_asserteq(100, sandbox_get_beep_frequency(dev)); |
| 51 | |
| 52 | ut_asserteq(0, sound_stop_beep(dev)); |
| 53 | ut_asserteq(0, sandbox_get_beep_frequency(dev)); |
| 54 | |
| 55 | return 0; |
| 56 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 57 | DM_TEST(dm_test_sound_beep, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |