diff options
author | Geir Storli <geirst@yahooinc.com> | 2024-02-26 15:00:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-26 15:00:42 +0100 |
commit | fdb5bcf7c46b6f6453db8722acf10a9217c888d8 (patch) | |
tree | 0ac79a5be7a1b47f7aa6211faf87c5ed39e83b7d | |
parent | b1a8ba49de9863484cb71b6c7147a064fc677d19 (diff) | |
parent | 9ed632cfa0d9b8fd0e5d4f1e282cc24bf19b8e80 (diff) |
Merge pull request #30397 from vespa-engine/toregge/rewrite-event-barrier-unit-test-to-gtest
Rewrite event barrier unit test to gtest.
-rw-r--r-- | vespalib/src/tests/eventbarrier/CMakeLists.txt | 1 | ||||
-rw-r--r-- | vespalib/src/tests/eventbarrier/eventbarrier.cpp | 114 |
2 files changed, 44 insertions, 71 deletions
diff --git a/vespalib/src/tests/eventbarrier/CMakeLists.txt b/vespalib/src/tests/eventbarrier/CMakeLists.txt index 07911f740f2..e4ee14a1ed7 100644 --- a/vespalib/src/tests/eventbarrier/CMakeLists.txt +++ b/vespalib/src/tests/eventbarrier/CMakeLists.txt @@ -4,5 +4,6 @@ vespa_add_executable(vespalib_eventbarrier_test_app TEST eventbarrier.cpp DEPENDS vespalib + GTest::gtest ) vespa_add_test(NAME vespalib_eventbarrier_test_app COMMAND vespalib_eventbarrier_test_app) diff --git a/vespalib/src/tests/eventbarrier/eventbarrier.cpp b/vespalib/src/tests/eventbarrier/eventbarrier.cpp index c513809f6df..31db0e61fe7 100644 --- a/vespalib/src/tests/eventbarrier/eventbarrier.cpp +++ b/vespalib/src/tests/eventbarrier/eventbarrier.cpp @@ -1,7 +1,7 @@ // 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/eventbarrier.hpp> +#include <vespa/vespalib/gtest/gtest.h> using namespace vespalib; @@ -13,19 +13,7 @@ struct MyBarrier { } }; -class Test : public TestApp -{ -public: - void testEmpty(); - void testSimple(); - void testBarrierChain(); - void testEventAfter(); - void testReorder(); - int Main() override; -}; - -void -Test::testEmpty() +TEST(EventBarrierTest, test_empty) { // waiting for an empty set of events @@ -34,45 +22,43 @@ Test::testEmpty() EXPECT_TRUE(!eb.startBarrier(b)); EXPECT_TRUE(!b.done); - EXPECT_EQUAL(eb.countEvents(), 0u); - EXPECT_EQUAL(eb.countBarriers(), 0u); + EXPECT_EQ(eb.countEvents(), 0u); + EXPECT_EQ(eb.countBarriers(), 0u); uint32_t token = eb.startEvent(); eb.completeEvent(token); EXPECT_TRUE(!eb.startBarrier(b)); EXPECT_TRUE(!b.done); - EXPECT_EQUAL(eb.countEvents(), 0u); - EXPECT_EQUAL(eb.countBarriers(), 0u); + EXPECT_EQ(eb.countEvents(), 0u); + EXPECT_EQ(eb.countBarriers(), 0u); } -void -Test::testSimple() +TEST(EventBarrierTest, test_simple) { // a single barrier waiting for a single event MyBarrier b; EventBarrier<MyBarrier> eb; - EXPECT_EQUAL(eb.countEvents(), 0u); - EXPECT_EQUAL(eb.countBarriers(), 0u); + EXPECT_EQ(eb.countEvents(), 0u); + EXPECT_EQ(eb.countBarriers(), 0u); uint32_t token = eb.startEvent(); - EXPECT_EQUAL(eb.countEvents(), 1u); - EXPECT_EQUAL(eb.countBarriers(), 0u); + EXPECT_EQ(eb.countEvents(), 1u); + EXPECT_EQ(eb.countBarriers(), 0u); EXPECT_TRUE(eb.startBarrier(b)); EXPECT_TRUE(!b.done); - EXPECT_EQUAL(eb.countEvents(), 1u); - EXPECT_EQUAL(eb.countBarriers(), 1u); + EXPECT_EQ(eb.countEvents(), 1u); + EXPECT_EQ(eb.countBarriers(), 1u); eb.completeEvent(token); EXPECT_TRUE(b.done); - EXPECT_EQUAL(eb.countEvents(), 0u); - EXPECT_EQUAL(eb.countBarriers(), 0u); + EXPECT_EQ(eb.countEvents(), 0u); + EXPECT_EQ(eb.countBarriers(), 0u); } -void -Test::testBarrierChain() +TEST(EventBarriarTest, test_barrier_chain) { // more than one barrier waiting for the same set of events @@ -80,12 +66,12 @@ Test::testBarrierChain() MyBarrier b2; MyBarrier b3; EventBarrier<MyBarrier> eb; - EXPECT_EQUAL(eb.countEvents(), 0u); - EXPECT_EQUAL(eb.countBarriers(), 0u); + EXPECT_EQ(eb.countEvents(), 0u); + EXPECT_EQ(eb.countBarriers(), 0u); uint32_t token = eb.startEvent(); - EXPECT_EQUAL(eb.countEvents(), 1u); - EXPECT_EQUAL(eb.countBarriers(), 0u); + EXPECT_EQ(eb.countEvents(), 1u); + EXPECT_EQ(eb.countBarriers(), 0u); EXPECT_TRUE(eb.startBarrier(b1)); EXPECT_TRUE(eb.startBarrier(b2)); @@ -94,53 +80,51 @@ Test::testBarrierChain() EXPECT_TRUE(!b2.done); EXPECT_TRUE(!b3.done); - EXPECT_EQUAL(eb.countEvents(), 1u); - EXPECT_EQUAL(eb.countBarriers(), 3u); + EXPECT_EQ(eb.countEvents(), 1u); + EXPECT_EQ(eb.countBarriers(), 3u); eb.completeEvent(token); EXPECT_TRUE(b1.done); EXPECT_TRUE(b2.done); EXPECT_TRUE(b3.done); - EXPECT_EQUAL(eb.countEvents(), 0u); - EXPECT_EQUAL(eb.countBarriers(), 0u); + EXPECT_EQ(eb.countEvents(), 0u); + EXPECT_EQ(eb.countBarriers(), 0u); } -void -Test::testEventAfter() +TEST(EventBarrierTest, test_event_after) { // new events starting after the start of a barrier MyBarrier b; EventBarrier<MyBarrier> eb; - EXPECT_EQUAL(eb.countEvents(), 0u); - EXPECT_EQUAL(eb.countBarriers(), 0u); + EXPECT_EQ(eb.countEvents(), 0u); + EXPECT_EQ(eb.countBarriers(), 0u); uint32_t token = eb.startEvent(); - EXPECT_EQUAL(eb.countEvents(), 1u); - EXPECT_EQUAL(eb.countBarriers(), 0u); + EXPECT_EQ(eb.countEvents(), 1u); + EXPECT_EQ(eb.countBarriers(), 0u); EXPECT_TRUE(eb.startBarrier(b)); EXPECT_TRUE(!b.done); - EXPECT_EQUAL(eb.countEvents(), 1u); - EXPECT_EQUAL(eb.countBarriers(), 1u); + EXPECT_EQ(eb.countEvents(), 1u); + EXPECT_EQ(eb.countBarriers(), 1u); uint32_t t2 = eb.startEvent(); EXPECT_TRUE(!b.done); - EXPECT_EQUAL(eb.countEvents(), 2u); - EXPECT_EQUAL(eb.countBarriers(), 1u); + EXPECT_EQ(eb.countEvents(), 2u); + EXPECT_EQ(eb.countBarriers(), 1u); eb.completeEvent(token); EXPECT_TRUE(b.done); - EXPECT_EQUAL(eb.countEvents(), 1u); - EXPECT_EQUAL(eb.countBarriers(), 0u); + EXPECT_EQ(eb.countEvents(), 1u); + EXPECT_EQ(eb.countBarriers(), 0u); eb.completeEvent(t2); - EXPECT_EQUAL(eb.countEvents(), 0u); - EXPECT_EQUAL(eb.countBarriers(), 0u); + EXPECT_EQ(eb.countEvents(), 0u); + EXPECT_EQ(eb.countBarriers(), 0u); } -void -Test::testReorder() +TEST(EventBarriarTest, test_reorder) { // events completing in a different order than they started @@ -157,8 +141,8 @@ Test::testReorder() eb.startBarrier(b3); uint32_t t4 = eb.startEvent(); - EXPECT_EQUAL(eb.countEvents(), 4u); - EXPECT_EQUAL(eb.countBarriers(), 3u); + EXPECT_EQ(eb.countEvents(), 4u); + EXPECT_EQ(eb.countBarriers(), 3u); EXPECT_TRUE(!b1.done); EXPECT_TRUE(!b2.done); @@ -184,20 +168,8 @@ Test::testReorder() EXPECT_TRUE(b2.done); EXPECT_TRUE(b3.done); - EXPECT_EQUAL(eb.countEvents(), 0u); - EXPECT_EQUAL(eb.countBarriers(), 0u); -} - -int -Test::Main() -{ - TEST_INIT("eventbarrier_test"); - testEmpty(); - testSimple(); - testBarrierChain(); - testEventAfter(); - testReorder(); - TEST_DONE(); + EXPECT_EQ(eb.countEvents(), 0u); + EXPECT_EQ(eb.countBarriers(), 0u); } -TEST_APPHOOK(Test); +GTEST_MAIN_RUN_ALL_TESTS() |