summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/cmd/setexpr.c84
-rw-r--r--test/common/test_autoboot.c6
-rw-r--r--test/dm/core.c14
-rw-r--r--test/dm/of_platdata.c7
-rw-r--r--test/py/tests/test_fs/test_squashfs/sqfs_common.py2
-rw-r--r--test/py/tests/test_tpm2.py18
-rw-r--r--test/str_ut.c97
7 files changed, 223 insertions, 5 deletions
diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c
index 08b6e6e724..0dc94f7e61 100644
--- a/test/cmd/setexpr.c
+++ b/test/cmd/setexpr.c
@@ -386,6 +386,90 @@ static int setexpr_test_str_long(struct unit_test_state *uts)
}
SETEXPR_TEST(setexpr_test_str_long, UT_TESTF_CONSOLE_REC);
+#ifdef CONFIG_CMD_SETEXPR_FMT
+/* Test 'setexpr' command with simply setting integers */
+static int setexpr_test_fmt(struct unit_test_state *uts)
+{
+ u8 *buf;
+
+ buf = map_sysmem(0, BUF_SIZE);
+ memset(buf, '\xff', BUF_SIZE);
+
+ /* Test decimal conversion */
+ ut_assertok(run_command("setexpr fred fmt %d 0xff", 0));
+ ut_asserteq_str("255", env_get("fred"));
+ /* Test hexadecimal conversion with 0x prefix and 4 digits */
+ ut_assertok(run_command("setexpr fred fmt 0x%04x 257", 0));
+ ut_asserteq_str("0x0257", env_get("fred"));
+ /* Test octal conversion with % prefix */
+ ut_assertok(run_command("setexpr fred fmt %%%o 8", 0));
+ ut_asserteq_str("%10", env_get("fred"));
+ /* Test argument surrounded by %% */
+ ut_assertok(run_command("setexpr fred fmt %%%x%% 0xff", 0));
+ ut_asserteq_str("%ff%", env_get("fred"));
+ /* Test escape sequence */
+ ut_assertok(run_command("setexpr fred fmt \"hello\\040world\"", 0));
+ ut_asserteq_str("hello world", env_get("fred"));
+ /* Test %b with string containing octal escape sequence */
+ ut_assertok(run_command("setexpr fred fmt oh%bno \137", 0));
+ ut_asserteq_str("oh_no", env_get("fred"));
+ /* Test %b with string containing \c escape sequence */
+ ut_assertok(run_command("setexpr fred fmt hello%bworld \"\\c\"", 0));
+ ut_asserteq_str("hello", env_get("fred"));
+ /* Test multiple arguments referencing environment varialbes */
+ ut_assertok(run_command("setenv a eff", 0));
+ ut_assertok(run_command("setenv b hello", 0));
+ ut_assertok(run_command("setenv c 0x63", 0));
+ ut_assertok(run_command("setenv d world", 0));
+ ut_assertok(run_command("setexpr fred fmt \"0x%08x-%s-%d-%s\" $a $b $c $d", 0));
+ ut_asserteq_str("0x00000eff-hello-99-world", env_get("fred"));
+ /* Test with two format specifiers, but only one argument */
+ ut_assertok(run_command("setexpr fred fmt %d_%x 100", 0));
+ ut_asserteq_str("256_0", env_get("fred"));
+ /* Test maximum string length */
+ ut_assertok(run_command("setexpr fred fmt \"%0127d\" 7b", 0));
+ ut_asserteq_str("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000123", env_get("fred"));
+ /* Test maximum unsigned integer size */
+ ut_assertok(run_command("setexpr fred fmt %u ffffffffffffffff", 0));
+ ut_asserteq_str("18446744073709551615", env_get("fred"));
+ /* Test maximum positive integer size */
+ ut_assertok(run_command("setexpr fred fmt %d 7fffffffffffffff", 0));
+ ut_asserteq_str("9223372036854775807", env_get("fred"));
+ /* Test maximum negative integer size */
+ ut_assertok(run_command("setexpr fred fmt %d 8000000000000000", 0));
+ ut_asserteq_str("-9223372036854775808", env_get("fred"));
+ /* Test minimum negative integer size */
+ ut_assertok(run_command("setexpr fred fmt %d ffffffffffffffff", 0));
+ ut_asserteq_str("-1", env_get("fred"));
+ /* Test signed value with + sign */
+ ut_assertok(run_command("setexpr fred fmt %d +5", 0));
+ ut_asserteq_str("5", env_get("fred"));
+ /* Test signed value with - sign */
+ ut_assertok(run_command("setexpr fred fmt %d -4", 0));
+ ut_asserteq_str("-4", env_get("fred"));
+ /* Test unsigned value with + sign */
+ ut_assertok(run_command("setexpr fred fmt %u +3", 0));
+ ut_asserteq_str("3", env_get("fred"));
+ /* Test unsigned value with - sign */
+ ut_assertok(run_command("setexpr fred fmt %x -2", 0));
+ ut_asserteq_str("fffffffffffffffe", env_get("fred"));
+ /* Error test with missing format specifier */
+ ut_asserteq(1, run_command("setexpr fred fmd hello 0xff", 0));
+ /* Error test with invalid format type */
+ ut_asserteq(1, run_command("setexpr fred fmt %a 0xff", 0));
+ /* Error test with incomplete format specifier */
+ ut_asserteq(1, run_command("setexpr fred fmt hello% bf", 0));
+ /* Error exceeding maximum string length */
+ ut_asserteq(1, run_command("setexpr fred fmt \"%0128d\" 456", 0));
+
+ unmap_sysmem(buf);
+
+ return 0;
+}
+
+SETEXPR_TEST(setexpr_test_fmt, UT_TESTF_CONSOLE_REC);
+#endif
+
int do_ut_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
struct unit_test *tests = UNIT_TEST_SUITE_START(setexpr_test);
diff --git a/test/common/test_autoboot.c b/test/common/test_autoboot.c
index 6564ac7049..42a1e4ab1f 100644
--- a/test/common/test_autoboot.c
+++ b/test/common/test_autoboot.c
@@ -16,13 +16,19 @@
static int check_for_input(struct unit_test_state *uts, const char *in,
bool correct)
{
+ bool old_val;
/* The bootdelay is set to 1 second in test_autoboot() */
const char *autoboot_prompt =
"Enter password \"a\" in 1 seconds to stop autoboot";
console_record_reset_enable();
console_in_puts(in);
+
+ /* turn on keyed autoboot for the test, if possible */
+ old_val = autoboot_set_keyed(true);
autoboot_command("echo Autoboot password unlock not successful");
+ old_val = autoboot_set_keyed(old_val);
+
ut_assert_nextline(autoboot_prompt);
if (!correct)
ut_assert_nextline("Autoboot password unlock not successful");
diff --git a/test/dm/core.c b/test/dm/core.c
index 0492698997..48e66b7333 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -177,6 +177,20 @@ 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);
+/* compare node names ignoring the unit address */
+static int dm_test_compare_node_name(struct unit_test_state *uts)
+{
+ ofnode node;
+
+ node = ofnode_path("/mmio-bus@0");
+ ut_assert(ofnode_valid(node));
+ ut_assert(ofnode_name_eq(node, "mmio-bus"));
+
+ return 0;
+}
+
+DM_TEST(dm_test_compare_node_name, UT_TESTF_SCAN_PDATA);
+
/* Test that binding with uclass plat setting occurs correctly */
static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts)
{
diff --git a/test/dm/of_platdata.c b/test/dm/of_platdata.c
index 0f89c7a7da..0463cf0b43 100644
--- a/test/dm/of_platdata.c
+++ b/test/dm/of_platdata.c
@@ -35,12 +35,13 @@ static int dm_test_of_plat_props(struct unit_test_state *uts)
plat = dev_get_plat(dev);
ut_assert(plat->boolval);
ut_asserteq(1, plat->intval);
- ut_asserteq(4, ARRAY_SIZE(plat->intarray));
+ ut_asserteq(3, ARRAY_SIZE(plat->intarray));
ut_asserteq(2, plat->intarray[0]);
ut_asserteq(3, plat->intarray[1]);
ut_asserteq(4, plat->intarray[2]);
- ut_asserteq(0, plat->intarray[3]);
ut_asserteq(5, plat->byteval);
+ ut_asserteq(1, ARRAY_SIZE(plat->maybe_empty_int));
+ ut_asserteq(0, plat->maybe_empty_int[0]);
ut_asserteq(3, ARRAY_SIZE(plat->bytearray));
ut_asserteq(6, plat->bytearray[0]);
ut_asserteq(0, plat->bytearray[1]);
@@ -61,7 +62,6 @@ static int dm_test_of_plat_props(struct unit_test_state *uts)
ut_asserteq(5, plat->intarray[0]);
ut_asserteq(0, plat->intarray[1]);
ut_asserteq(0, plat->intarray[2]);
- ut_asserteq(0, plat->intarray[3]);
ut_asserteq(8, plat->byteval);
ut_asserteq(3, ARRAY_SIZE(plat->bytearray));
ut_asserteq(1, plat->bytearray[0]);
@@ -80,6 +80,7 @@ static int dm_test_of_plat_props(struct unit_test_state *uts)
ut_asserteq_str("one", plat->stringarray[0]);
ut_asserteq_str("", plat->stringarray[1]);
ut_asserteq_str("", plat->stringarray[2]);
+ ut_asserteq(1, plat->maybe_empty_int[0]);
ut_assertok(uclass_next_device_err(&dev));
plat = dev_get_plat(dev);
diff --git a/test/py/tests/test_fs/test_squashfs/sqfs_common.py b/test/py/tests/test_fs/test_squashfs/sqfs_common.py
index 267c4b57d1..8b84c2cdca 100644
--- a/test/py/tests/test_fs/test_squashfs/sqfs_common.py
+++ b/test/py/tests/test_fs/test_squashfs/sqfs_common.py
@@ -146,7 +146,7 @@ def get_mksquashfs_version():
out = subprocess.run(['mksquashfs -version'], shell=True, check=True,
capture_output=True, text=True)
# 'out' is: mksquashfs version X (yyyy/mm/dd) ...
- return float(out.stdout.split()[2])
+ return float(out.stdout.split()[2].split('-')[0])
def check_mksquashfs_version():
""" Checks if mksquashfs meets the required version. """
diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py
index 70f906da51..ac04f7191e 100644
--- a/test/py/tests/test_tpm2.py
+++ b/test/py/tests/test_tpm2.py
@@ -216,7 +216,9 @@ def test_tpm2_pcr_extend(u_boot_console):
output = u_boot_console.run_command('echo $?')
assert output.endswith('0')
- read_pcr = u_boot_console.run_command('tpm2 pcr_read 0 0x%x' % ram)
+ # Read the value back into a different place so we can still use 'ram' as
+ # our zero bytes
+ read_pcr = u_boot_console.run_command('tpm2 pcr_read 0 0x%x' % (ram + 0x20))
output = u_boot_console.run_command('echo $?')
assert output.endswith('0')
assert 'f5 a5 fd 42 d1 6a 20 30 27 98 ef 6e d3 09 97 9b' in read_pcr
@@ -226,6 +228,20 @@ def test_tpm2_pcr_extend(u_boot_console):
new_updates = int(re.findall(r'\d+', str)[0])
assert (updates + 1) == new_updates
+ u_boot_console.run_command('tpm2 pcr_extend 0 0x%x' % ram)
+ output = u_boot_console.run_command('echo $?')
+ assert output.endswith('0')
+
+ read_pcr = u_boot_console.run_command('tpm2 pcr_read 0 0x%x' % (ram + 0x20))
+ output = u_boot_console.run_command('echo $?')
+ assert output.endswith('0')
+ assert '7a 05 01 f5 95 7b df 9c b3 a8 ff 49 66 f0 22 65' in read_pcr
+ assert 'f9 68 65 8b 7a 9c 62 64 2c ba 11 65 e8 66 42 f5' in read_pcr
+
+ str = re.findall(r'\d+ known updates', read_pcr)[0]
+ new_updates = int(re.findall(r'\d+', str)[0])
+ assert (updates + 2) == new_updates
+
@pytest.mark.buildconfigspec('cmd_tpm_v2')
def test_tpm2_cleanup(u_boot_console):
"""Ensure the TPM is cleared from password or test related configuration."""
diff --git a/test/str_ut.c b/test/str_ut.c
index 359d7d4ea1..d2840d5152 100644
--- a/test/str_ut.c
+++ b/test/str_ut.c
@@ -15,6 +15,10 @@
static const char str1[] = "I'm sorry I'm late.";
static const char str2[] = "1099abNo, don't bother apologising.";
static const char str3[] = "0xbI'm sorry you're alive.";
+static const char str4[] = "1234567890123 I lost closer friends";
+static const char str5[] = "0x9876543210the last time I was deloused";
+static const char str6[] = "0778octal is seldom used";
+static const char str7[] = "707it is a piece of computing history";
/* Declare a new str test */
#define STR_TEST(_name, _flags) UNIT_TEST(_name, _flags, str_test)
@@ -84,6 +88,12 @@ static int str_simple_strtoul(struct unit_test_state *uts)
/* Base 10 and base 16 */
ut_assertok(run_strtoul(uts, str2, 10, 1099, 4, upper));
ut_assertok(run_strtoul(uts, str2, 16, 0x1099ab, 6, upper));
+ ut_assertok(run_strtoul(uts, str3, 16, 0xb, 3, upper));
+ ut_assertok(run_strtoul(uts, str3, 10, 0xb, 3, upper));
+
+ /* Octal */
+ ut_assertok(run_strtoul(uts, str6, 0, 63, 3, upper));
+ ut_assertok(run_strtoul(uts, str7, 8, 0x1c7, 3, upper));
/* Invalid string */
ut_assertok(run_strtoul(uts, str1, 10, 0, 0, upper));
@@ -105,6 +115,93 @@ static int str_simple_strtoul(struct unit_test_state *uts)
}
STR_TEST(str_simple_strtoul, 0);
+static int run_strtoull(struct unit_test_state *uts, const char *str, int base,
+ unsigned long long expect_val, int expect_endp_offset,
+ bool upper)
+{
+ char out[TEST_STR_SIZE];
+ char *endp;
+ unsigned long long val;
+
+ strcpy(out, str);
+ if (upper)
+ str_to_upper(out, out, -1);
+
+ val = simple_strtoull(out, &endp, base);
+ ut_asserteq(expect_val, val);
+ ut_asserteq(expect_endp_offset, endp - out);
+
+ return 0;
+}
+
+static int str_simple_strtoull(struct unit_test_state *uts)
+{
+ int upper;
+
+ /* Check that it is case-insentive */
+ for (upper = 0; upper < 2; upper++) {
+ /* Base 10 and base 16 */
+ ut_assertok(run_strtoull(uts, str2, 10, 1099, 4, upper));
+ ut_assertok(run_strtoull(uts, str2, 16, 0x1099ab, 6, upper));
+ ut_assertok(run_strtoull(uts, str3, 16, 0xb, 3, upper));
+ ut_assertok(run_strtoull(uts, str3, 10, 0xb, 3, upper));
+
+ /* Octal */
+ ut_assertok(run_strtoull(uts, str6, 0, 63, 3, upper));
+ ut_assertok(run_strtoull(uts, str7, 8, 0x1c7, 3, upper));
+
+ /* Large values */
+ ut_assertok(run_strtoull(uts, str4, 10, 1234567890123, 13,
+ upper));
+ ut_assertok(run_strtoull(uts, str4, 16, 0x1234567890123, 13,
+ upper));
+ ut_assertok(run_strtoull(uts, str5, 0, 0x9876543210, 12,
+ upper));
+
+ /* Invalid string */
+ ut_assertok(run_strtoull(uts, str1, 10, 0, 0, upper));
+
+ /* Base 0 */
+ ut_assertok(run_strtoull(uts, str1, 0, 0, 0, upper));
+ ut_assertok(run_strtoull(uts, str2, 0, 1099, 4, upper));
+ ut_assertok(run_strtoull(uts, str3, 0, 0xb, 3, upper));
+
+ /* Base 2 */
+ ut_assertok(run_strtoull(uts, str1, 2, 0, 0, upper));
+ ut_assertok(run_strtoull(uts, str2, 2, 2, 2, upper));
+ }
+
+ /* Check endp being NULL */
+ ut_asserteq(1099, simple_strtoull(str2, NULL, 0));
+
+ return 0;
+}
+STR_TEST(str_simple_strtoull, 0);
+
+static int str_hextoul(struct unit_test_state *uts)
+{
+ char *endp;
+
+ /* Just a simple test, since we know this uses simple_strtoul() */
+ ut_asserteq(0x1099ab, hextoul(str2, &endp));
+ ut_asserteq(6, endp - str2);
+
+ return 0;
+}
+STR_TEST(str_hextoul, 0);
+
+static int str_dectoul(struct unit_test_state *uts)
+{
+ char *endp;
+
+ /* Just a simple test, since we know this uses simple_strtoul() */
+ ut_asserteq(1099, dectoul(str2, &endp));
+ ut_asserteq(4, endp - str2);
+
+ return 0;
+}
+STR_TEST(str_dectoul, 0);
+
int do_ut_str(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
struct unit_test *tests = UNIT_TEST_SUITE_START(str_test);