##// END OF EJS Templates
Simplify zoom test that show the bug
perrinel -
r1389:e107d05ceec4
parent child
Show More
@@ -1,572 +1,558
1 1 #include "FuzzingDefs.h"
2 2 #include "FuzzingOperations.h"
3 3 #include "FuzzingUtils.h"
4 4 #include "FuzzingValidators.h"
5 5
6 6 #include "AmdaProvider.h"
7 7
8 8 #include <Common/SignalWaiter.h>
9 9 #include <Network/NetworkController.h>
10 10 #include <Settings/SqpSettingsDefs.h>
11 11 #include <SqpApplication.h>
12 12 #include <Time/TimeController.h>
13 13 #include <Variable/Variable.h>
14 14 #include <Variable/VariableController.h>
15 15
16 16 #include <QLoggingCategory>
17 17 #include <QObject>
18 18 #include <QtTest>
19 19
20 20 #include <memory>
21 21
22 22 Q_LOGGING_CATEGORY(LOG_TestAmdaFuzzing, "TestAmdaFuzzing")
23 23
24 24 /**
25 25 * Macro used to generate a getter for a property in @sa FuzzingTest. The macro generates a static
26 26 * attribute that is initialized by searching in properties the property and use a default value if
27 27 * it's not present. Macro arguments are:
28 28 * - GETTER_NAME : name of the getter
29 29 * - PROPERTY_NAME: used to generate constants for property's name ({PROPERTY_NAME}_PROPERTY) and
30 30 * default value ({PROPERTY_NAME}_DEFAULT_VALUE)
31 31 * - TYPE : return type of the getter
32 32 */
33 33 // clang-format off
34 34 #define DECLARE_PROPERTY_GETTER(GETTER_NAME, PROPERTY_NAME, TYPE) \
35 35 TYPE GETTER_NAME() const \
36 36 { \
37 37 static auto result = m_Properties.value(PROPERTY_NAME##_PROPERTY, PROPERTY_NAME##_DEFAULT_VALUE).value<TYPE>(); \
38 38 return result; \
39 39 } \
40 40 // clang-format on
41 41
42 42 namespace {
43 43
44 44 // /////// //
45 45 // Aliases //
46 46 // /////// //
47 47
48 48 using IntPair = std::pair<int, int>;
49 49 using Weight = double;
50 50 using Weights = std::vector<Weight>;
51 51
52 52 struct OperationProperty {
53 53 Weight m_Weight{1.};
54 54 bool m_WaitAcquisition{false};
55 55 };
56 56
57 57 using VariableOperation = std::pair<VariableId, std::shared_ptr<IFuzzingOperation> >;
58 58 using VariablesOperations = std::vector<VariableOperation>;
59 59
60 60 struct CustomVariableOperation {
61 61 VariableOperation m_VariableOperation{};
62 62 bool m_WaitAcquisition{false};
63 63 };
64 64 using CustomVariablesOperations = std::vector<CustomVariableOperation>;
65 65
66 66 using OperationsTypes = std::map<FuzzingOperationType, OperationProperty>;
67 67 using OperationsPool = std::map<std::shared_ptr<IFuzzingOperation>, OperationProperty>;
68 68
69 69 using Validators = std::vector<std::shared_ptr<IFuzzingValidator> >;
70 70
71 71 // ///////// //
72 72 // Constants //
73 73 // ///////// //
74 74
75 75 // Defaults values used when the associated properties have not been set for the test
76 76 const auto ACQUISITION_TIMEOUT_DEFAULT_VALUE = 30000;
77 77 const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100;
78 78 const auto NB_MAX_SYNC_GROUPS_DEFAULT_VALUE = 1;
79 79 const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 2;
80 80 const auto AVAILABLE_OPERATIONS_DEFAULT_VALUE = QVariant::fromValue(
81 81 OperationsTypes{{FuzzingOperationType::CREATE, {400., true}},
82 82 {FuzzingOperationType::DELETE, {0.0}}, // Delete operation is less frequent
83 83 {FuzzingOperationType::PAN_LEFT, {1.}},
84 84 {FuzzingOperationType::PAN_RIGHT, {1.}},
85 {FuzzingOperationType::ZOOM_IN, {1.}},
86 {FuzzingOperationType::ZOOM_OUT, {1.}},
85 {FuzzingOperationType::ZOOM_IN, {0.}},
86 {FuzzingOperationType::ZOOM_OUT, {0.}},
87 87 {FuzzingOperationType::SYNCHRONIZE, {4000.0}},
88 88 {FuzzingOperationType::DESYNCHRONIZE, {0.4}}});
89 89 const auto CACHE_TOLERANCE_DEFAULT_VALUE = 0.2;
90 90
91 91 /// Min/max delays between each operation (in ms)
92 const auto OPERATION_DELAY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(3000, 3000));
92 const auto OPERATION_DELAY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(20, 20));
93 93
94 94 /// Validators for the tests (executed in the order in which they're defined)
95 95 const auto VALIDATORS_DEFAULT_VALUE = QVariant::fromValue(
96 96 ValidatorsTypes{{FuzzingValidatorType::RANGE, FuzzingValidatorType::DATA}});
97 97
98 98 /// Min/max number of operations to execute before calling validation
99 const auto VALIDATION_FREQUENCY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(8, 8));
99 const auto VALIDATION_FREQUENCY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(2, 2));
100 100
101 101
102 102 // /////// //////
103 103 // CUSTOM CASE //
104 104 // /////// //////
105 105
106 106 auto op = [](auto type){
107 107 return FuzzingOperationFactory::create(type);
108 108 };
109 109
110 110
111 111 const QVariant CUSTOM_CASE_ONE =QVariant::fromValue(CustomVariablesOperations{{{0, op(FuzzingOperationType::CREATE)}, true},
112 112 {{0, op(FuzzingOperationType::SYNCHRONIZE)}},
113 113 {{1, op(FuzzingOperationType::CREATE)}, true},
114 114 {{1, op(FuzzingOperationType::SYNCHRONIZE)}},
115 115 {{0, op(FuzzingOperationType::PAN_LEFT)}},
116 116 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
117 117 {{0, op(FuzzingOperationType::PAN_LEFT)}},
118 118 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
119 119 {{0, op(FuzzingOperationType::PAN_LEFT)}},
120 120 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
121 121 {{0, op(FuzzingOperationType::PAN_LEFT)}},
122 122 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
123 123 {{0, op(FuzzingOperationType::PAN_LEFT)}},
124 124 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
125 125 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
126 126 {{1, op(FuzzingOperationType::PAN_LEFT)}},
127 127 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
128 128 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
129 129 {{0, op(FuzzingOperationType::PAN_LEFT)}},
130 130 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
131 131 {{0, op(FuzzingOperationType::PAN_LEFT)}},
132 132 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
133 133 {{0, op(FuzzingOperationType::PAN_LEFT)}},
134 134 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
135 135 {{0, op(FuzzingOperationType::PAN_LEFT)}},
136 136 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
137 137 {{0, op(FuzzingOperationType::PAN_LEFT)}},
138 138 {{1, op(FuzzingOperationType::PAN_LEFT)}},
139 139 {{0, op(FuzzingOperationType::PAN_LEFT)}},
140 140 {{1, op(FuzzingOperationType::PAN_LEFT)}},
141 141 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
142 142 {{1, op(FuzzingOperationType::PAN_LEFT)}},
143 143 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
144 144 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
145 145 {{0, op(FuzzingOperationType::PAN_LEFT)}},
146 146 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
147 147 {{0, op(FuzzingOperationType::PAN_LEFT)}},
148 148 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
149 149 {{0, op(FuzzingOperationType::PAN_LEFT)}},
150 150 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
151 151 {{0, op(FuzzingOperationType::PAN_LEFT)}},
152 152 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
153 153 {{0, op(FuzzingOperationType::PAN_LEFT)}},
154 154 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
155 155 {{0, op(FuzzingOperationType::PAN_LEFT)}},
156 156 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
157 157 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
158 158 {{1, op(FuzzingOperationType::PAN_LEFT)}},
159 159 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
160 160 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
161 161 {{0, op(FuzzingOperationType::PAN_LEFT)}},
162 162 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
163 163 {{0, op(FuzzingOperationType::PAN_LEFT)}},
164 164 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
165 165 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
166 166 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
167 167 {{0, op(FuzzingOperationType::PAN_LEFT)}},
168 168 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
169 169 {{0, op(FuzzingOperationType::PAN_LEFT)}},
170 170 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
171 171 {{0, op(FuzzingOperationType::PAN_LEFT)}},
172 172 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
173 173 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
174 174 {{1, op(FuzzingOperationType::PAN_LEFT)}},
175 175 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
176 176 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
177 177 {{0, op(FuzzingOperationType::PAN_LEFT)}},
178 178 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
179 179 {{0, op(FuzzingOperationType::PAN_LEFT)}},
180 180 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
181 181 {{0, op(FuzzingOperationType::PAN_LEFT)}},
182 182 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
183 183 {{0, op(FuzzingOperationType::PAN_LEFT)}},
184 184 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
185 185 {{0, op(FuzzingOperationType::PAN_LEFT)}},
186 186 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
187 187 {{0, op(FuzzingOperationType::PAN_LEFT)}},
188 188 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
189 189 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
190 190 {{1, op(FuzzingOperationType::PAN_LEFT)}},
191 191 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
192 192 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
193 193 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
194 194 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
195 195 {{0, op(FuzzingOperationType::PAN_LEFT)}},
196 196 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
197 197 {{0, op(FuzzingOperationType::PAN_LEFT)}},
198 198 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
199 199 {{0, op(FuzzingOperationType::PAN_LEFT)}},
200 200 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
201 201 {{0, op(FuzzingOperationType::PAN_LEFT)}},
202 202 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
203 203 {{0, op(FuzzingOperationType::PAN_LEFT)}},
204 204 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
205 205 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
206 206 {{1, op(FuzzingOperationType::PAN_LEFT)}},
207 207 {{0, op(FuzzingOperationType::PAN_RIGHT)}},
208 208 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
209 209 {{0, op(FuzzingOperationType::PAN_LEFT)}},
210 210 {{1, op(FuzzingOperationType::PAN_RIGHT)}},
211 211 });
212 212
213 213 const QVariant CUSTOM_CASE_TWO =QVariant::fromValue(CustomVariablesOperations{{{0, op(FuzzingOperationType::CREATE)}, true},
214 214 {{0, op(FuzzingOperationType::SYNCHRONIZE)}},
215 215 {{1, op(FuzzingOperationType::CREATE)}, true},
216 216 {{1, op(FuzzingOperationType::SYNCHRONIZE)}},
217 {{0, op(FuzzingOperationType::ZOOM_IN)}},
218 {{1, op(FuzzingOperationType::ZOOM_IN)}},
219 {{0, op(FuzzingOperationType::ZOOM_IN)}},
220 {{1, op(FuzzingOperationType::ZOOM_OUT)}},
221 {{0, op(FuzzingOperationType::ZOOM_OUT)}},
222 217 {{1, op(FuzzingOperationType::ZOOM_OUT)}},
223 {{0, op(FuzzingOperationType::ZOOM_IN)}},
224 {{1, op(FuzzingOperationType::ZOOM_OUT)}},
225 {{0, op(FuzzingOperationType::ZOOM_IN)}},
226 {{0, op(FuzzingOperationType::ZOOM_OUT)}},
227 {{1, op(FuzzingOperationType::ZOOM_IN)}},
228 {{0, op(FuzzingOperationType::ZOOM_IN)}},
229 {{0, op(FuzzingOperationType::ZOOM_OUT)}},
230 218 {{1, op(FuzzingOperationType::ZOOM_IN)}},
231 {{0, op(FuzzingOperationType::ZOOM_IN)}},
232 {{0, op(FuzzingOperationType::ZOOM_OUT)}},
233 219 });
234 220
235 221 // /////// //
236 222 // Methods //
237 223 // /////// //
238 224
239 225 /// Goes through the variables pool and operations pool to determine the set of {variable/operation}
240 226 /// pairs that are valid (i.e. operation that can be executed on variable)
241 227 std::pair<VariablesOperations, Weights> availableOperations(const FuzzingState &fuzzingState,
242 228 const OperationsPool &operationsPool)
243 229 {
244 230 VariablesOperations result{};
245 231 Weights weights{};
246 232
247 233 for (const auto &variablesPoolEntry : fuzzingState.m_VariablesPool) {
248 234 auto variableId = variablesPoolEntry.first;
249 235
250 236 for (const auto &operationsPoolEntry : operationsPool) {
251 237 auto operation = operationsPoolEntry.first;
252 238 auto operationProperty = operationsPoolEntry.second;
253 239
254 240 // A pair is valid if the current operation can be executed on the current variable
255 241 if (operation->canExecute(variableId, fuzzingState)) {
256 242 result.push_back({variableId, operation});
257 243 weights.push_back(operationProperty.m_Weight);
258 244 }
259 245 }
260 246 }
261 247
262 248 return {result, weights};
263 249 }
264 250
265 251 OperationsPool createOperationsPool(const OperationsTypes &types)
266 252 {
267 253 OperationsPool result{};
268 254
269 255 std::transform(
270 256 types.cbegin(), types.cend(), std::inserter(result, result.end()), [](const auto &type) {
271 257 return std::make_pair(FuzzingOperationFactory::create(type.first), type.second);
272 258 });
273 259
274 260 return result;
275 261 }
276 262
277 263 Validators createValidators(const ValidatorsTypes &types)
278 264 {
279 265 Validators result{};
280 266
281 267 std::transform(types.cbegin(), types.cend(), std::inserter(result, result.end()),
282 268 [](const auto &type) { return FuzzingValidatorFactory::create(type); });
283 269
284 270 return result;
285 271 }
286 272
287 273 /**
288 274 * Validates all the variables' states passed in parameter, according to a set of validators
289 275 * @param variablesPool the variables' states
290 276 * @param validators the validators used for validation
291 277 */
292 278 void validate(const VariablesPool &variablesPool, const Validators &validators)
293 279 {
294 280 for (const auto &variablesPoolEntry : variablesPool) {
295 281 auto variableId = variablesPoolEntry.first;
296 282 const auto &variableState = variablesPoolEntry.second;
297 283
298 284 auto variableMessage = variableState.m_Variable ? variableState.m_Variable->name()
299 285 : QStringLiteral("null variable");
300 286 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Validating state of variable at index"
301 287 << variableId << "(" << variableMessage << ")...";
302 288
303 289 for (const auto &validator : validators) {
304 290 validator->validate(VariableState{variableState});
305 291 }
306 292
307 293 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Validation completed.";
308 294 }
309 295 }
310 296
311 297 /**
312 298 * Class to run random tests
313 299 */
314 300 class FuzzingTest {
315 301 public:
316 302 explicit FuzzingTest(VariableController &variableController, Properties properties)
317 303 : m_VariableController{variableController},
318 304 m_Properties{std::move(properties)},
319 305 m_FuzzingState{}
320 306 {
321 307 // Inits variables pool: at init, all variables are null
322 308 for (auto variableId = 0; variableId < nbMaxVariables(); ++variableId) {
323 309 m_FuzzingState.m_VariablesPool[variableId] = VariableState{};
324 310 }
325 311
326 312 // Inits sync groups and registers them into the variable controller
327 313 for (auto i = 0; i < nbMaxSyncGroups(); ++i) {
328 314 auto syncGroupId = SyncGroupId::createUuid();
329 315 variableController.onAddSynchronizationGroupId(syncGroupId);
330 316 m_FuzzingState.m_SyncGroupsPool[syncGroupId] = SyncGroup{};
331 317 }
332 318 }
333 319
334 320 void execute()
335 321 {
336 322
337 323 // Inits the count of the number of operations before the next validation
338 324 int nextValidationCounter = 0;
339 325 auto updateValidationCounter = [this, &nextValidationCounter]() {
340 326 nextValidationCounter = RandomGenerator::instance().generateInt(
341 327 validationFrequencies().first, validationFrequencies().second);
342 328 qCInfo(LOG_TestAmdaFuzzing()).noquote()
343 329 << "Next validation in " << nextValidationCounter << "operation(s)...";
344 330 };
345 331 updateValidationCounter();
346 332
347 333 // Get custom operations
348 334 auto customOperations = m_Properties.value(CUSTOM_OPERATIONS_PROPERTY).value<CustomVariablesOperations>();
349 335 auto isCustomTest = !customOperations.empty();
350 336
351 337 auto nbOperations = isCustomTest ? customOperations.size() : nbMaxOperations();
352 338
353 339 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Running" << nbOperations << "operations on"
354 340 << nbMaxVariables() << "variable(s)...";
355 341
356 342 auto canExecute = true;
357 343 for (auto i = 0; i < nbOperations && canExecute; ++i) {
358 344 VariableOperation variableOperation{};
359 345 auto forceWait = false;
360 346
361 347 if(isCustomTest){
362 348 auto customOperation = customOperations.front();
363 349 variableOperation = customOperation.m_VariableOperation;
364 350 customOperations.erase(customOperations.begin());
365 351
366 352 canExecute = variableOperation.second->canExecute(variableOperation.first, m_FuzzingState);
367 353 forceWait = customOperation.m_WaitAcquisition;
368 354 } else {
369 355 // Retrieves all operations that can be executed in the current context
370 356 VariablesOperations variableOperations{};
371 357 Weights weights{};
372 358 std::tie(variableOperations, weights)
373 359 = availableOperations(m_FuzzingState, operationsPool());
374 360
375 361 // Of the operations available, chooses a random operation and executes it
376 362 variableOperation
377 363 = RandomGenerator::instance().randomChoice(variableOperations, weights);
378 364 canExecute = !variableOperations.empty();
379 365 forceWait = operationsPool().at(variableOperation.second).m_WaitAcquisition;
380 366 }
381 367
382 368 if (canExecute) {
383 369 --nextValidationCounter;
384 370
385 371 auto variableId = variableOperation.first;
386 372 auto fuzzingOperation = variableOperation.second;
387 373
388 374 auto waitAcquisition = nextValidationCounter == 0
389 375 || forceWait;
390 376
391 377 fuzzingOperation->execute(variableId, m_FuzzingState, m_VariableController,
392 378 m_Properties);
393 379
394 380 if (waitAcquisition) {
395 381 qCDebug(LOG_TestAmdaFuzzing()) << "Waiting for acquisition to finish...";
396 382 SignalWaiter{m_VariableController, SIGNAL(acquisitionFinished())}.wait(
397 383 acquisitionTimeout());
398 384
399 385 // Validates variables
400 386 if (nextValidationCounter == 0) {
401 387 validate(m_FuzzingState.m_VariablesPool, validators());
402 388 updateValidationCounter();
403 389 }
404 390 }
405 391 else {
406 392 // Delays the next operation with a randomly generated time
407 393 auto delay = RandomGenerator::instance().generateInt(operationDelays().first,
408 394 operationDelays().second);
409 395 qCDebug(LOG_TestAmdaFuzzing())
410 396 << "Waiting " << delay << "ms before the next operation...";
411 397 QTest::qWait(delay);
412 398 }
413 399 }
414 400 else {
415 401 qCInfo(LOG_TestAmdaFuzzing()).noquote()
416 402 << "No more operations are available, the execution of the test will stop...";
417 403 }
418 404 }
419 405
420 406 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Execution of the test completed.";
421 407 }
422 408
423 409 private:
424 410 OperationsPool operationsPool() const
425 411 {
426 412 static auto result = createOperationsPool(
427 413 m_Properties.value(AVAILABLE_OPERATIONS_PROPERTY, AVAILABLE_OPERATIONS_DEFAULT_VALUE)
428 414 .value<OperationsTypes>());
429 415 return result;
430 416 }
431 417
432 418 Validators validators() const
433 419 {
434 420 static auto result
435 421 = createValidators(m_Properties.value(VALIDATORS_PROPERTY, VALIDATORS_DEFAULT_VALUE)
436 422 .value<ValidatorsTypes>());
437 423 return result;
438 424 }
439 425
440 426 DECLARE_PROPERTY_GETTER(nbMaxOperations, NB_MAX_OPERATIONS, int)
441 427 DECLARE_PROPERTY_GETTER(nbMaxSyncGroups, NB_MAX_SYNC_GROUPS, int)
442 428 DECLARE_PROPERTY_GETTER(nbMaxVariables, NB_MAX_VARIABLES, int)
443 429 DECLARE_PROPERTY_GETTER(operationDelays, OPERATION_DELAY_BOUNDS, IntPair)
444 430 DECLARE_PROPERTY_GETTER(validationFrequencies, VALIDATION_FREQUENCY_BOUNDS, IntPair)
445 431 DECLARE_PROPERTY_GETTER(acquisitionTimeout, ACQUISITION_TIMEOUT, int)
446 432
447 433 VariableController &m_VariableController;
448 434 Properties m_Properties;
449 435 FuzzingState m_FuzzingState;
450 436 };
451 437
452 438 } // namespace
453 439
454 440 Q_DECLARE_METATYPE(OperationsTypes)
455 441 Q_DECLARE_METATYPE(CustomVariablesOperations)
456 442
457 443 class TestAmdaFuzzing : public QObject {
458 444 Q_OBJECT
459 445
460 446 private slots:
461 447 /// Input data for @sa testFuzzing()
462 448 void testFuzzing_data();
463 449 void testFuzzing();
464 450 };
465 451
466 452 void TestAmdaFuzzing::testFuzzing_data()
467 453 {
468 454 // Note: Comment this line to run fuzzing tests
469 455 // QSKIP("Fuzzing tests are disabled by default");
470 456
471 457 // ////////////// //
472 458 // Test structure //
473 459 // ////////////// //
474 460
475 461 QTest::addColumn<Properties>("properties"); // Properties for random test
476 462
477 463 // ////////// //
478 464 // Test cases //
479 465 // ////////// //
480 466
481 auto maxRange = SqpRange::fromDateTime({2017, 1, 1}, {0, 0}, {2017, 1, 5}, {0, 0});
467 auto maxRange = SqpRange::fromDateTime({2017, 1, 3}, {0, 0}, {2017, 1, 5}, {0, 0});
482 468 MetadataPool metadataPool{{{"dataType", "vector"}, {"xml:id", "c1_b"}}};
483 469
484 470 // Note: we don't use auto here as we want to pass std::shared_ptr<IDataProvider> as is in the
485 471 // QVariant
486 472 std::shared_ptr<IDataProvider> provider = std::make_shared<AmdaProvider>();
487 473
488 474
489 475 // Case Custom one : Only lot of pan on two variables synchronized
490 476 // QTest::newRow("fuzzingTestPan") << Properties{
491 477 // {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)},
492 478 // {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)},
493 479 // {PROVIDER_PROPERTY, QVariant::fromValue(provider)},
494 480 // {CUSTOM_OPERATIONS_PROPERTY, CUSTOM_CASE_ONE}};
495 481
496 482 QTest::newRow("fuzzingTestZoom") << Properties{
497 483 {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)},
498 484 {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)},
499 485 {PROVIDER_PROPERTY, QVariant::fromValue(provider)},
500 486 {CUSTOM_OPERATIONS_PROPERTY, CUSTOM_CASE_TWO}};
501 487
502 488
503 // Fuzzing
489 //// Fuzzing
504 490 // QTest::newRow("fuzzingTest") << Properties{
505 491 // {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)},
506 492 // {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)},
507 493 // {PROVIDER_PROPERTY, QVariant::fromValue(provider)}};
508 494
509 495 }
510 496
511 497 void TestAmdaFuzzing::testFuzzing()
512 498 {
513 499 QFETCH(Properties, properties);
514 500
515 501 // Sets cache property
516 502 QSettings settings{};
517 503 auto cacheTolerance = properties.value(CACHE_TOLERANCE_PROPERTY, CACHE_TOLERANCE_DEFAULT_VALUE);
518 504 settings.setValue(GENERAL_TOLERANCE_AT_INIT_KEY, cacheTolerance);
519 505 settings.setValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, cacheTolerance);
520 506
521 507 auto &variableController = sqpApp->variableController();
522 508 auto &timeController = sqpApp->timeController();
523 509
524 510 // Generates random initial range (bounded to max range)
525 511 auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE))
526 512 .value<SqpRange>();
527 513
528 514 QVERIFY(maxRange != INVALID_RANGE);
529 515
530 516 auto initialRangeStart
531 517 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
532 518 auto initialRangeEnd
533 519 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
534 520 if (initialRangeStart > initialRangeEnd) {
535 521 std::swap(initialRangeStart, initialRangeEnd);
536 522 }
537 523
538 524 // Sets initial range on time controller
539 525 SqpRange initialRange{initialRangeStart, initialRangeEnd};
540 526 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Setting initial range to" << initialRange << "...";
541 527 timeController.onTimeToUpdate(initialRange);
542 528 properties.insert(INITIAL_RANGE_PROPERTY, QVariant::fromValue(initialRange));
543 529
544 530 FuzzingTest test{variableController, properties};
545 531 test.execute();
546 532 }
547 533
548 534 int main(int argc, char *argv[])
549 535 {
550 536 // Increases the test function timeout (which is 5 minutes by default) to 12 hours
551 537 // https://stackoverflow.com/questions/42655932/setting-timeout-to-qt-test
552 538 qputenv("QTEST_FUNCTION_TIMEOUT", QByteArray::number(12*60*60*1000));
553 539
554 540 QLoggingCategory::setFilterRules(
555 541 "*.warning=false\n"
556 542 "*.info=false\n"
557 543 "*.debug=false\n"
558 544 "FuzzingOperations.info=true\n"
559 545 "FuzzingValidators.info=true\n"
560 546 "TestAmdaFuzzing.info=true\n");
561 547
562 548 SqpApplication app{argc, argv};
563 549 SqpApplication::setOrganizationName("LPP");
564 550 SqpApplication::setOrganizationDomain("lpp.fr");
565 551 SqpApplication::setApplicationName("SciQLop-TestFuzzing");
566 552 app.setAttribute(Qt::AA_Use96Dpi, true);
567 553 TestAmdaFuzzing testObject{};
568 554 QTEST_SET_MAIN_SOURCE_PATH
569 555 return QTest::qExec(&testObject, argc, argv);
570 556 }
571 557
572 558 #include "TestAmdaFuzzing.moc"
General Comments 0
You need to be logged in to leave comments. Login now