##// END OF EJS Templates
Adds validators to the fuzzing test...
Alexandre Leroux -
r1228:6bf9a231f6d8
parent child
Show More
@@ -1,11 +1,12
1 #include "FuzzingDefs.h"
1 #include "FuzzingDefs.h"
2
2
3 const QString NB_MAX_OPERATIONS_PROPERTY = QStringLiteral("component");
3 const QString NB_MAX_OPERATIONS_PROPERTY = QStringLiteral("component");
4 const QString NB_MAX_VARIABLES_PROPERTY = QStringLiteral("nbMaxVariables");
4 const QString NB_MAX_VARIABLES_PROPERTY = QStringLiteral("nbMaxVariables");
5 const QString AVAILABLE_OPERATIONS_PROPERTY = QStringLiteral("availableOperations");
5 const QString AVAILABLE_OPERATIONS_PROPERTY = QStringLiteral("availableOperations");
6 const QString CACHE_TOLERANCE_PROPERTY = QStringLiteral("cacheTolerance");
6 const QString CACHE_TOLERANCE_PROPERTY = QStringLiteral("cacheTolerance");
7 const QString INITIAL_RANGE_PROPERTY = QStringLiteral("initialRange");
7 const QString INITIAL_RANGE_PROPERTY = QStringLiteral("initialRange");
8 const QString MAX_RANGE_PROPERTY = QStringLiteral("maxRange");
8 const QString MAX_RANGE_PROPERTY = QStringLiteral("maxRange");
9 const QString METADATA_POOL_PROPERTY = QStringLiteral("metadataPool");
9 const QString METADATA_POOL_PROPERTY = QStringLiteral("metadataPool");
10 const QString PROVIDER_PROPERTY = QStringLiteral("provider");
10 const QString PROVIDER_PROPERTY = QStringLiteral("provider");
11 const QString OPERATION_DELAY_PROPERTY = QStringLiteral("operationDelay");
11 const QString OPERATION_DELAY_PROPERTY = QStringLiteral("operationDelay");
12 const QString VALIDATORS_PROPERTY = QStringLiteral("validators");
@@ -1,63 +1,65
1 #ifndef SCIQLOP_FUZZINGDEFS_H
1 #ifndef SCIQLOP_FUZZINGDEFS_H
2 #define SCIQLOP_FUZZINGDEFS_H
2 #define SCIQLOP_FUZZINGDEFS_H
3
3
4 #include <Data/SqpRange.h>
4 #include <Data/SqpRange.h>
5
5
6 #include <QString>
6 #include <QString>
7 #include <QVariantHash>
7 #include <QVariantHash>
8
8
9 #include <memory>
9 #include <memory>
10
10
11 // /////// //
11 // /////// //
12 // Aliases //
12 // Aliases //
13 // /////// //
13 // /////// //
14
14
15 using MetadataPool = std::vector<QVariantHash>;
15 using MetadataPool = std::vector<QVariantHash>;
16 Q_DECLARE_METATYPE(MetadataPool)
16 Q_DECLARE_METATYPE(MetadataPool)
17
17
18 using Properties = QVariantHash;
18 using Properties = QVariantHash;
19
19
20 // ///////// //
20 // ///////// //
21 // Constants //
21 // Constants //
22 // ///////// //
22 // ///////// //
23
23
24 /// Max number of operations to generate
24 /// Max number of operations to generate
25 extern const QString NB_MAX_OPERATIONS_PROPERTY;
25 extern const QString NB_MAX_OPERATIONS_PROPERTY;
26
26
27 /// Max number of variables to manipulate through operations
27 /// Max number of variables to manipulate through operations
28 extern const QString NB_MAX_VARIABLES_PROPERTY;
28 extern const QString NB_MAX_VARIABLES_PROPERTY;
29
29
30 /// Set of operations available for the test
30 /// Set of operations available for the test
31 extern const QString AVAILABLE_OPERATIONS_PROPERTY;
31 extern const QString AVAILABLE_OPERATIONS_PROPERTY;
32
32
33 /// Tolerance used for variable's cache (in ratio)
33 /// Tolerance used for variable's cache (in ratio)
34 extern const QString CACHE_TOLERANCE_PROPERTY;
34 extern const QString CACHE_TOLERANCE_PROPERTY;
35
35
36 /// Range with which the timecontroller is initialized
36 /// Range with which the timecontroller is initialized
37 extern const QString INITIAL_RANGE_PROPERTY;
37 extern const QString INITIAL_RANGE_PROPERTY;
38
38
39 /// Max range that an operation can reach
39 /// Max range that an operation can reach
40 extern const QString MAX_RANGE_PROPERTY;
40 extern const QString MAX_RANGE_PROPERTY;
41
41
42 /// Set of metadata that can be associated to a variable
42 /// Set of metadata that can be associated to a variable
43 extern const QString METADATA_POOL_PROPERTY;
43 extern const QString METADATA_POOL_PROPERTY;
44
44
45 /// Provider used to retrieve data
45 /// Provider used to retrieve data
46 extern const QString PROVIDER_PROPERTY;
46 extern const QString PROVIDER_PROPERTY;
47
47
48 /// Time left for an operation to execute
48 /// Time left for an operation to execute
49 extern const QString OPERATION_DELAY_PROPERTY;
49 extern const QString OPERATION_DELAY_PROPERTY;
50
50
51 /// Validators used to validate an operation
52 extern const QString VALIDATORS_PROPERTY;
51
53
52 // /////// //
54 // /////// //
53 // Structs //
55 // Structs //
54 // /////// //
56 // /////// //
55
57
56 class Variable;
58 class Variable;
57
59
58 struct VariableState {
60 struct VariableState {
59 std::shared_ptr<Variable> m_Variable{nullptr};
61 std::shared_ptr<Variable> m_Variable{nullptr};
60 SqpRange m_Range{INVALID_RANGE};
62 SqpRange m_Range{INVALID_RANGE};
61 };
63 };
62
64
63 #endif // SCIQLOP_FUZZINGDEFS_H
65 #endif // SCIQLOP_FUZZINGDEFS_H
@@ -1,33 +1,40
1 #ifndef SCIQLOP_FUZZINGVALIDATORS_H
1 #ifndef SCIQLOP_FUZZINGVALIDATORS_H
2 #define SCIQLOP_FUZZINGVALIDATORS_H
2 #define SCIQLOP_FUZZINGVALIDATORS_H
3
3
4 #include <memory>
5 #include <set>
6
4 #include <QLoggingCategory>
7 #include <QLoggingCategory>
8 #include <QMetaType>
5
9
6 Q_DECLARE_LOGGING_CATEGORY(LOG_FuzzingValidators)
10 Q_DECLARE_LOGGING_CATEGORY(LOG_FuzzingValidators)
7
11
8 class VariableState;
12 class VariableState;
9
13
10 /// Types of validators that can be defined
14 /// Types of validators that can be defined
11 enum class FuzzingValidatorType {
15 enum class FuzzingValidatorType {
12 DATA, ///< Validates variable's data
16 DATA, ///< Validates variable's data
13 RANGE ///< Validates variable's range
17 RANGE ///< Validates variable's range
14 };
18 };
15
19
16 /**
20 /**
17 * Struct that represents a validator. A validator checks if the state of a variable is valid at the
21 * Struct that represents a validator. A validator checks if the state of a variable is valid at the
18 * moment it is called during a fuzzing test
22 * moment it is called during a fuzzing test
19 */
23 */
20 struct IFuzzingValidator {
24 struct IFuzzingValidator {
21 virtual ~IFuzzingValidator() noexcept = default;
25 virtual ~IFuzzingValidator() noexcept = default;
22
26
23 /// Validates the variable's state passed in parameter
27 /// Validates the variable's state passed in parameter
24 virtual void validate(const VariableState &variableState) const = 0;
28 virtual void validate(const VariableState &variableState) const = 0;
25 };
29 };
26
30
27 /// Factory of @sa IFuzzingValidator
31 /// Factory of @sa IFuzzingValidator
28 struct FuzzingValidatorFactory {
32 struct FuzzingValidatorFactory {
29 /// Creates a validator according to the type passed in parameter
33 /// Creates a validator according to the type passed in parameter
30 static std::unique_ptr<IFuzzingValidator> create(FuzzingValidatorType type);
34 static std::unique_ptr<IFuzzingValidator> create(FuzzingValidatorType type);
31 };
35 };
32
36
37 using ValidatorsTypes = std::vector<FuzzingValidatorType>;
38 Q_DECLARE_METATYPE(ValidatorsTypes)
39
33 #endif // SCIQLOP_FUZZINGVALIDATORS_H
40 #endif // SCIQLOP_FUZZINGVALIDATORS_H
@@ -1,280 +1,305
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
5
5 #include "AmdaProvider.h"
6 #include "AmdaProvider.h"
6
7
7 #include <Network/NetworkController.h>
8 #include <Network/NetworkController.h>
8 #include <Settings/SqpSettingsDefs.h>
9 #include <Settings/SqpSettingsDefs.h>
9 #include <SqpApplication.h>
10 #include <SqpApplication.h>
10 #include <Time/TimeController.h>
11 #include <Time/TimeController.h>
11 #include <Variable/Variable.h>
12 #include <Variable/Variable.h>
12 #include <Variable/VariableController.h>
13 #include <Variable/VariableController.h>
13
14
14 #include <QLoggingCategory>
15 #include <QLoggingCategory>
15 #include <QObject>
16 #include <QObject>
16 #include <QtTest>
17 #include <QtTest>
17
18
18 #include <memory>
19 #include <memory>
19
20
20 Q_LOGGING_CATEGORY(LOG_TestAmdaFuzzing, "TestAmdaFuzzing")
21 Q_LOGGING_CATEGORY(LOG_TestAmdaFuzzing, "TestAmdaFuzzing")
21
22
22 namespace {
23 namespace {
23
24
24 // /////// //
25 // /////// //
25 // Aliases //
26 // Aliases //
26 // /////// //
27 // /////// //
27
28
28 using VariableId = int;
29 using VariableId = int;
29 using Weight = double;
30 using Weight = double;
30 using Weights = std::vector<Weight>;
31 using Weights = std::vector<Weight>;
31
32
32 using VariableOperation = std::pair<VariableId, std::shared_ptr<IFuzzingOperation> >;
33 using VariableOperation = std::pair<VariableId, std::shared_ptr<IFuzzingOperation> >;
33 using VariablesOperations = std::vector<VariableOperation>;
34 using VariablesOperations = std::vector<VariableOperation>;
34
35
35 using WeightedOperationsPool = std::map<std::shared_ptr<IFuzzingOperation>, Weight>;
36 using WeightedOperationsPool = std::map<std::shared_ptr<IFuzzingOperation>, Weight>;
36 using VariablesPool = std::map<VariableId, VariableState>;
37 using VariablesPool = std::map<VariableId, VariableState>;
38 using Validators = std::vector<std::shared_ptr<IFuzzingValidator> >;
37
39
38 // ///////// //
40 // ///////// //
39 // Constants //
41 // Constants //
40 // ///////// //
42 // ///////// //
41
43
42 // Defaults values used when the associated properties have not been set for the test
44 // Defaults values used when the associated properties have not been set for the test
43 const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100;
45 const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100;
44 const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 1;
46 const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 1;
45 const auto AVAILABLE_OPERATIONS_DEFAULT_VALUE = QVariant::fromValue(WeightedOperationsTypes{
47 const auto AVAILABLE_OPERATIONS_DEFAULT_VALUE = QVariant::fromValue(WeightedOperationsTypes{
46 {FuzzingOperationType::CREATE, 1.},
48 {FuzzingOperationType::CREATE, 1.},
47 {FuzzingOperationType::DELETE, 0.1}, // Delete operation is less frequent
49 {FuzzingOperationType::DELETE, 0.1}, // Delete operation is less frequent
48 {FuzzingOperationType::PAN_LEFT, 1.},
50 {FuzzingOperationType::PAN_LEFT, 1.},
49 {FuzzingOperationType::PAN_RIGHT, 1.},
51 {FuzzingOperationType::PAN_RIGHT, 1.},
50 {FuzzingOperationType::ZOOM_IN, 1.},
52 {FuzzingOperationType::ZOOM_IN, 1.},
51 {FuzzingOperationType::ZOOM_OUT, 1.}});
53 {FuzzingOperationType::ZOOM_OUT, 1.}});
52 const auto CACHE_TOLERANCE_DEFAULT_VALUE = 0.2;
54 const auto CACHE_TOLERANCE_DEFAULT_VALUE = 0.2;
53
55
54 /// Delay between each operation (in ms)
56 /// Delay between each operation (in ms)
55 const auto OPERATION_DELAY_DEFAULT_VALUE = 3000;
57 const auto OPERATION_DELAY_DEFAULT_VALUE = 3000;
56
58
59 /// Validators for the tests (executed in the order in which they're defined)
60 const auto VALIDATORS_DEFAULT_VALUE = QVariant::fromValue(
61 ValidatorsTypes{{FuzzingValidatorType::RANGE, FuzzingValidatorType::DATA}});
62
57 // /////// //
63 // /////// //
58 // Methods //
64 // Methods //
59 // /////// //
65 // /////// //
60
66
61 /// Goes through the variables pool and operations pool to determine the set of {variable/operation}
67 /// Goes through the variables pool and operations pool to determine the set of {variable/operation}
62 /// pairs that are valid (i.e. operation that can be executed on variable)
68 /// pairs that are valid (i.e. operation that can be executed on variable)
63 std::pair<VariablesOperations, Weights>
69 std::pair<VariablesOperations, Weights>
64 availableOperations(const VariablesPool &variablesPool,
70 availableOperations(const VariablesPool &variablesPool,
65 const WeightedOperationsPool &operationsPool)
71 const WeightedOperationsPool &operationsPool)
66 {
72 {
67 VariablesOperations result{};
73 VariablesOperations result{};
68 Weights weights{};
74 Weights weights{};
69
75
70 for (const auto &variablesPoolEntry : variablesPool) {
76 for (const auto &variablesPoolEntry : variablesPool) {
71 auto variableId = variablesPoolEntry.first;
77 auto variableId = variablesPoolEntry.first;
72 const auto &variableState = variablesPoolEntry.second;
78 const auto &variableState = variablesPoolEntry.second;
73
79
74 for (const auto &operationsPoolEntry : operationsPool) {
80 for (const auto &operationsPoolEntry : operationsPool) {
75 auto operation = operationsPoolEntry.first;
81 auto operation = operationsPoolEntry.first;
76 auto weight = operationsPoolEntry.second;
82 auto weight = operationsPoolEntry.second;
77
83
78 // A pair is valid if the current operation can be executed on the current variable
84 // A pair is valid if the current operation can be executed on the current variable
79 if (operation->canExecute(variableState)) {
85 if (operation->canExecute(variableState)) {
80 result.push_back({variableId, operation});
86 result.push_back({variableId, operation});
81 weights.push_back(weight);
87 weights.push_back(weight);
82 }
88 }
83 }
89 }
84 }
90 }
85
91
86 return {result, weights};
92 return {result, weights};
87 }
93 }
88
94
89 WeightedOperationsPool createOperationsPool(const WeightedOperationsTypes &types)
95 WeightedOperationsPool createOperationsPool(const WeightedOperationsTypes &types)
90 {
96 {
91 WeightedOperationsPool result{};
97 WeightedOperationsPool result{};
92
98
93 std::transform(
99 std::transform(
94 types.cbegin(), types.cend(), std::inserter(result, result.end()), [](const auto &type) {
100 types.cbegin(), types.cend(), std::inserter(result, result.end()), [](const auto &type) {
95 return std::make_pair(FuzzingOperationFactory::create(type.first), type.second);
101 return std::make_pair(FuzzingOperationFactory::create(type.first), type.second);
96 });
102 });
97
103
98 return result;
104 return result;
99 }
105 }
100
106
107 Validators createValidators(const ValidatorsTypes &types)
108 {
109 Validators result{};
110
111 std::transform(types.cbegin(), types.cend(), std::inserter(result, result.end()),
112 [](const auto &type) { return FuzzingValidatorFactory::create(type); });
113
114 return result;
115 }
116
101 /**
117 /**
102 * Class to run random tests
118 * Class to run random tests
103 */
119 */
104 class FuzzingTest {
120 class FuzzingTest {
105 public:
121 public:
106 explicit FuzzingTest(VariableController &variableController, Properties properties)
122 explicit FuzzingTest(VariableController &variableController, Properties properties)
107 : m_VariableController{variableController},
123 : m_VariableController{variableController},
108 m_Properties{std::move(properties)},
124 m_Properties{std::move(properties)},
109 m_VariablesPool{}
125 m_VariablesPool{}
110 {
126 {
111 // Inits variables pool: at init, all variables are null
127 // Inits variables pool: at init, all variables are null
112 for (auto variableId = 0; variableId < nbMaxVariables(); ++variableId) {
128 for (auto variableId = 0; variableId < nbMaxVariables(); ++variableId) {
113 m_VariablesPool[variableId] = VariableState{};
129 m_VariablesPool[variableId] = VariableState{};
114 }
130 }
115 }
131 }
116
132
117 void execute()
133 void execute()
118 {
134 {
119 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Running" << nbMaxOperations() << "operations on"
135 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Running" << nbMaxOperations() << "operations on"
120 << nbMaxVariables() << "variable(s)...";
136 << nbMaxVariables() << "variable(s)...";
121
137
122 auto canExecute = true;
138 auto canExecute = true;
123 for (auto i = 0; i < nbMaxOperations() && canExecute; ++i) {
139 for (auto i = 0; i < nbMaxOperations() && canExecute; ++i) {
124 // Retrieves all operations that can be executed in the current context
140 // Retrieves all operations that can be executed in the current context
125 VariablesOperations variableOperations{};
141 VariablesOperations variableOperations{};
126 Weights weights{};
142 Weights weights{};
127 std::tie(variableOperations, weights)
143 std::tie(variableOperations, weights)
128 = availableOperations(m_VariablesPool, operationsPool());
144 = availableOperations(m_VariablesPool, operationsPool());
129
145
130 canExecute = !variableOperations.empty();
146 canExecute = !variableOperations.empty();
131 if (canExecute) {
147 if (canExecute) {
132 // Of the operations available, chooses a random operation and executes it
148 // Of the operations available, chooses a random operation and executes it
133 auto variableOperation
149 auto variableOperation
134 = RandomGenerator::instance().randomChoice(variableOperations, weights);
150 = RandomGenerator::instance().randomChoice(variableOperations, weights);
135
151
136 auto variableId = variableOperation.first;
152 auto variableId = variableOperation.first;
137 auto &variableState = m_VariablesPool.at(variableId);
153 auto &variableState = m_VariablesPool.at(variableId);
138 auto fuzzingOperation = variableOperation.second;
154 auto fuzzingOperation = variableOperation.second;
139
155
140 fuzzingOperation->execute(variableState, m_VariableController, m_Properties);
156 fuzzingOperation->execute(variableState, m_VariableController, m_Properties);
141 QTest::qWait(operationDelay());
157 QTest::qWait(operationDelay());
142 }
158 }
143 else {
159 else {
144 qCInfo(LOG_TestAmdaFuzzing()).noquote()
160 qCInfo(LOG_TestAmdaFuzzing()).noquote()
145 << "No more operations are available, the execution of the test will stop...";
161 << "No more operations are available, the execution of the test will stop...";
146 }
162 }
147 }
163 }
148
164
149 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Execution of the test completed.";
165 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Execution of the test completed.";
150 }
166 }
151
167
152 private:
168 private:
153 int nbMaxOperations() const
169 int nbMaxOperations() const
154 {
170 {
155 static auto result
171 static auto result
156 = m_Properties.value(NB_MAX_OPERATIONS_PROPERTY, NB_MAX_OPERATIONS_DEFAULT_VALUE)
172 = m_Properties.value(NB_MAX_OPERATIONS_PROPERTY, NB_MAX_OPERATIONS_DEFAULT_VALUE)
157 .toInt();
173 .toInt();
158 return result;
174 return result;
159 }
175 }
160
176
161 int nbMaxVariables() const
177 int nbMaxVariables() const
162 {
178 {
163 static auto result
179 static auto result
164 = m_Properties.value(NB_MAX_VARIABLES_PROPERTY, NB_MAX_VARIABLES_DEFAULT_VALUE).toInt();
180 = m_Properties.value(NB_MAX_VARIABLES_PROPERTY, NB_MAX_VARIABLES_DEFAULT_VALUE).toInt();
165 return result;
181 return result;
166 }
182 }
167
183
168 int operationDelay() const
184 int operationDelay() const
169 {
185 {
170 static auto result
186 static auto result
171 = m_Properties.value(OPERATION_DELAY_PROPERTY, OPERATION_DELAY_DEFAULT_VALUE).toInt();
187 = m_Properties.value(OPERATION_DELAY_PROPERTY, OPERATION_DELAY_DEFAULT_VALUE).toInt();
172 return result;
188 return result;
173 }
189 }
174
190
175 WeightedOperationsPool operationsPool() const
191 WeightedOperationsPool operationsPool() const
176 {
192 {
177 static auto result = createOperationsPool(
193 static auto result = createOperationsPool(
178 m_Properties.value(AVAILABLE_OPERATIONS_PROPERTY, AVAILABLE_OPERATIONS_DEFAULT_VALUE)
194 m_Properties.value(AVAILABLE_OPERATIONS_PROPERTY, AVAILABLE_OPERATIONS_DEFAULT_VALUE)
179 .value<WeightedOperationsTypes>());
195 .value<WeightedOperationsTypes>());
180 return result;
196 return result;
181 }
197 }
182
198
199 Validators validators() const
200 {
201 static auto result
202 = createValidators(m_Properties.value(VALIDATORS_PROPERTY, VALIDATORS_DEFAULT_VALUE)
203 .value<ValidatorsTypes>());
204 return result;
205 }
206
183 VariableController &m_VariableController;
207 VariableController &m_VariableController;
184 Properties m_Properties;
208 Properties m_Properties;
185 VariablesPool m_VariablesPool;
209 VariablesPool m_VariablesPool;
186 };
210 };
187
211
188 } // namespace
212 } // namespace
189
213
190 class TestAmdaFuzzing : public QObject {
214 class TestAmdaFuzzing : public QObject {
191 Q_OBJECT
215 Q_OBJECT
192
216
193 private slots:
217 private slots:
194 /// Input data for @sa testFuzzing()
218 /// Input data for @sa testFuzzing()
195 void testFuzzing_data();
219 void testFuzzing_data();
196 void testFuzzing();
220 void testFuzzing();
197 };
221 };
198
222
199 void TestAmdaFuzzing::testFuzzing_data()
223 void TestAmdaFuzzing::testFuzzing_data()
200 {
224 {
201 // ////////////// //
225 // ////////////// //
202 // Test structure //
226 // Test structure //
203 // ////////////// //
227 // ////////////// //
204
228
205 QTest::addColumn<Properties>("properties"); // Properties for random test
229 QTest::addColumn<Properties>("properties"); // Properties for random test
206
230
207 // ////////// //
231 // ////////// //
208 // Test cases //
232 // Test cases //
209 // ////////// //
233 // ////////// //
210
234
211 auto maxRange = SqpRange::fromDateTime({2017, 1, 1}, {0, 0}, {2017, 1, 5}, {0, 0});
235 auto maxRange = SqpRange::fromDateTime({2017, 1, 1}, {0, 0}, {2017, 1, 5}, {0, 0});
212 MetadataPool metadataPool{{{"dataType", "vector"}, {"xml:id", "imf"}}};
236 MetadataPool metadataPool{{{"dataType", "vector"}, {"xml:id", "imf"}}};
213
237
214 // Note: we don't use auto here as we want to pass std::shared_ptr<IDataProvider> as is in the
238 // Note: we don't use auto here as we want to pass std::shared_ptr<IDataProvider> as is in the
215 // QVariant
239 // QVariant
216 std::shared_ptr<IDataProvider> provider = std::make_shared<AmdaProvider>();
240 std::shared_ptr<IDataProvider> provider = std::make_shared<AmdaProvider>();
217
241
218 QTest::newRow("fuzzingTest") << Properties{
242 QTest::newRow("fuzzingTest") << Properties{
219 {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)},
243 {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)},
220 {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)},
244 {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)},
221 {PROVIDER_PROPERTY, QVariant::fromValue(provider)}};
245 {PROVIDER_PROPERTY, QVariant::fromValue(provider)}};
222 }
246 }
223
247
224 void TestAmdaFuzzing::testFuzzing()
248 void TestAmdaFuzzing::testFuzzing()
225 {
249 {
226 QFETCH(Properties, properties);
250 QFETCH(Properties, properties);
227
251
228 // Sets cache property
252 // Sets cache property
229 QSettings settings{};
253 QSettings settings{};
230 auto cacheTolerance = properties.value(CACHE_TOLERANCE_PROPERTY, CACHE_TOLERANCE_DEFAULT_VALUE);
254 auto cacheTolerance = properties.value(CACHE_TOLERANCE_PROPERTY, CACHE_TOLERANCE_DEFAULT_VALUE);
231 settings.setValue(GENERAL_TOLERANCE_AT_INIT_KEY, cacheTolerance);
255 settings.setValue(GENERAL_TOLERANCE_AT_INIT_KEY, cacheTolerance);
232 settings.setValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, cacheTolerance);
256 settings.setValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, cacheTolerance);
233
257
234 auto &variableController = sqpApp->variableController();
258 auto &variableController = sqpApp->variableController();
235 auto &timeController = sqpApp->timeController();
259 auto &timeController = sqpApp->timeController();
236
260
237 // Generates random initial range (bounded to max range)
261 // Generates random initial range (bounded to max range)
238 auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE))
262 auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE))
239 .value<SqpRange>();
263 .value<SqpRange>();
240
264
241 QVERIFY(maxRange != INVALID_RANGE);
265 QVERIFY(maxRange != INVALID_RANGE);
242
266
243 auto initialRangeStart
267 auto initialRangeStart
244 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
268 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
245 auto initialRangeEnd
269 auto initialRangeEnd
246 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
270 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
247 if (initialRangeStart > initialRangeEnd) {
271 if (initialRangeStart > initialRangeEnd) {
248 std::swap(initialRangeStart, initialRangeEnd);
272 std::swap(initialRangeStart, initialRangeEnd);
249 }
273 }
250
274
251 // Sets initial range on time controller
275 // Sets initial range on time controller
252 SqpRange initialRange{initialRangeStart, initialRangeEnd};
276 SqpRange initialRange{initialRangeStart, initialRangeEnd};
253 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Setting initial range to" << initialRange << "...";
277 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Setting initial range to" << initialRange << "...";
254 timeController.onTimeToUpdate(initialRange);
278 timeController.onTimeToUpdate(initialRange);
255 properties.insert(INITIAL_RANGE_PROPERTY, QVariant::fromValue(initialRange));
279 properties.insert(INITIAL_RANGE_PROPERTY, QVariant::fromValue(initialRange));
256
280
257 FuzzingTest test{variableController, properties};
281 FuzzingTest test{variableController, properties};
258 test.execute();
282 test.execute();
259 }
283 }
260
284
261 int main(int argc, char *argv[])
285 int main(int argc, char *argv[])
262 {
286 {
263 QLoggingCategory::setFilterRules(
287 QLoggingCategory::setFilterRules(
264 "*.warning=false\n"
288 "*.warning=false\n"
265 "*.info=false\n"
289 "*.info=false\n"
266 "*.debug=false\n"
290 "*.debug=false\n"
267 "FuzzingOperations.info=true\n"
291 "FuzzingOperations.info=true\n"
292 "FuzzingValidators.info=true\n"
268 "TestAmdaFuzzing.info=true\n");
293 "TestAmdaFuzzing.info=true\n");
269
294
270 SqpApplication app{argc, argv};
295 SqpApplication app{argc, argv};
271 SqpApplication::setOrganizationName("LPP");
296 SqpApplication::setOrganizationName("LPP");
272 SqpApplication::setOrganizationDomain("lpp.fr");
297 SqpApplication::setOrganizationDomain("lpp.fr");
273 SqpApplication::setApplicationName("SciQLop-TestFuzzing");
298 SqpApplication::setApplicationName("SciQLop-TestFuzzing");
274 app.setAttribute(Qt::AA_Use96Dpi, true);
299 app.setAttribute(Qt::AA_Use96Dpi, true);
275 TestAmdaFuzzing testObject{};
300 TestAmdaFuzzing testObject{};
276 QTEST_SET_MAIN_SOURCE_PATH
301 QTEST_SET_MAIN_SOURCE_PATH
277 return QTest::qExec(&testObject, argc, argv);
302 return QTest::qExec(&testObject, argc, argv);
278 }
303 }
279
304
280 #include "TestAmdaFuzzing.moc"
305 #include "TestAmdaFuzzing.moc"
General Comments 0
You need to be logged in to leave comments. Login now