29template <
typename PKTSTREAM>
32#ifdef INSTRUMENTATION_SLOWDOWN
33 const int n_iter = 500;
35 const int n_iter = 250000;
51 for (
int iter = 0; iter < n_iter; ++iter)
64 for (
size_t i = 0; i < r; ++i)
65 src.
push_back(
'a' +
static_cast<unsigned char>(i % 26));
66 PKTSTREAM::prepend_size(src);
67 if (src.
size() > fc_big.remaining_payload(big))
79 fc_big.prepare(bigcmp);
94 pktstream.put(in, fc);
95 while (pktstream.ready())
97 pktstream.get(
out, fc);
98 PKTSTREAM::prepend_size(
out);
107 count += bigorig.
size();
110 ASSERT_EQ(nbig, ncmp);
111 ASSERT_EQ(bigorig, bigcmp);
120 do_test<PacketStream<std::uint16_t>>(
false,
false);
125 do_test<PacketStream<std::uint32_t>>(
false,
false);
130 do_test<PacketStreamResidual<std::uint16_t>>(
true,
false);
135 do_test<PacketStreamResidual<std::uint32_t>>(
true,
false);
138template <
typename PKTSTREAM>
141 bool actual_throw =
false;
144 PKTSTREAM::validate_size(size, fc);
146 catch (
typename PKTSTREAM::embedded_packet_size_error &)
150 if (expect_throw != actual_throw)
151 THROW_FMT(
"validate_size: bad throw, expect=%s, actual=%s, FC=%s size=%s",
158template <
typename PKTSTREAM>
161 const size_t payload = 2048;
162 const size_t headroom = 16;
163 const size_t tailroom = 0;
164 const size_t align_block = 16;
167 validate_size<PKTSTREAM>(fixed, 2048,
false);
168 validate_size<PKTSTREAM>(fixed, 2049,
true);
169 validate_size<PKTSTREAM>(grow, 2048,
false);
170 validate_size<PKTSTREAM>(grow, 2049,
false);
175 validate_size_test<PacketStream<std::uint16_t>>();
180 validate_size_test<PacketStream<std::uint32_t>>();
void push_back(const T &value)
Append a T object to the end of the array, resizing the array if necessary.
size_t size() const
Returns the size of the buffer in T objects.
T * data()
Get a mutable pointer to the start of the array.
void advance(const size_t delta)
Advances the buffer by the specified delta.
bool empty() const
Returns true if the buffer is empty.
void write(const T *data, const size_t size)
Write data to the buffer.
size_t prepare(Buffer &buf) const
Abstract base class for random number generators.
std::uint32_t randrange32(const std::uint32_t end)
Return a uniformly distributed random number in the range [0, end)
bool randbool()
Return a random boolean.
#define OPENVPN_LOG(args)
constexpr BufferFlags GROW(1U<< 2)
if enabled, buffer will grow (otherwise buffer_full exception will be thrown)
constexpr BufferFlags NO_FLAGS(0U)
no flags set
static std::stringstream out
static size_t rand_size(RandomAPI &prng)
static void do_test(const bool grow, const bool verbose)
static void validate_size(const Frame::Context &fc, const size_t size, const bool expect_throw)
static void validate_size_test()