[Openmp-commits] [openmp] a1b0db8 - [OpenMP][omptest] Add Dispatch equality operator (#162667)
via Openmp-commits
openmp-commits at lists.llvm.org
Wed Oct 15 08:46:30 PDT 2025
Author: Michael Halkenhäuser
Date: 2025-10-15T17:46:27+02:00
New Revision: a1b0db82cf5fdf0a2981877c9a939a8097393049
URL: https://github.com/llvm/llvm-project/commit/a1b0db82cf5fdf0a2981877c9a939a8097393049
DIFF: https://github.com/llvm/llvm-project/commit/a1b0db82cf5fdf0a2981877c9a939a8097393049.diff
LOG: [OpenMP][omptest] Add Dispatch equality operator (#162667)
Add equality op which checks 'Kind'
- For now this seems more reasonable than defaulting to true
Chose to keep toString and equality unit tests separate
Added:
openmp/tools/omptest/test/unittests/internal-event-eq-test.cpp
openmp/tools/omptest/test/unittests/internal-event-tostring-test.cpp
Modified:
openmp/tools/omptest/include/InternalEvent.h
openmp/tools/omptest/src/InternalEventOperators.cpp
Removed:
openmp/tools/omptest/test/unittests/internal-event-test.cpp
################################################################################
diff --git a/openmp/tools/omptest/include/InternalEvent.h b/openmp/tools/omptest/include/InternalEvent.h
index 1348c48f72005..743fad99ff4a0 100644
--- a/openmp/tools/omptest/include/InternalEvent.h
+++ b/openmp/tools/omptest/include/InternalEvent.h
@@ -371,6 +371,7 @@ struct BufferRecordDeallocation : public EventBase<BufferRecordDeallocation> {
// take precedence over the following default equality operator definition.
bool operator==(const ParallelBegin &, const ParallelBegin &);
bool operator==(const Work &, const Work &);
+bool operator==(const Dispatch &, const Dispatch &);
bool operator==(const ImplicitTask &, const ImplicitTask &);
bool operator==(const SyncRegion &, const SyncRegion &);
bool operator==(const Target &, const Target &);
diff --git a/openmp/tools/omptest/src/InternalEventOperators.cpp b/openmp/tools/omptest/src/InternalEventOperators.cpp
index 1ec33d574381f..dde64098ed31b 100644
--- a/openmp/tools/omptest/src/InternalEventOperators.cpp
+++ b/openmp/tools/omptest/src/InternalEventOperators.cpp
@@ -36,6 +36,11 @@ bool operator==(const Work &Expected, const Work &Observed) {
isSameTaskData && isSameCount;
}
+bool operator==(const Dispatch &Expected, const Dispatch &Observed) {
+ bool isSameKind = (Expected.Kind == Observed.Kind);
+ return isSameKind;
+}
+
bool operator==(const ImplicitTask &Expected, const ImplicitTask &Observed) {
bool isSameEndpoint = (Expected.Endpoint == Observed.Endpoint);
bool isSameActualParallelism =
diff --git a/openmp/tools/omptest/test/unittests/internal-event-eq-test.cpp b/openmp/tools/omptest/test/unittests/internal-event-eq-test.cpp
new file mode 100644
index 0000000000000..d30d6daecca5f
--- /dev/null
+++ b/openmp/tools/omptest/test/unittests/internal-event-eq-test.cpp
@@ -0,0 +1,65 @@
+#include "InternalEvent.h"
+#include <omp-tools.h>
+#include <sstream>
+
+#include "gtest/gtest.h"
+
+using namespace omptest;
+
+TEST(InternalEvent_equality_ops, Dispatch_identity) {
+ ompt_data_t DI{.value = 31};
+ internal::Dispatch D{/*ParallelData=*/(ompt_data_t *)0x11,
+ /*TaskData=*/(ompt_data_t *)0x22,
+ /*Kind=*/ompt_dispatch_t::ompt_dispatch_iteration,
+ /*Instance=*/DI};
+
+ EXPECT_EQ(D == D, true);
+}
+
+TEST(InternalEvent_equality_ops, Dispatch_same) {
+ ompt_data_t DI{.ptr = (void *)0x33};
+ internal::Dispatch D1{/*ParallelData=*/(ompt_data_t *)0x11,
+ /*TaskData=*/(ompt_data_t *)0x22,
+ /*Kind=*/ompt_dispatch_t::ompt_dispatch_section,
+ /*Instance=*/DI};
+
+ internal::Dispatch D2{/*ParallelData=*/(ompt_data_t *)0x11,
+ /*TaskData=*/(ompt_data_t *)0x22,
+ /*Kind=*/ompt_dispatch_t::ompt_dispatch_section,
+ /*Instance=*/DI};
+
+ EXPECT_EQ(D1 == D2, true);
+}
+
+TEST(InternalEvent_equality_ops, Dispatch_
diff erent_kind) {
+ ompt_data_t DI{.ptr = (void *)0x33};
+ internal::Dispatch D1{/*ParallelData=*/(ompt_data_t *)0x11,
+ /*TaskData=*/(ompt_data_t *)0x22,
+ /*Kind=*/ompt_dispatch_t::ompt_dispatch_section,
+ /*Instance=*/DI};
+
+ internal::Dispatch D2{/*ParallelData=*/(ompt_data_t *)0x11,
+ /*TaskData=*/(ompt_data_t *)0x22,
+ /*Kind=*/ompt_dispatch_t::ompt_dispatch_iteration,
+ /*Instance=*/DI};
+
+ // Demonstrate that 'Kind' is the only relevant field for equality.
+ EXPECT_EQ(D1 == D2, false);
+}
+
+TEST(InternalEvent_equality_ops, Dispatch_same_kind_
diff erent_other) {
+ ompt_data_t DI1{.ptr = (void *)0x33};
+ internal::Dispatch D1{/*ParallelData=*/(ompt_data_t *)0x11,
+ /*TaskData=*/(ompt_data_t *)0x22,
+ /*Kind=*/ompt_dispatch_t::ompt_dispatch_section,
+ /*Instance=*/DI1};
+
+ ompt_data_t DI2{.ptr = (void *)0x66};
+ internal::Dispatch D2{/*ParallelData=*/(ompt_data_t *)0x44,
+ /*TaskData=*/(ompt_data_t *)0x55,
+ /*Kind=*/ompt_dispatch_t::ompt_dispatch_section,
+ /*Instance=*/DI2};
+
+ // Demonstrate that 'Kind' is the only relevant field for equality.
+ EXPECT_EQ(D1 == D2, true);
+}
diff --git a/openmp/tools/omptest/test/unittests/internal-event-test.cpp b/openmp/tools/omptest/test/unittests/internal-event-tostring-test.cpp
similarity index 100%
rename from openmp/tools/omptest/test/unittests/internal-event-test.cpp
rename to openmp/tools/omptest/test/unittests/internal-event-tostring-test.cpp
More information about the Openmp-commits
mailing list