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> |
| 12 | #include <asm/test.h> |
| 13 | |
| 14 | /* Basic test of the sound codec uclass */ |
| 15 | static 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)); |
| 28 | ut_asserteq(4560, sandbox_get_sound_sum(dev)); |
| 29 | ut_assertok(sound_beep(dev, 1, 100)); |
| 30 | ut_asserteq(9120, sandbox_get_sound_sum(dev)); |
| 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | DM_TEST(dm_test_sound, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | 2850266 | 2019-02-16 20:24:54 -0700 | [diff] [blame] | 35 | |
| 36 | /* Test of the 'start beep' operations */ |
| 37 | static int dm_test_sound_beep(struct unit_test_state *uts) |
| 38 | { |
| 39 | struct udevice *dev; |
| 40 | |
| 41 | /* check probe success */ |
| 42 | ut_assertok(uclass_first_device_err(UCLASS_SOUND, &dev)); |
| 43 | ut_asserteq(-ENOSYS, sound_start_beep(dev, 100)); |
| 44 | ut_asserteq(0, sandbox_get_beep_frequency(dev)); |
| 45 | |
| 46 | sandbox_set_allow_beep(dev, true); |
| 47 | ut_asserteq(0, sound_start_beep(dev, 100)); |
| 48 | ut_asserteq(100, sandbox_get_beep_frequency(dev)); |
| 49 | |
| 50 | ut_asserteq(0, sound_stop_beep(dev)); |
| 51 | ut_asserteq(0, sandbox_get_beep_frequency(dev)); |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | DM_TEST(dm_test_sound_beep, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |