diff options
Diffstat (limited to 'test/dm')
-rw-r--r-- | test/dm/Makefile | 7 | ||||
-rw-r--r-- | test/dm/clk.c | 59 | ||||
-rw-r--r-- | test/dm/cmd_dm.c | 82 | ||||
-rw-r--r-- | test/dm/led.c | 72 | ||||
-rw-r--r-- | test/dm/mmc.c | 27 | ||||
-rw-r--r-- | test/dm/ram.c | 28 | ||||
-rw-r--r-- | test/dm/regmap.c | 82 | ||||
-rw-r--r-- | test/dm/regulator.c | 2 | ||||
-rw-r--r-- | test/dm/reset.c | 74 | ||||
-rw-r--r-- | test/dm/syscon.c | 31 | ||||
-rw-r--r-- | test/dm/test-main.c | 15 |
11 files changed, 397 insertions, 82 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile index 19ad2fb99f..eda9643185 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -15,13 +15,20 @@ obj-$(CONFIG_UT_DM) += test-uclass.o # subsystem you must add sandbox tests here. obj-$(CONFIG_UT_DM) += core.o ifneq ($(CONFIG_SANDBOX),) +obj-$(CONFIG_CLK) += clk.o obj-$(CONFIG_DM_ETH) += eth.o obj-$(CONFIG_DM_GPIO) += gpio.o obj-$(CONFIG_DM_I2C) += i2c.o +obj-$(CONFIG_LED) += led.o +obj-$(CONFIG_DM_MMC) += mmc.o obj-$(CONFIG_DM_PCI) += pci.o +obj-$(CONFIG_RAM) += ram.o +obj-y += regmap.o +obj-$(CONFIG_RESET) += reset.o obj-$(CONFIG_DM_RTC) += rtc.o obj-$(CONFIG_DM_SPI_FLASH) += sf.o obj-$(CONFIG_DM_SPI) += spi.o +obj-y += syscon.o obj-$(CONFIG_DM_USB) += usb.o obj-$(CONFIG_DM_PMIC) += pmic.o obj-$(CONFIG_DM_REGULATOR) += regulator.o diff --git a/test/dm/clk.c b/test/dm/clk.c new file mode 100644 index 0000000000..9ff6d95103 --- /dev/null +++ b/test/dm/clk.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2015 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <clk.h> +#include <dm.h> +#include <asm/test.h> +#include <dm/test.h> +#include <linux/err.h> +#include <test/ut.h> + +/* Test that we can find and adjust clocks */ +static int dm_test_clk_base(struct unit_test_state *uts) +{ + struct udevice *clk; + ulong rate; + + ut_assertok(uclass_get_device(UCLASS_CLK, 0, &clk)); + rate = clk_get_rate(clk); + ut_asserteq(SANDBOX_CLK_RATE, rate); + ut_asserteq(-EINVAL, clk_set_rate(clk, 0)); + ut_assertok(clk_set_rate(clk, rate * 2)); + ut_asserteq(SANDBOX_CLK_RATE * 2, clk_get_rate(clk)); + + return 0; +} +DM_TEST(dm_test_clk_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test that peripheral clocks work as expected */ +static int dm_test_clk_periph(struct unit_test_state *uts) +{ + struct udevice *clk; + ulong rate; + + ut_assertok(uclass_get_device(UCLASS_CLK, 0, &clk)); + rate = clk_set_periph_rate(clk, PERIPH_ID_COUNT, 123); + ut_asserteq(-EINVAL, rate); + ut_asserteq(1, IS_ERR_VALUE(rate)); + + rate = clk_set_periph_rate(clk, PERIPH_ID_SPI, 123); + ut_asserteq(0, rate); + ut_asserteq(123, clk_get_periph_rate(clk, PERIPH_ID_SPI)); + + rate = clk_set_periph_rate(clk, PERIPH_ID_SPI, 1234); + ut_asserteq(123, rate); + + rate = clk_set_periph_rate(clk, PERIPH_ID_I2C, 567); + + rate = clk_set_periph_rate(clk, PERIPH_ID_SPI, 1234); + ut_asserteq(1234, rate); + + ut_asserteq(567, clk_get_periph_rate(clk, PERIPH_ID_I2C)); + + return 0; +} +DM_TEST(dm_test_clk_periph, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); diff --git a/test/dm/cmd_dm.c b/test/dm/cmd_dm.c index 5bb2a99c8f..5c501ec254 100644 --- a/test/dm/cmd_dm.c +++ b/test/dm/cmd_dm.c @@ -14,96 +14,20 @@ #include <errno.h> #include <asm/io.h> #include <dm/root.h> -#include <dm/uclass-internal.h> - -static void show_devices(struct udevice *dev, int depth, int last_flag) -{ - int i, is_last; - struct udevice *child; - char class_name[12]; - - /* print the first 11 characters to not break the tree-format. */ - strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name)); - printf(" %-11s [ %c ] ", class_name, - dev->flags & DM_FLAG_ACTIVATED ? '+' : ' '); - - for (i = depth; i >= 0; i--) { - is_last = (last_flag >> i) & 1; - if (i) { - if (is_last) - printf(" "); - else - printf("| "); - } else { - if (is_last) - printf("`-- "); - else - printf("|-- "); - } - } - - printf("%s\n", dev->name); - - list_for_each_entry(child, &dev->child_head, sibling_node) { - is_last = list_is_last(&child->sibling_node, &dev->child_head); - show_devices(child, depth + 1, (last_flag << 1) | is_last); - } -} +#include <dm/util.h> static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - struct udevice *root; - - root = dm_root(); - if (root) { - printf(" Class Probed Name\n"); - printf("----------------------------------------\n"); - show_devices(root, -1, 0); - } + dm_dump_all(); return 0; } -/** - * dm_display_line() - Display information about a single device - * - * Displays a single line of information with an option prefix - * - * @dev: Device to display - */ -static void dm_display_line(struct udevice *dev) -{ - printf("- %c %s @ %08lx", - dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ', - dev->name, (ulong)map_to_sysmem(dev)); - if (dev->seq != -1 || dev->req_seq != -1) - printf(", seq %d, (req %d)", dev->seq, dev->req_seq); - puts("\n"); -} - static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - struct uclass *uc; - int ret; - int id; - - for (id = 0; id < UCLASS_COUNT; id++) { - struct udevice *dev; - - ret = uclass_get(id, &uc); - if (ret) - continue; - - printf("uclass %d: %s\n", id, uc->uc_drv->name); - if (list_empty(&uc->dev_head)) - continue; - list_for_each_entry(dev, &uc->dev_head, uclass_node) { - dm_display_line(dev); - } - puts("\n"); - } + dm_dump_uclass(); return 0; } diff --git a/test/dm/led.c b/test/dm/led.c new file mode 100644 index 0000000000..8ee075cf1c --- /dev/null +++ b/test/dm/led.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2015 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <dm.h> +#include <led.h> +#include <asm/gpio.h> +#include <dm/test.h> +#include <test/ut.h> + +DECLARE_GLOBAL_DATA_PTR; + +/* 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)); + led_set_on(dev, 1); + ut_asserteq(1, sandbox_gpio_get_value(gpio, offset)); + led_set_on(dev, 0); + ut_asserteq(0, sandbox_gpio_get_value(gpio, offset)); + + return 0; +} +DM_TEST(dm_test_led_gpio, 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); diff --git a/test/dm/mmc.c b/test/dm/mmc.c new file mode 100644 index 0000000000..046142322d --- /dev/null +++ b/test/dm/mmc.c @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <dm.h> +#include <mmc.h> +#include <dm/test.h> +#include <test/ut.h> + +DECLARE_GLOBAL_DATA_PTR; + +/* + * Basic test of the mmc uclass. We could expand this by implementing an MMC + * stack for sandbox, or at least implementing the basic operation. + */ +static int dm_test_mmc_base(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev)); + + return 0; +} +DM_TEST(dm_test_mmc_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); diff --git a/test/dm/ram.c b/test/dm/ram.c new file mode 100644 index 0000000000..3a7c5fffdd --- /dev/null +++ b/test/dm/ram.c @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2015 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <dm.h> +#include <ram.h> +#include <dm/test.h> +#include <test/ut.h> + +DECLARE_GLOBAL_DATA_PTR; + +/* Basic test of the ram uclass */ +static int dm_test_ram_base(struct unit_test_state *uts) +{ + struct udevice *dev; + struct ram_info info; + + ut_assertok(uclass_get_device(UCLASS_RAM, 0, &dev)); + ut_assertok(ram_get_info(dev, &info)); + ut_asserteq(0, info.base); + ut_asserteq(gd->ram_size, info.size); + + return 0; +} +DM_TEST(dm_test_ram_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); diff --git a/test/dm/regmap.c b/test/dm/regmap.c new file mode 100644 index 0000000000..7f66058735 --- /dev/null +++ b/test/dm/regmap.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2015 Google, Inc +2 * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <dm.h> +#include <mapmem.h> +#include <regmap.h> +#include <syscon.h> +#include <asm/test.h> +#include <dm/test.h> +#include <test/ut.h> + +DECLARE_GLOBAL_DATA_PTR; + +/* Base test of register maps */ +static int dm_test_regmap_base(struct unit_test_state *uts) +{ + struct udevice *dev; + struct regmap *map; + int i; + + ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev)); + map = syscon_get_regmap(dev); + ut_assertok_ptr(map); + ut_asserteq(1, map->range_count); + ut_asserteq(0x10, map->base); + ut_asserteq(0x10, map->range->start); + ut_asserteq(4, map->range->size); + ut_asserteq_ptr(&map->base_range, map->range); + ut_asserteq(0x10, map_to_sysmem(regmap_get_range(map, 0))); + + ut_assertok(uclass_get_device(UCLASS_SYSCON, 1, &dev)); + map = syscon_get_regmap(dev); + ut_assertok_ptr(map); + ut_asserteq(4, map->range_count); + ut_asserteq(0x20, map->base); + ut_assert(&map->base_range != map->range); + for (i = 0; i < 4; i++) { + const unsigned long addr = 0x20 + 8 * i; + + ut_asserteq(addr, map->range[i].start); + ut_asserteq(5 + i, map->range[i].size); + ut_asserteq(addr, map_to_sysmem(regmap_get_range(map, i))); + } + + /* Check that we can't pretend a different device is a syscon */ + ut_assertok(uclass_get_device(UCLASS_I2C, 0, &dev)); + map = syscon_get_regmap(dev); + ut_asserteq_ptr(ERR_PTR(-ENOEXEC), map); + + return 0; +} +DM_TEST(dm_test_regmap_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test we can access a regmap through syscon */ +static int dm_test_regmap_syscon(struct unit_test_state *uts) +{ + struct regmap *map; + + map = syscon_get_regmap_by_driver_data(SYSCON0); + ut_assertok_ptr(map); + ut_asserteq(1, map->range_count); + + map = syscon_get_regmap_by_driver_data(SYSCON1); + ut_assertok_ptr(map); + ut_asserteq(4, map->range_count); + + map = syscon_get_regmap_by_driver_data(SYSCON_COUNT); + ut_asserteq_ptr(ERR_PTR(-ENODEV), map); + + ut_asserteq(0x10, map_to_sysmem(syscon_get_first_range(SYSCON0))); + ut_asserteq(0x20, map_to_sysmem(syscon_get_first_range(SYSCON1))); + ut_asserteq_ptr(ERR_PTR(-ENODEV), + syscon_get_first_range(SYSCON_COUNT)); + + return 0; +} + +DM_TEST(dm_test_regmap_syscon, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); diff --git a/test/dm/regulator.c b/test/dm/regulator.c index d279c04c84..3d0056f2dc 100644 --- a/test/dm/regulator.c +++ b/test/dm/regulator.c @@ -210,7 +210,7 @@ static int dm_test_power_regulator_autoset(struct unit_test_state *uts) * Expected output state: uV=1200000; uA=200000; output enabled */ platname = regulator_names[BUCK1][PLATNAME]; - ut_assertok(regulator_autoset(platname, &dev_autoset, false)); + ut_assertok(regulator_autoset_by_name(platname, &dev_autoset)); /* Check, that the returned device is proper */ ut_assertok(regulator_get_by_platname(platname, &dev)); diff --git a/test/dm/reset.c b/test/dm/reset.c new file mode 100644 index 0000000000..5d53f252bb --- /dev/null +++ b/test/dm/reset.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2015 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <dm.h> +#include <reset.h> +#include <asm/state.h> +#include <asm/test.h> +#include <dm/test.h> +#include <test/ut.h> + +/* Test that we can use particular reset devices */ +static int dm_test_reset_base(struct unit_test_state *uts) +{ + struct sandbox_state *state = state_get_current(); + struct udevice *dev; + + /* Device 0 is the platform data device - it should never respond */ + ut_assertok(uclass_get_device(UCLASS_RESET, 0, &dev)); + ut_asserteq(-ENODEV, reset_request(dev, RESET_WARM)); + ut_asserteq(-ENODEV, reset_request(dev, RESET_COLD)); + ut_asserteq(-ENODEV, reset_request(dev, RESET_POWER)); + + /* Device 1 is the warm reset device */ + ut_assertok(uclass_get_device(UCLASS_RESET, 1, &dev)); + ut_asserteq(-EACCES, reset_request(dev, RESET_WARM)); + ut_asserteq(-ENOSYS, reset_request(dev, RESET_COLD)); + ut_asserteq(-ENOSYS, reset_request(dev, RESET_POWER)); + + state->reset_allowed[RESET_WARM] = true; + ut_asserteq(-EINPROGRESS, reset_request(dev, RESET_WARM)); + state->reset_allowed[RESET_WARM] = false; + + /* Device 2 is the cold reset device */ + ut_assertok(uclass_get_device(UCLASS_RESET, 2, &dev)); + ut_asserteq(-ENOSYS, reset_request(dev, RESET_WARM)); + ut_asserteq(-EACCES, reset_request(dev, RESET_COLD)); + state->reset_allowed[RESET_POWER] = false; + ut_asserteq(-EACCES, reset_request(dev, RESET_POWER)); + state->reset_allowed[RESET_POWER] = true; + + return 0; +} +DM_TEST(dm_test_reset_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test that we can walk through the reset devices */ +static int dm_test_reset_walk(struct unit_test_state *uts) +{ + struct sandbox_state *state = state_get_current(); + + /* If we generate a power reset, we will exit sandbox! */ + state->reset_allowed[RESET_POWER] = false; + ut_asserteq(-EACCES, reset_walk(RESET_WARM)); + ut_asserteq(-EACCES, reset_walk(RESET_COLD)); + ut_asserteq(-EACCES, reset_walk(RESET_POWER)); + + /* + * Enable cold reset - this should make cold reset work, plus a warm + * reset should be promoted to cold, since this is the next step + * along. + */ + state->reset_allowed[RESET_COLD] = true; + ut_asserteq(-EINPROGRESS, reset_walk(RESET_WARM)); + ut_asserteq(-EINPROGRESS, reset_walk(RESET_COLD)); + ut_asserteq(-EACCES, reset_walk(RESET_POWER)); + state->reset_allowed[RESET_COLD] = false; + state->reset_allowed[RESET_POWER] = true; + + return 0; +} +DM_TEST(dm_test_reset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); diff --git a/test/dm/syscon.c b/test/dm/syscon.c new file mode 100644 index 0000000000..36424816b8 --- /dev/null +++ b/test/dm/syscon.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <dm.h> +#include <syscon.h> +#include <asm/test.h> +#include <dm/test.h> +#include <test/ut.h> + +DECLARE_GLOBAL_DATA_PTR; + +/* Base test of system controllers */ +static int dm_test_syscon_base(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev)); + ut_asserteq(SYSCON0, dev->driver_data); + + ut_assertok(uclass_get_device(UCLASS_SYSCON, 1, &dev)); + ut_asserteq(SYSCON1, dev->driver_data); + + ut_asserteq(-ENODEV, uclass_get_device(UCLASS_SYSCON, 2, &dev)); + + return 0; +} +DM_TEST(dm_test_syscon_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); diff --git a/test/dm/test-main.c b/test/dm/test-main.c index 0477d2fa73..0e43ab9548 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -76,6 +76,7 @@ static int dm_test_main(const char *test_name) struct unit_test_state *uts = &global_dm_test_state; uts->priv = &_global_priv_dm_test_state; struct unit_test *test; + int run_count; /* * If we have no device tree, or it only has a root node, then these @@ -90,10 +91,17 @@ static int dm_test_main(const char *test_name) if (!test_name) printf("Running %d driver model tests\n", n_ents); + run_count = 0; for (test = tests; test < tests + n_ents; test++) { - if (test_name && strcmp(test_name, test->name)) + const char *name = test->name; + + /* All tests have this prefix */ + if (!strncmp(name, "dm_test_", 8)) + name += 8; + if (test_name && strcmp(test_name, name)) continue; printf("Test: %s\n", test->name); + run_count++; ut_assertok(dm_test_init(uts)); uts->start = mallinfo(); @@ -109,7 +117,10 @@ static int dm_test_main(const char *test_name) ut_assertok(dm_test_destroy(uts)); } - printf("Failures: %d\n", uts->fail_count); + if (test_name && !run_count) + printf("Test '%s' not found\n", test_name); + else + printf("Failures: %d\n", uts->fail_count); gd->dm_root = NULL; ut_assertok(dm_init()); |