summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2020-02-11 10:58:41 -0500
committerTom Rini <trini@konsulko.com>2020-02-11 10:58:41 -0500
commit9a8942b53d57149754e0dfc975e0d92d1afd4087 (patch)
treede55e5352f3a8a79c413c0b8cb533428e5476841 /test
parentae347120eed8204b1fdf018ddf79131964e57016 (diff)
parent21d651fb29cf268b1a5f64d080e3d352ee32c87f (diff)
Merge tag 'dm-pull-6feb20' of https://gitlab.denx.de/u-boot/custodians/u-boot-dm
sandbox conversion to SDL2 TPM TEE driver Various minor sandbox video enhancements New driver model core utility functions
Diffstat (limited to 'test')
-rw-r--r--test/bloblist.c61
-rw-r--r--test/dm/clk.c1
-rw-r--r--test/dm/devres.c1
-rw-r--r--test/dm/dma.c1
-rw-r--r--test/dm/gpio.c1
-rw-r--r--test/dm/mailbox.c1
-rw-r--r--test/dm/ofnode.c55
-rw-r--r--test/dm/power-domain.c1
-rw-r--r--test/dm/regmap.c1
-rw-r--r--test/dm/reset.c1
-rw-r--r--test/dm/sound.c1
-rw-r--r--test/dm/spmi.c1
-rw-r--r--test/dm/syscon.c1
-rw-r--r--test/dm/tee.c1
-rw-r--r--test/dm/test-fdt.c39
-rw-r--r--test/dm/test-main.c4
-rw-r--r--test/dm/video.c1
-rw-r--r--test/lib/lmb.c1
-rw-r--r--test/unicode_ut.c1
-rw-r--r--test/ut.c46
20 files changed, 216 insertions, 4 deletions
diff --git a/test/bloblist.c b/test/bloblist.c
index d0f7296e0d..bdcca0291c 100644
--- a/test/bloblist.c
+++ b/test/bloblist.c
@@ -24,6 +24,7 @@ enum {
TEST_SIZE = 10,
TEST_SIZE2 = 20,
+ TEST_SIZE_LARGE = 0xe0,
TEST_ADDR = CONFIG_BLOBLIST_ADDR,
TEST_BLOBLIST_SIZE = 0x100,
@@ -33,13 +34,31 @@ static struct bloblist_hdr *clear_bloblist(void)
{
struct bloblist_hdr *hdr;
- /* Clear out any existing bloblist so we have a clean slate */
+ /*
+ * Clear out any existing bloblist so we have a clean slate. Zero the
+ * header so that existing records are removed, but set everything else
+ * to 0xff for testing purposes.
+ */
hdr = map_sysmem(CONFIG_BLOBLIST_ADDR, TEST_BLOBLIST_SIZE);
- memset(hdr, '\0', TEST_BLOBLIST_SIZE);
+ memset(hdr, '\xff', TEST_BLOBLIST_SIZE);
+ memset(hdr, '\0', sizeof(*hdr));
return hdr;
}
+static int check_zero(void *data, int size)
+{
+ u8 *ptr;
+ int i;
+
+ for (ptr = data, i = 0; i < size; i++, ptr++) {
+ if (*ptr)
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int bloblist_test_init(struct unit_test_state *uts)
{
struct bloblist_hdr *hdr;
@@ -83,10 +102,14 @@ static int bloblist_test_blob(struct unit_test_state *uts)
data = bloblist_find(TEST_TAG, TEST_SIZE);
ut_asserteq_ptr(rec + 1, data);
+ /* Check the data is zeroed */
+ ut_assertok(check_zero(data, TEST_SIZE));
+
/* Check the 'ensure' method */
ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE));
ut_assertnull(bloblist_ensure(TEST_TAG, TEST_SIZE2));
rec2 = (struct bloblist_rec *)(data + ALIGN(TEST_SIZE, BLOBLIST_ALIGN));
+ ut_assertok(check_zero(data, TEST_SIZE));
/* Check for a non-existent record */
ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE));
@@ -97,6 +120,40 @@ static int bloblist_test_blob(struct unit_test_state *uts)
}
BLOBLIST_TEST(bloblist_test_blob, 0);
+/* Check bloblist_ensure_size_ret() */
+static int bloblist_test_blob_ensure(struct unit_test_state *uts)
+{
+ void *data, *data2;
+ int size;
+
+ /* At the start there should be no records */
+ clear_bloblist();
+ ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0));
+
+ /* Test with an empty bloblist */
+ size = TEST_SIZE;
+ ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data));
+ ut_asserteq(TEST_SIZE, size);
+ ut_assertok(check_zero(data, TEST_SIZE));
+
+ /* Check that we get the same thing again */
+ ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data2));
+ ut_asserteq(TEST_SIZE, size);
+ ut_asserteq_ptr(data, data2);
+
+ /* Check that the size remains the same */
+ size = TEST_SIZE2;
+ ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data));
+ ut_asserteq(TEST_SIZE, size);
+
+ /* Check running out of space */
+ size = TEST_SIZE_LARGE;
+ ut_asserteq(-ENOSPC, bloblist_ensure_size_ret(TEST_TAG2, &size, &data));
+
+ return 0;
+}
+BLOBLIST_TEST(bloblist_test_blob_ensure, 0);
+
static int bloblist_test_bad_blob(struct unit_test_state *uts)
{
struct bloblist_hdr *hdr;
diff --git a/test/dm/clk.c b/test/dm/clk.c
index 31335a543f..003b78934f 100644
--- a/test/dm/clk.c
+++ b/test/dm/clk.c
@@ -6,6 +6,7 @@
#include <common.h>
#include <clk.h>
#include <dm.h>
+#include <malloc.h>
#include <asm/clk.h>
#include <dm/test.h>
#include <dm/device-internal.h>
diff --git a/test/dm/devres.c b/test/dm/devres.c
index e7331897de..cbd0972c9b 100644
--- a/test/dm/devres.c
+++ b/test/dm/devres.c
@@ -10,6 +10,7 @@
#include <dm.h>
#include <malloc.h>
#include <dm/device-internal.h>
+#include <dm/devres.h>
#include <dm/test.h>
#include <dm/uclass-internal.h>
#include <test/ut.h>
diff --git a/test/dm/dma.c b/test/dm/dma.c
index b56d17731d..12cba57a56 100644
--- a/test/dm/dma.c
+++ b/test/dm/dma.c
@@ -8,6 +8,7 @@
#include <common.h>
#include <dm.h>
+#include <malloc.h>
#include <dm/test.h>
#include <dma.h>
#include <test/ut.h>
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index bb4b20cea9..349123a657 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -6,6 +6,7 @@
#include <common.h>
#include <fdtdec.h>
#include <dm.h>
+#include <malloc.h>
#include <dm/root.h>
#include <dm/test.h>
#include <dm/util.h>
diff --git a/test/dm/mailbox.c b/test/dm/mailbox.c
index 4562d2ac4f..e6c521b8b5 100644
--- a/test/dm/mailbox.c
+++ b/test/dm/mailbox.c
@@ -5,6 +5,7 @@
#include <common.h>
#include <dm.h>
+#include <malloc.h>
#include <dm/test.h>
#include <asm/mbox.h>
#include <test/ut.h>
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index 745de50c7b..1c49eaf38b 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -58,3 +58,58 @@ static int dm_test_ofnode_fmap(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_ofnode_read(struct unit_test_state *uts)
+{
+ const u32 *val;
+ ofnode node;
+ int size;
+
+ node = ofnode_path("/a-test");
+ ut_assert(ofnode_valid(node));
+
+ val = ofnode_read_prop(node, "int-value", &size);
+ ut_assertnonnull(val);
+ ut_asserteq(4, size);
+ ut_asserteq(1234, fdt32_to_cpu(val[0]));
+
+ val = ofnode_read_prop(node, "missing", &size);
+ ut_assertnull(val);
+ ut_asserteq(-FDT_ERR_NOTFOUND, size);
+
+ /* Check it works without a size parameter */
+ val = ofnode_read_prop(node, "missing", NULL);
+ ut_assertnull(val);
+
+ return 0;
+}
+DM_TEST(dm_test_ofnode_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_ofnode_read_chosen(struct unit_test_state *uts)
+{
+ const char *str;
+ const u32 *val;
+ ofnode node;
+ int size;
+
+ str = ofnode_read_chosen_string("setting");
+ ut_assertnonnull(str);
+ ut_asserteq_str("sunrise ohoka", str);
+ ut_asserteq_ptr(NULL, ofnode_read_chosen_string("no-setting"));
+
+ node = ofnode_get_chosen_node("other-node");
+ ut_assert(ofnode_valid(node));
+ ut_asserteq_str("c-test@5", ofnode_get_name(node));
+
+ node = ofnode_get_chosen_node("setting");
+ ut_assert(!ofnode_valid(node));
+
+ val = ofnode_read_chosen_prop("int-values", &size);
+ ut_assertnonnull(val);
+ ut_asserteq(8, size);
+ ut_asserteq(0x1937, fdt32_to_cpu(val[0]));
+ ut_asserteq(72993, fdt32_to_cpu(val[1]));
+
+ return 0;
+}
+DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/power-domain.c b/test/dm/power-domain.c
index 48318218a9..8baf5d09d1 100644
--- a/test/dm/power-domain.c
+++ b/test/dm/power-domain.c
@@ -5,6 +5,7 @@
#include <common.h>
#include <dm.h>
+#include <malloc.h>
#include <dm/test.h>
#include <asm/power-domain.h>
#include <test/ut.h>
diff --git a/test/dm/regmap.c b/test/dm/regmap.c
index 6fd1f20656..b21f66732b 100644
--- a/test/dm/regmap.c
+++ b/test/dm/regmap.c
@@ -10,6 +10,7 @@
#include <syscon.h>
#include <asm/test.h>
#include <dm/test.h>
+#include <linux/err.h>
#include <test/ut.h>
/* Base test of register maps */
diff --git a/test/dm/reset.c b/test/dm/reset.c
index c61daed490..8370820428 100644
--- a/test/dm/reset.c
+++ b/test/dm/reset.c
@@ -5,6 +5,7 @@
#include <common.h>
#include <dm.h>
+#include <malloc.h>
#include <reset.h>
#include <dm/test.h>
#include <asm/reset.h>
diff --git a/test/dm/sound.c b/test/dm/sound.c
index 3767abbd1c..aa5368f05b 100644
--- a/test/dm/sound.c
+++ b/test/dm/sound.c
@@ -28,6 +28,7 @@ static int dm_test_sound(struct unit_test_state *uts)
ut_asserteq(4560, sandbox_get_sound_sum(dev));
ut_assertok(sound_beep(dev, 1, 100));
ut_asserteq(9120, sandbox_get_sound_sum(dev));
+ ut_asserteq(false, sandbox_get_sound_active(dev));
return 0;
}
diff --git a/test/dm/spmi.c b/test/dm/spmi.c
index e6a910859e..668b7e133f 100644
--- a/test/dm/spmi.c
+++ b/test/dm/spmi.c
@@ -6,6 +6,7 @@
#include <common.h>
#include <fdtdec.h>
#include <dm.h>
+#include <malloc.h>
#include <dm/device.h>
#include <dm/root.h>
#include <dm/test.h>
diff --git a/test/dm/syscon.c b/test/dm/syscon.c
index 0ff9da7ec6..f1021f374b 100644
--- a/test/dm/syscon.c
+++ b/test/dm/syscon.c
@@ -9,6 +9,7 @@
#include <regmap.h>
#include <asm/test.h>
#include <dm/test.h>
+#include <linux/err.h>
#include <test/ut.h>
/* Base test of system controllers */
diff --git a/test/dm/tee.c b/test/dm/tee.c
index 22f05a4219..d40f13d291 100644
--- a/test/dm/tee.c
+++ b/test/dm/tee.c
@@ -5,6 +5,7 @@
#include <common.h>
#include <dm.h>
+#include <malloc.h>
#include <dm/test.h>
#include <sandboxtee.h>
#include <tee.h>
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 698ca0e7cf..75ae08081c 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -12,6 +12,7 @@
#include <dm/test.h>
#include <dm/root.h>
#include <dm/device-internal.h>
+#include <dm/devres.h>
#include <dm/uclass-internal.h>
#include <dm/util.h>
#include <dm/lists.h>
@@ -914,3 +915,41 @@ static int dm_test_uclass_drvdata(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_uclass_drvdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test device_first_child_ofdata_err(), etc. */
+static int dm_test_child_ofdata(struct unit_test_state *uts)
+{
+ struct udevice *bus, *dev;
+ int count;
+
+ 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));
+ count++;
+ }
+ ut_asserteq(3, count);
+
+ return 0;
+}
+DM_TEST(dm_test_child_ofdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test device_first_child_err(), etc. */
+static int dm_test_first_child_probe(struct unit_test_state *uts)
+{
+ struct udevice *bus, *dev;
+ int count;
+
+ 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);
+ count++;
+ }
+ ut_asserteq(3, count);
+
+ return 0;
+}
+DM_TEST(dm_test_first_child_probe, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/test-main.c b/test/dm/test-main.c
index 72648162a9..d7dc8d1f91 100644
--- a/test/dm/test-main.c
+++ b/test/dm/test-main.c
@@ -97,11 +97,11 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test,
* Silence the console and rely on console recording to get
* our output.
*/
- console_record_reset();
+ console_record_reset_enable();
if (!state->show_test_output)
gd->flags |= GD_FLG_SILENT;
test->func(uts);
- gd->flags &= ~GD_FLG_SILENT;
+ gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
state_set_skip_delays(false);
ut_assertok(dm_test_destroy(uts));
diff --git a/test/dm/video.c b/test/dm/video.c
index 3151ebb73f..f72979fac4 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -7,6 +7,7 @@
#include <common.h>
#include <bzlib.h>
#include <dm.h>
+#include <malloc.h>
#include <mapmem.h>
#include <os.h>
#include <video.h>
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index ec68227bb6..1336b54b11 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -5,6 +5,7 @@
#include <common.h>
#include <lmb.h>
+#include <malloc.h>
#include <dm/test.h>
#include <test/ut.h>
diff --git a/test/unicode_ut.c b/test/unicode_ut.c
index 47532a64df..4d99c20bc0 100644
--- a/test/unicode_ut.c
+++ b/test/unicode_ut.c
@@ -9,6 +9,7 @@
#include <charset.h>
#include <command.h>
#include <errno.h>
+#include <malloc.h>
#include <test/test.h>
#include <test/suites.h>
#include <test/ut.h>
diff --git a/test/ut.c b/test/ut.c
index 265da4a0d8..c64f0b554d 100644
--- a/test/ut.c
+++ b/test/ut.c
@@ -6,6 +6,7 @@
*/
#include <common.h>
+#include <console.h>
#include <malloc.h>
#include <test/test.h>
#include <test/ut.h>
@@ -46,3 +47,48 @@ long ut_check_delta(ulong last)
return ut_check_free() - last;
}
+int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args);
+ va_end(args);
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+
+ return strcmp(uts->expect_str, uts->actual_str);
+}
+
+int ut_check_console_end(struct unit_test_state *uts)
+{
+ if (!console_record_avail())
+ return 0;
+
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+
+ return 1;
+}
+
+int ut_check_console_dump(struct unit_test_state *uts, int total_bytes)
+{
+ char *str = uts->actual_str;
+ int upto;
+
+ /* Handle empty dump */
+ if (!total_bytes)
+ return 0;
+
+ for (upto = 0; upto < total_bytes;) {
+ int len;
+ int bytes;
+
+ len = console_record_readline(str, sizeof(uts->actual_str));
+ if (str[8] != ':' || str[9] != ' ')
+ return 1;
+
+ bytes = len - 8 - 2 - 3 * 16 - 4;
+ upto += bytes;
+ }
+
+ return upto == total_bytes ? 0 : 1;
+}