@@ -1,388 +1,391 | |||||
1 | #include "FuzzingDefs.h" |
|
1 | #include "FuzzingDefs.h" | |
2 | #include "FuzzingOperations.h" |
|
2 | #include "FuzzingOperations.h" | |
3 | #include "FuzzingUtils.h" |
|
3 | #include "FuzzingUtils.h" | |
4 | #include "FuzzingValidators.h" |
|
4 | #include "FuzzingValidators.h" | |
5 |
|
5 | |||
6 | #include "AmdaProvider.h" |
|
6 | #include "AmdaProvider.h" | |
7 |
|
7 | |||
8 | #include <Common/SignalWaiter.h> |
|
8 | #include <Common/SignalWaiter.h> | |
9 | #include <Network/NetworkController.h> |
|
9 | #include <Network/NetworkController.h> | |
10 | #include <Settings/SqpSettingsDefs.h> |
|
10 | #include <Settings/SqpSettingsDefs.h> | |
11 | #include <SqpApplication.h> |
|
11 | #include <SqpApplication.h> | |
12 | #include <Time/TimeController.h> |
|
12 | #include <Time/TimeController.h> | |
13 | #include <Variable/Variable.h> |
|
13 | #include <Variable/Variable.h> | |
14 | #include <Variable/VariableController.h> |
|
14 | #include <Variable/VariableController.h> | |
15 |
|
15 | |||
16 | #include <QLoggingCategory> |
|
16 | #include <QLoggingCategory> | |
17 | #include <QObject> |
|
17 | #include <QObject> | |
18 | #include <QtTest> |
|
18 | #include <QtTest> | |
19 |
|
19 | |||
20 | #include <memory> |
|
20 | #include <memory> | |
21 |
|
21 | |||
22 | Q_LOGGING_CATEGORY(LOG_TestAmdaFuzzing, "TestAmdaFuzzing") |
|
22 | Q_LOGGING_CATEGORY(LOG_TestAmdaFuzzing, "TestAmdaFuzzing") | |
23 |
|
23 | |||
24 | /** |
|
24 | /** | |
25 | * Macro used to generate a getter for a property in @sa FuzzingTest. The macro generates a static |
|
25 | * Macro used to generate a getter for a property in @sa FuzzingTest. The macro generates a static | |
26 | * attribute that is initialized by searching in properties the property and use a default value if |
|
26 | * attribute that is initialized by searching in properties the property and use a default value if | |
27 | * it's not present. Macro arguments are: |
|
27 | * it's not present. Macro arguments are: | |
28 | * - GETTER_NAME : name of the getter |
|
28 | * - GETTER_NAME : name of the getter | |
29 | * - PROPERTY_NAME: used to generate constants for property's name ({PROPERTY_NAME}_PROPERTY) and |
|
29 | * - PROPERTY_NAME: used to generate constants for property's name ({PROPERTY_NAME}_PROPERTY) and | |
30 | * default value ({PROPERTY_NAME}_DEFAULT_VALUE) |
|
30 | * default value ({PROPERTY_NAME}_DEFAULT_VALUE) | |
31 | * - TYPE : return type of the getter |
|
31 | * - TYPE : return type of the getter | |
32 | */ |
|
32 | */ | |
33 | // clang-format off |
|
33 | // clang-format off | |
34 | #define DECLARE_PROPERTY_GETTER(GETTER_NAME, PROPERTY_NAME, TYPE) \ |
|
34 | #define DECLARE_PROPERTY_GETTER(GETTER_NAME, PROPERTY_NAME, TYPE) \ | |
35 | TYPE GETTER_NAME() const \ |
|
35 | TYPE GETTER_NAME() const \ | |
36 | { \ |
|
36 | { \ | |
37 | static auto result = m_Properties.value(PROPERTY_NAME##_PROPERTY, PROPERTY_NAME##_DEFAULT_VALUE).value<TYPE>(); \ |
|
37 | static auto result = m_Properties.value(PROPERTY_NAME##_PROPERTY, PROPERTY_NAME##_DEFAULT_VALUE).value<TYPE>(); \ | |
38 | return result; \ |
|
38 | return result; \ | |
39 | } \ |
|
39 | } \ | |
40 | // clang-format on |
|
40 | // clang-format on | |
41 |
|
41 | |||
42 | namespace { |
|
42 | namespace { | |
43 |
|
43 | |||
44 | // /////// // |
|
44 | // /////// // | |
45 | // Aliases // |
|
45 | // Aliases // | |
46 | // /////// // |
|
46 | // /////// // | |
47 |
|
47 | |||
48 | using IntPair = std::pair<int, int>; |
|
48 | using IntPair = std::pair<int, int>; | |
49 | using Weight = double; |
|
49 | using Weight = double; | |
50 | using Weights = std::vector<Weight>; |
|
50 | using Weights = std::vector<Weight>; | |
51 |
|
51 | |||
52 | struct OperationProperty { |
|
52 | struct OperationProperty { | |
53 | Weight m_Weight{1.}; |
|
53 | Weight m_Weight{1.}; | |
54 | bool m_WaitAcquisition{false}; |
|
54 | bool m_WaitAcquisition{false}; | |
55 | }; |
|
55 | }; | |
56 |
|
56 | |||
57 | using VariableOperation = std::pair<VariableId, std::shared_ptr<IFuzzingOperation> >; |
|
57 | using VariableOperation = std::pair<VariableId, std::shared_ptr<IFuzzingOperation> >; | |
58 | using VariablesOperations = std::vector<VariableOperation>; |
|
58 | using VariablesOperations = std::vector<VariableOperation>; | |
59 |
|
59 | |||
60 | using OperationsTypes = std::map<FuzzingOperationType, OperationProperty>; |
|
60 | using OperationsTypes = std::map<FuzzingOperationType, OperationProperty>; | |
61 | using OperationsPool = std::map<std::shared_ptr<IFuzzingOperation>, OperationProperty>; |
|
61 | using OperationsPool = std::map<std::shared_ptr<IFuzzingOperation>, OperationProperty>; | |
62 |
|
62 | |||
63 | using Validators = std::vector<std::shared_ptr<IFuzzingValidator> >; |
|
63 | using Validators = std::vector<std::shared_ptr<IFuzzingValidator> >; | |
64 |
|
64 | |||
65 | // ///////// // |
|
65 | // ///////// // | |
66 | // Constants // |
|
66 | // Constants // | |
67 | // ///////// // |
|
67 | // ///////// // | |
68 |
|
68 | |||
69 | // Defaults values used when the associated properties have not been set for the test |
|
69 | // Defaults values used when the associated properties have not been set for the test | |
70 | const auto ACQUISITION_TIMEOUT_DEFAULT_VALUE = 30000; |
|
70 | const auto ACQUISITION_TIMEOUT_DEFAULT_VALUE = 30000; | |
71 | const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100; |
|
71 | const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100; | |
72 | const auto NB_MAX_SYNC_GROUPS_DEFAULT_VALUE = 1; |
|
72 | const auto NB_MAX_SYNC_GROUPS_DEFAULT_VALUE = 1; | |
73 | const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 1; |
|
73 | const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 1; | |
74 | const auto AVAILABLE_OPERATIONS_DEFAULT_VALUE = QVariant::fromValue( |
|
74 | const auto AVAILABLE_OPERATIONS_DEFAULT_VALUE = QVariant::fromValue( | |
75 | OperationsTypes{{FuzzingOperationType::CREATE, {1., true}}, |
|
75 | OperationsTypes{{FuzzingOperationType::CREATE, {1., true}}, | |
76 | {FuzzingOperationType::DELETE, {0.1}}, // Delete operation is less frequent |
|
76 | {FuzzingOperationType::DELETE, {0.1}}, // Delete operation is less frequent | |
77 | {FuzzingOperationType::PAN_LEFT, {1.}}, |
|
77 | {FuzzingOperationType::PAN_LEFT, {1.}}, | |
78 | {FuzzingOperationType::PAN_RIGHT, {1.}}, |
|
78 | {FuzzingOperationType::PAN_RIGHT, {1.}}, | |
79 | {FuzzingOperationType::ZOOM_IN, {1.}}, |
|
79 | {FuzzingOperationType::ZOOM_IN, {1.}}, | |
80 | {FuzzingOperationType::ZOOM_OUT, {1.}}, |
|
80 | {FuzzingOperationType::ZOOM_OUT, {1.}}, | |
81 | {FuzzingOperationType::SYNCHRONIZE, {0.8}}, |
|
81 | {FuzzingOperationType::SYNCHRONIZE, {0.8}}, | |
82 | {FuzzingOperationType::DESYNCHRONIZE, {0.4}}}); |
|
82 | {FuzzingOperationType::DESYNCHRONIZE, {0.4}}}); | |
83 | const auto CACHE_TOLERANCE_DEFAULT_VALUE = 0.2; |
|
83 | const auto CACHE_TOLERANCE_DEFAULT_VALUE = 0.2; | |
84 |
|
84 | |||
85 | /// Min/max delays between each operation (in ms) |
|
85 | /// Min/max delays between each operation (in ms) | |
86 | const auto OPERATION_DELAY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(100, 3000)); |
|
86 | const auto OPERATION_DELAY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(100, 3000)); | |
87 |
|
87 | |||
88 | /// Validators for the tests (executed in the order in which they're defined) |
|
88 | /// Validators for the tests (executed in the order in which they're defined) | |
89 | const auto VALIDATORS_DEFAULT_VALUE = QVariant::fromValue( |
|
89 | const auto VALIDATORS_DEFAULT_VALUE = QVariant::fromValue( | |
90 | ValidatorsTypes{{FuzzingValidatorType::RANGE, FuzzingValidatorType::DATA}}); |
|
90 | ValidatorsTypes{{FuzzingValidatorType::RANGE, FuzzingValidatorType::DATA}}); | |
91 |
|
91 | |||
92 | /// Min/max number of operations to execute before calling validation |
|
92 | /// Min/max number of operations to execute before calling validation | |
93 | const auto VALIDATION_FREQUENCY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(1, 10)); |
|
93 | const auto VALIDATION_FREQUENCY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(1, 10)); | |
94 |
|
94 | |||
95 | // /////// // |
|
95 | // /////// // | |
96 | // Methods // |
|
96 | // Methods // | |
97 | // /////// // |
|
97 | // /////// // | |
98 |
|
98 | |||
99 | /// Goes through the variables pool and operations pool to determine the set of {variable/operation} |
|
99 | /// Goes through the variables pool and operations pool to determine the set of {variable/operation} | |
100 | /// pairs that are valid (i.e. operation that can be executed on variable) |
|
100 | /// pairs that are valid (i.e. operation that can be executed on variable) | |
101 | std::pair<VariablesOperations, Weights> availableOperations(const FuzzingState &fuzzingState, |
|
101 | std::pair<VariablesOperations, Weights> availableOperations(const FuzzingState &fuzzingState, | |
102 | const OperationsPool &operationsPool) |
|
102 | const OperationsPool &operationsPool) | |
103 | { |
|
103 | { | |
104 | VariablesOperations result{}; |
|
104 | VariablesOperations result{}; | |
105 | Weights weights{}; |
|
105 | Weights weights{}; | |
106 |
|
106 | |||
107 | for (const auto &variablesPoolEntry : fuzzingState.m_VariablesPool) { |
|
107 | for (const auto &variablesPoolEntry : fuzzingState.m_VariablesPool) { | |
108 | auto variableId = variablesPoolEntry.first; |
|
108 | auto variableId = variablesPoolEntry.first; | |
109 |
|
109 | |||
110 | for (const auto &operationsPoolEntry : operationsPool) { |
|
110 | for (const auto &operationsPoolEntry : operationsPool) { | |
111 | auto operation = operationsPoolEntry.first; |
|
111 | auto operation = operationsPoolEntry.first; | |
112 | auto operationProperty = operationsPoolEntry.second; |
|
112 | auto operationProperty = operationsPoolEntry.second; | |
113 |
|
113 | |||
114 | // A pair is valid if the current operation can be executed on the current variable |
|
114 | // A pair is valid if the current operation can be executed on the current variable | |
115 | if (operation->canExecute(variableId, fuzzingState)) { |
|
115 | if (operation->canExecute(variableId, fuzzingState)) { | |
116 | result.push_back({variableId, operation}); |
|
116 | result.push_back({variableId, operation}); | |
117 | weights.push_back(operationProperty.m_Weight); |
|
117 | weights.push_back(operationProperty.m_Weight); | |
118 | } |
|
118 | } | |
119 | } |
|
119 | } | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | return {result, weights}; |
|
122 | return {result, weights}; | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | OperationsPool createOperationsPool(const OperationsTypes &types) |
|
125 | OperationsPool createOperationsPool(const OperationsTypes &types) | |
126 | { |
|
126 | { | |
127 | OperationsPool result{}; |
|
127 | OperationsPool result{}; | |
128 |
|
128 | |||
129 | std::transform( |
|
129 | std::transform( | |
130 | types.cbegin(), types.cend(), std::inserter(result, result.end()), [](const auto &type) { |
|
130 | types.cbegin(), types.cend(), std::inserter(result, result.end()), [](const auto &type) { | |
131 | return std::make_pair(FuzzingOperationFactory::create(type.first), type.second); |
|
131 | return std::make_pair(FuzzingOperationFactory::create(type.first), type.second); | |
132 | }); |
|
132 | }); | |
133 |
|
133 | |||
134 | return result; |
|
134 | return result; | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | Validators createValidators(const ValidatorsTypes &types) |
|
137 | Validators createValidators(const ValidatorsTypes &types) | |
138 | { |
|
138 | { | |
139 | Validators result{}; |
|
139 | Validators result{}; | |
140 |
|
140 | |||
141 | std::transform(types.cbegin(), types.cend(), std::inserter(result, result.end()), |
|
141 | std::transform(types.cbegin(), types.cend(), std::inserter(result, result.end()), | |
142 | [](const auto &type) { return FuzzingValidatorFactory::create(type); }); |
|
142 | [](const auto &type) { return FuzzingValidatorFactory::create(type); }); | |
143 |
|
143 | |||
144 | return result; |
|
144 | return result; | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | /** |
|
147 | /** | |
148 | * Validates all the variables' states passed in parameter, according to a set of validators |
|
148 | * Validates all the variables' states passed in parameter, according to a set of validators | |
149 | * @param variablesPool the variables' states |
|
149 | * @param variablesPool the variables' states | |
150 | * @param validators the validators used for validation |
|
150 | * @param validators the validators used for validation | |
151 | */ |
|
151 | */ | |
152 | void validate(const VariablesPool &variablesPool, const Validators &validators) |
|
152 | void validate(const VariablesPool &variablesPool, const Validators &validators) | |
153 | { |
|
153 | { | |
154 | for (const auto &variablesPoolEntry : variablesPool) { |
|
154 | for (const auto &variablesPoolEntry : variablesPool) { | |
155 | auto variableId = variablesPoolEntry.first; |
|
155 | auto variableId = variablesPoolEntry.first; | |
156 | const auto &variableState = variablesPoolEntry.second; |
|
156 | const auto &variableState = variablesPoolEntry.second; | |
157 |
|
157 | |||
158 | auto variableMessage = variableState.m_Variable ? variableState.m_Variable->name() |
|
158 | auto variableMessage = variableState.m_Variable ? variableState.m_Variable->name() | |
159 | : QStringLiteral("null variable"); |
|
159 | : QStringLiteral("null variable"); | |
160 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Validating state of variable at index" |
|
160 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Validating state of variable at index" | |
161 | << variableId << "(" << variableMessage << ")..."; |
|
161 | << variableId << "(" << variableMessage << ")..."; | |
162 |
|
162 | |||
163 | for (const auto &validator : validators) { |
|
163 | for (const auto &validator : validators) { | |
164 | validator->validate(VariableState{variableState}); |
|
164 | validator->validate(VariableState{variableState}); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Validation completed."; |
|
167 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Validation completed."; | |
168 | } |
|
168 | } | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | /** |
|
171 | /** | |
172 | * Class to run random tests |
|
172 | * Class to run random tests | |
173 | */ |
|
173 | */ | |
174 | class FuzzingTest { |
|
174 | class FuzzingTest { | |
175 | public: |
|
175 | public: | |
176 | explicit FuzzingTest(VariableController &variableController, Properties properties) |
|
176 | explicit FuzzingTest(VariableController &variableController, Properties properties) | |
177 | : m_VariableController{variableController}, |
|
177 | : m_VariableController{variableController}, | |
178 | m_Properties{std::move(properties)}, |
|
178 | m_Properties{std::move(properties)}, | |
179 | m_FuzzingState{} |
|
179 | m_FuzzingState{} | |
180 | { |
|
180 | { | |
181 | // Inits variables pool: at init, all variables are null |
|
181 | // Inits variables pool: at init, all variables are null | |
182 | for (auto variableId = 0; variableId < nbMaxVariables(); ++variableId) { |
|
182 | for (auto variableId = 0; variableId < nbMaxVariables(); ++variableId) { | |
183 | m_FuzzingState.m_VariablesPool[variableId] = VariableState{}; |
|
183 | m_FuzzingState.m_VariablesPool[variableId] = VariableState{}; | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | // Inits sync groups and registers them into the variable controller |
|
186 | // Inits sync groups and registers them into the variable controller | |
187 | for (auto i = 0; i < nbMaxSyncGroups(); ++i) { |
|
187 | for (auto i = 0; i < nbMaxSyncGroups(); ++i) { | |
188 | auto syncGroupId = SyncGroupId::createUuid(); |
|
188 | auto syncGroupId = SyncGroupId::createUuid(); | |
189 | variableController.onAddSynchronizationGroupId(syncGroupId); |
|
189 | variableController.onAddSynchronizationGroupId(syncGroupId); | |
190 | m_FuzzingState.m_SyncGroupsPool[syncGroupId] = SyncGroup{}; |
|
190 | m_FuzzingState.m_SyncGroupsPool[syncGroupId] = SyncGroup{}; | |
191 | } |
|
191 | } | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | void execute() |
|
194 | void execute() | |
195 | { |
|
195 | { | |
196 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Running" << nbMaxOperations() << "operations on" |
|
196 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Running" << nbMaxOperations() << "operations on" | |
197 | << nbMaxVariables() << "variable(s)..."; |
|
197 | << nbMaxVariables() << "variable(s)..."; | |
198 |
|
198 | |||
199 |
|
199 | |||
200 | // Inits the count of the number of operations before the next validation |
|
200 | // Inits the count of the number of operations before the next validation | |
201 | int nextValidationCounter = 0; |
|
201 | int nextValidationCounter = 0; | |
202 | auto updateValidationCounter = [this, &nextValidationCounter]() { |
|
202 | auto updateValidationCounter = [this, &nextValidationCounter]() { | |
203 | nextValidationCounter = RandomGenerator::instance().generateInt( |
|
203 | nextValidationCounter = RandomGenerator::instance().generateInt( | |
204 | validationFrequencies().first, validationFrequencies().second); |
|
204 | validationFrequencies().first, validationFrequencies().second); | |
205 | qCInfo(LOG_TestAmdaFuzzing()).noquote() |
|
205 | qCInfo(LOG_TestAmdaFuzzing()).noquote() | |
206 | << "Next validation in " << nextValidationCounter << "operation(s)..."; |
|
206 | << "Next validation in " << nextValidationCounter << "operation(s)..."; | |
207 | }; |
|
207 | }; | |
208 | updateValidationCounter(); |
|
208 | updateValidationCounter(); | |
209 |
|
209 | |||
210 | auto canExecute = true; |
|
210 | auto canExecute = true; | |
211 | for (auto i = 0; i < nbMaxOperations() && canExecute; ++i) { |
|
211 | for (auto i = 0; i < nbMaxOperations() && canExecute; ++i) { | |
212 | // Retrieves all operations that can be executed in the current context |
|
212 | // Retrieves all operations that can be executed in the current context | |
213 | VariablesOperations variableOperations{}; |
|
213 | VariablesOperations variableOperations{}; | |
214 | Weights weights{}; |
|
214 | Weights weights{}; | |
215 | std::tie(variableOperations, weights) |
|
215 | std::tie(variableOperations, weights) | |
216 | = availableOperations(m_FuzzingState, operationsPool()); |
|
216 | = availableOperations(m_FuzzingState, operationsPool()); | |
217 |
|
217 | |||
218 | canExecute = !variableOperations.empty(); |
|
218 | canExecute = !variableOperations.empty(); | |
219 | if (canExecute) { |
|
219 | if (canExecute) { | |
220 | --nextValidationCounter; |
|
220 | --nextValidationCounter; | |
221 |
|
221 | |||
222 | // Of the operations available, chooses a random operation and executes it |
|
222 | // Of the operations available, chooses a random operation and executes it | |
223 | auto variableOperation |
|
223 | auto variableOperation | |
224 | = RandomGenerator::instance().randomChoice(variableOperations, weights); |
|
224 | = RandomGenerator::instance().randomChoice(variableOperations, weights); | |
225 |
|
225 | |||
226 | auto variableId = variableOperation.first; |
|
226 | auto variableId = variableOperation.first; | |
227 | auto fuzzingOperation = variableOperation.second; |
|
227 | auto fuzzingOperation = variableOperation.second; | |
228 |
|
228 | |||
229 | auto waitAcquisition = nextValidationCounter == 0 |
|
229 | auto waitAcquisition = nextValidationCounter == 0 | |
230 | || operationsPool().at(fuzzingOperation).m_WaitAcquisition; |
|
230 | || operationsPool().at(fuzzingOperation).m_WaitAcquisition; | |
231 |
|
231 | |||
232 | fuzzingOperation->execute(variableId, m_FuzzingState, m_VariableController, |
|
232 | fuzzingOperation->execute(variableId, m_FuzzingState, m_VariableController, | |
233 | m_Properties); |
|
233 | m_Properties); | |
234 |
|
234 | |||
235 | if (waitAcquisition) { |
|
235 | if (waitAcquisition) { | |
236 | qCDebug(LOG_TestAmdaFuzzing()) << "Waiting for acquisition to finish..."; |
|
236 | qCDebug(LOG_TestAmdaFuzzing()) << "Waiting for acquisition to finish..."; | |
237 | SignalWaiter{m_VariableController, SIGNAL(acquisitionFinished())}.wait( |
|
237 | SignalWaiter{m_VariableController, SIGNAL(acquisitionFinished())}.wait( | |
238 | acquisitionTimeout()); |
|
238 | acquisitionTimeout()); | |
239 |
|
239 | |||
240 | // Validates variables |
|
240 | // Validates variables | |
241 | if (nextValidationCounter == 0) { |
|
241 | if (nextValidationCounter == 0) { | |
242 | validate(m_FuzzingState.m_VariablesPool, validators()); |
|
242 | validate(m_FuzzingState.m_VariablesPool, validators()); | |
243 | updateValidationCounter(); |
|
243 | updateValidationCounter(); | |
244 | } |
|
244 | } | |
245 | } |
|
245 | } | |
246 | else { |
|
246 | else { | |
247 | // Delays the next operation with a randomly generated time |
|
247 | // Delays the next operation with a randomly generated time | |
248 | auto delay = RandomGenerator::instance().generateInt(operationDelays().first, |
|
248 | auto delay = RandomGenerator::instance().generateInt(operationDelays().first, | |
249 | operationDelays().second); |
|
249 | operationDelays().second); | |
250 | qCDebug(LOG_TestAmdaFuzzing()) |
|
250 | qCDebug(LOG_TestAmdaFuzzing()) | |
251 | << "Waiting " << delay << "ms before the next operation..."; |
|
251 | << "Waiting " << delay << "ms before the next operation..."; | |
252 | QTest::qWait(delay); |
|
252 | QTest::qWait(delay); | |
253 | } |
|
253 | } | |
254 | } |
|
254 | } | |
255 | else { |
|
255 | else { | |
256 | qCInfo(LOG_TestAmdaFuzzing()).noquote() |
|
256 | qCInfo(LOG_TestAmdaFuzzing()).noquote() | |
257 | << "No more operations are available, the execution of the test will stop..."; |
|
257 | << "No more operations are available, the execution of the test will stop..."; | |
258 | } |
|
258 | } | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Execution of the test completed."; |
|
261 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Execution of the test completed."; | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | private: |
|
264 | private: | |
265 | OperationsPool operationsPool() const |
|
265 | OperationsPool operationsPool() const | |
266 | { |
|
266 | { | |
267 | static auto result = createOperationsPool( |
|
267 | static auto result = createOperationsPool( | |
268 | m_Properties.value(AVAILABLE_OPERATIONS_PROPERTY, AVAILABLE_OPERATIONS_DEFAULT_VALUE) |
|
268 | m_Properties.value(AVAILABLE_OPERATIONS_PROPERTY, AVAILABLE_OPERATIONS_DEFAULT_VALUE) | |
269 | .value<OperationsTypes>()); |
|
269 | .value<OperationsTypes>()); | |
270 | return result; |
|
270 | return result; | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | Validators validators() const |
|
273 | Validators validators() const | |
274 | { |
|
274 | { | |
275 | static auto result |
|
275 | static auto result | |
276 | = createValidators(m_Properties.value(VALIDATORS_PROPERTY, VALIDATORS_DEFAULT_VALUE) |
|
276 | = createValidators(m_Properties.value(VALIDATORS_PROPERTY, VALIDATORS_DEFAULT_VALUE) | |
277 | .value<ValidatorsTypes>()); |
|
277 | .value<ValidatorsTypes>()); | |
278 | return result; |
|
278 | return result; | |
279 | } |
|
279 | } | |
280 |
|
280 | |||
281 | DECLARE_PROPERTY_GETTER(nbMaxOperations, NB_MAX_OPERATIONS, int) |
|
281 | DECLARE_PROPERTY_GETTER(nbMaxOperations, NB_MAX_OPERATIONS, int) | |
282 | DECLARE_PROPERTY_GETTER(nbMaxSyncGroups, NB_MAX_SYNC_GROUPS, int) |
|
282 | DECLARE_PROPERTY_GETTER(nbMaxSyncGroups, NB_MAX_SYNC_GROUPS, int) | |
283 | DECLARE_PROPERTY_GETTER(nbMaxVariables, NB_MAX_VARIABLES, int) |
|
283 | DECLARE_PROPERTY_GETTER(nbMaxVariables, NB_MAX_VARIABLES, int) | |
284 | DECLARE_PROPERTY_GETTER(operationDelays, OPERATION_DELAY_BOUNDS, IntPair) |
|
284 | DECLARE_PROPERTY_GETTER(operationDelays, OPERATION_DELAY_BOUNDS, IntPair) | |
285 | DECLARE_PROPERTY_GETTER(validationFrequencies, VALIDATION_FREQUENCY_BOUNDS, IntPair) |
|
285 | DECLARE_PROPERTY_GETTER(validationFrequencies, VALIDATION_FREQUENCY_BOUNDS, IntPair) | |
286 | DECLARE_PROPERTY_GETTER(acquisitionTimeout, ACQUISITION_TIMEOUT, int) |
|
286 | DECLARE_PROPERTY_GETTER(acquisitionTimeout, ACQUISITION_TIMEOUT, int) | |
287 |
|
287 | |||
288 | VariableController &m_VariableController; |
|
288 | VariableController &m_VariableController; | |
289 | Properties m_Properties; |
|
289 | Properties m_Properties; | |
290 | FuzzingState m_FuzzingState; |
|
290 | FuzzingState m_FuzzingState; | |
291 | }; |
|
291 | }; | |
292 |
|
292 | |||
293 | } // namespace |
|
293 | } // namespace | |
294 |
|
294 | |||
295 | Q_DECLARE_METATYPE(OperationsTypes) |
|
295 | Q_DECLARE_METATYPE(OperationsTypes) | |
296 |
|
296 | |||
297 | class TestAmdaFuzzing : public QObject { |
|
297 | class TestAmdaFuzzing : public QObject { | |
298 | Q_OBJECT |
|
298 | Q_OBJECT | |
299 |
|
299 | |||
300 | private slots: |
|
300 | private slots: | |
301 | /// Input data for @sa testFuzzing() |
|
301 | /// Input data for @sa testFuzzing() | |
302 | void testFuzzing_data(); |
|
302 | void testFuzzing_data(); | |
303 | void testFuzzing(); |
|
303 | void testFuzzing(); | |
304 | }; |
|
304 | }; | |
305 |
|
305 | |||
306 | void TestAmdaFuzzing::testFuzzing_data() |
|
306 | void TestAmdaFuzzing::testFuzzing_data() | |
307 | { |
|
307 | { | |
|
308 | // Note: Comment this line to run fuzzing tests | |||
|
309 | QSKIP("Fuzzing tests are disabled by default"); | |||
|
310 | ||||
308 | // ////////////// // |
|
311 | // ////////////// // | |
309 | // Test structure // |
|
312 | // Test structure // | |
310 | // ////////////// // |
|
313 | // ////////////// // | |
311 |
|
314 | |||
312 | QTest::addColumn<Properties>("properties"); // Properties for random test |
|
315 | QTest::addColumn<Properties>("properties"); // Properties for random test | |
313 |
|
316 | |||
314 | // ////////// // |
|
317 | // ////////// // | |
315 | // Test cases // |
|
318 | // Test cases // | |
316 | // ////////// // |
|
319 | // ////////// // | |
317 |
|
320 | |||
318 | auto maxRange = SqpRange::fromDateTime({2017, 1, 1}, {0, 0}, {2017, 1, 5}, {0, 0}); |
|
321 | auto maxRange = SqpRange::fromDateTime({2017, 1, 1}, {0, 0}, {2017, 1, 5}, {0, 0}); | |
319 | MetadataPool metadataPool{{{"dataType", "vector"}, {"xml:id", "imf"}}}; |
|
322 | MetadataPool metadataPool{{{"dataType", "vector"}, {"xml:id", "imf"}}}; | |
320 |
|
323 | |||
321 | // Note: we don't use auto here as we want to pass std::shared_ptr<IDataProvider> as is in the |
|
324 | // Note: we don't use auto here as we want to pass std::shared_ptr<IDataProvider> as is in the | |
322 | // QVariant |
|
325 | // QVariant | |
323 | std::shared_ptr<IDataProvider> provider = std::make_shared<AmdaProvider>(); |
|
326 | std::shared_ptr<IDataProvider> provider = std::make_shared<AmdaProvider>(); | |
324 |
|
327 | |||
325 | QTest::newRow("fuzzingTest") << Properties{ |
|
328 | QTest::newRow("fuzzingTest") << Properties{ | |
326 | {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)}, |
|
329 | {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)}, | |
327 | {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)}, |
|
330 | {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)}, | |
328 | {PROVIDER_PROPERTY, QVariant::fromValue(provider)}}; |
|
331 | {PROVIDER_PROPERTY, QVariant::fromValue(provider)}}; | |
329 | } |
|
332 | } | |
330 |
|
333 | |||
331 | void TestAmdaFuzzing::testFuzzing() |
|
334 | void TestAmdaFuzzing::testFuzzing() | |
332 | { |
|
335 | { | |
333 | QFETCH(Properties, properties); |
|
336 | QFETCH(Properties, properties); | |
334 |
|
337 | |||
335 | // Sets cache property |
|
338 | // Sets cache property | |
336 | QSettings settings{}; |
|
339 | QSettings settings{}; | |
337 | auto cacheTolerance = properties.value(CACHE_TOLERANCE_PROPERTY, CACHE_TOLERANCE_DEFAULT_VALUE); |
|
340 | auto cacheTolerance = properties.value(CACHE_TOLERANCE_PROPERTY, CACHE_TOLERANCE_DEFAULT_VALUE); | |
338 | settings.setValue(GENERAL_TOLERANCE_AT_INIT_KEY, cacheTolerance); |
|
341 | settings.setValue(GENERAL_TOLERANCE_AT_INIT_KEY, cacheTolerance); | |
339 | settings.setValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, cacheTolerance); |
|
342 | settings.setValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, cacheTolerance); | |
340 |
|
343 | |||
341 | auto &variableController = sqpApp->variableController(); |
|
344 | auto &variableController = sqpApp->variableController(); | |
342 | auto &timeController = sqpApp->timeController(); |
|
345 | auto &timeController = sqpApp->timeController(); | |
343 |
|
346 | |||
344 | // Generates random initial range (bounded to max range) |
|
347 | // Generates random initial range (bounded to max range) | |
345 | auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE)) |
|
348 | auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE)) | |
346 | .value<SqpRange>(); |
|
349 | .value<SqpRange>(); | |
347 |
|
350 | |||
348 | QVERIFY(maxRange != INVALID_RANGE); |
|
351 | QVERIFY(maxRange != INVALID_RANGE); | |
349 |
|
352 | |||
350 | auto initialRangeStart |
|
353 | auto initialRangeStart | |
351 | = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd); |
|
354 | = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd); | |
352 | auto initialRangeEnd |
|
355 | auto initialRangeEnd | |
353 | = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd); |
|
356 | = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd); | |
354 | if (initialRangeStart > initialRangeEnd) { |
|
357 | if (initialRangeStart > initialRangeEnd) { | |
355 | std::swap(initialRangeStart, initialRangeEnd); |
|
358 | std::swap(initialRangeStart, initialRangeEnd); | |
356 | } |
|
359 | } | |
357 |
|
360 | |||
358 | // Sets initial range on time controller |
|
361 | // Sets initial range on time controller | |
359 | SqpRange initialRange{initialRangeStart, initialRangeEnd}; |
|
362 | SqpRange initialRange{initialRangeStart, initialRangeEnd}; | |
360 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Setting initial range to" << initialRange << "..."; |
|
363 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Setting initial range to" << initialRange << "..."; | |
361 | timeController.onTimeToUpdate(initialRange); |
|
364 | timeController.onTimeToUpdate(initialRange); | |
362 | properties.insert(INITIAL_RANGE_PROPERTY, QVariant::fromValue(initialRange)); |
|
365 | properties.insert(INITIAL_RANGE_PROPERTY, QVariant::fromValue(initialRange)); | |
363 |
|
366 | |||
364 | FuzzingTest test{variableController, properties}; |
|
367 | FuzzingTest test{variableController, properties}; | |
365 | test.execute(); |
|
368 | test.execute(); | |
366 | } |
|
369 | } | |
367 |
|
370 | |||
368 | int main(int argc, char *argv[]) |
|
371 | int main(int argc, char *argv[]) | |
369 | { |
|
372 | { | |
370 | QLoggingCategory::setFilterRules( |
|
373 | QLoggingCategory::setFilterRules( | |
371 | "*.warning=false\n" |
|
374 | "*.warning=false\n" | |
372 | "*.info=false\n" |
|
375 | "*.info=false\n" | |
373 | "*.debug=false\n" |
|
376 | "*.debug=false\n" | |
374 | "FuzzingOperations.info=true\n" |
|
377 | "FuzzingOperations.info=true\n" | |
375 | "FuzzingValidators.info=true\n" |
|
378 | "FuzzingValidators.info=true\n" | |
376 | "TestAmdaFuzzing.info=true\n"); |
|
379 | "TestAmdaFuzzing.info=true\n"); | |
377 |
|
380 | |||
378 | SqpApplication app{argc, argv}; |
|
381 | SqpApplication app{argc, argv}; | |
379 | SqpApplication::setOrganizationName("LPP"); |
|
382 | SqpApplication::setOrganizationName("LPP"); | |
380 | SqpApplication::setOrganizationDomain("lpp.fr"); |
|
383 | SqpApplication::setOrganizationDomain("lpp.fr"); | |
381 | SqpApplication::setApplicationName("SciQLop-TestFuzzing"); |
|
384 | SqpApplication::setApplicationName("SciQLop-TestFuzzing"); | |
382 | app.setAttribute(Qt::AA_Use96Dpi, true); |
|
385 | app.setAttribute(Qt::AA_Use96Dpi, true); | |
383 | TestAmdaFuzzing testObject{}; |
|
386 | TestAmdaFuzzing testObject{}; | |
384 | QTEST_SET_MAIN_SOURCE_PATH |
|
387 | QTEST_SET_MAIN_SOURCE_PATH | |
385 | return QTest::qExec(&testObject, argc, argv); |
|
388 | return QTest::qExec(&testObject, argc, argv); | |
386 | } |
|
389 | } | |
387 |
|
390 | |||
388 | #include "TestAmdaFuzzing.moc" |
|
391 | #include "TestAmdaFuzzing.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now