Commit 64ce0cad9e04aab19eb4c3f61333b203548281a7

Authored by Simon Glass
1 parent 201c29a2d6

dm: test: Add a test for the ram uclass

Add a test to confirm that we can probe this device and get information on
the available RAM.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 6 changed files with 73 additions and 0 deletions Side-by-side Diff

arch/sandbox/dts/test.dts
... ... @@ -196,6 +196,10 @@
196 196 };
197 197 };
198 198  
  199 + ram {
  200 + compatible = "sandbox,ram";
  201 + };
  202 +
199 203 reset@0 {
200 204 compatible = "sandbox,warm-reset";
201 205 };
configs/sandbox_defconfig
... ... @@ -47,4 +47,5 @@
47 47 CONFIG_UT_ENV=y
48 48 CONFIG_CLK=y
49 49 CONFIG_RESET=y
  50 +CONFIG_RAM=y
drivers/ram/Makefile
... ... @@ -5,4 +5,5 @@
5 5 # SPDX-License-Identifier: GPL-2.0+
6 6 #
7 7 obj-$(CONFIG_RAM) += ram-uclass.o
  8 +obj-$(CONFIG_SANDBOX) += sandbox_ram.o
drivers/ram/sandbox_ram.c
  1 +/*
  2 + * Copyright (c) 2015 Google, Inc
  3 + * Written by Simon Glass <sjg@chromium.org>
  4 + *
  5 + * SPDX-License-Identifier: GPL-2.0+
  6 + */
  7 +
  8 +#include <common.h>
  9 +#include <dm.h>
  10 +#include <errno.h>
  11 +#include <ram.h>
  12 +#include <asm/test.h>
  13 +
  14 +DECLARE_GLOBAL_DATA_PTR;
  15 +
  16 +static int sandbox_get_info(struct udevice *dev, struct ram_info *info)
  17 +{
  18 + info->base = 0;
  19 + info->size = gd->ram_size;
  20 +
  21 + return 0;
  22 +}
  23 +
  24 +static const struct ram_ops sandbox_ram_ops = {
  25 + .get_info = sandbox_get_info,
  26 +};
  27 +
  28 +static const struct udevice_id sandbox_ram_ids[] = {
  29 + { .compatible = "sandbox,ram" },
  30 + { }
  31 +};
  32 +
  33 +U_BOOT_DRIVER(warm_ram_sandbox) = {
  34 + .name = "ram_sandbox",
  35 + .id = UCLASS_RAM,
  36 + .of_match = sandbox_ram_ids,
  37 + .ops = &sandbox_ram_ops,
  38 +};
... ... @@ -20,6 +20,7 @@
20 20 obj-$(CONFIG_DM_GPIO) += gpio.o
21 21 obj-$(CONFIG_DM_I2C) += i2c.o
22 22 obj-$(CONFIG_DM_PCI) += pci.o
  23 +obj-$(CONFIG_RAM) += ram.o
23 24 obj-$(CONFIG_RESET) += reset.o
24 25 obj-$(CONFIG_DM_RTC) += rtc.o
25 26 obj-$(CONFIG_DM_SPI_FLASH) += sf.o
  1 +/*
  2 + * Copyright (C) 2015 Google, Inc
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#include <common.h>
  8 +#include <dm.h>
  9 +#include <ram.h>
  10 +#include <dm/test.h>
  11 +#include <test/ut.h>
  12 +
  13 +DECLARE_GLOBAL_DATA_PTR;
  14 +
  15 +/* Basic test of the ram uclass */
  16 +static int dm_test_ram_base(struct unit_test_state *uts)
  17 +{
  18 + struct udevice *dev;
  19 + struct ram_info info;
  20 +
  21 + ut_assertok(uclass_get_device(UCLASS_RAM, 0, &dev));
  22 + ut_assertok(ram_get_info(dev, &info));
  23 + ut_asserteq(0, info.base);
  24 + ut_asserteq(gd->ram_size, info.size);
  25 +
  26 + return 0;
  27 +}
  28 +DM_TEST(dm_test_ram_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);