diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/cmd/test_echo.c | 2 | ||||
-rw-r--r-- | test/dm/Makefile | 1 | ||||
-rw-r--r-- | test/dm/qfw.c | 42 | ||||
-rw-r--r-- | test/dm/scmi.c | 129 | ||||
-rw-r--r-- | test/lib/Makefile | 1 | ||||
-rw-r--r-- | test/lib/strlcat.c | 126 | ||||
-rw-r--r-- | test/py/tests/test_qfw.py | 26 |
7 files changed, 291 insertions, 36 deletions
diff --git a/test/cmd/test_echo.c b/test/cmd/test_echo.c index 9d60d7d1a0b..091e4f823c9 100644 --- a/test/cmd/test_echo.c +++ b/test/cmd/test_echo.c @@ -34,6 +34,8 @@ static struct test_data echo_data[] = { */ {"setenv jQx X; echo \"a)\" ${jQx} 'b)' '${jQx}' c) ${jQx}; setenv jQx", "a) X b) ${jQx} c) X"}, + /* Test shell variable assignments without substitutions */ + {"foo=bar echo baz", "baz"}, /* Test handling of shell variables. */ {"setenv jQx; for jQx in 1 2 3; do echo -n \"${jQx}, \"; done; echo;", "1, 2, 3, "}, diff --git a/test/dm/Makefile b/test/dm/Makefile index f5cc5540e8a..d54abb73413 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -98,5 +98,6 @@ endif ifneq ($(CONFIG_EFI_PARTITION),) obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o endif +obj-$(CONFIG_QFW) += qfw.o endif endif # !SPL diff --git a/test/dm/qfw.c b/test/dm/qfw.c new file mode 100644 index 00000000000..f3f35689830 --- /dev/null +++ b/test/dm/qfw.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2021 Asherah Connor <ashe@kivikakk.ee> + */ + +#include <common.h> +#include <qfw.h> +#include <dm.h> +#include <asm/test.h> +#include <dm/test.h> +#include <test/ut.h> + +/* + * Exercise the device enough to be satisfied the initialisation and DMA + * interfaces work. + */ + +static int dm_test_qfw_cpus(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_first_device_err(UCLASS_QFW, &dev)); + ut_asserteq(5, qfw_online_cpus(dev)); + + return 0; +} + +DM_TEST(dm_test_qfw_cpus, UT_TESTF_SCAN_PDATA); + +static int dm_test_qfw_firmware_list(struct unit_test_state *uts) +{ + struct udevice *dev; + struct fw_file *file; + + ut_assertok(uclass_first_device_err(UCLASS_QFW, &dev)); + ut_assertok(qfw_read_firmware_list(dev)); + ut_assertok_ptr((file = qfw_find_file(dev, "test-one"))); + + return 0; +} + +DM_TEST(dm_test_qfw_firmware_list, UT_TESTF_SCAN_PDATA); diff --git a/test/dm/scmi.c b/test/dm/scmi.c index be60b44b3b0..c938e6d4fc0 100644 --- a/test/dm/scmi.c +++ b/test/dm/scmi.c @@ -20,6 +20,7 @@ #include <dm/device-internal.h> #include <dm/test.h> #include <linux/kconfig.h> +#include <power/regulator.h> #include <test/ut.h> static int ut_assert_scmi_state_preprobe(struct unit_test_state *uts) @@ -38,30 +39,35 @@ static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts, { struct sandbox_scmi_devices *scmi_devices; struct sandbox_scmi_service *scmi_ctx; + struct sandbox_scmi_agent *agent0; + struct sandbox_scmi_agent *agent1; /* Device references to check context against test sequence */ scmi_devices = sandbox_scmi_devices_ctx(dev); ut_assertnonnull(scmi_devices); - if (IS_ENABLED(CONFIG_CLK_SCMI)) - ut_asserteq(3, scmi_devices->clk_count); - if (IS_ENABLED(CONFIG_RESET_SCMI)) - ut_asserteq(1, scmi_devices->reset_count); + ut_asserteq(3, scmi_devices->clk_count); + ut_asserteq(1, scmi_devices->reset_count); + ut_asserteq(2, scmi_devices->regul_count); /* State of the simulated SCMI server exposed */ scmi_ctx = sandbox_scmi_service_ctx(); + agent0 = scmi_ctx->agent[0]; + agent1 = scmi_ctx->agent[1]; ut_asserteq(2, scmi_ctx->agent_count); - ut_assertnonnull(scmi_ctx->agent[0]); - ut_asserteq(2, scmi_ctx->agent[0]->clk_count); - ut_assertnonnull(scmi_ctx->agent[0]->clk); - ut_asserteq(1, scmi_ctx->agent[0]->reset_count); - ut_assertnonnull(scmi_ctx->agent[0]->reset); + ut_assertnonnull(agent0); + ut_asserteq(2, agent0->clk_count); + ut_assertnonnull(agent0->clk); + ut_asserteq(1, agent0->reset_count); + ut_assertnonnull(agent0->reset); + ut_asserteq(2, agent0->voltd_count); + ut_assertnonnull(agent0->voltd); - ut_assertnonnull(scmi_ctx->agent[1]); - ut_assertnonnull(scmi_ctx->agent[1]->clk); - ut_asserteq(1, scmi_ctx->agent[1]->clk_count); + ut_assertnonnull(agent1); + ut_assertnonnull(agent1->clk); + ut_asserteq(1, agent1->clk_count); return 0; } @@ -106,26 +112,26 @@ static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts) return ret; } - DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT); static int dm_test_scmi_clocks(struct unit_test_state *uts) { struct sandbox_scmi_devices *scmi_devices; struct sandbox_scmi_service *scmi_ctx; + struct sandbox_scmi_agent *agent0; + struct sandbox_scmi_agent *agent1; struct udevice *dev = NULL; int ret_dev; int ret; - if (!IS_ENABLED(CONFIG_CLK_SCMI)) - return 0; - ret = load_sandbox_scmi_test_devices(uts, &dev); if (ret) return ret; scmi_devices = sandbox_scmi_devices_ctx(dev); scmi_ctx = sandbox_scmi_service_ctx(); + agent0 = scmi_ctx->agent[0]; + agent1 = scmi_ctx->agent[1]; /* Test SCMI clocks rate manipulation */ ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0])); @@ -135,9 +141,9 @@ static int dm_test_scmi_clocks(struct unit_test_state *uts) ret_dev = clk_set_rate(&scmi_devices->clk[1], 1088); ut_assert(!ret_dev || ret_dev == 1088); - ut_asserteq(1000, scmi_ctx->agent[0]->clk[0].rate); - ut_asserteq(1088, scmi_ctx->agent[0]->clk[1].rate); - ut_asserteq(44, scmi_ctx->agent[1]->clk[0].rate); + ut_asserteq(1000, agent0->clk[0].rate); + ut_asserteq(1088, agent0->clk[1].rate); + ut_asserteq(44, agent1->clk[0].rate); ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0])); ut_asserteq(1088, clk_get_rate(&scmi_devices->clk[1])); @@ -148,56 +154,107 @@ static int dm_test_scmi_clocks(struct unit_test_state *uts) ut_assert(!ret_dev || ret_dev == 333); /* Test SCMI clocks gating manipulation */ - ut_assert(!scmi_ctx->agent[0]->clk[0].enabled); - ut_assert(!scmi_ctx->agent[0]->clk[1].enabled); - ut_assert(!scmi_ctx->agent[1]->clk[0].enabled); + ut_assert(!agent0->clk[0].enabled); + ut_assert(!agent0->clk[1].enabled); + ut_assert(!agent1->clk[0].enabled); ut_asserteq(0, clk_enable(&scmi_devices->clk[1])); ut_asserteq(0, clk_enable(&scmi_devices->clk[2])); - ut_assert(!scmi_ctx->agent[0]->clk[0].enabled); - ut_assert(scmi_ctx->agent[0]->clk[1].enabled); - ut_assert(scmi_ctx->agent[1]->clk[0].enabled); + ut_assert(!agent0->clk[0].enabled); + ut_assert(agent0->clk[1].enabled); + ut_assert(agent1->clk[0].enabled); ut_assertok(clk_disable(&scmi_devices->clk[1])); ut_assertok(clk_disable(&scmi_devices->clk[2])); - ut_assert(!scmi_ctx->agent[0]->clk[0].enabled); - ut_assert(!scmi_ctx->agent[0]->clk[1].enabled); - ut_assert(!scmi_ctx->agent[1]->clk[0].enabled); + ut_assert(!agent0->clk[0].enabled); + ut_assert(!agent0->clk[1].enabled); + ut_assert(!agent1->clk[0].enabled); return release_sandbox_scmi_test_devices(uts, dev); } - DM_TEST(dm_test_scmi_clocks, UT_TESTF_SCAN_FDT); static int dm_test_scmi_resets(struct unit_test_state *uts) { struct sandbox_scmi_devices *scmi_devices; struct sandbox_scmi_service *scmi_ctx; + struct sandbox_scmi_agent *agent0; struct udevice *dev = NULL; int ret; - if (!IS_ENABLED(CONFIG_RESET_SCMI)) - return 0; - ret = load_sandbox_scmi_test_devices(uts, &dev); if (ret) return ret; scmi_devices = sandbox_scmi_devices_ctx(dev); scmi_ctx = sandbox_scmi_service_ctx(); + agent0 = scmi_ctx->agent[0]; /* Test SCMI resect controller manipulation */ - ut_assert(!scmi_ctx->agent[0]->reset[0].asserted) + ut_assert(!agent0->reset[0].asserted) ut_assertok(reset_assert(&scmi_devices->reset[0])); - ut_assert(scmi_ctx->agent[0]->reset[0].asserted) + ut_assert(agent0->reset[0].asserted) ut_assertok(reset_deassert(&scmi_devices->reset[0])); - ut_assert(!scmi_ctx->agent[0]->reset[0].asserted); + ut_assert(!agent0->reset[0].asserted); return release_sandbox_scmi_test_devices(uts, dev); } - DM_TEST(dm_test_scmi_resets, UT_TESTF_SCAN_FDT); + +static int dm_test_scmi_voltage_domains(struct unit_test_state *uts) +{ + struct sandbox_scmi_devices *scmi_devices; + struct sandbox_scmi_service *scmi_ctx; + struct sandbox_scmi_agent *agent0; + struct dm_regulator_uclass_plat *uc_pdata; + struct udevice *dev; + struct udevice *regul0_dev; + + ut_assertok(load_sandbox_scmi_test_devices(uts, &dev)); + + scmi_devices = sandbox_scmi_devices_ctx(dev); + scmi_ctx = sandbox_scmi_service_ctx(); + agent0 = scmi_ctx->agent[0]; + + /* Set/Get an SCMI voltage domain level */ + regul0_dev = scmi_devices->regul[0]; + ut_assert(regul0_dev); + + uc_pdata = dev_get_uclass_plat(regul0_dev); + ut_assert(uc_pdata); + + ut_assertok(regulator_set_value(regul0_dev, uc_pdata->min_uV)); + ut_asserteq(agent0->voltd[0].voltage_uv, uc_pdata->min_uV); + + ut_assert(regulator_get_value(regul0_dev) == uc_pdata->min_uV); + + ut_assertok(regulator_set_value(regul0_dev, uc_pdata->max_uV)); + ut_asserteq(agent0->voltd[0].voltage_uv, uc_pdata->max_uV); + + ut_assert(regulator_get_value(regul0_dev) == uc_pdata->max_uV); + + /* Enable/disable SCMI voltage domains */ + ut_assertok(regulator_set_enable(scmi_devices->regul[0], false)); + ut_assertok(regulator_set_enable(scmi_devices->regul[1], false)); + ut_assert(!agent0->voltd[0].enabled); + ut_assert(!agent0->voltd[1].enabled); + + ut_assertok(regulator_set_enable(scmi_devices->regul[0], true)); + ut_assert(agent0->voltd[0].enabled); + ut_assert(!agent0->voltd[1].enabled); + + ut_assertok(regulator_set_enable(scmi_devices->regul[1], true)); + ut_assert(agent0->voltd[0].enabled); + ut_assert(agent0->voltd[1].enabled); + + ut_assertok(regulator_set_enable(scmi_devices->regul[0], false)); + ut_assert(!agent0->voltd[0].enabled); + ut_assert(agent0->voltd[1].enabled); + + return release_sandbox_scmi_test_devices(uts, dev); +} +DM_TEST(dm_test_scmi_voltage_domains, UT_TESTF_SCAN_FDT); diff --git a/test/lib/Makefile b/test/lib/Makefile index a30f615aa9c..aa2e66bc7f4 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -11,6 +11,7 @@ obj-y += longjmp.o obj-$(CONFIG_CONSOLE_RECORD) += test_print.o obj-$(CONFIG_SSCANF) += sscanf.o obj-y += string.o +obj-y += strlcat.o obj-$(CONFIG_ERRNO_STR) += test_errno_str.o obj-$(CONFIG_UT_LIB_ASN1) += asn1.o obj-$(CONFIG_UT_LIB_RSA) += rsa.o diff --git a/test/lib/strlcat.c b/test/lib/strlcat.c new file mode 100644 index 00000000000..ee61684c405 --- /dev/null +++ b/test/lib/strlcat.c @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.1+ +/* + * Copyright (C) 2021 Sean Anderson <seanga2@gmail.com> + * Copyright (C) 2011-2021 Free Software Foundation, Inc. + * + * These tests adapted from glibc's string/test-strncat.c + */ + +#include <common.h> +#include <test/lib.h> +#include <test/test.h> +#include <test/ut.h> + +#define BUF_SIZE 4096 +char buf1[BUF_SIZE], buf2[BUF_SIZE]; + +static int do_test_strlcat(struct unit_test_state *uts, int line, size_t align1, + size_t align2, size_t len1, size_t len2, size_t n) +{ + char *s1, *s2; + size_t i, len, expected, actual; + + align1 &= 7; + if (align1 + len1 >= BUF_SIZE) + return 0; + if (align1 + n > BUF_SIZE) + return 0; + + align2 &= 7; + if (align2 + len1 + len2 >= BUF_SIZE) + return 0; + if (align2 + len1 + n > BUF_SIZE) + return 0; + + s1 = buf1 + align1; + s2 = buf2 + align2; + + for (i = 0; i < len1 - 1; i++) + s1[i] = 32 + 23 * i % (127 - 32); + s1[len1 - 1] = '\0'; + + for (i = 0; i < len2 - 1; i++) + s2[i] = 32 + 23 * i % (127 - 32); + s2[len2 - 1] = '\0'; + + expected = len2 < n ? min(len1 + len2 - 1, n) : n; + actual = strlcat(s2, s1, n); + if (expected != actual) { + ut_failf(uts, __FILE__, line, __func__, + "strlcat(s2, s1, 2) == len2 < n ? min(len1 + len2, n) : n", + "Expected %#lx (%ld), got %#lx (%ld)", + expected, expected, actual, actual); + return CMD_RET_FAILURE; + } + + len = min3(len1, n - len2, (size_t)0); + if (memcmp(s2 + len2, s1, len)) { + ut_failf(uts, __FILE__, line, __func__, + "s2 + len1 == s1", + "Expected \"%.*s\", got \"%.*s\"", + (int)len, s1, (int)len, s2 + len2); + return CMD_RET_FAILURE; + } + + i = min(n, len1 + len2 - 1) - 1; + if (len2 < n && s2[i] != '\0') { + ut_failf(uts, __FILE__, line, __func__, + "n < len1 && s2[len2 + n] == '\\0'", + "Expected s2[%ld] = '\\0', got %d ('%c')", + i, s2[i], s2[i]); + return CMD_RET_FAILURE; + } + + return 0; +} + +#define test_strlcat(align1, align2, len1, len2, n) do { \ + int ret = do_test_strlcat(uts, __LINE__, align1, align2, len1, len2, \ + n); \ + if (ret) \ + return ret; \ +} while (0) + +static int lib_test_strlcat(struct unit_test_state *uts) +{ + size_t i, n; + + test_strlcat(0, 2, 2, 2, SIZE_MAX); + test_strlcat(0, 0, 4, 4, SIZE_MAX); + test_strlcat(4, 0, 4, 4, SIZE_MAX); + test_strlcat(0, 0, 8, 8, SIZE_MAX); + test_strlcat(0, 8, 8, 8, SIZE_MAX); + + for (i = 1; i < 8; i++) { + test_strlcat(0, 0, 8 << i, 8 << i, SIZE_MAX); + test_strlcat(8 - i, 2 * i, 8 << i, 8 << i, SIZE_MAX); + test_strlcat(0, 0, 8 << i, 2 << i, SIZE_MAX); + test_strlcat(8 - i, 2 * i, 8 << i, 2 << i, SIZE_MAX); + + test_strlcat(i, 2 * i, 8 << i, 1, SIZE_MAX); + test_strlcat(2 * i, i, 8 << i, 1, SIZE_MAX); + test_strlcat(i, i, 8 << i, 10, SIZE_MAX); + } + + for (n = 2; n <= 2048; n *= 4) { + test_strlcat(0, 2, 2, 2, n); + test_strlcat(0, 0, 4, 4, n); + test_strlcat(4, 0, 4, 4, n); + test_strlcat(0, 0, 8, 8, n); + test_strlcat(0, 8, 8, 8, n); + + for (i = 1; i < 8; i++) { + test_strlcat(0, 0, 8 << i, 8 << i, n); + test_strlcat(8 - i, 2 * i, 8 << i, 8 << i, n); + test_strlcat(0, 0, 8 << i, 2 << i, n); + test_strlcat(8 - i, 2 * i, 8 << i, 2 << i, n); + + test_strlcat(i, 2 * i, 8 << i, 1, n); + test_strlcat(2 * i, i, 8 << i, 1, n); + test_strlcat(i, i, 8 << i, 10, n); + } + } + + return 0; +} +LIB_TEST(lib_test_strlcat, 0); diff --git a/test/py/tests/test_qfw.py b/test/py/tests/test_qfw.py new file mode 100644 index 00000000000..8b668c9721a --- /dev/null +++ b/test/py/tests/test_qfw.py @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2021, Asherah Connor <ashe@kivikakk.ee> + +# Test qfw command implementation + +import pytest + +@pytest.mark.buildconfigspec('cmd_qfw') +def test_qfw_cpus(u_boot_console): + "Test QEMU firmware config reports the CPU count." + + output = u_boot_console.run_command('qfw cpus') + # The actual number varies depending on the board under test, so only + # assert a non-zero output. + assert 'cpu(s) online' in output + assert '0 cpu(s) online' not in output + +@pytest.mark.buildconfigspec('cmd_qfw') +def test_qfw_list(u_boot_console): + "Test QEMU firmware config lists devices." + + output = u_boot_console.run_command('qfw list') + # Assert either: + # 1) 'test-one', from the sandbox driver, or + # 2) 'bootorder', found in every real QEMU implementation. + assert ("bootorder" in output) or ("test-one" in output) |