##// END OF EJS Templates
Defines fuzzing operations...
Alexandre Leroux -
r1202:1d0fdfceb8fb
parent child
Show More
@@ -0,0 +1,48
1 #include "FuzzingOperations.h"
2
3 #include <Variable/Variable.h>
4 #include <Variable/VariableController.h>
5
6 Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations")
7
8 namespace {
9
10 struct CreateOperation : public IFuzzingOperation {
11 bool canExecute(std::shared_ptr<Variable> variable) const override {
12 /// @todo: complete
13 return false;
14 }
15
16 void execute(std::shared_ptr<Variable>& variable, VariableController &variableController, const Properties &properties) const override{
17 /// @todo: complete
18 }
19 };
20
21 struct UnknownOperation : public IFuzzingOperation {
22 bool canExecute(std::shared_ptr<Variable> variable) const override {
23 Q_UNUSED(variable);
24 return false;
25 }
26
27 void execute(std::shared_ptr<Variable>& variable, VariableController &variableController, const Properties &properties) const override{
28 Q_UNUSED(variable);
29 Q_UNUSED(variableController);
30 Q_UNUSED(properties);
31 // Does nothing
32 }
33 };
34
35 } // namespace
36
37 std::unique_ptr<IFuzzingOperation> FuzzingOperationFactory::create(FuzzingOperationType type)
38 {
39 switch (type) {
40 case FuzzingOperationType::CREATE:
41 return std::make_unique<CreateOperation>();
42 default:
43 // Default case returns unknown operation
44 break;
45 }
46
47 return std::make_unique<UnknownOperation>();
48 }
@@ -0,0 +1,47
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 Variable;
15 class VariableController;
16
17 /**
18 * Enumeration of types of existing fuzzing operations
19 */
20 enum class FuzzingOperationType {
21 CREATE
22 };
23
24 /// Interface that represents an operation that can be executed during a fuzzing test
25 struct IFuzzingOperation {
26 virtual ~IFuzzingOperation() noexcept = default;
27
28 /// Checks if the operation can be executed according to the current state of the variable passed in parameter
29 virtual bool canExecute(std::shared_ptr<Variable> variable) const = 0;
30 /// Executes the operation on the variable passed in parameter
31 /// @param variable the variable on which to execute the operation
32 /// @param variableController the controller associated to the operation
33 /// @param properties properties that can be used to configure the operation
34 /// @remarks variable is passed as a reference because, according to the operation, it can be modified (in/out parameter)
35 virtual void execute(std::shared_ptr<Variable> &variable, VariableController& variableController, const Properties& properties = {}) const = 0;
36 };
37
38 /// Factory of @sa IFuzzingOperation
39 struct FuzzingOperationFactory {
40 /// Creates a fuzzing operation from a type
41 static std::unique_ptr<IFuzzingOperation> create(FuzzingOperationType type);
42 };
43
44 using OperationsTypes = std::set<FuzzingOperationType>;
45 Q_DECLARE_METATYPE(OperationsTypes)
46
47 #endif // SCIQLOP_FUZZINGOPERATIONS_H
@@ -1,83 +1,85
1 1
2 2 amdaplugin_moc_headers = [
3 3 'include/AmdaPlugin.h',
4 4 'include/AmdaProvider.h'
5 5 ]
6 6
7 7 amdaplugin_sources = [
8 8 'src/AmdaDefs.cpp',
9 9 'src/AmdaParser.cpp',
10 10 'src/AmdaPlugin.cpp',
11 11 'src/AmdaProvider.cpp',
12 12 'src/AmdaResultParser.cpp',
13 13 'src/AmdaResultParserDefs.cpp',
14 14 'src/AmdaResultParserHelper.cpp',
15 15 'src/AmdaServer.cpp'
16 16 ]
17 17
18 18 amdaplugin_ui_files = []
19 19 amdaplugin_resources_files = [
20 20 'resources/amdaresources.qrc'
21 21 ]
22 22
23 23 amdaplugin_inc = include_directories(['include', '../../plugin/include'])
24 24
25 25 moc_gen = generator(moc,
26 26 output : 'moc_@BASENAME@.cpp',
27 27 arguments : ['@INPUT@',
28 28 '-DSCIQLOP_PLUGIN_JSON_FILE_PATH="'+meson.source_root()+'/plugins/amda/resources/amda.json"',
29 29 '-I', meson.current_source_dir()+'/include',
30 30 '-I', meson.current_source_dir()+'/../../plugin/include',
31 31 '-o', '@OUTPUT@'])
32 32
33 33 rcc_gen = generator(rcc,
34 34 output : 'qrc_@BASENAME@.cpp',
35 35 arguments : ['--name=@BASENAME@"',
36 36 '--output',
37 37 '@OUTPUT@',
38 38 '@INPUT@'])
39 39
40 40 amdaplugin_moc_plugin_files = moc_gen.process(amdaplugin_moc_headers)
41 41
42 42 amdaplugin_rcc_plugin_files = rcc_gen.process(amdaplugin_resources_files)
43 43
44 44 #amdaplugin_rcc_plugin_files = qt5.preprocess(
45 45 # qresources : amdaplugin_resources_files)
46 46
47 47 amdaplugin_moc_files = qt5.preprocess(
48 48 ui_files : amdaplugin_ui_files)
49 49
50 50 sciqlop_amdaplugin = library('amdaplugin',
51 51 amdaplugin_sources,
52 52 amdaplugin_moc_files,
53 53 amdaplugin_rcc_plugin_files,
54 54 amdaplugin_moc_plugin_files,
55 55 cpp_args : ['-DAMDA_LIB','-DQT_PLUGIN'],
56 56 include_directories : [amdaplugin_inc],
57 57 dependencies : [sciqlop_core, sciqlop_gui],
58 58 install : true
59 59 )
60 60
61 61
62 62 tests = [
63 63 [['tests/TestAmdaParser.cpp'],'test_amda_parser','AMDA parser test'],
64 64 [['tests/TestAmdaResultParser.cpp'],'test_amda_result_parser','AMDA result parser test'],
65 65 [['tests/TestAmdaAcquisition.cpp'],'test_amda_acquisition','AMDA Acquisition test'],
66 66 [['tests/TestAmdaFuzzing.cpp'],'test_amda_fuzzing','AMDA fuzzing test']
67 67 ]
68 68
69 69 tests_sources = [
70 70 'tests/FuzzingDefs.h',
71 71 'tests/FuzzingDefs.cpp',
72 'tests/FuzzingOperations.h',
73 'tests/FuzzingOperations.cpp',
72 74 ]
73 75
74 76 foreach unit_test : tests
75 77 test_moc_files = qt5.preprocess(moc_sources : unit_test[0])
76 78 test_exe = executable(unit_test[1],unit_test[0] , test_moc_files,
77 79 link_with : [sciqlop_amdaplugin],
78 80 include_directories : [amdaplugin_inc],
79 81 cpp_args : ['-DAMDA_TESTS_RESOURCES_DIR="'+meson.current_source_dir()+'/tests-resources"'],
80 82 sources : [tests_sources],
81 83 dependencies : [sciqlop_core, sciqlop_gui, qt5test])
82 84 test(unit_test[2], test_exe, args: ['-teamcity', '-o', '@0@.teamcity.txt'.format(unit_test[1])], timeout: 3 * 60)
83 85 endforeach
@@ -1,117 +1,123
1 1 #include "FuzzingDefs.h"
2 #include "FuzzingOperations.h"
2 3 #include <Network/NetworkController.h>
3 4 #include <SqpApplication.h>
4 5 #include <Time/TimeController.h>
5 6 #include <Variable/VariableController.h>
6 7
7 8 #include <QLoggingCategory>
8 9 #include <QObject>
9 10 #include <QtTest>
10 11
11 12 #include <memory>
12 13
13 14 Q_LOGGING_CATEGORY(LOG_TestAmdaFuzzing, "TestAmdaFuzzing")
14 15
15 16 namespace {
16 17
18 // /////// //
19 // Aliases //
20 // /////// //
21
22 using OperationsPool = std::set<std::shared_ptr<IFuzzingOperation> >;
17 23 // ///////// //
18 24 // Constants //
19 25 // ///////// //
20 26
21 27 // Defaults values used when the associated properties have not been set for the test
22 28 const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100;
23 29 const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 1;
24 30 /**
25 31 * Class to run random tests
26 32 */
27 33 class FuzzingTest {
28 34 public:
29 35 explicit FuzzingTest(VariableController &variableController, Properties properties)
30 36 : m_VariableController{variableController},
31 37 m_Properties{std::move(properties)},
32 38 {
33 39 }
34 40
35 41 void execute()
36 42 {
37 43 /// @todo: complete
38 44 qCInfo(LOG_TestAmdaFuzzing()) << "Running" << nbMaxOperations() << "operations on"
39 45 << nbMaxVariables() << "variables...";
40 46
41 47 qCInfo(LOG_TestAmdaFuzzing()) << "Execution of the test completed.";
42 48 }
43 49
44 50 private:
45 51 int nbMaxOperations() const
46 52 {
47 53 static auto result
48 54 = m_Properties.value(NB_MAX_OPERATIONS_PROPERTY, NB_MAX_OPERATIONS_DEFAULT_VALUE)
49 55 .toInt();
50 56 return result;
51 57 }
52 58
53 59 int nbMaxVariables() const
54 60 {
55 61 static auto result
56 62 = m_Properties.value(NB_MAX_VARIABLES_PROPERTY, NB_MAX_VARIABLES_DEFAULT_VALUE).toInt();
57 63 return result;
58 64 }
59 65
60 66 VariableController &m_VariableController;
61 67 Properties m_Properties;
62 68 };
63 69
64 70 } // namespace
65 71
66 72 class TestAmdaFuzzing : public QObject {
67 73 Q_OBJECT
68 74
69 75 private slots:
70 76 /// Input data for @sa testFuzzing()
71 77 void testFuzzing_data();
72 78 void testFuzzing();
73 79 };
74 80
75 81 void TestAmdaFuzzing::testFuzzing_data()
76 82 {
77 83 // ////////////// //
78 84 // Test structure //
79 85 // ////////////// //
80 86
81 87 QTest::addColumn<Properties>("properties"); // Properties for random test
82 88
83 89 // ////////// //
84 90 // Test cases //
85 91 // ////////// //
86 92
87 93 ///@todo: complete
88 94 }
89 95
90 96 void TestAmdaFuzzing::testFuzzing()
91 97 {
92 98 QFETCH(Properties, properties);
93 99
94 100 auto &variableController = sqpApp->variableController();
95 101 auto &timeController = sqpApp->timeController();
96 102
97 103 FuzzingTest test{variableController, properties};
98 104 test.execute();
99 105 }
100 106
101 107 int main(int argc, char *argv[])
102 108 {
103 109 QLoggingCategory::setFilterRules(
104 110 "*.warning=false\n"
105 111 "*.info=false\n"
106 112 "*.debug=false\n"
107 113 "FuzzingOperations.info=true\n"
108 114 "TestAmdaFuzzing.info=true\n");
109 115
110 116 SqpApplication app{argc, argv};
111 117 app.setAttribute(Qt::AA_Use96Dpi, true);
112 118 TestAmdaFuzzing testObject{};
113 119 QTEST_SET_MAIN_SOURCE_PATH
114 120 return QTest::qExec(&testObject, argc, argv);
115 121 }
116 122
117 123 #include "TestAmdaFuzzing.moc"
General Comments 0
You need to be logged in to leave comments. Login now