aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib/src/tests')
-rw-r--r--vespalib/src/tests/array/CMakeLists.txt1
-rw-r--r--vespalib/src/tests/array/sort_benchmark.cpp46
-rw-r--r--vespalib/src/tests/bits/CMakeLists.txt1
-rw-r--r--vespalib/src/tests/bits/bits_test.cpp37
4 files changed, 52 insertions, 33 deletions
diff --git a/vespalib/src/tests/array/CMakeLists.txt b/vespalib/src/tests/array/CMakeLists.txt
index 3f08aa07b4d..11e81cc42ce 100644
--- a/vespalib/src/tests/array/CMakeLists.txt
+++ b/vespalib/src/tests/array/CMakeLists.txt
@@ -11,5 +11,6 @@ vespa_add_executable(vespalib_sort_benchmark_app
sort_benchmark.cpp
DEPENDS
vespalib
+ GTest::gtest
)
vespa_add_test(NAME vespalib_sort_benchmark_app COMMAND vespalib_sort_benchmark_app BENCHMARK)
diff --git a/vespalib/src/tests/array/sort_benchmark.cpp b/vespalib/src/tests/array/sort_benchmark.cpp
index ba95c663332..db5c3c80f5f 100644
--- a/vespalib/src/tests/array/sort_benchmark.cpp
+++ b/vespalib/src/tests/array/sort_benchmark.cpp
@@ -1,6 +1,6 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/util/rusage.h>
+#include <vespa/vespalib/gtest/gtest.h>
#include <vespa/vespalib/util/array.hpp>
#include <csignal>
#include <algorithm>
@@ -10,19 +10,32 @@ LOG_SETUP("sort_benchmark");
using namespace vespalib;
-class Test : public TestApp
+class SortBenchmark : public ::testing::Test
{
+ int _argc;
+ char** _argv;
public:
-private:
+ SortBenchmark(int argc, char **argv);
+ ~SortBenchmark() override;
+ void TestBody() override;
+protected:
template<typename T>
vespalib::Array<T> create(size_t count);
template<typename T>
void sortDirect(size_t count);
template<typename T>
void sortInDirect(size_t count);
- int Main() override;
};
+SortBenchmark::SortBenchmark(int argc, char** argv)
+ : testing::Test(),
+ _argc(argc),
+ _argv(argv)
+{
+}
+
+SortBenchmark::~SortBenchmark() = default;
+
template<size_t N>
class TT
{
@@ -46,7 +59,7 @@ private:
template<typename T>
vespalib::Array<T>
-Test::create(size_t count)
+SortBenchmark::create(size_t count)
{
vespalib::Array<T> v;
v.reserve(count);
@@ -58,7 +71,7 @@ Test::create(size_t count)
}
template<typename T>
-void Test::sortDirect(size_t count)
+void SortBenchmark::sortDirect(size_t count)
{
vespalib::Array<T> v(create<T>(count));
LOG(info, "Running sortDirect with %ld count and payload of %ld", v.size(), sizeof(T));
@@ -69,7 +82,7 @@ void Test::sortDirect(size_t count)
}
template<typename T>
-void Test::sortInDirect(size_t count)
+void SortBenchmark::sortInDirect(size_t count)
{
vespalib::Array<T> k(create<T>(count));
LOG(info, "Running sortInDirect with %ld count and payload of %ld", k.size(), sizeof(T));
@@ -84,8 +97,8 @@ void Test::sortInDirect(size_t count)
}
}
-int
-Test::Main()
+void
+SortBenchmark::TestBody()
{
std::string type("sortdirect");
size_t count = 1000000;
@@ -99,8 +112,7 @@ Test::Main()
if (_argc > 3) {
payLoad = strtol(_argv[3], NULL, 0);
}
- TEST_INIT("sort_benchmark");
- steady_time start(steady_clock::now());
+ steady_time start(steady_clock::now());
if (payLoad < 8) {
using T = TT<8>;
if (type == "sortdirect") {
@@ -176,9 +188,13 @@ Test::Main()
}
}
LOG(info, "rusage = {\n%s\n}", vespalib::RUsage::createSelf(start).toString().c_str());
- ASSERT_EQUAL(0, kill(0, SIGPROF));
- TEST_DONE();
+ ASSERT_EQ(0, kill(0, SIGPROF));
}
-TEST_APPHOOK(Test);
-
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ ::testing::RegisterTest("SortBenchmark", "benchmark", nullptr, "",
+ __FILE__, __LINE__,
+ [=]() -> SortBenchmark* { return new SortBenchmark(argc, argv); });
+ return RUN_ALL_TESTS();
+}
diff --git a/vespalib/src/tests/bits/CMakeLists.txt b/vespalib/src/tests/bits/CMakeLists.txt
index 71a977a295a..3ba0c6afc1c 100644
--- a/vespalib/src/tests/bits/CMakeLists.txt
+++ b/vespalib/src/tests/bits/CMakeLists.txt
@@ -4,5 +4,6 @@ vespa_add_executable(vespalib_bits_test_app TEST
bits_test.cpp
DEPENDS
vespalib
+ GTest::gtest
)
vespa_add_test(NAME vespalib_bits_test_app COMMAND vespalib_bits_test_app)
diff --git a/vespalib/src/tests/bits/bits_test.cpp b/vespalib/src/tests/bits/bits_test.cpp
index 6341477c2a7..6b01b2cd63a 100644
--- a/vespalib/src/tests/bits/bits_test.cpp
+++ b/vespalib/src/tests/bits/bits_test.cpp
@@ -1,23 +1,25 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/util/bits.h>
+#include <vespa/vespalib/gtest/gtest.h>
using namespace vespalib;
-class Test : public TestApp
+class BitsTest : public ::testing::Test
{
-public:
- int Main() override;
+protected:
+ BitsTest();
+ ~BitsTest() override;
template <typename T>
void testFixed(const T * v, size_t sz, const T * exp);
void testBuffer();
};
-int
-Test::Main()
+BitsTest::BitsTest() = default;
+BitsTest::~BitsTest() = default;
+
+TEST_F(BitsTest, test_bits)
{
- TEST_INIT("bits_test");
uint8_t u8[5] = { 0, 0x1, 0x7f, 0x87, 0xff };
uint8_t exp8[5] = { 0, 0x80, 0xfe, 0xe1, 0xff };
testFixed(u8, sizeof(u8)/sizeof(u8[0]), exp8);
@@ -31,29 +33,28 @@ Test::Main()
uint64_t exp64[5] = { 0, 0x8000000000000000, 0xfe00000000000000, 0xe100000000000000, 0xff00000000000000 };
testFixed(u64, sizeof(u64)/sizeof(u64[0]), exp64);
testBuffer();
- TEST_DONE();
}
template <typename T>
-void Test::testFixed(const T * v, size_t sz, const T * exp)
+void BitsTest::testFixed(const T * v, size_t sz, const T * exp)
{
- EXPECT_EQUAL(0u, Bits::reverse(static_cast<T>(0)));
- EXPECT_EQUAL(1ul << (sizeof(T)*8 - 1), Bits::reverse(static_cast<T>(1)));
- EXPECT_EQUAL(static_cast<T>(-1), Bits::reverse(static_cast<T>(-1)));
+ EXPECT_EQ(0u, Bits::reverse(static_cast<T>(0)));
+ EXPECT_EQ(1ul << (sizeof(T)*8 - 1), Bits::reverse(static_cast<T>(1)));
+ EXPECT_EQ(static_cast<T>(-1), Bits::reverse(static_cast<T>(-1)));
for (size_t i(0); i < sz; i++) {
- EXPECT_EQUAL(Bits::reverse(v[i]), exp[i]);
- EXPECT_EQUAL(Bits::reverse(Bits::reverse(v[i])), v[i]);
+ EXPECT_EQ(Bits::reverse(v[i]), exp[i]);
+ EXPECT_EQ(Bits::reverse(Bits::reverse(v[i])), v[i]);
}
}
-void Test::testBuffer()
+void BitsTest::testBuffer()
{
uint64_t a(0x0102040810204080ul);
uint64_t b(a);
Bits::reverse(&a, sizeof(a));
- EXPECT_EQUAL(a, Bits::reverse(b));
+ EXPECT_EQ(a, Bits::reverse(b));
Bits::reverse(&a, sizeof(a));
- EXPECT_EQUAL(a, b);
+ EXPECT_EQ(a, b);
}
-TEST_APPHOOK(Test)
+GTEST_MAIN_RUN_ALL_TESTS()