Add valgrind variant, fix false positives

This commit is contained in:
Vinnie Falco
2017-07-31 09:34:22 -07:00
parent 0a3029b8ac
commit 8def3b1ba7
5 changed files with 90 additions and 7 deletions

View File

@@ -43,12 +43,11 @@ matrix:
sources:
- *base_sources
# GCC 5.0, Release + Valgrind
# GCC 5.0, Valgrind
- os: linux
compiler: g++-5
env:
- DO_VALGRIND=true
- VARIANT=release
- VARIANT=valgrind
- TOOLSET=gcc
- COMPILER=g++-5
- CXXSTD=c++11

View File

@@ -7,6 +7,7 @@ Version 95:
* Add test::stream
* Tidy up static_buffer braced init
* Fix html redirect
* Add valgrind variant, fix false positives
--------------------------------------------------------------------------------

View File

@@ -58,6 +58,12 @@ variant coverage :
<linkflags>"--coverage"
;
variant valgrind :
release
:
<define>BOOST_USE_VALGRIND=1
;
variant ubasan
:
release

View File

@@ -119,8 +119,6 @@ function build_bjam ()
build_bjam
DO_VALGRIND=${DO_VALGRIND:-false}
if [[ $VARIANT == "coverage" ]]; then
# for lcov to work effectively, the paths and includes
# passed to the compiler should not contain "." or "..".
@@ -137,7 +135,7 @@ if [[ $VARIANT == "coverage" ]]; then
~/.local/bin/codecov -X gcov -f lcov.info
find "$BOOST_ROOT" -name "*.gcda" | xargs rm -f
elif [[ "$DO_VALGRIND" = true ]]; then
elif [[ $VARIANT == "valgrind" ]]; then
run_tests_with_valgrind "$BIN_DIR" fat-tests
else

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