##// END OF EJS Templates
Passes FuzzingState and variable id instead VariableState to the methods of operations
Alexandre Leroux -
r1236:ea04bef9c90c
parent child
Show More
@@ -15,13 +15,14 Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations")
15 15 namespace {
16 16
17 17 struct CreateOperation : public IFuzzingOperation {
18 bool canExecute(const VariableState &variableState) const override
18 bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override
19 19 {
20 20 // A variable can be created only if it doesn't exist yet
21 return variableState.m_Variable == nullptr;
21 return fuzzingState.variableState(variableId).m_Variable == nullptr;
22 22 }
23 23
24 void execute(VariableState &variableState, VariableController &variableController,
24 void execute(VariableId variableId, FuzzingState &fuzzingState,
25 VariableController &variableController,
25 26 const Properties &properties) const override
26 27 {
27 28 // Retrieves metadata pool from properties, and choose one of the metadata entries to
@@ -41,22 +42,23 struct CreateOperation : public IFuzzingOperation {
41 42 = variableController.createVariable(variableName, variableMetadata, variableProvider);
42 43
43 44 // Updates variable's state
45 auto &variableState = fuzzingState.variableState(variableId);
44 46 variableState.m_Range = properties.value(INITIAL_RANGE_PROPERTY).value<SqpRange>();
45 47 std::swap(variableState.m_Variable, newVariable);
46 48 }
47 49 };
48 50
49 51 struct DeleteOperation : public IFuzzingOperation {
50 bool canExecute(const VariableState &variableState) const override
52 bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override
51 53 {
52 54 // A variable can be delete only if it exists
53 return variableState.m_Variable != nullptr;
55 return fuzzingState.variableState(variableId).m_Variable != nullptr;
54 56 }
55 57
56 void execute(VariableState &variableState, VariableController &variableController,
57 const Properties &properties) const override
58 void execute(VariableId variableId, FuzzingState &fuzzingState,
59 VariableController &variableController, const Properties &) const override
58 60 {
59 Q_UNUSED(properties);
61 auto &variableState = fuzzingState.variableState(variableId);
60 62
61 63 qCInfo(LOG_FuzzingOperations()).noquote()
62 64 << "Deleting variable" << variableState.m_Variable->name() << "...";
@@ -100,14 +102,16 struct MoveOperation : public IFuzzingOperation {
100 102 {
101 103 }
102 104
103 bool canExecute(const VariableState &variableState) const override
105 bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override
104 106 {
105 return variableState.m_Variable != nullptr;
107 return fuzzingState.variableState(variableId).m_Variable != nullptr;
106 108 }
107 109
108 void execute(VariableState &variableState, VariableController &variableController,
110 void execute(VariableId variableId, FuzzingState &fuzzingState,
111 VariableController &variableController,
109 112 const Properties &properties) const override
110 113 {
114 auto &variableState = fuzzingState.variableState(variableId);
111 115 auto variable = variableState.m_Variable;
112 116
113 117 // Gets the max range defined
@@ -146,19 +150,11 struct MoveOperation : public IFuzzingOperation {
146 150 };
147 151
148 152 struct UnknownOperation : public IFuzzingOperation {
149 bool canExecute(const VariableState &variableState) const override
150 {
151 Q_UNUSED(variableState);
152 return false;
153 }
153 bool canExecute(VariableId, const FuzzingState &) const override { return false; }
154 154
155 void execute(VariableState &variableState, VariableController &variableController,
156 const Properties &properties) const override
155 void execute(VariableId, FuzzingState &, VariableController &,
156 const Properties &) const override
157 157 {
158 Q_UNUSED(variableState);
159 Q_UNUSED(variableController);
160 Q_UNUSED(properties);
161 // Does nothing
162 158 }
163 159 };
164 160
@@ -22,17 +22,19 enum class FuzzingOperationType { CREATE, DELETE, PAN_LEFT, PAN_RIGHT, ZOOM_IN,
22 22 struct IFuzzingOperation {
23 23 virtual ~IFuzzingOperation() noexcept = default;
24 24
25 /// Checks if the operation can be executed according to the current variable state passed in
26 /// parameter
27 virtual bool canExecute(const VariableState &variableState) const = 0;
28 /// Executes the operation on the variable state passed in parameter
29 /// @param variableState the variable state on which to execute the operation
25 /// Checks if the operation can be executed according to the current test's state for the
26 /// variable passed in parameter
27 virtual bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const = 0;
28 /// Executes the operation on the variable for which its identifier is passed in parameter
29 /// @param variableId the variable identifier
30 /// @param fuzzingState the current test's state on which to find the variable and execute the
31 /// operation
30 32 /// @param variableController the controller associated to the operation
31 33 /// @param properties properties that can be used to configure the operation
32 /// @remarks variableState is passed as a reference because, according to the operation, it can
33 /// be
34 /// modified (in/out parameter)
35 virtual void execute(VariableState &variableState, VariableController &variableController,
34 /// @remarks fuzzingState is passed as a reference because, according to the operation, it can
35 /// be modified (in/out parameter)
36 virtual void execute(VariableId variableId, FuzzingState &fuzzingState,
37 VariableController &variableController,
36 38 const Properties &properties = {}) const = 0;
37 39 };
38 40
@@ -26,7 +26,6 namespace {
26 26 // Aliases //
27 27 // /////// //
28 28
29 using VariableId = int;
30 29 using Weight = double;
31 30 using Weights = std::vector<Weight>;
32 31
@@ -34,7 +33,6 using VariableOperation = std::pair<VariableId, std::shared_ptr<IFuzzingOperatio
34 33 using VariablesOperations = std::vector<VariableOperation>;
35 34
36 35 using WeightedOperationsPool = std::map<std::shared_ptr<IFuzzingOperation>, Weight>;
37 using VariablesPool = std::map<VariableId, VariableState>;
38 36 using Validators = std::vector<std::shared_ptr<IFuzzingValidator> >;
39 37
40 38 // ///////// //
@@ -67,22 +65,20 const auto VALIDATORS_DEFAULT_VALUE = QVariant::fromValue(
67 65 /// Goes through the variables pool and operations pool to determine the set of {variable/operation}
68 66 /// pairs that are valid (i.e. operation that can be executed on variable)
69 67 std::pair<VariablesOperations, Weights>
70 availableOperations(const VariablesPool &variablesPool,
71 const WeightedOperationsPool &operationsPool)
68 availableOperations(const FuzzingState &fuzzingState, const WeightedOperationsPool &operationsPool)
72 69 {
73 70 VariablesOperations result{};
74 71 Weights weights{};
75 72
76 for (const auto &variablesPoolEntry : variablesPool) {
73 for (const auto &variablesPoolEntry : fuzzingState.m_VariablesPool) {
77 74 auto variableId = variablesPoolEntry.first;
78 const auto &variableState = variablesPoolEntry.second;
79 75
80 76 for (const auto &operationsPoolEntry : operationsPool) {
81 77 auto operation = operationsPoolEntry.first;
82 78 auto weight = operationsPoolEntry.second;
83 79
84 80 // A pair is valid if the current operation can be executed on the current variable
85 if (operation->canExecute(variableState)) {
81 if (operation->canExecute(variableId, fuzzingState)) {
86 82 result.push_back({variableId, operation});
87 83 weights.push_back(weight);
88 84 }
@@ -146,11 +142,11 public:
146 142 explicit FuzzingTest(VariableController &variableController, Properties properties)
147 143 : m_VariableController{variableController},
148 144 m_Properties{std::move(properties)},
149 m_VariablesPool{}
145 m_FuzzingState{}
150 146 {
151 147 // Inits variables pool: at init, all variables are null
152 148 for (auto variableId = 0; variableId < nbMaxVariables(); ++variableId) {
153 m_VariablesPool[variableId] = VariableState{};
149 m_FuzzingState.m_VariablesPool[variableId] = VariableState{};
154 150 }
155 151 }
156 152
@@ -165,7 +161,7 public:
165 161 VariablesOperations variableOperations{};
166 162 Weights weights{};
167 163 std::tie(variableOperations, weights)
168 = availableOperations(m_VariablesPool, operationsPool());
164 = availableOperations(m_FuzzingState, operationsPool());
169 165
170 166 canExecute = !variableOperations.empty();
171 167 if (canExecute) {
@@ -174,14 +170,14 public:
174 170 = RandomGenerator::instance().randomChoice(variableOperations, weights);
175 171
176 172 auto variableId = variableOperation.first;
177 auto &variableState = m_VariablesPool.at(variableId);
178 173 auto fuzzingOperation = variableOperation.second;
179 174
180 fuzzingOperation->execute(variableState, m_VariableController, m_Properties);
175 fuzzingOperation->execute(variableId, m_FuzzingState, m_VariableController,
176 m_Properties);
181 177 QTest::qWait(operationDelay());
182 178
183 179 // Validates variables
184 validate(m_VariablesPool, validators());
180 validate(m_FuzzingState.m_VariablesPool, validators());
185 181 }
186 182 else {
187 183 qCInfo(LOG_TestAmdaFuzzing()).noquote()
@@ -233,7 +229,7 private:
233 229
234 230 VariableController &m_VariableController;
235 231 Properties m_Properties;
236 VariablesPool m_VariablesPool;
232 FuzzingState m_FuzzingState;
237 233 };
238 234
239 235 } // namespace
General Comments 0
You need to be logged in to leave comments. Login now