diff options
Diffstat (limited to 'test/dm')
| -rw-r--r-- | test/dm/Makefile | 1 | ||||
| -rw-r--r-- | test/dm/acpi.c | 8 | ||||
| -rw-r--r-- | test/dm/eth.c | 6 | ||||
| -rw-r--r-- | test/dm/fwu_mdata.c | 48 | ||||
| -rw-r--r-- | test/dm/part.c | 53 | ||||
| -rw-r--r-- | test/dm/phy_common_props.c | 319 | ||||
| -rw-r--r-- | test/dm/spi.c | 16 |
7 files changed, 444 insertions, 7 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile index 771b703b737..d69b0e08d66 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -88,6 +88,7 @@ obj-$(CONFIG_P2SB) += p2sb.o obj-$(CONFIG_PCI_ENDPOINT) += pci_ep.o obj-$(CONFIG_PCH) += pch.o obj-$(CONFIG_PHY) += phy.o +obj-$(CONFIG_PHY_COMMON_PROPS) += phy_common_props.o ifneq ($(CONFIG_PINMUX),) obj-$(CONFIG_PINCONF) += pinmux.o endif diff --git a/test/dm/acpi.c b/test/dm/acpi.c index 559ea269de2..2de7983f9ae 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -374,14 +374,14 @@ static int dm_test_acpi_ctx_and_base_tables(struct unit_test_state *uts) rsdt = PTR_ALIGN((void *)rsdp + sizeof(*rsdp), 16); ut_asserteq_ptr(rsdt, ctx.rsdt); ut_asserteq_mem("RSDT", rsdt->header.signature, ACPI_NAME_LEN); - ut_asserteq(sizeof(*rsdt), rsdt->header.length); - ut_assertok(table_compute_checksum(rsdt, sizeof(*rsdt))); + ut_asserteq(sizeof(struct acpi_table_header), rsdt->header.length); + ut_assertok(table_compute_checksum(rsdt, rsdt->header.length)); xsdt = PTR_ALIGN((void *)rsdt + sizeof(*rsdt), 16); ut_asserteq_ptr(xsdt, ctx.xsdt); ut_asserteq_mem("XSDT", xsdt->header.signature, ACPI_NAME_LEN); - ut_asserteq(sizeof(*xsdt), xsdt->header.length); - ut_assertok(table_compute_checksum(xsdt, sizeof(*xsdt))); + ut_asserteq(sizeof(struct acpi_table_header), xsdt->header.length); + ut_assertok(table_compute_checksum(xsdt, xsdt->header.length)); end = PTR_ALIGN((void *)xsdt + sizeof(*xsdt), 64); ut_asserteq_ptr(end, ctx.current); diff --git a/test/dm/eth.c b/test/dm/eth.c index 1087ae9572d..ed0b57d8861 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -449,7 +449,7 @@ static int dm_test_net_retry(struct unit_test_state *uts) } DM_TEST(dm_test_net_retry, UTF_SCAN_FDT); -#if CONFIG_IS_ENABLED(NET) +#if CONFIG_IS_ENABLED(NET_LEGACY) static int sb_check_arp_reply(struct udevice *dev, void *packet, unsigned int len) { @@ -517,7 +517,7 @@ static int sb_with_async_arp_handler(struct udevice *dev, void *packet, } #endif -#if CONFIG_IS_ENABLED(NET) +#if CONFIG_IS_ENABLED(NET_LEGACY) static int dm_test_eth_async_arp_reply(struct unit_test_state *uts) { net_ping_ip = string_to_ip("1.1.2.2"); @@ -537,7 +537,7 @@ static int dm_test_eth_async_arp_reply(struct unit_test_state *uts) DM_TEST(dm_test_eth_async_arp_reply, UTF_SCAN_FDT); #endif -#if CONFIG_IS_ENABLED(NET) +#if CONFIG_IS_ENABLED(NET_LEGACY) static int sb_check_ping_reply(struct udevice *dev, void *packet, unsigned int len) { diff --git a/test/dm/fwu_mdata.c b/test/dm/fwu_mdata.c index cfe543d8a23..8624ccf61f7 100644 --- a/test/dm/fwu_mdata.c +++ b/test/dm/fwu_mdata.c @@ -143,3 +143,51 @@ static int dm_test_fwu_mdata_write(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_fwu_mdata_write, UTF_SCAN_FDT); + +static int dm_test_fwu_mdata_get_image_guid(struct unit_test_state *uts) +{ + efi_guid_t image_type_guid = + EFI_GUID(0x09d7cf52, 0x0720, 0x4710, \ + 0x91, 0xd1, 0x08, 0x46, 0x9b, 0x7f, 0xe9, 0xc8); + efi_guid_t bank_0_image_guid = + EFI_GUID(0x10057a86, 0xdaf1, 0x4f93, \ + 0xba, 0x7f, 0xb1, 0x95, 0xf7, 0xfa, 0x41, 0x70); + efi_guid_t bank_1_image_guid = + EFI_GUID(0xdb62ed3e, 0x6237, 0x4fb4, \ + 0x80, 0xc4, 0x1b, 0x74, 0xd8, 0x46, 0xa8, 0xe7); + efi_guid_t wrong_image_type_guid = + EFI_GUID(0x12345678, 0x1302, 0x133f, \ + 0x18, 0x0a, 0x14, 0x05, 0x18, 0x05, 0x14, 0x0b); + struct udevice *dev; + efi_guid_t image_guid; + + ut_assertok(setup_blk_device(uts)); + ut_assertok(populate_mmc_disk_image(uts)); + ut_assertok(write_mmc_blk_device(uts)); + + /* + * Trigger lib/fwu_updates/fwu.c fwu_boottime_checks() + * to populate g_dev global pointer in that library. + */ + ut_assertok(event_notify_null(EVT_POST_PREBOOT)); + + ut_assertok(uclass_first_device_err(UCLASS_FWU_MDATA, &dev)); + + ut_assertok(fwu_init()); + + ut_assertok(fwu_mdata_get_image_guid(&image_guid, &image_type_guid, 0)); + ut_assertok(guidcmp(&image_guid, &bank_0_image_guid)); + + ut_assertok(fwu_mdata_get_image_guid(&image_guid, &image_type_guid, 1)); + ut_assertok(guidcmp(&image_guid, &bank_1_image_guid)); + + ut_asserteq(-EINVAL, fwu_mdata_get_image_guid(&image_guid, + &image_type_guid, 2)); + + ut_asserteq(-ENOENT, fwu_mdata_get_image_guid(&image_guid, + &wrong_image_type_guid, + 0)); + + return 0; +} +DM_TEST(dm_test_fwu_mdata_get_image_guid, UTF_SCAN_FDT); diff --git a/test/dm/part.c b/test/dm/part.c index caae23bd4aa..ad37d7f406f 100644 --- a/test/dm/part.c +++ b/test/dm/part.c @@ -195,3 +195,56 @@ static int dm_test_part_get_info_by_type(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_part_get_info_by_type, UTF_SCAN_PDATA | UTF_SCAN_FDT); + +static int dm_test_part_get_info_by_uuid(struct unit_test_state *uts) +{ + struct disk_partition parts[] = { + { + .start = 48, + .size = 1, + .name = "test1", + .uuid = "c5bce7a2-03f0-4d03-9048-01ff23b9d527", + }, + { + .start = 49, + .size = 1, + .name = "test2", + .uuid = "9df346e8-2c53-4cd8-b9ac-3af83f9a9b74", + }, + }; + char disk_guid[UUID_STR_LEN + 1] = + "8d60b397-1bb6-4d33-80ee-b1587d24c2f8"; + struct blk_desc *mmc_dev_desc; + struct disk_partition info; + int part, i; + + ut_asserteq(2, blk_get_device_by_str("mmc", "2", &mmc_dev_desc)); + + if (CONFIG_IS_ENABLED(RANDOM_UUID)) { + for (i = 0; i < ARRAY_SIZE(parts); i++) + gen_rand_uuid_str(parts[i].uuid, UUID_STR_FORMAT_STD); + + gen_rand_uuid_str(disk_guid, UUID_STR_FORMAT_STD); + } + + ut_assertok(gpt_restore(mmc_dev_desc, disk_guid, parts, + ARRAY_SIZE(parts))); + + for (i = 0; i < ARRAY_SIZE(parts); i++) { + part = part_get_info_by_uuid(mmc_dev_desc, parts[i].uuid, + &info); + + ut_asserteq(i + 1, part); + ut_asserteq_str(parts[i].name, info.name); + ut_asserteq(parts[i].start, info.start); + ut_asserteq(parts[i].size, info.size); + } + + part = part_get_info_by_uuid(mmc_dev_desc, + "00000000-0000-0000-0000-000000000000", + &info); + ut_assert(part < 0); + + return 0; +} +DM_TEST(dm_test_part_get_info_by_uuid, UTF_SCAN_PDATA | UTF_SCAN_FDT); diff --git a/test/dm/phy_common_props.c b/test/dm/phy_common_props.c new file mode 100644 index 00000000000..21f5042b7a0 --- /dev/null +++ b/test/dm/phy_common_props.c @@ -0,0 +1,319 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * U-Boot sandbox DM tests for PHY common props + * + * Ported from Linux KUnit test: + * linux/drivers/phy/phy-common-props-test.c + * + * Copyright 2025-2026 NXP + */ +#include <dm.h> +#include <dm/ofnode.h> +#include <dm/test.h> +#include <linux/bitops.h> +#include <linux/phy/phy-common-props.h> +#include <dt-bindings/phy/phy.h> +#include <test/test.h> +#include <test/ut.h> + +/* --- RX polarity tests -------------------------------------------------- */ + +/* Test: rx-polarity property is missing => default PHY_POL_NORMAL */ +static int dm_test_phy_common_props_rx_missing(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-missing"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_rx_polarity(node, "sgmii", &val); + ut_asserteq(0, ret); + ut_asserteq(PHY_POL_NORMAL, val); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_rx_missing, UTF_SCAN_FDT); + +/* Test: rx-polarity has more values than rx-polarity-names => -EINVAL */ +static int dm_test_phy_common_props_rx_more_values(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-more-values"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_rx_polarity(node, "sgmii", &val); + ut_asserteq(-EINVAL, ret); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_rx_more_values, UTF_SCAN_FDT); + +/* Test: rx-polarity has 1 value and rx-polarity-names does not exist */ +static int dm_test_phy_common_props_rx_single_value(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-single"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_rx_polarity(node, "sgmii", &val); + ut_asserteq(0, ret); + ut_asserteq(PHY_POL_INVERT, val); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_rx_single_value, UTF_SCAN_FDT); + +/* Test: rx-polarity-names has more values than rx-polarity => -EINVAL */ +static int dm_test_phy_common_props_rx_more_names(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-more-names"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_rx_polarity(node, "sgmii", &val); + ut_asserteq(-EINVAL, ret); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_rx_more_names, UTF_SCAN_FDT); + +/* Test: valid arrays, find polarity by mode name */ +static int dm_test_phy_common_props_rx_find_by_name(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-find-by-name"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_rx_polarity(node, "sgmii", &val); + ut_asserteq(0, ret); + ut_asserteq(PHY_POL_NORMAL, val); + + ret = phy_get_manual_rx_polarity(node, "2500base-x", &val); + ut_asserteq(0, ret); + ut_asserteq(PHY_POL_INVERT, val); + + /* "usb-ss" has PHY_POL_AUTO; auto is supported here */ + ret = phy_get_rx_polarity(node, "usb-ss", BIT(PHY_POL_AUTO), + PHY_POL_AUTO, &val); + ut_asserteq(0, ret); + ut_asserteq(PHY_POL_AUTO, val); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_rx_find_by_name, UTF_SCAN_FDT); + +/* Test: name not found, no "default" entry => -EINVAL */ +static int dm_test_phy_common_props_rx_no_default(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-no-default"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_rx_polarity(node, "sgmii", &val); + ut_asserteq(-EINVAL, ret); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_rx_no_default, UTF_SCAN_FDT); + +/* Test: name not found, "default" entry exists => use default polarity */ +static int dm_test_phy_common_props_rx_with_default(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-with-default"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_rx_polarity(node, "sgmii", &val); + ut_asserteq(0, ret); + ut_asserteq(PHY_POL_INVERT, val); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_rx_with_default, UTF_SCAN_FDT); + +/* Test: polarity value found but not in supported set => -EOPNOTSUPP */ +static int dm_test_phy_common_props_rx_unsupported(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-unsupported"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_rx_polarity(node, "sgmii", &val); + ut_asserteq(-EOPNOTSUPP, ret); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_rx_unsupported, UTF_SCAN_FDT); + +/* --- TX polarity tests -------------------------------------------------- */ + +/* Test: tx-polarity property is missing => default PHY_POL_NORMAL */ +static int dm_test_phy_common_props_tx_missing(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-missing"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_tx_polarity(node, "sgmii", &val); + ut_asserteq(0, ret); + ut_asserteq(PHY_POL_NORMAL, val); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_tx_missing, UTF_SCAN_FDT); + +/* Test: tx-polarity has more values than tx-polarity-names => -EINVAL */ +static int dm_test_phy_common_props_tx_more_values(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-more-values"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_tx_polarity(node, "sgmii", &val); + ut_asserteq(-EINVAL, ret); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_tx_more_values, UTF_SCAN_FDT); + +/* Test: tx-polarity has 1 value and tx-polarity-names does not exist */ +static int dm_test_phy_common_props_tx_single_value(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-single"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_tx_polarity(node, "sgmii", &val); + ut_asserteq(0, ret); + ut_asserteq(PHY_POL_INVERT, val); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_tx_single_value, UTF_SCAN_FDT); + +/* Test: tx-polarity-names has more values than tx-polarity => -EINVAL */ +static int dm_test_phy_common_props_tx_more_names(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-more-names"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_tx_polarity(node, "sgmii", &val); + ut_asserteq(-EINVAL, ret); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_tx_more_names, UTF_SCAN_FDT); + +/* Test: valid arrays, find polarity by mode name */ +static int dm_test_phy_common_props_tx_find_by_name(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-find-by-name"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_tx_polarity(node, "sgmii", &val); + ut_asserteq(0, ret); + ut_asserteq(PHY_POL_NORMAL, val); + + ret = phy_get_manual_tx_polarity(node, "2500base-x", &val); + ut_asserteq(0, ret); + ut_asserteq(PHY_POL_INVERT, val); + + ret = phy_get_manual_tx_polarity(node, "1000base-x", &val); + ut_asserteq(0, ret); + ut_asserteq(PHY_POL_NORMAL, val); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_tx_find_by_name, UTF_SCAN_FDT); + +/* Test: name not found, no "default" entry => -EINVAL */ +static int dm_test_phy_common_props_tx_no_default(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-no-default"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_tx_polarity(node, "sgmii", &val); + ut_asserteq(-EINVAL, ret); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_tx_no_default, UTF_SCAN_FDT); + +/* Test: name not found, "default" entry exists => use default polarity */ +static int dm_test_phy_common_props_tx_with_default(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-with-default"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_tx_polarity(node, "sgmii", &val); + ut_asserteq(0, ret); + ut_asserteq(PHY_POL_INVERT, val); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_tx_with_default, UTF_SCAN_FDT); + +/* Test: polarity value found but not in supported set => -EOPNOTSUPP */ +static int dm_test_phy_common_props_tx_unsupported(struct unit_test_state *uts) +{ + ofnode node = ofnode_path("/phy-common-props-unsupported"); + unsigned int val; + int ret; + + ut_assert(ofnode_valid(node)); + + ret = phy_get_manual_tx_polarity(node, "sgmii", &val); + ut_asserteq(-EOPNOTSUPP, ret); + + return 0; +} + +DM_TEST(dm_test_phy_common_props_tx_unsupported, UTF_SCAN_FDT); diff --git a/test/dm/spi.c b/test/dm/spi.c index 249a9238fed..a89ba06274f 100644 --- a/test/dm/spi.c +++ b/test/dm/spi.c @@ -170,6 +170,22 @@ static int dm_test_spi_claim_bus(struct unit_test_state *uts) } DM_TEST(dm_test_spi_claim_bus, UTF_SCAN_PDATA | UTF_SCAN_FDT); +static int dm_test_spi_set_wordlen(struct unit_test_state *uts) +{ + struct spi_slave *slave; + struct udevice *bus; + const int busnum = 0, cs = 0; + + ut_assertok(spi_get_bus_and_cs(busnum, cs, &bus, &slave)); + ut_assertok(spi_set_wordlen(slave, 8)); + ut_asserteq(8, sandbox_spi_get_wordlen(slave->dev)); + ut_assertok(spi_set_wordlen(slave, 9)); + ut_asserteq(9, sandbox_spi_get_wordlen(slave->dev)); + + return 0; +} +DM_TEST(dm_test_spi_set_wordlen, UTF_SCAN_PDATA | UTF_SCAN_FDT); + /* Test that sandbox SPI works correctly */ static int dm_test_spi_xfer(struct unit_test_state *uts) { |
