drivers/thunderbolt/test.c
Source file repositories/reference/linux-study-clean/drivers/thunderbolt/test.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thunderbolt/test.c- Extension
.c- Size
- 89592 bytes
- Lines
- 2904
- Domain
- Driver Families
- Bucket
- drivers/thunderbolt
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.hlinux/idr.htb.htunnel.h
Detected Declarations
struct port_expectationstruct hop_expectationfunction Copyrightfunction __ida_destroyfunction kunit_ida_initfunction tb_test_path_basicfunction tb_test_path_not_connected_walkfunction tb_test_path_single_hop_walkfunction tb_test_path_daisy_chain_walkfunction tb_test_path_simple_tree_walkfunction tb_test_path_complex_tree_walkfunction tb_test_path_max_length_walkfunction tb_test_path_not_connectedfunction tb_test_path_not_bonded_lane0function tb_test_path_not_bonded_lane1function tb_test_path_not_bonded_lane1_chainfunction tb_test_path_not_bonded_lane1_chain_reversefunction tb_test_path_mixed_chainfunction tb_test_path_mixed_chain_reversefunction tb_test_tunnel_pciefunction tb_test_tunnel_dpfunction tb_test_tunnel_dp_chainfunction tb_test_tunnel_dp_treefunction tb_test_tunnel_dp_max_lengthfunction tb_test_tunnel_3dpfunction tb_test_tunnel_usb3function tb_test_tunnel_port_on_pathfunction tb_test_tunnel_dmafunction tb_test_tunnel_dma_rxfunction tb_test_tunnel_dma_txfunction tb_test_tunnel_dma_chainfunction tb_test_tunnel_dma_matchfunction tb_test_credit_alloc_legacy_not_bondedfunction tb_test_credit_alloc_legacy_bondedfunction tb_test_credit_alloc_pciefunction tb_test_credit_alloc_without_dpfunction tb_test_credit_alloc_dpfunction tb_test_credit_alloc_usb3function tb_test_credit_alloc_dmafunction tb_test_credit_alloc_dma_multiplefunction tb_test_credit_alloc_allfunction tb_test_property_parsefunction tb_test_property_formatfunction compare_dirsfunction tb_test_property_copy
Annotated Snippet
struct port_expectation {
u64 route;
u8 port;
enum tb_port_type type;
};
static void tb_test_path_single_hop_walk(struct kunit *test)
{
/*
* Walks from Host PCIe downstream port to Device #1 PCIe
* upstream port.
*
* [Host]
* 1 |
* 1 |
* [Device]
*/
static const struct port_expectation test_data[] = {
{ .route = 0x0, .port = 8, .type = TB_TYPE_PCIE_DOWN },
{ .route = 0x0, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x1, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x1, .port = 9, .type = TB_TYPE_PCIE_UP },
};
struct tb_port *src_port, *dst_port, *p;
struct tb_switch *host, *dev;
int i;
host = alloc_host(test);
dev = alloc_dev_default(test, host, 1, true);
src_port = &host->ports[8];
dst_port = &dev->ports[9];
/* 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);
}
static void tb_test_path_daisy_chain_walk(struct kunit *test)
{
/*
* Walks from Host DP IN to Device #2 DP OUT.
*
* [Host]
* 1 |
* 1 |
* [Device #1]
* 3 /
* 1 /
* [Device #2]
*/
static const struct port_expectation test_data[] = {
{ .route = 0x0, .port = 5, .type = TB_TYPE_DP_HDMI_IN },
{ .route = 0x0, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x1, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x1, .port = 3, .type = TB_TYPE_PORT },
{ .route = 0x301, .port = 1, .type = TB_TYPE_PORT },
{ .route = 0x301, .port = 13, .type = TB_TYPE_DP_HDMI_OUT },
};
struct tb_port *src_port, *dst_port, *p;
struct tb_switch *host, *dev1, *dev2;
int i;
host = alloc_host(test);
dev1 = alloc_dev_default(test, host, 0x1, true);
dev2 = alloc_dev_default(test, dev1, 0x301, true);
src_port = &host->ports[5];
Annotation
- Immediate include surface: `kunit/test.h`, `linux/idr.h`, `tb.h`, `tunnel.h`.
- Detected declarations: `struct port_expectation`, `struct hop_expectation`, `function Copyright`, `function __ida_destroy`, `function kunit_ida_init`, `function tb_test_path_basic`, `function tb_test_path_not_connected_walk`, `function tb_test_path_single_hop_walk`, `function tb_test_path_daisy_chain_walk`, `function tb_test_path_simple_tree_walk`.
- Atlas domain: Driver Families / drivers/thunderbolt.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.