@@ -1,77 +1,91 | |||||
1 | #include "FuzzingDefs.h" |
|
1 | #include "FuzzingDefs.h" | |
2 |
|
2 | |||
3 | const QString NB_MAX_OPERATIONS_PROPERTY = QStringLiteral("component"); |
|
3 | const QString NB_MAX_OPERATIONS_PROPERTY = QStringLiteral("component"); | |
4 | const QString NB_MAX_SYNC_GROUPS_PROPERTY = QStringLiteral("nbSyncGroups"); |
|
4 | const QString NB_MAX_SYNC_GROUPS_PROPERTY = QStringLiteral("nbSyncGroups"); | |
5 | const QString NB_MAX_VARIABLES_PROPERTY = QStringLiteral("nbMaxVariables"); |
|
5 | const QString NB_MAX_VARIABLES_PROPERTY = QStringLiteral("nbMaxVariables"); | |
6 | const QString AVAILABLE_OPERATIONS_PROPERTY = QStringLiteral("availableOperations"); |
|
6 | const QString AVAILABLE_OPERATIONS_PROPERTY = QStringLiteral("availableOperations"); | |
7 | const QString CACHE_TOLERANCE_PROPERTY = QStringLiteral("cacheTolerance"); |
|
7 | const QString CACHE_TOLERANCE_PROPERTY = QStringLiteral("cacheTolerance"); | |
8 | const QString INITIAL_RANGE_PROPERTY = QStringLiteral("initialRange"); |
|
8 | const QString INITIAL_RANGE_PROPERTY = QStringLiteral("initialRange"); | |
9 | const QString MAX_RANGE_PROPERTY = QStringLiteral("maxRange"); |
|
9 | const QString MAX_RANGE_PROPERTY = QStringLiteral("maxRange"); | |
10 | const QString METADATA_POOL_PROPERTY = QStringLiteral("metadataPool"); |
|
10 | const QString METADATA_POOL_PROPERTY = QStringLiteral("metadataPool"); | |
11 | const QString PROVIDER_PROPERTY = QStringLiteral("provider"); |
|
11 | const QString PROVIDER_PROPERTY = QStringLiteral("provider"); | |
12 | const QString OPERATION_DELAY_PROPERTY = QStringLiteral("operationDelay"); |
|
12 | const QString OPERATION_DELAY_PROPERTY = QStringLiteral("operationDelay"); | |
13 | const QString VALIDATORS_PROPERTY = QStringLiteral("validators"); |
|
13 | const QString VALIDATORS_PROPERTY = QStringLiteral("validators"); | |
14 |
|
14 | |||
15 | // //////////// // |
|
15 | // //////////// // | |
16 | // FuzzingState // |
|
16 | // FuzzingState // | |
17 | // //////////// // |
|
17 | // //////////// // | |
18 |
|
18 | |||
19 | const SyncGroup &FuzzingState::syncGroup(SyncGroupId id) const |
|
19 | const SyncGroup &FuzzingState::syncGroup(SyncGroupId id) const | |
20 | { |
|
20 | { | |
21 | return m_SyncGroupsPool.at(id); |
|
21 | return m_SyncGroupsPool.at(id); | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | SyncGroup &FuzzingState::syncGroup(SyncGroupId id) |
|
24 | SyncGroup &FuzzingState::syncGroup(SyncGroupId id) | |
25 | { |
|
25 | { | |
26 | return m_SyncGroupsPool.at(id); |
|
26 | return m_SyncGroupsPool.at(id); | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | const VariableState &FuzzingState::variableState(VariableId id) const |
|
29 | const VariableState &FuzzingState::variableState(VariableId id) const | |
30 | { |
|
30 | { | |
31 | return m_VariablesPool.at(id); |
|
31 | return m_VariablesPool.at(id); | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | VariableState &FuzzingState::variableState(VariableId id) |
|
34 | VariableState &FuzzingState::variableState(VariableId id) | |
35 | { |
|
35 | { | |
36 | return m_VariablesPool.at(id); |
|
36 | return m_VariablesPool.at(id); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | SyncGroupId FuzzingState::syncGroupId(VariableId variableId) const |
|
39 | SyncGroupId FuzzingState::syncGroupId(VariableId variableId) const | |
40 | { |
|
40 | { | |
41 | auto end = m_SyncGroupsPool.cend(); |
|
41 | auto end = m_SyncGroupsPool.cend(); | |
42 | auto it |
|
42 | auto it | |
43 | = std::find_if(m_SyncGroupsPool.cbegin(), end, [&variableId](const auto &syncGroupEntry) { |
|
43 | = std::find_if(m_SyncGroupsPool.cbegin(), end, [&variableId](const auto &syncGroupEntry) { | |
44 | const auto &syncGroup = syncGroupEntry.second; |
|
44 | const auto &syncGroup = syncGroupEntry.second; | |
45 | return syncGroup.m_Variables.find(variableId) != syncGroup.m_Variables.end(); |
|
45 | return syncGroup.m_Variables.find(variableId) != syncGroup.m_Variables.end(); | |
46 | }); |
|
46 | }); | |
47 |
|
47 | |||
48 | return it != end ? it->first : SyncGroupId{}; |
|
48 | return it != end ? it->first : SyncGroupId{}; | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | std::vector<SyncGroupId> FuzzingState::syncGroupsIds() const |
|
51 | std::vector<SyncGroupId> FuzzingState::syncGroupsIds() const | |
52 | { |
|
52 | { | |
53 | std::vector<SyncGroupId> result{}; |
|
53 | std::vector<SyncGroupId> result{}; | |
54 |
|
54 | |||
55 | for (const auto &entry : m_SyncGroupsPool) { |
|
55 | for (const auto &entry : m_SyncGroupsPool) { | |
56 | result.push_back(entry.first); |
|
56 | result.push_back(entry.first); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | return result; |
|
59 | return result; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void FuzzingState::synchronizeVariable(VariableId variableId, SyncGroupId syncGroupId) |
|
62 | void FuzzingState::synchronizeVariable(VariableId variableId, SyncGroupId syncGroupId) | |
63 | { |
|
63 | { | |
64 | if (syncGroupId.isNull()) { |
|
64 | if (syncGroupId.isNull()) { | |
65 | return; |
|
65 | return; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | // Registers variable into sync group: if it's the first variable, sets the variable range as |
|
68 | // Registers variable into sync group: if it's the first variable, sets the variable range as | |
69 | // the sync group range |
|
69 | // the sync group range | |
70 | auto &syncGroup = m_SyncGroupsPool.at(syncGroupId); |
|
70 | auto &syncGroup = m_SyncGroupsPool.at(syncGroupId); | |
71 | syncGroup.m_Variables.insert(variableId); |
|
71 | syncGroup.m_Variables.insert(variableId); | |
72 | if (syncGroup.m_Variables.size() == 1) { |
|
72 | if (syncGroup.m_Variables.size() == 1) { | |
73 | auto &variableState = m_VariablesPool.at(variableId); |
|
73 | auto &variableState = m_VariablesPool.at(variableId); | |
74 | syncGroup.m_Range = variableState.m_Range; |
|
74 | syncGroup.m_Range = variableState.m_Range; | |
75 | } |
|
75 | } | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
|
78 | void FuzzingState::desynchronizeVariable(VariableId variableId, SyncGroupId syncGroupId) | |||
|
79 | { | |||
|
80 | if (syncGroupId.isNull()) { | |||
|
81 | return; | |||
|
82 | } | |||
|
83 | ||||
|
84 | // Unregisters variable from sync group: if there is no more variable in the group, resets the range | |||
|
85 | auto &syncGroup = m_SyncGroupsPool.at(syncGroupId); | |||
|
86 | syncGroup.m_Variables.erase(variableId); | |||
|
87 | if (syncGroup.m_Variables.empty()) { | |||
|
88 | syncGroup.m_Range = INVALID_RANGE; | |||
|
89 | } | |||
|
90 | } | |||
|
91 |
@@ -1,113 +1,118 | |||||
1 | #ifndef SCIQLOP_FUZZINGDEFS_H |
|
1 | #ifndef SCIQLOP_FUZZINGDEFS_H | |
2 | #define SCIQLOP_FUZZINGDEFS_H |
|
2 | #define SCIQLOP_FUZZINGDEFS_H | |
3 |
|
3 | |||
4 | #include <Data/SqpRange.h> |
|
4 | #include <Data/SqpRange.h> | |
5 |
|
5 | |||
6 | #include <QString> |
|
6 | #include <QString> | |
7 | #include <QUuid> |
|
7 | #include <QUuid> | |
8 | #include <QVariantHash> |
|
8 | #include <QVariantHash> | |
9 |
|
9 | |||
10 | #include <memory> |
|
10 | #include <memory> | |
11 | #include <set> |
|
11 | #include <set> | |
12 |
|
12 | |||
13 | // /////// // |
|
13 | // /////// // | |
14 | // Aliases // |
|
14 | // Aliases // | |
15 | // /////// // |
|
15 | // /////// // | |
16 |
|
16 | |||
17 | using MetadataPool = std::vector<QVariantHash>; |
|
17 | using MetadataPool = std::vector<QVariantHash>; | |
18 | Q_DECLARE_METATYPE(MetadataPool) |
|
18 | Q_DECLARE_METATYPE(MetadataPool) | |
19 |
|
19 | |||
20 | using Properties = QVariantHash; |
|
20 | using Properties = QVariantHash; | |
21 |
|
21 | |||
22 | // ///////// // |
|
22 | // ///////// // | |
23 | // Constants // |
|
23 | // Constants // | |
24 | // ///////// // |
|
24 | // ///////// // | |
25 |
|
25 | |||
26 | /// Max number of operations to generate |
|
26 | /// Max number of operations to generate | |
27 | extern const QString NB_MAX_OPERATIONS_PROPERTY; |
|
27 | extern const QString NB_MAX_OPERATIONS_PROPERTY; | |
28 |
|
28 | |||
29 | /// Max number of sync groups to create through operations |
|
29 | /// Max number of sync groups to create through operations | |
30 | extern const QString NB_MAX_SYNC_GROUPS_PROPERTY; |
|
30 | extern const QString NB_MAX_SYNC_GROUPS_PROPERTY; | |
31 |
|
31 | |||
32 | /// Max number of variables to manipulate through operations |
|
32 | /// Max number of variables to manipulate through operations | |
33 | extern const QString NB_MAX_VARIABLES_PROPERTY; |
|
33 | extern const QString NB_MAX_VARIABLES_PROPERTY; | |
34 |
|
34 | |||
35 | /// Set of operations available for the test |
|
35 | /// Set of operations available for the test | |
36 | extern const QString AVAILABLE_OPERATIONS_PROPERTY; |
|
36 | extern const QString AVAILABLE_OPERATIONS_PROPERTY; | |
37 |
|
37 | |||
38 | /// Tolerance used for variable's cache (in ratio) |
|
38 | /// Tolerance used for variable's cache (in ratio) | |
39 | extern const QString CACHE_TOLERANCE_PROPERTY; |
|
39 | extern const QString CACHE_TOLERANCE_PROPERTY; | |
40 |
|
40 | |||
41 | /// Range with which the timecontroller is initialized |
|
41 | /// Range with which the timecontroller is initialized | |
42 | extern const QString INITIAL_RANGE_PROPERTY; |
|
42 | extern const QString INITIAL_RANGE_PROPERTY; | |
43 |
|
43 | |||
44 | /// Max range that an operation can reach |
|
44 | /// Max range that an operation can reach | |
45 | extern const QString MAX_RANGE_PROPERTY; |
|
45 | extern const QString MAX_RANGE_PROPERTY; | |
46 |
|
46 | |||
47 | /// Set of metadata that can be associated to a variable |
|
47 | /// Set of metadata that can be associated to a variable | |
48 | extern const QString METADATA_POOL_PROPERTY; |
|
48 | extern const QString METADATA_POOL_PROPERTY; | |
49 |
|
49 | |||
50 | /// Provider used to retrieve data |
|
50 | /// Provider used to retrieve data | |
51 | extern const QString PROVIDER_PROPERTY; |
|
51 | extern const QString PROVIDER_PROPERTY; | |
52 |
|
52 | |||
53 | /// Time left for an operation to execute |
|
53 | /// Time left for an operation to execute | |
54 | extern const QString OPERATION_DELAY_PROPERTY; |
|
54 | extern const QString OPERATION_DELAY_PROPERTY; | |
55 |
|
55 | |||
56 | /// Validators used to validate an operation |
|
56 | /// Validators used to validate an operation | |
57 | extern const QString VALIDATORS_PROPERTY; |
|
57 | extern const QString VALIDATORS_PROPERTY; | |
58 |
|
58 | |||
59 | // /////// // |
|
59 | // /////// // | |
60 | // Structs // |
|
60 | // Structs // | |
61 | // /////// // |
|
61 | // /////// // | |
62 |
|
62 | |||
63 | class Variable; |
|
63 | class Variable; | |
64 | struct VariableState { |
|
64 | struct VariableState { | |
65 | std::shared_ptr<Variable> m_Variable{nullptr}; |
|
65 | std::shared_ptr<Variable> m_Variable{nullptr}; | |
66 | SqpRange m_Range{INVALID_RANGE}; |
|
66 | SqpRange m_Range{INVALID_RANGE}; | |
67 | }; |
|
67 | }; | |
68 |
|
68 | |||
69 | using VariableId = int; |
|
69 | using VariableId = int; | |
70 | using VariablesPool = std::map<VariableId, VariableState>; |
|
70 | using VariablesPool = std::map<VariableId, VariableState>; | |
71 |
|
71 | |||
72 | /** |
|
72 | /** | |
73 | * Defines a synchronization group for a fuzzing state. A group reports the variables synchronized |
|
73 | * Defines a synchronization group for a fuzzing state. A group reports the variables synchronized | |
74 | * with each other, and the current range of the group (i.e. range of the last synchronized variable |
|
74 | * with each other, and the current range of the group (i.e. range of the last synchronized variable | |
75 | * that has been moved) |
|
75 | * that has been moved) | |
76 | */ |
|
76 | */ | |
77 | struct SyncGroup { |
|
77 | struct SyncGroup { | |
78 | std::set<VariableId> m_Variables{}; |
|
78 | std::set<VariableId> m_Variables{}; | |
79 | SqpRange m_Range{INVALID_RANGE}; |
|
79 | SqpRange m_Range{INVALID_RANGE}; | |
80 | }; |
|
80 | }; | |
81 |
|
81 | |||
82 | using SyncGroupId = QUuid; |
|
82 | using SyncGroupId = QUuid; | |
83 | using SyncGroupsPool = std::map<SyncGroupId, SyncGroup>; |
|
83 | using SyncGroupsPool = std::map<SyncGroupId, SyncGroup>; | |
84 |
|
84 | |||
85 | /** |
|
85 | /** | |
86 | * Defines a current state during a fuzzing state. It contains all the variables manipulated during |
|
86 | * Defines a current state during a fuzzing state. It contains all the variables manipulated during | |
87 | * the test, as well as the synchronization status of these variables. |
|
87 | * the test, as well as the synchronization status of these variables. | |
88 | */ |
|
88 | */ | |
89 | struct FuzzingState { |
|
89 | struct FuzzingState { | |
90 | const SyncGroup &syncGroup(SyncGroupId id) const; |
|
90 | const SyncGroup &syncGroup(SyncGroupId id) const; | |
91 | SyncGroup &syncGroup(SyncGroupId id); |
|
91 | SyncGroup &syncGroup(SyncGroupId id); | |
92 |
|
92 | |||
93 | const VariableState &variableState(VariableId id) const; |
|
93 | const VariableState &variableState(VariableId id) const; | |
94 | VariableState &variableState(VariableId id); |
|
94 | VariableState &variableState(VariableId id); | |
95 |
|
95 | |||
96 | /// @return the identifier of the synchronization group in which the variable passed in |
|
96 | /// @return the identifier of the synchronization group in which the variable passed in | |
97 | /// parameter is located. If the variable is not in any group, returns an invalid identifier |
|
97 | /// parameter is located. If the variable is not in any group, returns an invalid identifier | |
98 | SyncGroupId syncGroupId(VariableId variableId) const; |
|
98 | SyncGroupId syncGroupId(VariableId variableId) const; | |
99 |
|
99 | |||
100 | /// @return the set of synchronization group identifiers |
|
100 | /// @return the set of synchronization group identifiers | |
101 | std::vector<SyncGroupId> syncGroupsIds() const; |
|
101 | std::vector<SyncGroupId> syncGroupsIds() const; | |
102 |
|
102 | |||
103 | /// Updates fuzzing state according to a variable synchronization |
|
103 | /// Updates fuzzing state according to a variable synchronization | |
104 | /// @param variableId the variable that is synchronized |
|
104 | /// @param variableId the variable that is synchronized | |
105 | /// @param syncGroupId the synchronization group |
|
105 | /// @param syncGroupId the synchronization group | |
106 | void synchronizeVariable(VariableId variableId, SyncGroupId syncGroupId); |
|
106 | void synchronizeVariable(VariableId variableId, SyncGroupId syncGroupId); | |
107 |
|
107 | |||
|
108 | /// Updates fuzzing state according to a variable desynchronization | |||
|
109 | /// @param variableId the variable that is desynchronized | |||
|
110 | /// @param syncGroupId the synchronization group from which to remove the variable | |||
|
111 | void desynchronizeVariable(VariableId variableId, SyncGroupId syncGroupId); | |||
|
112 | ||||
108 |
|
113 | |||
109 | VariablesPool m_VariablesPool; |
|
114 | VariablesPool m_VariablesPool; | |
110 | SyncGroupsPool m_SyncGroupsPool; |
|
115 | SyncGroupsPool m_SyncGroupsPool; | |
111 | }; |
|
116 | }; | |
112 |
|
117 | |||
113 | #endif // SCIQLOP_FUZZINGDEFS_H |
|
118 | #endif // SCIQLOP_FUZZINGDEFS_H |
@@ -1,245 +1,264 | |||||
1 | #include "FuzzingOperations.h" |
|
1 | #include "FuzzingOperations.h" | |
2 | #include "FuzzingUtils.h" |
|
2 | #include "FuzzingUtils.h" | |
3 |
|
3 | |||
4 | #include <Data/IDataProvider.h> |
|
4 | #include <Data/IDataProvider.h> | |
5 |
|
5 | |||
6 | #include <Variable/Variable.h> |
|
6 | #include <Variable/Variable.h> | |
7 | #include <Variable/VariableController.h> |
|
7 | #include <Variable/VariableController.h> | |
8 |
|
8 | |||
9 | #include <QUuid> |
|
9 | #include <QUuid> | |
10 |
|
10 | |||
11 | #include <functional> |
|
11 | #include <functional> | |
12 |
|
12 | |||
13 | Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations") |
|
13 | Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations") | |
14 |
|
14 | |||
15 | namespace { |
|
15 | namespace { | |
16 |
|
16 | |||
17 | struct CreateOperation : public IFuzzingOperation { |
|
17 | struct CreateOperation : public IFuzzingOperation { | |
18 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override |
|
18 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override | |
19 | { |
|
19 | { | |
20 | // A variable can be created only if it doesn't exist yet |
|
20 | // A variable can be created only if it doesn't exist yet | |
21 | return fuzzingState.variableState(variableId).m_Variable == nullptr; |
|
21 | return fuzzingState.variableState(variableId).m_Variable == nullptr; | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | void execute(VariableId variableId, FuzzingState &fuzzingState, |
|
24 | void execute(VariableId variableId, FuzzingState &fuzzingState, | |
25 | VariableController &variableController, |
|
25 | VariableController &variableController, | |
26 | const Properties &properties) const override |
|
26 | const Properties &properties) const override | |
27 | { |
|
27 | { | |
28 | // Retrieves metadata pool from properties, and choose one of the metadata entries to |
|
28 | // Retrieves metadata pool from properties, and choose one of the metadata entries to | |
29 | // associate it with the variable |
|
29 | // associate it with the variable | |
30 | auto metaDataPool = properties.value(METADATA_POOL_PROPERTY).value<MetadataPool>(); |
|
30 | auto metaDataPool = properties.value(METADATA_POOL_PROPERTY).value<MetadataPool>(); | |
31 | auto variableMetadata = RandomGenerator::instance().randomChoice(metaDataPool); |
|
31 | auto variableMetadata = RandomGenerator::instance().randomChoice(metaDataPool); | |
32 |
|
32 | |||
33 | // Retrieves provider |
|
33 | // Retrieves provider | |
34 | auto variableProvider |
|
34 | auto variableProvider | |
35 | = properties.value(PROVIDER_PROPERTY).value<std::shared_ptr<IDataProvider> >(); |
|
35 | = properties.value(PROVIDER_PROPERTY).value<std::shared_ptr<IDataProvider> >(); | |
36 |
|
36 | |||
37 | auto variableName = QString{"Var_%1"}.arg(QUuid::createUuid().toString()); |
|
37 | auto variableName = QString{"Var_%1"}.arg(QUuid::createUuid().toString()); | |
38 | qCInfo(LOG_FuzzingOperations()).noquote() |
|
38 | qCInfo(LOG_FuzzingOperations()).noquote() | |
39 | << "Creating variable" << variableName << "(metadata:" << variableMetadata << ")..."; |
|
39 | << "Creating variable" << variableName << "(metadata:" << variableMetadata << ")..."; | |
40 |
|
40 | |||
41 | auto newVariable |
|
41 | auto newVariable | |
42 | = variableController.createVariable(variableName, variableMetadata, variableProvider); |
|
42 | = variableController.createVariable(variableName, variableMetadata, variableProvider); | |
43 |
|
43 | |||
44 | // Updates variable's state |
|
44 | // Updates variable's state | |
45 | auto &variableState = fuzzingState.variableState(variableId); |
|
45 | auto &variableState = fuzzingState.variableState(variableId); | |
46 | variableState.m_Range = properties.value(INITIAL_RANGE_PROPERTY).value<SqpRange>(); |
|
46 | variableState.m_Range = properties.value(INITIAL_RANGE_PROPERTY).value<SqpRange>(); | |
47 | std::swap(variableState.m_Variable, newVariable); |
|
47 | std::swap(variableState.m_Variable, newVariable); | |
48 | } |
|
48 | } | |
49 | }; |
|
49 | }; | |
50 |
|
50 | |||
51 | struct DeleteOperation : public IFuzzingOperation { |
|
51 | struct DeleteOperation : public IFuzzingOperation { | |
52 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override |
|
52 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override | |
53 | { |
|
53 | { | |
54 | // A variable can be delete only if it exists |
|
54 | // A variable can be delete only if it exists | |
55 | return fuzzingState.variableState(variableId).m_Variable != nullptr; |
|
55 | return fuzzingState.variableState(variableId).m_Variable != nullptr; | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | void execute(VariableId variableId, FuzzingState &fuzzingState, |
|
58 | void execute(VariableId variableId, FuzzingState &fuzzingState, | |
59 | VariableController &variableController, const Properties &) const override |
|
59 | VariableController &variableController, const Properties &) const override | |
60 | { |
|
60 | { | |
61 | auto &variableState = fuzzingState.variableState(variableId); |
|
61 | auto &variableState = fuzzingState.variableState(variableId); | |
62 |
|
62 | |||
63 | qCInfo(LOG_FuzzingOperations()).noquote() |
|
63 | qCInfo(LOG_FuzzingOperations()).noquote() | |
64 | << "Deleting variable" << variableState.m_Variable->name() << "..."; |
|
64 | << "Deleting variable" << variableState.m_Variable->name() << "..."; | |
65 | variableController.deleteVariable(variableState.m_Variable); |
|
65 | variableController.deleteVariable(variableState.m_Variable); | |
66 |
|
66 | |||
67 | // Updates variable's state |
|
67 | // Updates variable's state | |
68 | variableState.m_Range = INVALID_RANGE; |
|
68 | variableState.m_Range = INVALID_RANGE; | |
69 | variableState.m_Variable = nullptr; |
|
69 | variableState.m_Variable = nullptr; | |
|
70 | ||||
|
71 | // Desynchronizes the variable if it was in a sync group | |||
|
72 | auto syncGroupId = fuzzingState.syncGroupId(variableId); | |||
|
73 | fuzzingState.desynchronizeVariable(variableId, syncGroupId); | |||
70 | } |
|
74 | } | |
71 | }; |
|
75 | }; | |
72 |
|
76 | |||
73 | /** |
|
77 | /** | |
74 | * Defines a move operation through a range. |
|
78 | * Defines a move operation through a range. | |
75 | * |
|
79 | * | |
76 | * A move operation is determined by three functions: |
|
80 | * A move operation is determined by three functions: | |
77 | * - Two 'move' functions, used to indicate in which direction the beginning and the end of a range |
|
81 | * - Two 'move' functions, used to indicate in which direction the beginning and the end of a range | |
78 | * are going during the operation. These functions will be: |
|
82 | * are going during the operation. These functions will be: | |
79 | * -- {<- / <-} for pan left |
|
83 | * -- {<- / <-} for pan left | |
80 | * -- {-> / ->} for pan right |
|
84 | * -- {-> / ->} for pan right | |
81 | * -- {-> / <-} for zoom in |
|
85 | * -- {-> / <-} for zoom in | |
82 | * -- {<- / ->} for zoom out |
|
86 | * -- {<- / ->} for zoom out | |
83 | * - One 'max move' functions, used to compute the max delta at which the operation can move a |
|
87 | * - One 'max move' functions, used to compute the max delta at which the operation can move a | |
84 | * range, according to a max range. For exemple, for a range of {1, 5} and a max range of {0, 10}, |
|
88 | * range, according to a max range. For exemple, for a range of {1, 5} and a max range of {0, 10}, | |
85 | * max deltas will be: |
|
89 | * max deltas will be: | |
86 | * -- {0, 4} for pan left |
|
90 | * -- {0, 4} for pan left | |
87 | * -- {6, 10} for pan right |
|
91 | * -- {6, 10} for pan right | |
88 | * -- {3, 3} for zoom in |
|
92 | * -- {3, 3} for zoom in | |
89 | * -- {0, 6} for zoom out (same spacing left and right) |
|
93 | * -- {0, 6} for zoom out (same spacing left and right) | |
90 | */ |
|
94 | */ | |
91 | struct MoveOperation : public IFuzzingOperation { |
|
95 | struct MoveOperation : public IFuzzingOperation { | |
92 | using MoveFunction = std::function<double(double currentValue, double maxValue)>; |
|
96 | using MoveFunction = std::function<double(double currentValue, double maxValue)>; | |
93 | using MaxMoveFunction = std::function<double(const SqpRange &range, const SqpRange &maxRange)>; |
|
97 | using MaxMoveFunction = std::function<double(const SqpRange &range, const SqpRange &maxRange)>; | |
94 |
|
98 | |||
95 | explicit MoveOperation(MoveFunction rangeStartMoveFun, MoveFunction rangeEndMoveFun, |
|
99 | explicit MoveOperation(MoveFunction rangeStartMoveFun, MoveFunction rangeEndMoveFun, | |
96 | MaxMoveFunction maxMoveFun, |
|
100 | MaxMoveFunction maxMoveFun, | |
97 | const QString &label = QStringLiteral("Move operation")) |
|
101 | const QString &label = QStringLiteral("Move operation")) | |
98 | : m_RangeStartMoveFun{std::move(rangeStartMoveFun)}, |
|
102 | : m_RangeStartMoveFun{std::move(rangeStartMoveFun)}, | |
99 | m_RangeEndMoveFun{std::move(rangeEndMoveFun)}, |
|
103 | m_RangeEndMoveFun{std::move(rangeEndMoveFun)}, | |
100 | m_MaxMoveFun{std::move(maxMoveFun)}, |
|
104 | m_MaxMoveFun{std::move(maxMoveFun)}, | |
101 | m_Label{label} |
|
105 | m_Label{label} | |
102 | { |
|
106 | { | |
103 | } |
|
107 | } | |
104 |
|
108 | |||
105 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override |
|
109 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override | |
106 | { |
|
110 | { | |
107 | return fuzzingState.variableState(variableId).m_Variable != nullptr; |
|
111 | return fuzzingState.variableState(variableId).m_Variable != nullptr; | |
108 | } |
|
112 | } | |
109 |
|
113 | |||
110 | void execute(VariableId variableId, FuzzingState &fuzzingState, |
|
114 | void execute(VariableId variableId, FuzzingState &fuzzingState, | |
111 | VariableController &variableController, |
|
115 | VariableController &variableController, | |
112 | const Properties &properties) const override |
|
116 | const Properties &properties) const override | |
113 | { |
|
117 | { | |
114 | auto &variableState = fuzzingState.variableState(variableId); |
|
118 | auto &variableState = fuzzingState.variableState(variableId); | |
115 | auto variable = variableState.m_Variable; |
|
119 | auto variable = variableState.m_Variable; | |
116 |
|
120 | |||
117 | // Gets the max range defined |
|
121 | // Gets the max range defined | |
118 | auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE)) |
|
122 | auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE)) | |
119 | .value<SqpRange>(); |
|
123 | .value<SqpRange>(); | |
120 | auto variableRange = variable->range(); |
|
124 | auto variableRange = variable->range(); | |
121 |
|
125 | |||
122 | if (maxRange == INVALID_RANGE || variableRange.m_TStart < maxRange.m_TStart |
|
126 | if (maxRange == INVALID_RANGE || variableRange.m_TStart < maxRange.m_TStart | |
123 | || variableRange.m_TEnd > maxRange.m_TEnd) { |
|
127 | || variableRange.m_TEnd > maxRange.m_TEnd) { | |
124 | qCWarning(LOG_FuzzingOperations()) << "Can't execute operation: invalid max range"; |
|
128 | qCWarning(LOG_FuzzingOperations()) << "Can't execute operation: invalid max range"; | |
125 | return; |
|
129 | return; | |
126 | } |
|
130 | } | |
127 |
|
131 | |||
128 | // Computes the max delta at which the variable can move, up to the limits of the max range |
|
132 | // Computes the max delta at which the variable can move, up to the limits of the max range | |
129 | auto deltaMax = m_MaxMoveFun(variable->range(), maxRange); |
|
133 | auto deltaMax = m_MaxMoveFun(variable->range(), maxRange); | |
130 |
|
134 | |||
131 | // Generates random delta that will be used to move variable |
|
135 | // Generates random delta that will be used to move variable | |
132 | auto delta = RandomGenerator::instance().generateDouble(0, deltaMax); |
|
136 | auto delta = RandomGenerator::instance().generateDouble(0, deltaMax); | |
133 |
|
137 | |||
134 | // Moves variable to its new range |
|
138 | // Moves variable to its new range | |
135 | auto newVariableRange = SqpRange{m_RangeStartMoveFun(variableRange.m_TStart, delta), |
|
139 | auto newVariableRange = SqpRange{m_RangeStartMoveFun(variableRange.m_TStart, delta), | |
136 | m_RangeEndMoveFun(variableRange.m_TEnd, delta)}; |
|
140 | m_RangeEndMoveFun(variableRange.m_TEnd, delta)}; | |
137 | qCInfo(LOG_FuzzingOperations()).noquote() |
|
141 | qCInfo(LOG_FuzzingOperations()).noquote() | |
138 | << "Performing" << m_Label << "on" << variable->name() << "(from" << variableRange |
|
142 | << "Performing" << m_Label << "on" << variable->name() << "(from" << variableRange | |
139 | << "to" << newVariableRange << ")..."; |
|
143 | << "to" << newVariableRange << ")..."; | |
140 | variableController.onRequestDataLoading({variable}, newVariableRange, false); |
|
144 | variableController.onRequestDataLoading({variable}, newVariableRange, false); | |
141 |
|
145 | |||
142 | // Updates variable's state |
|
146 | // Updates variable's state | |
143 | variableState.m_Range = newVariableRange; |
|
147 | variableState.m_Range = newVariableRange; | |
144 | } |
|
148 | } | |
145 |
|
149 | |||
146 | MoveFunction m_RangeStartMoveFun; |
|
150 | MoveFunction m_RangeStartMoveFun; | |
147 | MoveFunction m_RangeEndMoveFun; |
|
151 | MoveFunction m_RangeEndMoveFun; | |
148 | MaxMoveFunction m_MaxMoveFun; |
|
152 | MaxMoveFunction m_MaxMoveFun; | |
149 | QString m_Label; |
|
153 | QString m_Label; | |
150 | }; |
|
154 | }; | |
151 |
|
155 | |||
152 | struct SynchronizeOperation : public IFuzzingOperation { |
|
156 | struct SynchronizeOperation : public IFuzzingOperation { | |
153 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override |
|
157 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override | |
154 | { |
|
158 | { | |
155 | auto variable = fuzzingState.variableState(variableId).m_Variable; |
|
159 | auto variable = fuzzingState.variableState(variableId).m_Variable; | |
156 | return variable != nullptr && !fuzzingState.m_SyncGroupsPool.empty() |
|
160 | return variable != nullptr && !fuzzingState.m_SyncGroupsPool.empty() | |
157 | && fuzzingState.syncGroupId(variableId).isNull(); |
|
161 | && fuzzingState.syncGroupId(variableId).isNull(); | |
158 | } |
|
162 | } | |
159 |
|
163 | |||
160 | void execute(VariableId variableId, FuzzingState &fuzzingState, |
|
164 | void execute(VariableId variableId, FuzzingState &fuzzingState, | |
161 | VariableController &variableController, const Properties &) const override |
|
165 | VariableController &variableController, const Properties &) const override | |
162 | { |
|
166 | { | |
163 | auto &variableState = fuzzingState.variableState(variableId); |
|
167 | auto &variableState = fuzzingState.variableState(variableId); | |
164 |
|
168 | |||
165 | // Chooses a random synchronization group and adds the variable into sync group |
|
169 | // Chooses a random synchronization group and adds the variable into sync group | |
166 | auto syncGroupId = RandomGenerator::instance().randomChoice(fuzzingState.syncGroupsIds()); |
|
170 | auto syncGroupId = RandomGenerator::instance().randomChoice(fuzzingState.syncGroupsIds()); | |
167 | qCInfo(LOG_FuzzingOperations()).noquote() |
|
171 | qCInfo(LOG_FuzzingOperations()).noquote() | |
168 | << "Adding" << variableState.m_Variable->name() << "into synchronization group" |
|
172 | << "Adding" << variableState.m_Variable->name() << "into synchronization group" | |
169 | << syncGroupId << "..."; |
|
173 | << syncGroupId << "..."; | |
170 | variableController.onAddSynchronized(variableState.m_Variable, syncGroupId); |
|
174 | variableController.onAddSynchronized(variableState.m_Variable, syncGroupId); | |
171 |
|
175 | |||
172 | // Updates state |
|
176 | // Updates state | |
173 | fuzzingState.synchronizeVariable(variableId, syncGroupId); |
|
177 | fuzzingState.synchronizeVariable(variableId, syncGroupId); | |
174 | } |
|
178 | } | |
175 | }; |
|
179 | }; | |
176 |
|
180 | |||
177 | struct DesynchronizeOperation : public IFuzzingOperation { |
|
181 | struct DesynchronizeOperation : public IFuzzingOperation { | |
178 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override |
|
182 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override | |
179 | { |
|
183 | { | |
180 | auto variable = fuzzingState.variableState(variableId).m_Variable; |
|
184 | auto variable = fuzzingState.variableState(variableId).m_Variable; | |
181 | return variable != nullptr && !fuzzingState.syncGroupId(variableId).isNull(); |
|
185 | return variable != nullptr && !fuzzingState.syncGroupId(variableId).isNull(); | |
182 | } |
|
186 | } | |
183 |
|
187 | |||
184 | void execute(VariableId variableId, FuzzingState &fuzzingState, |
|
188 | void execute(VariableId variableId, FuzzingState &fuzzingState, | |
185 | VariableController &variableController, const Properties &) const override |
|
189 | VariableController &variableController, const Properties &) const override | |
186 | { |
|
190 | { | |
|
191 | auto &variableState = fuzzingState.variableState(variableId); | |||
|
192 | ||||
|
193 | // Gets the sync group of the variable | |||
|
194 | auto syncGroupId = fuzzingState.syncGroupId(variableId); | |||
|
195 | ||||
|
196 | qCInfo(LOG_FuzzingOperations()).noquote() | |||
|
197 | << "Removing" << variableState.m_Variable->name() << "from synchronization group" | |||
|
198 | << syncGroupId << "..."; | |||
|
199 | variableController.onAddSynchronized(variableState.m_Variable, syncGroupId); | |||
|
200 | ||||
|
201 | // Updates state | |||
|
202 | fuzzingState.desynchronizeVariable(variableId, syncGroupId); | |||
|
203 | } | |||
|
204 | }; | |||
|
205 | ||||
187 | struct UnknownOperation : public IFuzzingOperation { |
|
206 | struct UnknownOperation : public IFuzzingOperation { | |
188 | bool canExecute(VariableId, const FuzzingState &) const override { return false; } |
|
207 | bool canExecute(VariableId, const FuzzingState &) const override { return false; } | |
189 |
|
208 | |||
190 | void execute(VariableId, FuzzingState &, VariableController &, |
|
209 | void execute(VariableId, FuzzingState &, VariableController &, | |
191 | const Properties &) const override |
|
210 | const Properties &) const override | |
192 | { |
|
211 | { | |
193 | } |
|
212 | } | |
194 | }; |
|
213 | }; | |
195 |
|
214 | |||
196 | } // namespace |
|
215 | } // namespace | |
197 |
|
216 | |||
198 | std::unique_ptr<IFuzzingOperation> FuzzingOperationFactory::create(FuzzingOperationType type) |
|
217 | std::unique_ptr<IFuzzingOperation> FuzzingOperationFactory::create(FuzzingOperationType type) | |
199 | { |
|
218 | { | |
200 | switch (type) { |
|
219 | switch (type) { | |
201 | case FuzzingOperationType::CREATE: |
|
220 | case FuzzingOperationType::CREATE: | |
202 | return std::make_unique<CreateOperation>(); |
|
221 | return std::make_unique<CreateOperation>(); | |
203 | case FuzzingOperationType::DELETE: |
|
222 | case FuzzingOperationType::DELETE: | |
204 | return std::make_unique<DeleteOperation>(); |
|
223 | return std::make_unique<DeleteOperation>(); | |
205 | case FuzzingOperationType::PAN_LEFT: |
|
224 | case FuzzingOperationType::PAN_LEFT: | |
206 | return std::make_unique<MoveOperation>( |
|
225 | return std::make_unique<MoveOperation>( | |
207 | std::minus<double>(), std::minus<double>(), |
|
226 | std::minus<double>(), std::minus<double>(), | |
208 | [](const SqpRange &range, const SqpRange &maxRange) { |
|
227 | [](const SqpRange &range, const SqpRange &maxRange) { | |
209 | return range.m_TStart - maxRange.m_TStart; |
|
228 | return range.m_TStart - maxRange.m_TStart; | |
210 | }, |
|
229 | }, | |
211 | QStringLiteral("Pan left operation")); |
|
230 | QStringLiteral("Pan left operation")); | |
212 | case FuzzingOperationType::PAN_RIGHT: |
|
231 | case FuzzingOperationType::PAN_RIGHT: | |
213 | return std::make_unique<MoveOperation>( |
|
232 | return std::make_unique<MoveOperation>( | |
214 | std::plus<double>(), std::plus<double>(), |
|
233 | std::plus<double>(), std::plus<double>(), | |
215 | [](const SqpRange &range, const SqpRange &maxRange) { |
|
234 | [](const SqpRange &range, const SqpRange &maxRange) { | |
216 | return maxRange.m_TEnd - range.m_TEnd; |
|
235 | return maxRange.m_TEnd - range.m_TEnd; | |
217 | }, |
|
236 | }, | |
218 | QStringLiteral("Pan right operation")); |
|
237 | QStringLiteral("Pan right operation")); | |
219 | case FuzzingOperationType::ZOOM_IN: |
|
238 | case FuzzingOperationType::ZOOM_IN: | |
220 | return std::make_unique<MoveOperation>( |
|
239 | return std::make_unique<MoveOperation>( | |
221 | std::plus<double>(), std::minus<double>(), |
|
240 | std::plus<double>(), std::minus<double>(), | |
222 | [](const SqpRange &range, const SqpRange &maxRange) { |
|
241 | [](const SqpRange &range, const SqpRange &maxRange) { | |
223 | Q_UNUSED(maxRange) |
|
242 | Q_UNUSED(maxRange) | |
224 | return range.m_TEnd - (range.m_TStart + range.m_TEnd) / 2.; |
|
243 | return range.m_TEnd - (range.m_TStart + range.m_TEnd) / 2.; | |
225 | }, |
|
244 | }, | |
226 | QStringLiteral("Zoom in operation")); |
|
245 | QStringLiteral("Zoom in operation")); | |
227 | case FuzzingOperationType::ZOOM_OUT: |
|
246 | case FuzzingOperationType::ZOOM_OUT: | |
228 | return std::make_unique<MoveOperation>( |
|
247 | return std::make_unique<MoveOperation>( | |
229 | std::minus<double>(), std::plus<double>(), |
|
248 | std::minus<double>(), std::plus<double>(), | |
230 | [](const SqpRange &range, const SqpRange &maxRange) { |
|
249 | [](const SqpRange &range, const SqpRange &maxRange) { | |
231 | return std::min(range.m_TStart - maxRange.m_TStart, |
|
250 | return std::min(range.m_TStart - maxRange.m_TStart, | |
232 | maxRange.m_TEnd - range.m_TEnd); |
|
251 | maxRange.m_TEnd - range.m_TEnd); | |
233 | }, |
|
252 | }, | |
234 | QStringLiteral("Zoom out operation")); |
|
253 | QStringLiteral("Zoom out operation")); | |
235 | case FuzzingOperationType::SYNCHRONIZE: |
|
254 | case FuzzingOperationType::SYNCHRONIZE: | |
236 | return std::make_unique<SynchronizeOperation>(); |
|
255 | return std::make_unique<SynchronizeOperation>(); | |
237 | case FuzzingOperationType::DESYNCHRONIZE: |
|
256 | case FuzzingOperationType::DESYNCHRONIZE: | |
238 | return std::make_unique<DesynchronizeOperation>(); |
|
257 | return std::make_unique<DesynchronizeOperation>(); | |
239 | default: |
|
258 | default: | |
240 | // Default case returns unknown operation |
|
259 | // Default case returns unknown operation | |
241 | break; |
|
260 | break; | |
242 | } |
|
261 | } | |
243 |
|
262 | |||
244 | return std::make_unique<UnknownOperation>(); |
|
263 | return std::make_unique<UnknownOperation>(); | |
245 | } |
|
264 | } |
General Comments 0
You need to be logged in to leave comments.
Login now