18#include "pw_assert/assert.h"
19#include "pw_chrono/system_clock.h"
20#include "pw_rpc/internal/fake_channel_output.h"
21#include "pw_rpc/method_info.h"
22#include "pw_status/status.h"
23#include "pw_sync/counting_semaphore.h"
24#include "pw_thread/yield.h"
26namespace pw::rpc::test {
32template <
unsigned kTimeoutSeconds = 10,
typename Function>
33void WaitForPackets(internal::test::FakeChannelOutput& output,
36 sync::CountingSemaphore sem;
37 output.set_on_send([&sem](ConstByteSpan, Status) { sem.release(); });
41 for (
int i = 0; i < count; ++i) {
42 PW_ASSERT(sem.try_acquire_for(std::chrono::seconds(kTimeoutSeconds)));
45 output.set_on_send(
nullptr);
75template <auto kMethod,
typename Context>
76Status SendResponseIfCalled(
77 Context& client_context,
78 const MethodResponseType<kMethod>& response,
85 client_context.output().template total_payloads<kMethod>();
87 client_context.server().template SendResponse<kMethod>(response, status);
96template <auto kMethod,
typename Context>
97Status SendResponseIfCalled(
98 Context& client_context,
102 return SendResponseIfCalled<kMethod, Context>(
103 client_context, {}, status, timeout);
static constexpr Status DeadlineExceeded()
Deadline passed before operation completed.
Definition: status.h:136
static constexpr duration for_at_least(std::chrono::duration< Rep, Period > d)
Definition: system_clock.h:125
static time_point now() noexcept
This is thread and IRQ safe. This must be provided by the backend.
Definition: system_clock.h:117
std::chrono::duration< rep, period > duration
Alias for durations representable with this clock.
Definition: system_clock.h:90
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:73
constexpr Status OkStatus()
Definition: status.h:297