aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile1
-rw-r--r--test/bootm.c247
-rw-r--r--test/cmd/Makefile1
-rw-r--r--test/cmd/setexpr.c384
-rw-r--r--test/cmd_ut.c4
-rw-r--r--test/dm/acpi.c20
-rw-r--r--test/dm/adc.c2
-rw-r--r--test/dm/blk.c5
-rw-r--r--test/dm/bus.c187
-rw-r--r--test/dm/core.c111
-rw-r--r--test/dm/cpu.c2
-rw-r--r--test/dm/devres.c4
-rw-r--r--test/dm/gpio.c2
-rw-r--r--test/dm/i2c.c3
-rw-r--r--test/dm/mux-emul.c2
-rw-r--r--test/dm/of_platdata.c30
-rw-r--r--test/dm/ofnode.c12
-rw-r--r--test/dm/ofread.c2
-rw-r--r--test/dm/pci.c6
-rw-r--r--test/dm/regmap.c2
-rw-r--r--test/dm/regulator.c18
-rw-r--r--test/dm/spi.c87
-rw-r--r--test/dm/test-driver.c13
-rw-r--r--test/dm/test-fdt.c312
-rw-r--r--test/dm/test-main.c8
-rw-r--r--test/dm/test-uclass.c13
-rw-r--r--test/dm/video.c8
-rw-r--r--test/dm/virtio.c2
-rw-r--r--test/env/hashtable.c2
-rw-r--r--test/py/tests/test_efi_capsule/capsule_defs.py5
-rw-r--r--test/py/tests/test_efi_capsule/conftest.py74
-rw-r--r--test/py/tests/test_efi_capsule/test_capsule_firmware.py241
-rw-r--r--test/py/tests/test_efi_capsule/uboot_bin_env.its36
-rw-r--r--test/py/tests/test_ofplatdata.py1
-rw-r--r--test/py/tests/test_sandbox_exit.py24
-rw-r--r--test/unicode_ut.c2
36 files changed, 1429 insertions, 444 deletions
diff --git a/test/Makefile b/test/Makefile
index 8296734..d4323f9 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -5,6 +5,7 @@
ifneq ($(CONFIG_SANDBOX),)
obj-$(CONFIG_$(SPL_)CMDLINE) += bloblist.o
endif
+obj-$(CONFIG_$(SPL_)CMDLINE) += bootm.o
obj-$(CONFIG_$(SPL_)CMDLINE) += cmd/
obj-$(CONFIG_$(SPL_)CMDLINE) += cmd_ut.o
obj-$(CONFIG_$(SPL_)CMDLINE) += command_ut.o
diff --git a/test/bootm.c b/test/bootm.c
new file mode 100644
index 0000000..92dc2b6
--- /dev/null
+++ b/test/bootm.c
@@ -0,0 +1,247 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for bootm routines
+ *
+ * Copyright 2020 Google LLC
+ */
+
+#include <common.h>
+#include <bootm.h>
+#include <test/suites.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define BOOTM_TEST(_name, _flags) UNIT_TEST(_name, _flags, bootm_test)
+
+enum {
+ BUF_SIZE = 1024,
+};
+
+#define CONSOLE_STR "console=/dev/ttyS0"
+
+/* Test cmdline processing where nothing happens */
+static int bootm_test_nop(struct unit_test_state *uts)
+{
+ char buf[BUF_SIZE];
+
+ *buf = '\0';
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, true));
+ ut_asserteq_str("", buf);
+
+ strcpy(buf, "test");
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, true));
+ ut_asserteq_str("test", buf);
+
+ return 0;
+}
+BOOTM_TEST(bootm_test_nop, 0);
+
+/* Test cmdline processing when out of space */
+static int bootm_test_nospace(struct unit_test_state *uts)
+{
+ char buf[BUF_SIZE];
+
+ /* Zero buffer size */
+ *buf = '\0';
+ ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, 0, true));
+
+ /* Buffer string not terminated */
+ memset(buf, 'a', BUF_SIZE);
+ ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, BUF_SIZE, true));
+
+ /* Not enough space to copy string */
+ memset(buf, '\0', BUF_SIZE);
+ memset(buf, 'a', BUF_SIZE / 2);
+ ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, BUF_SIZE, true));
+
+ /* Just enough space */
+ memset(buf, '\0', BUF_SIZE);
+ memset(buf, 'a', BUF_SIZE / 2 - 1);
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, true));
+
+ return 0;
+}
+BOOTM_TEST(bootm_test_nospace, 0);
+
+/* Test silent processing */
+static int bootm_test_silent(struct unit_test_state *uts)
+{
+ char buf[BUF_SIZE];
+
+ /* 'silent_linux' not set should do nothing */
+ env_set("silent_linux", NULL);
+ strcpy(buf, CONSOLE_STR);
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SILENT));
+ ut_asserteq_str(CONSOLE_STR, buf);
+
+ ut_assertok(env_set("silent_linux", "no"));
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SILENT));
+ ut_asserteq_str(CONSOLE_STR, buf);
+
+ ut_assertok(env_set("silent_linux", "yes"));
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SILENT));
+ ut_asserteq_str("console=", buf);
+
+ /* Empty buffer should still add the string */
+ *buf = '\0';
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SILENT));
+ ut_asserteq_str("console=", buf);
+
+ /* Check nothing happens when do_silent is false */
+ *buf = '\0';
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, 0));
+ ut_asserteq_str("", buf);
+
+ /* Not enough space */
+ *buf = '\0';
+ ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, 8, BOOTM_CL_SILENT));
+
+ /* Just enough space */
+ *buf = '\0';
+ ut_assertok(bootm_process_cmdline(buf, 9, BOOTM_CL_SILENT));
+
+ /* add at end */
+ strcpy(buf, "something");
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SILENT));
+ ut_asserteq_str("something console=", buf);
+
+ /* change at start */
+ strcpy(buf, CONSOLE_STR " something");
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SILENT));
+ ut_asserteq_str("console= something", buf);
+
+ return 0;
+}
+BOOTM_TEST(bootm_test_silent, 0);
+
+/* Test substitution processing */
+static int bootm_test_subst(struct unit_test_state *uts)
+{
+ char buf[BUF_SIZE];
+
+ /* try with an unset variable */
+ ut_assertok(env_set("var", NULL));
+ strcpy(buf, "some${var}thing");
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SUBST));
+ ut_asserteq_str("something", buf);
+
+ /* Replace with shorter string */
+ ut_assertok(env_set("var", "bb"));
+ strcpy(buf, "some${var}thing");
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SUBST));
+ ut_asserteq_str("somebbthing", buf);
+
+ /* Replace with same-length string */
+ ut_assertok(env_set("var", "abc"));
+ strcpy(buf, "some${var}thing");
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SUBST));
+ ut_asserteq_str("someabcthing", buf);
+
+ /* Replace with longer string */
+ ut_assertok(env_set("var", "abcde"));
+ strcpy(buf, "some${var}thing");
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SUBST));
+ ut_asserteq_str("someabcdething", buf);
+
+ /* Check it is case sensitive */
+ ut_assertok(env_set("VAR", NULL));
+ strcpy(buf, "some${VAR}thing");
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SUBST));
+ ut_asserteq_str("something", buf);
+
+ /* Check too long - need 12 bytes for each string */
+ strcpy(buf, "some${var}thing");
+ ut_asserteq(-ENOSPC,
+ bootm_process_cmdline(buf, 12 * 2 - 1, BOOTM_CL_SUBST));
+
+ /* Check just enough space */
+ strcpy(buf, "some${var}thing");
+ ut_assertok(bootm_process_cmdline(buf, 16 * 2, BOOTM_CL_SUBST));
+ ut_asserteq_str("someabcdething", buf);
+
+ /*
+ * Check the substition string being too long. This results in a string
+ * of 12 (13 bytes). We need enough space for that plus the original
+ * "a${var}c" string of 9 bytes. So 12 + 9 = 21 bytes.
+ */
+ ut_assertok(env_set("var", "1234567890"));
+ strcpy(buf, "a${var}c");
+ ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, 21, BOOTM_CL_SUBST));
+
+ strcpy(buf, "a${var}c");
+ ut_asserteq(0, bootm_process_cmdline(buf, 22, BOOTM_CL_SUBST));
+
+ /* Check multiple substitutions */
+ ut_assertok(env_set("var", "abc"));
+ strcpy(buf, "some${var}thing${bvar}else");
+ ut_asserteq(0, bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SUBST));
+ ut_asserteq_str("someabcthingelse", buf);
+
+ /* Check multiple substitutions */
+ ut_assertok(env_set("bvar", "123"));
+ strcpy(buf, "some${var}thing${bvar}else");
+ ut_asserteq(0, bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SUBST));
+ ut_asserteq_str("someabcthing123else", buf);
+
+ return 0;
+}
+BOOTM_TEST(bootm_test_subst, 0);
+
+/* Test silent processing in the bootargs variable */
+static int bootm_test_silent_var(struct unit_test_state *uts)
+{
+ env_set("bootargs", NULL);
+ ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SUBST));
+ ut_assertnull(env_get("bootargs"));
+
+ ut_assertok(env_set("bootargs", "some${var}thing"));
+ ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SUBST));
+ ut_asserteq_str("something", env_get("bootargs"));
+
+ return 0;
+}
+BOOTM_TEST(bootm_test_silent_var, 0);
+
+/* Test substitution processing in the bootargs variable */
+static int bootm_test_subst_var(struct unit_test_state *uts)
+{
+ env_set("bootargs", NULL);
+ ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
+ ut_asserteq_str("console=", env_get("bootargs"));
+
+ ut_assertok(env_set("var", "abc"));
+ ut_assertok(env_set("bootargs", "some${var}thing"));
+ ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
+ ut_asserteq_str("some${var}thing console=", env_get("bootargs"));
+
+ return 0;
+}
+BOOTM_TEST(bootm_test_subst_var, 0);
+
+/* Test substitution and silent console processing in the bootargs variable */
+static int bootm_test_subst_both(struct unit_test_state *uts)
+{
+ ut_assertok(env_set("silent_linux", "yes"));
+ env_set("bootargs", NULL);
+ ut_assertok(bootm_process_cmdline_env(BOOTM_CL_ALL));
+ ut_asserteq_str("console=", env_get("bootargs"));
+
+ ut_assertok(env_set("bootargs", "some${var}thing " CONSOLE_STR));
+ ut_assertok(env_set("var", "1234567890"));
+ ut_assertok(bootm_process_cmdline_env(BOOTM_CL_ALL));
+ ut_asserteq_str("some1234567890thing console=", env_get("bootargs"));
+
+ return 0;
+}
+BOOTM_TEST(bootm_test_subst_both, 0);
+
+int do_ut_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+ struct unit_test *tests = ll_entry_start(struct unit_test, bootm_test);
+ const int n_ents = ll_entry_count(struct unit_test, bootm_test);
+
+ return cmd_ut_category("bootm", "bootm_test_", tests, n_ents,
+ argc, argv);
+}
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index 859dcda..b2f71af 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -4,3 +4,4 @@
obj-y += mem.o
obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
+obj-y += setexpr.o
diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c
new file mode 100644
index 0000000..fd6d869
--- /dev/null
+++ b/test/cmd/setexpr.c
@@ -0,0 +1,384 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for setexpr command
+ *
+ * Copyright 2020 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <console.h>
+#include <mapmem.h>
+#include <dm/test.h>
+#include <test/suites.h>
+#include <test/ut.h>
+
+#define BUF_SIZE 0x100
+
+/* Declare a new mem test */
+#define SETEXPR_TEST(_name, _flags) UNIT_TEST(_name, _flags, setexpr_test)
+
+/* Test 'setexpr' command with simply setting integers */
+static int setexpr_test_int(struct unit_test_state *uts)
+{
+ u8 *buf;
+
+ buf = map_sysmem(0, BUF_SIZE);
+ memset(buf, '\xff', BUF_SIZE);
+
+ /* byte */
+ buf[0x0] = 0x12;
+ ut_assertok(run_command("setexpr.b fred 0", 0));
+ ut_asserteq_str("0", env_get("fred"));
+ ut_assertok(run_command("setexpr.b fred *0", 0));
+ ut_asserteq_str("12", env_get("fred"));
+
+ /* 16-bit */
+ *(short *)buf = 0x2345;
+ ut_assertok(run_command("setexpr.w fred 0", 0));
+ ut_asserteq_str("0", env_get("fred"));
+ ut_assertok(run_command("setexpr.w fred *0", 0));
+ ut_asserteq_str("2345", env_get("fred"));
+
+ /* 32-bit */
+ *(u32 *)buf = 0x3456789a;
+ ut_assertok(run_command("setexpr.l fred 0", 0));
+ ut_asserteq_str("0", env_get("fred"));
+ ut_assertok(run_command("setexpr.l fred *0", 0));
+ ut_asserteq_str("3456789a", env_get("fred"));
+
+ /* 64-bit */
+ *(u64 *)buf = 0x456789abcdef0123;
+ ut_assertok(run_command("setexpr.q fred 0", 0));
+ ut_asserteq_str("0", env_get("fred"));
+ ut_assertok(run_command("setexpr.q fred *0", 0));
+ ut_asserteq_str("456789abcdef0123", env_get("fred"));
+
+ /* default */
+ ut_assertok(run_command("setexpr fred 0", 0));
+ ut_asserteq_str("0", env_get("fred"));
+ ut_assertok(run_command("setexpr fred *0", 0));
+ ut_asserteq_str("cdef0123", env_get("fred"));
+
+ unmap_sysmem(buf);
+
+ return 0;
+}
+SETEXPR_TEST(setexpr_test_int, UT_TESTF_CONSOLE_REC);
+
+/* Test 'setexpr' command with + operator */
+static int setexpr_test_plus(struct unit_test_state *uts)
+{
+ char *buf;
+
+ buf = map_sysmem(0, BUF_SIZE);
+ memset(buf, '\xff', BUF_SIZE);
+
+ /* byte */
+ buf[0x0] = 0x12;
+ buf[0x10] = 0x34;
+ ut_assertok(run_command("setexpr.b fred *0 + *10", 0));
+ ut_asserteq_str("46", env_get("fred"));
+
+ /* 16-bit */
+ *(short *)buf = 0x2345;
+ *(short *)(buf + 0x10) = 0xf012;
+ ut_assertok(run_command("setexpr.w fred *0 + *10", 0));
+ ut_asserteq_str("11357", env_get("fred"));
+
+ /* 32-bit */
+ *(u32 *)buf = 0x3456789a;
+ *(u32 *)(buf + 0x10) = 0xc3384235;
+ ut_assertok(run_command("setexpr.l fred *0 + *10", 0));
+ ut_asserteq_str("f78ebacf", env_get("fred"));
+
+ /* 64-bit */
+ *(u64 *)buf = 0x456789abcdef0123;
+ *(u64 *)(buf + 0x10) = 0x4987328372849283;
+ ut_assertok(run_command("setexpr.q fred *0 + *10", 0));
+ ut_asserteq_str("8eeebc2f407393a6", env_get("fred"));
+
+ /* default */
+ ut_assertok(run_command("setexpr fred *0 + *10", 0));
+ ut_asserteq_str("1407393a6", env_get("fred"));
+
+ unmap_sysmem(buf);
+
+ return 0;
+}
+SETEXPR_TEST(setexpr_test_plus, UT_TESTF_CONSOLE_REC);
+
+/* Test 'setexpr' command with other operators */
+static int setexpr_test_oper(struct unit_test_state *uts)
+{
+ char *buf;
+
+ buf = map_sysmem(0, BUF_SIZE);
+ memset(buf, '\xff', BUF_SIZE);
+
+ *(u32 *)buf = 0x1234;
+ *(u32 *)(buf + 0x10) = 0x560000;
+
+ /* Quote | to avoid confusing hush */
+ ut_assertok(run_command("setexpr fred *0 \"|\" *10", 0));
+ ut_asserteq_str("561234", env_get("fred"));
+
+ *(u32 *)buf = 0x561200;
+ *(u32 *)(buf + 0x10) = 0x1234;
+
+ /* Quote & to avoid confusing hush */
+ ut_assertok(run_command("setexpr.l fred *0 \"&\" *10", 0));
+ ut_asserteq_str("1200", env_get("fred"));
+
+ ut_assertok(run_command("setexpr.l fred *0 ^ *10", 0));
+ ut_asserteq_str("560034", env_get("fred"));
+
+ ut_assertok(run_command("setexpr.l fred *0 - *10", 0));
+ ut_asserteq_str("55ffcc", env_get("fred"));
+
+ ut_assertok(run_command("setexpr.l fred *0 * *10", 0));
+ ut_asserteq_str("61ebfa800", env_get("fred"));
+
+ ut_assertok(run_command("setexpr.l fred *0 / *10", 0));
+ ut_asserteq_str("4ba", env_get("fred"));
+
+ ut_assertok(run_command("setexpr.l fred *0 % *10", 0));
+ ut_asserteq_str("838", env_get("fred"));
+
+ unmap_sysmem(buf);
+
+ return 0;
+}
+SETEXPR_TEST(setexpr_test_oper, UT_TESTF_CONSOLE_REC);
+
+/* Test 'setexpr' command with regex */
+static int setexpr_test_regex(struct unit_test_state *uts)
+{
+ char *buf, *val;
+
+ buf = map_sysmem(0, BUF_SIZE);
+
+ /* Single substitution */
+ ut_assertok(run_command("setenv fred 'this is a test'", 0));
+ ut_assertok(run_command("setexpr fred sub is us", 0));
+ val = env_get("fred");
+ ut_asserteq_str("thus is a test", val);
+
+ /* Global substitution */
+ ut_assertok(run_command("setenv fred 'this is a test'", 0));
+ ut_assertok(run_command("setexpr fred gsub is us", 0));
+ val = env_get("fred");
+ ut_asserteq_str("thus us a test", val);
+
+ /* Global substitution */
+ ut_assertok(run_command("setenv fred 'this is a test'", 0));
+ ut_assertok(run_command("setenv mary 'this is a test'", 0));
+ ut_assertok(run_command("setexpr fred gsub is us \"${mary}\"", 0));
+ val = env_get("fred");
+ ut_asserteq_str("thus us a test", val);
+ val = env_get("mary");
+ ut_asserteq_str("this is a test", val);
+
+ unmap_sysmem(buf);
+
+ return 0;
+}
+SETEXPR_TEST(setexpr_test_regex, UT_TESTF_CONSOLE_REC);
+
+/* Test 'setexpr' command with regex replacement that expands the string */
+static int setexpr_test_regex_inc(struct unit_test_state *uts)
+{
+ char *buf, *val;
+
+ buf = map_sysmem(0, BUF_SIZE);
+
+ ut_assertok(run_command("setenv fred 'this is a test'", 0));
+ ut_assertok(run_command("setexpr fred gsub is much_longer_string", 0));
+ val = env_get("fred");
+ ut_asserteq_str("thmuch_longer_string much_longer_string a test", val);
+ unmap_sysmem(buf);
+
+ return 0;
+}
+SETEXPR_TEST(setexpr_test_regex_inc, UT_TESTF_CONSOLE_REC);
+
+/* Test setexpr_regex_sub() directly to check buffer usage */
+static int setexpr_test_sub(struct unit_test_state *uts)
+{
+ char *buf, *nbuf;
+ int i;
+
+ buf = map_sysmem(0, BUF_SIZE);
+ nbuf = map_sysmem(0x1000, BUF_SIZE);
+
+ /* Add a pattern so we can check the buffer limits */
+ memset(buf, '\xff', BUF_SIZE);
+ memset(nbuf, '\xff', BUF_SIZE);
+ for (i = BUF_SIZE; i < 0x1000; i++) {
+ buf[i] = i & 0xff;
+ nbuf[i] = i & 0xff;
+ }
+ strcpy(buf, "this is a test");
+
+ /*
+ * This is a regression test, since a bug was found in the use of
+ * memmove() in setexpr
+ */
+ ut_assertok(setexpr_regex_sub(buf, BUF_SIZE, nbuf, BUF_SIZE, "is",
+ "us it is longer", true));
+ ut_asserteq_str("thus it is longer us it is longer a test", buf);
+ for (i = BUF_SIZE; i < 0x1000; i++) {
+ ut_assertf(buf[i] == (char)i,
+ "buf byte at %x should be %02x, got %02x)\n",
+ i, i & 0xff, (u8)buf[i]);
+ ut_assertf(nbuf[i] == (char)i,
+ "nbuf byte at %x should be %02x, got %02x)\n",
+ i, i & 0xff, (u8)nbuf[i]);
+ }
+
+ unmap_sysmem(buf);
+
+ return 0;
+}
+SETEXPR_TEST(setexpr_test_sub, UT_TESTF_CONSOLE_REC);
+
+/* Test setexpr_regex_sub() with back references */
+static int setexpr_test_backref(struct unit_test_state *uts)
+{
+ char *buf, *nbuf;
+ int i;
+
+ buf = map_sysmem(0, BUF_SIZE);
+ nbuf = map_sysmem(0x1000, BUF_SIZE);
+
+ /* Add a pattern so we can check the buffer limits */
+ memset(buf, '\xff', BUF_SIZE);
+ memset(nbuf, '\xff', BUF_SIZE);
+ for (i = BUF_SIZE; i < 0x1000; i++) {
+ buf[i] = i & 0xff;
+ nbuf[i] = i & 0xff;
+ }
+ strcpy(buf, "this is surely a test is it? yes this is indeed a test");
+
+ /*
+ * This is a regression test, since a bug was found in the use of
+ * memmove() in setexpr
+ */
+ ut_assertok(setexpr_regex_sub(buf, BUF_SIZE, nbuf, BUF_SIZE,
+ "(this) (is) (surely|indeed)",
+ "us \\1 \\2 \\3!", true));
+ ut_asserteq_str("us this is surely! a test is it? yes us this is indeed! a test",
+ buf);
+
+ /* The following checks fail at present due to a bug in setexpr */
+ return 0;
+ for (i = BUF_SIZE; i < 0x1000; i++) {
+ ut_assertf(buf[i] == (char)i,
+ "buf byte at %x should be %02x, got %02x)\n",
+ i, i & 0xff, (u8)buf[i]);
+ ut_assertf(nbuf[i] == (char)i,
+ "nbuf byte at %x should be %02x, got %02x)\n",
+ i, i & 0xff, (u8)nbuf[i]);
+ }
+
+ unmap_sysmem(buf);
+
+ return 0;
+}
+SETEXPR_TEST(setexpr_test_backref, UT_TESTF_CONSOLE_REC);
+
+/* Test 'setexpr' command with setting strings */
+static int setexpr_test_str(struct unit_test_state *uts)
+{
+ ulong start_mem;
+ char *buf;
+
+ buf = map_sysmem(0, BUF_SIZE);
+ memset(buf, '\xff', BUF_SIZE);
+
+ /*
+ * Set 'fred' to the same length as we expect to get below, to avoid a
+ * new allocation in 'setexpr'. That way we can check for memory leaks.
+ */
+ ut_assertok(env_set("fred", "x"));
+ start_mem = ut_check_free();
+ strcpy(buf, "hello");
+ ut_asserteq(1, run_command("setexpr.s fred 0", 0));
+ ut_assertok(ut_check_delta(start_mem));
+
+ start_mem = ut_check_free();
+ ut_assertok(env_set("fred", "12345"));
+ ut_assertok(run_command("setexpr.s fred *0", 0));
+ ut_asserteq_str("hello", env_get("fred"));
+ ut_assertok(ut_check_delta(start_mem));
+
+ unmap_sysmem(buf);
+
+ return 0;
+}
+SETEXPR_TEST(setexpr_test_str, UT_TESTF_CONSOLE_REC);
+
+
+/* Test 'setexpr' command with concatenating strings */
+static int setexpr_test_str_oper(struct unit_test_state *uts)
+{
+ ulong start_mem;
+ char *buf;
+
+ buf = map_sysmem(0, BUF_SIZE);
+ memset(buf, '\xff', BUF_SIZE);
+ strcpy(buf, "hello");
+ strcpy(buf + 0x10, " there");
+
+ ut_assertok(console_record_reset_enable());
+ start_mem = ut_check_free();
+ ut_asserteq(1, run_command("setexpr.s fred *0 * *10", 0));
+ ut_assertok(ut_check_delta(start_mem));
+ ut_assert_nextline("invalid op");
+ ut_assert_console_end();
+
+ /*
+ * Set 'fred' to the same length as we expect to get below, to avoid a
+ * new allocation in 'setexpr'. That way we can check for memory leaks.
+ */
+ ut_assertok(env_set("fred", "12345012345"));
+ start_mem = ut_check_free();
+ ut_assertok(run_command("setexpr.s fred *0 + *10", 0));
+ ut_asserteq_str("hello there", env_get("fred"));
+ ut_assertok(ut_check_delta(start_mem));
+
+ unmap_sysmem(buf);
+
+ return 0;
+}
+SETEXPR_TEST(setexpr_test_str_oper, UT_TESTF_CONSOLE_REC);
+
+/* Test 'setexpr' command with a string that is too long */
+static int setexpr_test_str_long(struct unit_test_state *uts)
+{
+ const int size = 128 << 10; /* setexpr strings are a max of 64KB */
+ char *buf, *val;
+
+ buf = map_sysmem(0, size);
+ memset(buf, 'a', size);
+
+ /* String should be truncated to 64KB */
+ ut_assertok(run_command("setexpr.s fred *0", 0));
+ val = env_get("fred");
+ ut_asserteq(64 << 10, strlen(val));
+
+ unmap_sysmem(buf);
+
+ return 0;
+}
+SETEXPR_TEST(setexpr_test_str_long, UT_TESTF_CONSOLE_REC);
+
+int do_ut_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+ struct unit_test *tests = ll_entry_start(struct unit_test,
+ setexpr_test);
+ const int n_ents = ll_entry_count(struct unit_test, setexpr_test);
+
+ return cmd_ut_category("cmd_setexpr", "cmd_mem_", tests, n_ents, argc,
+ argv);
+}
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 8f0bc68..fad1c89 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -75,6 +75,8 @@ static struct cmd_tbl cmd_ut_sub[] = {
U_BOOT_CMD_MKENT(log, CONFIG_SYS_MAXARGS, 1, do_ut_log, "", ""),
#endif
U_BOOT_CMD_MKENT(mem, CONFIG_SYS_MAXARGS, 1, do_ut_mem, "", ""),
+ U_BOOT_CMD_MKENT(setexpr, CONFIG_SYS_MAXARGS, 1, do_ut_setexpr, "",
+ ""),
#ifdef CONFIG_UT_TIME
U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
#endif
@@ -86,6 +88,7 @@ static struct cmd_tbl cmd_ut_sub[] = {
"", ""),
U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist,
"", ""),
+ U_BOOT_CMD_MKENT(bootm, CONFIG_SYS_MAXARGS, 1, do_ut_bootm, "", ""),
U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS, 1, do_ut_str,
"", ""),
#endif
@@ -153,6 +156,7 @@ static char ut_help_text[] =
#ifdef CONFIG_UT_OVERLAY
"ut overlay [test-name]\n"
#endif
+ "ut setexpr [test-name] - test setexpr command\n"
#ifdef CONFIG_SANDBOX
"ut str - Basic test of string functions\n"
#endif
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index f5eddac..e0a323e 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -25,12 +25,12 @@
#define BUF_SIZE 4096
/**
- * struct testacpi_platdata - Platform data for the test ACPI device
+ * struct testacpi_plat - Platform data for the test ACPI device
*
* @no_name: true to emit an empty ACPI name from testacpi_get_name()
* @return_error: true to return an error instead of a name
*/
-struct testacpi_platdata {
+struct testacpi_plat {
bool return_error;
bool no_name;
};
@@ -53,7 +53,7 @@ static int testacpi_write_tables(const struct udevice *dev,
static int testacpi_get_name(const struct udevice *dev, char *out_name)
{
- struct testacpi_platdata *plat = dev_get_platdata(dev);
+ struct testacpi_plat *plat = dev_get_plat(dev);
if (plat->return_error)
return -EINVAL;
@@ -110,7 +110,7 @@ U_BOOT_DRIVER(testacpi_drv) = {
.of_match = testacpi_ids,
.id = UCLASS_TEST_ACPI,
.bind = dm_scan_fdt_dev,
- .platdata_auto_alloc_size = sizeof(struct testacpi_platdata),
+ .plat_auto = sizeof(struct testacpi_plat),
ACPI_OPS_PTR(&testacpi_ops)
};
@@ -123,7 +123,7 @@ UCLASS_DRIVER(testacpi) = {
static int dm_test_acpi_get_name(struct unit_test_state *uts)
{
char name[ACPI_NAME_MAX];
- struct udevice *dev, *dev2, *i2c, *spi, *serial, *timer, *sound;
+ struct udevice *dev, *dev2, *i2c, *spi, *timer, *sound;
struct udevice *pci, *root;
/* Test getting the name from the driver */
@@ -146,10 +146,6 @@ static int dm_test_acpi_get_name(struct unit_test_state *uts)
ut_assertok(acpi_get_name(spi, name));
ut_asserteq_str("SPI0", name);
- /* The uart has no sequence number, so this should fail */
- ut_assertok(uclass_first_device(UCLASS_SERIAL, &serial));
- ut_asserteq(-ENXIO, acpi_get_name(serial, name));
-
/* ACPI doesn't know about the timer */
ut_assertok(uclass_first_device(UCLASS_TIMER, &timer));
ut_asserteq(-ENOENT, acpi_get_name(timer, name));
@@ -422,7 +418,7 @@ DM_TEST(dm_test_acpi_cmd_dump, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
/* Test acpi_device_path() */
static int dm_test_acpi_device_path(struct unit_test_state *uts)
{
- struct testacpi_platdata *plat;
+ struct testacpi_plat *plat;
char buf[ACPI_PATH_MAX];
struct udevice *dev, *child;
@@ -442,13 +438,13 @@ static int dm_test_acpi_device_path(struct unit_test_state *uts)
buf);
/* Test handling of a device which doesn't produce a name */
- plat = dev_get_platdata(dev);
+ plat = dev_get_plat(dev);
plat->no_name = true;
ut_assertok(acpi_device_path(child, buf, sizeof(buf)));
ut_asserteq_str("\\_SB." ACPI_TEST_CHILD_NAME, buf);
/* Test handling of a device which returns an error */
- plat = dev_get_platdata(dev);
+ plat = dev_get_plat(dev);
plat->return_error = true;
ut_asserteq(-EINVAL, acpi_device_path(child, buf, sizeof(buf)));
diff --git a/test/dm/adc.c b/test/dm/adc.c
index 8c6e4b0..740167e 100644
--- a/test/dm/adc.c
+++ b/test/dm/adc.c
@@ -67,7 +67,7 @@ static int dm_test_adc_supply(struct unit_test_state *uts)
ut_assertok(regulator_set_value(supply, SANDBOX_BUCK2_SET_UV));
ut_asserteq(SANDBOX_BUCK2_SET_UV, regulator_get_value(supply));
- /* Update ADC platdata and get new Vdd value */
+ /* Update ADC plat and get new Vdd value */
ut_assertok(adc_vdd_value(dev, &uV));
ut_asserteq(SANDBOX_BUCK2_SET_UV, uV);
diff --git a/test/dm/blk.c b/test/dm/blk.c
index f34c13f..a39a1eb 100644
--- a/test/dm/blk.c
+++ b/test/dm/blk.c
@@ -19,9 +19,6 @@ static int dm_test_blk_base(struct unit_test_state *uts)
{
struct udevice *blk1, *blk3, *dev;
- /* Make sure there are no block devices */
- ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_BLK, 0, &dev));
-
/* Create two, one the parent of the other */
ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
IF_TYPE_HOST, 1, 512, 2, &blk1));
@@ -139,7 +136,7 @@ static int dm_test_blk_devnum(struct unit_test_state *uts)
* Check that the block device devnum matches its parent's
* sequence number
*/
- desc = dev_get_uclass_platdata(dev);
+ desc = dev_get_uclass_plat(dev);
ut_asserteq(desc->devnum, i);
}
diff --git a/test/dm/bus.c b/test/dm/bus.c
index 27b7266..e768eab 100644
--- a/test/dm/bus.c
+++ b/test/dm/bus.c
@@ -19,104 +19,6 @@
DECLARE_GLOBAL_DATA_PTR;
-struct dm_test_parent_platdata {
- int count;
- int bind_flag;
- int uclass_bind_flag;
-};
-
-enum {
- FLAG_CHILD_PROBED = 10,
- FLAG_CHILD_REMOVED = -7,
-};
-
-static struct dm_test_state *test_state;
-
-static int testbus_drv_probe(struct udevice *dev)
-{
- return dm_scan_fdt_dev(dev);
-}
-
-static int testbus_child_post_bind(struct udevice *dev)
-{
- struct dm_test_parent_platdata *plat;
-
- plat = dev_get_parent_platdata(dev);
- plat->bind_flag = 1;
- plat->uclass_bind_flag = 2;
-
- return 0;
-}
-
-static int testbus_child_pre_probe(struct udevice *dev)
-{
- struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
-
- parent_data->flag += FLAG_CHILD_PROBED;
-
- return 0;
-}
-
-static int testbus_child_pre_probe_uclass(struct udevice *dev)
-{
- struct dm_test_priv *priv = dev_get_priv(dev);
-
- priv->uclass_flag++;
-
- return 0;
-}
-
-static int testbus_child_post_probe_uclass(struct udevice *dev)
-{
- struct dm_test_priv *priv = dev_get_priv(dev);
-
- priv->uclass_postp++;
-
- return 0;
-}
-
-static int testbus_child_post_remove(struct udevice *dev)
-{
- struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
- struct dm_test_state *dms = test_state;
-
- parent_data->flag += FLAG_CHILD_REMOVED;
- if (dms)
- dms->removed = dev;
-
- return 0;
-}
-
-static const struct udevice_id testbus_ids[] = {
- {
- .compatible = "denx,u-boot-test-bus",
- .data = DM_TEST_TYPE_FIRST },
- { }
-};
-
-U_BOOT_DRIVER(testbus_drv) = {
- .name = "testbus_drv",
- .of_match = testbus_ids,
- .id = UCLASS_TEST_BUS,
- .probe = testbus_drv_probe,
- .child_post_bind = testbus_child_post_bind,
- .priv_auto_alloc_size = sizeof(struct dm_test_priv),
- .platdata_auto_alloc_size = sizeof(struct dm_test_pdata),
- .per_child_auto_alloc_size = sizeof(struct dm_test_parent_data),
- .per_child_platdata_auto_alloc_size =
- sizeof(struct dm_test_parent_platdata),
- .child_pre_probe = testbus_child_pre_probe,
- .child_post_remove = testbus_child_post_remove,
-};
-
-UCLASS_DRIVER(testbus) = {
- .name = "testbus",
- .id = UCLASS_TEST_BUS,
- .flags = DM_UC_FLAG_SEQ_ALIAS,
- .child_pre_probe = testbus_child_pre_probe_uclass,
- .child_post_probe = testbus_child_post_probe_uclass,
-};
-
/* Test that we can probe for children */
static int dm_test_bus_children(struct unit_test_state *uts)
{
@@ -153,20 +55,21 @@ static int dm_test_bus_children_funcs(struct unit_test_state *uts)
ut_assertok(device_get_child(bus, 0, &dev));
ut_asserteq(-ENODEV, device_get_child(bus, 4, &dev));
ut_assertok(device_get_child_by_seq(bus, 5, &dev));
- ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
ut_asserteq_str("c-test@5", dev->name);
/* Device with sequence number 0 should be accessible */
- ut_asserteq(-ENODEV, device_find_child_by_seq(bus, -1, true, &dev));
- ut_assertok(device_find_child_by_seq(bus, 0, true, &dev));
- ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
- ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 0, false, &dev));
+ ut_asserteq(-ENODEV, device_find_child_by_seq(bus, -1, &dev));
+ ut_assertok(device_find_child_by_seq(bus, 0, &dev));
+ ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
+ ut_asserteq(0, device_find_child_by_seq(bus, 0, &dev));
ut_assertok(device_get_child_by_seq(bus, 0, &dev));
- ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
+ ut_asserteq(0, device_find_child_by_seq(bus, 0, &dev));
/* There is no device with sequence number 2 */
- ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, false, &dev));
- ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, true, &dev));
+ ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, &dev));
+ ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, &dev));
ut_asserteq(-ENODEV, device_get_child_by_seq(bus, 2, &dev));
/* Looking for something that is not a child */
@@ -193,10 +96,10 @@ static int dm_test_bus_children_of_offset(struct unit_test_state *uts)
ut_assert(node > 0);
ut_assertok(device_find_child_by_of_offset(bus, node, &dev));
ut_assertnonnull(dev);
- ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
+ ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
ut_assertok(device_get_child_by_of_offset(bus, node, &dev));
ut_assertnonnull(dev);
- ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
return 0;
}
@@ -220,7 +123,7 @@ static int dm_test_bus_children_iterators(struct unit_test_state *uts)
ut_asserteq_ptr(dev, NULL);
/* Move to the next child without using device_find_first_child() */
- ut_assertok(device_find_child_by_seq(bus, 5, true, &dev));
+ ut_assertok(device_find_child_by_seq(bus, 5, &dev));
ut_asserteq_str("c-test@5", dev->name);
ut_assertok(device_find_next_child(&dev));
ut_asserteq_str("c-test@0", dev->name);
@@ -245,7 +148,7 @@ static int test_bus_parent_data(struct unit_test_state *uts)
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
/* Check that parent data is allocated */
- ut_assertok(device_find_child_by_seq(bus, 0, true, &dev));
+ ut_assertok(device_find_child_by_seq(bus, 0, &dev));
ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
ut_assertok(device_get_child_by_seq(bus, 0, &dev));
parent_data = dev_get_parent_priv(dev);
@@ -312,19 +215,19 @@ static int dm_test_bus_parent_data_uclass(struct unit_test_state *uts)
/* Set the driver size to 0 so that the uclass size is used */
ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus));
drv = (struct driver *)bus->driver;
- size = drv->per_child_auto_alloc_size;
+ size = drv->per_child_auto;
#ifdef CONFIG_SANDBOX
os_mprotect_allow(bus->uclass->uc_drv, sizeof(*bus->uclass->uc_drv));
os_mprotect_allow(drv, sizeof(*drv));
#endif
- bus->uclass->uc_drv->per_child_auto_alloc_size = size;
- drv->per_child_auto_alloc_size = 0;
+ bus->uclass->uc_drv->per_child_auto = size;
+ drv->per_child_auto = 0;
ret = test_bus_parent_data(uts);
if (ret)
return ret;
- bus->uclass->uc_drv->per_child_auto_alloc_size = 0;
- drv->per_child_auto_alloc_size = size;
+ bus->uclass->uc_drv->per_child_auto = 0;
+ drv->per_child_auto = size;
return 0;
}
@@ -335,11 +238,10 @@ DM_TEST(dm_test_bus_parent_data_uclass,
static int dm_test_bus_parent_ops(struct unit_test_state *uts)
{
struct dm_test_parent_data *parent_data;
- struct dm_test_state *dms = uts->priv;
struct udevice *bus, *dev;
struct uclass *uc;
- test_state = dms;
+ testbus_get_clear_removed();
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc));
@@ -351,7 +253,7 @@ static int dm_test_bus_parent_ops(struct unit_test_state *uts)
ut_assertok(device_probe(dev));
parent_data = dev_get_parent_priv(dev);
- ut_asserteq(FLAG_CHILD_PROBED, parent_data->flag);
+ ut_asserteq(TEST_FLAG_CHILD_PROBED, parent_data->flag);
}
uclass_foreach_dev(dev, uc) {
@@ -359,20 +261,19 @@ static int dm_test_bus_parent_ops(struct unit_test_state *uts)
if (dev->parent != bus)
continue;
parent_data = dev_get_parent_priv(dev);
- ut_asserteq(FLAG_CHILD_PROBED, parent_data->flag);
+ ut_asserteq(TEST_FLAG_CHILD_PROBED, parent_data->flag);
ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
- ut_asserteq_ptr(dms->removed, dev);
+ ut_asserteq_ptr(testbus_get_clear_removed(), dev);
}
- test_state = NULL;
return 0;
}
DM_TEST(dm_test_bus_parent_ops, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
-static int test_bus_parent_platdata(struct unit_test_state *uts)
+static int test_bus_parent_plat(struct unit_test_state *uts)
{
- struct dm_test_parent_platdata *plat;
+ struct dm_test_parent_plat *plat;
struct udevice *bus, *dev;
/* Check that the bus has no children */
@@ -386,7 +287,7 @@ static int test_bus_parent_platdata(struct unit_test_state *uts)
dev;
device_find_next_child(&dev)) {
/* Check that platform data is allocated */
- plat = dev_get_parent_platdata(dev);
+ plat = dev_get_parent_plat(dev);
ut_assert(plat != NULL);
/*
@@ -398,7 +299,7 @@ static int test_bus_parent_platdata(struct unit_test_state *uts)
device_probe(dev);
device_remove(dev, DM_REMOVE_NORMAL);
- ut_asserteq_ptr(plat, dev_get_parent_platdata(dev));
+ ut_asserteq_ptr(plat, dev_get_parent_plat(dev));
ut_asserteq(1, plat->count);
ut_assertok(device_probe(dev));
}
@@ -410,7 +311,7 @@ static int test_bus_parent_platdata(struct unit_test_state *uts)
dev;
device_find_next_child(&dev)) {
/* Check that platform data is allocated */
- plat = dev_get_parent_platdata(dev);
+ plat = dev_get_parent_plat(dev);
ut_assert(plat != NULL);
ut_asserteq(1, plat->count);
}
@@ -423,13 +324,13 @@ static int test_bus_parent_platdata(struct unit_test_state *uts)
device_unbind(dev);
} while (dev);
- /* Now the child platdata should be removed and re-added */
+ /* Now the child plat should be removed and re-added */
device_probe(bus);
for (device_find_first_child(bus, &dev);
dev;
device_find_next_child(&dev)) {
/* Check that platform data is allocated */
- plat = dev_get_parent_platdata(dev);
+ plat = dev_get_parent_plat(dev);
ut_assert(plat != NULL);
ut_asserteq(0, plat->count);
}
@@ -439,14 +340,14 @@ static int test_bus_parent_platdata(struct unit_test_state *uts)
}
/* Test that the bus can store platform data about each child */
-static int dm_test_bus_parent_platdata(struct unit_test_state *uts)
+static int dm_test_bus_parent_plat(struct unit_test_state *uts)
{
- return test_bus_parent_platdata(uts);
+ return test_bus_parent_plat(uts);
}
-DM_TEST(dm_test_bus_parent_platdata, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_bus_parent_plat, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
/* As above but the size is controlled by the uclass */
-static int dm_test_bus_parent_platdata_uclass(struct unit_test_state *uts)
+static int dm_test_bus_parent_plat_uclass(struct unit_test_state *uts)
{
struct udevice *bus;
struct driver *drv;
@@ -456,28 +357,28 @@ static int dm_test_bus_parent_platdata_uclass(struct unit_test_state *uts)
/* Set the driver size to 0 so that the uclass size is used */
ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus));
drv = (struct driver *)bus->driver;
- size = drv->per_child_platdata_auto_alloc_size;
+ size = drv->per_child_plat_auto;
#ifdef CONFIG_SANDBOX
os_mprotect_allow(bus->uclass->uc_drv, sizeof(*bus->uclass->uc_drv));
os_mprotect_allow(drv, sizeof(*drv));
#endif
- bus->uclass->uc_drv->per_child_platdata_auto_alloc_size = size;
- drv->per_child_platdata_auto_alloc_size = 0;
- ret = test_bus_parent_platdata(uts);
+ bus->uclass->uc_drv->per_child_plat_auto = size;
+ drv->per_child_plat_auto = 0;
+ ret = test_bus_parent_plat(uts);
if (ret)
return ret;
- bus->uclass->uc_drv->per_child_platdata_auto_alloc_size = 0;
- drv->per_child_platdata_auto_alloc_size = size;
+ bus->uclass->uc_drv->per_child_plat_auto = 0;
+ drv->per_child_plat_auto = size;
return 0;
}
-DM_TEST(dm_test_bus_parent_platdata_uclass,
+DM_TEST(dm_test_bus_parent_plat_uclass,
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
/* Test that the child post_bind method is called */
static int dm_test_bus_child_post_bind(struct unit_test_state *uts)
{
- struct dm_test_parent_platdata *plat;
+ struct dm_test_parent_plat *plat;
struct udevice *bus, *dev;
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
@@ -485,7 +386,7 @@ static int dm_test_bus_child_post_bind(struct unit_test_state *uts)
dev;
device_find_next_child(&dev)) {
/* Check that platform data is allocated */
- plat = dev_get_parent_platdata(dev);
+ plat = dev_get_parent_plat(dev);
ut_assert(plat != NULL);
ut_asserteq(1, plat->bind_flag);
}
@@ -498,7 +399,7 @@ DM_TEST(dm_test_bus_child_post_bind, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
/* Test that the child post_bind method is called */
static int dm_test_bus_child_post_bind_uclass(struct unit_test_state *uts)
{
- struct dm_test_parent_platdata *plat;
+ struct dm_test_parent_plat *plat;
struct udevice *bus, *dev;
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
@@ -506,7 +407,7 @@ static int dm_test_bus_child_post_bind_uclass(struct unit_test_state *uts)
dev;
device_find_next_child(&dev)) {
/* Check that platform data is allocated */
- plat = dev_get_parent_platdata(dev);
+ plat = dev_get_parent_plat(dev);
ut_assert(plat != NULL);
ut_asserteq(2, plat->uclass_bind_flag);
}
diff --git a/test/dm/core.c b/test/dm/core.c
index 6f380a5..1f5ca57 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -43,29 +43,29 @@ static const struct dm_test_pdata test_pdata_pre_reloc = {
.ping_add = TEST_INTVAL_PRE_RELOC,
};
-U_BOOT_DEVICE(dm_test_info1) = {
+U_BOOT_DRVINFO(dm_test_info1) = {
.name = "test_drv",
- .platdata = &test_pdata[0],
+ .plat = &test_pdata[0],
};
-U_BOOT_DEVICE(dm_test_info2) = {
+U_BOOT_DRVINFO(dm_test_info2) = {
.name = "test_drv",
- .platdata = &test_pdata[1],
+ .plat = &test_pdata[1],
};
-U_BOOT_DEVICE(dm_test_info3) = {
+U_BOOT_DRVINFO(dm_test_info3) = {
.name = "test_drv",
- .platdata = &test_pdata[2],
+ .plat = &test_pdata[2],
};
static struct driver_info driver_info_manual = {
.name = "test_manual_drv",
- .platdata = &test_pdata_manual,
+ .plat = &test_pdata_manual,
};
static struct driver_info driver_info_pre_reloc = {
.name = "test_pre_reloc_drv",
- .platdata = &test_pdata_pre_reloc,
+ .plat = &test_pdata_pre_reloc,
};
static struct driver_info driver_info_act_dma = {
@@ -105,7 +105,7 @@ int dm_leak_check_end(struct unit_test_state *uts)
return 0;
}
-/* Test that binding with platdata occurs correctly */
+/* Test that binding with plat occurs correctly */
static int dm_test_autobind(struct unit_test_state *uts)
{
struct dm_test_state *dms = uts->priv;
@@ -116,14 +116,14 @@ static int dm_test_autobind(struct unit_test_state *uts)
* device with no children.
*/
ut_assert(dms->root);
- ut_asserteq(1, list_count_items(&gd->uclass_root));
+ ut_asserteq(1, list_count_items(gd->uclass_root));
ut_asserteq(0, list_count_items(&gd->dm_root->child_head));
ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]);
- ut_assertok(dm_scan_platdata(false));
+ ut_assertok(dm_scan_plat(false));
/* We should have our test class now at least, plus more children */
- ut_assert(1 < list_count_items(&gd->uclass_root));
+ ut_assert(1 < list_count_items(gd->uclass_root));
ut_assert(0 < list_count_items(&gd->dm_root->child_head));
/* Our 3 dm_test_infox children should be bound to the test uclass */
@@ -131,7 +131,7 @@ static int dm_test_autobind(struct unit_test_state *uts)
/* No devices should be probed */
list_for_each_entry(dev, &gd->dm_root->child_head, sibling_node)
- ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
+ ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
/* Our test driver should have been bound 3 times */
ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND] == 3);
@@ -140,7 +140,7 @@ static int dm_test_autobind(struct unit_test_state *uts)
}
DM_TEST(dm_test_autobind, 0);
-/* Test that binding with uclass platdata allocation occurs correctly */
+/* Test that binding with uclass plat allocation occurs correctly */
static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts)
{
struct dm_test_perdev_uc_pdata *uc_pdata;
@@ -152,16 +152,16 @@ static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts)
/**
* Test if test uclass driver requires allocation for the uclass
- * platform data and then check the dev->uclass_platdata pointer.
+ * platform data and then check the dev->uclass_plat pointer.
*/
- ut_assert(uc->uc_drv->per_device_platdata_auto_alloc_size);
+ ut_assert(uc->uc_drv->per_device_plat_auto);
for (uclass_find_first_device(UCLASS_TEST, &dev);
dev;
uclass_find_next_device(&dev)) {
ut_assertnonnull(dev);
- uc_pdata = dev_get_uclass_platdata(dev);
+ uc_pdata = dev_get_uclass_plat(dev);
ut_assert(uc_pdata);
}
@@ -169,7 +169,7 @@ static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts)
}
DM_TEST(dm_test_autobind_uclass_pdata_alloc, UT_TESTF_SCAN_PDATA);
-/* Test that binding with uclass platdata setting occurs correctly */
+/* Test that binding with uclass plat setting occurs correctly */
static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts)
{
struct dm_test_perdev_uc_pdata *uc_pdata;
@@ -184,7 +184,7 @@ static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts)
uclass_find_next_device(&dev)) {
ut_assertnonnull(dev);
- uc_pdata = dev_get_uclass_platdata(dev);
+ uc_pdata = dev_get_uclass_plat(dev);
ut_assert(uc_pdata);
ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1);
ut_assert(uc_pdata->intval2 == TEST_UC_PDATA_INTVAL2);
@@ -212,7 +212,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts)
ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]);
/* The root device should not be activated until needed */
- ut_assert(dms->root->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED);
/*
* We should be able to find the three test devices, and they should
@@ -222,17 +222,17 @@ static int dm_test_autoprobe(struct unit_test_state *uts)
for (i = 0; i < 3; i++) {
ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
ut_assert(dev);
- ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED),
+ ut_assertf(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED),
"Driver %d/%s already activated", i, dev->name);
/* This should activate it */
ut_assertok(uclass_get_device(UCLASS_TEST, i, &dev));
ut_assert(dev);
- ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
/* Activating a device should activate the root device */
if (!i)
- ut_assert(dms->root->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED);
}
/*
@@ -255,7 +255,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts)
ut_assert(priv);
ut_asserteq(expected_base_add, priv->base_add);
- pdata = dev->platdata;
+ pdata = dev_get_plat(dev);
expected_base_add += pdata->ping_add;
}
@@ -263,8 +263,8 @@ static int dm_test_autoprobe(struct unit_test_state *uts)
}
DM_TEST(dm_test_autoprobe, UT_TESTF_SCAN_PDATA);
-/* Check that we see the correct platdata in each device */
-static int dm_test_platdata(struct unit_test_state *uts)
+/* Check that we see the correct plat in each device */
+static int dm_test_plat(struct unit_test_state *uts)
{
const struct dm_test_pdata *pdata;
struct udevice *dev;
@@ -273,13 +273,13 @@ static int dm_test_platdata(struct unit_test_state *uts)
for (i = 0; i < 3; i++) {
ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
ut_assert(dev);
- pdata = dev->platdata;
+ pdata = dev_get_plat(dev);
ut_assert(pdata->ping_add == test_pdata[i].ping_add);
}
return 0;
}
-DM_TEST(dm_test_platdata, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_plat, UT_TESTF_SCAN_PDATA);
/* Test that we can bind, probe, remove, unbind a driver */
static int dm_test_lifecycle(struct unit_test_state *uts)
@@ -297,7 +297,7 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
ut_assert(dev);
ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND]
== op_count[DM_TEST_OP_BIND] + 1);
- ut_assert(!dev->priv);
+ ut_assert(!dev_get_priv(dev));
/* Probe the device - it should fail allocating private data */
dms->force_fail_alloc = 1;
@@ -305,14 +305,14 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
ut_assert(ret == -ENOMEM);
ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE]
== op_count[DM_TEST_OP_PROBE] + 1);
- ut_assert(!dev->priv);
+ ut_assert(!dev_get_priv(dev));
/* Try again without the alloc failure */
dms->force_fail_alloc = 0;
ut_assertok(device_probe(dev));
ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE]
== op_count[DM_TEST_OP_PROBE] + 2);
- ut_assert(dev->priv);
+ ut_assert(dev_get_priv(dev));
/* This should be device 3 in the uclass */
ut_assertok(uclass_find_device(UCLASS_TEST, 3, &test_dev));
@@ -400,10 +400,10 @@ int dm_check_operations(struct unit_test_state *uts, struct udevice *dev,
int expected;
int pingret;
- /* Getting the child device should allocate platdata / priv */
+ /* Getting the child device should allocate plat / priv */
ut_assertok(testfdt_ping(dev, 10, &pingret));
- ut_assert(dev->priv);
- ut_assert(dev->platdata);
+ ut_assert(dev_get_priv(dev));
+ ut_assert(dev_get_plat(dev));
expected = 10 + base;
ut_asserteq(expected, pingret);
@@ -414,7 +414,7 @@ int dm_check_operations(struct unit_test_state *uts, struct udevice *dev,
ut_asserteq(expected, pingret);
/* Now check the ping_total */
- priv = dev->priv;
+ priv = dev_get_priv(dev);
ut_asserteq(DM_TEST_START_TOTAL + 10 + 20 + base * 2,
priv->ping_total);
@@ -438,13 +438,13 @@ static int dm_test_operations(struct unit_test_state *uts)
/*
* Get the 'reg' property, which tells us what the ping add
- * should be. We don't use the platdata because we want
+ * should be. We don't use the plat because we want
* to test the code that sets that up (testfdt_drv_probe()).
*/
base = test_pdata[i].ping_add;
debug("dev=%d, base=%d\n", i, base);
- ut_assert(!dm_check_operations(uts, dev, base, dev->priv));
+ ut_assert(!dm_check_operations(uts, dev, base, dev_get_priv(dev)));
}
return 0;
@@ -460,13 +460,13 @@ static int dm_test_remove(struct unit_test_state *uts)
for (i = 0; i < 3; i++) {
ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
ut_assert(dev);
- ut_assertf(dev->flags & DM_FLAG_ACTIVATED,
+ ut_assertf(dev_get_flags(dev) & DM_FLAG_ACTIVATED,
"Driver %d/%s not activated", i, dev->name);
ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
- ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED),
+ ut_assertf(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED),
"Driver %d/%s should have deactivated", i,
dev->name);
- ut_assert(!dev->priv);
+ ut_assert(!dev_get_priv(dev));
}
return 0;
@@ -485,8 +485,8 @@ static int dm_test_leak(struct unit_test_state *uts)
dm_leak_check_start(uts);
- ut_assertok(dm_scan_platdata(false));
- ut_assertok(dm_scan_fdt(gd->fdt_blob, false));
+ ut_assertok(dm_scan_plat(false));
+ ut_assertok(dm_scan_fdt(false));
/* Scanning the uclass is enough to probe all the devices */
for (id = UCLASS_ROOT; id < UCLASS_COUNT; id++) {
@@ -512,7 +512,7 @@ static int dm_test_uclass(struct unit_test_state *uts)
ut_assertok(uclass_get(UCLASS_TEST, &uc));
ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_DESTROY]);
- ut_assert(uc->priv);
+ ut_assert(uclass_get_priv(uc));
ut_assertok(uclass_destroy(uc));
ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
@@ -547,7 +547,7 @@ static int create_children(struct unit_test_state *uts, struct udevice *parent,
&driver_info_manual, &dev));
pdata = calloc(1, sizeof(*pdata));
pdata->ping_add = key + i;
- dev->platdata = pdata;
+ dev_set_plat(dev, pdata);
if (child)
child[i] = dev;
}
@@ -1052,8 +1052,8 @@ static int dm_test_inactive_child(struct unit_test_state *uts)
*/
ut_asserteq(-ENODEV, device_find_first_inactive_child(parent,
UCLASS_TEST, &dev1));
- ut_assertok(device_bind_ofnode(parent, DM_GET_DRIVER(test_drv),
- "test_child", 0, ofnode_null(), &dev1));
+ ut_assertok(device_bind(parent, DM_DRIVER_GET(test_drv),
+ "test_child", 0, ofnode_null(), &dev1));
ut_assertok(device_find_first_inactive_child(parent, UCLASS_TEST,
&dev2));
@@ -1066,3 +1066,22 @@ static int dm_test_inactive_child(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_inactive_child, UT_TESTF_SCAN_PDATA);
+
+/* Make sure all bound devices have a sequence number */
+static int dm_test_all_have_seq(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ struct uclass *uc;
+
+ list_for_each_entry(uc, gd->uclass_root, sibling_node) {
+ list_for_each_entry(dev, &uc->dev_head, uclass_node) {
+ if (dev->seq_ == -1)
+ printf("Device '%s' has no seq (%d)\n",
+ dev->name, dev->seq_);
+ ut_assert(dev->seq_ != -1);
+ }
+ }
+
+ return 0;
+}
+DM_TEST(dm_test_all_have_seq, UT_TESTF_SCAN_PDATA);
diff --git a/test/dm/cpu.c b/test/dm/cpu.c
index 28869c1..ed12caf 100644
--- a/test/dm/cpu.c
+++ b/test/dm/cpu.c
@@ -25,7 +25,7 @@ static int dm_test_cpu(struct unit_test_state *uts)
for (uclass_find_first_device(UCLASS_CPU, &dev);
dev;
uclass_find_next_device(&dev))
- ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
ut_assertok(uclass_get_device_by_name(UCLASS_CPU, "cpu-test1", &dev));
ut_asserteq_ptr(cpu_get_current_dev(), dev);
diff --git a/test/dm/devres.c b/test/dm/devres.c
index e1e088a..4f959d1 100644
--- a/test/dm/devres.c
+++ b/test/dm/devres.c
@@ -158,8 +158,8 @@ static int dm_test_devres_phase(struct unit_test_state *uts)
ut_asserteq(1, stats.allocs);
ut_asserteq(TEST_DEVRES_SIZE, stats.total_size);
- /* Getting platdata should add one allocation */
- ut_assertok(device_ofdata_to_platdata(dev));
+ /* Getting plat should add one allocation */
+ ut_assertok(device_of_to_plat(dev));
devres_get_stats(dev, &stats);
ut_asserteq(2, stats.allocs);
ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE3, stats.total_size);
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index 54e960b..d7b85e7 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -30,7 +30,7 @@ static int dm_test_gpio(struct unit_test_state *uts)
/*
* We expect to get 4 banks. One is anonymous (just numbered) and
- * comes from platdata. The other are named a (20 gpios),
+ * comes from plat. The other are named a (20 gpios),
* b (10 gpios) and c (10 gpios) and come from the device tree. See
* test/dm/test.dts.
*/
diff --git a/test/dm/i2c.c b/test/dm/i2c.c
index 681ce45..d74f5f9 100644
--- a/test/dm/i2c.c
+++ b/test/dm/i2c.c
@@ -28,9 +28,6 @@ static int dm_test_i2c_find(struct unit_test_state *uts)
struct udevice *bus, *dev;
const int no_chip = 0x10;
- ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_I2C, busnum,
- false, &bus));
-
/*
* The post_bind() method will bind devices to chip selects. Check
* this then remove the emulation and the slave device.
diff --git a/test/dm/mux-emul.c b/test/dm/mux-emul.c
index 141fd4d..45154ce 100644
--- a/test/dm/mux-emul.c
+++ b/test/dm/mux-emul.c
@@ -60,7 +60,7 @@ U_BOOT_DRIVER(emul_mux) = {
.of_match = mux_emul_of_match,
.ops = &mux_emul_ops,
.probe = mux_emul_probe,
- .priv_auto_alloc_size = sizeof(struct mux_emul_priv),
+ .priv_auto = sizeof(struct mux_emul_priv),
};
static int dm_test_mux_emul_default_state(struct unit_test_state *uts)
diff --git a/test/dm/of_platdata.c b/test/dm/of_platdata.c
index 4f3cc15..cfc43a5 100644
--- a/test/dm/of_platdata.c
+++ b/test/dm/of_platdata.c
@@ -8,7 +8,7 @@
#include <test/ut.h>
/* Test that we can find a device using of-platdata */
-static int dm_test_of_platdata_base(struct unit_test_state *uts)
+static int dm_test_of_plat_base(struct unit_test_state *uts)
{
struct udevice *dev;
@@ -17,10 +17,10 @@ static int dm_test_of_platdata_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_platdata_base, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_base, UT_TESTF_SCAN_PDATA);
/* Test that we can read properties from a device */
-static int dm_test_of_platdata_props(struct unit_test_state *uts)
+static int dm_test_of_plat_props(struct unit_test_state *uts)
{
struct dtd_sandbox_spl_test *plat;
struct udevice *dev;
@@ -31,7 +31,7 @@ static int dm_test_of_platdata_props(struct unit_test_state *uts)
ut_asserteq_str("sandbox_clk_test", dev->name);
ut_assertok(uclass_next_device_err(&dev));
- plat = dev_get_platdata(dev);
+ plat = dev_get_plat(dev);
ut_assert(plat->boolval);
ut_asserteq(1, plat->intval);
ut_asserteq(4, ARRAY_SIZE(plat->intarray));
@@ -54,7 +54,7 @@ static int dm_test_of_platdata_props(struct unit_test_state *uts)
ut_asserteq_str("", plat->stringarray[2]);
ut_assertok(uclass_next_device_err(&dev));
- plat = dev_get_platdata(dev);
+ plat = dev_get_plat(dev);
ut_assert(!plat->boolval);
ut_asserteq(3, plat->intval);
ut_asserteq(5, plat->intarray[0]);
@@ -74,14 +74,14 @@ static int dm_test_of_platdata_props(struct unit_test_state *uts)
ut_asserteq_str("message", plat->stringarray[2]);
ut_assertok(uclass_next_device_err(&dev));
- plat = dev_get_platdata(dev);
+ plat = dev_get_plat(dev);
ut_assert(!plat->boolval);
ut_asserteq_str("one", plat->stringarray[0]);
ut_asserteq_str("", plat->stringarray[1]);
ut_asserteq_str("", plat->stringarray[2]);
ut_assertok(uclass_next_device_err(&dev));
- plat = dev_get_platdata(dev);
+ plat = dev_get_plat(dev);
ut_assert(!plat->boolval);
ut_asserteq_str("spl", plat->stringarray[0]);
@@ -89,7 +89,7 @@ static int dm_test_of_platdata_props(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_platdata_props, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_props, UT_TESTF_SCAN_PDATA);
/*
* find_driver_info - recursively find the driver_info for a device
@@ -139,7 +139,7 @@ static int find_driver_info(struct unit_test_state *uts, struct udevice *parent,
}
/* Check that every device is recorded in its driver_info struct */
-static int dm_test_of_platdata_dev(struct unit_test_state *uts)
+static int dm_test_of_plat_dev(struct unit_test_state *uts)
{
const struct driver_info *info =
ll_entry_start(struct driver_info, driver_info);
@@ -171,17 +171,17 @@ static int dm_test_of_platdata_dev(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_platdata_dev, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_dev, UT_TESTF_SCAN_PDATA);
/* Test handling of phandles that point to other devices */
-static int dm_test_of_platdata_phandle(struct unit_test_state *uts)
+static int dm_test_of_plat_phandle(struct unit_test_state *uts)
{
struct dtd_sandbox_clk_test *plat;
struct udevice *dev, *clk;
ut_assertok(uclass_first_device_err(UCLASS_MISC, &dev));
ut_asserteq_str("sandbox_clk_test", dev->name);
- plat = dev_get_platdata(dev);
+ plat = dev_get_plat(dev);
ut_assertok(device_get_by_driver_info_idx(plat->clocks[0].idx, &clk));
ut_asserteq_str("fixed_clock", clk->name);
@@ -204,11 +204,11 @@ static int dm_test_of_platdata_phandle(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_platdata_phandle, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_phandle, UT_TESTF_SCAN_PDATA);
#if CONFIG_IS_ENABLED(OF_PLATDATA_PARENT)
/* Test that device parents are correctly set up */
-static int dm_test_of_platdata_parent(struct unit_test_state *uts)
+static int dm_test_of_plat_parent(struct unit_test_state *uts)
{
struct udevice *rtc, *i2c;
@@ -218,5 +218,5 @@ static int dm_test_of_platdata_parent(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_platdata_parent, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_parent, UT_TESTF_SCAN_PDATA);
#endif
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index fb1ceb1..c539134 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -249,3 +249,15 @@ static int dm_test_ofnode_get_child_count(struct unit_test_state *uts)
}
DM_TEST(dm_test_ofnode_get_child_count,
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+static int dm_test_ofnode_is_enabled(struct unit_test_state *uts)
+{
+ ofnode root_node = ofnode_path("/");
+ ofnode node = ofnode_path("/usb@0");
+
+ ut_assert(ofnode_is_enabled(root_node));
+ ut_assert(!ofnode_is_enabled(node));
+
+ return 0;
+}
+DM_TEST(dm_test_ofnode_is_enabled, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
diff --git a/test/dm/ofread.c b/test/dm/ofread.c
index 9064426..8c7dd82 100644
--- a/test/dm/ofread.c
+++ b/test/dm/ofread.c
@@ -33,7 +33,7 @@ static int dm_test_ofnode_get_property_by_prop(struct unit_test_state *uts)
ut_asserteq(4, len);
break;
case 3:
- /* only for platdata */
+ /* only for plat */
ut_asserteq_str("name", propname);
ut_asserteq(6, len);
ut_asserteq_str("flash", value);
diff --git a/test/dm/pci.c b/test/dm/pci.c
index 76490be..fa2e4a8 100644
--- a/test/dm/pci.c
+++ b/test/dm/pci.c
@@ -120,13 +120,13 @@ static int dm_test_pci_drvdata(struct unit_test_state *uts)
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap));
ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data);
- ut_assertok(dev_of_valid(swap));
+ ut_assertok(dev_has_ofnode(swap));
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x0c, 0), &swap));
ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data);
- ut_assertok(dev_of_valid(swap));
+ ut_assertok(dev_has_ofnode(swap));
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x10, 0), &swap));
ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data);
- ut_assertok(!dev_of_valid(swap));
+ ut_assertok(!dev_has_ofnode(swap));
return 0;
}
diff --git a/test/dm/regmap.c b/test/dm/regmap.c
index 2effef3..22a2930 100644
--- a/test/dm/regmap.c
+++ b/test/dm/regmap.c
@@ -280,7 +280,7 @@ U_BOOT_DRIVER(regmap_test) = {
.of_match = regmaptest_ids,
.id = UCLASS_NOP,
.probe = remaptest_probe,
- .priv_auto_alloc_size = sizeof(struct regmaptest_priv),
+ .priv_auto = sizeof(struct regmaptest_priv),
};
static int dm_test_devm_regmap(struct unit_test_state *uts)
diff --git a/test/dm/regulator.c b/test/dm/regulator.c
index 0e7a232..86f4862 100644
--- a/test/dm/regulator.c
+++ b/test/dm/regulator.c
@@ -50,7 +50,7 @@ static const char *regulator_names[OUTPUT_COUNT][OUTPUT_NAME_COUNT] = {
/* Test regulator get method */
static int dm_test_power_regulator_get(struct unit_test_state *uts)
{
- struct dm_regulator_uclass_platdata *uc_pdata;
+ struct dm_regulator_uclass_plat *uc_pdata;
struct udevice *dev_by_devname;
struct udevice *dev_by_platname;
const char *devname;
@@ -77,7 +77,7 @@ static int dm_test_power_regulator_get(struct unit_test_state *uts)
* a device with the name equal to the requested one.
*/
ut_assertok(regulator_get_by_platname(platname, &dev_by_platname));
- uc_pdata = dev_get_uclass_platdata(dev_by_platname);
+ uc_pdata = dev_get_uclass_plat(dev_by_platname);
ut_assert(uc_pdata);
ut_asserteq_str(platname, uc_pdata->name);
@@ -95,7 +95,7 @@ DM_TEST(dm_test_power_regulator_get, UT_TESTF_SCAN_FDT);
/* Test regulator set and get Voltage method */
static int dm_test_power_regulator_set_get_voltage(struct unit_test_state *uts)
{
- struct dm_regulator_uclass_platdata *uc_pdata;
+ struct dm_regulator_uclass_plat *uc_pdata;
struct udevice *dev;
const char *platname;
int val_set, val_get;
@@ -104,7 +104,7 @@ static int dm_test_power_regulator_set_get_voltage(struct unit_test_state *uts)
platname = regulator_names[BUCK1][PLATNAME];
ut_assertok(regulator_get_by_platname(platname, &dev));
- uc_pdata = dev_get_uclass_platdata(dev);
+ uc_pdata = dev_get_uclass_plat(dev);
ut_assert(uc_pdata);
val_set = uc_pdata->min_uV;
@@ -122,7 +122,7 @@ DM_TEST(dm_test_power_regulator_set_get_voltage, UT_TESTF_SCAN_FDT);
/* Test regulator set and get Current method */
static int dm_test_power_regulator_set_get_current(struct unit_test_state *uts)
{
- struct dm_regulator_uclass_platdata *uc_pdata;
+ struct dm_regulator_uclass_plat *uc_pdata;
struct udevice *dev;
const char *platname;
int val_set, val_get;
@@ -131,7 +131,7 @@ static int dm_test_power_regulator_set_get_current(struct unit_test_state *uts)
platname = regulator_names[LDO1][PLATNAME];
ut_assertok(regulator_get_by_platname(platname, &dev));
- uc_pdata = dev_get_uclass_platdata(dev);
+ uc_pdata = dev_get_uclass_plat(dev);
ut_assert(uc_pdata);
val_set = uc_pdata->min_uA;
@@ -146,7 +146,7 @@ static int dm_test_power_regulator_set_get_current(struct unit_test_state *uts)
platname = regulator_names[LDO2][PLATNAME];
ut_assertok(regulator_get_by_platname(platname, &dev));
- uc_pdata = dev_get_uclass_platdata(dev);
+ uc_pdata = dev_get_uclass_plat(dev);
ut_assert(uc_pdata);
ut_asserteq(-ENODATA, uc_pdata->min_uA);
ut_asserteq(-ENODATA, uc_pdata->max_uA);
@@ -220,7 +220,7 @@ DM_TEST(dm_test_power_regulator_set_get_mode, UT_TESTF_SCAN_FDT);
/* Test regulator set and get suspend Voltage method */
static int dm_test_power_regulator_set_get_suspend_voltage(struct unit_test_state *uts)
{
- struct dm_regulator_uclass_platdata *uc_pdata;
+ struct dm_regulator_uclass_plat *uc_pdata;
const struct dm_regulator_ops *ops;
struct udevice *dev;
const char *platname;
@@ -230,7 +230,7 @@ static int dm_test_power_regulator_set_get_suspend_voltage(struct unit_test_stat
platname = regulator_names[BUCK1][PLATNAME];
ut_assertok(regulator_get_by_platname(platname, &dev));
- uc_pdata = dev_get_uclass_platdata(dev);
+ uc_pdata = dev_get_uclass_plat(dev);
ut_assert(uc_pdata);
ops = dev_get_driver_ops(dev);
diff --git a/test/dm/spi.c b/test/dm/spi.c
index fb180ae..ee4ad3a 100644
--- a/test/dm/spi.c
+++ b/test/dm/spi.c
@@ -9,6 +9,7 @@
#include <spi.h>
#include <spi_flash.h>
#include <asm/state.h>
+#include <asm/test.h>
#include <dm/device-internal.h>
#include <dm/test.h>
#include <dm/uclass-internal.h>
@@ -22,13 +23,10 @@ static int dm_test_spi_find(struct unit_test_state *uts)
struct sandbox_state *state = state_get_current();
struct spi_slave *slave;
struct udevice *bus, *dev;
- const int busnum = 0, cs = 0, mode = 0, speed = 1000000, cs_b = 1;
+ const int busnum = 0, cs = 0, mode = 0, speed = 1000000, cs_b = 2;
struct spi_cs_info info;
ofnode node;
- ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_SPI, busnum,
- false, &bus));
-
/*
* The post_bind() method will bind devices to chip selects. Check
* this then remove the emulation and the slave device.
@@ -94,6 +92,87 @@ static int dm_test_spi_find(struct unit_test_state *uts)
}
DM_TEST(dm_test_spi_find, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+/* dm_test_spi_switch_slaves - Helper function to check whether spi_claim_bus
+ * operates correctly with two spi slaves.
+ *
+ * Check that switching back and forth between two slaves claiming the bus
+ * will update dm_spi_bus->speed and sandbox_spi bus speed/mode correctly.
+ *
+ * @uts - unit test state
+ * @slave_a - first spi slave used for testing
+ * @slave_b - second spi slave used for testing
+ */
+static int dm_test_spi_switch_slaves(struct unit_test_state *uts,
+ struct spi_slave *slave_a,
+ struct spi_slave *slave_b)
+{
+ struct udevice *bus;
+ struct dm_spi_bus *bus_data;
+
+ /* Check that slaves are on the same bus */
+ ut_asserteq_ptr(dev_get_parent(slave_a->dev),
+ dev_get_parent(slave_b->dev));
+
+ bus = dev_get_parent(slave_a->dev);
+ bus_data = dev_get_uclass_priv(bus);
+
+ ut_assertok(spi_claim_bus(slave_a));
+ ut_asserteq(slave_a->max_hz, bus_data->speed);
+ ut_asserteq(slave_a->max_hz, sandbox_spi_get_speed(bus));
+ ut_asserteq(slave_a->mode, sandbox_spi_get_mode(bus));
+ spi_release_bus(slave_a);
+
+ ut_assertok(spi_claim_bus(slave_b));
+ ut_asserteq(slave_b->max_hz, bus_data->speed);
+ ut_asserteq(slave_b->max_hz, sandbox_spi_get_speed(bus));
+ ut_asserteq(slave_b->mode, sandbox_spi_get_mode(bus));
+ spi_release_bus(slave_b);
+
+ ut_assertok(spi_claim_bus(slave_a));
+ ut_asserteq(slave_a->max_hz, bus_data->speed);
+ ut_asserteq(slave_a->max_hz, sandbox_spi_get_speed(bus));
+ ut_asserteq(slave_a->mode, sandbox_spi_get_mode(bus));
+ spi_release_bus(slave_a);
+
+ return 0;
+}
+
+static int dm_test_spi_claim_bus(struct unit_test_state *uts)
+{
+ struct udevice *bus;
+ struct spi_slave *slave_a, *slave_b;
+ struct dm_spi_slave_plat *slave_plat;
+ const int busnum = 0, cs_a = 0, cs_b = 1, mode = 0;
+
+ /* Get spi slave on CS0 */
+ ut_assertok(spi_get_bus_and_cs(busnum, cs_a, 1000000, mode, NULL, 0,
+ &bus, &slave_a));
+ /* Get spi slave on CS1 */
+ ut_assertok(spi_get_bus_and_cs(busnum, cs_b, 1000000, mode, NULL, 0,
+ &bus, &slave_b));
+
+ /* Different max_hz, different mode. */
+ ut_assert(slave_a->max_hz != slave_b->max_hz);
+ ut_assert(slave_a->mode != slave_b->mode);
+ dm_test_spi_switch_slaves(uts, slave_a, slave_b);
+
+ /* Different max_hz, same mode. */
+ slave_a->mode = slave_b->mode;
+ dm_test_spi_switch_slaves(uts, slave_a, slave_b);
+
+ /*
+ * Same max_hz, different mode.
+ * Restore original mode for slave_a, from platdata.
+ */
+ slave_plat = dev_get_parent_plat(slave_a->dev);
+ slave_a->mode = slave_plat->mode;
+ slave_a->max_hz = slave_b->max_hz;
+ dm_test_spi_switch_slaves(uts, slave_a, slave_b);
+
+ return 0;
+}
+DM_TEST(dm_test_spi_claim_bus, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
/* Test that sandbox SPI works correctly */
static int dm_test_spi_xfer(struct unit_test_state *uts)
{
diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c
index 08bdf01..a67f5d3 100644
--- a/test/dm/test-driver.c
+++ b/test/dm/test-driver.c
@@ -12,6 +12,7 @@
#include <log.h>
#include <malloc.h>
#include <asm/io.h>
+#include <dm/device-internal.h>
#include <dm/test.h>
#include <test/test.h>
#include <test/ut.h>
@@ -21,7 +22,7 @@ static struct unit_test_state *uts = &global_dm_test_state;
static int testdrv_ping(struct udevice *dev, int pingval, int *pingret)
{
- const struct dm_test_pdata *pdata = dev_get_platdata(dev);
+ const struct dm_test_pdata *pdata = dev_get_plat(dev);
struct dm_test_priv *priv = dev_get_priv(dev);
*pingret = pingval + pdata->ping_add;
@@ -67,7 +68,7 @@ static int test_remove(struct udevice *dev)
static int test_unbind(struct udevice *dev)
{
/* Private data should not be allocated */
- ut_assert(!dev->priv);
+ ut_assert(!dev_get_priv(dev));
dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
return 0;
@@ -81,7 +82,7 @@ U_BOOT_DRIVER(test_drv) = {
.probe = test_probe,
.remove = test_remove,
.unbind = test_unbind,
- .priv_auto_alloc_size = sizeof(struct dm_test_priv),
+ .priv_auto = sizeof(struct dm_test_priv),
};
U_BOOT_DRIVER(test2_drv) = {
@@ -92,7 +93,7 @@ U_BOOT_DRIVER(test2_drv) = {
.probe = test_probe,
.remove = test_remove,
.unbind = test_unbind,
- .priv_auto_alloc_size = sizeof(struct dm_test_priv),
+ .priv_auto = sizeof(struct dm_test_priv),
};
static int test_manual_drv_ping(struct udevice *dev, int pingval, int *pingret)
@@ -119,8 +120,8 @@ static int test_manual_probe(struct udevice *dev)
dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
if (!dms->force_fail_alloc)
- dev->priv = calloc(1, sizeof(struct dm_test_priv));
- if (!dev->priv)
+ dev_set_priv(dev, calloc(1, sizeof(struct dm_test_priv)));
+ if (!dev_get_priv(dev))
return -ENOMEM;
return 0;
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index cc12419..b535390 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -23,116 +23,13 @@
DECLARE_GLOBAL_DATA_PTR;
-static int testfdt_drv_ping(struct udevice *dev, int pingval, int *pingret)
-{
- const struct dm_test_pdata *pdata = dev->platdata;
- struct dm_test_priv *priv = dev_get_priv(dev);
-
- *pingret = pingval + pdata->ping_add;
- priv->ping_total += *pingret;
-
- return 0;
-}
-
-static const struct test_ops test_ops = {
- .ping = testfdt_drv_ping,
-};
-
-static int testfdt_ofdata_to_platdata(struct udevice *dev)
-{
- struct dm_test_pdata *pdata = dev_get_platdata(dev);
-
- pdata->ping_add = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
- "ping-add", -1);
- pdata->base = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev),
- "ping-expect");
-
- return 0;
-}
-
-static int testfdt_drv_probe(struct udevice *dev)
-{
- struct dm_test_priv *priv = dev_get_priv(dev);
-
- priv->ping_total += DM_TEST_START_TOTAL;
-
- /*
- * If this device is on a bus, the uclass_flag will be set before
- * calling this function. In the meantime the uclass_postp is
- * initlized to a value -1. These are used respectively by
- * dm_test_bus_child_pre_probe_uclass() and
- * dm_test_bus_child_post_probe_uclass().
- */
- priv->uclass_total += priv->uclass_flag;
- priv->uclass_postp = -1;
-
- return 0;
-}
-
-static const struct udevice_id testfdt_ids[] = {
- {
- .compatible = "denx,u-boot-fdt-test",
- .data = DM_TEST_TYPE_FIRST },
- {
- .compatible = "google,another-fdt-test",
- .data = DM_TEST_TYPE_SECOND },
- { }
-};
-
-U_BOOT_DRIVER(testfdt_drv) = {
- .name = "testfdt_drv",
- .of_match = testfdt_ids,
- .id = UCLASS_TEST_FDT,
- .ofdata_to_platdata = testfdt_ofdata_to_platdata,
- .probe = testfdt_drv_probe,
- .ops = &test_ops,
- .priv_auto_alloc_size = sizeof(struct dm_test_priv),
- .platdata_auto_alloc_size = sizeof(struct dm_test_pdata),
-};
-
-static const struct udevice_id testfdt1_ids[] = {
- {
- .compatible = "denx,u-boot-fdt-test1",
- .data = DM_TEST_TYPE_FIRST },
- { }
-};
-
-U_BOOT_DRIVER(testfdt1_drv) = {
- .name = "testfdt1_drv",
- .of_match = testfdt1_ids,
- .id = UCLASS_TEST_FDT,
- .ofdata_to_platdata = testfdt_ofdata_to_platdata,
- .probe = testfdt_drv_probe,
- .ops = &test_ops,
- .priv_auto_alloc_size = sizeof(struct dm_test_priv),
- .platdata_auto_alloc_size = sizeof(struct dm_test_pdata),
- .flags = DM_FLAG_PRE_RELOC,
-};
-
-/* From here is the testfdt uclass code */
-int testfdt_ping(struct udevice *dev, int pingval, int *pingret)
-{
- const struct test_ops *ops = device_get_ops(dev);
-
- if (!ops->ping)
- return -ENOSYS;
-
- return ops->ping(dev, pingval, pingret);
-}
-
-UCLASS_DRIVER(testfdt) = {
- .name = "testfdt",
- .id = UCLASS_TEST_FDT,
- .flags = DM_UC_FLAG_SEQ_ALIAS,
-};
-
struct dm_testprobe_pdata {
int probe_err;
};
static int testprobe_drv_probe(struct udevice *dev)
{
- struct dm_testprobe_pdata *pdata = dev_get_platdata(dev);
+ struct dm_testprobe_pdata *pdata = dev_get_plat(dev);
return pdata->probe_err;
}
@@ -147,7 +44,7 @@ U_BOOT_DRIVER(testprobe_drv) = {
.of_match = testprobe_ids,
.id = UCLASS_TEST_PROBE,
.probe = testprobe_drv_probe,
- .platdata_auto_alloc_size = sizeof(struct dm_testprobe_pdata),
+ .plat_auto = sizeof(struct dm_testprobe_pdata),
};
UCLASS_DRIVER(testprobe) = {
@@ -167,14 +64,14 @@ struct dm_testdevres_priv {
static int testdevres_drv_bind(struct udevice *dev)
{
- struct dm_testdevres_pdata *pdata = dev_get_platdata(dev);
+ struct dm_testdevres_pdata *pdata = dev_get_plat(dev);
pdata->ptr = devm_kmalloc(dev, TEST_DEVRES_SIZE, 0);
return 0;
}
-static int testdevres_drv_ofdata_to_platdata(struct udevice *dev)
+static int testdevres_drv_of_to_plat(struct udevice *dev)
{
struct dm_testdevres_priv *priv = dev_get_priv(dev);
@@ -202,10 +99,10 @@ U_BOOT_DRIVER(testdevres_drv) = {
.of_match = testdevres_ids,
.id = UCLASS_TEST_DEVRES,
.bind = testdevres_drv_bind,
- .ofdata_to_platdata = testdevres_drv_ofdata_to_platdata,
+ .of_to_plat = testdevres_drv_of_to_plat,
.probe = testdevres_drv_probe,
- .platdata_auto_alloc_size = sizeof(struct dm_testdevres_pdata),
- .priv_auto_alloc_size = sizeof(struct dm_testdevres_priv),
+ .plat_auto = sizeof(struct dm_testdevres_pdata),
+ .priv_auto = sizeof(struct dm_testdevres_priv),
};
UCLASS_DRIVER(testdevres) = {
@@ -232,7 +129,7 @@ int dm_check_devices(struct unit_test_state *uts, int num_devices)
/*
* Get the 'ping-expect' property, which tells us what the
- * ping add should be. We don't use the platdata because we
+ * ping add should be. We don't use the plat because we
* want to test the code that sets that up
* (testfdt_drv_probe()).
*/
@@ -257,7 +154,7 @@ static int dm_test_fdt(struct unit_test_state *uts)
int ret;
int i;
- ret = dm_extended_scan_fdt(gd->fdt_blob, false);
+ ret = dm_extended_scan(false);
ut_assert(!ret);
ret = uclass_get(UCLASS_TEST_FDT, &uc);
@@ -271,7 +168,7 @@ static int dm_test_fdt(struct unit_test_state *uts)
ret = uclass_find_device(UCLASS_TEST_FDT, i, &dev);
ut_assert(!ret);
ut_assert(!dev_get_priv(dev));
- ut_assert(dev->platdata);
+ ut_assert(dev_get_plat(dev));
}
ut_assertok(dm_check_devices(uts, num_devices));
@@ -308,7 +205,7 @@ static int dm_test_fdt_pre_reloc(struct unit_test_state *uts)
struct uclass *uc;
int ret;
- ret = dm_scan_fdt(gd->fdt_blob, true);
+ ret = dm_scan_fdt(true);
ut_assert(!ret);
ret = uclass_get(UCLASS_TEST_FDT, &uc);
@@ -331,22 +228,30 @@ static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
struct udevice *dev;
/* A few basic santiy tests */
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 3, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 3, &dev));
ut_asserteq_str("b-test", dev->name);
+ ut_asserteq(3, dev_seq(dev));
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 8, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 8, &dev));
ut_asserteq_str("a-test", dev->name);
+ ut_asserteq(8, dev_seq(dev));
+
+ /*
+ * This device has no alias so gets the next value after all available
+ * aliases. The last alias is testfdt12
+ */
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 13, &dev));
+ ut_asserteq_str("d-test", dev->name);
+ ut_asserteq(13, dev_seq(dev));
- ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 5,
- true, &dev));
+ ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 9,
+ &dev));
ut_asserteq_ptr(NULL, dev);
/* Test aliases */
ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 6, &dev));
ut_asserteq_str("e-test", dev->name);
-
- ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 7,
- true, &dev));
+ ut_asserteq(6, dev_seq(dev));
/*
* Note that c-test nodes are not probed since it is not a top-level
@@ -354,6 +259,7 @@ static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
*/
ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 3, &dev));
ut_asserteq_str("b-test", dev->name);
+ ut_asserteq(3, dev_seq(dev));
/*
* d-test wants sequence number 3 also, but it can't have it because
@@ -361,36 +267,98 @@ static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
*/
ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 2, &dev));
ut_asserteq_str("d-test", dev->name);
+ ut_asserteq(13, dev_seq(dev));
+
+ /* g-test gets the next value after f-test */
+ ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 15, &dev));
+ ut_asserteq_str("g-test", dev->name);
+ ut_asserteq(15, dev_seq(dev));
+
+ /* And we should still have holes in our sequence numbers */
+ ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 0,
+ &dev));
+ ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 1,
+ &dev));
+ ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 2,
+ &dev));
+ ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 4,
+ &dev));
+ ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 7,
+ &dev));
+ ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 9,
+ &dev));
+ ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 10,
+ &dev));
+ ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 11,
+ &dev));
+
+ return 0;
+}
+DM_TEST(dm_test_fdt_uclass_seq, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* More tests for sequence numbers */
+static int dm_test_fdt_uclass_seq_manual(struct unit_test_state *uts)
+{
+ struct udevice *dev;
/*
- * d-test actually gets 9, because thats the next free one after the
- * aliases.
+ * Since DM_UC_FLAG_NO_AUTO_SEQ is set for this uclass, only testfdtm1
+ * should get a sequence number assigned
*/
- ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 9, &dev));
- ut_asserteq_str("d-test", dev->name);
+ ut_assertok(uclass_get_device(UCLASS_TEST_FDT_MANUAL, 0, &dev));
+ ut_asserteq_str("testfdtm0", dev->name);
+ ut_asserteq(-1, dev_seq(dev));
- /* initially no one wants seq 10 */
- ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_TEST_FDT, 10,
- &dev));
- ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
- ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 4, &dev));
+ ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT_MANUAL, 1, &dev));
+ ut_asserteq_str("testfdtm1", dev->name);
+ ut_asserteq(1, dev_seq(dev));
- /* But now that it is probed, we can find it */
- ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 10, &dev));
- ut_asserteq_str("f-test", dev->name);
+ ut_assertok(uclass_get_device(UCLASS_TEST_FDT_MANUAL, 2, &dev));
+ ut_asserteq_str("testfdtm2", dev->name);
+ ut_asserteq(-1, dev_seq(dev));
+
+ return 0;
+}
+DM_TEST(dm_test_fdt_uclass_seq_manual, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ ofnode node;
+
+ /* Check creating a device with an alias */
+ node = ofnode_path("/some-bus/c-test@1");
+ ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv),
+ "c-test@1", NULL, node, &dev));
+ ut_asserteq(12, dev_seq(dev));
+ ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 12, &dev));
+ ut_asserteq_str("c-test@1", dev->name);
/*
- * And we should still have holes in our sequence numbers, that is 2
- * and 4 should not be used.
+ * Now bind a device without an alias. It should not get the next
+ * sequence number after all aliases, and existing bound devices. The
+ * last alias is 12, so we have:
+ *
+ * 13 d-test
+ * 14 f-test
+ * 15 g-test
+ * 16 h-test
+ * 17 another-test
+ * 18 chosen-test
+ *
+ * So next available is 19
*/
- ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 2,
- true, &dev));
- ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 4,
- true, &dev));
+ ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv),
+ "fred", NULL, ofnode_null(), &dev));
+ ut_asserteq(19, dev_seq(dev));
+
+ ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv),
+ "fred2", NULL, ofnode_null(), &dev));
+ ut_asserteq(20, dev_seq(dev));
return 0;
}
-DM_TEST(dm_test_fdt_uclass_seq, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_fdt_uclass_seq_more, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
/* Test that we can find a device by device tree offset */
static int dm_test_fdt_offset(struct unit_test_state *uts)
@@ -445,7 +413,7 @@ static int dm_test_first_next_device(struct unit_test_state *uts)
/* Remove them and try again, with an error on the second one */
ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 1, &dev));
- pdata = dev_get_platdata(dev);
+ pdata = dev_get_plat(dev);
pdata->probe_err = -ENOMEM;
device_remove(parent, DM_REMOVE_NORMAL);
ut_assertok(uclass_first_device(UCLASS_TEST_PROBE, &dev));
@@ -454,7 +422,7 @@ static int dm_test_first_next_device(struct unit_test_state *uts)
/* Now an error on the first one */
ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 0, &dev));
- pdata = dev_get_platdata(dev);
+ pdata = dev_get_plat(dev);
pdata->probe_err = -ENOENT;
device_remove(parent, DM_REMOVE_NORMAL);
ut_asserteq(-ENOENT, uclass_first_device(UCLASS_TEST_PROBE, &dev));
@@ -541,21 +509,21 @@ static int dm_test_first_next_ok_device(struct unit_test_state *uts)
ut_assertok(check_devices(uts, devlist, 0));
/* Remove them and try again, with an error on the second one */
- pdata = dev_get_platdata(devlist[1]);
+ pdata = dev_get_plat(devlist[1]);
pdata->probe_err = -ENOENT - 1;
device_remove(parent, DM_REMOVE_NORMAL);
ut_assertok(check_devices(uts, devlist, 1 << 1));
/* Now an error on the first one */
- pdata = dev_get_platdata(devlist[0]);
+ pdata = dev_get_plat(devlist[0]);
pdata->probe_err = -ENOENT - 0;
device_remove(parent, DM_REMOVE_NORMAL);
ut_assertok(check_devices(uts, devlist, 3 << 0));
/* Now errors on all */
- pdata = dev_get_platdata(devlist[2]);
+ pdata = dev_get_plat(devlist[2]);
pdata->probe_err = -ENOENT - 2;
- pdata = dev_get_platdata(devlist[3]);
+ pdata = dev_get_plat(devlist[3]);
pdata->probe_err = -ENOENT - 3;
device_remove(parent, DM_REMOVE_NORMAL);
ut_assertok(check_devices(uts, devlist, 0xf << 0));
@@ -587,30 +555,30 @@ static int dm_test_fdt_translation(struct unit_test_state *uts)
fdt32_t dma_addr[2];
/* Some simple translations */
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
ut_asserteq_str("dev@0,0", dev->name);
ut_asserteq(0x8000, dev_read_addr(dev));
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, &dev));
ut_asserteq_str("dev@1,100", dev->name);
ut_asserteq(0x9000, dev_read_addr(dev));
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 2, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 2, &dev));
ut_asserteq_str("dev@2,200", dev->name);
ut_asserteq(0xA000, dev_read_addr(dev));
/* No translation for busses with #size-cells == 0 */
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 3, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 3, &dev));
ut_asserteq_str("dev@42", dev->name);
ut_asserteq(0x42, dev_read_addr(dev));
/* dma address translation */
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
dma_addr[0] = cpu_to_be32(0);
dma_addr[1] = cpu_to_be32(0);
ut_asserteq(0x10000000, dev_translate_dma_address(dev, dma_addr));
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, &dev));
dma_addr[0] = cpu_to_be32(1);
dma_addr[1] = cpu_to_be32(0x100);
ut_asserteq(0x20000000, dev_translate_dma_address(dev, dma_addr));
@@ -628,7 +596,7 @@ static int dm_test_fdt_get_addr_ptr_flat(struct unit_test_state *uts)
ut_assertok(uclass_first_device_err(UCLASS_GPIO, &gpio));
ut_assertnull(devfdt_get_addr_ptr(gpio));
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
ptr = devfdt_get_addr_ptr(dev);
ut_asserteq_ptr((void *)0x8000, ptr);
@@ -643,7 +611,7 @@ static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts)
fdt_addr_t addr;
void *paddr;
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
addr = devfdt_get_addr(dev);
ut_asserteq(0x8000, addr);
@@ -664,7 +632,7 @@ static int dm_test_fdt_remap_addr_index_flat(struct unit_test_state *uts)
fdt_size_t size;
void *paddr;
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
addr = devfdt_get_addr_size_index(dev, 0, &size);
ut_asserteq(0x8000, addr);
@@ -686,7 +654,7 @@ static int dm_test_fdt_remap_addr_name_flat(struct unit_test_state *uts)
fdt_size_t size;
void *paddr;
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
addr = devfdt_get_addr_size_name(dev, "sandbox-dummy-0", &size);
ut_asserteq(0x8000, addr);
@@ -707,7 +675,7 @@ static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts)
fdt_addr_t addr;
void *paddr;
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
addr = dev_read_addr(dev);
ut_asserteq(0x8000, addr);
@@ -728,7 +696,7 @@ static int dm_test_fdt_remap_addr_index_live(struct unit_test_state *uts)
fdt_size_t size;
void *paddr;
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
addr = dev_read_addr_size_index(dev, 0, &size);
ut_asserteq(0x8000, addr);
@@ -750,7 +718,7 @@ static int dm_test_fdt_remap_addr_name_live(struct unit_test_state *uts)
fdt_size_t size;
void *paddr;
- ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
addr = dev_read_addr_size_name(dev, "sandbox-dummy-0", &size);
ut_asserteq(0x8000, addr);
@@ -785,7 +753,7 @@ static int dm_test_fdt_livetree_writing(struct unit_test_state *uts)
device_bind_driver_to_node(dm_root(), "usb_sandbox", "usb@2", node,
&dev);
- ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 2, true, &dev));
+ ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 2, &dev));
/* Test string property setting */
@@ -1062,9 +1030,9 @@ static int dm_test_child_ofdata(struct unit_test_state *uts)
ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus));
count = 0;
- device_foreach_child_ofdata_to_platdata(dev, bus) {
- ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID);
- ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
+ device_foreach_child_of_to_plat(dev, bus) {
+ ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID);
+ ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
count++;
}
ut_asserteq(3, count);
@@ -1082,8 +1050,8 @@ static int dm_test_first_child_probe(struct unit_test_state *uts)
ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus));
count = 0;
device_foreach_child_probe(dev, bus) {
- ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID);
- ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
count++;
}
ut_asserteq(3, count);
@@ -1099,19 +1067,19 @@ static int dm_test_ofdata_order(struct unit_test_state *uts)
ut_assertok(uclass_find_first_device(UCLASS_I2C, &bus));
ut_assertnonnull(bus);
- ut_assert(!(bus->flags & DM_FLAG_PLATDATA_VALID));
+ ut_assert(!(dev_get_flags(bus) & DM_FLAG_PLATDATA_VALID));
ut_assertok(device_find_first_child(bus, &dev));
ut_assertnonnull(dev);
- ut_assert(!(dev->flags & DM_FLAG_PLATDATA_VALID));
+ ut_assert(!(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID));
/* read the child's ofdata which should cause the parent's to be read */
- ut_assertok(device_ofdata_to_platdata(dev));
- ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID);
- ut_assert(bus->flags & DM_FLAG_PLATDATA_VALID);
+ ut_assertok(device_of_to_plat(dev));
+ ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID);
+ ut_assert(dev_get_flags(bus) & DM_FLAG_PLATDATA_VALID);
- ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
- ut_assert(!(bus->flags & DM_FLAG_ACTIVATED));
+ ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
+ ut_assert(!(dev_get_flags(bus) & DM_FLAG_ACTIVATED));
return 0;
}
diff --git a/test/dm/test-main.c b/test/dm/test-main.c
index fd24635..69458d6 100644
--- a/test/dm/test-main.c
+++ b/test/dm/test-main.c
@@ -89,12 +89,12 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test,
uts->start = mallinfo();
if (test->flags & UT_TESTF_SCAN_PDATA)
- ut_assertok(dm_scan_platdata(false));
+ ut_assertok(dm_scan_plat(false));
if (test->flags & UT_TESTF_PROBE_TEST)
ut_assertok(do_autoprobe(uts));
if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
(test->flags & UT_TESTF_SCAN_FDT))
- ut_assertok(dm_extended_scan_fdt(gd->fdt_blob, false));
+ ut_assertok(dm_extended_scan(false));
/*
* Silence the console and rely on console recording to get
@@ -211,9 +211,9 @@ int dm_test_main(const char *test_name)
gd_set_of_root(uts->of_root);
gd->dm_root = NULL;
ut_assertok(dm_init(CONFIG_IS_ENABLED(OF_LIVE)));
- dm_scan_platdata(false);
+ dm_scan_plat(false);
if (!CONFIG_IS_ENABLED(OF_PLATDATA))
- dm_scan_fdt(gd->fdt_blob, false);
+ dm_scan_fdt(false);
return uts->fail_count ? CMD_RET_FAILURE : 0;
}
diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c
index 760731b..f1b7aaa 100644
--- a/test/dm/test-uclass.c
+++ b/test/dm/test-uclass.c
@@ -36,7 +36,7 @@ static int test_post_bind(struct udevice *dev)
dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++;
ut_assert(!device_active(dev));
- uc_pdata = dev_get_uclass_platdata(dev);
+ uc_pdata = dev_get_uclass_plat(dev);
ut_assert(uc_pdata);
uc_pdata->intval1 = TEST_UC_PDATA_INTVAL1;
@@ -82,7 +82,7 @@ static int test_post_probe(struct udevice *dev)
if (&prev->uclass_node != &uc->dev_head) {
struct dm_test_uclass_perdev_priv *prev_uc_priv
= dev_get_uclass_priv(prev);
- struct dm_test_pdata *pdata = prev->platdata;
+ struct dm_test_pdata *pdata = dev_get_plat(prev);
ut_assert(pdata);
ut_assert(prev_uc_priv);
@@ -102,7 +102,7 @@ static int test_pre_remove(struct udevice *dev)
static int test_init(struct uclass *uc)
{
dm_testdrv_op_count[DM_TEST_OP_INIT]++;
- ut_assert(uc->priv);
+ ut_assert(uclass_get_priv(uc));
return 0;
}
@@ -124,8 +124,7 @@ UCLASS_DRIVER(test) = {
.pre_remove = test_pre_remove,
.init = test_init,
.destroy = test_destroy,
- .priv_auto_alloc_size = sizeof(struct dm_test_uclass_priv),
- .per_device_auto_alloc_size = sizeof(struct dm_test_uclass_perdev_priv),
- .per_device_platdata_auto_alloc_size =
- sizeof(struct dm_test_perdev_uc_pdata),
+ .priv_auto = sizeof(struct dm_test_uclass_priv),
+ .per_device_auto = sizeof(struct dm_test_uclass_perdev_priv),
+ .per_device_plat_auto = sizeof(struct dm_test_perdev_uc_pdata),
};
diff --git a/test/dm/video.c b/test/dm/video.c
index 1af948d..da0ae36 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -107,7 +107,7 @@ static int select_vidconsole(struct unit_test_state *uts, const char *drv_name)
ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
ut_assert(!device_active(dev));
- plat = dev_get_platdata(dev);
+ plat = dev_get_plat(dev);
plat->vidconsole_drv_name = "vidconsole0";
return 0;
@@ -217,7 +217,7 @@ static int check_vidconsole_output(struct unit_test_state *uts, int rot,
ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
ut_assert(!device_active(dev));
- plat = dev_get_platdata(dev);
+ plat = dev_get_plat(dev);
plat->rot = rot;
ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
@@ -359,7 +359,7 @@ static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
ut_assert(!device_active(dev));
- plat = dev_get_platdata(dev);
+ plat = dev_get_plat(dev);
plat->font_size = 100;
ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
@@ -380,7 +380,7 @@ static int dm_test_video_truetype_bs(struct unit_test_state *uts)
ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
ut_assert(!device_active(dev));
- plat = dev_get_platdata(dev);
+ plat = dev_get_plat(dev);
plat->font_size = 100;
ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
diff --git a/test/dm/virtio.c b/test/dm/virtio.c
index 2e876c3..ad35598 100644
--- a/test/dm/virtio.c
+++ b/test/dm/virtio.c
@@ -122,7 +122,7 @@ static int dm_test_virtio_remove(struct unit_test_state *uts)
ut_assertok(virtio_set_status(dev, VIRTIO_CONFIG_S_DRIVER_OK));
/* check the device can be successfully removed */
- dev->flags |= DM_FLAG_ACTIVATED;
+ dev_or_flags(dev, DM_FLAG_ACTIVATED);
ut_assertok(device_remove(bus, DM_REMOVE_ACTIVE_ALL));
return 0;
diff --git a/test/env/hashtable.c b/test/env/hashtable.c
index 339cc19..70102f9 100644
--- a/test/env/hashtable.c
+++ b/test/env/hashtable.c
@@ -80,7 +80,7 @@ static int htab_create_delete(struct unit_test_state *uts,
ut_asserteq_str(key, ritem->key);
ut_asserteq_str(key, ritem->data);
- ut_asserteq(1, hdelete_r(key, htab, 0));
+ ut_asserteq(0, hdelete_r(key, htab, 0));
}
return 0;
diff --git a/test/py/tests/test_efi_capsule/capsule_defs.py b/test/py/tests/test_efi_capsule/capsule_defs.py
new file mode 100644
index 0000000..4fd6353
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/capsule_defs.py
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+# Directories
+CAPSULE_DATA_DIR = '/EFI/CapsuleTestData'
+CAPSULE_INSTALL_DIR = '/EFI/UpdateCapsule'
diff --git a/test/py/tests/test_efi_capsule/conftest.py b/test/py/tests/test_efi_capsule/conftest.py
new file mode 100644
index 0000000..6ad5608
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/conftest.py
@@ -0,0 +1,74 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2020, Linaro Limited
+# Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
+
+import os
+import os.path
+import re
+from subprocess import call, check_call, check_output, CalledProcessError
+import pytest
+from capsule_defs import *
+
+#
+# Fixture for UEFI secure boot test
+#
+
+
+@pytest.fixture(scope='session')
+def efi_capsule_data(request, u_boot_config):
+ """Set up a file system to be used in UEFI capsule test.
+
+ Args:
+ request: Pytest request object.
+ u_boot_config: U-boot configuration.
+
+ Return:
+ A path to disk image to be used for testing
+ """
+ global CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
+
+ mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
+ data_dir = mnt_point + CAPSULE_DATA_DIR
+ install_dir = mnt_point + CAPSULE_INSTALL_DIR
+ image_path = u_boot_config.persistent_data_dir + '/test_efi_capsule.img'
+
+ try:
+ # Create a target device
+ check_call('dd if=/dev/zero of=./spi.bin bs=1MiB count=16', shell=True)
+
+ check_call('rm -rf %s' % mnt_point, shell=True)
+ check_call('mkdir -p %s' % data_dir, shell=True)
+ check_call('mkdir -p %s' % install_dir, shell=True)
+
+ # Create capsule files
+ # two regions: one for u-boot.bin and the other for u-boot.env
+ check_call('cd %s; echo -n u-boot:Old > u-boot.bin.old; echo -n u-boot:New > u-boot.bin.new; echo -n u-boot-env:Old -> u-boot.env.old; echo -n u-boot-env:New > u-boot.env.new' % data_dir,
+ shell=True)
+ check_call('sed -e \"s?BINFILE1?u-boot.bin.new?\" -e \"s?BINFILE2?u-boot.env.new?\" %s/test/py/tests/test_efi_capsule/uboot_bin_env.its > %s/uboot_bin_env.its' %
+ (u_boot_config.source_dir, data_dir),
+ shell=True)
+ check_call('cd %s; %s/tools/mkimage -f uboot_bin_env.its uboot_bin_env.itb' %
+ (data_dir, u_boot_config.build_dir),
+ shell=True)
+ check_call('cd %s; %s/tools/mkeficapsule --fit uboot_bin_env.itb --index 1 Test01' %
+ (data_dir, u_boot_config.build_dir),
+ shell=True)
+ check_call('cd %s; %s/tools/mkeficapsule --raw u-boot.bin.new --index 1 Test02' %
+ (data_dir, u_boot_config.build_dir),
+ shell=True)
+
+ # Create a disk image with EFI system partition
+ check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' %
+ (mnt_point, image_path), shell=True)
+ check_call('sgdisk %s -A 1:set:0 -t 1:C12A7328-F81F-11D2-BA4B-00A0C93EC93B' %
+ image_path, shell=True)
+
+ except CalledProcessError as exception:
+ pytest.skip('Setup failed: %s' % exception.cmd)
+ return
+ else:
+ yield image_path
+ finally:
+ call('rm -rf %s' % mnt_point, shell=True)
+ call('rm -f %s' % image_path, shell=True)
+ call('rm -f ./spi.bin', shell=True)
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware.py b/test/py/tests/test_efi_capsule/test_capsule_firmware.py
new file mode 100644
index 0000000..f006fa9
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware.py
@@ -0,0 +1,241 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2020, Linaro Limited
+# Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
+#
+# U-Boot UEFI: Firmware Update Test
+
+"""
+This test verifies capsule-on-disk firmware update
+"""
+
+from subprocess import check_call, check_output, CalledProcessError
+import pytest
+from capsule_defs import *
+
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('efi_capsule_firmware_fit')
+@pytest.mark.buildconfigspec('efi_capsule_firmware_raw')
+@pytest.mark.buildconfigspec('efi_capsule_on_disk')
+@pytest.mark.buildconfigspec('dfu')
+@pytest.mark.buildconfigspec('dfu_sf')
+@pytest.mark.buildconfigspec('cmd_efidebug')
+@pytest.mark.buildconfigspec('cmd_fat')
+@pytest.mark.buildconfigspec('cmd_memory')
+@pytest.mark.buildconfigspec('cmd_nvedit_efi')
+@pytest.mark.buildconfigspec('cmd_sf')
+@pytest.mark.slow
+class TestEfiCapsuleFirmwareFit(object):
+ def test_efi_capsule_fw1(
+ self, u_boot_config, u_boot_console, efi_capsule_data):
+ """
+ Test Case 1 - Update U-Boot and U-Boot environment on SPI Flash
+ but with OsIndications unset
+ No update should happen
+ 0x100000-0x150000: U-Boot binary (but dummy)
+ 0x150000-0x200000: U-Boot environment (but dummy)
+ """
+ disk_img = efi_capsule_data
+ with u_boot_console.log.section('Test Case 1-a, before reboot'):
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % disk_img,
+ 'efidebug boot add 1 TEST host 0:1 /helloworld.efi ""',
+ 'efidebug boot order 1',
+ 'env set -e OsIndications',
+ 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
+ 'env save'])
+
+ # initialize contents
+ output = u_boot_console.run_command_list([
+ 'sf probe 0:0',
+ 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR,
+ 'sf write 4000000 100000 10',
+ 'sf read 5000000 100000 10',
+ 'md.b 5000000 10'])
+ assert 'Old' in ''.join(output)
+ output = u_boot_console.run_command_list([
+ 'sf probe 0:0',
+ 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR,
+ 'sf write 4000000 150000 10',
+ 'sf read 5000000 150000 10',
+ 'md.b 5000000 10'])
+ assert 'Old' in ''.join(output)
+
+ # place a capsule file
+ output = u_boot_console.run_command_list([
+ 'fatload host 0:1 4000000 %s/Test01' % CAPSULE_DATA_DIR,
+ 'fatwrite host 0:1 4000000 %s/Test01 $filesize' % CAPSULE_INSTALL_DIR,
+ 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+ assert 'Test01' in ''.join(output)
+
+ # reboot
+ u_boot_console.restart_uboot()
+
+ capsule_early = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_on_disk_early')
+ with u_boot_console.log.section('Test Case 1-b, after reboot'):
+ if not capsule_early:
+ # make sure that dfu_alt_info exists even persistent variables
+ # are not available.
+ output = u_boot_console.run_command_list([
+ 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
+ 'host bind 0 %s' % disk_img,
+ 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+ assert 'Test01' in ''.join(output)
+
+ # need to run uefi command to initiate capsule handling
+ output = u_boot_console.run_command(
+ 'env print -e -all Capsule0000')
+
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % disk_img,
+ 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+ assert 'Test01' in ''.join(output)
+
+ output = u_boot_console.run_command_list([
+ 'sf probe 0:0',
+ 'sf read 4000000 100000 10',
+ 'md.b 4000000 10'])
+ assert 'u-boot:Old' in ''.join(output)
+
+ output = u_boot_console.run_command_list([
+ 'sf read 4000000 150000 10',
+ 'md.b 4000000 10'])
+ assert 'u-boot-env:Old' in ''.join(output)
+
+ def test_efi_capsule_fw2(
+ self, u_boot_config, u_boot_console, efi_capsule_data):
+ """
+ Test Case 2 - Update U-Boot and U-Boot environment on SPI Flash
+ 0x100000-0x150000: U-Boot binary (but dummy)
+ 0x150000-0x200000: U-Boot environment (but dummy)
+ """
+ disk_img = efi_capsule_data
+ with u_boot_console.log.section('Test Case 2-a, before reboot'):
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % disk_img,
+ 'efidebug boot add 1 TEST host 0:1 /helloworld.efi ""',
+ 'efidebug boot order 1',
+ 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
+ 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
+ 'env save'])
+
+ # initialize contents
+ output = u_boot_console.run_command_list([
+ 'sf probe 0:0',
+ 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR,
+ 'sf write 4000000 100000 10',
+ 'sf read 5000000 100000 10',
+ 'md.b 5000000 10'])
+ assert 'Old' in ''.join(output)
+ output = u_boot_console.run_command_list([
+ 'sf probe 0:0',
+ 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR,
+ 'sf write 4000000 150000 10',
+ 'sf read 5000000 150000 10',
+ 'md.b 5000000 10'])
+ assert 'Old' in ''.join(output)
+
+ # place a capsule file
+ output = u_boot_console.run_command_list([
+ 'fatload host 0:1 4000000 %s/Test01' % CAPSULE_DATA_DIR,
+ 'fatwrite host 0:1 4000000 %s/Test01 $filesize' % CAPSULE_INSTALL_DIR,
+ 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+ assert 'Test01' in ''.join(output)
+
+ # reboot
+ u_boot_console.restart_uboot()
+
+ capsule_early = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_on_disk_early')
+ with u_boot_console.log.section('Test Case 2-b, after reboot'):
+ if not capsule_early:
+ # make sure that dfu_alt_info exists even persistent variables
+ # are not available.
+ output = u_boot_console.run_command_list([
+ 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
+ 'host bind 0 %s' % disk_img,
+ 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+ assert 'Test01' in ''.join(output)
+
+ # need to run uefi command to initiate capsule handling
+ output = u_boot_console.run_command(
+ 'env print -e -all Capsule0000')
+
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % disk_img,
+ 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+ assert 'Test01' not in ''.join(output)
+
+ output = u_boot_console.run_command_list([
+ 'sf probe 0:0',
+ 'sf read 4000000 100000 10',
+ 'md.b 4000000 10'])
+ assert 'u-boot:New' in ''.join(output)
+
+ output = u_boot_console.run_command_list([
+ 'sf read 4000000 150000 10',
+ 'md.b 4000000 10'])
+ assert 'u-boot-env:New' in ''.join(output)
+
+ def test_efi_capsule_fw3(
+ self, u_boot_config, u_boot_console, efi_capsule_data):
+ """
+ Test Case 3 - Update U-Boot on SPI Flash, raw image format
+ 0x100000-0x150000: U-Boot binary (but dummy)
+ """
+ disk_img = efi_capsule_data
+ with u_boot_console.log.section('Test Case 3-a, before reboot'):
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % disk_img,
+ 'efidebug boot add 1 TEST host 0:1 /helloworld.efi ""',
+ 'efidebug boot order 1',
+ 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
+ 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
+ 'env save'])
+
+ # initialize content
+ output = u_boot_console.run_command_list([
+ 'sf probe 0:0',
+ 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR,
+ 'sf write 4000000 100000 10',
+ 'sf read 5000000 100000 10',
+ 'md.b 5000000 10'])
+ assert 'Old' in ''.join(output)
+
+ # place a capsule file
+ output = u_boot_console.run_command_list([
+ 'fatload host 0:1 4000000 %s/Test02' % CAPSULE_DATA_DIR,
+ 'fatwrite host 0:1 4000000 %s/Test02 $filesize' % CAPSULE_INSTALL_DIR,
+ 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+ assert 'Test02' in ''.join(output)
+
+ # reboot
+ u_boot_console.restart_uboot()
+
+ capsule_early = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_on_disk_early')
+ with u_boot_console.log.section('Test Case 3-b, after reboot'):
+ if not capsule_early:
+ # make sure that dfu_alt_info exists even persistent variables
+ # are not available.
+ output = u_boot_console.run_command_list([
+ 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
+ 'host bind 0 %s' % disk_img,
+ 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+ assert 'Test02' in ''.join(output)
+
+ # need to run uefi command to initiate capsule handling
+ output = u_boot_console.run_command(
+ 'env print -e -all Capsule0000')
+
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % disk_img,
+ 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+ assert 'Test02' not in ''.join(output)
+
+ output = u_boot_console.run_command_list([
+ 'sf probe 0:0',
+ 'sf read 4000000 100000 10',
+ 'md.b 4000000 10'])
+ assert 'u-boot:New' in ''.join(output)
diff --git a/test/py/tests/test_efi_capsule/uboot_bin_env.its b/test/py/tests/test_efi_capsule/uboot_bin_env.its
new file mode 100644
index 0000000..31e2f80
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/uboot_bin_env.its
@@ -0,0 +1,36 @@
+/*
+ * Automatic software update for U-Boot
+ * Make sure the flashing addresses ('load' prop) is correct for your board!
+ */
+
+/dts-v1/;
+
+/ {
+ description = "Automatic U-Boot environment update";
+ #address-cells = <2>;
+
+ images {
+ u-boot-bin@100000 {
+ description = "U-Boot binary on SPI Flash";
+ data = /incbin/("BINFILE1");
+ compression = "none";
+ type = "firmware";
+ arch = "sandbox";
+ load = <0>;
+ hash-1 {
+ algo = "sha1";
+ };
+ };
+ u-boot-env@150000 {
+ description = "U-Boot environment on SPI Flash";
+ data = /incbin/("BINFILE2");
+ compression = "none";
+ type = "firmware";
+ arch = "sandbox";
+ load = <0>;
+ hash-1 {
+ algo = "sha1";
+ };
+ };
+ };
+};
diff --git a/test/py/tests/test_ofplatdata.py b/test/py/tests/test_ofplatdata.py
index 78837a3..d55338e 100644
--- a/test/py/tests/test_ofplatdata.py
+++ b/test/py/tests/test_ofplatdata.py
@@ -17,7 +17,6 @@ def test_spl_devicetree(u_boot_console):
assert "u-boot,dm-spl" not in output
assert "u-boot,dm-tpl" not in output
- assert "spl-test4" in output
assert "spl-test5" not in output
assert "spl-test6" not in output
assert "spl-test7" in output
diff --git a/test/py/tests/test_sandbox_exit.py b/test/py/tests/test_sandbox_exit.py
index 2d242ae..706f5fa 100644
--- a/test/py/tests/test_sandbox_exit.py
+++ b/test/py/tests/test_sandbox_exit.py
@@ -19,3 +19,27 @@ def test_ctrl_c(u_boot_console):
u_boot_console.kill(signal.SIGINT)
assert(u_boot_console.validate_exited())
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_exception')
+@pytest.mark.buildconfigspec('sandbox_crash_reset')
+def test_exception_reset(u_boot_console):
+ """Test that SIGILL causes a reset."""
+
+ u_boot_console.run_command('exception undefined', wait_for_prompt=False)
+ m = u_boot_console.p.expect(['resetting ...', 'U-Boot'])
+ if m != 0:
+ raise Exception('SIGILL did not lead to reset')
+ m = u_boot_console.p.expect(['U-Boot', '=>'])
+ if m != 0:
+ raise Exception('SIGILL did not lead to reset')
+ u_boot_console.restart_uboot()
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_exception')
+@pytest.mark.notbuildconfigspec('sandbox_crash_reset')
+def test_exception_exit(u_boot_console):
+ """Test that SIGILL causes a reset."""
+
+ u_boot_console.run_command('exception undefined', wait_for_prompt=False)
+ assert(u_boot_console.validate_exited())
diff --git a/test/unicode_ut.c b/test/unicode_ut.c
index 33fc8b0..6130ef0 100644
--- a/test/unicode_ut.c
+++ b/test/unicode_ut.c
@@ -603,7 +603,7 @@ static int unicode_test_efi_create_indexed_name(struct unit_test_state *uts)
u16 *pos;
memset(buf, 0xeb, sizeof(buf));
- pos = efi_create_indexed_name(buf, "Capsule", 0x0af9);
+ pos = efi_create_indexed_name(buf, sizeof(buf), "Capsule", 0x0af9);
ut_asserteq_mem(expected, buf, sizeof(expected));
ut_asserteq(pos - buf, u16_strnlen(buf, SIZE_MAX));