aboutsummaryrefslogtreecommitdiff
path: root/test/dm/led.c
diff options
context:
space:
mode:
authorSimon Glass2017-04-10 11:34:57 -0600
committerSimon Glass2017-04-14 19:38:57 -0600
commit53378dac8dc33e3fd5f07d60bd7a5f8258ac7a20 (patch)
tree13613de1ea3ed6d991b440f0797cb25a671da40d /test/dm/led.c
parent9413ad4f0def2e06a5042106a6e1650a1aa03a5a (diff)
dm: led: Add support for blinking LEDs
Allow LEDs to be blinked if the driver supports it. Enable this for sandbox so that the tests run. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Ziping Chen <techping.chan@gmail.com>
Diffstat (limited to 'test/dm/led.c')
-rw-r--r--test/dm/led.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/dm/led.c b/test/dm/led.c
index 2cc24127e2a..fde700be386 100644
--- a/test/dm/led.c
+++ b/test/dm/led.c
@@ -98,3 +98,27 @@ static int dm_test_led_label(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_led_label, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test LED blinking */
+#ifdef CONFIG_LED_BLINK
+static int dm_test_led_blink(struct unit_test_state *uts)
+{
+ const int offset = 1;
+ struct udevice *dev, *gpio;
+
+ /*
+ * Check that we get an error when trying to blink an LED, since it is
+ * not supported by the GPIO LED driver.
+ */
+ ut_assertok(uclass_get_device(UCLASS_LED, 1, &dev));
+ ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
+ ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
+ ut_asserteq(-ENOSYS, led_set_state(dev, LEDST_BLINK));
+ ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
+ ut_asserteq(LEDST_OFF, led_get_state(dev));
+ ut_asserteq(-ENOSYS, led_set_period(dev, 100));
+
+ return 0;
+}
+DM_TEST(dm_test_led_blink, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+#endif