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