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