##// END OF EJS Templates
Adds the ability to force an acquisition pending for an operation (2)...
Alexandre Leroux -
r1250:a7d21961e1ef
parent child
Show More
@@ -1,385 +1,388
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(WeightedOperationsTypes{
74 const auto AVAILABLE_OPERATIONS_DEFAULT_VALUE = QVariant::fromValue(WeightedOperationsTypes{
75 {FuzzingOperationType::CREATE, 1.},
75 {FuzzingOperationType::CREATE, 1.},
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
231
231 fuzzingOperation->execute(variableId, m_FuzzingState, m_VariableController,
232 fuzzingOperation->execute(variableId, m_FuzzingState, m_VariableController,
232 m_Properties);
233 m_Properties);
233
234
234 if (waitAcquisition) {
235 if (waitAcquisition) {
235 qCDebug(LOG_TestAmdaFuzzing()) << "Waiting for acquisition to finish...";
236 qCDebug(LOG_TestAmdaFuzzing()) << "Waiting for acquisition to finish...";
236 SignalWaiter{m_VariableController, SIGNAL(acquisitionFinished())}.wait(
237 SignalWaiter{m_VariableController, SIGNAL(acquisitionFinished())}.wait(
237 acquisitionTimeout());
238 acquisitionTimeout());
238
239
239 // Validates variables
240 // Validates variables
241 if (nextValidationCounter == 0) {
240 validate(m_FuzzingState.m_VariablesPool, validators());
242 validate(m_FuzzingState.m_VariablesPool, validators());
241 updateValidationCounter();
243 updateValidationCounter();
242 }
244 }
245 }
243 else {
246 else {
244 // Delays the next operation with a randomly generated time
247 // Delays the next operation with a randomly generated time
245 auto delay = RandomGenerator::instance().generateInt(operationDelays().first,
248 auto delay = RandomGenerator::instance().generateInt(operationDelays().first,
246 operationDelays().second);
249 operationDelays().second);
247 qCDebug(LOG_TestAmdaFuzzing())
250 qCDebug(LOG_TestAmdaFuzzing())
248 << "Waiting " << delay << "ms before the next operation...";
251 << "Waiting " << delay << "ms before the next operation...";
249 QTest::qWait(delay);
252 QTest::qWait(delay);
250 }
253 }
251 }
254 }
252 else {
255 else {
253 qCInfo(LOG_TestAmdaFuzzing()).noquote()
256 qCInfo(LOG_TestAmdaFuzzing()).noquote()
254 << "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...";
255 }
258 }
256 }
259 }
257
260
258 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Execution of the test completed.";
261 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Execution of the test completed.";
259 }
262 }
260
263
261 private:
264 private:
262 OperationsPool operationsPool() const
265 OperationsPool operationsPool() const
263 {
266 {
264 static auto result = createOperationsPool(
267 static auto result = createOperationsPool(
265 m_Properties.value(AVAILABLE_OPERATIONS_PROPERTY, AVAILABLE_OPERATIONS_DEFAULT_VALUE)
268 m_Properties.value(AVAILABLE_OPERATIONS_PROPERTY, AVAILABLE_OPERATIONS_DEFAULT_VALUE)
266 .value<OperationsTypes>());
269 .value<OperationsTypes>());
267 return result;
270 return result;
268 }
271 }
269
272
270 Validators validators() const
273 Validators validators() const
271 {
274 {
272 static auto result
275 static auto result
273 = createValidators(m_Properties.value(VALIDATORS_PROPERTY, VALIDATORS_DEFAULT_VALUE)
276 = createValidators(m_Properties.value(VALIDATORS_PROPERTY, VALIDATORS_DEFAULT_VALUE)
274 .value<ValidatorsTypes>());
277 .value<ValidatorsTypes>());
275 return result;
278 return result;
276 }
279 }
277
280
278 DECLARE_PROPERTY_GETTER(nbMaxOperations, NB_MAX_OPERATIONS, int)
281 DECLARE_PROPERTY_GETTER(nbMaxOperations, NB_MAX_OPERATIONS, int)
279 DECLARE_PROPERTY_GETTER(nbMaxSyncGroups, NB_MAX_SYNC_GROUPS, int)
282 DECLARE_PROPERTY_GETTER(nbMaxSyncGroups, NB_MAX_SYNC_GROUPS, int)
280 DECLARE_PROPERTY_GETTER(nbMaxVariables, NB_MAX_VARIABLES, int)
283 DECLARE_PROPERTY_GETTER(nbMaxVariables, NB_MAX_VARIABLES, int)
281 DECLARE_PROPERTY_GETTER(operationDelays, OPERATION_DELAY_BOUNDS, IntPair)
284 DECLARE_PROPERTY_GETTER(operationDelays, OPERATION_DELAY_BOUNDS, IntPair)
282 DECLARE_PROPERTY_GETTER(validationFrequencies, VALIDATION_FREQUENCY_BOUNDS, IntPair)
285 DECLARE_PROPERTY_GETTER(validationFrequencies, VALIDATION_FREQUENCY_BOUNDS, IntPair)
283 DECLARE_PROPERTY_GETTER(acquisitionTimeout, ACQUISITION_TIMEOUT, int)
286 DECLARE_PROPERTY_GETTER(acquisitionTimeout, ACQUISITION_TIMEOUT, int)
284
287
285 VariableController &m_VariableController;
288 VariableController &m_VariableController;
286 Properties m_Properties;
289 Properties m_Properties;
287 FuzzingState m_FuzzingState;
290 FuzzingState m_FuzzingState;
288 };
291 };
289
292
290 } // namespace
293 } // namespace
291
294
292 Q_DECLARE_METATYPE(OperationsTypes)
295 Q_DECLARE_METATYPE(OperationsTypes)
293
296
294 class TestAmdaFuzzing : public QObject {
297 class TestAmdaFuzzing : public QObject {
295 Q_OBJECT
298 Q_OBJECT
296
299
297 private slots:
300 private slots:
298 /// Input data for @sa testFuzzing()
301 /// Input data for @sa testFuzzing()
299 void testFuzzing_data();
302 void testFuzzing_data();
300 void testFuzzing();
303 void testFuzzing();
301 };
304 };
302
305
303 void TestAmdaFuzzing::testFuzzing_data()
306 void TestAmdaFuzzing::testFuzzing_data()
304 {
307 {
305 // ////////////// //
308 // ////////////// //
306 // Test structure //
309 // Test structure //
307 // ////////////// //
310 // ////////////// //
308
311
309 QTest::addColumn<Properties>("properties"); // Properties for random test
312 QTest::addColumn<Properties>("properties"); // Properties for random test
310
313
311 // ////////// //
314 // ////////// //
312 // Test cases //
315 // Test cases //
313 // ////////// //
316 // ////////// //
314
317
315 auto maxRange = SqpRange::fromDateTime({2017, 1, 1}, {0, 0}, {2017, 1, 5}, {0, 0});
318 auto maxRange = SqpRange::fromDateTime({2017, 1, 1}, {0, 0}, {2017, 1, 5}, {0, 0});
316 MetadataPool metadataPool{{{"dataType", "vector"}, {"xml:id", "imf"}}};
319 MetadataPool metadataPool{{{"dataType", "vector"}, {"xml:id", "imf"}}};
317
320
318 // Note: we don't use auto here as we want to pass std::shared_ptr<IDataProvider> as is in the
321 // Note: we don't use auto here as we want to pass std::shared_ptr<IDataProvider> as is in the
319 // QVariant
322 // QVariant
320 std::shared_ptr<IDataProvider> provider = std::make_shared<AmdaProvider>();
323 std::shared_ptr<IDataProvider> provider = std::make_shared<AmdaProvider>();
321
324
322 QTest::newRow("fuzzingTest") << Properties{
325 QTest::newRow("fuzzingTest") << Properties{
323 {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)},
326 {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)},
324 {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)},
327 {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)},
325 {PROVIDER_PROPERTY, QVariant::fromValue(provider)}};
328 {PROVIDER_PROPERTY, QVariant::fromValue(provider)}};
326 }
329 }
327
330
328 void TestAmdaFuzzing::testFuzzing()
331 void TestAmdaFuzzing::testFuzzing()
329 {
332 {
330 QFETCH(Properties, properties);
333 QFETCH(Properties, properties);
331
334
332 // Sets cache property
335 // Sets cache property
333 QSettings settings{};
336 QSettings settings{};
334 auto cacheTolerance = properties.value(CACHE_TOLERANCE_PROPERTY, CACHE_TOLERANCE_DEFAULT_VALUE);
337 auto cacheTolerance = properties.value(CACHE_TOLERANCE_PROPERTY, CACHE_TOLERANCE_DEFAULT_VALUE);
335 settings.setValue(GENERAL_TOLERANCE_AT_INIT_KEY, cacheTolerance);
338 settings.setValue(GENERAL_TOLERANCE_AT_INIT_KEY, cacheTolerance);
336 settings.setValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, cacheTolerance);
339 settings.setValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, cacheTolerance);
337
340
338 auto &variableController = sqpApp->variableController();
341 auto &variableController = sqpApp->variableController();
339 auto &timeController = sqpApp->timeController();
342 auto &timeController = sqpApp->timeController();
340
343
341 // Generates random initial range (bounded to max range)
344 // Generates random initial range (bounded to max range)
342 auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE))
345 auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE))
343 .value<SqpRange>();
346 .value<SqpRange>();
344
347
345 QVERIFY(maxRange != INVALID_RANGE);
348 QVERIFY(maxRange != INVALID_RANGE);
346
349
347 auto initialRangeStart
350 auto initialRangeStart
348 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
351 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
349 auto initialRangeEnd
352 auto initialRangeEnd
350 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
353 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
351 if (initialRangeStart > initialRangeEnd) {
354 if (initialRangeStart > initialRangeEnd) {
352 std::swap(initialRangeStart, initialRangeEnd);
355 std::swap(initialRangeStart, initialRangeEnd);
353 }
356 }
354
357
355 // Sets initial range on time controller
358 // Sets initial range on time controller
356 SqpRange initialRange{initialRangeStart, initialRangeEnd};
359 SqpRange initialRange{initialRangeStart, initialRangeEnd};
357 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Setting initial range to" << initialRange << "...";
360 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Setting initial range to" << initialRange << "...";
358 timeController.onTimeToUpdate(initialRange);
361 timeController.onTimeToUpdate(initialRange);
359 properties.insert(INITIAL_RANGE_PROPERTY, QVariant::fromValue(initialRange));
362 properties.insert(INITIAL_RANGE_PROPERTY, QVariant::fromValue(initialRange));
360
363
361 FuzzingTest test{variableController, properties};
364 FuzzingTest test{variableController, properties};
362 test.execute();
365 test.execute();
363 }
366 }
364
367
365 int main(int argc, char *argv[])
368 int main(int argc, char *argv[])
366 {
369 {
367 QLoggingCategory::setFilterRules(
370 QLoggingCategory::setFilterRules(
368 "*.warning=false\n"
371 "*.warning=false\n"
369 "*.info=false\n"
372 "*.info=false\n"
370 "*.debug=false\n"
373 "*.debug=false\n"
371 "FuzzingOperations.info=true\n"
374 "FuzzingOperations.info=true\n"
372 "FuzzingValidators.info=true\n"
375 "FuzzingValidators.info=true\n"
373 "TestAmdaFuzzing.info=true\n");
376 "TestAmdaFuzzing.info=true\n");
374
377
375 SqpApplication app{argc, argv};
378 SqpApplication app{argc, argv};
376 SqpApplication::setOrganizationName("LPP");
379 SqpApplication::setOrganizationName("LPP");
377 SqpApplication::setOrganizationDomain("lpp.fr");
380 SqpApplication::setOrganizationDomain("lpp.fr");
378 SqpApplication::setApplicationName("SciQLop-TestFuzzing");
381 SqpApplication::setApplicationName("SciQLop-TestFuzzing");
379 app.setAttribute(Qt::AA_Use96Dpi, true);
382 app.setAttribute(Qt::AA_Use96Dpi, true);
380 TestAmdaFuzzing testObject{};
383 TestAmdaFuzzing testObject{};
381 QTEST_SET_MAIN_SOURCE_PATH
384 QTEST_SET_MAIN_SOURCE_PATH
382 return QTest::qExec(&testObject, argc, argv);
385 return QTest::qExec(&testObject, argc, argv);
383 }
386 }
384
387
385 #include "TestAmdaFuzzing.moc"
388 #include "TestAmdaFuzzing.moc"
General Comments 0
You need to be logged in to leave comments. Login now