Skip to content

Commit 4b93c54

Browse files
committed
thunderbolt: test: split up test cases in tb_test_credit_alloc_all
The tb_test_credit_alloc_all() function had a huge number of KUNIT_ASSERT() statements, all of which (though the magic of many many layers of inscrutable macros) ended up allocating and initializing various test assertion structures on the stack. Don't do that. The kernel stack isn't infinite, and we have compiler warnings (now errors) for the case where a stack frame grows too large. Like it did here, by not an inconsiderable margin: drivers/thunderbolt/test.c: In function ‘tb_test_credit_alloc_all’: drivers/thunderbolt/test.c:2367:1: error: the frame size of 4500 bytes is larger than 2048 bytes [-Werror=frame-larger-than=] 2367 | } | ^ Solve this similarly to the lib/test_scanf case: split out the tests into several smaller functions, each just testing one particular tunnel credit allocation. This makes the i386 allyesconfig build work for me again. Signed-off-by: Linus Torvalds <[email protected]>
1 parent ba7b1f8 commit 4b93c54

File tree

1 file changed

+81
-17
lines changed

1 file changed

+81
-17
lines changed

drivers/thunderbolt/test.c

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,23 +2206,13 @@ static void tb_test_credit_alloc_dma_multiple(struct kunit *test)
22062206
tb_tunnel_free(tunnel2);
22072207
}
22082208

2209-
static void tb_test_credit_alloc_all(struct kunit *test)
2209+
static struct tb_tunnel *TB_TEST_PCIE_TUNNEL(struct kunit *test,
2210+
struct tb_switch *host, struct tb_switch *dev)
22102211
{
2211-
struct tb_port *up, *down, *in, *out, *nhi, *port;
2212-
struct tb_tunnel *pcie_tunnel, *dp_tunnel1, *dp_tunnel2, *usb3_tunnel;
2213-
struct tb_tunnel *dma_tunnel1, *dma_tunnel2;
2214-
struct tb_switch *host, *dev;
2212+
struct tb_port *up, *down;
2213+
struct tb_tunnel *pcie_tunnel;
22152214
struct tb_path *path;
22162215

2217-
/*
2218-
* Create PCIe, 2 x DP, USB 3.x and two DMA tunnels from host to
2219-
* device. Expectation is that all these can be established with
2220-
* the default credit allocation found in Intel hardware.
2221-
*/
2222-
2223-
host = alloc_host_usb4(test);
2224-
dev = alloc_dev_usb4(test, host, 0x1, true);
2225-
22262216
down = &host->ports[8];
22272217
up = &dev->ports[9];
22282218
pcie_tunnel = tb_tunnel_alloc_pci(NULL, up, down);
@@ -2243,9 +2233,18 @@ static void tb_test_credit_alloc_all(struct kunit *test)
22432233
KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U);
22442234
KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 64U);
22452235

2236+
return pcie_tunnel;
2237+
}
2238+
2239+
static struct tb_tunnel *TB_TEST_DP_TUNNEL1(struct kunit *test,
2240+
struct tb_switch *host, struct tb_switch *dev)
2241+
{
2242+
struct tb_port *in, *out;
2243+
struct tb_tunnel *dp_tunnel1;
2244+
struct tb_path *path;
2245+
22462246
in = &host->ports[5];
22472247
out = &dev->ports[13];
2248-
22492248
dp_tunnel1 = tb_tunnel_alloc_dp(NULL, in, out, 0, 0);
22502249
KUNIT_ASSERT_TRUE(test, dp_tunnel1 != NULL);
22512250
KUNIT_ASSERT_EQ(test, dp_tunnel1->npaths, (size_t)3);
@@ -2271,9 +2270,18 @@ static void tb_test_credit_alloc_all(struct kunit *test)
22712270
KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U);
22722271
KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 1U);
22732272

2273+
return dp_tunnel1;
2274+
}
2275+
2276+
static struct tb_tunnel *TB_TEST_DP_TUNNEL2(struct kunit *test,
2277+
struct tb_switch *host, struct tb_switch *dev)
2278+
{
2279+
struct tb_port *in, *out;
2280+
struct tb_tunnel *dp_tunnel2;
2281+
struct tb_path *path;
2282+
22742283
in = &host->ports[6];
22752284
out = &dev->ports[14];
2276-
22772285
dp_tunnel2 = tb_tunnel_alloc_dp(NULL, in, out, 0, 0);
22782286
KUNIT_ASSERT_TRUE(test, dp_tunnel2 != NULL);
22792287
KUNIT_ASSERT_EQ(test, dp_tunnel2->npaths, (size_t)3);
@@ -2299,6 +2307,16 @@ static void tb_test_credit_alloc_all(struct kunit *test)
22992307
KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U);
23002308
KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 1U);
23012309

2310+
return dp_tunnel2;
2311+
}
2312+
2313+
static struct tb_tunnel *TB_TEST_USB3_TUNNEL(struct kunit *test,
2314+
struct tb_switch *host, struct tb_switch *dev)
2315+
{
2316+
struct tb_port *up, *down;
2317+
struct tb_tunnel *usb3_tunnel;
2318+
struct tb_path *path;
2319+
23022320
down = &host->ports[12];
23032321
up = &dev->ports[16];
23042322
usb3_tunnel = tb_tunnel_alloc_usb3(NULL, up, down, 0, 0);
@@ -2319,9 +2337,18 @@ static void tb_test_credit_alloc_all(struct kunit *test)
23192337
KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U);
23202338
KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 32U);
23212339

2340+
return usb3_tunnel;
2341+
}
2342+
2343+
static struct tb_tunnel *TB_TEST_DMA_TUNNEL1(struct kunit *test,
2344+
struct tb_switch *host, struct tb_switch *dev)
2345+
{
2346+
struct tb_port *nhi, *port;
2347+
struct tb_tunnel *dma_tunnel1;
2348+
struct tb_path *path;
2349+
23222350
nhi = &host->ports[7];
23232351
port = &dev->ports[3];
2324-
23252352
dma_tunnel1 = tb_tunnel_alloc_dma(NULL, nhi, port, 8, 1, 8, 1);
23262353
KUNIT_ASSERT_TRUE(test, dma_tunnel1 != NULL);
23272354
KUNIT_ASSERT_EQ(test, dma_tunnel1->npaths, (size_t)2);
@@ -2340,6 +2367,18 @@ static void tb_test_credit_alloc_all(struct kunit *test)
23402367
KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U);
23412368
KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 14U);
23422369

2370+
return dma_tunnel1;
2371+
}
2372+
2373+
static struct tb_tunnel *TB_TEST_DMA_TUNNEL2(struct kunit *test,
2374+
struct tb_switch *host, struct tb_switch *dev)
2375+
{
2376+
struct tb_port *nhi, *port;
2377+
struct tb_tunnel *dma_tunnel2;
2378+
struct tb_path *path;
2379+
2380+
nhi = &host->ports[7];
2381+
port = &dev->ports[3];
23432382
dma_tunnel2 = tb_tunnel_alloc_dma(NULL, nhi, port, 9, 2, 9, 2);
23442383
KUNIT_ASSERT_TRUE(test, dma_tunnel2 != NULL);
23452384
KUNIT_ASSERT_EQ(test, dma_tunnel2->npaths, (size_t)2);
@@ -2358,6 +2397,31 @@ static void tb_test_credit_alloc_all(struct kunit *test)
23582397
KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U);
23592398
KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 1U);
23602399

2400+
return dma_tunnel2;
2401+
}
2402+
2403+
static void tb_test_credit_alloc_all(struct kunit *test)
2404+
{
2405+
struct tb_tunnel *pcie_tunnel, *dp_tunnel1, *dp_tunnel2, *usb3_tunnel;
2406+
struct tb_tunnel *dma_tunnel1, *dma_tunnel2;
2407+
struct tb_switch *host, *dev;
2408+
2409+
/*
2410+
* Create PCIe, 2 x DP, USB 3.x and two DMA tunnels from host to
2411+
* device. Expectation is that all these can be established with
2412+
* the default credit allocation found in Intel hardware.
2413+
*/
2414+
2415+
host = alloc_host_usb4(test);
2416+
dev = alloc_dev_usb4(test, host, 0x1, true);
2417+
2418+
pcie_tunnel = TB_TEST_PCIE_TUNNEL(test, host, dev);
2419+
dp_tunnel1 = TB_TEST_DP_TUNNEL1(test, host, dev);
2420+
dp_tunnel2 = TB_TEST_DP_TUNNEL2(test, host, dev);
2421+
usb3_tunnel = TB_TEST_USB3_TUNNEL(test, host, dev);
2422+
dma_tunnel1 = TB_TEST_DMA_TUNNEL1(test, host, dev);
2423+
dma_tunnel2 = TB_TEST_DMA_TUNNEL2(test, host, dev);
2424+
23612425
tb_tunnel_free(dma_tunnel2);
23622426
tb_tunnel_free(dma_tunnel1);
23632427
tb_tunnel_free(usb3_tunnel);

0 commit comments

Comments
 (0)