aboutsummaryrefslogtreecommitdiffstats
path: root/storageframework
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-05-27 13:16:13 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-05-27 13:16:13 +0000
commitea99d9064c25de9da79ca41da6124f79817676e1 (patch)
tree68e96569212c5f9cfa784860aa50390e82eefd75 /storageframework
parentbdde5f1b839ae2947007af1b1feb9045417fb39b (diff)
Rewrite storageframework tests from cppunit to gtest.
Diffstat (limited to 'storageframework')
-rw-r--r--storageframework/src/tests/CMakeLists.txt14
-rw-r--r--storageframework/src/tests/testrunner.cpp13
-rw-r--r--storageframework/src/tests/thread/CMakeLists.txt1
-rw-r--r--storageframework/src/tests/thread/taskthreadtest.cpp64
-rw-r--r--storageframework/src/tests/thread/tickingthreadtest.cpp86
5 files changed, 49 insertions, 129 deletions
diff --git a/storageframework/src/tests/CMakeLists.txt b/storageframework/src/tests/CMakeLists.txt
index e84fe5fb663..d658605a911 100644
--- a/storageframework/src/tests/CMakeLists.txt
+++ b/storageframework/src/tests/CMakeLists.txt
@@ -7,6 +7,7 @@ vespa_add_executable(storageframework_gtest_runner_app TEST
gtest_runner.cpp
DEPENDS
storageframework_testclock
+ storageframework_testthread
gtest
)
@@ -14,16 +15,3 @@ vespa_add_test(
NAME storageframework_gtest_runner_app
COMMAND storageframework_gtest_runner_app
)
-
-# Runner for unit tests written in CppUnit (DEPRECATED).
-vespa_add_executable(storageframework_testrunner_app TEST
- SOURCES
- testrunner.cpp
- DEPENDS
- storageframework_testthread
-)
-
-vespa_add_test(
- NAME storageframework_testrunner_app
- COMMAND storageframework_testrunner_app
-)
diff --git a/storageframework/src/tests/testrunner.cpp b/storageframework/src/tests/testrunner.cpp
deleted file mode 100644
index 7bd12fedce5..00000000000
--- a/storageframework/src/tests/testrunner.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include <vespa/vdstestlib/cppunit/cppunittestrunner.h>
-
-#include <vespa/log/log.h>
-LOG_SETUP("persistencecppunittests");
-
-int
-main(int argc, const char *argv[])
-{
- vdstestlib::CppUnitTestRunner testRunner;
- return testRunner.run(argc, argv);
-}
diff --git a/storageframework/src/tests/thread/CMakeLists.txt b/storageframework/src/tests/thread/CMakeLists.txt
index 700e720feb3..3e6db8c9b57 100644
--- a/storageframework/src/tests/thread/CMakeLists.txt
+++ b/storageframework/src/tests/thread/CMakeLists.txt
@@ -5,4 +5,5 @@ vespa_add_library(storageframework_testthread
taskthreadtest.cpp
DEPENDS
storageframework
+ gtest
)
diff --git a/storageframework/src/tests/thread/taskthreadtest.cpp b/storageframework/src/tests/thread/taskthreadtest.cpp
index 54874626517..fc4d2dfc704 100644
--- a/storageframework/src/tests/thread/taskthreadtest.cpp
+++ b/storageframework/src/tests/thread/taskthreadtest.cpp
@@ -1,47 +1,35 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/storageframework/generic/thread/taskthread.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
+#include <vespa/vespalib/gtest/gtest.h>
-namespace storage {
-namespace framework {
+namespace storage::framework {
-struct TaskThreadTest : public CppUnit::TestFixture
-{
+namespace {
- void testNormalUsage();
+struct Task {
+ std::string _name;
+ uint8_t _priority;
- CPPUNIT_TEST_SUITE(TaskThreadTest);
- CPPUNIT_TEST(testNormalUsage);
- CPPUNIT_TEST_SUITE_END();
-};
+ Task(const std::string& name, uint8_t priority)
+ : _name(name), _priority(priority) {}
-CPPUNIT_TEST_SUITE_REGISTRATION(TaskThreadTest);
+ bool operator<(const Task& other) const {
+ return (_priority > other._priority);
+ }
+ uint8_t getPriority() const { return _priority; }
+};
-namespace {
- struct Task {
- std::string _name;
- uint8_t _priority;
-
- Task(const std::string& name, uint8_t priority)
- : _name(name), _priority(priority) {}
-
- bool operator<(const Task& other) const {
- return (_priority > other._priority);
- }
- uint8_t getPriority() const { return _priority; }
- };
+struct MyThread : public TaskThread<Task> {
+ MyThread(ThreadLock& lock) : TaskThread<Task>(lock) {}
+ ThreadWaitInfo doNonCriticalTick(ThreadIndex) override {
+ return ThreadWaitInfo::NO_MORE_CRITICAL_WORK_KNOWN;
+ }
+};
- struct MyThread : public TaskThread<Task> {
- MyThread(ThreadLock& lock) : TaskThread<Task>(lock) {}
- ThreadWaitInfo doNonCriticalTick(ThreadIndex) override {
- return ThreadWaitInfo::NO_MORE_CRITICAL_WORK_KNOWN;
- }
- };
}
-void
-TaskThreadTest::testNormalUsage()
+TEST(TaskThreadTest, test_normal_usage)
{
TickingThreadPool::UP pool(TickingThreadPool::createDefault("testApp"));
@@ -50,19 +38,17 @@ TaskThreadTest::testNormalUsage()
t.addTask(Task("b", 3));
t.addTask(Task("c", 8));
t.addTask(Task("d", 4));
- CPPUNIT_ASSERT(t.empty()); // Still empty before critical tick has run
+ EXPECT_TRUE(t.empty()); // Still empty before critical tick has run
dynamic_cast<TickingThread&>(t).doCriticalTick(0);
- CPPUNIT_ASSERT(!t.empty());
- CPPUNIT_ASSERT_EQUAL(3, (int) t.peek().getPriority());
+ EXPECT_TRUE(!t.empty());
+ EXPECT_EQ(3, t.peek().getPriority());
std::ostringstream ost;
while (!t.empty()) {
Task task(t.peek());
ost << task._name << '(' << ((int) task.getPriority()) << ") ";
t.pop();
}
- CPPUNIT_ASSERT_EQUAL(std::string("b(3) d(4) a(6) c(8) "), ost.str());
+ EXPECT_EQ(std::string("b(3) d(4) a(6) c(8) "), ost.str());
}
-
-} // framework
-} // storage
+}
diff --git a/storageframework/src/tests/thread/tickingthreadtest.cpp b/storageframework/src/tests/thread/tickingthreadtest.cpp
index 3e96bcd7a0f..97ae08eef3d 100644
--- a/storageframework/src/tests/thread/tickingthreadtest.cpp
+++ b/storageframework/src/tests/thread/tickingthreadtest.cpp
@@ -1,42 +1,13 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/util/stringfmt.h>
-#include <vespa/vespalib/util/exception.h>
#include <vespa/storageframework/defaultimplementation/clock/realclock.h>
#include <vespa/storageframework/defaultimplementation/component/testcomponentregister.h>
#include <vespa/storageframework/generic/thread/tickingthread.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
-
-namespace storage {
-namespace framework {
-namespace defaultimplementation {
-
-struct TickingThreadTest : public CppUnit::TestFixture
-{
- void testTicksBeforeWaitBasic();
- void testTicksBeforeWaitLiveUpdate();
- void testDestroyWithoutStarting();
- void testVerboseStopping();
- void testStopOnDeletion();
- void testLockAllTicks();
- void testLockCriticalTicks();
- void testFailsOnStartWithoutThreads();
- void testBroadcast();
-
- CPPUNIT_TEST_SUITE(TickingThreadTest);
- CPPUNIT_TEST(testTicksBeforeWaitBasic);
- CPPUNIT_TEST(testTicksBeforeWaitLiveUpdate);
- CPPUNIT_TEST(testDestroyWithoutStarting);
- CPPUNIT_TEST(testVerboseStopping);
- CPPUNIT_TEST(testStopOnDeletion);
- CPPUNIT_TEST(testLockAllTicks);
- CPPUNIT_TEST(testLockCriticalTicks);
- CPPUNIT_TEST(testFailsOnStartWithoutThreads);
- CPPUNIT_TEST(testBroadcast);
- CPPUNIT_TEST_SUITE_END();
-};
+#include <vespa/vespalib/gtest/gtest.h>
+#include <vespa/vespalib/util/exception.h>
+#include <vespa/vespalib/util/stringfmt.h>
-CPPUNIT_TEST_SUITE_REGISTRATION(TickingThreadTest);
+namespace storage::framework::defaultimplementation {
namespace {
@@ -126,8 +97,7 @@ MyApp::~MyApp() { }
}
-void
-TickingThreadTest::testTicksBeforeWaitBasic()
+TEST(TickingThreadTest, test_ticks_before_wait_basic)
{
TestComponentRegister testReg(
ComponentRegisterImpl::UP(new ComponentRegisterImpl));
@@ -142,12 +112,11 @@ TickingThreadTest::testTicksBeforeWaitBasic()
FastOS_Thread::Sleep(1);
totalSleepMs++;
}
- CPPUNIT_ASSERT(totalSleepMs > 10);
+ EXPECT_GT(totalSleepMs, 10);
app._threadPool->stop();
}
-void
-TickingThreadTest::testTicksBeforeWaitLiveUpdate()
+TEST(TickingThreadTest, test_ticks_before_wait_live_update)
{
TestComponentRegister testReg(
ComponentRegisterImpl::UP(new ComponentRegisterImpl));
@@ -168,13 +137,12 @@ TickingThreadTest::testTicksBeforeWaitLiveUpdate()
FastOS_Thread::Sleep(1);
}
- CPPUNIT_ASSERT(maxAttempts>0);
- CPPUNIT_ASSERT(app.getTotalNonCritTicks() >= ticksBeforeWaitMs);
+ EXPECT_GT(maxAttempts, 0);
+ EXPECT_GE(app.getTotalNonCritTicks(), ticksBeforeWaitMs);
app._threadPool->stop();
}
-void
-TickingThreadTest::testDestroyWithoutStarting()
+TEST(TickingThreadTest, test_destroy_without_starting)
{
TestComponentRegister testReg(
ComponentRegisterImpl::UP(new ComponentRegisterImpl));
@@ -182,8 +150,7 @@ TickingThreadTest::testDestroyWithoutStarting()
MyApp app(threadCount, true);
}
-void
-TickingThreadTest::testVerboseStopping()
+TEST(TickingThreadTest, test_verbose_stopping)
{
TestComponentRegister testReg(
ComponentRegisterImpl::UP(new ComponentRegisterImpl));
@@ -196,8 +163,7 @@ TickingThreadTest::testVerboseStopping()
app._threadPool->stop();
}
-void
-TickingThreadTest::testStopOnDeletion()
+TEST(TickingThreadTest, test_stop_on_deletion)
{
TestComponentRegister testReg(
ComponentRegisterImpl::UP(new ComponentRegisterImpl));
@@ -209,8 +175,7 @@ TickingThreadTest::testStopOnDeletion()
}
}
-void
-TickingThreadTest::testLockAllTicks()
+TEST(TickingThreadTest, test_lock_all_ticks)
{
TestComponentRegister testReg(
ComponentRegisterImpl::UP(new ComponentRegisterImpl));
@@ -231,15 +196,14 @@ TickingThreadTest::testLockAllTicks()
while (app2.getMinCritTick() < 2 * ticks2 / threadCount) {
FastOS_Thread::Sleep(1);
}
- CPPUNIT_ASSERT_EQUAL(ticks1, app1.getTotalTicks());
+ EXPECT_EQ(ticks1, app1.getTotalTicks());
}
while (app1.getMinCritTick() < 2 * ticks1 / threadCount) {
FastOS_Thread::Sleep(1);
}
}
-void
-TickingThreadTest::testLockCriticalTicks()
+TEST(TickingThreadTest, test_lock_critical_ticks)
{
TestComponentRegister testReg(
ComponentRegisterImpl::UP(new ComponentRegisterImpl));
@@ -263,13 +227,12 @@ TickingThreadTest::testLockCriticalTicks()
for (int j=0; j<threadCount; ++j) {
++app._context[j]._critTickCount;
}
- CPPUNIT_ASSERT(!app.hasCritOverlap());
+ EXPECT_TRUE(!app.hasCritOverlap());
}
}
}
-void
-TickingThreadTest::testFailsOnStartWithoutThreads()
+TEST(TickingThreadTest, test_fails_on_start_without_threads)
{
TestComponentRegister testReg(
ComponentRegisterImpl::UP(new ComponentRegisterImpl));
@@ -277,11 +240,10 @@ TickingThreadTest::testFailsOnStartWithoutThreads()
MyApp app(threadCount, true);
try{
app.start(testReg.getThreadPoolImpl());
- CPPUNIT_FAIL("Expected starting without threads to fail");
+ FAIL() << "Expected starting without threads to fail";
} catch (vespalib::Exception& e) {
- CPPUNIT_ASSERT_EQUAL(vespalib::string(
- "Makes no sense to start threadpool without threads"),
- e.getMessage());
+ EXPECT_EQ(vespalib::string("Makes no sense to start threadpool without threads"),
+ e.getMessage());
}
}
@@ -349,9 +311,7 @@ BroadcastApp::~BroadcastApp() {}
}
-
-void
-TickingThreadTest::testBroadcast()
+TEST(TickingThreadTest, test_broadcast)
{
TestComponentRegister testReg(
ComponentRegisterImpl::UP(new ComponentRegisterImpl));
@@ -367,6 +327,4 @@ TickingThreadTest::testBroadcast()
FastOS_Thread::Sleep(1);
}
-} // defaultimplementation
-} // framework
-} // storage
+}