summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/bloblist.c21
-rw-r--r--test/dm/Makefile1
-rw-r--r--test/dm/core.c41
-rw-r--r--test/dm/efi_media.c24
-rw-r--r--test/dm/ofnode.c96
-rw-r--r--test/dm/phy.c83
-rw-r--r--test/dm/video.c189
-rw-r--r--test/py/conftest.py2
-rw-r--r--test/py/multiplexed_log.py10
-rw-r--r--test/py/tests/test_efi_selftest.py20
-rw-r--r--test/py/tests/test_env.py107
-rw-r--r--test/py/tests/test_lsblk.py1
-rw-r--r--test/py/tests/test_tpm2.py1
-rw-r--r--test/py/u_boot_utils.py5
14 files changed, 574 insertions, 27 deletions
diff --git a/test/bloblist.c b/test/bloblist.c
index b48be38dc3e..720be7e244f 100644
--- a/test/bloblist.c
+++ b/test/bloblist.c
@@ -19,9 +19,9 @@ DECLARE_GLOBAL_DATA_PTR;
UNIT_TEST(_name, _flags, bloblist_test)
enum {
- TEST_TAG = 1,
- TEST_TAG2 = 2,
- TEST_TAG_MISSING = 3,
+ TEST_TAG = BLOBLISTT_U_BOOT_SPL_HANDOFF,
+ TEST_TAG2 = BLOBLISTT_VBOOT_CTX,
+ TEST_TAG_MISSING = 0x10000,
TEST_SIZE = 10,
TEST_SIZE2 = 20,
@@ -71,7 +71,9 @@ static int bloblist_test_init(struct unit_test_state *uts)
hdr = clear_bloblist();
ut_asserteq(-ENOENT, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
+ ut_asserteq_ptr(NULL, bloblist_check_magic(TEST_ADDR));
ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0));
+ ut_asserteq_ptr(hdr, bloblist_check_magic(TEST_ADDR));
hdr->version++;
ut_asserteq(-EPROTONOSUPPORT, bloblist_check(TEST_ADDR,
TEST_BLOBLIST_SIZE));
@@ -83,6 +85,11 @@ static int bloblist_test_init(struct unit_test_state *uts)
ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
ut_assertok(bloblist_finish());
ut_assertok(bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
+
+ hdr->magic++;
+ ut_asserteq_ptr(NULL, bloblist_check_magic(TEST_ADDR));
+ hdr->magic--;
+
hdr->flags++;
ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
@@ -100,6 +107,8 @@ static int bloblist_test_blob(struct unit_test_state *uts)
hdr = clear_bloblist();
ut_assertnull(bloblist_find(TEST_TAG, TEST_BLOBLIST_SIZE));
ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0));
+ ut_asserteq(TEST_BLOBLIST_SIZE, bloblist_get_size());
+ ut_asserteq(TEST_ADDR, bloblist_get_base());
ut_asserteq(map_to_sysmem(hdr), TEST_ADDR);
/* Add a record and check that we can find it */
@@ -281,10 +290,10 @@ static int bloblist_test_cmd_list(struct unit_test_state *uts)
ut_silence_console(uts);
console_record_reset();
run_command("bloblist list", 0);
- ut_assert_nextline("Address Size Tag Name");
- ut_assert_nextline("%08lx %8x 1 EC host event",
+ ut_assert_nextline("Address Size Tag Name");
+ ut_assert_nextline("%08lx %8x 8000 SPL hand-off",
(ulong)map_to_sysmem(data), TEST_SIZE);
- ut_assert_nextline("%08lx %8x 2 SPL hand-off",
+ ut_assert_nextline("%08lx %8x 106 Chrome OS vboot context",
(ulong)map_to_sysmem(data2), TEST_SIZE2);
ut_assert_console_end();
ut_unsilence_console(uts);
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 548649f8e82..d46552fbf32 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_DMA) += dma.o
obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o
obj-$(CONFIG_DM_DSA) += dsa.o
obj-$(CONFIG_ECDSA_VERIFY) += ecdsa.o
+obj-$(CONFIG_EFI_MEDIA_SANDBOX) += efi_media.o
obj-$(CONFIG_DM_ETH) += eth.o
ifneq ($(CONFIG_EFI_PARTITION),)
obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
diff --git a/test/dm/core.c b/test/dm/core.c
index c9a7606666c..c76dfdb1651 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -307,11 +307,15 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
{
int op_count[DM_TEST_OP_COUNT];
struct udevice *dev, *test_dev;
+ int start_dev_count, start_uc_count;
+ int dev_count, uc_count;
int pingret;
int ret;
memcpy(op_count, dm_testdrv_op_count, sizeof(op_count));
+ dm_get_stats(&start_dev_count, &start_uc_count);
+
ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
&dev));
ut_assert(dev);
@@ -319,6 +323,11 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
== op_count[DM_TEST_OP_BIND] + 1);
ut_assert(!dev_get_priv(dev));
+ /* We should have one more device */
+ dm_get_stats(&dev_count, &uc_count);
+ ut_asserteq(start_dev_count + 1, dev_count);
+ ut_asserteq(start_uc_count, uc_count);
+
/* Probe the device - it should fail allocating private data */
uts->force_fail_alloc = 1;
ret = device_probe(dev);
@@ -353,6 +362,11 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_UNBIND]);
ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_PRE_UNBIND]);
+ /* We should have one less device */
+ dm_get_stats(&dev_count, &uc_count);
+ ut_asserteq(start_dev_count, dev_count);
+ ut_asserteq(start_uc_count, uc_count);
+
return 0;
}
DM_TEST(dm_test_lifecycle, UT_TESTF_SCAN_PDATA | UT_TESTF_PROBE_TEST);
@@ -526,17 +540,31 @@ DM_TEST(dm_test_leak, 0);
/* Test uclass init/destroy methods */
static int dm_test_uclass(struct unit_test_state *uts)
{
+ int dev_count, uc_count;
struct uclass *uc;
+ /* We should have just the root device and uclass */
+ dm_get_stats(&dev_count, &uc_count);
+ ut_asserteq(1, dev_count);
+ ut_asserteq(1, uc_count);
+
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(uclass_get_priv(uc));
+ dm_get_stats(&dev_count, &uc_count);
+ ut_asserteq(1, dev_count);
+ ut_asserteq(2, uc_count);
+
ut_assertok(uclass_destroy(uc));
ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_DESTROY]);
+ dm_get_stats(&dev_count, &uc_count);
+ ut_asserteq(1, dev_count);
+ ut_asserteq(1, uc_count);
+
return 0;
}
DM_TEST(dm_test_uclass, 0);
@@ -1217,3 +1245,16 @@ static int dm_test_dma_offset(struct unit_test_state *uts)
}
DM_TEST(dm_test_dma_offset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
#endif
+
+/* Test dm_get_stats() */
+static int dm_test_get_stats(struct unit_test_state *uts)
+{
+ int dev_count, uc_count;
+
+ dm_get_stats(&dev_count, &uc_count);
+ ut_assert(dev_count > 50);
+ ut_assert(uc_count > 30);
+
+ return 0;
+}
+DM_TEST(dm_test_get_stats, UT_TESTF_SCAN_FDT);
diff --git a/test/dm/efi_media.c b/test/dm/efi_media.c
new file mode 100644
index 00000000000..e343a0e9c85
--- /dev/null
+++ b/test/dm/efi_media.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for EFI_MEDIA uclass
+ *
+ * Copyright 2021 Google LLC
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+/* Test that we can use the EFI_MEDIA uclass */
+static int dm_test_efi_media(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+
+ ut_assertok(uclass_first_device_err(UCLASS_EFI_MEDIA, &dev));
+
+ return 0;
+}
+DM_TEST(dm_test_efi_media, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index cea0746bb3b..5e7c9681c79 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -351,3 +351,99 @@ static int dm_test_ofnode_for_each_compatible_node(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_ofnode_for_each_compatible_node, UT_TESTF_SCAN_FDT);
+
+static int dm_test_ofnode_string(struct unit_test_state *uts)
+{
+ const char **val;
+ const char *out;
+ ofnode node;
+
+ node = ofnode_path("/a-test");
+ ut_assert(ofnode_valid(node));
+
+ /* single string */
+ ut_asserteq(1, ofnode_read_string_count(node, "str-value"));
+ ut_assertok(ofnode_read_string_index(node, "str-value", 0, &out));
+ ut_asserteq_str("test string", out);
+ ut_asserteq(0, ofnode_stringlist_search(node, "str-value",
+ "test string"));
+ ut_asserteq(1, ofnode_read_string_list(node, "str-value", &val));
+ ut_asserteq_str("test string", val[0]);
+ ut_assertnull(val[1]);
+ free(val);
+
+ /* list of strings */
+ ut_asserteq(5, ofnode_read_string_count(node, "mux-control-names"));
+ ut_assertok(ofnode_read_string_index(node, "mux-control-names", 0,
+ &out));
+ ut_asserteq_str("mux0", out);
+ ut_asserteq(0, ofnode_stringlist_search(node, "mux-control-names",
+ "mux0"));
+ ut_asserteq(5, ofnode_read_string_list(node, "mux-control-names",
+ &val));
+ ut_asserteq_str("mux0", val[0]);
+ ut_asserteq_str("mux1", val[1]);
+ ut_asserteq_str("mux2", val[2]);
+ ut_asserteq_str("mux3", val[3]);
+ ut_asserteq_str("mux4", val[4]);
+ ut_assertnull(val[5]);
+ free(val);
+
+ ut_assertok(ofnode_read_string_index(node, "mux-control-names", 4,
+ &out));
+ ut_asserteq_str("mux4", out);
+ ut_asserteq(4, ofnode_stringlist_search(node, "mux-control-names",
+ "mux4"));
+
+ return 0;
+}
+DM_TEST(dm_test_ofnode_string, 0);
+
+static int dm_test_ofnode_string_err(struct unit_test_state *uts)
+{
+ const char **val;
+ const char *out;
+ ofnode node;
+
+ /*
+ * Test error codes only on livetree, as they are different with
+ * flattree
+ */
+ node = ofnode_path("/a-test");
+ ut_assert(ofnode_valid(node));
+
+ /* non-existent property */
+ ut_asserteq(-EINVAL, ofnode_read_string_count(node, "missing"));
+ ut_asserteq(-EINVAL, ofnode_read_string_index(node, "missing", 0,
+ &out));
+ ut_asserteq(-EINVAL, ofnode_read_string_list(node, "missing", &val));
+
+ /* empty property */
+ ut_asserteq(-ENODATA, ofnode_read_string_count(node, "bool-value"));
+ ut_asserteq(-ENODATA, ofnode_read_string_index(node, "bool-value", 0,
+ &out));
+ ut_asserteq(-ENODATA, ofnode_read_string_list(node, "bool-value",
+ &val));
+
+ /* badly formatted string list */
+ ut_asserteq(-EILSEQ, ofnode_read_string_count(node, "int64-value"));
+ ut_asserteq(-EILSEQ, ofnode_read_string_index(node, "int64-value", 0,
+ &out));
+ ut_asserteq(-EILSEQ, ofnode_read_string_list(node, "int64-value",
+ &val));
+
+ /* out of range / not found */
+ ut_asserteq(-ENODATA, ofnode_read_string_index(node, "str-value", 1,
+ &out));
+ ut_asserteq(-ENODATA, ofnode_stringlist_search(node, "str-value",
+ "other"));
+
+ /* negative value for index is not allowed, so don't test for that */
+
+ ut_asserteq(-ENODATA, ofnode_read_string_index(node,
+ "mux-control-names", 5,
+ &out));
+
+ return 0;
+}
+DM_TEST(dm_test_ofnode_string_err, UT_TESTF_LIVE_TREE);
diff --git a/test/dm/phy.c b/test/dm/phy.c
index ecbd47bf12f..df4c73fc701 100644
--- a/test/dm/phy.c
+++ b/test/dm/phy.c
@@ -79,12 +79,15 @@ static int dm_test_phy_ops(struct unit_test_state *uts)
ut_assertok(generic_phy_power_off(&phy1));
/*
- * test operations after exit().
- * The sandbox phy driver does not allow it.
+ * Test power_on() failure after exit().
+ * The sandbox phy driver does not allow power-on/off after
+ * exit, but the uclass counts power-on/init calls and skips
+ * calling the driver's ops when e.g. powering off an already
+ * powered-off phy.
*/
ut_assertok(generic_phy_exit(&phy1));
ut_assert(generic_phy_power_on(&phy1) != 0);
- ut_assert(generic_phy_power_off(&phy1) != 0);
+ ut_assertok(generic_phy_power_off(&phy1));
/*
* test normal operations again (after re-init)
@@ -99,6 +102,17 @@ static int dm_test_phy_ops(struct unit_test_state *uts)
*/
ut_assertok(generic_phy_reset(&phy1));
+ /*
+ * Test power_off() failure after exit().
+ * For this we need to call exit() while the phy is powered-on,
+ * so that the uclass actually calls the driver's power-off()
+ * and reports the resulting failure.
+ */
+ ut_assertok(generic_phy_power_on(&phy1));
+ ut_assertok(generic_phy_exit(&phy1));
+ ut_assert(generic_phy_power_off(&phy1) != 0);
+ ut_assertok(generic_phy_power_on(&phy1));
+
/* PHY2 has a known problem with power off */
ut_assertok(generic_phy_init(&phy2));
ut_assertok(generic_phy_power_on(&phy2));
@@ -106,8 +120,8 @@ static int dm_test_phy_ops(struct unit_test_state *uts)
/* PHY3 has a known problem with power off and power on */
ut_assertok(generic_phy_init(&phy3));
- ut_asserteq(-EIO, generic_phy_power_off(&phy3));
- ut_asserteq(-EIO, generic_phy_power_off(&phy3));
+ ut_asserteq(-EIO, generic_phy_power_on(&phy3));
+ ut_assertok(generic_phy_power_off(&phy3));
return 0;
}
@@ -145,3 +159,62 @@ static int dm_test_phy_bulk(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_phy_bulk, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+static int dm_test_phy_multi_exit(struct unit_test_state *uts)
+{
+ struct phy phy1_method1;
+ struct phy phy1_method2;
+ struct phy phy1_method3;
+ struct udevice *parent;
+
+ /* Get the same phy instance in 3 different ways. */
+ ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
+ "gen_phy_user", &parent));
+ ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1_method1));
+ ut_asserteq(0, phy1_method1.id);
+ ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1_method2));
+ ut_asserteq(0, phy1_method2.id);
+ ut_asserteq_ptr(phy1_method1.dev, phy1_method1.dev);
+
+ ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
+ "gen_phy_user1", &parent));
+ ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1_method3));
+ ut_asserteq(0, phy1_method3.id);
+ ut_asserteq_ptr(phy1_method1.dev, phy1_method3.dev);
+
+ /*
+ * Test using the same PHY from different handles.
+ * In non-test code these could be in different drivers.
+ */
+
+ /*
+ * These must only call the driver's ops at the first init()
+ * and power_on().
+ */
+ ut_assertok(generic_phy_init(&phy1_method1));
+ ut_assertok(generic_phy_init(&phy1_method2));
+ ut_assertok(generic_phy_power_on(&phy1_method1));
+ ut_assertok(generic_phy_power_on(&phy1_method2));
+ ut_assertok(generic_phy_init(&phy1_method3));
+ ut_assertok(generic_phy_power_on(&phy1_method3));
+
+ /*
+ * These must not call the driver's ops as other handles still
+ * want the PHY powered-on and initialized.
+ */
+ ut_assertok(generic_phy_power_off(&phy1_method3));
+ ut_assertok(generic_phy_exit(&phy1_method3));
+
+ /*
+ * We would get an error here if the generic_phy_exit() above
+ * actually called the driver's exit(), as the sandbox driver
+ * doesn't allow power-off() after exit().
+ */
+ ut_assertok(generic_phy_power_off(&phy1_method1));
+ ut_assertok(generic_phy_power_off(&phy1_method2));
+ ut_assertok(generic_phy_exit(&phy1_method1));
+ ut_assertok(generic_phy_exit(&phy1_method2));
+
+ return 0;
+}
+DM_TEST(dm_test_phy_multi_exit, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
diff --git a/test/dm/video.c b/test/dm/video.c
index da0ae3622f7..d4a3c9c6c17 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -7,12 +7,14 @@
#include <common.h>
#include <bzlib.h>
#include <dm.h>
+#include <gzip.h>
#include <log.h>
#include <malloc.h>
#include <mapmem.h>
#include <os.h>
#include <video.h>
#include <video_console.h>
+#include <asm/test.h>
#include <dm/test.h>
#include <dm/uclass-internal.h>
#include <test/test.h>
@@ -113,6 +115,31 @@ static int select_vidconsole(struct unit_test_state *uts, const char *drv_name)
return 0;
}
+/**
+ * video_get_nologo() - Disable the logo on the video device and return it
+ *
+ * @uts: Test state
+ * @devp: Returns video device
+ * @return 0 if OK, -ve on error
+ */
+static int video_get_nologo(struct unit_test_state *uts, struct udevice **devp)
+{
+ struct video_uc_plat *uc_plat;
+ struct udevice *dev;
+
+ ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+ ut_assertnonnull(dev);
+ uc_plat = dev_get_uclass_plat(dev);
+ uc_plat->hide_logo = true;
+
+ /* now probe it */
+ ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
+ ut_assertnonnull(dev);
+ *devp = dev;
+
+ return 0;
+}
+
/* Test text output works on the video console */
static int dm_test_video_text(struct unit_test_state *uts)
{
@@ -123,7 +150,7 @@ static int dm_test_video_text(struct unit_test_state *uts)
#define SCROLL_LINES 100
ut_assertok(select_vidconsole(uts, "vidconsole0"));
- ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+ ut_assertok(video_get_nologo(uts, &dev));
ut_asserteq(46, compress_frame_buffer(uts, dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
@@ -155,7 +182,7 @@ static int dm_test_video_chars(struct unit_test_state *uts)
const char *test_string = "Well\b\b\b\bxhe is\r \n\ta very \amodest \bman\n\t\tand Has much to\b\bto be modest about.";
ut_assertok(select_vidconsole(uts, "vidconsole0"));
- ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+ ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
vidconsole_put_string(con, test_string);
ut_asserteq(466, compress_frame_buffer(uts, dev));
@@ -172,7 +199,7 @@ static int dm_test_video_ansi(struct unit_test_state *uts)
struct udevice *dev, *con;
ut_assertok(select_vidconsole(uts, "vidconsole0"));
- ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+ ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
/* reference clear: */
@@ -220,7 +247,7 @@ static int check_vidconsole_output(struct unit_test_state *uts, int rot,
plat = dev_get_plat(dev);
plat->rot = rot;
- ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+ ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
ut_asserteq(46, compress_frame_buffer(uts, dev));
@@ -309,7 +336,7 @@ static int dm_test_video_bmp(struct unit_test_state *uts)
struct udevice *dev;
ulong addr;
- ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+ ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
@@ -319,13 +346,119 @@ static int dm_test_video_bmp(struct unit_test_state *uts)
}
DM_TEST(dm_test_video_bmp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+/* Test drawing a bitmap file on a 8bpp display */
+static int dm_test_video_bmp8(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ ulong addr;
+
+ ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+ ut_assertnonnull(dev);
+ ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));
+
+ ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
+
+ ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
+ ut_asserteq(1247, compress_frame_buffer(uts, dev));
+
+ return 0;
+}
+DM_TEST(dm_test_video_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test drawing a bitmap file on a 16bpp display */
+static int dm_test_video_bmp16(struct unit_test_state *uts)
+{
+ ulong src, src_len = ~0UL;
+ uint dst_len = ~0U;
+ struct udevice *dev;
+ ulong dst = 0x10000;
+
+ ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+ ut_assertnonnull(dev);
+ ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP16));
+
+ ut_assertok(read_file(uts, "tools/logos/denx-16bpp.bmp.gz", &src));
+ ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
+ &src_len));
+
+ ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
+ ut_asserteq(3700, compress_frame_buffer(uts, dev));
+
+ return 0;
+}
+DM_TEST(dm_test_video_bmp16, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test drawing a 24bpp bitmap file on a 16bpp display */
+static int dm_test_video_bmp24(struct unit_test_state *uts)
+{
+ ulong src, src_len = ~0UL;
+ uint dst_len = ~0U;
+ struct udevice *dev;
+ ulong dst = 0x10000;
+
+ ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+ ut_assertnonnull(dev);
+ ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP16));
+
+ ut_assertok(read_file(uts, "tools/logos/denx-24bpp.bmp.gz", &src));
+ ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
+ &src_len));
+
+ ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
+ ut_asserteq(3656, compress_frame_buffer(uts, dev));
+
+ return 0;
+}
+DM_TEST(dm_test_video_bmp24, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test drawing a 24bpp bitmap file on a 32bpp display */
+static int dm_test_video_bmp24_32(struct unit_test_state *uts)
+{
+ ulong src, src_len = ~0UL;
+ uint dst_len = ~0U;
+ struct udevice *dev;
+ ulong dst = 0x10000;
+
+ ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+ ut_assertnonnull(dev);
+ ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
+
+ ut_assertok(read_file(uts, "tools/logos/denx-24bpp.bmp.gz", &src));
+ ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
+ &src_len));
+
+ ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
+ ut_asserteq(6827, compress_frame_buffer(uts, dev));
+
+ return 0;
+}
+DM_TEST(dm_test_video_bmp24_32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test drawing a bitmap file on a 32bpp display */
+static int dm_test_video_bmp32(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ ulong addr;
+
+ ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+ ut_assertnonnull(dev);
+ ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
+ ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
+
+ ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
+ ut_asserteq(2024, compress_frame_buffer(uts, dev));
+
+ return 0;
+}
+DM_TEST(dm_test_video_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
/* Test drawing a compressed bitmap file */
static int dm_test_video_bmp_comp(struct unit_test_state *uts)
{
struct udevice *dev;
ulong addr;
- ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+ ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(read_file(uts, "tools/logos/denx-comp.bmp", &addr));
ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
@@ -335,13 +468,51 @@ static int dm_test_video_bmp_comp(struct unit_test_state *uts)
}
DM_TEST(dm_test_video_bmp_comp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+/* Test drawing a bitmap file on a 32bpp display */
+static int dm_test_video_comp_bmp32(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ ulong addr;
+
+ ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+ ut_assertnonnull(dev);
+ ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
+
+ ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
+
+ ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
+ ut_asserteq(2024, compress_frame_buffer(uts, dev));
+
+ return 0;
+}
+DM_TEST(dm_test_video_comp_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test drawing a bitmap file on a 8bpp display */
+static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ ulong addr;
+
+ ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+ ut_assertnonnull(dev);
+ ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));
+
+ ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
+
+ ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
+ ut_asserteq(1247, compress_frame_buffer(uts, dev));
+
+ return 0;
+}
+DM_TEST(dm_test_video_comp_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
/* Test TrueType console */
static int dm_test_video_truetype(struct unit_test_state *uts)
{
struct udevice *dev, *con;
const char *test_string = "Criticism may not be agreeable, but it is necessary. It fulfils the same function as pain in the human body. It calls attention to an unhealthy state of things. Some see private enterprise as a predatory target to be shot, others as a cow to be milked, but few are those who see it as a sturdy horse pulling the wagon. The \aprice OF\b\bof greatness\n\tis responsibility.\n\nBye";
- ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+ ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
vidconsole_put_string(con, test_string);
ut_asserteq(12237, compress_frame_buffer(uts, dev));
@@ -362,7 +533,7 @@ static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
plat = dev_get_plat(dev);
plat->font_size = 100;
- ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+ ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
vidconsole_put_string(con, test_string);
ut_asserteq(35030, compress_frame_buffer(uts, dev));
@@ -383,7 +554,7 @@ static int dm_test_video_truetype_bs(struct unit_test_state *uts)
plat = dev_get_plat(dev);
plat->font_size = 100;
- ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+ ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
vidconsole_put_string(con, test_string);
ut_asserteq(29018, compress_frame_buffer(uts, dev));
diff --git a/test/py/conftest.py b/test/py/conftest.py
index 11a3f307ea8..16e445cd8ee 100644
--- a/test/py/conftest.py
+++ b/test/py/conftest.py
@@ -226,7 +226,7 @@ def pytest_configure(config):
import u_boot_console_exec_attach
console = u_boot_console_exec_attach.ConsoleExecAttach(log, ubconfig)
-re_ut_test_list = re.compile(r'[^a-zA-Z0-9_]_u_boot_list_2_ut_(.*)_test_2_\1_test_(.*)\s*$')
+re_ut_test_list = re.compile(r'[^a-zA-Z0-9_]_u_boot_list_2_ut_(.*)_test_2_(.*)\s*$')
def generate_ut_subtest(metafunc, fixture_name, sym_path):
"""Provide parametrization for a ut_subtest fixture.
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
index 442edada125..5e79075f2e6 100644
--- a/test/py/multiplexed_log.py
+++ b/test/py/multiplexed_log.py
@@ -111,7 +111,7 @@ class RunAndLog(object):
"""Clean up any resources managed by this object."""
pass
- def run(self, cmd, cwd=None, ignore_errors=False):
+ def run(self, cmd, cwd=None, ignore_errors=False, stdin=None):
"""Run a command as a sub-process, and log the results.
The output is available at self.output which can be useful if there is
@@ -125,6 +125,7 @@ class RunAndLog(object):
function will simply return if the command cannot be executed
or exits with an error code, otherwise an exception will be
raised if such problems occur.
+ stdin: Input string to pass to the command as stdin (or None)
Returns:
The output as a string.
@@ -137,8 +138,9 @@ class RunAndLog(object):
try:
p = subprocess.Popen(cmd, cwd=cwd,
- stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- (stdout, stderr) = p.communicate()
+ stdin=subprocess.PIPE if stdin else None,
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ (stdout, stderr) = p.communicate(input=stdin)
if stdout is not None:
stdout = stdout.decode('utf-8')
if stderr is not None:
@@ -165,7 +167,7 @@ class RunAndLog(object):
if output and not output.endswith('\n'):
output += '\n'
if exit_status and not exception and not ignore_errors:
- exception = Exception('Exit code: ' + str(exit_status))
+ exception = ValueError('Exit code: ' + str(exit_status))
if exception:
output += str(exception) + '\n'
self.logfile.write(self, output)
diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py
index 0161a6ea24a..a48cd3290c2 100644
--- a/test/py/tests/test_efi_selftest.py
+++ b/test/py/tests/test_efi_selftest.py
@@ -210,3 +210,23 @@ def test_efi_selftest_text_input_ex(u_boot_console):
if m != 0:
raise Exception('Failures occurred during the EFI selftest')
u_boot_console.restart_uboot()
+
+@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
+@pytest.mark.buildconfigspec('efi_tcg2_protocol')
+def test_efi_selftest_tcg2(u_boot_console):
+ """Test the EFI_TCG2 PROTOCOL
+
+ :param u_boot_console: U-Boot console
+
+ This function executes the 'tcg2' unit test.
+ """
+ u_boot_console.restart_uboot()
+ u_boot_console.run_command(cmd='setenv efi_selftest list')
+ output = u_boot_console.run_command('bootefi selftest')
+ assert '\'tcg2\'' in output
+ u_boot_console.run_command(cmd='setenv efi_selftest tcg2')
+ u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
+ m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
+ if m != 0:
+ raise Exception('Failures occurred during the EFI selftest')
+ u_boot_console.restart_uboot()
diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py
index 9bed2f48d77..f85cb031382 100644
--- a/test/py/tests/test_env.py
+++ b/test/py/tests/test_env.py
@@ -7,6 +7,7 @@
import os
import os.path
from subprocess import call, check_call, CalledProcessError
+import tempfile
import pytest
import u_boot_utils
@@ -515,3 +516,109 @@ def test_env_ext4(state_test_env):
finally:
if fs_img:
call('rm -f %s' % fs_img, shell=True)
+
+def test_env_text(u_boot_console):
+ """Test the script that converts the environment to a text file"""
+
+ def check_script(intext, expect_val):
+ """Check a test case
+
+ Args:
+ intext: Text to pass to the script
+ expect_val: Expected value of the CONFIG_EXTRA_ENV_TEXT string, or
+ None if we expect it not to be defined
+ """
+ with tempfile.TemporaryDirectory() as path:
+ fname = os.path.join(path, 'infile')
+ with open(fname, 'w') as inf:
+ print(intext, file=inf)
+ result = u_boot_utils.run_and_log(cons, ['awk', '-f', script, fname])
+ if expect_val is not None:
+ expect = '#define CONFIG_EXTRA_ENV_TEXT "%s"\n' % expect_val
+ assert result == expect
+ else:
+ assert result == ''
+
+ cons = u_boot_console
+ script = os.path.join(cons.config.source_dir, 'scripts', 'env2string.awk')
+
+ # simple script with a single var
+ check_script('fred=123', 'fred=123\\0')
+
+ # no vars
+ check_script('', None)
+
+ # two vars
+ check_script('''fred=123
+ernie=456''', 'fred=123\\0ernie=456\\0')
+
+ # blank lines
+ check_script('''fred=123
+
+
+ernie=456
+
+''', 'fred=123\\0ernie=456\\0')
+
+ # append
+ check_script('''fred=123
+ernie=456
+fred+= 456''', 'fred=123 456\\0ernie=456\\0')
+
+ # append from empty
+ check_script('''fred=
+ernie=456
+fred+= 456''', 'fred= 456\\0ernie=456\\0')
+
+ # variable with + in it
+ check_script('fred+ernie=123', 'fred+ernie=123\\0')
+
+ # ignores variables that are empty
+ check_script('''fred=
+fred+=
+ernie=456''', 'ernie=456\\0')
+
+ # single-character env name
+ check_script('''f=123
+e=456
+f+= 456''', 'e=456\\0f=123 456\\0')
+
+ # contains quotes
+ check_script('''fred="my var"
+ernie=another"''', 'fred=\\"my var\\"\\0ernie=another\\"\\0')
+
+ # variable name ending in +
+ check_script('''fred\\+=my var
+fred++= again''', 'fred+=my var again\\0')
+
+ # variable name containing +
+ check_script('''fred+jane=both
+fred+jane+=again
+ernie=456''', 'fred+jane=bothagain\\0ernie=456\\0')
+
+ # multi-line vars - new vars always start at column 1
+ check_script('''fred=first
+ second
+\tthird with tab
+
+ after blank
+ confusing=oops
+ernie=another"''', 'fred=first second third with tab after blank confusing=oops\\0ernie=another\\"\\0')
+
+ # real-world example
+ check_script('''ubifs_boot=
+ env exists bootubipart ||
+ env set bootubipart UBI;
+ env exists bootubivol ||
+ env set bootubivol boot;
+ if ubi part ${bootubipart} &&
+ ubifsmount ubi${devnum}:${bootubivol};
+ then
+ devtype=ubi;
+ run scan_dev_for_boot;
+ fi
+''',
+ 'ubifs_boot=env exists bootubipart || env set bootubipart UBI; '
+ 'env exists bootubivol || env set bootubivol boot; '
+ 'if ubi part ${bootubipart} && ubifsmount ubi${devnum}:${bootubivol}; '
+ 'then devtype=ubi; run scan_dev_for_boot; fi\\0')
diff --git a/test/py/tests/test_lsblk.py b/test/py/tests/test_lsblk.py
index 40ffe01263e..a719a48e6ee 100644
--- a/test/py/tests/test_lsblk.py
+++ b/test/py/tests/test_lsblk.py
@@ -4,6 +4,7 @@
import pytest
+@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('blk')
@pytest.mark.buildconfigspec('cmd_lsblk')
def test_lsblk(u_boot_console):
diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py
index 7c89f5f2937..d2ad6f9e73c 100644
--- a/test/py/tests/test_tpm2.py
+++ b/test/py/tests/test_tpm2.py
@@ -186,6 +186,7 @@ def test_tpm2_change_auth(u_boot_console):
u_boot_console.run_command('tpm2 clear TPM2_RH_PLATFORM')
assert output.endswith('0')
+@pytest.mark.buildconfigspec('sandbox')
@pytest.mark.buildconfigspec('cmd_tpm_v2')
def test_tpm2_get_capability(u_boot_console):
"""Execute a TPM_GetCapability command.
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py
index 089eda5434c..c4fc23aeda3 100644
--- a/test/py/u_boot_utils.py
+++ b/test/py/u_boot_utils.py
@@ -157,7 +157,7 @@ def wait_until_file_open_fails(fn, ignore_errors):
return
raise Exception('File can still be opened')
-def run_and_log(u_boot_console, cmd, ignore_errors=False):
+def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None):
"""Run a command and log its output.
Args:
@@ -169,6 +169,7 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False):
will simply return if the command cannot be executed or exits with
an error code, otherwise an exception will be raised if such
problems occur.
+ stdin: Input string to pass to the command as stdin (or None)
Returns:
The output as a string.
@@ -176,7 +177,7 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False):
if isinstance(cmd, str):
cmd = cmd.split()
runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
- output = runner.run(cmd, ignore_errors=ignore_errors)
+ output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin)
runner.close()
return output