Skip to content

Commit a1b0db8

Browse files
authored
[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
1 parent 5e668fe commit a1b0db8

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

openmp/tools/omptest/include/InternalEvent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ struct BufferRecordDeallocation : public EventBase<BufferRecordDeallocation> {
371371
// take precedence over the following default equality operator definition.
372372
bool operator==(const ParallelBegin &, const ParallelBegin &);
373373
bool operator==(const Work &, const Work &);
374+
bool operator==(const Dispatch &, const Dispatch &);
374375
bool operator==(const ImplicitTask &, const ImplicitTask &);
375376
bool operator==(const SyncRegion &, const SyncRegion &);
376377
bool operator==(const Target &, const Target &);

openmp/tools/omptest/src/InternalEventOperators.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ bool operator==(const Work &Expected, const Work &Observed) {
3636
isSameTaskData && isSameCount;
3737
}
3838

39+
bool operator==(const Dispatch &Expected, const Dispatch &Observed) {
40+
bool isSameKind = (Expected.Kind == Observed.Kind);
41+
return isSameKind;
42+
}
43+
3944
bool operator==(const ImplicitTask &Expected, const ImplicitTask &Observed) {
4045
bool isSameEndpoint = (Expected.Endpoint == Observed.Endpoint);
4146
bool isSameActualParallelism =
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include "InternalEvent.h"
2+
#include <omp-tools.h>
3+
#include <sstream>
4+
5+
#include "gtest/gtest.h"
6+
7+
using namespace omptest;
8+
9+
TEST(InternalEvent_equality_ops, Dispatch_identity) {
10+
ompt_data_t DI{.value = 31};
11+
internal::Dispatch D{/*ParallelData=*/(ompt_data_t *)0x11,
12+
/*TaskData=*/(ompt_data_t *)0x22,
13+
/*Kind=*/ompt_dispatch_t::ompt_dispatch_iteration,
14+
/*Instance=*/DI};
15+
16+
EXPECT_EQ(D == D, true);
17+
}
18+
19+
TEST(InternalEvent_equality_ops, Dispatch_same) {
20+
ompt_data_t DI{.ptr = (void *)0x33};
21+
internal::Dispatch D1{/*ParallelData=*/(ompt_data_t *)0x11,
22+
/*TaskData=*/(ompt_data_t *)0x22,
23+
/*Kind=*/ompt_dispatch_t::ompt_dispatch_section,
24+
/*Instance=*/DI};
25+
26+
internal::Dispatch D2{/*ParallelData=*/(ompt_data_t *)0x11,
27+
/*TaskData=*/(ompt_data_t *)0x22,
28+
/*Kind=*/ompt_dispatch_t::ompt_dispatch_section,
29+
/*Instance=*/DI};
30+
31+
EXPECT_EQ(D1 == D2, true);
32+
}
33+
34+
TEST(InternalEvent_equality_ops, Dispatch_different_kind) {
35+
ompt_data_t DI{.ptr = (void *)0x33};
36+
internal::Dispatch D1{/*ParallelData=*/(ompt_data_t *)0x11,
37+
/*TaskData=*/(ompt_data_t *)0x22,
38+
/*Kind=*/ompt_dispatch_t::ompt_dispatch_section,
39+
/*Instance=*/DI};
40+
41+
internal::Dispatch D2{/*ParallelData=*/(ompt_data_t *)0x11,
42+
/*TaskData=*/(ompt_data_t *)0x22,
43+
/*Kind=*/ompt_dispatch_t::ompt_dispatch_iteration,
44+
/*Instance=*/DI};
45+
46+
// Demonstrate that 'Kind' is the only relevant field for equality.
47+
EXPECT_EQ(D1 == D2, false);
48+
}
49+
50+
TEST(InternalEvent_equality_ops, Dispatch_same_kind_different_other) {
51+
ompt_data_t DI1{.ptr = (void *)0x33};
52+
internal::Dispatch D1{/*ParallelData=*/(ompt_data_t *)0x11,
53+
/*TaskData=*/(ompt_data_t *)0x22,
54+
/*Kind=*/ompt_dispatch_t::ompt_dispatch_section,
55+
/*Instance=*/DI1};
56+
57+
ompt_data_t DI2{.ptr = (void *)0x66};
58+
internal::Dispatch D2{/*ParallelData=*/(ompt_data_t *)0x44,
59+
/*TaskData=*/(ompt_data_t *)0x55,
60+
/*Kind=*/ompt_dispatch_t::ompt_dispatch_section,
61+
/*Instance=*/DI2};
62+
63+
// Demonstrate that 'Kind' is the only relevant field for equality.
64+
EXPECT_EQ(D1 == D2, true);
65+
}

0 commit comments

Comments
 (0)