Skip to content

Commit

Permalink
Merge pull request #31737 from vespa-engine/balder/reduce-amount-of-i…
Browse files Browse the repository at this point in the history
…nlined-code

Reduce the amount of code in header files.
  • Loading branch information
toregge committed Jun 27, 2024
2 parents ebf45b2 + d9a9b6a commit 7c74a29
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 46 deletions.

This file was deleted.

21 changes: 0 additions & 21 deletions searchcore/src/tests/proton/documentdb/configurer/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion vespalib/src/vespa/vespalib/testkit/test_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool TestHook::runMyTest(const FixtureFactory & fixture_factory, size_t num_thre
FixtureUP fixture_up = fixture_factory();
fixture_up->thread_id = i;
fixture_up->num_threads = num_threads;
threads.emplace_back(new TestThreadWrapper(_ignore, latch, barrier, traceStack, *fixture_up));
threads.emplace_back(std::make_unique<TestThreadWrapper>(_ignore, latch, barrier, traceStack, *fixture_up));
fixtures.push_back(std::move(fixture_up));
}
for (size_t i = 1; i < num_threads; ++i) {
Expand Down
29 changes: 25 additions & 4 deletions vespalib/src/vespa/vespalib/testkit/test_master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ TestMaster TestMaster::master;
__thread TestMaster::ThreadState *TestMaster::_threadState = nullptr;

//-----------------------------------------------------------------------------
TestMaster::TraceItem::TraceItem(const std::string &file_in, uint32_t line_in, const std::string &msg_in)
: file(file_in), line(line_in), msg(msg_in)
TestMaster::TraceItem::TraceItem(std::string file_in, uint32_t line_in, std::string msg_in)
: file(std::move(file_in)), line(line_in), msg(std::move(msg_in))
{}
TestMaster::TraceItem::TraceItem(TraceItem &&) noexcept = default;
TestMaster::TraceItem & TestMaster::TraceItem::operator=(TraceItem &&) noexcept = default;
Expand All @@ -39,8 +39,8 @@ TestMaster::TraceItem & TestMaster::TraceItem::operator=(const TraceItem &) = de
TestMaster::TraceItem::~TraceItem() = default;

TestMaster::ThreadState::~ThreadState() = default;
TestMaster::ThreadState::ThreadState(const std::string &n)
: name(n), passCnt(0), failCnt(0), preIgnoreFailCnt(0),
TestMaster::ThreadState::ThreadState(std::string n)
: name(std::move(n)), passCnt(0), failCnt(0), preIgnoreFailCnt(0),
ignore(false), unwind(false), traceStack(), barrier(nullptr)
{}

Expand Down Expand Up @@ -166,6 +166,27 @@ TestMaster::reportConclusion(const lock_guard &)
return ok;
}

void
TestMaster::report_compare(const char *file, uint32_t line, const char *aName, const char *bName, const char *opText, bool fatal,
const std::function<void(std::ostream &)> & printLhs,
const std::function<void(std::ostream &)> & printRhs)
{
std::string str;
str += aName;
str += opText;
str += bName;
std::ostringstream lhs;
std::ostringstream rhs;
printLhs(lhs);
printRhs(rhs);
{
lock_guard guard(_lock);
checkFailed(guard, file, line, str.c_str());
printDiff(guard, str, file, line, lhs.str(), rhs.str());
handleFailure(guard, fatal);
}
}

//-----------------------------------------------------------------------------

TestMaster::TestMaster()
Expand Down
11 changes: 7 additions & 4 deletions vespalib/src/vespa/vespalib/testkit/test_master.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vector>
#include <memory>
#include <mutex>
#include <functional>

namespace vespalib {

Expand All @@ -32,7 +33,7 @@ class TestMaster
std::string file;
uint32_t line;
std::string msg;
TraceItem(const std::string &file_in, uint32_t line_in, const std::string &msg_in);
TraceItem(std::string file_in, uint32_t line_in, std::string msg_in);
TraceItem(TraceItem &&) noexcept;
TraceItem & operator=(TraceItem &&) noexcept;
TraceItem(const TraceItem &);
Expand All @@ -51,7 +52,7 @@ class TestMaster
std::vector<TraceItem> traceStack;
Barrier *barrier;
~ThreadState();
ThreadState(const std::string &n);
ThreadState(std::string n);
ThreadState(ThreadState &&) noexcept = default;
ThreadState & operator=(ThreadState &&) noexcept = default;
};
Expand Down Expand Up @@ -89,6 +90,9 @@ class TestMaster
bool reportConclusion(const lock_guard &);


void report_compare(const char *file, uint32_t line, const char *aName, const char *bName, const char *opText, bool fatal,
const std::function<void(std::ostream &)> & printLhs,
const std::function<void(std::ostream &)> & printRhs);
public:
~TestMaster();
TestMaster(const TestMaster &) = delete;
Expand All @@ -109,8 +113,7 @@ class TestMaster
void close_debug_files();
void pushState(const char *file, uint32_t line, const char *msg);
void popState();
bool check(bool rc, const char *file, uint32_t line,
const char *str, bool fatal);
bool check(bool rc, const char *file, uint32_t line, const char *str, bool fatal);
template<class A, class B, class OP>
bool compare(const char *file, uint32_t line,
const char *aName, const char *bName, const char *opText,
Expand Down
19 changes: 4 additions & 15 deletions vespalib/src/vespa/vespalib/testkit/test_master.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,13 @@ TestMaster::compare(const char *file, uint32_t line,
const char *opText,
const A &a, const B &b, const OP &op, bool fatal)
{
if (op(a,b)) {
if (op(a,b)) [[likely]]{
++threadState().passCnt;
return true;
}
std::string str;
str += aName;
str += opText;
str += bName;
std::ostringstream lhs;
std::ostringstream rhs;
lhs << a;
rhs << b;
{
lock_guard guard(_lock);
checkFailed(guard, file, line, str.c_str());
printDiff(guard, str, file, line, lhs.str(), rhs.str());
handleFailure(guard, fatal);
}
report_compare(file, line, aName, bName, opText, fatal,
[&](std::ostream & os) { os << a;},
[&](std::ostream & os) { os << b;});
return false;
}

Expand Down

0 comments on commit 7c74a29

Please sign in to comment.