1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Google, Inc
11 #include <test/test.h>
14 /* Basic test of the pwm uclass */
15 static int dm_test_pwm_base(struct unit_test_state *uts)
23 ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &dev));
24 ut_assertnonnull(dev);
25 ut_assertok(pwm_set_config(dev, 0, 100, 50));
26 ut_assertok(pwm_set_enable(dev, 0, true));
27 ut_assertok(pwm_set_enable(dev, 1, true));
28 ut_assertok(pwm_set_enable(dev, 2, true));
29 ut_asserteq(-ENOSPC, pwm_set_enable(dev, 3, true));
30 ut_assertok(pwm_set_invert(dev, 0, true));
32 ut_assertok(pwm_set_config(dev, 2, 100, 50));
33 ut_assertok(sandbox_pwm_get_config(dev, 2, &period_ns, &duty_ns,
35 ut_asserteq(period_ns, 4096);
36 ut_asserteq(duty_ns, 50 * 4096 / 100);
38 ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
39 ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
40 ut_assertok(uclass_get_device(UCLASS_PWM, 2, &dev));
41 ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 3, &dev));
45 DM_TEST(dm_test_pwm_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);