[orc-rt] Support multiple copies of OpCounter unittest utility. (#161985)
This commit templatizes OpCounter with a size_t argument, allowing multiple copies of OpCounter to be easily created. This functionality will be used in upcoming unit tests that need to count operations on several types at once.
This commit is contained in:
@@ -15,7 +15,6 @@ add_orc_rt_unittest(CoreTests
|
||||
AllocActionTest.cpp
|
||||
BitmaskEnumTest.cpp
|
||||
CallableTraitsHelperTest.cpp
|
||||
CommonTestUtils.cpp
|
||||
ErrorTest.cpp
|
||||
ExecutorAddressTest.cpp
|
||||
IntervalMapTest.cpp
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
//===- CommonTestUtils.cpp ------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Common test utilities.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CommonTestUtils.h"
|
||||
|
||||
size_t OpCounter::DefaultConstructions = 0;
|
||||
size_t OpCounter::CopyConstructions = 0;
|
||||
size_t OpCounter::CopyAssignments = 0;
|
||||
size_t OpCounter::MoveConstructions = 0;
|
||||
size_t OpCounter::MoveAssignments = 0;
|
||||
size_t OpCounter::Destructions = 0;
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
class OpCounter {
|
||||
template <size_t Idx = 0> class OpCounter {
|
||||
public:
|
||||
OpCounter() { ++DefaultConstructions; }
|
||||
OpCounter(const OpCounter &Other) { ++CopyConstructions; }
|
||||
@@ -57,4 +57,11 @@ private:
|
||||
static size_t Destructions;
|
||||
};
|
||||
|
||||
template <size_t Idx> size_t OpCounter<Idx>::DefaultConstructions = 0;
|
||||
template <size_t Idx> size_t OpCounter<Idx>::CopyConstructions = 0;
|
||||
template <size_t Idx> size_t OpCounter<Idx>::CopyAssignments = 0;
|
||||
template <size_t Idx> size_t OpCounter<Idx>::MoveConstructions = 0;
|
||||
template <size_t Idx> size_t OpCounter<Idx>::MoveAssignments = 0;
|
||||
template <size_t Idx> size_t OpCounter<Idx>::Destructions = 0;
|
||||
|
||||
#endif // ORC_RT_UNITTEST_COMMONTESTUTILS_H
|
||||
|
||||
@@ -47,28 +47,28 @@ TEST(BindTest, LambdaCapture) {
|
||||
}
|
||||
|
||||
TEST(BindTest, MinimalMoves) {
|
||||
OpCounter::reset();
|
||||
OpCounter<>::reset();
|
||||
{
|
||||
auto B = bind_front([](OpCounter &O, int) {}, OpCounter());
|
||||
auto B = bind_front([](OpCounter<> &O, int) {}, OpCounter<>());
|
||||
B(0);
|
||||
}
|
||||
EXPECT_EQ(OpCounter::defaultConstructions(), 1U);
|
||||
EXPECT_EQ(OpCounter::copies(), 0U);
|
||||
EXPECT_EQ(OpCounter::moves(), 1U);
|
||||
EXPECT_EQ(OpCounter::destructions(), 2U);
|
||||
EXPECT_EQ(OpCounter<>::defaultConstructions(), 1U);
|
||||
EXPECT_EQ(OpCounter<>::copies(), 0U);
|
||||
EXPECT_EQ(OpCounter<>::moves(), 1U);
|
||||
EXPECT_EQ(OpCounter<>::destructions(), 2U);
|
||||
}
|
||||
|
||||
TEST(BindTest, MinimalCopies) {
|
||||
OpCounter::reset();
|
||||
OpCounter<>::reset();
|
||||
{
|
||||
OpCounter O;
|
||||
auto B = bind_front([](OpCounter &O, int) {}, O);
|
||||
OpCounter<> O;
|
||||
auto B = bind_front([](OpCounter<> &O, int) {}, O);
|
||||
B(0);
|
||||
}
|
||||
EXPECT_EQ(OpCounter::defaultConstructions(), 1U);
|
||||
EXPECT_EQ(OpCounter::copies(), 1U);
|
||||
EXPECT_EQ(OpCounter::moves(), 0U);
|
||||
EXPECT_EQ(OpCounter::destructions(), 2U);
|
||||
EXPECT_EQ(OpCounter<>::defaultConstructions(), 1U);
|
||||
EXPECT_EQ(OpCounter<>::copies(), 1U);
|
||||
EXPECT_EQ(OpCounter<>::moves(), 0U);
|
||||
EXPECT_EQ(OpCounter<>::destructions(), 2U);
|
||||
}
|
||||
|
||||
TEST(BindTest, ForwardUnboundArgs) {
|
||||
|
||||
Reference in New Issue
Block a user