@@ -21,6 +21,9 namespace { | |||
|
21 | 21 | |
|
22 | 22 | using VariableId = int; |
|
23 | 23 | |
|
24 | using VariableOperation = std::pair<VariableId, std::shared_ptr<IFuzzingOperation> >; | |
|
25 | using VariablesOperations = std::vector<VariableOperation>; | |
|
26 | ||
|
24 | 27 | using OperationsPool = std::set<std::shared_ptr<IFuzzingOperation> >; |
|
25 | 28 | using VariablesPool = std::map<VariableId, std::shared_ptr<Variable> >; |
|
26 | 29 | |
@@ -33,6 +36,32 const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100; | |||
|
33 | 36 | const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 1; |
|
34 | 37 | const auto AVAILABLE_OPERATIONS_DEFAULT_VALUE |
|
35 | 38 | = QVariant::fromValue(OperationsTypes{FuzzingOperationType::CREATE}); |
|
39 | // /////// // | |
|
40 | // Methods // | |
|
41 | // /////// // | |
|
42 | ||
|
43 | /// Goes through the variables pool and operations pool to determine the set of {variable/operation} | |
|
44 | /// pairs that are valid (i.e. operation that can be executed on variable) | |
|
45 | VariablesOperations availableOperations(const VariablesPool &variablesPool, | |
|
46 | const OperationsPool &operationsPool) | |
|
47 | { | |
|
48 | VariablesOperations result{}; | |
|
49 | ||
|
50 | for (const auto &variablesPoolEntry : variablesPool) { | |
|
51 | auto variableId = variablesPoolEntry.first; | |
|
52 | auto variable = variablesPoolEntry.second; | |
|
53 | ||
|
54 | for (const auto &operation : operationsPool) { | |
|
55 | // A pair is valid if the current operation can be executed on the current variable | |
|
56 | if (operation->canExecute(variable)) { | |
|
57 | result.push_back({variableId, operation}); | |
|
58 | } | |
|
59 | } | |
|
60 | } | |
|
61 | ||
|
62 | return result; | |
|
63 | } | |
|
64 | ||
|
36 | 65 | OperationsPool createOperationsPool(const OperationsTypes &types) |
|
37 | 66 | { |
|
38 | 67 | OperationsPool result{}; |
@@ -61,10 +90,35 public: | |||
|
61 | 90 | |
|
62 | 91 | void execute() |
|
63 | 92 | { |
|
64 | /// @todo: complete | |
|
65 | 93 | qCInfo(LOG_TestAmdaFuzzing()) << "Running" << nbMaxOperations() << "operations on" |
|
66 | 94 | << nbMaxVariables() << "variables..."; |
|
67 | 95 | |
|
96 | auto canExecute = true; | |
|
97 | for (auto i = 0; i < nbMaxOperations() && canExecute; ++i) { | |
|
98 | // Retrieves all operations that can be executed in the current context | |
|
99 | auto variableOperations = availableOperations(m_VariablesPool, operationsPool()); | |
|
100 | ||
|
101 | canExecute = !variableOperations.empty(); | |
|
102 | if (canExecute) { | |
|
103 | // Of the operations available, chooses a random operation and executes it | |
|
104 | auto variableOperation | |
|
105 | = /* TODO: gets a random operation */; | |
|
106 | ||
|
107 | auto variableId = variableOperation.first; | |
|
108 | auto variable = m_VariablesPool.at(variableId); | |
|
109 | auto fuzzingOperation = variableOperation.second; | |
|
110 | ||
|
111 | fuzzingOperation->execute(variable, m_VariableController, m_Properties); | |
|
112 | ||
|
113 | // Updates variable pool with the new state of the variable after operation | |
|
114 | m_VariablesPool[variableId] = variable; | |
|
115 | } | |
|
116 | else { | |
|
117 | qCInfo(LOG_TestAmdaFuzzing()) | |
|
118 | << "No more operations are available, the execution of the test will stop..."; | |
|
119 | } | |
|
120 | } | |
|
121 | ||
|
68 | 122 | qCInfo(LOG_TestAmdaFuzzing()) << "Execution of the test completed."; |
|
69 | 123 | } |
|
70 | 124 |
General Comments 0
You need to be logged in to leave comments.
Login now