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