From 4bf11f142443b7df41a282e14437cf71271e2f6b Mon Sep 17 00:00:00 2001 From: David Rees Date: Sun, 15 Dec 2024 12:08:52 -0800 Subject: [PATCH] pw_bluetooth_proxy: Move AcquireL2capCoc calls to use test util MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I93b21089e735d48cd4c41382e6270bd345ddf649 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/254633 Reviewed-by: Ali Saeed Docs-Not-Needed: David Rees Commit-Queue: David Rees Lint: Lint 🤖 Pigweed-Auto-Submit: David Rees --- pw_bluetooth_proxy/proxy_host_test.cc | 51 +++---------------- .../pw_bluetooth_proxy_private/test_utils.h | 5 +- pw_bluetooth_proxy/test_utils.cc | 33 +++++++----- 3 files changed, 29 insertions(+), 60 deletions(-) diff --git a/pw_bluetooth_proxy/proxy_host_test.cc b/pw_bluetooth_proxy/proxy_host_test.cc index c3fb8d321..c268e7b54 100644 --- a/pw_bluetooth_proxy/proxy_host_test.cc +++ b/pw_bluetooth_proxy/proxy_host_test.cc @@ -2305,55 +2305,16 @@ TEST(L2capCocTest, CannotCreateChannelWithInvalidArgs) { /*br_edr_acl_credits_to_reserve=*/0); // Connection handle too large by 1. - EXPECT_EQ( - proxy - .AcquireL2capCoc( - /*connection_handle=*/0x0FFF, - /*rx_config=*/ - {.cid = 0x123, .mtu = 0x123, .mps = 0x123, .credits = 0x123}, - /*tx_config=*/ - {.cid = 0x123, .mtu = 0x123, .mps = 0x123, .credits = 0x123}, - /*receive_fn=*/nullptr, - // TODO: https://pwbug.dev/382783733 - Remove cast after ambiguous - // Acquire method deleted. - /*event_fn=*/ - static_cast>(nullptr)) - .status(), - PW_STATUS_INVALID_ARGUMENT); + EXPECT_EQ(BuildCocWithResult(proxy, CocParameters{.handle = 0x0FFF}).status(), + PW_STATUS_INVALID_ARGUMENT); // Local CID invalid (0). - EXPECT_EQ( - proxy - .AcquireL2capCoc( - /*connection_handle=*/0x123, - /*rx_config=*/ - {.cid = 0, .mtu = 0x123, .mps = 0x123, .credits = 0x123}, - /*tx_config=*/ - {.cid = 0x123, .mtu = 0x123, .mps = 0x123, .credits = 0x123}, - /*receive_fn=*/nullptr, - // TODO: https://pwbug.dev/382783733 - Remove cast after ambiguous - // Acquire method deleted. - /*event_fn=*/ - static_cast>(nullptr)) - .status(), - PW_STATUS_INVALID_ARGUMENT); + EXPECT_EQ(BuildCocWithResult(proxy, CocParameters{.local_cid = 0}).status(), + PW_STATUS_INVALID_ARGUMENT); // Remote CID invalid (0). - EXPECT_EQ( - proxy - .AcquireL2capCoc( - /*connection_handle=*/0x123, - /*rx_config=*/ - {.cid = 0x123, .mtu = 0x123, .mps = 0x123, .credits = 0x123}, - /*tx_config=*/ - {.cid = 0, .mtu = 0x123, .mps = 0x123, .credits = 0x123}, - /*receive_fn=*/nullptr, - // TODO: https://pwbug.dev/382783733 - Remove cast after ambiguous - // Acquire method deleted. - /*event_fn=*/ - static_cast>(nullptr)) - .status(), - PW_STATUS_INVALID_ARGUMENT); + EXPECT_EQ(BuildCocWithResult(proxy, CocParameters{.remote_cid = 0}).status(), + PW_STATUS_INVALID_ARGUMENT); } // ########## L2capCocWriteTest diff --git a/pw_bluetooth_proxy/pw_bluetooth_proxy_private/test_utils.h b/pw_bluetooth_proxy/pw_bluetooth_proxy_private/test_utils.h index 03bb7948e..d3af10ee3 100644 --- a/pw_bluetooth_proxy/pw_bluetooth_proxy_private/test_utils.h +++ b/pw_bluetooth_proxy/pw_bluetooth_proxy_private/test_utils.h @@ -193,7 +193,10 @@ struct CocParameters { pw::Function&& queue_space_available_fn = nullptr; }; -// Open and return an L2CAP connection-oriented channel managed by `proxy`. +// Attempt to AcquireL2capCoc and return result. +pw::Result BuildCocWithResult(ProxyHost& proxy, CocParameters params); + +// Acquire L2capCoc and return result. L2capCoc BuildCoc(ProxyHost& proxy, CocParameters params); struct BasicL2capParameters { diff --git a/pw_bluetooth_proxy/test_utils.cc b/pw_bluetooth_proxy/test_utils.cc index c4c270ed6..b472f1ca2 100644 --- a/pw_bluetooth_proxy/test_utils.cc +++ b/pw_bluetooth_proxy/test_utils.cc @@ -313,21 +313,25 @@ Status SendL2capDisconnectRsp(ProxyHost& proxy, return OkStatus(); } -// Open and return an L2CAP connection-oriented channel managed by `proxy`. +pw::Result BuildCocWithResult(ProxyHost& proxy, + CocParameters params) { + return proxy.AcquireL2capCoc(params.handle, + {.cid = params.local_cid, + .mtu = params.rx_mtu, + .mps = params.rx_mps, + .credits = params.rx_credits}, + {.cid = params.remote_cid, + .mtu = params.tx_mtu, + .mps = params.tx_mps, + .credits = params.tx_credits}, + std::move(params.receive_fn), + std::move(params.event_fn), + std::move(params.queue_space_available_fn)); +} + L2capCoc BuildCoc(ProxyHost& proxy, CocParameters params) { - pw::Result channel = - proxy.AcquireL2capCoc(params.handle, - {.cid = params.local_cid, - .mtu = params.rx_mtu, - .mps = params.rx_mps, - .credits = params.rx_credits}, - {.cid = params.remote_cid, - .mtu = params.tx_mtu, - .mps = params.tx_mps, - .credits = params.tx_credits}, - std::move(params.receive_fn), - std::move(params.event_fn), - std::move(params.queue_space_available_fn)); + pw::Result channel = BuildCocWithResult(proxy, std::move(params)); + PW_TEST_EXPECT_OK(channel); return std::move(channel.value()); } @@ -341,6 +345,7 @@ BasicL2capChannel BuildBasicL2capChannel(ProxyHost& proxy, std::move(params.payload_from_controller_fn), std::move(params.queue_space_available_fn), std::move(params.event_fn)); + PW_TEST_EXPECT_OK(channel); return std::move(channel.value()); }