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