Skip to content

Commit

Permalink
pw_bluetooth_proxy: Move AcquireL2capCoc calls to use test util
Browse files Browse the repository at this point in the history
Change-Id: I93b21089e735d48cd4c41382e6270bd345ddf649
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/254633
Reviewed-by: Ali Saeed <saeedali@google.com>
Docs-Not-Needed: David Rees <drees@google.com>
Commit-Queue: David Rees <drees@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Pigweed-Auto-Submit: David Rees <drees@google.com>
  • Loading branch information
studgeek authored and CQ Bot Account committed Dec 15, 2024
1 parent 4183fe8 commit 4bf11f1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 60 deletions.
51 changes: 6 additions & 45 deletions pw_bluetooth_proxy/proxy_host_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Function<void(L2capChannelEvent event)>>(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<Function<void(L2capChannelEvent event)>>(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<Function<void(L2capChannelEvent event)>>(nullptr))
.status(),
PW_STATUS_INVALID_ARGUMENT);
EXPECT_EQ(BuildCocWithResult(proxy, CocParameters{.remote_cid = 0}).status(),
PW_STATUS_INVALID_ARGUMENT);
}

// ########## L2capCocWriteTest
Expand Down
5 changes: 4 additions & 1 deletion pw_bluetooth_proxy/pw_bluetooth_proxy_private/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ struct CocParameters {
pw::Function<void()>&& queue_space_available_fn = nullptr;
};

// Open and return an L2CAP connection-oriented channel managed by `proxy`.
// Attempt to AcquireL2capCoc and return result.
pw::Result<L2capCoc> BuildCocWithResult(ProxyHost& proxy, CocParameters params);

// Acquire L2capCoc and return result.
L2capCoc BuildCoc(ProxyHost& proxy, CocParameters params);

struct BasicL2capParameters {
Expand Down
33 changes: 19 additions & 14 deletions pw_bluetooth_proxy/test_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,21 +313,25 @@ Status SendL2capDisconnectRsp(ProxyHost& proxy,
return OkStatus();
}

// Open and return an L2CAP connection-oriented channel managed by `proxy`.
pw::Result<L2capCoc> 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<L2capCoc> 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<L2capCoc> channel = BuildCocWithResult(proxy, std::move(params));
PW_TEST_EXPECT_OK(channel);
return std::move(channel.value());
}

Expand All @@ -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());
}

Expand Down

0 comments on commit 4bf11f1

Please sign in to comment.