[llvm] [orc-rt] Support multiple copies of OpCounter unittest utility. (PR #161985)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 4 17:58:09 PDT 2025
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/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.
>From c47f16a3309a67ad4cea4f0e30994f282525f781 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Sun, 5 Oct 2025 11:44:08 +1100
Subject: [PATCH] [orc-rt] Support multiple copies of OpCounter unittest
utility.
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.
---
orc-rt/unittests/CMakeLists.txt | 1 -
orc-rt/unittests/CommonTestUtils.cpp | 20 --------------------
orc-rt/unittests/CommonTestUtils.h | 9 ++++++++-
orc-rt/unittests/bind-test.cpp | 26 +++++++++++++-------------
4 files changed, 21 insertions(+), 35 deletions(-)
delete mode 100644 orc-rt/unittests/CommonTestUtils.cpp
diff --git a/orc-rt/unittests/CMakeLists.txt b/orc-rt/unittests/CMakeLists.txt
index 54c453de3a97f..4d3da682d4222 100644
--- a/orc-rt/unittests/CMakeLists.txt
+++ b/orc-rt/unittests/CMakeLists.txt
@@ -15,7 +15,6 @@ add_orc_rt_unittest(CoreTests
AllocActionTest.cpp
BitmaskEnumTest.cpp
CallableTraitsHelperTest.cpp
- CommonTestUtils.cpp
ErrorTest.cpp
ExecutorAddressTest.cpp
IntervalMapTest.cpp
diff --git a/orc-rt/unittests/CommonTestUtils.cpp b/orc-rt/unittests/CommonTestUtils.cpp
deleted file mode 100644
index d9f9433d167fd..0000000000000
--- a/orc-rt/unittests/CommonTestUtils.cpp
+++ /dev/null
@@ -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;
diff --git a/orc-rt/unittests/CommonTestUtils.h b/orc-rt/unittests/CommonTestUtils.h
index 5ff2c8e6e8989..1c66bddaf75be 100644
--- a/orc-rt/unittests/CommonTestUtils.h
+++ b/orc-rt/unittests/CommonTestUtils.h
@@ -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 @@ class OpCounter {
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
diff --git a/orc-rt/unittests/bind-test.cpp b/orc-rt/unittests/bind-test.cpp
index bfaef4e9c1ebe..93a61e6387b49 100644
--- a/orc-rt/unittests/bind-test.cpp
+++ b/orc-rt/unittests/bind-test.cpp
@@ -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) {
More information about the llvm-commits
mailing list