24std::mutex OmptAsserter::StaticMemberAccessMutex;
25std::weak_ptr<OmptEventGroupInterface>
26 OmptAsserter::EventGroupInterfaceInstance;
27std::weak_ptr<logging::Logger> OmptAsserter::LoggingInstance;
31 std::lock_guard<std::mutex> Lock(StaticMemberAccessMutex);
39 EventGroups = std::make_shared<OmptEventGroupInterface>();
49 Log = LoggingInstance.lock();
53 Log = std::make_shared<logging::Logger>();
55 LoggingInstance =
Log;
66 return SuppressedEvents.find(EvTy) != SuppressedEvents.end();
72 SuppressedEvents.insert(EvTy);
76 assert(
false &&
"Base class 'insert' has undefined semantics.");
91 assert(ExpectedEvent.getEventType() == ObservedEvent.getEventType() &&
92 "Type mismatch: Expected != Observed event type");
93 assert(
EventGroups &&
"Missing EventGroups interface");
96 auto GroupName = ExpectedEvent.getEventGroup();
98 if (GroupName ==
"default")
102 auto Event = ObservedEvent.getEvent();
104 switch (Event->Type) {
105 case EventTy::Target:
107 if (E->Endpoint == ompt_scope_begin) {
111 }
else if (E->Endpoint == ompt_scope_end) {
118 case EventTy::TargetEmi:
120 if (E->Endpoint == ompt_scope_begin) {
124 }
else if (E->Endpoint == ompt_scope_end) {
131 case EventTy::TargetDataOp:
133 return EventGroups->checkActiveEventGroups(GroupName,
137 case EventTy::TargetDataOpEmi:
143 case EventTy::TargetSubmit:
145 return EventGroups->checkActiveEventGroups(GroupName,
149 case EventTy::TargetSubmitEmi:
155 case EventTy::BufferRecord:
164 case EventTy::ThreadBegin:
165 case EventTy::ThreadEnd:
166 case EventTy::ParallelBegin:
167 case EventTy::ParallelEnd:
169 case EventTy::Dispatch:
170 case EventTy::TaskCreate:
171 case EventTy::Dependences:
172 case EventTy::TaskDependence:
173 case EventTy::TaskSchedule:
174 case EventTy::ImplicitTask:
175 case EventTy::Masked:
176 case EventTy::SyncRegion:
177 case EventTy::MutexAcquire:
179 case EventTy::NestLock:
181 case EventTy::Cancel:
182 case EventTy::DeviceInitialize:
183 case EventTy::DeviceFinalize:
184 case EventTy::DeviceLoad:
185 case EventTy::DeviceUnload:
186 case EventTy::BufferRequest:
187 case EventTy::BufferComplete:
188 case EventTy::BufferRecordDeallocation:
192 case EventTy::AssertionSyncPoint:
193 case EventTy::AssertionSuspend:
195 Log->log(
"Observed invalid event type: " + Event->toString(),
197 __builtin_unreachable();
207 Events.emplace_back(std::move(AE));
234 Log->logEventMismatch(
"[OmptSequencedAsserter] The events are not equal",
244 if (NumRemainingEvents == 0)
247 Log->logEventMismatch(
248 "[OmptSequencedAsserter] Encountered SyncPoint while still awaiting " +
249 std::to_string(NumRemainingEvents) +
" events. Asserted " +
251 std::to_string(
Events.size()) +
" events successfully.",
268 Log->logEventMismatch(
269 "[OmptSequencedAsserter] Too many events to check (" +
272 std::to_string(
Events.size()) +
" events successfully.",
286 while (
Events[
NextEvent].getEventType() == EventTy::AssertionSuspend) {
306 Log->logEventMismatch(
307 "[OmptSequencedAsserter] Encountered forbidden event", E, AE);
327 return E.getEventExpectedState() ==
328 ObserveState::Always;
342 Log->logEventMismatch(
"[OmptSequencedAsserter] Expected event was not "
343 "encountered (Remaining events: " +
355 Events.emplace_back(std::move(AE));
368 if (AE.getEventType() == EventTy::AssertionSyncPoint) {
371 if (NumRemainingEvents == 0)
374 Log->logEventMismatch(
375 "[OmptEventAsserter] Encountered SyncPoint while still awaiting " +
376 std::to_string(NumRemainingEvents) +
" events. Asserted " +
383 for (
size_t i = 0;
i <
Events.size(); ++
i) {
390 Log->logEventMismatch(
"[OmptEventAsserter] Encountered forbidden event",
399 Log->logEventMismatch(
"[OmptEventAsserter] Too many events to check (" +
403 " events successfully. (Remaining events: " +
412 return std::count_if(
414 return E.getEventExpectedState() == ObserveState::Always;
421 for (
const auto &E :
Events) {
425 Log->logEventMismatch(
"[OmptEventAsserter] Expected event was not "
426 "encountered (Remaining events: " +
441 auto Notification{AE.toString()};
442 Notification.push_back(
'\n');
443 OutStream << Notification;
448 std::lock_guard<std::mutex> Lock(GroupMutex);
449 auto EventGroup = ActiveEventGroups.find(GroupName);
450 if (EventGroup != ActiveEventGroups.end() &&
453 ActiveEventGroups.emplace(GroupName, Group);
458 const std::string &GroupName) {
459 std::lock_guard<std::mutex> Lock(GroupMutex);
460 auto EventGroup = ActiveEventGroups.find(GroupName);
461 auto DeprecatedEventGroup = DeprecatedEventGroups.find(GroupName);
462 if (EventGroup == ActiveEventGroups.end() &&
463 DeprecatedEventGroup != DeprecatedEventGroups.end())
465 DeprecatedEventGroups.emplace(GroupName, EventGroup->second);
466 ActiveEventGroups.erase(GroupName);
472 std::lock_guard<std::mutex> Lock(GroupMutex);
473 auto EventGroup = ActiveEventGroups.find(GroupName);
474 return (EventGroup != ActiveEventGroups.end() &&
480 std::lock_guard<std::mutex> Lock(GroupMutex);
481 auto EventGroup = DeprecatedEventGroups.find(GroupName);
482 return (EventGroup != DeprecatedEventGroups.end() &&
Provides ompTest-tailored logging, with log-levels and formatting/coloring.
Contains all asserter-related class declarations and important enums.
virtual omptest::AssertState checkState()
Determine and return the asserter's state.
std::shared_ptr< OmptEventGroupInterface > EventGroups
Pointer to the OmptEventGroupInterface.
AssertMode OperationMode
Operation mode during assertion / notification.
std::mutex AssertMutex
Mutex to avoid data races w.r.t. event notifications and/or insertions.
int NumNotifications
The total number of effective notifications.
void notify(omptest::OmptAssertEvent &&AE) override
Called from the CallbackHandler with a corresponding AssertEvent to which callback was handled.
virtual void insert(omptest::OmptAssertEvent &&AE)
Add an event to the asserter's internal data structure.
virtual void notifyImpl(omptest::OmptAssertEvent &&AE)=0
Implemented in subclasses to implement what should actually be done with the notification.
int NumSuccessfulAsserts
The number of successful assertion checks.
void setOperationMode(AssertMode Mode)
Set the asserter's mode of operation w.r.t. assertion.
bool verifyEventGroups(const omptest::OmptAssertEvent &ExpectedEvent, const omptest::OmptAssertEvent &ObservedEvent)
Check the observed events' group association.
std::shared_ptr< logging::Logger > Log
Pointer to the logging instance.
omptest::AssertState State
The asserter's current state.
bool checkActiveEventGroups(const std::string &GroupName, omptest::AssertEventGroup Group)
Check if given group is currently part of the active event groups.
bool checkDeprecatedEventGroups(const std::string &GroupName, omptest::AssertEventGroup Group)
Check if given group is currently part of the deprecated event groups.
bool addActiveEventGroup(const std::string &GroupName, omptest::AssertEventGroup Group)
Add given group to the set of active event groups.
bool deprecateActiveEventGroup(const std::string &GroupName)
Move given group from the set of active event groups to the set of previously active event groups.
void notify(omptest::OmptAssertEvent &&AE) override
Called from the CallbackHandler with a corresponding AssertEvent to which callback was handled.
void suppressEvent(omptest::internal::EventTy EvTy)
Add the given event type to the set of suppressed events.
bool isSuppressedEventType(omptest::internal::EventTy EvTy)
Check if the given event type is from the set of suppressed event types.
void permitEvent(omptest::internal::EventTy EvTy)
Remove the given event type to the set of suppressed events.
void setActive(bool Enabled)
Control whether this asserter should be considered 'active'.
bool isActive()
Check if this asserter is considered 'active'.
size_t getRemainingEventCount() override
Get the number of currently remaining events, with: ObserveState::Always.
bool consumeSuspend()
Notification helper function, implementing Suspend logic.
bool consumeRegularEvent(const omptest::OmptAssertEvent &AE)
Notification helper function, implementing regular event notification logic.
void insert(omptest::OmptAssertEvent &&AE) override
Add the event to the in-sequence set of events that the asserter should check for.
bool consumeSyncPoint(const omptest::OmptAssertEvent &AE)
Notification helper function, implementing SyncPoint logic.
virtual void notifyImpl(omptest::OmptAssertEvent &&AE) override
Implements the asserter's actual logic.
omptest::AssertState checkState() override
Determine and return the asserter's state.
size_t NextEvent
Index of the next, expected event.
bool checkExcessNotify(const omptest::OmptAssertEvent &AE)
Notification helper function, implementing excess event notification logic.
std::vector< omptest::OmptAssertEvent > Events
EventTy
Enum values are used for comparison of observed and asserted events List is based on OpenMP 5....
POD type, which holds the target region id, corresponding to an event group.
Assertion event struct, provides statically callable CTORs.
internal::EventTy getEventType() const
Return the actual event type enum value.
virtual void notifyImpl(omptest::OmptAssertEvent &&AE) override
Implements the asserter's logic.
size_t getRemainingEventCount() override
Get the number of currently remaining events, with: ObserveState::Always.
void insert(omptest::OmptAssertEvent &&AE) override
Add the event to the set of events that the asserter should check for.
omptest::AssertState checkState() override
Determine and return the asserter's state.
std::vector< omptest::OmptAssertEvent > Events
For now use vector (but do set semantics)