u-boot-brain/test/dm/led.c
Tom Rini 83d290c56f SPDX: Convert all of our single license tags to Linux Kernel style
When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from.  So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry.  Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents.  There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>
2018-05-07 09:34:12 -04:00

122 lines
3.5 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2015 Google, Inc
*/
#include <common.h>
#include <dm.h>
#include <led.h>
#include <asm/gpio.h>
#include <dm/test.h>
#include <test/ut.h>
/* Base test of the led uclass */
static int dm_test_led_base(struct unit_test_state *uts)
{
struct udevice *dev;
/* Get the top-level device */
ut_assertok(uclass_get_device(UCLASS_LED, 0, &dev));
ut_assertok(uclass_get_device(UCLASS_LED, 1, &dev));
ut_assertok(uclass_get_device(UCLASS_LED, 2, &dev));
ut_asserteq(-ENODEV, uclass_get_device(UCLASS_LED, 3, &dev));
return 0;
}
DM_TEST(dm_test_led_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
/* Test of the led uclass using the led_gpio driver */
static int dm_test_led_gpio(struct unit_test_state *uts)
{
const int offset = 1;
struct udevice *dev, *gpio;
/*
* Check that we can manipulate an LED. LED 1 is connected to GPIO
* bank gpio_a, offset 1.
*/
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_assertok(led_set_state(dev, LEDST_ON));
ut_asserteq(1, sandbox_gpio_get_value(gpio, offset));
ut_asserteq(LEDST_ON, led_get_state(dev));
ut_assertok(led_set_state(dev, LEDST_OFF));
ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
ut_asserteq(LEDST_OFF, led_get_state(dev));
return 0;
}
DM_TEST(dm_test_led_gpio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
/* Test that we can toggle LEDs */
static int dm_test_led_toggle(struct unit_test_state *uts)
{
const int offset = 1;
struct udevice *dev, *gpio;
/*
* Check that we can manipulate an LED. LED 1 is connected to GPIO
* bank gpio_a, offset 1.
*/
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_assertok(led_set_state(dev, LEDST_TOGGLE));
ut_asserteq(1, sandbox_gpio_get_value(gpio, offset));
ut_asserteq(LEDST_ON, led_get_state(dev));
ut_assertok(led_set_state(dev, LEDST_TOGGLE));
ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
ut_asserteq(LEDST_OFF, led_get_state(dev));
return 0;
}
DM_TEST(dm_test_led_toggle, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
/* Test obtaining an LED by label */
static int dm_test_led_label(struct unit_test_state *uts)
{
struct udevice *dev, *cmp;
ut_assertok(led_get_by_label("sandbox:red", &dev));
ut_asserteq(1, device_active(dev));
ut_assertok(uclass_get_device(UCLASS_LED, 1, &cmp));
ut_asserteq_ptr(dev, cmp);
ut_assertok(led_get_by_label("sandbox:green", &dev));
ut_asserteq(1, device_active(dev));
ut_assertok(uclass_get_device(UCLASS_LED, 2, &cmp));
ut_asserteq_ptr(dev, cmp);
ut_asserteq(-ENODEV, led_get_by_label("sandbox:blue", &dev));
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