##// END OF EJS Templates
add fuzzing amda test skip
perrinel -
r1401:5ce5cfcc084a develop
parent child
Show More
@@ -1,560 +1,560
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 = 100000;
77 77 const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 160;
78 78 const auto NB_MAX_SYNC_GROUPS_DEFAULT_VALUE = 8;
79 79 const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 30;
80 80 const auto AVAILABLE_OPERATIONS_DEFAULT_VALUE = QVariant::fromValue(
81 81 OperationsTypes{{FuzzingOperationType::CREATE, {40000., 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 85 {FuzzingOperationType::ZOOM_IN, {1.}},
86 86 {FuzzingOperationType::ZOOM_OUT, {1.}},
87 87 {FuzzingOperationType::SYNCHRONIZE, {500.0}},
88 88 {FuzzingOperationType::DESYNCHRONIZE, {0.0}}});
89 89 const auto CACHE_TOLERANCE_DEFAULT_VALUE = 0.2;
90 90
91 91 /// Min/max delays between each operation (in ms)
92 92 const auto OPERATION_DELAY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(20, 3000));
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 99 const auto VALIDATION_FREQUENCY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(2, 10));
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 217 {{1, op(FuzzingOperationType::ZOOM_OUT)}},
218 218 {{1, op(FuzzingOperationType::ZOOM_IN)}},
219 219 });
220 220
221 221 // /////// //
222 222 // Methods //
223 223 // /////// //
224 224
225 225 /// Goes through the variables pool and operations pool to determine the set of {variable/operation}
226 226 /// pairs that are valid (i.e. operation that can be executed on variable)
227 227 std::pair<VariablesOperations, Weights> availableOperations(const FuzzingState &fuzzingState,
228 228 const OperationsPool &operationsPool)
229 229 {
230 230 VariablesOperations result{};
231 231 Weights weights{};
232 232
233 233 for (const auto &variablesPoolEntry : fuzzingState.m_VariablesPool) {
234 234 auto variableId = variablesPoolEntry.first;
235 235
236 236 for (const auto &operationsPoolEntry : operationsPool) {
237 237 auto operation = operationsPoolEntry.first;
238 238 auto operationProperty = operationsPoolEntry.second;
239 239
240 240 // A pair is valid if the current operation can be executed on the current variable
241 241 if (operation->canExecute(variableId, fuzzingState)) {
242 242 result.push_back({variableId, operation});
243 243 weights.push_back(operationProperty.m_Weight);
244 244 }
245 245 }
246 246 }
247 247
248 248 return {result, weights};
249 249 }
250 250
251 251 OperationsPool createOperationsPool(const OperationsTypes &types)
252 252 {
253 253 OperationsPool result{};
254 254
255 255 std::transform(
256 256 types.cbegin(), types.cend(), std::inserter(result, result.end()), [](const auto &type) {
257 257 return std::make_pair(FuzzingOperationFactory::create(type.first), type.second);
258 258 });
259 259
260 260 return result;
261 261 }
262 262
263 263 Validators createValidators(const ValidatorsTypes &types)
264 264 {
265 265 Validators result{};
266 266
267 267 std::transform(types.cbegin(), types.cend(), std::inserter(result, result.end()),
268 268 [](const auto &type) { return FuzzingValidatorFactory::create(type); });
269 269
270 270 return result;
271 271 }
272 272
273 273 /**
274 274 * Validates all the variables' states passed in parameter, according to a set of validators
275 275 * @param variablesPool the variables' states
276 276 * @param validators the validators used for validation
277 277 */
278 278 void validate(const VariablesPool &variablesPool, const Validators &validators)
279 279 {
280 280 for (const auto &variablesPoolEntry : variablesPool) {
281 281 auto variableId = variablesPoolEntry.first;
282 282 const auto &variableState = variablesPoolEntry.second;
283 283
284 284 auto variableMessage = variableState.m_Variable ? variableState.m_Variable->name()
285 285 : QStringLiteral("null variable");
286 286 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Validating state of variable at index"
287 287 << variableId << "(" << variableMessage << ")...";
288 288
289 289 for (const auto &validator : validators) {
290 290 validator->validate(VariableState{variableState});
291 291 }
292 292
293 293 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Validation completed.";
294 294 }
295 295 }
296 296
297 297 /**
298 298 * Class to run random tests
299 299 */
300 300 class FuzzingTest {
301 301 public:
302 302 explicit FuzzingTest(VariableController &variableController, Properties properties)
303 303 : m_VariableController{variableController},
304 304 m_Properties{std::move(properties)},
305 305 m_FuzzingState{}
306 306 {
307 307 // Inits variables pool: at init, all variables are null
308 308 for (auto variableId = 0; variableId < nbMaxVariables(); ++variableId) {
309 309 m_FuzzingState.m_VariablesPool[variableId] = VariableState{};
310 310 }
311 311
312 312 // Inits sync groups and registers them into the variable controller
313 313 for (auto i = 0; i < nbMaxSyncGroups(); ++i) {
314 314 auto syncGroupId = SyncGroupId::createUuid();
315 315 variableController.onAddSynchronizationGroupId(syncGroupId);
316 316 m_FuzzingState.m_SyncGroupsPool[syncGroupId] = SyncGroup{};
317 317 }
318 318 }
319 319
320 320 void execute()
321 321 {
322 322
323 323 // Inits the count of the number of operations before the next validation
324 324 int nextValidationCounter = 0;
325 325 auto updateValidationCounter = [this, &nextValidationCounter]() {
326 326 nextValidationCounter = RandomGenerator::instance().generateInt(
327 327 validationFrequencies().first, validationFrequencies().second);
328 328 qCInfo(LOG_TestAmdaFuzzing()).noquote()
329 329 << "Next validation in " << nextValidationCounter << "operation(s)...";
330 330 };
331 331 updateValidationCounter();
332 332
333 333 // Get custom operations
334 334 auto customOperations = m_Properties.value(CUSTOM_OPERATIONS_PROPERTY).value<CustomVariablesOperations>();
335 335 auto isCustomTest = !customOperations.empty();
336 336
337 337 auto nbOperations = isCustomTest ? customOperations.size() : nbMaxOperations();
338 338
339 339 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Running" << nbOperations << "operations on"
340 340 << nbMaxVariables() << "variable(s)...";
341 341
342 342 auto canExecute = true;
343 343 for (auto i = 0; i < nbOperations && canExecute; ++i) {
344 344 VariableOperation variableOperation{};
345 345 auto forceWait = false;
346 346
347 347 if(isCustomTest){
348 348 auto customOperation = customOperations.front();
349 349 variableOperation = customOperation.m_VariableOperation;
350 350 customOperations.erase(customOperations.begin());
351 351
352 352 canExecute = variableOperation.second->canExecute(variableOperation.first, m_FuzzingState);
353 353 forceWait = customOperation.m_WaitAcquisition;
354 354 } else {
355 355 // Retrieves all operations that can be executed in the current context
356 356 VariablesOperations variableOperations{};
357 357 Weights weights{};
358 358 std::tie(variableOperations, weights)
359 359 = availableOperations(m_FuzzingState, operationsPool());
360 360
361 361 // Of the operations available, chooses a random operation and executes it
362 362 variableOperation
363 363 = RandomGenerator::instance().randomChoice(variableOperations, weights);
364 364 canExecute = !variableOperations.empty();
365 365 forceWait = operationsPool().at(variableOperation.second).m_WaitAcquisition;
366 366 }
367 367
368 368 if (canExecute) {
369 369 --nextValidationCounter;
370 370
371 371 auto variableId = variableOperation.first;
372 372 auto fuzzingOperation = variableOperation.second;
373 373
374 374 auto waitAcquisition = nextValidationCounter == 0
375 375 || forceWait;
376 376
377 377 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Operation :" << i +1 << " on"
378 378 << nbOperations;
379 379 fuzzingOperation->execute(variableId, m_FuzzingState, m_VariableController,
380 380 m_Properties);
381 381
382 382 if (waitAcquisition) {
383 383 qCDebug(LOG_TestAmdaFuzzing()) << "Waiting for acquisition to finish...";
384 384 SignalWaiter{m_VariableController, SIGNAL(acquisitionFinished())}.wait(
385 385 acquisitionTimeout());
386 386
387 387 // Validates variables
388 388 if (nextValidationCounter == 0) {
389 389 validate(m_FuzzingState.m_VariablesPool, validators());
390 390 updateValidationCounter();
391 391 }
392 392 }
393 393 else {
394 394 // Delays the next operation with a randomly generated time
395 395 auto delay = RandomGenerator::instance().generateInt(operationDelays().first,
396 396 operationDelays().second);
397 397 qCDebug(LOG_TestAmdaFuzzing())
398 398 << "Waiting " << delay << "ms before the next operation...";
399 399 QTest::qWait(delay);
400 400 }
401 401 }
402 402 else {
403 403 qCInfo(LOG_TestAmdaFuzzing()).noquote()
404 404 << "No more operations are available, the execution of the test will stop...";
405 405 }
406 406 }
407 407
408 408 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Execution of the test completed.";
409 409 }
410 410
411 411 private:
412 412 OperationsPool operationsPool() const
413 413 {
414 414 static auto result = createOperationsPool(
415 415 m_Properties.value(AVAILABLE_OPERATIONS_PROPERTY, AVAILABLE_OPERATIONS_DEFAULT_VALUE)
416 416 .value<OperationsTypes>());
417 417 return result;
418 418 }
419 419
420 420 Validators validators() const
421 421 {
422 422 static auto result
423 423 = createValidators(m_Properties.value(VALIDATORS_PROPERTY, VALIDATORS_DEFAULT_VALUE)
424 424 .value<ValidatorsTypes>());
425 425 return result;
426 426 }
427 427
428 428 DECLARE_PROPERTY_GETTER(nbMaxOperations, NB_MAX_OPERATIONS, int)
429 429 DECLARE_PROPERTY_GETTER(nbMaxSyncGroups, NB_MAX_SYNC_GROUPS, int)
430 430 DECLARE_PROPERTY_GETTER(nbMaxVariables, NB_MAX_VARIABLES, int)
431 431 DECLARE_PROPERTY_GETTER(operationDelays, OPERATION_DELAY_BOUNDS, IntPair)
432 432 DECLARE_PROPERTY_GETTER(validationFrequencies, VALIDATION_FREQUENCY_BOUNDS, IntPair)
433 433 DECLARE_PROPERTY_GETTER(acquisitionTimeout, ACQUISITION_TIMEOUT, int)
434 434
435 435 VariableController &m_VariableController;
436 436 Properties m_Properties;
437 437 FuzzingState m_FuzzingState;
438 438 };
439 439
440 440 } // namespace
441 441
442 442 Q_DECLARE_METATYPE(OperationsTypes)
443 443 Q_DECLARE_METATYPE(CustomVariablesOperations)
444 444
445 445 class TestAmdaFuzzing : public QObject {
446 446 Q_OBJECT
447 447
448 448 private slots:
449 449 /// Input data for @sa testFuzzing()
450 450 void testFuzzing_data();
451 451 void testFuzzing();
452 452 };
453 453
454 454 void TestAmdaFuzzing::testFuzzing_data()
455 455 {
456 456 // Note: Comment this line to run fuzzing tests
457 // QSKIP("Fuzzing tests are disabled by default");
457 QSKIP("Fuzzing tests are disabled by default");
458 458
459 459 // ////////////// //
460 460 // Test structure //
461 461 // ////////////// //
462 462
463 463 QTest::addColumn<Properties>("properties"); // Properties for random test
464 464
465 465 // ////////// //
466 466 // Test cases //
467 467 // ////////// //
468 468
469 469 auto maxRange = SqpRange::fromDateTime({2017, 1, 5}, {8, 0}, {2017, 1, 5}, {16, 0});
470 470 MetadataPool metadataPool{{{"dataType", "vector"}, {"xml:id", "c1_b"}}};
471 471
472 472 // Note: we don't use auto here as we want to pass std::shared_ptr<IDataProvider> as is in the
473 473 // QVariant
474 474 std::shared_ptr<IDataProvider> provider = std::make_shared<AmdaProvider>();
475 475
476 476
477 477 // Case Custom one : Only lot of pan on two variables synchronized
478 478 // QTest::newRow("fuzzingTestPan") << Properties{
479 479 // {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)},
480 480 // {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)},
481 481 // {PROVIDER_PROPERTY, QVariant::fromValue(provider)},
482 482 // {CUSTOM_OPERATIONS_PROPERTY, CUSTOM_CASE_ONE}};
483 483
484 484 // QTest::newRow("fuzzingTestZoom") << Properties{
485 485 // {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)},
486 486 // {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)},
487 487 // {PROVIDER_PROPERTY, QVariant::fromValue(provider)},
488 488 // {CUSTOM_OPERATIONS_PROPERTY, CUSTOM_CASE_TWO}};
489 489
490 490
491 491 //// Fuzzing
492 492 QTest::newRow("fuzzingTest") << Properties{
493 493 {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)},
494 494 {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)},
495 495 {PROVIDER_PROPERTY, QVariant::fromValue(provider)}};
496 496
497 497 }
498 498
499 499 void TestAmdaFuzzing::testFuzzing()
500 500 {
501 501 QFETCH(Properties, properties);
502 502
503 503 // Sets cache property
504 504 QSettings settings{};
505 505 auto cacheTolerance = properties.value(CACHE_TOLERANCE_PROPERTY, CACHE_TOLERANCE_DEFAULT_VALUE);
506 506 settings.setValue(GENERAL_TOLERANCE_AT_INIT_KEY, cacheTolerance);
507 507 settings.setValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, cacheTolerance);
508 508
509 509 auto &variableController = sqpApp->variableController();
510 510 auto &timeController = sqpApp->timeController();
511 511
512 512 // Generates random initial range (bounded to max range)
513 513 auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE))
514 514 .value<SqpRange>();
515 515
516 516 QVERIFY(maxRange != INVALID_RANGE);
517 517
518 518 auto initialRangeStart
519 519 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
520 520 auto initialRangeEnd
521 521 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
522 522 if (initialRangeStart > initialRangeEnd) {
523 523 std::swap(initialRangeStart, initialRangeEnd);
524 524 }
525 525
526 526 // Sets initial range on time controller
527 527 SqpRange initialRange{initialRangeStart, initialRangeEnd};
528 528 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Setting initial range to" << initialRange << "...";
529 529 timeController.onTimeToUpdate(initialRange);
530 530 properties.insert(INITIAL_RANGE_PROPERTY, QVariant::fromValue(initialRange));
531 531
532 532 FuzzingTest test{variableController, properties};
533 533 test.execute();
534 534 }
535 535
536 536 int main(int argc, char *argv[])
537 537 {
538 538 // Increases the test function timeout (which is 5 minutes by default) to 12 hours
539 539 // https://stackoverflow.com/questions/42655932/setting-timeout-to-qt-test
540 540 qputenv("QTEST_FUNCTION_TIMEOUT", QByteArray::number(12*60*60*1000));
541 541
542 542 QLoggingCategory::setFilterRules(
543 543 "*.warning=false\n"
544 544 "*.info=false\n"
545 545 "*.debug=false\n"
546 546 "FuzzingOperations.info=true\n"
547 547 "FuzzingValidators.info=true\n"
548 548 "TestAmdaFuzzing.info=true\n");
549 549
550 550 SqpApplication app{argc, argv};
551 551 SqpApplication::setOrganizationName("LPP");
552 552 SqpApplication::setOrganizationDomain("lpp.fr");
553 553 SqpApplication::setApplicationName("SciQLop-TestFuzzing");
554 554 app.setAttribute(Qt::AA_Use96Dpi, true);
555 555 TestAmdaFuzzing testObject{};
556 556 QTEST_SET_MAIN_SOURCE_PATH
557 557 return QTest::qExec(&testObject, argc, argv);
558 558 }
559 559
560 560 #include "TestAmdaFuzzing.moc"
General Comments 0
You need to be logged in to leave comments. Login now