##// END OF EJS Templates
Randomizes the number of operations to wait between calling validation (defines min/max frequencies)
Alexandre Leroux -
r1244:7202dffeda15
parent child
Show More
@@ -11,6 +11,7 const QString METADATA_POOL_PROPERTY = QStringLiteral("metadataPool");
11 11 const QString PROVIDER_PROPERTY = QStringLiteral("provider");
12 12 const QString OPERATION_DELAY_BOUNDS_PROPERTY = QStringLiteral("operationDelays");
13 13 const QString VALIDATORS_PROPERTY = QStringLiteral("validators");
14 const QString VALIDATION_FREQUENCY_BOUNDS_PROPERTY = QStringLiteral("validationFrequencyBounds");
14 15
15 16 // //////////// //
16 17 // FuzzingState //
@@ -56,6 +56,9 extern const QString OPERATION_DELAY_BOUNDS_PROPERTY;
56 56 /// Validators used to validate an operation
57 57 extern const QString VALIDATORS_PROPERTY;
58 58
59 /// Min/max number of operations to execute before calling validation of the current test's state
60 extern const QString VALIDATION_FREQUENCY_BOUNDS_PROPERTY;
61
59 62 // /////// //
60 63 // Structs //
61 64 // /////// //
@@ -61,6 +61,9 const auto OPERATION_DELAY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_
61 61 const auto VALIDATORS_DEFAULT_VALUE = QVariant::fromValue(
62 62 ValidatorsTypes{{FuzzingValidatorType::RANGE, FuzzingValidatorType::DATA}});
63 63
64 /// 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));
66
64 67 // /////// //
65 68 // Methods //
66 69 // /////// //
@@ -165,6 +168,17 public:
165 168 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Running" << nbMaxOperations() << "operations on"
166 169 << nbMaxVariables() << "variable(s)...";
167 170
171
172 // Inits the count of the number of operations before the next validation
173 int nextValidationCounter = 0;
174 auto updateValidationCounter = [this, &nextValidationCounter]() {
175 nextValidationCounter = RandomGenerator::instance().generateInt(
176 validationFrequencies().first, validationFrequencies().second);
177 qCInfo(LOG_TestAmdaFuzzing()).noquote()
178 << "Next validation in " << nextValidationCounter << "operations...";
179 };
180 updateValidationCounter();
181
168 182 auto canExecute = true;
169 183 for (auto i = 0; i < nbMaxOperations() && canExecute; ++i) {
170 184 // Retrieves all operations that can be executed in the current context
@@ -175,6 +189,8 public:
175 189
176 190 canExecute = !variableOperations.empty();
177 191 if (canExecute) {
192 --nextValidationCounter;
193
178 194 // Of the operations available, chooses a random operation and executes it
179 195 auto variableOperation
180 196 = RandomGenerator::instance().randomChoice(variableOperations, weights);
@@ -193,7 +209,10 public:
193 209 QTest::qWait(delay);
194 210
195 211 // Validates variables
212 if (nextValidationCounter == 0) {
196 213 validate(m_FuzzingState.m_VariablesPool, validators());
214 updateValidationCounter();
215 }
197 216 }
198 217 else {
199 218 qCInfo(LOG_TestAmdaFuzzing()).noquote()
@@ -253,6 +272,15 private:
253 272 return result;
254 273 }
255 274
275 std::pair<int, int> validationFrequencies() const
276 {
277 static auto result = m_Properties
278 .value(VALIDATION_FREQUENCY_BOUNDS_PROPERTY,
279 VALIDATION_FREQUENCY_BOUNDS_DEFAULT_VALUE)
280 .value<std::pair<int, int> >();
281 return result;
282 }
283
256 284 VariableController &m_VariableController;
257 285 Properties m_Properties;
258 286 FuzzingState m_FuzzingState;
General Comments 0
You need to be logged in to leave comments. Login now