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; }
/** * This test case is trying to test the following scenario: * - All ethernet devices are not probed * - "ethaddr" for all ethernet devices are not set * - "ethact" is set to a valid ethernet device name * * With Sandbox default test configuration, all ethernet devices are * probed after power-up, so we have to manually create such scenario: * - Remove all ethernet devices * - Remove all "ethaddr" environment variables * - Set "ethact" to the first ethernet device * * Do a ping test to see if anything goes wrong. */ static int dm_test_eth_act(struct unit_test_state *uts) { struct udevice *dev[DM_TEST_ETH_NUM]; const char *ethname[DM_TEST_ETH_NUM] = {"eth@10002000", "eth@10003000", "sbe5", "eth@10004000"}; const char *addrname[DM_TEST_ETH_NUM] = {"ethaddr", "eth5addr", "eth3addr", "eth1addr"}; char ethaddr[DM_TEST_ETH_NUM][18]; int i; memset(ethaddr, '\0', sizeof(ethaddr)); net_ping_ip = string_to_ip("1.1.2.2"); /* Prepare the test scenario */ for (i = 0; i < DM_TEST_ETH_NUM; i++) { ut_assertok(uclass_find_device_by_name(UCLASS_ETH, ethname[i], &dev[i])); ut_assertok(device_remove(dev[i], DM_REMOVE_NORMAL)); /* Invalidate MAC address */ strncpy(ethaddr[i], env_get(addrname[i]), 17); /* Must disable access protection for ethaddr before clearing */ env_set(".flags", addrname[i]); env_set(addrname[i], NULL); } /* Set ethact to "eth@10002000" */ env_set("ethact", ethname[0]); /* Segment fault might happen if something is wrong */ ut_asserteq(-ENODEV, net_loop(PING)); for (i = 0; i < DM_TEST_ETH_NUM; i++) { /* Restore the env */ env_set(".flags", addrname[i]); env_set(addrname[i], ethaddr[i]); /* Probe the device again */ ut_assertok(device_probe(dev[i])); } env_set(".flags", NULL); env_set("ethact", NULL); return 0; }