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