aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@vespa.ai>2024-06-26 22:17:48 +0000
committerHenning Baldersheim <balder@vespa.ai>2024-06-27 08:01:32 +0000
commitd9a9b6a928bc310595c1172ef36ffb66ca0f4b4a (patch)
treea5548a0ef6574b57ae6b5c5f9175698aa14f0fa5 /vespalib/src
parentc5fc5beeb159e7c85da61411489b8b97faa2a387 (diff)
- Reduce the amount of code in header files.
- This reduces the size of each generated TestMaster::compare method from 3-5k down to around 0.3k. - There are a total of 2225 TestMaster::compare methods generated in all out test_apps. - GC leftover files - Use std::move
Diffstat (limited to 'vespalib/src')
-rw-r--r--vespalib/src/vespa/vespalib/testkit/test_hook.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/testkit/test_master.cpp29
-rw-r--r--vespalib/src/vespa/vespalib/testkit/test_master.h11
-rw-r--r--vespalib/src/vespa/vespalib/testkit/test_master.hpp19
4 files changed, 37 insertions, 24 deletions
diff --git a/vespalib/src/vespa/vespalib/testkit/test_hook.cpp b/vespalib/src/vespa/vespalib/testkit/test_hook.cpp
index b14b575ae93..27561983924 100644
--- a/vespalib/src/vespa/vespalib/testkit/test_hook.cpp
+++ b/vespalib/src/vespa/vespalib/testkit/test_hook.cpp
@@ -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) {
diff --git a/vespalib/src/vespa/vespalib/testkit/test_master.cpp b/vespalib/src/vespa/vespalib/testkit/test_master.cpp
index 4698d40ecc5..89a968cf990 100644
--- a/vespalib/src/vespa/vespalib/testkit/test_master.cpp
+++ b/vespalib/src/vespa/vespalib/testkit/test_master.cpp
@@ -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;
@@ -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)
{}
@@ -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()
diff --git a/vespalib/src/vespa/vespalib/testkit/test_master.h b/vespalib/src/vespa/vespalib/testkit/test_master.h
index 232ef8009c9..70d2b441b51 100644
--- a/vespalib/src/vespa/vespalib/testkit/test_master.h
+++ b/vespalib/src/vespa/vespalib/testkit/test_master.h
@@ -6,6 +6,7 @@
#include <vector>
#include <memory>
#include <mutex>
+#include <functional>
namespace vespalib {
@@ -32,7 +33,7 @@ public:
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 &);
@@ -51,7 +52,7 @@ private:
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;
};
@@ -89,6 +90,9 @@ private:
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;
@@ -109,8 +113,7 @@ public:
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,
diff --git a/vespalib/src/vespa/vespalib/testkit/test_master.hpp b/vespalib/src/vespa/vespalib/testkit/test_master.hpp
index 065a64fb2ab..ba5dc54e965 100644
--- a/vespalib/src/vespa/vespalib/testkit/test_master.hpp
+++ b/vespalib/src/vespa/vespalib/testkit/test_master.hpp
@@ -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;
}