/* The asserts include a return on fail; cleanup in the caller */ static int _dm_test_net_retry(struct unit_test_state *uts) { /* * eth1 is disabled and netretry is yes, so the ping should succeed and * the active device should be eth0 */ sandbox_eth_disable_response(1, true); env_set("ethact", "eth@10004000"); env_set("netretry", "yes"); sandbox_eth_skip_timeout(); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10002000", env_get("ethact")); /* * eth1 is disabled and netretry is no, so the ping should fail and the * active device should be eth1 */ env_set("ethact", "eth@10004000"); env_set("netretry", "no"); sandbox_eth_skip_timeout(); ut_asserteq(-ENONET, net_loop(PING)); ut_asserteq_str("eth@10004000", env_get("ethact")); return 0; }
/* Test that we can iterate through children */ static int dm_test_bus_children_iterators(struct unit_test_state *uts) { struct udevice *bus, *dev, *child; /* Walk through the children one by one */ ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); ut_assertok(device_find_first_child(bus, &dev)); ut_asserteq_str("c-test@5", dev->name); ut_assertok(device_find_next_child(&dev)); ut_asserteq_str("c-test@0", dev->name); ut_assertok(device_find_next_child(&dev)); ut_asserteq_str("c-test@1", dev->name); ut_assertok(device_find_next_child(&dev)); ut_asserteq_ptr(dev, NULL); /* Move to the next child without using device_find_first_child() */ ut_assertok(device_find_child_by_seq(bus, 5, true, &dev)); ut_asserteq_str("c-test@5", dev->name); ut_assertok(device_find_next_child(&dev)); ut_asserteq_str("c-test@0", dev->name); /* Try a device with no children */ ut_assertok(device_find_first_child(dev, &child)); ut_asserteq_ptr(child, NULL); return 0; }
static int _dm_test_eth_rotate2(struct unit_test_state *uts) { /* Make sure we can skip invalid devices */ env_set("ethact", "eth@10004000"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10004000", env_get("ethact")); /* Make sure we can handle device name which is not eth# */ env_set("ethact", "sbe5"); ut_assertok(net_loop(PING)); ut_asserteq_str("sbe5", env_get("ethact")); return 0; }
/* The asserts include a return on fail; cleanup in the caller */ static int _dm_test_eth_rotate1(struct unit_test_state *uts) { /* Make sure that the default is to rotate to the next interface */ env_set("ethact", "eth@10004000"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10002000", env_get("ethact")); /* If ethrotate is no, then we should fail on a bad MAC */ env_set("ethact", "eth@10004000"); env_set("ethrotate", "no"); ut_asserteq(-EINVAL, net_loop(PING)); ut_asserteq_str("eth@10004000", env_get("ethact")); return 0; }
/* Test if bus childs got probed propperly*/ static int dm_test_spmi_probe(struct unit_test_state *uts) { const char *name = "spmi@0"; struct udevice *bus, *dev; ut_assertok(uclass_get_device(UCLASS_SPMI, 0, &bus)); /* Check bus name */ ut_asserteq_str(name, bus->name); /* Check that it has some devices */ ut_asserteq(device_has_children(bus), true); ut_assertok(device_find_first_child(bus, &dev)); /* There should be at least one child */ ut_assertnonnull(dev); /* Check that only PMICs are connected to the bus */ while (dev) { ut_asserteq(device_get_uclass_id(dev), UCLASS_PMIC); device_find_next_child(&dev); } return 0; }
static int dm_test_uclass_devices_find_by_name(struct unit_test_state *uts) { struct udevice *finddev; struct udevice *testdev; int findret, ret; /* * For each test device found in fdt like: "a-test", "b-test", etc., * use its name and try to find it by uclass_find_device_by_name(). * Then, on success check if: * - current 'testdev' name is equal to the returned 'finddev' name * - current 'testdev' pointer is equal to the returned 'finddev' * * We assume that, each uclass's device name is unique, so if not, then * this will fail on checking condition: testdev == finddev, since the * uclass_find_device_by_name(), returns the first device by given name. */ for (ret = uclass_find_first_device(UCLASS_TEST_FDT, &testdev); testdev; ret = uclass_find_next_device(&testdev)) { ut_assertok(ret); ut_assert(testdev); findret = uclass_find_device_by_name(UCLASS_TEST_FDT, testdev->name, &finddev); ut_assertok(findret); ut_assert(testdev); ut_asserteq_str(testdev->name, finddev->name); ut_asserteq_ptr(testdev, finddev); } return 0; }
/* Test that we can find a device by device tree offset */ static int dm_test_fdt_offset(struct unit_test_state *uts) { const void *blob = gd->fdt_blob; struct udevice *dev; int node; node = fdt_path_offset(blob, "/e-test"); ut_assert(node > 0); ut_assertok(uclass_get_device_by_of_offset(UCLASS_TEST_FDT, node, &dev)); ut_asserteq_str("e-test", dev->name); /* This node should not be bound */ node = fdt_path_offset(blob, "/junk"); ut_assert(node > 0); ut_asserteq(-ENODEV, uclass_get_device_by_of_offset(UCLASS_TEST_FDT, node, &dev)); /* This is not a top level node so should not be probed */ node = fdt_path_offset(blob, "/some-bus/c-test@5"); ut_assert(node > 0); ut_asserteq(-ENODEV, uclass_get_device_by_of_offset(UCLASS_TEST_FDT, node, &dev)); return 0; }
/* Test that we can use the swapcase device correctly */ static int dm_test_pci_swapcase(struct unit_test_state *uts) { struct udevice *emul, *swap; ulong io_addr, mem_addr; char *ptr; /* Check that asking for the device automatically fires up PCI */ ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &emul)); ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap)); ut_assert(device_active(swap)); /* First test I/O */ io_addr = dm_pci_read_bar32(swap, 0); outb(2, io_addr); ut_asserteq(2, inb(io_addr)); /* * Now test memory mapping - note we must unmap and remap to cause * the swapcase emulation to see our data and response. */ mem_addr = dm_pci_read_bar32(swap, 1); ptr = map_sysmem(mem_addr, 20); strcpy(ptr, "This is a TesT"); unmap_sysmem(ptr); ptr = map_sysmem(mem_addr, 20); ut_asserteq_str("tHIS IS A tESt", ptr); unmap_sysmem(ptr); return 0; }
static int dm_test_sysreset_get_status(struct unit_test_state *uts) { struct udevice *dev; char msg[64]; /* Device 1 is the warm sysreset device */ ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev)); ut_assertok(sysreset_get_status(dev, msg, sizeof(msg))); ut_asserteq_str("Reset Status: WARM", msg); /* Device 2 is the cold sysreset device */ ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev)); ut_assertok(sysreset_get_status(dev, msg, sizeof(msg))); ut_asserteq_str("Reset Status: COLD", msg); return 0; }
static int dm_test_eth_prime(struct unit_test_state *uts) { net_ping_ip = string_to_ip("1.1.2.2"); /* Expected to be "eth@10003000" because of ethprime variable */ env_set("ethact", NULL); env_set("ethprime", "eth5"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10003000", env_get("ethact")); /* Expected to be "eth@10002000" because it is first */ env_set("ethact", NULL); env_set("ethprime", NULL); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10002000", env_get("ethact")); return 0; }
static int dm_test_eth(struct unit_test_state *uts) { net_ping_ip = string_to_ip("1.1.2.2"); env_set("ethact", "eth@10002000"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10002000", env_get("ethact")); env_set("ethact", "eth@10003000"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10003000", env_get("ethact")); env_set("ethact", "eth@10004000"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10004000", env_get("ethact")); return 0; }
/* Test that gpio_request() copies its string */ static int dm_test_gpio_copy(struct dm_test_state *dms) { unsigned int offset, gpio; struct udevice *dev; char buf[80], name[10]; ut_assertok(gpio_lookup_name("b6", &dev, &offset, &gpio)); strcpy(name, "odd_name"); ut_assertok(gpio_request(gpio, name)); sandbox_gpio_set_direction(dev, offset, 1); sandbox_gpio_set_value(dev, offset, 1); ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b6: output: 1 [x] odd_name", buf); strcpy(name, "nothing"); ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b6: output: 1 [x] odd_name", buf); return 0; }
/* Test regulator get method */ static int dm_test_power_regulator_get(struct unit_test_state *uts) { struct dm_regulator_uclass_platdata *uc_pdata; struct udevice *dev_by_devname; struct udevice *dev_by_platname; const char *devname; const char *platname; int i; for (i = 0; i < OUTPUT_COUNT; i++) { /* * Do the test for each regulator's devname and platname, * which are related to a single device. */ devname = regulator_names[i][DEVNAME]; platname = regulator_names[i][PLATNAME]; /* * Check, that regulator_get_by_devname() function, returns * a device with the name equal to the requested one. */ ut_assertok(regulator_get_by_devname(devname, &dev_by_devname)); ut_asserteq_str(devname, dev_by_devname->name); /* * Check, that regulator_get_by_platname() function, returns * a device with the name equal to the requested one. */ ut_assertok(regulator_get_by_platname(platname, &dev_by_platname)); uc_pdata = dev_get_uclass_platdata(dev_by_platname); ut_assert(uc_pdata); ut_asserteq_str(platname, uc_pdata->name); /* * Check, that the pointers returned by both get functions, * points to the same regulator device. */ ut_asserteq_ptr(dev_by_devname, dev_by_platname); } return 0; }
/* Test PMIC get method */ static int dm_test_power_pmic_get(struct unit_test_state *uts) { const char *name = "sandbox_pmic"; struct udevice *dev; ut_assertok(pmic_get(name, &dev)); ut_assertnonnull(dev); /* Check PMIC's name */ ut_asserteq_str(name, dev->name); return 0; }
static int dm_test_eth_alias(struct unit_test_state *uts) { net_ping_ip = string_to_ip("1.1.2.2"); env_set("ethact", "eth0"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10002000", env_get("ethact")); env_set("ethact", "eth1"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10004000", env_get("ethact")); /* Expected to fail since eth2 is not defined in the device tree */ env_set("ethact", "eth2"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10002000", env_get("ethact")); env_set("ethact", "eth5"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10003000", env_get("ethact")); return 0; }
static int env_test_attrs_lookup_regex(struct unit_test_state *uts) { char attrs[32]; ut_assertok(env_attr_lookup("foo1?:bar", "foo", attrs)); ut_asserteq_str("bar", attrs); ut_assertok(env_attr_lookup("foo1?:bar", "foo1", attrs)); ut_asserteq_str("bar", attrs); ut_assertok(env_attr_lookup(".foo:bar", ".foo", attrs)); ut_asserteq_str("bar", attrs); ut_assertok(env_attr_lookup(".foo:bar", "ufoo", attrs)); ut_asserteq_str("bar", attrs); ut_assertok(env_attr_lookup("\\.foo:bar", ".foo", attrs)); ut_asserteq_str("bar", attrs); ut_asserteq(-ENOENT, env_attr_lookup("\\.foo:bar", "ufoo", attrs)); return 0; }
/* Test that sequence numbers are allocated properly */ static int dm_test_fdt_uclass_seq(struct unit_test_state *uts) { struct udevice *dev; /* A few basic santiy tests */ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 3, true, &dev)); ut_asserteq_str("b-test", dev->name); ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 8, true, &dev)); ut_asserteq_str("a-test", dev->name); ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 5, true, &dev)); ut_asserteq_ptr(NULL, dev); /* Test aliases */ ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 6, &dev)); ut_asserteq_str("e-test", dev->name); ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 7, true, &dev)); /* * Note that c-test nodes are not probed since it is not a top-level * node */ ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 3, &dev)); ut_asserteq_str("b-test", dev->name); /* * d-test wants sequence number 3 also, but it can't have it because * b-test gets it first. */ ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 2, &dev)); ut_asserteq_str("d-test", dev->name); /* d-test actually gets 0 */ ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 0, &dev)); ut_asserteq_str("d-test", dev->name); /* initially no one wants seq 1 */ ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_TEST_FDT, 1, &dev)); ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev)); ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 4, &dev)); /* But now that it is probed, we can find it */ ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 1, &dev)); ut_asserteq_str("f-test", dev->name); return 0; }
/* Test that gpio_requestf() works as expected */ static int dm_test_gpio_requestf(struct dm_test_state *dms) { unsigned int offset, gpio; struct udevice *dev; char buf[80]; ut_assertok(gpio_lookup_name("b5", &dev, &offset, &gpio)); ut_assertok(gpio_requestf(gpio, "testing %d %s", 1, "hi")); sandbox_gpio_set_direction(dev, offset, 1); sandbox_gpio_set_value(dev, offset, 1); ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b5: output: 1 [x] testing 1 hi", buf); return 0; }
static int dm_test_eth_async_ping_reply(struct unit_test_state *uts) { net_ping_ip = string_to_ip("1.1.2.2"); sandbox_eth_set_tx_handler(0, sb_with_async_ping_handler); /* Used by all of the ut_assert macros in the tx_handler */ sandbox_eth_set_priv(0, uts); env_set("ethact", "eth@10002000"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10002000", env_get("ethact")); sandbox_eth_set_tx_handler(0, NULL); return 0; }
/* Test our functions for accessing children */ static int dm_test_bus_children_funcs(struct unit_test_state *uts) { const void *blob = gd->fdt_blob; struct udevice *bus, *dev; int node; ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); /* device_get_child() */ ut_assertok(device_get_child(bus, 0, &dev)); ut_asserteq(-ENODEV, device_get_child(bus, 4, &dev)); ut_assertok(device_get_child_by_seq(bus, 5, &dev)); ut_assert(dev->flags & DM_FLAG_ACTIVATED); ut_asserteq_str("c-test@5", dev->name); /* Device with sequence number 0 should be accessible */ ut_asserteq(-ENODEV, device_find_child_by_seq(bus, -1, true, &dev)); ut_assertok(device_find_child_by_seq(bus, 0, true, &dev)); ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 0, false, &dev)); ut_assertok(device_get_child_by_seq(bus, 0, &dev)); ut_assert(dev->flags & DM_FLAG_ACTIVATED); /* There is no device with sequence number 2 */ ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, false, &dev)); ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, true, &dev)); ut_asserteq(-ENODEV, device_get_child_by_seq(bus, 2, &dev)); /* Looking for something that is not a child */ node = fdt_path_offset(blob, "/junk"); ut_asserteq(-ENODEV, device_find_child_by_of_offset(bus, node, &dev)); node = fdt_path_offset(blob, "/d-test"); ut_asserteq(-ENODEV, device_find_child_by_of_offset(bus, node, &dev)); /* Find a valid child */ node = fdt_path_offset(blob, "/some-bus/c-test@1"); ut_assertok(device_find_child_by_of_offset(bus, node, &dev)); ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); ut_assertok(device_get_child_by_of_offset(bus, node, &dev)); ut_assert(dev->flags & DM_FLAG_ACTIVATED); return 0; }
/* Test that sandbox anonymous GPIOs work correctly */ static int dm_test_gpio_anon(struct dm_test_state *dms) { unsigned int offset, gpio; struct udevice *dev; const char *name; int offset_count; /* And the anonymous bank */ ut_assertok(gpio_lookup_name("14", &dev, &offset, &gpio)); ut_asserteq_str(dev->name, "gpio_sandbox"); ut_asserteq(14, offset); ut_asserteq(14, gpio); name = gpio_get_bank_info(dev, &offset_count); ut_asserteq_ptr(NULL, name); ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT, offset_count); return 0; }
static int dm_test_uclass_devices_get_by_name(struct unit_test_state *uts) { struct udevice *finddev; struct udevice *testdev; int ret, findret; /* * For each test device found in fdt like: "a-test", "b-test", etc., * use its name and try to get it by uclass_get_device_by_name(). * On success check if: * - returned finddev' is active * - current 'testdev' name is equal to the returned 'finddev' name * - current 'testdev' pointer is equal to the returned 'finddev' * * We asserts that the 'testdev' is active on each loop entry, so we * could be sure that the 'finddev' is activated too, but for sure * we check it again. * * We assume that, each uclass's device name is unique, so if not, then * this will fail on checking condition: testdev == finddev, since the * uclass_get_device_by_name(), returns the first device by given name. */ for (ret = uclass_first_device(UCLASS_TEST_FDT, &testdev); testdev; ret = uclass_next_device(&testdev)) { ut_assertok(ret); ut_assert(testdev); ut_assert(device_active(testdev)); findret = uclass_get_device_by_name(UCLASS_TEST_FDT, testdev->name, &finddev); ut_assertok(findret); ut_assert(finddev); ut_assert(device_active(finddev)); ut_asserteq_str(testdev->name, finddev->name); ut_asserteq_ptr(testdev, finddev); } return 0; }
/* Test if it's possible to read bus directly and indirectly */ static int dm_test_spmi_access(struct unit_test_state *uts) { const char *pmic_name = "pm8916@0"; struct udevice *bus, *pmic; ut_assertok(uclass_get_device(UCLASS_SPMI, 0, &bus)); ut_assertok(device_get_child(bus, 0, &pmic)); /* Sanity check if it's proper PMIC */ ut_asserteq_str(pmic_name, pmic->name); /* Read PMIC ID reg using SPMI bus - it assumes it has slaveID == 0*/ ut_asserteq(spmi_reg_read(bus, 0, 0xC0, 0x4), 0x10); ut_asserteq(spmi_reg_read(bus, 0, 0xC0, 0x5), 0x5); /* Read ID reg via pmic interface */ ut_asserteq(pmic_reg_read(pmic, 0xC004), 0x10); ut_asserteq(pmic_reg_read(pmic, 0xC005), 0x5); return 0; }
/* Test if it's possible to access GPIO that should be in pmic */ static int dm_test_spmi_access_peripheral(struct unit_test_state *uts) { struct udevice *dev; unsigned int offset, gpio; const char *name; int offset_count; /* Get second pin of PMIC GPIO */ ut_assertok(gpio_lookup_name("spmi1", &dev, &offset, &gpio)); /* Check if PMIC is parent */ ut_asserteq(device_get_uclass_id(dev->parent), UCLASS_PMIC); /* This should be second gpio */ ut_asserteq(1, offset); name = gpio_get_bank_info(dev, &offset_count); /* Check bank name */ ut_asserteq_str("spmi", name); /* Check pin count */ ut_asserteq(4, offset_count); ut_assertok(gpio_request(gpio, "testing")); /* Try to set/clear gpio */ ut_assertok(gpio_direction_output(gpio, 0)); ut_asserteq(gpio_get_value(gpio), 0); ut_assertok(gpio_direction_output(gpio, 1)); ut_asserteq(gpio_get_value(gpio), 1); ut_assertok(gpio_direction_input(gpio)); ut_asserteq(gpio_get_value(gpio), 1); ut_assertok(gpio_free(gpio)); return 0; }
/* Test that we can find GPIOs using phandles */ static int dm_test_gpio_phandles(struct dm_test_state *dms) { struct gpio_desc desc, desc_list[8], desc_list2[8]; struct udevice *dev, *gpio_a, *gpio_b; ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev)); ut_asserteq_str("a-test", dev->name); ut_assertok(gpio_request_by_name(dev, "test-gpios", 1, &desc, 0)); ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio_a)); ut_assertok(uclass_get_device(UCLASS_GPIO, 2, &gpio_b)); ut_asserteq_str("base-gpios", gpio_a->name); ut_asserteq(true, !!device_active(gpio_a)); ut_asserteq_ptr(gpio_a, desc.dev); ut_asserteq(4, desc.offset); /* GPIOF_INPUT is the sandbox GPIO driver default */ ut_asserteq(GPIOF_INPUT, gpio_get_function(gpio_a, 4, NULL)); ut_assertok(dm_gpio_free(dev, &desc)); ut_asserteq(-ENOENT, gpio_request_by_name(dev, "test-gpios", 3, &desc, 0)); ut_asserteq_ptr(NULL, desc.dev); ut_asserteq(desc.offset, 0); ut_asserteq(-ENOENT, gpio_request_by_name(dev, "test-gpios", 5, &desc, 0)); /* Last GPIO is ignord as it comes after <0> */ ut_asserteq(3, gpio_request_list_by_name(dev, "test-gpios", desc_list, ARRAY_SIZE(desc_list), 0)); ut_asserteq(-EBUSY, gpio_request_list_by_name(dev, "test-gpios", desc_list2, ARRAY_SIZE(desc_list2), 0)); ut_assertok(gpio_free_list(dev, desc_list, 3)); ut_asserteq(3, gpio_request_list_by_name(dev, "test-gpios", desc_list, ARRAY_SIZE(desc_list), GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE)); ut_asserteq_ptr(gpio_a, desc_list[0].dev); ut_asserteq(1, desc_list[0].offset); ut_asserteq_ptr(gpio_a, desc_list[1].dev); ut_asserteq(4, desc_list[1].offset); ut_asserteq_ptr(gpio_b, desc_list[2].dev); ut_asserteq(5, desc_list[2].offset); ut_asserteq(1, dm_gpio_get_value(desc_list)); ut_assertok(gpio_free_list(dev, desc_list, 3)); ut_asserteq(6, gpio_request_list_by_name(dev, "test2-gpios", desc_list, ARRAY_SIZE(desc_list), 0)); /* This was set to output previously, so still will be */ ut_asserteq(GPIOF_OUTPUT, gpio_get_function(gpio_a, 1, NULL)); /* Active low should invert the input value */ ut_asserteq(GPIOF_INPUT, gpio_get_function(gpio_b, 6, NULL)); ut_asserteq(1, dm_gpio_get_value(&desc_list[2])); ut_asserteq(GPIOF_INPUT, gpio_get_function(gpio_b, 7, NULL)); ut_asserteq(GPIOF_OUTPUT, gpio_get_function(gpio_b, 8, NULL)); ut_asserteq(0, dm_gpio_get_value(&desc_list[4])); ut_asserteq(GPIOF_OUTPUT, gpio_get_function(gpio_b, 9, NULL)); ut_asserteq(1, dm_gpio_get_value(&desc_list[5])); return 0; }
static int env_test_attrs_lookup(struct unit_test_state *uts) { char attrs[32]; ut_assertok(env_attr_lookup("foo:bar", "foo", attrs)); ut_asserteq_str("bar", attrs); ut_assertok(env_attr_lookup(",foo:bar", "foo", attrs)); ut_asserteq_str("bar", attrs); ut_assertok(env_attr_lookup(",foo:bar,", "foo", attrs)); ut_asserteq_str("bar", attrs); ut_assertok(env_attr_lookup(" foo:bar", "foo", attrs)); ut_asserteq_str("bar", attrs); ut_assertok(env_attr_lookup("foo : bar", "foo", attrs)); ut_asserteq_str("bar", attrs); ut_assertok(env_attr_lookup(" foo: bar ", "foo", attrs)); ut_asserteq_str("bar", attrs); ut_assertok(env_attr_lookup("foo:bar ", "foo", attrs)); ut_asserteq_str("bar", attrs); ut_assertok(env_attr_lookup(",foo:bar,goo:baz", "foo", attrs)); ut_asserteq_str("bar", attrs); ut_asserteq(-ENOENT, env_attr_lookup(",,", "foo", attrs)); ut_asserteq(-ENOENT, env_attr_lookup("goo:baz", "foo", attrs)); ut_assertok(env_attr_lookup("foo:bar,foo:bat,foo:baz", "foo", attrs)); ut_asserteq_str("baz", attrs); ut_assertok(env_attr_lookup( " foo : bar , foo : bat , foot : baz ", "foo", attrs)); ut_asserteq_str("bat", attrs); ut_assertok(env_attr_lookup( " foo : bar , foo : bat , ufoo : baz ", "foo", attrs)); ut_asserteq_str("bat", attrs); ut_asserteq(-EINVAL, env_attr_lookup(NULL, "foo", attrs)); ut_asserteq(-EINVAL, env_attr_lookup("foo:bar", "foo", NULL)); return 0; }
/* Test that sandbox GPIOs work correctly */ static int dm_test_gpio(struct dm_test_state *dms) { unsigned int offset, gpio; struct dm_gpio_ops *ops; struct udevice *dev; const char *name; int offset_count; char buf[80]; /* * We expect to get 3 banks. One is anonymous (just numbered) and * comes from platdata. The other two are named a (20 gpios) * and b (10 gpios) and come from the device tree. See * test/dm/test.dts. */ ut_assertok(gpio_lookup_name("b4", &dev, &offset, &gpio)); ut_asserteq_str(dev->name, "extra-gpios"); ut_asserteq(4, offset); ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 20 + 4, gpio); name = gpio_get_bank_info(dev, &offset_count); ut_asserteq_str("b", name); ut_asserteq(10, offset_count); /* Get the operations for this device */ ops = gpio_get_ops(dev); ut_assert(ops->get_state); /* Cannot get a value until it is reserved */ ut_asserteq(-1, ops->get_value(dev, offset)); /* * Now some tests that use the 'sandbox' back door. All GPIOs * should default to input, include b4 that we are using here. */ ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b4: in: 0 [ ]", buf); /* Change it to an output */ sandbox_gpio_set_direction(dev, offset, 1); ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b4: out: 0 [ ]", buf); sandbox_gpio_set_value(dev, offset, 1); ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b4: out: 1 [ ]", buf); ut_assertok(ops->request(dev, offset, "testing")); ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b4: out: 1 [x] testing", buf); /* Change the value a bit */ ut_asserteq(1, ops->get_value(dev, offset)); ut_assertok(ops->set_value(dev, offset, 0)); ut_asserteq(0, ops->get_value(dev, offset)); ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b4: out: 0 [x] testing", buf); ut_assertok(ops->set_value(dev, offset, 1)); ut_asserteq(1, ops->get_value(dev, offset)); /* Make it an input */ ut_assertok(ops->direction_input(dev, offset)); ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b4: in: 1 [x] testing", buf); sandbox_gpio_set_value(dev, offset, 0); ut_asserteq(0, sandbox_gpio_get_value(dev, offset)); ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b4: in: 0 [x] testing", buf); ut_assertok(ops->free(dev, offset)); ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b4: in: 0 [ ]", buf); /* Check the 'a' bank also */ ut_assertok(gpio_lookup_name("a15", &dev, &offset, &gpio)); ut_asserteq_str(dev->name, "base-gpios"); ut_asserteq(15, offset); ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 15, gpio); name = gpio_get_bank_info(dev, &offset_count); ut_asserteq_str("a", name); ut_asserteq(20, offset_count); /* And the anonymous bank */ ut_assertok(gpio_lookup_name("14", &dev, &offset, &gpio)); ut_asserteq_str(dev->name, "gpio_sandbox"); ut_asserteq(14, offset); ut_asserteq(14, gpio); name = gpio_get_bank_info(dev, &offset_count); ut_asserteq_ptr(NULL, name); ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT, offset_count); return 0; }