in test.c [681:782]
static void tb_test_path_max_length_walk(struct kunit *test)
{
struct tb_switch *host, *dev1, *dev2, *dev3, *dev4, *dev5, *dev6;
struct tb_switch *dev7, *dev8, *dev9, *dev10, *dev11, *dev12;
struct tb_port *src_port, *dst_port, *p;
int i;
/*
* Walks from Device #6 DP IN to Device #12 DP OUT.
*
* [Host]
* 1 / \ 3
* 1 / \ 1
* [Device #1] [Device #7]
* 3 | | 3
* 1 | | 1
* [Device #2] [Device #8]
* 3 | | 3
* 1 | | 1
* [Device #3] [Device #9]
* 3 | | 3
* 1 | | 1
* [Device #4] [Device #10]
* 3 | | 3
* 1 | | 1
* [Device #5] [Device #11]
* 3 | | 3
* 1 | | 1
* [Device #6] [Device #12]
*/
static const struct port_expectation test_data[] = {
{ .route = 0x30303030301, .port = 13, .type = TB_TYPE_DP_HDMI_IN },
{ .route = 0x30303030301, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x303030301, .port = 3, .type = TB_TYPE_PORT },
{ .route = 0x303030301, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x3030301, .port = 3, .type = TB_TYPE_PORT },
{ .route = 0x3030301, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x30301, .port = 3, .type = TB_TYPE_PORT },
{ .route = 0x30301, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x301, .port = 3, .type = TB_TYPE_PORT },
{ .route = 0x301, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x1, .port = 3, .type = TB_TYPE_PORT },
{ .route = 0x1, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x0, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x0, .port = 3, .type = TB_TYPE_PORT },
{ .route = 0x3, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x3, .port = 3, .type = TB_TYPE_PORT },
{ .route = 0x303, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x303, .port = 3, .type = TB_TYPE_PORT },
{ .route = 0x30303, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x30303, .port = 3, .type = TB_TYPE_PORT },
{ .route = 0x3030303, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x3030303, .port = 3, .type = TB_TYPE_PORT },
{ .route = 0x303030303, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x303030303, .port = 3, .type = TB_TYPE_PORT },
{ .route = 0x30303030303, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x30303030303, .port = 13, .type = TB_TYPE_DP_HDMI_OUT },
};
host = alloc_host(test);
dev1 = alloc_dev_default(test, host, 0x1, true);
dev2 = alloc_dev_default(test, dev1, 0x301, true);
dev3 = alloc_dev_default(test, dev2, 0x30301, true);
dev4 = alloc_dev_default(test, dev3, 0x3030301, true);
dev5 = alloc_dev_default(test, dev4, 0x303030301, true);
dev6 = alloc_dev_with_dpin(test, dev5, 0x30303030301, true);
dev7 = alloc_dev_default(test, host, 0x3, true);
dev8 = alloc_dev_default(test, dev7, 0x303, true);
dev9 = alloc_dev_default(test, dev8, 0x30303, true);
dev10 = alloc_dev_default(test, dev9, 0x3030303, true);
dev11 = alloc_dev_default(test, dev10, 0x303030303, true);
dev12 = alloc_dev_default(test, dev11, 0x30303030303, true);
src_port = &dev6->ports[13];
dst_port = &dev12->ports[13];
/* Walk both directions */
i = 0;
tb_for_each_port_on_path(src_port, dst_port, p) {
KUNIT_EXPECT_TRUE(test, i < ARRAY_SIZE(test_data));
KUNIT_EXPECT_EQ(test, tb_route(p->sw), test_data[i].route);
KUNIT_EXPECT_EQ(test, p->port, test_data[i].port);
KUNIT_EXPECT_EQ(test, (enum tb_port_type)p->config.type,
test_data[i].type);
i++;
}
KUNIT_EXPECT_EQ(test, i, ARRAY_SIZE(test_data));
i = ARRAY_SIZE(test_data) - 1;
tb_for_each_port_on_path(dst_port, src_port, p) {
KUNIT_EXPECT_TRUE(test, i < ARRAY_SIZE(test_data));
KUNIT_EXPECT_EQ(test, tb_route(p->sw), test_data[i].route);
KUNIT_EXPECT_EQ(test, p->port, test_data[i].port);
KUNIT_EXPECT_EQ(test, (enum tb_port_type)p->config.type,
test_data[i].type);
i--;
}
KUNIT_EXPECT_EQ(test, i, -1);
}