@@ -0,0 +1,38 | |||||
|
1 | #ifndef SCIQLOP_SIGNALWAITER_H | |||
|
2 | #define SCIQLOP_SIGNALWAITER_H | |||
|
3 | ||||
|
4 | #include "CoreGlobal.h" | |||
|
5 | ||||
|
6 | #include <QEventLoop> | |||
|
7 | ||||
|
8 | /** | |||
|
9 | * Class for synchronously waiting for the reception of a signal. The signal to wait is passed to | |||
|
10 | * the construction of the object. When starting the wait, a timeout can be set to exit if the | |||
|
11 | * signal has not been sent | |||
|
12 | */ | |||
|
13 | class SCIQLOP_CORE_EXPORT SignalWaiter : public QObject { | |||
|
14 | Q_OBJECT | |||
|
15 | public: | |||
|
16 | /** | |||
|
17 | * Ctor | |||
|
18 | * @param object the sender of the signal | |||
|
19 | * @param signal the signal to listen | |||
|
20 | */ | |||
|
21 | explicit SignalWaiter(QObject &sender, const char *signal); | |||
|
22 | ||||
|
23 | /** | |||
|
24 | * Starts the signal and leaves after the signal has been received, or after the timeout | |||
|
25 | * @param timeout the timeout set (if 0, uses a default timeout) | |||
|
26 | * @return true if the signal was sent, false if the timeout occured | |||
|
27 | */ | |||
|
28 | bool wait(int timeout); | |||
|
29 | ||||
|
30 | private: | |||
|
31 | bool m_Timeout; | |||
|
32 | QEventLoop m_EventLoop; | |||
|
33 | ||||
|
34 | private slots: | |||
|
35 | void timeout(); | |||
|
36 | }; | |||
|
37 | ||||
|
38 | #endif // SCIQLOP_SIGNALWAITER_H |
@@ -0,0 +1,36 | |||||
|
1 | #include "Common/SignalWaiter.h" | |||
|
2 | ||||
|
3 | #include <QTimer> | |||
|
4 | ||||
|
5 | namespace { | |||
|
6 | ||||
|
7 | const auto DEFAULT_TIMEOUT = 30000; | |||
|
8 | ||||
|
9 | } // namespace | |||
|
10 | ||||
|
11 | SignalWaiter::SignalWaiter(QObject &sender, const char *signal) : m_Timeout{false} | |||
|
12 | { | |||
|
13 | connect(&sender, signal, &m_EventLoop, SLOT(quit())); | |||
|
14 | } | |||
|
15 | ||||
|
16 | bool SignalWaiter::wait(int timeout) | |||
|
17 | { | |||
|
18 | if (timeout == 0) { | |||
|
19 | timeout = DEFAULT_TIMEOUT; | |||
|
20 | } | |||
|
21 | ||||
|
22 | QTimer timer{}; | |||
|
23 | timer.setInterval(timeout); | |||
|
24 | timer.start(); | |||
|
25 | connect(&timer, &QTimer::timeout, this, &SignalWaiter::timeout); | |||
|
26 | ||||
|
27 | m_EventLoop.exec(); | |||
|
28 | ||||
|
29 | return !m_Timeout; | |||
|
30 | } | |||
|
31 | ||||
|
32 | void SignalWaiter::timeout() | |||
|
33 | { | |||
|
34 | m_Timeout = true; | |||
|
35 | m_EventLoop.quit(); | |||
|
36 | } |
@@ -0,0 +1,109 | |||||
|
1 | #include "FuzzingDefs.h" | |||
|
2 | ||||
|
3 | const QString ACQUISITION_TIMEOUT_PROPERTY = QStringLiteral("acquisitionTimeout"); | |||
|
4 | const QString NB_MAX_OPERATIONS_PROPERTY = QStringLiteral("component"); | |||
|
5 | const QString NB_MAX_SYNC_GROUPS_PROPERTY = QStringLiteral("nbSyncGroups"); | |||
|
6 | const QString NB_MAX_VARIABLES_PROPERTY = QStringLiteral("nbMaxVariables"); | |||
|
7 | const QString AVAILABLE_OPERATIONS_PROPERTY = QStringLiteral("availableOperations"); | |||
|
8 | const QString CACHE_TOLERANCE_PROPERTY = QStringLiteral("cacheTolerance"); | |||
|
9 | const QString INITIAL_RANGE_PROPERTY = QStringLiteral("initialRange"); | |||
|
10 | const QString MAX_RANGE_PROPERTY = QStringLiteral("maxRange"); | |||
|
11 | const QString METADATA_POOL_PROPERTY = QStringLiteral("metadataPool"); | |||
|
12 | const QString PROVIDER_PROPERTY = QStringLiteral("provider"); | |||
|
13 | const QString OPERATION_DELAY_BOUNDS_PROPERTY = QStringLiteral("operationDelays"); | |||
|
14 | const QString VALIDATORS_PROPERTY = QStringLiteral("validators"); | |||
|
15 | const QString VALIDATION_FREQUENCY_BOUNDS_PROPERTY = QStringLiteral("validationFrequencyBounds"); | |||
|
16 | ||||
|
17 | // //////////// // | |||
|
18 | // FuzzingState // | |||
|
19 | // //////////// // | |||
|
20 | ||||
|
21 | const SyncGroup &FuzzingState::syncGroup(SyncGroupId id) const | |||
|
22 | { | |||
|
23 | return m_SyncGroupsPool.at(id); | |||
|
24 | } | |||
|
25 | ||||
|
26 | SyncGroup &FuzzingState::syncGroup(SyncGroupId id) | |||
|
27 | { | |||
|
28 | return m_SyncGroupsPool.at(id); | |||
|
29 | } | |||
|
30 | ||||
|
31 | const VariableState &FuzzingState::variableState(VariableId id) const | |||
|
32 | { | |||
|
33 | return m_VariablesPool.at(id); | |||
|
34 | } | |||
|
35 | ||||
|
36 | VariableState &FuzzingState::variableState(VariableId id) | |||
|
37 | { | |||
|
38 | return m_VariablesPool.at(id); | |||
|
39 | } | |||
|
40 | ||||
|
41 | SyncGroupId FuzzingState::syncGroupId(VariableId variableId) const | |||
|
42 | { | |||
|
43 | auto end = m_SyncGroupsPool.cend(); | |||
|
44 | auto it | |||
|
45 | = std::find_if(m_SyncGroupsPool.cbegin(), end, [&variableId](const auto &syncGroupEntry) { | |||
|
46 | const auto &syncGroup = syncGroupEntry.second; | |||
|
47 | return syncGroup.m_Variables.find(variableId) != syncGroup.m_Variables.end(); | |||
|
48 | }); | |||
|
49 | ||||
|
50 | return it != end ? it->first : SyncGroupId{}; | |||
|
51 | } | |||
|
52 | ||||
|
53 | std::vector<SyncGroupId> FuzzingState::syncGroupsIds() const | |||
|
54 | { | |||
|
55 | std::vector<SyncGroupId> result{}; | |||
|
56 | ||||
|
57 | for (const auto &entry : m_SyncGroupsPool) { | |||
|
58 | result.push_back(entry.first); | |||
|
59 | } | |||
|
60 | ||||
|
61 | return result; | |||
|
62 | } | |||
|
63 | ||||
|
64 | void FuzzingState::synchronizeVariable(VariableId variableId, SyncGroupId syncGroupId) | |||
|
65 | { | |||
|
66 | if (syncGroupId.isNull()) { | |||
|
67 | return; | |||
|
68 | } | |||
|
69 | ||||
|
70 | // Registers variable into sync group: if it's the first variable, sets the variable range as | |||
|
71 | // the sync group range | |||
|
72 | auto &syncGroup = m_SyncGroupsPool.at(syncGroupId); | |||
|
73 | syncGroup.m_Variables.insert(variableId); | |||
|
74 | if (syncGroup.m_Variables.size() == 1) { | |||
|
75 | auto &variableState = m_VariablesPool.at(variableId); | |||
|
76 | syncGroup.m_Range = variableState.m_Range; | |||
|
77 | } | |||
|
78 | } | |||
|
79 | ||||
|
80 | void FuzzingState::desynchronizeVariable(VariableId variableId, SyncGroupId syncGroupId) | |||
|
81 | { | |||
|
82 | if (syncGroupId.isNull()) { | |||
|
83 | return; | |||
|
84 | } | |||
|
85 | ||||
|
86 | // Unregisters variable from sync group: if there is no more variable in the group, resets the | |||
|
87 | // range | |||
|
88 | auto &syncGroup = m_SyncGroupsPool.at(syncGroupId); | |||
|
89 | syncGroup.m_Variables.erase(variableId); | |||
|
90 | if (syncGroup.m_Variables.empty()) { | |||
|
91 | syncGroup.m_Range = INVALID_RANGE; | |||
|
92 | } | |||
|
93 | } | |||
|
94 | ||||
|
95 | void FuzzingState::updateRanges(VariableId variableId, const SqpRange &newRange) | |||
|
96 | { | |||
|
97 | auto syncGroupId = this->syncGroupId(variableId); | |||
|
98 | ||||
|
99 | // Retrieves the variables to update: | |||
|
100 | // - if the variable is synchronized to others, updates all synchronized variables | |||
|
101 | // - otherwise, updates only the variable | |||
|
102 | auto variablesToUpdate = syncGroupId.isNull() ? std::set<VariableId>{variableId} | |||
|
103 | : m_SyncGroupsPool.at(syncGroupId).m_Variables; | |||
|
104 | ||||
|
105 | // Sets new range | |||
|
106 | for (const auto &variableId : variablesToUpdate) { | |||
|
107 | m_VariablesPool.at(variableId).m_Range = newRange; | |||
|
108 | } | |||
|
109 | } |
@@ -0,0 +1,128 | |||||
|
1 | #ifndef SCIQLOP_FUZZINGDEFS_H | |||
|
2 | #define SCIQLOP_FUZZINGDEFS_H | |||
|
3 | ||||
|
4 | #include <Data/SqpRange.h> | |||
|
5 | ||||
|
6 | #include <QString> | |||
|
7 | #include <QUuid> | |||
|
8 | #include <QVariantHash> | |||
|
9 | ||||
|
10 | #include <memory> | |||
|
11 | #include <set> | |||
|
12 | ||||
|
13 | // /////// // | |||
|
14 | // Aliases // | |||
|
15 | // /////// // | |||
|
16 | ||||
|
17 | using MetadataPool = std::vector<QVariantHash>; | |||
|
18 | Q_DECLARE_METATYPE(MetadataPool) | |||
|
19 | ||||
|
20 | using Properties = QVariantHash; | |||
|
21 | ||||
|
22 | // ///////// // | |||
|
23 | // Constants // | |||
|
24 | // ///////// // | |||
|
25 | ||||
|
26 | /// Timeout set for data acquisition for an operation (in ms) | |||
|
27 | extern const QString ACQUISITION_TIMEOUT_PROPERTY; | |||
|
28 | ||||
|
29 | /// Max number of operations to generate | |||
|
30 | extern const QString NB_MAX_OPERATIONS_PROPERTY; | |||
|
31 | ||||
|
32 | /// Max number of sync groups to create through operations | |||
|
33 | extern const QString NB_MAX_SYNC_GROUPS_PROPERTY; | |||
|
34 | ||||
|
35 | /// Max number of variables to manipulate through operations | |||
|
36 | extern const QString NB_MAX_VARIABLES_PROPERTY; | |||
|
37 | ||||
|
38 | /// Set of operations available for the test | |||
|
39 | extern const QString AVAILABLE_OPERATIONS_PROPERTY; | |||
|
40 | ||||
|
41 | /// Tolerance used for variable's cache (in ratio) | |||
|
42 | extern const QString CACHE_TOLERANCE_PROPERTY; | |||
|
43 | ||||
|
44 | /// Range with which the timecontroller is initialized | |||
|
45 | extern const QString INITIAL_RANGE_PROPERTY; | |||
|
46 | ||||
|
47 | /// Max range that an operation can reach | |||
|
48 | extern const QString MAX_RANGE_PROPERTY; | |||
|
49 | ||||
|
50 | /// Set of metadata that can be associated to a variable | |||
|
51 | extern const QString METADATA_POOL_PROPERTY; | |||
|
52 | ||||
|
53 | /// Provider used to retrieve data | |||
|
54 | extern const QString PROVIDER_PROPERTY; | |||
|
55 | ||||
|
56 | /// Min/max times left for an operation to execute | |||
|
57 | extern const QString OPERATION_DELAY_BOUNDS_PROPERTY; | |||
|
58 | ||||
|
59 | /// Validators used to validate an operation | |||
|
60 | extern const QString VALIDATORS_PROPERTY; | |||
|
61 | ||||
|
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; | |||
|
64 | ||||
|
65 | // /////// // | |||
|
66 | // Structs // | |||
|
67 | // /////// // | |||
|
68 | ||||
|
69 | class Variable; | |||
|
70 | struct VariableState { | |||
|
71 | std::shared_ptr<Variable> m_Variable{nullptr}; | |||
|
72 | SqpRange m_Range{INVALID_RANGE}; | |||
|
73 | }; | |||
|
74 | ||||
|
75 | using VariableId = int; | |||
|
76 | using VariablesPool = std::map<VariableId, VariableState>; | |||
|
77 | ||||
|
78 | /** | |||
|
79 | * 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 | |||
|
81 | * that has been moved) | |||
|
82 | */ | |||
|
83 | struct SyncGroup { | |||
|
84 | std::set<VariableId> m_Variables{}; | |||
|
85 | SqpRange m_Range{INVALID_RANGE}; | |||
|
86 | }; | |||
|
87 | ||||
|
88 | using SyncGroupId = QUuid; | |||
|
89 | using SyncGroupsPool = std::map<SyncGroupId, SyncGroup>; | |||
|
90 | ||||
|
91 | /** | |||
|
92 | * 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. | |||
|
94 | */ | |||
|
95 | struct FuzzingState { | |||
|
96 | const SyncGroup &syncGroup(SyncGroupId id) const; | |||
|
97 | SyncGroup &syncGroup(SyncGroupId id); | |||
|
98 | ||||
|
99 | const VariableState &variableState(VariableId id) const; | |||
|
100 | VariableState &variableState(VariableId id); | |||
|
101 | ||||
|
102 | /// @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 | |||
|
104 | SyncGroupId syncGroupId(VariableId variableId) const; | |||
|
105 | ||||
|
106 | /// @return the set of synchronization group identifiers | |||
|
107 | std::vector<SyncGroupId> syncGroupsIds() const; | |||
|
108 | ||||
|
109 | /// Updates fuzzing state according to a variable synchronization | |||
|
110 | /// @param variableId the variable that is synchronized | |||
|
111 | /// @param syncGroupId the synchronization group | |||
|
112 | void synchronizeVariable(VariableId variableId, SyncGroupId syncGroupId); | |||
|
113 | ||||
|
114 | /// Updates fuzzing state according to a variable desynchronization | |||
|
115 | /// @param variableId the variable that is desynchronized | |||
|
116 | /// @param syncGroupId the synchronization group from which to remove the variable | |||
|
117 | void desynchronizeVariable(VariableId variableId, SyncGroupId syncGroupId); | |||
|
118 | ||||
|
119 | /// Updates the range of a variable and all variables to which it is synchronized | |||
|
120 | /// @param the variable for which to affect the range | |||
|
121 | /// @param the range to affect | |||
|
122 | void updateRanges(VariableId variableId, const SqpRange &newRange); | |||
|
123 | ||||
|
124 | VariablesPool m_VariablesPool; | |||
|
125 | SyncGroupsPool m_SyncGroupsPool; | |||
|
126 | }; | |||
|
127 | ||||
|
128 | #endif // SCIQLOP_FUZZINGDEFS_H |
@@ -0,0 +1,265 | |||||
|
1 | #include "FuzzingOperations.h" | |||
|
2 | #include "FuzzingUtils.h" | |||
|
3 | ||||
|
4 | #include <Data/IDataProvider.h> | |||
|
5 | ||||
|
6 | #include <Variable/Variable.h> | |||
|
7 | #include <Variable/VariableController.h> | |||
|
8 | ||||
|
9 | #include <QUuid> | |||
|
10 | ||||
|
11 | #include <functional> | |||
|
12 | ||||
|
13 | Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations") | |||
|
14 | ||||
|
15 | namespace { | |||
|
16 | ||||
|
17 | struct CreateOperation : public IFuzzingOperation { | |||
|
18 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override | |||
|
19 | { | |||
|
20 | // A variable can be created only if it doesn't exist yet | |||
|
21 | return fuzzingState.variableState(variableId).m_Variable == nullptr; | |||
|
22 | } | |||
|
23 | ||||
|
24 | void execute(VariableId variableId, FuzzingState &fuzzingState, | |||
|
25 | VariableController &variableController, | |||
|
26 | const Properties &properties) const override | |||
|
27 | { | |||
|
28 | // Retrieves metadata pool from properties, and choose one of the metadata entries to | |||
|
29 | // associate it with the variable | |||
|
30 | auto metaDataPool = properties.value(METADATA_POOL_PROPERTY).value<MetadataPool>(); | |||
|
31 | auto variableMetadata = RandomGenerator::instance().randomChoice(metaDataPool); | |||
|
32 | ||||
|
33 | // Retrieves provider | |||
|
34 | auto variableProvider | |||
|
35 | = properties.value(PROVIDER_PROPERTY).value<std::shared_ptr<IDataProvider> >(); | |||
|
36 | ||||
|
37 | auto variableName = QString{"Var_%1"}.arg(QUuid::createUuid().toString()); | |||
|
38 | qCInfo(LOG_FuzzingOperations()).noquote() | |||
|
39 | << "Creating variable" << variableName << "(metadata:" << variableMetadata << ")..."; | |||
|
40 | ||||
|
41 | auto newVariable | |||
|
42 | = variableController.createVariable(variableName, variableMetadata, variableProvider); | |||
|
43 | ||||
|
44 | // Updates variable's state | |||
|
45 | auto &variableState = fuzzingState.variableState(variableId); | |||
|
46 | variableState.m_Range = properties.value(INITIAL_RANGE_PROPERTY).value<SqpRange>(); | |||
|
47 | std::swap(variableState.m_Variable, newVariable); | |||
|
48 | } | |||
|
49 | }; | |||
|
50 | ||||
|
51 | struct DeleteOperation : public IFuzzingOperation { | |||
|
52 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override | |||
|
53 | { | |||
|
54 | // A variable can be delete only if it exists | |||
|
55 | return fuzzingState.variableState(variableId).m_Variable != nullptr; | |||
|
56 | } | |||
|
57 | ||||
|
58 | void execute(VariableId variableId, FuzzingState &fuzzingState, | |||
|
59 | VariableController &variableController, const Properties &) const override | |||
|
60 | { | |||
|
61 | auto &variableState = fuzzingState.variableState(variableId); | |||
|
62 | ||||
|
63 | qCInfo(LOG_FuzzingOperations()).noquote() | |||
|
64 | << "Deleting variable" << variableState.m_Variable->name() << "..."; | |||
|
65 | variableController.deleteVariable(variableState.m_Variable); | |||
|
66 | ||||
|
67 | // Updates variable's state | |||
|
68 | variableState.m_Range = INVALID_RANGE; | |||
|
69 | variableState.m_Variable = nullptr; | |||
|
70 | ||||
|
71 | // Desynchronizes the variable if it was in a sync group | |||
|
72 | auto syncGroupId = fuzzingState.syncGroupId(variableId); | |||
|
73 | fuzzingState.desynchronizeVariable(variableId, syncGroupId); | |||
|
74 | } | |||
|
75 | }; | |||
|
76 | ||||
|
77 | /** | |||
|
78 | * Defines a move operation through a range. | |||
|
79 | * | |||
|
80 | * A move operation is determined by three functions: | |||
|
81 | * - Two 'move' functions, used to indicate in which direction the beginning and the end of a range | |||
|
82 | * are going during the operation. These functions will be: | |||
|
83 | * -- {<- / <-} for pan left | |||
|
84 | * -- {-> / ->} for pan right | |||
|
85 | * -- {-> / <-} for zoom in | |||
|
86 | * -- {<- / ->} for zoom out | |||
|
87 | * - One 'max move' functions, used to compute the max delta at which the operation can move a | |||
|
88 | * range, according to a max range. For exemple, for a range of {1, 5} and a max range of {0, 10}, | |||
|
89 | * max deltas will be: | |||
|
90 | * -- {0, 4} for pan left | |||
|
91 | * -- {6, 10} for pan right | |||
|
92 | * -- {3, 3} for zoom in | |||
|
93 | * -- {0, 6} for zoom out (same spacing left and right) | |||
|
94 | */ | |||
|
95 | struct MoveOperation : public IFuzzingOperation { | |||
|
96 | using MoveFunction = std::function<double(double currentValue, double maxValue)>; | |||
|
97 | using MaxMoveFunction = std::function<double(const SqpRange &range, const SqpRange &maxRange)>; | |||
|
98 | ||||
|
99 | explicit MoveOperation(MoveFunction rangeStartMoveFun, MoveFunction rangeEndMoveFun, | |||
|
100 | MaxMoveFunction maxMoveFun, | |||
|
101 | const QString &label = QStringLiteral("Move operation")) | |||
|
102 | : m_RangeStartMoveFun{std::move(rangeStartMoveFun)}, | |||
|
103 | m_RangeEndMoveFun{std::move(rangeEndMoveFun)}, | |||
|
104 | m_MaxMoveFun{std::move(maxMoveFun)}, | |||
|
105 | m_Label{label} | |||
|
106 | { | |||
|
107 | } | |||
|
108 | ||||
|
109 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override | |||
|
110 | { | |||
|
111 | return fuzzingState.variableState(variableId).m_Variable != nullptr; | |||
|
112 | } | |||
|
113 | ||||
|
114 | void execute(VariableId variableId, FuzzingState &fuzzingState, | |||
|
115 | VariableController &variableController, | |||
|
116 | const Properties &properties) const override | |||
|
117 | { | |||
|
118 | auto &variableState = fuzzingState.variableState(variableId); | |||
|
119 | auto variable = variableState.m_Variable; | |||
|
120 | ||||
|
121 | // Gets the max range defined | |||
|
122 | auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE)) | |||
|
123 | .value<SqpRange>(); | |||
|
124 | auto variableRange = variableState.m_Range; | |||
|
125 | ||||
|
126 | if (maxRange == INVALID_RANGE || variableRange.m_TStart < maxRange.m_TStart | |||
|
127 | || variableRange.m_TEnd > maxRange.m_TEnd) { | |||
|
128 | qCWarning(LOG_FuzzingOperations()) << "Can't execute operation: invalid max range"; | |||
|
129 | return; | |||
|
130 | } | |||
|
131 | ||||
|
132 | // Computes the max delta at which the variable can move, up to the limits of the max range | |||
|
133 | auto deltaMax = m_MaxMoveFun(variableRange, maxRange); | |||
|
134 | ||||
|
135 | // Generates random delta that will be used to move variable | |||
|
136 | auto delta = RandomGenerator::instance().generateDouble(0, deltaMax); | |||
|
137 | ||||
|
138 | // Moves variable to its new range | |||
|
139 | auto isSynchronized = !fuzzingState.syncGroupId(variableId).isNull(); | |||
|
140 | auto newVariableRange = SqpRange{m_RangeStartMoveFun(variableRange.m_TStart, delta), | |||
|
141 | m_RangeEndMoveFun(variableRange.m_TEnd, delta)}; | |||
|
142 | qCInfo(LOG_FuzzingOperations()).noquote() | |||
|
143 | << "Performing" << m_Label << "on" << variable->name() << "(from" << variableRange | |||
|
144 | << "to" << newVariableRange << ")..."; | |||
|
145 | variableController.onRequestDataLoading({variable}, newVariableRange, isSynchronized); | |||
|
146 | ||||
|
147 | // Updates state | |||
|
148 | fuzzingState.updateRanges(variableId, newVariableRange); | |||
|
149 | } | |||
|
150 | ||||
|
151 | MoveFunction m_RangeStartMoveFun; | |||
|
152 | MoveFunction m_RangeEndMoveFun; | |||
|
153 | MaxMoveFunction m_MaxMoveFun; | |||
|
154 | QString m_Label; | |||
|
155 | }; | |||
|
156 | ||||
|
157 | struct SynchronizeOperation : public IFuzzingOperation { | |||
|
158 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override | |||
|
159 | { | |||
|
160 | auto variable = fuzzingState.variableState(variableId).m_Variable; | |||
|
161 | return variable != nullptr && !fuzzingState.m_SyncGroupsPool.empty() | |||
|
162 | && fuzzingState.syncGroupId(variableId).isNull(); | |||
|
163 | } | |||
|
164 | ||||
|
165 | void execute(VariableId variableId, FuzzingState &fuzzingState, | |||
|
166 | VariableController &variableController, const Properties &) const override | |||
|
167 | { | |||
|
168 | auto &variableState = fuzzingState.variableState(variableId); | |||
|
169 | ||||
|
170 | // Chooses a random synchronization group and adds the variable into sync group | |||
|
171 | auto syncGroupId = RandomGenerator::instance().randomChoice(fuzzingState.syncGroupsIds()); | |||
|
172 | qCInfo(LOG_FuzzingOperations()).noquote() | |||
|
173 | << "Adding" << variableState.m_Variable->name() << "into synchronization group" | |||
|
174 | << syncGroupId << "..."; | |||
|
175 | variableController.onAddSynchronized(variableState.m_Variable, syncGroupId); | |||
|
176 | ||||
|
177 | // Updates state | |||
|
178 | fuzzingState.synchronizeVariable(variableId, syncGroupId); | |||
|
179 | } | |||
|
180 | }; | |||
|
181 | ||||
|
182 | struct DesynchronizeOperation : public IFuzzingOperation { | |||
|
183 | bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override | |||
|
184 | { | |||
|
185 | auto variable = fuzzingState.variableState(variableId).m_Variable; | |||
|
186 | return variable != nullptr && !fuzzingState.syncGroupId(variableId).isNull(); | |||
|
187 | } | |||
|
188 | ||||
|
189 | void execute(VariableId variableId, FuzzingState &fuzzingState, | |||
|
190 | VariableController &variableController, const Properties &) const override | |||
|
191 | { | |||
|
192 | auto &variableState = fuzzingState.variableState(variableId); | |||
|
193 | ||||
|
194 | // Gets the sync group of the variable | |||
|
195 | auto syncGroupId = fuzzingState.syncGroupId(variableId); | |||
|
196 | ||||
|
197 | qCInfo(LOG_FuzzingOperations()).noquote() | |||
|
198 | << "Removing" << variableState.m_Variable->name() << "from synchronization group" | |||
|
199 | << syncGroupId << "..."; | |||
|
200 | variableController.onAddSynchronized(variableState.m_Variable, syncGroupId); | |||
|
201 | ||||
|
202 | // Updates state | |||
|
203 | fuzzingState.desynchronizeVariable(variableId, syncGroupId); | |||
|
204 | } | |||
|
205 | }; | |||
|
206 | ||||
|
207 | struct UnknownOperation : public IFuzzingOperation { | |||
|
208 | bool canExecute(VariableId, const FuzzingState &) const override { return false; } | |||
|
209 | ||||
|
210 | void execute(VariableId, FuzzingState &, VariableController &, | |||
|
211 | const Properties &) const override | |||
|
212 | { | |||
|
213 | } | |||
|
214 | }; | |||
|
215 | ||||
|
216 | } // namespace | |||
|
217 | ||||
|
218 | std::unique_ptr<IFuzzingOperation> FuzzingOperationFactory::create(FuzzingOperationType type) | |||
|
219 | { | |||
|
220 | switch (type) { | |||
|
221 | case FuzzingOperationType::CREATE: | |||
|
222 | return std::make_unique<CreateOperation>(); | |||
|
223 | case FuzzingOperationType::DELETE: | |||
|
224 | return std::make_unique<DeleteOperation>(); | |||
|
225 | case FuzzingOperationType::PAN_LEFT: | |||
|
226 | return std::make_unique<MoveOperation>( | |||
|
227 | std::minus<double>(), std::minus<double>(), | |||
|
228 | [](const SqpRange &range, const SqpRange &maxRange) { | |||
|
229 | return range.m_TStart - maxRange.m_TStart; | |||
|
230 | }, | |||
|
231 | QStringLiteral("Pan left operation")); | |||
|
232 | case FuzzingOperationType::PAN_RIGHT: | |||
|
233 | return std::make_unique<MoveOperation>( | |||
|
234 | std::plus<double>(), std::plus<double>(), | |||
|
235 | [](const SqpRange &range, const SqpRange &maxRange) { | |||
|
236 | return maxRange.m_TEnd - range.m_TEnd; | |||
|
237 | }, | |||
|
238 | QStringLiteral("Pan right operation")); | |||
|
239 | case FuzzingOperationType::ZOOM_IN: | |||
|
240 | return std::make_unique<MoveOperation>( | |||
|
241 | std::plus<double>(), std::minus<double>(), | |||
|
242 | [](const SqpRange &range, const SqpRange &maxRange) { | |||
|
243 | Q_UNUSED(maxRange) | |||
|
244 | return range.m_TEnd - (range.m_TStart + range.m_TEnd) / 2.; | |||
|
245 | }, | |||
|
246 | QStringLiteral("Zoom in operation")); | |||
|
247 | case FuzzingOperationType::ZOOM_OUT: | |||
|
248 | return std::make_unique<MoveOperation>( | |||
|
249 | std::minus<double>(), std::plus<double>(), | |||
|
250 | [](const SqpRange &range, const SqpRange &maxRange) { | |||
|
251 | return std::min(range.m_TStart - maxRange.m_TStart, | |||
|
252 | maxRange.m_TEnd - range.m_TEnd); | |||
|
253 | }, | |||
|
254 | QStringLiteral("Zoom out operation")); | |||
|
255 | case FuzzingOperationType::SYNCHRONIZE: | |||
|
256 | return std::make_unique<SynchronizeOperation>(); | |||
|
257 | case FuzzingOperationType::DESYNCHRONIZE: | |||
|
258 | return std::make_unique<DesynchronizeOperation>(); | |||
|
259 | default: | |||
|
260 | // Default case returns unknown operation | |||
|
261 | break; | |||
|
262 | } | |||
|
263 | ||||
|
264 | return std::make_unique<UnknownOperation>(); | |||
|
265 | } |
@@ -0,0 +1,56 | |||||
|
1 | #ifndef SCIQLOP_FUZZINGOPERATIONS_H | |||
|
2 | #define SCIQLOP_FUZZINGOPERATIONS_H | |||
|
3 | ||||
|
4 | #include "FuzzingDefs.h" | |||
|
5 | ||||
|
6 | #include <memory> | |||
|
7 | #include <set> | |||
|
8 | ||||
|
9 | #include <QLoggingCategory> | |||
|
10 | #include <QMetaType> | |||
|
11 | ||||
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_FuzzingOperations) | |||
|
13 | ||||
|
14 | class VariableController; | |||
|
15 | ||||
|
16 | /** | |||
|
17 | * Enumeration of types of existing fuzzing operations | |||
|
18 | */ | |||
|
19 | enum class FuzzingOperationType { | |||
|
20 | CREATE, | |||
|
21 | DELETE, | |||
|
22 | PAN_LEFT, | |||
|
23 | PAN_RIGHT, | |||
|
24 | ZOOM_IN, | |||
|
25 | ZOOM_OUT, | |||
|
26 | SYNCHRONIZE, | |||
|
27 | DESYNCHRONIZE | |||
|
28 | }; | |||
|
29 | ||||
|
30 | /// Interface that represents an operation that can be executed during a fuzzing test | |||
|
31 | struct IFuzzingOperation { | |||
|
32 | virtual ~IFuzzingOperation() noexcept = default; | |||
|
33 | ||||
|
34 | /// Checks if the operation can be executed according to the current test's state for the | |||
|
35 | /// variable passed in parameter | |||
|
36 | virtual bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const = 0; | |||
|
37 | /// Executes the operation on the variable for which its identifier is passed in parameter | |||
|
38 | /// @param variableId the variable identifier | |||
|
39 | /// @param fuzzingState the current test's state on which to find the variable and execute the | |||
|
40 | /// operation | |||
|
41 | /// @param variableController the controller associated to the operation | |||
|
42 | /// @param properties properties that can be used to configure the operation | |||
|
43 | /// @remarks fuzzingState is passed as a reference because, according to the operation, it can | |||
|
44 | /// be modified (in/out parameter) | |||
|
45 | virtual void execute(VariableId variableId, FuzzingState &fuzzingState, | |||
|
46 | VariableController &variableController, | |||
|
47 | const Properties &properties = {}) const = 0; | |||
|
48 | }; | |||
|
49 | ||||
|
50 | /// Factory of @sa IFuzzingOperation | |||
|
51 | struct FuzzingOperationFactory { | |||
|
52 | /// Creates a fuzzing operation from a type | |||
|
53 | static std::unique_ptr<IFuzzingOperation> create(FuzzingOperationType type); | |||
|
54 | }; | |||
|
55 | ||||
|
56 | #endif // SCIQLOP_FUZZINGOPERATIONS_H |
@@ -0,0 +1,25 | |||||
|
1 | #include "FuzzingUtils.h" | |||
|
2 | ||||
|
3 | RandomGenerator &RandomGenerator::instance() | |||
|
4 | { | |||
|
5 | static auto instance = RandomGenerator(); | |||
|
6 | return instance; | |||
|
7 | } | |||
|
8 | ||||
|
9 | double RandomGenerator::generateDouble(double min, double max) | |||
|
10 | { | |||
|
11 | std::uniform_real_distribution<double> dist{min, max}; | |||
|
12 | return dist(m_Mt); | |||
|
13 | } | |||
|
14 | ||||
|
15 | int RandomGenerator::generateInt(int min, int max) | |||
|
16 | { | |||
|
17 | std::uniform_int_distribution<int> dist{min, max}; | |||
|
18 | return dist(m_Mt); | |||
|
19 | } | |||
|
20 | ||||
|
21 | RandomGenerator::RandomGenerator() | |||
|
22 | { | |||
|
23 | std::random_device rd{}; | |||
|
24 | m_Mt = std::mt19937{rd()}; | |||
|
25 | } |
@@ -0,0 +1,63 | |||||
|
1 | #ifndef SCIQLOP_FUZZINGUTILS_H | |||
|
2 | #define SCIQLOP_FUZZINGUTILS_H | |||
|
3 | ||||
|
4 | #include <algorithm> | |||
|
5 | #include <random> | |||
|
6 | ||||
|
7 | /** | |||
|
8 | * Class that proposes random utility methods | |||
|
9 | */ | |||
|
10 | class RandomGenerator { | |||
|
11 | public: | |||
|
12 | /// @return the unique instance of the random generator | |||
|
13 | static RandomGenerator &instance(); | |||
|
14 | ||||
|
15 | /// Generates a random double between [min, max] | |||
|
16 | double generateDouble(double min, double max); | |||
|
17 | /// Generates a random int between [min, max] | |||
|
18 | int generateInt(int min, int max); | |||
|
19 | ||||
|
20 | /** | |||
|
21 | * Returns a random element among the elements of a container. An item may be more likely to be | |||
|
22 | * selected if it has an associated weight greater than other items | |||
|
23 | * @param container the container from which to retrieve an element | |||
|
24 | * @param weights the weight associated to each element of the container. The vector must have | |||
|
25 | * the same size of the container for the weights to be effective | |||
|
26 | * @param nbDraws the number of random draws to perform | |||
|
27 | * @return the random element retrieved, an element built by default if the container is empty | |||
|
28 | */ | |||
|
29 | template <typename T, typename ValueType = typename T::value_type> | |||
|
30 | ValueType randomChoice(const T &container, const std::vector<double> &weights = {}); | |||
|
31 | ||||
|
32 | private: | |||
|
33 | std::mt19937 m_Mt; | |||
|
34 | ||||
|
35 | explicit RandomGenerator(); | |||
|
36 | }; | |||
|
37 | ||||
|
38 | template <typename T, typename ValueType> | |||
|
39 | ValueType RandomGenerator::randomChoice(const T &container, const std::vector<double> &weights) | |||
|
40 | { | |||
|
41 | if (container.empty()) { | |||
|
42 | return ValueType{}; | |||
|
43 | } | |||
|
44 | ||||
|
45 | // Generates weights for each element: if the weights passed in parameter are malformed (the | |||
|
46 | // number of weights defined is inconsistent with the number of elements in the container, or | |||
|
47 | // all weights are zero), default weights are used | |||
|
48 | auto nbIndexes = container.size(); | |||
|
49 | std::vector<double> indexWeights(nbIndexes); | |||
|
50 | if (weights.size() != nbIndexes || std::all_of(weights.cbegin(), weights.cend(), | |||
|
51 | [](const auto &val) { return val == 0.; })) { | |||
|
52 | std::fill(indexWeights.begin(), indexWeights.end(), 1.); | |||
|
53 | } | |||
|
54 | else { | |||
|
55 | std::copy(weights.begin(), weights.end(), indexWeights.begin()); | |||
|
56 | } | |||
|
57 | ||||
|
58 | // Performs a draw to determine the index to return | |||
|
59 | std::discrete_distribution<> d{indexWeights.cbegin(), indexWeights.cend()}; | |||
|
60 | return container.at(d(m_Mt)); | |||
|
61 | } | |||
|
62 | ||||
|
63 | #endif // SCIQLOP_FUZZINGUTILS |
@@ -0,0 +1,228 | |||||
|
1 | #include "FuzzingValidators.h" | |||
|
2 | #include "FuzzingDefs.h" | |||
|
3 | ||||
|
4 | #include <Data/DataSeries.h> | |||
|
5 | #include <Variable/Variable.h> | |||
|
6 | ||||
|
7 | #include <QTest> | |||
|
8 | ||||
|
9 | #include <functional> | |||
|
10 | ||||
|
11 | Q_LOGGING_CATEGORY(LOG_FuzzingValidators, "FuzzingValidators") | |||
|
12 | ||||
|
13 | namespace { | |||
|
14 | ||||
|
15 | // ////////////// // | |||
|
16 | // DATA VALIDATOR // | |||
|
17 | // ////////////// // | |||
|
18 | ||||
|
19 | /// Singleton used to validate data of a variable | |||
|
20 | class DataValidatorHelper { | |||
|
21 | public: | |||
|
22 | /// @return the single instance of the helper | |||
|
23 | static DataValidatorHelper &instance(); | |||
|
24 | virtual ~DataValidatorHelper() noexcept = default; | |||
|
25 | ||||
|
26 | virtual void validate(const VariableState &variableState) const = 0; | |||
|
27 | }; | |||
|
28 | ||||
|
29 | /** | |||
|
30 | * Default implementation of @sa DataValidatorHelper | |||
|
31 | */ | |||
|
32 | class DefaultDataValidatorHelper : public DataValidatorHelper { | |||
|
33 | public: | |||
|
34 | void validate(const VariableState &variableState) const override | |||
|
35 | { | |||
|
36 | Q_UNUSED(variableState); | |||
|
37 | qCWarning(LOG_FuzzingValidators()).noquote() << "Checking variable's data... WARN: no data " | |||
|
38 | "verification is available for this server"; | |||
|
39 | } | |||
|
40 | }; | |||
|
41 | ||||
|
42 | /// Data resolution in local server's files | |||
|
43 | const auto LOCALHOST_SERVER_RESOLUTION = 4; | |||
|
44 | /// Reference value used to generate the data on the local server (a value is the number of seconds | |||
|
45 | /// between the data date and this reference date) | |||
|
46 | const auto LOCALHOST_REFERENCE_VALUE | |||
|
47 | = DateUtils::secondsSinceEpoch(QDateTime{QDate{2000, 1, 1}, QTime{}, Qt::UTC}); | |||
|
48 | ||||
|
49 | /** | |||
|
50 | * Implementation of @sa DataValidatorHelper for the local AMDA server | |||
|
51 | */ | |||
|
52 | class LocalhostServerDataValidatorHelper : public DataValidatorHelper { | |||
|
53 | public: | |||
|
54 | void validate(const VariableState &variableState) const override | |||
|
55 | { | |||
|
56 | // Don't check data for null variable | |||
|
57 | if (!variableState.m_Variable || variableState.m_Range == INVALID_RANGE) { | |||
|
58 | return; | |||
|
59 | } | |||
|
60 | ||||
|
61 | auto message = "Checking variable's data..."; | |||
|
62 | auto toDateString = [](double value) { return DateUtils::dateTime(value).toString(); }; | |||
|
63 | ||||
|
64 | // Checks that data are defined | |||
|
65 | auto variableDataSeries = variableState.m_Variable->dataSeries(); | |||
|
66 | if (variableDataSeries == nullptr && variableState.m_Range != INVALID_RANGE) { | |||
|
67 | qCInfo(LOG_FuzzingValidators()).noquote() | |||
|
68 | << message << "FAIL: the variable has no data while a range is defined"; | |||
|
69 | QFAIL(""); | |||
|
70 | } | |||
|
71 | ||||
|
72 | auto dataIts = variableDataSeries->xAxisRange(variableState.m_Range.m_TStart, | |||
|
73 | variableState.m_Range.m_TEnd); | |||
|
74 | ||||
|
75 | // Checks that the data are well defined in the range: | |||
|
76 | // - there is at least one data | |||
|
77 | // - the data are consistent (no data holes) | |||
|
78 | if (std::distance(dataIts.first, dataIts.second) == 0) { | |||
|
79 | qCInfo(LOG_FuzzingValidators()).noquote() | |||
|
80 | << message << "FAIL: the variable has no data"; | |||
|
81 | QFAIL(""); | |||
|
82 | } | |||
|
83 | ||||
|
84 | auto firstXAxisData = dataIts.first->x(); | |||
|
85 | auto lastXAxisData = (dataIts.second - 1)->x(); | |||
|
86 | ||||
|
87 | if (std::abs(firstXAxisData - variableState.m_Range.m_TStart) > LOCALHOST_SERVER_RESOLUTION | |||
|
88 | || std::abs(lastXAxisData - variableState.m_Range.m_TEnd) | |||
|
89 | > LOCALHOST_SERVER_RESOLUTION) { | |||
|
90 | qCInfo(LOG_FuzzingValidators()).noquote() | |||
|
91 | << message << "FAIL: the data in the defined range are inconsistent (data hole " | |||
|
92 | "found at the beginning or the end)"; | |||
|
93 | QFAIL(""); | |||
|
94 | } | |||
|
95 | ||||
|
96 | auto dataHoleIt = std::adjacent_find( | |||
|
97 | dataIts.first, dataIts.second, [](const auto &it1, const auto &it2) { | |||
|
98 | /// @todo: validate resolution | |||
|
99 | return std::abs(it1.x() - it2.x()) > 2 * (LOCALHOST_SERVER_RESOLUTION - 1); | |||
|
100 | }); | |||
|
101 | ||||
|
102 | if (dataHoleIt != dataIts.second) { | |||
|
103 | qCInfo(LOG_FuzzingValidators()).noquote() | |||
|
104 | << message << "FAIL: the data in the defined range are inconsistent (data hole " | |||
|
105 | "found between times " | |||
|
106 | << toDateString(dataHoleIt->x()) << "and " << toDateString((dataHoleIt + 1)->x()) | |||
|
107 | << ")"; | |||
|
108 | QFAIL(""); | |||
|
109 | } | |||
|
110 | ||||
|
111 | // Checks values | |||
|
112 | auto dataIndex = 0; | |||
|
113 | for (auto dataIt = dataIts.first; dataIt != dataIts.second; ++dataIt, ++dataIndex) { | |||
|
114 | auto xAxisData = dataIt->x(); | |||
|
115 | auto valuesData = dataIt->values(); | |||
|
116 | for (auto valueIndex = 0, valueEnd = valuesData.size(); valueIndex < valueEnd; | |||
|
117 | ++valueIndex) { | |||
|
118 | auto value = valuesData.at(valueIndex); | |||
|
119 | auto expectedValue = xAxisData + valueIndex * LOCALHOST_SERVER_RESOLUTION | |||
|
120 | - LOCALHOST_REFERENCE_VALUE; | |||
|
121 | ||||
|
122 | if (value != expectedValue) { | |||
|
123 | qCInfo(LOG_FuzzingValidators()).noquote() | |||
|
124 | << message << "FAIL: incorrect value data at time" | |||
|
125 | << toDateString(xAxisData) << ", index" << valueIndex << "(found:" << value | |||
|
126 | << ", expected:" << expectedValue << ")"; | |||
|
127 | QFAIL(""); | |||
|
128 | } | |||
|
129 | } | |||
|
130 | } | |||
|
131 | ||||
|
132 | // At this step validation is OK | |||
|
133 | qCInfo(LOG_FuzzingValidators()).noquote() << message << "OK"; | |||
|
134 | } | |||
|
135 | }; | |||
|
136 | ||||
|
137 | /// Creates the @sa DataValidatorHelper according to the server passed in parameter | |||
|
138 | std::unique_ptr<DataValidatorHelper> createDataValidatorInstance(const QString &server) | |||
|
139 | { | |||
|
140 | if (server == QString{"localhost"}) { | |||
|
141 | return std::make_unique<LocalhostServerDataValidatorHelper>(); | |||
|
142 | } | |||
|
143 | else { | |||
|
144 | return std::make_unique<DefaultDataValidatorHelper>(); | |||
|
145 | } | |||
|
146 | } | |||
|
147 | ||||
|
148 | DataValidatorHelper &DataValidatorHelper::instance() | |||
|
149 | { | |||
|
150 | // Creates instance depending on the SCIQLOP_AMDA_SERVER value at compile time | |||
|
151 | static auto instance = createDataValidatorInstance(SCIQLOP_AMDA_SERVER); | |||
|
152 | return *instance; | |||
|
153 | } | |||
|
154 | ||||
|
155 | // /////////////// // | |||
|
156 | // RANGE VALIDATOR // | |||
|
157 | // /////////////// // | |||
|
158 | ||||
|
159 | /** | |||
|
160 | * Checks that a range of a variable matches the expected range passed as a parameter | |||
|
161 | * @param variable the variable for which to check the range | |||
|
162 | * @param expectedRange the expected range | |||
|
163 | * @param getVariableRangeFun the function to retrieve the range from the variable | |||
|
164 | * @remarks if the variable is null, checks that the expected range is the invalid range | |||
|
165 | */ | |||
|
166 | void validateRange(std::shared_ptr<Variable> variable, const SqpRange &expectedRange, | |||
|
167 | std::function<SqpRange(const Variable &)> getVariableRangeFun) | |||
|
168 | { | |||
|
169 | auto compare = [](const auto &range, const auto &expectedRange, const auto &message) { | |||
|
170 | if (range == expectedRange) { | |||
|
171 | qCInfo(LOG_FuzzingValidators()).noquote() << message << "OK"; | |||
|
172 | } | |||
|
173 | else { | |||
|
174 | qCInfo(LOG_FuzzingValidators()).noquote() | |||
|
175 | << message << "FAIL (current range:" << range | |||
|
176 | << ", expected range:" << expectedRange << ")"; | |||
|
177 | QFAIL(""); | |||
|
178 | } | |||
|
179 | }; | |||
|
180 | ||||
|
181 | if (variable) { | |||
|
182 | compare(getVariableRangeFun(*variable), expectedRange, "Checking variable's range..."); | |||
|
183 | } | |||
|
184 | else { | |||
|
185 | compare(INVALID_RANGE, expectedRange, "Checking that there is no range set..."); | |||
|
186 | } | |||
|
187 | } | |||
|
188 | ||||
|
189 | /** | |||
|
190 | * Default implementation of @sa IFuzzingValidator. This validator takes as parameter of its | |||
|
191 | * construction a function of validation which is called in the validate() method | |||
|
192 | */ | |||
|
193 | class FuzzingValidator : public IFuzzingValidator { | |||
|
194 | public: | |||
|
195 | /// Signature of a validation function | |||
|
196 | using ValidationFunction = std::function<void(const VariableState &variableState)>; | |||
|
197 | ||||
|
198 | explicit FuzzingValidator(ValidationFunction fun) : m_Fun(std::move(fun)) {} | |||
|
199 | ||||
|
200 | void validate(const VariableState &variableState) const override { m_Fun(variableState); } | |||
|
201 | ||||
|
202 | private: | |||
|
203 | ValidationFunction m_Fun; | |||
|
204 | }; | |||
|
205 | ||||
|
206 | } // namespace | |||
|
207 | ||||
|
208 | std::unique_ptr<IFuzzingValidator> FuzzingValidatorFactory::create(FuzzingValidatorType type) | |||
|
209 | { | |||
|
210 | switch (type) { | |||
|
211 | case FuzzingValidatorType::DATA: | |||
|
212 | return std::make_unique<FuzzingValidator>([](const VariableState &variableState) { | |||
|
213 | DataValidatorHelper::instance().validate(variableState); | |||
|
214 | }); | |||
|
215 | case FuzzingValidatorType::RANGE: | |||
|
216 | return std::make_unique<FuzzingValidator>([](const VariableState &variableState) { | |||
|
217 | auto getVariableRange = [](const Variable &variable) { return variable.range(); }; | |||
|
218 | validateRange(variableState.m_Variable, variableState.m_Range, getVariableRange); | |||
|
219 | }); | |||
|
220 | default: | |||
|
221 | // Default case returns invalid validator | |||
|
222 | break; | |||
|
223 | } | |||
|
224 | ||||
|
225 | // Invalid validator | |||
|
226 | return std::make_unique<FuzzingValidator>( | |||
|
227 | [](const VariableState &) { QFAIL("Invalid validator"); }); | |||
|
228 | } |
@@ -0,0 +1,40 | |||||
|
1 | #ifndef SCIQLOP_FUZZINGVALIDATORS_H | |||
|
2 | #define SCIQLOP_FUZZINGVALIDATORS_H | |||
|
3 | ||||
|
4 | #include <memory> | |||
|
5 | #include <set> | |||
|
6 | ||||
|
7 | #include <QLoggingCategory> | |||
|
8 | #include <QMetaType> | |||
|
9 | ||||
|
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_FuzzingValidators) | |||
|
11 | ||||
|
12 | class VariableState; | |||
|
13 | ||||
|
14 | /// Types of validators that can be defined | |||
|
15 | enum class FuzzingValidatorType { | |||
|
16 | DATA, ///< Validates variable's data | |||
|
17 | RANGE ///< Validates variable's range | |||
|
18 | }; | |||
|
19 | ||||
|
20 | /** | |||
|
21 | * Struct that represents a validator. A validator checks if the state of a variable is valid at the | |||
|
22 | * moment it is called during a fuzzing test | |||
|
23 | */ | |||
|
24 | struct IFuzzingValidator { | |||
|
25 | virtual ~IFuzzingValidator() noexcept = default; | |||
|
26 | ||||
|
27 | /// Validates the variable's state passed in parameter | |||
|
28 | virtual void validate(const VariableState &variableState) const = 0; | |||
|
29 | }; | |||
|
30 | ||||
|
31 | /// Factory of @sa IFuzzingValidator | |||
|
32 | struct FuzzingValidatorFactory { | |||
|
33 | /// Creates a validator according to the type passed in parameter | |||
|
34 | static std::unique_ptr<IFuzzingValidator> create(FuzzingValidatorType type); | |||
|
35 | }; | |||
|
36 | ||||
|
37 | using ValidatorsTypes = std::vector<FuzzingValidatorType>; | |||
|
38 | Q_DECLARE_METATYPE(ValidatorsTypes) | |||
|
39 | ||||
|
40 | #endif // SCIQLOP_FUZZINGVALIDATORS_H |
@@ -0,0 +1,391 | |||||
|
1 | #include "FuzzingDefs.h" | |||
|
2 | #include "FuzzingOperations.h" | |||
|
3 | #include "FuzzingUtils.h" | |||
|
4 | #include "FuzzingValidators.h" | |||
|
5 | ||||
|
6 | #include "AmdaProvider.h" | |||
|
7 | ||||
|
8 | #include <Common/SignalWaiter.h> | |||
|
9 | #include <Network/NetworkController.h> | |||
|
10 | #include <Settings/SqpSettingsDefs.h> | |||
|
11 | #include <SqpApplication.h> | |||
|
12 | #include <Time/TimeController.h> | |||
|
13 | #include <Variable/Variable.h> | |||
|
14 | #include <Variable/VariableController.h> | |||
|
15 | ||||
|
16 | #include <QLoggingCategory> | |||
|
17 | #include <QObject> | |||
|
18 | #include <QtTest> | |||
|
19 | ||||
|
20 | #include <memory> | |||
|
21 | ||||
|
22 | Q_LOGGING_CATEGORY(LOG_TestAmdaFuzzing, "TestAmdaFuzzing") | |||
|
23 | ||||
|
24 | /** | |||
|
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 | |||
|
27 | * it's not present. Macro arguments are: | |||
|
28 | * - GETTER_NAME : name of the getter | |||
|
29 | * - PROPERTY_NAME: used to generate constants for property's name ({PROPERTY_NAME}_PROPERTY) and | |||
|
30 | * default value ({PROPERTY_NAME}_DEFAULT_VALUE) | |||
|
31 | * - TYPE : return type of the getter | |||
|
32 | */ | |||
|
33 | // clang-format off | |||
|
34 | #define DECLARE_PROPERTY_GETTER(GETTER_NAME, PROPERTY_NAME, TYPE) \ | |||
|
35 | TYPE GETTER_NAME() const \ | |||
|
36 | { \ | |||
|
37 | static auto result = m_Properties.value(PROPERTY_NAME##_PROPERTY, PROPERTY_NAME##_DEFAULT_VALUE).value<TYPE>(); \ | |||
|
38 | return result; \ | |||
|
39 | } \ | |||
|
40 | // clang-format on | |||
|
41 | ||||
|
42 | namespace { | |||
|
43 | ||||
|
44 | // /////// // | |||
|
45 | // Aliases // | |||
|
46 | // /////// // | |||
|
47 | ||||
|
48 | using IntPair = std::pair<int, int>; | |||
|
49 | using Weight = double; | |||
|
50 | using Weights = std::vector<Weight>; | |||
|
51 | ||||
|
52 | struct OperationProperty { | |||
|
53 | Weight m_Weight{1.}; | |||
|
54 | bool m_WaitAcquisition{false}; | |||
|
55 | }; | |||
|
56 | ||||
|
57 | using VariableOperation = std::pair<VariableId, std::shared_ptr<IFuzzingOperation> >; | |||
|
58 | using VariablesOperations = std::vector<VariableOperation>; | |||
|
59 | ||||
|
60 | using OperationsTypes = std::map<FuzzingOperationType, OperationProperty>; | |||
|
61 | using OperationsPool = std::map<std::shared_ptr<IFuzzingOperation>, OperationProperty>; | |||
|
62 | ||||
|
63 | using Validators = std::vector<std::shared_ptr<IFuzzingValidator> >; | |||
|
64 | ||||
|
65 | // ///////// // | |||
|
66 | // Constants // | |||
|
67 | // ///////// // | |||
|
68 | ||||
|
69 | // Defaults values used when the associated properties have not been set for the test | |||
|
70 | const auto ACQUISITION_TIMEOUT_DEFAULT_VALUE = 30000; | |||
|
71 | const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100; | |||
|
72 | const auto NB_MAX_SYNC_GROUPS_DEFAULT_VALUE = 1; | |||
|
73 | const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 1; | |||
|
74 | const auto AVAILABLE_OPERATIONS_DEFAULT_VALUE = QVariant::fromValue( | |||
|
75 | OperationsTypes{{FuzzingOperationType::CREATE, {1., true}}, | |||
|
76 | {FuzzingOperationType::DELETE, {0.1}}, // Delete operation is less frequent | |||
|
77 | {FuzzingOperationType::PAN_LEFT, {1.}}, | |||
|
78 | {FuzzingOperationType::PAN_RIGHT, {1.}}, | |||
|
79 | {FuzzingOperationType::ZOOM_IN, {1.}}, | |||
|
80 | {FuzzingOperationType::ZOOM_OUT, {1.}}, | |||
|
81 | {FuzzingOperationType::SYNCHRONIZE, {0.8}}, | |||
|
82 | {FuzzingOperationType::DESYNCHRONIZE, {0.4}}}); | |||
|
83 | const auto CACHE_TOLERANCE_DEFAULT_VALUE = 0.2; | |||
|
84 | ||||
|
85 | /// Min/max delays between each operation (in ms) | |||
|
86 | const auto OPERATION_DELAY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(100, 3000)); | |||
|
87 | ||||
|
88 | /// Validators for the tests (executed in the order in which they're defined) | |||
|
89 | const auto VALIDATORS_DEFAULT_VALUE = QVariant::fromValue( | |||
|
90 | ValidatorsTypes{{FuzzingValidatorType::RANGE, FuzzingValidatorType::DATA}}); | |||
|
91 | ||||
|
92 | /// 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)); | |||
|
94 | ||||
|
95 | // /////// // | |||
|
96 | // Methods // | |||
|
97 | // /////// // | |||
|
98 | ||||
|
99 | /// 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) | |||
|
101 | std::pair<VariablesOperations, Weights> availableOperations(const FuzzingState &fuzzingState, | |||
|
102 | const OperationsPool &operationsPool) | |||
|
103 | { | |||
|
104 | VariablesOperations result{}; | |||
|
105 | Weights weights{}; | |||
|
106 | ||||
|
107 | for (const auto &variablesPoolEntry : fuzzingState.m_VariablesPool) { | |||
|
108 | auto variableId = variablesPoolEntry.first; | |||
|
109 | ||||
|
110 | for (const auto &operationsPoolEntry : operationsPool) { | |||
|
111 | auto operation = operationsPoolEntry.first; | |||
|
112 | auto operationProperty = operationsPoolEntry.second; | |||
|
113 | ||||
|
114 | // A pair is valid if the current operation can be executed on the current variable | |||
|
115 | if (operation->canExecute(variableId, fuzzingState)) { | |||
|
116 | result.push_back({variableId, operation}); | |||
|
117 | weights.push_back(operationProperty.m_Weight); | |||
|
118 | } | |||
|
119 | } | |||
|
120 | } | |||
|
121 | ||||
|
122 | return {result, weights}; | |||
|
123 | } | |||
|
124 | ||||
|
125 | OperationsPool createOperationsPool(const OperationsTypes &types) | |||
|
126 | { | |||
|
127 | OperationsPool result{}; | |||
|
128 | ||||
|
129 | std::transform( | |||
|
130 | types.cbegin(), types.cend(), std::inserter(result, result.end()), [](const auto &type) { | |||
|
131 | return std::make_pair(FuzzingOperationFactory::create(type.first), type.second); | |||
|
132 | }); | |||
|
133 | ||||
|
134 | return result; | |||
|
135 | } | |||
|
136 | ||||
|
137 | Validators createValidators(const ValidatorsTypes &types) | |||
|
138 | { | |||
|
139 | Validators result{}; | |||
|
140 | ||||
|
141 | std::transform(types.cbegin(), types.cend(), std::inserter(result, result.end()), | |||
|
142 | [](const auto &type) { return FuzzingValidatorFactory::create(type); }); | |||
|
143 | ||||
|
144 | return result; | |||
|
145 | } | |||
|
146 | ||||
|
147 | /** | |||
|
148 | * Validates all the variables' states passed in parameter, according to a set of validators | |||
|
149 | * @param variablesPool the variables' states | |||
|
150 | * @param validators the validators used for validation | |||
|
151 | */ | |||
|
152 | void validate(const VariablesPool &variablesPool, const Validators &validators) | |||
|
153 | { | |||
|
154 | for (const auto &variablesPoolEntry : variablesPool) { | |||
|
155 | auto variableId = variablesPoolEntry.first; | |||
|
156 | const auto &variableState = variablesPoolEntry.second; | |||
|
157 | ||||
|
158 | auto variableMessage = variableState.m_Variable ? variableState.m_Variable->name() | |||
|
159 | : QStringLiteral("null variable"); | |||
|
160 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Validating state of variable at index" | |||
|
161 | << variableId << "(" << variableMessage << ")..."; | |||
|
162 | ||||
|
163 | for (const auto &validator : validators) { | |||
|
164 | validator->validate(VariableState{variableState}); | |||
|
165 | } | |||
|
166 | ||||
|
167 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Validation completed."; | |||
|
168 | } | |||
|
169 | } | |||
|
170 | ||||
|
171 | /** | |||
|
172 | * Class to run random tests | |||
|
173 | */ | |||
|
174 | class FuzzingTest { | |||
|
175 | public: | |||
|
176 | explicit FuzzingTest(VariableController &variableController, Properties properties) | |||
|
177 | : m_VariableController{variableController}, | |||
|
178 | m_Properties{std::move(properties)}, | |||
|
179 | m_FuzzingState{} | |||
|
180 | { | |||
|
181 | // Inits variables pool: at init, all variables are null | |||
|
182 | for (auto variableId = 0; variableId < nbMaxVariables(); ++variableId) { | |||
|
183 | m_FuzzingState.m_VariablesPool[variableId] = VariableState{}; | |||
|
184 | } | |||
|
185 | ||||
|
186 | // Inits sync groups and registers them into the variable controller | |||
|
187 | for (auto i = 0; i < nbMaxSyncGroups(); ++i) { | |||
|
188 | auto syncGroupId = SyncGroupId::createUuid(); | |||
|
189 | variableController.onAddSynchronizationGroupId(syncGroupId); | |||
|
190 | m_FuzzingState.m_SyncGroupsPool[syncGroupId] = SyncGroup{}; | |||
|
191 | } | |||
|
192 | } | |||
|
193 | ||||
|
194 | void execute() | |||
|
195 | { | |||
|
196 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Running" << nbMaxOperations() << "operations on" | |||
|
197 | << nbMaxVariables() << "variable(s)..."; | |||
|
198 | ||||
|
199 | ||||
|
200 | // Inits the count of the number of operations before the next validation | |||
|
201 | int nextValidationCounter = 0; | |||
|
202 | auto updateValidationCounter = [this, &nextValidationCounter]() { | |||
|
203 | nextValidationCounter = RandomGenerator::instance().generateInt( | |||
|
204 | validationFrequencies().first, validationFrequencies().second); | |||
|
205 | qCInfo(LOG_TestAmdaFuzzing()).noquote() | |||
|
206 | << "Next validation in " << nextValidationCounter << "operation(s)..."; | |||
|
207 | }; | |||
|
208 | updateValidationCounter(); | |||
|
209 | ||||
|
210 | auto canExecute = true; | |||
|
211 | for (auto i = 0; i < nbMaxOperations() && canExecute; ++i) { | |||
|
212 | // Retrieves all operations that can be executed in the current context | |||
|
213 | VariablesOperations variableOperations{}; | |||
|
214 | Weights weights{}; | |||
|
215 | std::tie(variableOperations, weights) | |||
|
216 | = availableOperations(m_FuzzingState, operationsPool()); | |||
|
217 | ||||
|
218 | canExecute = !variableOperations.empty(); | |||
|
219 | if (canExecute) { | |||
|
220 | --nextValidationCounter; | |||
|
221 | ||||
|
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; | |||
|
227 | auto fuzzingOperation = variableOperation.second; | |||
|
228 | ||||
|
229 | auto waitAcquisition = nextValidationCounter == 0 | |||
|
230 | || operationsPool().at(fuzzingOperation).m_WaitAcquisition; | |||
|
231 | ||||
|
232 | fuzzingOperation->execute(variableId, m_FuzzingState, m_VariableController, | |||
|
233 | m_Properties); | |||
|
234 | ||||
|
235 | if (waitAcquisition) { | |||
|
236 | qCDebug(LOG_TestAmdaFuzzing()) << "Waiting for acquisition to finish..."; | |||
|
237 | SignalWaiter{m_VariableController, SIGNAL(acquisitionFinished())}.wait( | |||
|
238 | acquisitionTimeout()); | |||
|
239 | ||||
|
240 | // Validates variables | |||
|
241 | if (nextValidationCounter == 0) { | |||
|
242 | validate(m_FuzzingState.m_VariablesPool, validators()); | |||
|
243 | updateValidationCounter(); | |||
|
244 | } | |||
|
245 | } | |||
|
246 | else { | |||
|
247 | // Delays the next operation with a randomly generated time | |||
|
248 | auto delay = RandomGenerator::instance().generateInt(operationDelays().first, | |||
|
249 | operationDelays().second); | |||
|
250 | qCDebug(LOG_TestAmdaFuzzing()) | |||
|
251 | << "Waiting " << delay << "ms before the next operation..."; | |||
|
252 | QTest::qWait(delay); | |||
|
253 | } | |||
|
254 | } | |||
|
255 | else { | |||
|
256 | qCInfo(LOG_TestAmdaFuzzing()).noquote() | |||
|
257 | << "No more operations are available, the execution of the test will stop..."; | |||
|
258 | } | |||
|
259 | } | |||
|
260 | ||||
|
261 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Execution of the test completed."; | |||
|
262 | } | |||
|
263 | ||||
|
264 | private: | |||
|
265 | OperationsPool operationsPool() const | |||
|
266 | { | |||
|
267 | static auto result = createOperationsPool( | |||
|
268 | m_Properties.value(AVAILABLE_OPERATIONS_PROPERTY, AVAILABLE_OPERATIONS_DEFAULT_VALUE) | |||
|
269 | .value<OperationsTypes>()); | |||
|
270 | return result; | |||
|
271 | } | |||
|
272 | ||||
|
273 | Validators validators() const | |||
|
274 | { | |||
|
275 | static auto result | |||
|
276 | = createValidators(m_Properties.value(VALIDATORS_PROPERTY, VALIDATORS_DEFAULT_VALUE) | |||
|
277 | .value<ValidatorsTypes>()); | |||
|
278 | return result; | |||
|
279 | } | |||
|
280 | ||||
|
281 | DECLARE_PROPERTY_GETTER(nbMaxOperations, NB_MAX_OPERATIONS, int) | |||
|
282 | DECLARE_PROPERTY_GETTER(nbMaxSyncGroups, NB_MAX_SYNC_GROUPS, int) | |||
|
283 | DECLARE_PROPERTY_GETTER(nbMaxVariables, NB_MAX_VARIABLES, int) | |||
|
284 | DECLARE_PROPERTY_GETTER(operationDelays, OPERATION_DELAY_BOUNDS, IntPair) | |||
|
285 | DECLARE_PROPERTY_GETTER(validationFrequencies, VALIDATION_FREQUENCY_BOUNDS, IntPair) | |||
|
286 | DECLARE_PROPERTY_GETTER(acquisitionTimeout, ACQUISITION_TIMEOUT, int) | |||
|
287 | ||||
|
288 | VariableController &m_VariableController; | |||
|
289 | Properties m_Properties; | |||
|
290 | FuzzingState m_FuzzingState; | |||
|
291 | }; | |||
|
292 | ||||
|
293 | } // namespace | |||
|
294 | ||||
|
295 | Q_DECLARE_METATYPE(OperationsTypes) | |||
|
296 | ||||
|
297 | class TestAmdaFuzzing : public QObject { | |||
|
298 | Q_OBJECT | |||
|
299 | ||||
|
300 | private slots: | |||
|
301 | /// Input data for @sa testFuzzing() | |||
|
302 | void testFuzzing_data(); | |||
|
303 | void testFuzzing(); | |||
|
304 | }; | |||
|
305 | ||||
|
306 | void TestAmdaFuzzing::testFuzzing_data() | |||
|
307 | { | |||
|
308 | // Note: Comment this line to run fuzzing tests | |||
|
309 | QSKIP("Fuzzing tests are disabled by default"); | |||
|
310 | ||||
|
311 | // ////////////// // | |||
|
312 | // Test structure // | |||
|
313 | // ////////////// // | |||
|
314 | ||||
|
315 | QTest::addColumn<Properties>("properties"); // Properties for random test | |||
|
316 | ||||
|
317 | // ////////// // | |||
|
318 | // Test cases // | |||
|
319 | // ////////// // | |||
|
320 | ||||
|
321 | auto maxRange = SqpRange::fromDateTime({2017, 1, 1}, {0, 0}, {2017, 1, 5}, {0, 0}); | |||
|
322 | MetadataPool metadataPool{{{"dataType", "vector"}, {"xml:id", "imf"}}}; | |||
|
323 | ||||
|
324 | // Note: we don't use auto here as we want to pass std::shared_ptr<IDataProvider> as is in the | |||
|
325 | // QVariant | |||
|
326 | std::shared_ptr<IDataProvider> provider = std::make_shared<AmdaProvider>(); | |||
|
327 | ||||
|
328 | QTest::newRow("fuzzingTest") << Properties{ | |||
|
329 | {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)}, | |||
|
330 | {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)}, | |||
|
331 | {PROVIDER_PROPERTY, QVariant::fromValue(provider)}}; | |||
|
332 | } | |||
|
333 | ||||
|
334 | void TestAmdaFuzzing::testFuzzing() | |||
|
335 | { | |||
|
336 | QFETCH(Properties, properties); | |||
|
337 | ||||
|
338 | // Sets cache property | |||
|
339 | QSettings settings{}; | |||
|
340 | auto cacheTolerance = properties.value(CACHE_TOLERANCE_PROPERTY, CACHE_TOLERANCE_DEFAULT_VALUE); | |||
|
341 | settings.setValue(GENERAL_TOLERANCE_AT_INIT_KEY, cacheTolerance); | |||
|
342 | settings.setValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, cacheTolerance); | |||
|
343 | ||||
|
344 | auto &variableController = sqpApp->variableController(); | |||
|
345 | auto &timeController = sqpApp->timeController(); | |||
|
346 | ||||
|
347 | // Generates random initial range (bounded to max range) | |||
|
348 | auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE)) | |||
|
349 | .value<SqpRange>(); | |||
|
350 | ||||
|
351 | QVERIFY(maxRange != INVALID_RANGE); | |||
|
352 | ||||
|
353 | auto initialRangeStart | |||
|
354 | = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd); | |||
|
355 | auto initialRangeEnd | |||
|
356 | = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd); | |||
|
357 | if (initialRangeStart > initialRangeEnd) { | |||
|
358 | std::swap(initialRangeStart, initialRangeEnd); | |||
|
359 | } | |||
|
360 | ||||
|
361 | // Sets initial range on time controller | |||
|
362 | SqpRange initialRange{initialRangeStart, initialRangeEnd}; | |||
|
363 | qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Setting initial range to" << initialRange << "..."; | |||
|
364 | timeController.onTimeToUpdate(initialRange); | |||
|
365 | properties.insert(INITIAL_RANGE_PROPERTY, QVariant::fromValue(initialRange)); | |||
|
366 | ||||
|
367 | FuzzingTest test{variableController, properties}; | |||
|
368 | test.execute(); | |||
|
369 | } | |||
|
370 | ||||
|
371 | int main(int argc, char *argv[]) | |||
|
372 | { | |||
|
373 | QLoggingCategory::setFilterRules( | |||
|
374 | "*.warning=false\n" | |||
|
375 | "*.info=false\n" | |||
|
376 | "*.debug=false\n" | |||
|
377 | "FuzzingOperations.info=true\n" | |||
|
378 | "FuzzingValidators.info=true\n" | |||
|
379 | "TestAmdaFuzzing.info=true\n"); | |||
|
380 | ||||
|
381 | SqpApplication app{argc, argv}; | |||
|
382 | SqpApplication::setOrganizationName("LPP"); | |||
|
383 | SqpApplication::setOrganizationDomain("lpp.fr"); | |||
|
384 | SqpApplication::setApplicationName("SciQLop-TestFuzzing"); | |||
|
385 | app.setAttribute(Qt::AA_Use96Dpi, true); | |||
|
386 | TestAmdaFuzzing testObject{}; | |||
|
387 | QTEST_SET_MAIN_SOURCE_PATH | |||
|
388 | return QTest::qExec(&testObject, argc, argv); | |||
|
389 | } | |||
|
390 | ||||
|
391 | #include "TestAmdaFuzzing.moc" |
@@ -14,6 +14,14 | |||||
14 | * @brief The SqpRange struct holds the information of time parameters |
|
14 | * @brief The SqpRange struct holds the information of time parameters | |
15 | */ |
|
15 | */ | |
16 | struct SqpRange { |
|
16 | struct SqpRange { | |
|
17 | /// Creates SqpRange from dates and times | |||
|
18 | static SqpRange fromDateTime(const QDate &startDate, const QTime &startTime, | |||
|
19 | const QDate &endDate, const QTime &endTime) | |||
|
20 | { | |||
|
21 | return {DateUtils::secondsSinceEpoch(QDateTime{startDate, startTime, Qt::UTC}), | |||
|
22 | DateUtils::secondsSinceEpoch(QDateTime{endDate, endTime, Qt::UTC})}; | |||
|
23 | } | |||
|
24 | ||||
17 | /// Start time (UTC) |
|
25 | /// Start time (UTC) | |
18 | double m_TStart; |
|
26 | double m_TStart; | |
19 | /// End time (UTC) |
|
27 | /// End time (UTC) |
@@ -85,6 +85,10 signals: | |||||
85 | /// Signal emitted when a sub range of the cacheRange of the variable can be displayed |
|
85 | /// Signal emitted when a sub range of the cacheRange of the variable can be displayed | |
86 | void updateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
86 | void updateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); | |
87 |
|
87 | |||
|
88 | /// Signal emitted when all acquisitions related to the variables have been completed (whether | |||
|
89 | /// validated, canceled, or failed) | |||
|
90 | void acquisitionFinished(); | |||
|
91 | ||||
88 | public slots: |
|
92 | public slots: | |
89 | /// Request the data loading of the variable whithin range |
|
93 | /// Request the data loading of the variable whithin range | |
90 | void onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, const SqpRange &range, |
|
94 | void onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, const SqpRange &range, |
@@ -5,6 +5,7 catalogueapi_dep = dependency('CatalogueAPI', required : true, fallback:['Catalo | |||||
5 |
|
5 | |||
6 | core_moc_headers = [ |
|
6 | core_moc_headers = [ | |
7 | 'include/Catalogue/CatalogueController.h', |
|
7 | 'include/Catalogue/CatalogueController.h', | |
|
8 | 'include/Common/SignalWaiter.h', | |||
8 | 'include/Data/IDataProvider.h', |
|
9 | 'include/Data/IDataProvider.h', | |
9 | 'include/DataSource/DataSourceController.h', |
|
10 | 'include/DataSource/DataSourceController.h', | |
10 | 'include/DataSource/DataSourceItemAction.h', |
|
11 | 'include/DataSource/DataSourceItemAction.h', | |
@@ -24,6 +25,7 core_moc_files = qt5.preprocess(moc_headers : core_moc_headers) | |||||
24 |
|
25 | |||
25 | core_sources = [ |
|
26 | core_sources = [ | |
26 | 'src/Common/DateUtils.cpp', |
|
27 | 'src/Common/DateUtils.cpp', | |
|
28 | 'src/Common/SignalWaiter.cpp', | |||
27 | 'src/Common/StringUtils.cpp', |
|
29 | 'src/Common/StringUtils.cpp', | |
28 | 'src/Common/MimeTypesDef.cpp', |
|
30 | 'src/Common/MimeTypesDef.cpp', | |
29 | 'src/Catalogue/CatalogueController.cpp', |
|
31 | 'src/Catalogue/CatalogueController.cpp', |
@@ -890,6 +890,9 void VariableController::VariableControllerPrivate::updateVariables(QUuid varReq | |||||
890 | // cleaning varRequestId |
|
890 | // cleaning varRequestId | |
891 | qCDebug(LOG_VariableController()) << tr("m_VarGroupIdToVarIds erase") << varRequestId; |
|
891 | qCDebug(LOG_VariableController()) << tr("m_VarGroupIdToVarIds erase") << varRequestId; | |
892 | m_VarGroupIdToVarIds.erase(varRequestId); |
|
892 | m_VarGroupIdToVarIds.erase(varRequestId); | |
|
893 | if (m_VarGroupIdToVarIds.empty()) { | |||
|
894 | emit q->acquisitionFinished(); | |||
|
895 | } | |||
893 | } |
|
896 | } | |
894 | } |
|
897 | } | |
895 |
|
898 | |||
@@ -1019,6 +1022,9 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid | |||||
1019 | } |
|
1022 | } | |
1020 | qCDebug(LOG_VariableController()) << tr("cancelVariableRequest: erase") << varRequestId; |
|
1023 | qCDebug(LOG_VariableController()) << tr("cancelVariableRequest: erase") << varRequestId; | |
1021 | m_VarGroupIdToVarIds.erase(varRequestId); |
|
1024 | m_VarGroupIdToVarIds.erase(varRequestId); | |
|
1025 | if (m_VarGroupIdToVarIds.empty()) { | |||
|
1026 | emit q->acquisitionFinished(); | |||
|
1027 | } | |||
1022 | } |
|
1028 | } | |
1023 |
|
1029 | |||
1024 | void VariableController::VariableControllerPrivate::executeVarRequest(std::shared_ptr<Variable> var, |
|
1030 | void VariableController::VariableControllerPrivate::executeVarRequest(std::shared_ptr<Variable> var, |
@@ -115,6 +115,7 IF(BUILD_TESTS) | |||||
115 | ${testDirectory}/*.cpp |
|
115 | ${testDirectory}/*.cpp | |
116 | ${testDirectory}/*.h) |
|
116 | ${testDirectory}/*.h) | |
117 | LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) |
|
117 | LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) | |
|
118 | LIST(APPEND testFilesToFormat ${currentTestSources}) | |||
118 | # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) |
|
119 | # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) | |
119 |
|
120 | |||
120 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) |
|
121 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) |
@@ -62,7 +62,19 sciqlop_amdaplugin = library('amdaplugin', | |||||
62 | tests = [ |
|
62 | tests = [ | |
63 | [['tests/TestAmdaParser.cpp'],'test_amda_parser','AMDA parser test'], |
|
63 | [['tests/TestAmdaParser.cpp'],'test_amda_parser','AMDA parser test'], | |
64 | [['tests/TestAmdaResultParser.cpp'],'test_amda_result_parser','AMDA result parser test'], |
|
64 | [['tests/TestAmdaResultParser.cpp'],'test_amda_result_parser','AMDA result parser test'], | |
65 | [['tests/TestAmdaAcquisition.cpp'],'test_amda_acquisition','AMDA Acquisition test'] |
|
65 | [['tests/TestAmdaAcquisition.cpp'],'test_amda_acquisition','AMDA Acquisition test'], | |
|
66 | [['tests/TestAmdaFuzzing.cpp'],'test_amda_fuzzing','AMDA fuzzing test'] | |||
|
67 | ] | |||
|
68 | ||||
|
69 | tests_sources = [ | |||
|
70 | 'tests/FuzzingDefs.h', | |||
|
71 | 'tests/FuzzingDefs.cpp', | |||
|
72 | 'tests/FuzzingOperations.h', | |||
|
73 | 'tests/FuzzingOperations.cpp', | |||
|
74 | 'tests/FuzzingUtils.h', | |||
|
75 | 'tests/FuzzingUtils.cpp', | |||
|
76 | 'tests/FuzzingValidators.h', | |||
|
77 | 'tests/FuzzingValidators.cpp' | |||
66 | ] |
|
78 | ] | |
67 |
|
79 | |||
68 | foreach unit_test : tests |
|
80 | foreach unit_test : tests | |
@@ -71,6 +83,7 foreach unit_test : tests | |||||
71 | link_with : [sciqlop_amdaplugin], |
|
83 | link_with : [sciqlop_amdaplugin], | |
72 | include_directories : [amdaplugin_inc], |
|
84 | include_directories : [amdaplugin_inc], | |
73 | cpp_args : ['-DAMDA_TESTS_RESOURCES_DIR="'+meson.current_source_dir()+'/tests-resources"'], |
|
85 | cpp_args : ['-DAMDA_TESTS_RESOURCES_DIR="'+meson.current_source_dir()+'/tests-resources"'], | |
|
86 | sources : [tests_sources], | |||
74 | dependencies : [sciqlop_core, sciqlop_gui, qt5test]) |
|
87 | dependencies : [sciqlop_core, sciqlop_gui, qt5test]) | |
75 | test(unit_test[2], test_exe, args: ['-teamcity', '-o', '@0@.teamcity.txt'.format(unit_test[1])], timeout: 3 * 60) |
|
88 | test(unit_test[2], test_exe, args: ['-teamcity', '-o', '@0@.teamcity.txt'.format(unit_test[1])], timeout: 3 * 60) | |
76 | endforeach |
|
89 | endforeach |
General Comments 0
You need to be logged in to leave comments.
Login now