2 * Copyright (C) 2015 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
14 DECLARE_GLOBAL_DATA_PTR;
16 /* Base test of the led uclass */
17 static int dm_test_led_base(struct unit_test_state *uts)
21 /* Get the top-level device */
22 ut_assertok(uclass_get_device(UCLASS_LED, 0, &dev));
23 ut_assertok(uclass_get_device(UCLASS_LED, 1, &dev));
24 ut_assertok(uclass_get_device(UCLASS_LED, 2, &dev));
25 ut_asserteq(-ENODEV, uclass_get_device(UCLASS_LED, 3, &dev));
29 DM_TEST(dm_test_led_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
31 /* Test of the led uclass using the led_gpio driver */
32 static int dm_test_led_gpio(struct unit_test_state *uts)
35 struct udevice *dev, *gpio;
38 * Check that we can manipulate an LED. LED 1 is connected to GPIO
39 * bank gpio_a, offset 1.
41 ut_assertok(uclass_get_device(UCLASS_LED, 1, &dev));
42 ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
43 ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
45 ut_asserteq(1, sandbox_gpio_get_value(gpio, offset));
47 ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
51 DM_TEST(dm_test_led_gpio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
53 /* Test obtaining an LED by label */
54 static int dm_test_led_label(struct unit_test_state *uts)
56 struct udevice *dev, *cmp;
58 ut_assertok(led_get_by_label("sandbox:red", &dev));
59 ut_asserteq(1, device_active(dev));
60 ut_assertok(uclass_get_device(UCLASS_LED, 1, &cmp));
61 ut_asserteq_ptr(dev, cmp);
63 ut_assertok(led_get_by_label("sandbox:green", &dev));
64 ut_asserteq(1, device_active(dev));
65 ut_assertok(uclass_get_device(UCLASS_LED, 2, &cmp));
66 ut_asserteq_ptr(dev, cmp);
68 ut_asserteq(-ENODEV, led_get_by_label("sandbox:blue", &dev));
72 DM_TEST(dm_test_led_label, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);