Add valgrind variant, fix false positives

This commit is contained in:
Vinnie Falco committed 2017-07-31 12:37:32 -07:00
1 parent 0a3029b8ac
commit 8def3b1ba7
5 files changed
+90 -7

No files matched your search

+80 -1
View File
@@ -15,7 +15,10 @@
#include <boost/beast/test/string_istream.hpp>
#include <boost/beast/test/yield_to.hpp>
#include <boost/beast/unit_test/suite.hpp>
#include <boost/asio.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/read.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/optional.hpp>
namespace boost {
namespace beast {
@@ -45,6 +48,80 @@ public:
}
}
struct loop : std::enable_shared_from_this<loop>
{
using stream_type = test::fail_stream<
test::string_istream>;
static std::size_t constexpr limit = 100;
std::string s_;
std::size_t n_ = 0;
std::size_t cap_;
unit_test::suite& suite_;
boost::asio::io_service& ios_;
boost::optional<stream_type> fs_;
boost::optional<buffered_read_stream<
stream_type&, multi_buffer>> brs_;
loop(
unit_test::suite& suite,
boost::asio::io_service& ios,
std::size_t cap)
: cap_(cap)
, suite_(suite)
, ios_(ios)
{
}
void
run()
{
do_read();
}
void
on_read(error_code ec, std::size_t)
{
using boost::asio::buffer;
if(! ec)
{
suite_.expect(s_ ==
"Hello, world!", __FILE__, __LINE__);
return;
}
++n_;
if(! suite_.expect(n_ < limit, __FILE__, __LINE__))
return;
s_.clear();
do_read();
}
void
do_read()
{
using boost::asio::buffer;
using boost::asio::buffer_copy;
s_.resize(13);
fs_.emplace(n_, ios_, ", world!");
brs_.emplace(*fs_);
brs_->buffer().commit(buffer_copy(
brs_->buffer().prepare(5), buffer("Hello", 5)));
boost::asio::async_read(*brs_,
buffer(&s_[0], s_.size()),
std::bind(
&loop::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
}
};
void
testAsyncLoop()
{
std::make_shared<loop>(*this, ios_, 0)->run();
std::make_shared<loop>(*this, ios_, 3)->run();
}
void testRead(yield_context do_yield)
{
using boost::asio::buffer;
@@ -137,6 +214,8 @@ public:
yield_to([&](yield_context yield){
testRead(yield);});
testAsyncLoop();
}
};