From 4bcf5995377c61c28e8b80ab6efc1f206edf7cff 2017-12-19 14:14:49 From: Alexandre Leroux Date: 2017-12-19 14:14:49 Subject: [PATCH] Implements canExecute() method of syn/desync operations --- diff --git a/plugins/amda/tests/FuzzingDefs.cpp b/plugins/amda/tests/FuzzingDefs.cpp index 4cc54cf..b4f80f7 100644 --- a/plugins/amda/tests/FuzzingDefs.cpp +++ b/plugins/amda/tests/FuzzingDefs.cpp @@ -36,3 +36,15 @@ VariableState &FuzzingState::variableState(VariableId id) return m_VariablesPool.at(id); } +SyncGroupId FuzzingState::syncGroupId(VariableId variableId) const +{ + auto end = m_SyncGroupsPool.cend(); + auto it + = std::find_if(m_SyncGroupsPool.cbegin(), end, [&variableId](const auto &syncGroupEntry) { + const auto &syncGroup = syncGroupEntry.second; + return syncGroup.m_Variables.find(variableId) != syncGroup.m_Variables.end(); + }); + + return it != end ? it->first : SyncGroupId{}; +} + diff --git a/plugins/amda/tests/FuzzingDefs.h b/plugins/amda/tests/FuzzingDefs.h index 965b7a7..b488421 100644 --- a/plugins/amda/tests/FuzzingDefs.h +++ b/plugins/amda/tests/FuzzingDefs.h @@ -93,6 +93,10 @@ struct FuzzingState { const VariableState &variableState(VariableId id) const; VariableState &variableState(VariableId id); + /// @return the identifier of the synchronization group in which the variable passed in + /// parameter is located. If the variable is not in any group, returns an invalid identifier + SyncGroupId syncGroupId(VariableId variableId) const; + VariablesPool m_VariablesPool; SyncGroupsPool m_SyncGroupsPool; diff --git a/plugins/amda/tests/FuzzingOperations.cpp b/plugins/amda/tests/FuzzingOperations.cpp index 113da22..4aaf8e3 100644 --- a/plugins/amda/tests/FuzzingOperations.cpp +++ b/plugins/amda/tests/FuzzingOperations.cpp @@ -152,6 +152,9 @@ struct MoveOperation : public IFuzzingOperation { struct SynchronizeOperation : public IFuzzingOperation { bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override { + auto variable = fuzzingState.variableState(variableId).m_Variable; + return variable != nullptr && !fuzzingState.m_SyncGroupsPool.empty() + && fuzzingState.syncGroupId(variableId).isNull(); } void execute(VariableId variableId, FuzzingState &fuzzingState, @@ -163,6 +166,8 @@ struct SynchronizeOperation : public IFuzzingOperation { struct DesynchronizeOperation : public IFuzzingOperation { bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override { + auto variable = fuzzingState.variableState(variableId).m_Variable; + return variable != nullptr && !fuzzingState.syncGroupId(variableId).isNull(); } void execute(VariableId variableId, FuzzingState &fuzzingState,