30template <
typename PKTSTREAM>
33#ifdef INSTRUMENTATION_SLOWDOWN
34 const int n_iter = 500;
36 const int n_iter = 250000;
52 for (
int iter = 0; iter < n_iter; ++iter)
65 for (
size_t i = 0; i < r; ++i)
66 src.
push_back(
'a' +
static_cast<unsigned char>(i % 26));
67 PKTSTREAM::prepend_size(src);
68 if (src.
size() > fc_big.remaining_payload(big))
80 fc_big.prepare(bigcmp);
95 pktstream.put(in, fc);
96 while (pktstream.ready())
98 pktstream.get(
out, fc);
99 PKTSTREAM::prepend_size(
out);
108 count += bigorig.
size();
111 ASSERT_EQ(nbig, ncmp);
112 ASSERT_EQ(bigorig, bigcmp);
121 do_test<PacketStream<std::uint16_t>>(
false,
false);
126 do_test<PacketStream<std::uint32_t>>(
false,
false);
129TEST(pktstream, test_16_residual)
131 do_test<PacketStreamResidual<std::uint16_t>>(
true,
false);
134TEST(pktstream, test_32_residual)
136 do_test<PacketStreamResidual<std::uint32_t>>(
true,
false);
139template <
typename PKTSTREAM>
142 bool actual_throw =
false;
145 PKTSTREAM::validate_size(size, fc);
147 catch (
typename PKTSTREAM::embedded_packet_size_error &)
151 if (expect_throw != actual_throw)
152 THROW_FMT(
"validate_size: bad throw, expect=%s, actual=%s, FC=%s size=%s",
159template <
typename PKTSTREAM>
162 const size_t payload = 2048;
163 const size_t headroom = 16;
164 const size_t tailroom = 0;
165 const size_t align_block = 16;
168 validate_size<PKTSTREAM>(fixed, 2048,
false);
169 validate_size<PKTSTREAM>(fixed, 2049,
true);
170 validate_size<PKTSTREAM>(grow, 2048,
false);
171 validate_size<PKTSTREAM>(grow, 2049,
false);
174TEST(pktstream, validate_size_16)
176 validate_size_test<PacketStream<std::uint16_t>>();
179TEST(pktstream, validate_size_32)
181 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.
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()