##// 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 amdaplugin_moc_headers = [
2 amdaplugin_moc_headers = [
3 'include/AmdaPlugin.h',
3 'include/AmdaPlugin.h',
4 'include/AmdaProvider.h'
4 'include/AmdaProvider.h'
5 ]
5 ]
6
6
7 amdaplugin_sources = [
7 amdaplugin_sources = [
8 'src/AmdaDefs.cpp',
8 'src/AmdaDefs.cpp',
9 'src/AmdaParser.cpp',
9 'src/AmdaParser.cpp',
10 'src/AmdaPlugin.cpp',
10 'src/AmdaPlugin.cpp',
11 'src/AmdaProvider.cpp',
11 'src/AmdaProvider.cpp',
12 'src/AmdaResultParser.cpp',
12 'src/AmdaResultParser.cpp',
13 'src/AmdaResultParserDefs.cpp',
13 'src/AmdaResultParserDefs.cpp',
14 'src/AmdaResultParserHelper.cpp',
14 'src/AmdaResultParserHelper.cpp',
15 'src/AmdaServer.cpp'
15 'src/AmdaServer.cpp'
16 ]
16 ]
17
17
18 amdaplugin_ui_files = []
18 amdaplugin_ui_files = []
19 amdaplugin_resources_files = [
19 amdaplugin_resources_files = [
20 'resources/amdaresources.qrc'
20 'resources/amdaresources.qrc'
21 ]
21 ]
22
22
23 amdaplugin_inc = include_directories(['include', '../../plugin/include'])
23 amdaplugin_inc = include_directories(['include', '../../plugin/include'])
24
24
25 moc_gen = generator(moc,
25 moc_gen = generator(moc,
26 output : 'moc_@BASENAME@.cpp',
26 output : 'moc_@BASENAME@.cpp',
27 arguments : ['@INPUT@',
27 arguments : ['@INPUT@',
28 '-DSCIQLOP_PLUGIN_JSON_FILE_PATH="'+meson.source_root()+'/plugins/amda/resources/amda.json"',
28 '-DSCIQLOP_PLUGIN_JSON_FILE_PATH="'+meson.source_root()+'/plugins/amda/resources/amda.json"',
29 '-I', meson.current_source_dir()+'/include',
29 '-I', meson.current_source_dir()+'/include',
30 '-I', meson.current_source_dir()+'/../../plugin/include',
30 '-I', meson.current_source_dir()+'/../../plugin/include',
31 '-o', '@OUTPUT@'])
31 '-o', '@OUTPUT@'])
32
32
33 rcc_gen = generator(rcc,
33 rcc_gen = generator(rcc,
34 output : 'qrc_@BASENAME@.cpp',
34 output : 'qrc_@BASENAME@.cpp',
35 arguments : ['--name=@BASENAME@"',
35 arguments : ['--name=@BASENAME@"',
36 '--output',
36 '--output',
37 '@OUTPUT@',
37 '@OUTPUT@',
38 '@INPUT@'])
38 '@INPUT@'])
39
39
40 amdaplugin_moc_plugin_files = moc_gen.process(amdaplugin_moc_headers)
40 amdaplugin_moc_plugin_files = moc_gen.process(amdaplugin_moc_headers)
41
41
42 amdaplugin_rcc_plugin_files = rcc_gen.process(amdaplugin_resources_files)
42 amdaplugin_rcc_plugin_files = rcc_gen.process(amdaplugin_resources_files)
43
43
44 #amdaplugin_rcc_plugin_files = qt5.preprocess(
44 #amdaplugin_rcc_plugin_files = qt5.preprocess(
45 # qresources : amdaplugin_resources_files)
45 # qresources : amdaplugin_resources_files)
46
46
47 amdaplugin_moc_files = qt5.preprocess(
47 amdaplugin_moc_files = qt5.preprocess(
48 ui_files : amdaplugin_ui_files)
48 ui_files : amdaplugin_ui_files)
49
49
50 sciqlop_amdaplugin = library('amdaplugin',
50 sciqlop_amdaplugin = library('amdaplugin',
51 amdaplugin_sources,
51 amdaplugin_sources,
52 amdaplugin_moc_files,
52 amdaplugin_moc_files,
53 amdaplugin_rcc_plugin_files,
53 amdaplugin_rcc_plugin_files,
54 amdaplugin_moc_plugin_files,
54 amdaplugin_moc_plugin_files,
55 cpp_args : ['-DAMDA_LIB','-DQT_PLUGIN'],
55 cpp_args : ['-DAMDA_LIB','-DQT_PLUGIN'],
56 include_directories : [amdaplugin_inc],
56 include_directories : [amdaplugin_inc],
57 dependencies : [sciqlop_core, sciqlop_gui],
57 dependencies : [sciqlop_core, sciqlop_gui],
58 install : true
58 install : true
59 )
59 )
60
60
61
61
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']
66 [['tests/TestAmdaFuzzing.cpp'],'test_amda_fuzzing','AMDA fuzzing test']
67 ]
67 ]
68
68
69 tests_sources = [
69 tests_sources = [
70 'tests/FuzzingDefs.h',
70 'tests/FuzzingDefs.h',
71 'tests/FuzzingDefs.cpp',
71 'tests/FuzzingDefs.cpp',
72 'tests/FuzzingOperations.h',
73 'tests/FuzzingOperations.cpp',
72 ]
74 ]
73
75
74 foreach unit_test : tests
76 foreach unit_test : tests
75 test_moc_files = qt5.preprocess(moc_sources : unit_test[0])
77 test_moc_files = qt5.preprocess(moc_sources : unit_test[0])
76 test_exe = executable(unit_test[1],unit_test[0] , test_moc_files,
78 test_exe = executable(unit_test[1],unit_test[0] , test_moc_files,
77 link_with : [sciqlop_amdaplugin],
79 link_with : [sciqlop_amdaplugin],
78 include_directories : [amdaplugin_inc],
80 include_directories : [amdaplugin_inc],
79 cpp_args : ['-DAMDA_TESTS_RESOURCES_DIR="'+meson.current_source_dir()+'/tests-resources"'],
81 cpp_args : ['-DAMDA_TESTS_RESOURCES_DIR="'+meson.current_source_dir()+'/tests-resources"'],
80 sources : [tests_sources],
82 sources : [tests_sources],
81 dependencies : [sciqlop_core, sciqlop_gui, qt5test])
83 dependencies : [sciqlop_core, sciqlop_gui, qt5test])
82 test(unit_test[2], test_exe, args: ['-teamcity', '-o', '@0@.teamcity.txt'.format(unit_test[1])], timeout: 3 * 60)
84 test(unit_test[2], test_exe, args: ['-teamcity', '-o', '@0@.teamcity.txt'.format(unit_test[1])], timeout: 3 * 60)
83 endforeach
85 endforeach
@@ -1,117 +1,123
1 #include "FuzzingDefs.h"
1 #include "FuzzingDefs.h"
2 #include "FuzzingOperations.h"
2 #include <Network/NetworkController.h>
3 #include <Network/NetworkController.h>
3 #include <SqpApplication.h>
4 #include <SqpApplication.h>
4 #include <Time/TimeController.h>
5 #include <Time/TimeController.h>
5 #include <Variable/VariableController.h>
6 #include <Variable/VariableController.h>
6
7
7 #include <QLoggingCategory>
8 #include <QLoggingCategory>
8 #include <QObject>
9 #include <QObject>
9 #include <QtTest>
10 #include <QtTest>
10
11
11 #include <memory>
12 #include <memory>
12
13
13 Q_LOGGING_CATEGORY(LOG_TestAmdaFuzzing, "TestAmdaFuzzing")
14 Q_LOGGING_CATEGORY(LOG_TestAmdaFuzzing, "TestAmdaFuzzing")
14
15
15 namespace {
16 namespace {
16
17
18 // /////// //
19 // Aliases //
20 // /////// //
21
22 using OperationsPool = std::set<std::shared_ptr<IFuzzingOperation> >;
17 // ///////// //
23 // ///////// //
18 // Constants //
24 // Constants //
19 // ///////// //
25 // ///////// //
20
26
21 // Defaults values used when the associated properties have not been set for the test
27 // Defaults values used when the associated properties have not been set for the test
22 const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100;
28 const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100;
23 const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 1;
29 const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 1;
24 /**
30 /**
25 * Class to run random tests
31 * Class to run random tests
26 */
32 */
27 class FuzzingTest {
33 class FuzzingTest {
28 public:
34 public:
29 explicit FuzzingTest(VariableController &variableController, Properties properties)
35 explicit FuzzingTest(VariableController &variableController, Properties properties)
30 : m_VariableController{variableController},
36 : m_VariableController{variableController},
31 m_Properties{std::move(properties)},
37 m_Properties{std::move(properties)},
32 {
38 {
33 }
39 }
34
40
35 void execute()
41 void execute()
36 {
42 {
37 /// @todo: complete
43 /// @todo: complete
38 qCInfo(LOG_TestAmdaFuzzing()) << "Running" << nbMaxOperations() << "operations on"
44 qCInfo(LOG_TestAmdaFuzzing()) << "Running" << nbMaxOperations() << "operations on"
39 << nbMaxVariables() << "variables...";
45 << nbMaxVariables() << "variables...";
40
46
41 qCInfo(LOG_TestAmdaFuzzing()) << "Execution of the test completed.";
47 qCInfo(LOG_TestAmdaFuzzing()) << "Execution of the test completed.";
42 }
48 }
43
49
44 private:
50 private:
45 int nbMaxOperations() const
51 int nbMaxOperations() const
46 {
52 {
47 static auto result
53 static auto result
48 = m_Properties.value(NB_MAX_OPERATIONS_PROPERTY, NB_MAX_OPERATIONS_DEFAULT_VALUE)
54 = m_Properties.value(NB_MAX_OPERATIONS_PROPERTY, NB_MAX_OPERATIONS_DEFAULT_VALUE)
49 .toInt();
55 .toInt();
50 return result;
56 return result;
51 }
57 }
52
58
53 int nbMaxVariables() const
59 int nbMaxVariables() const
54 {
60 {
55 static auto result
61 static auto result
56 = m_Properties.value(NB_MAX_VARIABLES_PROPERTY, NB_MAX_VARIABLES_DEFAULT_VALUE).toInt();
62 = m_Properties.value(NB_MAX_VARIABLES_PROPERTY, NB_MAX_VARIABLES_DEFAULT_VALUE).toInt();
57 return result;
63 return result;
58 }
64 }
59
65
60 VariableController &m_VariableController;
66 VariableController &m_VariableController;
61 Properties m_Properties;
67 Properties m_Properties;
62 };
68 };
63
69
64 } // namespace
70 } // namespace
65
71
66 class TestAmdaFuzzing : public QObject {
72 class TestAmdaFuzzing : public QObject {
67 Q_OBJECT
73 Q_OBJECT
68
74
69 private slots:
75 private slots:
70 /// Input data for @sa testFuzzing()
76 /// Input data for @sa testFuzzing()
71 void testFuzzing_data();
77 void testFuzzing_data();
72 void testFuzzing();
78 void testFuzzing();
73 };
79 };
74
80
75 void TestAmdaFuzzing::testFuzzing_data()
81 void TestAmdaFuzzing::testFuzzing_data()
76 {
82 {
77 // ////////////// //
83 // ////////////// //
78 // Test structure //
84 // Test structure //
79 // ////////////// //
85 // ////////////// //
80
86
81 QTest::addColumn<Properties>("properties"); // Properties for random test
87 QTest::addColumn<Properties>("properties"); // Properties for random test
82
88
83 // ////////// //
89 // ////////// //
84 // Test cases //
90 // Test cases //
85 // ////////// //
91 // ////////// //
86
92
87 ///@todo: complete
93 ///@todo: complete
88 }
94 }
89
95
90 void TestAmdaFuzzing::testFuzzing()
96 void TestAmdaFuzzing::testFuzzing()
91 {
97 {
92 QFETCH(Properties, properties);
98 QFETCH(Properties, properties);
93
99
94 auto &variableController = sqpApp->variableController();
100 auto &variableController = sqpApp->variableController();
95 auto &timeController = sqpApp->timeController();
101 auto &timeController = sqpApp->timeController();
96
102
97 FuzzingTest test{variableController, properties};
103 FuzzingTest test{variableController, properties};
98 test.execute();
104 test.execute();
99 }
105 }
100
106
101 int main(int argc, char *argv[])
107 int main(int argc, char *argv[])
102 {
108 {
103 QLoggingCategory::setFilterRules(
109 QLoggingCategory::setFilterRules(
104 "*.warning=false\n"
110 "*.warning=false\n"
105 "*.info=false\n"
111 "*.info=false\n"
106 "*.debug=false\n"
112 "*.debug=false\n"
107 "FuzzingOperations.info=true\n"
113 "FuzzingOperations.info=true\n"
108 "TestAmdaFuzzing.info=true\n");
114 "TestAmdaFuzzing.info=true\n");
109
115
110 SqpApplication app{argc, argv};
116 SqpApplication app{argc, argv};
111 app.setAttribute(Qt::AA_Use96Dpi, true);
117 app.setAttribute(Qt::AA_Use96Dpi, true);
112 TestAmdaFuzzing testObject{};
118 TestAmdaFuzzing testObject{};
113 QTEST_SET_MAIN_SOURCE_PATH
119 QTEST_SET_MAIN_SOURCE_PATH
114 return QTest::qExec(&testObject, argc, argv);
120 return QTest::qExec(&testObject, argc, argv);
115 }
121 }
116
122
117 #include "TestAmdaFuzzing.moc"
123 #include "TestAmdaFuzzing.moc"
General Comments 0
You need to be logged in to leave comments. Login now