From b9a9a3a9f506717636dc86cd4432e87d9644eacd 2017-12-19 14:14:49 From: Alexandre Leroux Date: 2017-12-19 14:14:49 Subject: [PATCH] Implements execute() method of sync operation --- diff --git a/plugins/amda/tests/FuzzingDefs.cpp b/plugins/amda/tests/FuzzingDefs.cpp index b4f80f7..e2ea040 100644 --- a/plugins/amda/tests/FuzzingDefs.cpp +++ b/plugins/amda/tests/FuzzingDefs.cpp @@ -48,3 +48,30 @@ SyncGroupId FuzzingState::syncGroupId(VariableId variableId) const return it != end ? it->first : SyncGroupId{}; } +std::vector FuzzingState::syncGroupsIds() const +{ + std::vector result{}; + + for (const auto &entry : m_SyncGroupsPool) { + result.push_back(entry.first); + } + + return result; +} + +void FuzzingState::synchronizeVariable(VariableId variableId, SyncGroupId syncGroupId) +{ + if (syncGroupId.isNull()) { + return; + } + + // Registers variable into sync group: if it's the first variable, sets the variable range as + // the sync group range + auto &syncGroup = m_SyncGroupsPool.at(syncGroupId); + syncGroup.m_Variables.insert(variableId); + if (syncGroup.m_Variables.size() == 1) { + auto &variableState = m_VariablesPool.at(variableId); + syncGroup.m_Range = variableState.m_Range; + } +} + diff --git a/plugins/amda/tests/FuzzingDefs.h b/plugins/amda/tests/FuzzingDefs.h index b488421..a93857d 100644 --- a/plugins/amda/tests/FuzzingDefs.h +++ b/plugins/amda/tests/FuzzingDefs.h @@ -97,6 +97,14 @@ struct FuzzingState { /// parameter is located. If the variable is not in any group, returns an invalid identifier SyncGroupId syncGroupId(VariableId variableId) const; + /// @return the set of synchronization group identifiers + std::vector syncGroupsIds() const; + + /// Updates fuzzing state according to a variable synchronization + /// @param variableId the variable that is synchronized + /// @param syncGroupId the synchronization group + void synchronizeVariable(VariableId variableId, SyncGroupId syncGroupId); + VariablesPool m_VariablesPool; SyncGroupsPool m_SyncGroupsPool; diff --git a/plugins/amda/tests/FuzzingOperations.cpp b/plugins/amda/tests/FuzzingOperations.cpp index 4aaf8e3..8565513 100644 --- a/plugins/amda/tests/FuzzingOperations.cpp +++ b/plugins/amda/tests/FuzzingOperations.cpp @@ -160,6 +160,17 @@ struct SynchronizeOperation : public IFuzzingOperation { void execute(VariableId variableId, FuzzingState &fuzzingState, VariableController &variableController, const Properties &) const override { + auto &variableState = fuzzingState.variableState(variableId); + + // Chooses a random synchronization group and adds the variable into sync group + auto syncGroupId = RandomGenerator::instance().randomChoice(fuzzingState.syncGroupsIds()); + qCInfo(LOG_FuzzingOperations()).noquote() + << "Adding" << variableState.m_Variable->name() << "into synchronization group" + << syncGroupId << "..."; + variableController.onAddSynchronized(variableState.m_Variable, syncGroupId); + + // Updates state + fuzzingState.synchronizeVariable(variableId, syncGroupId); } };