Implement integration tests for fields with set and notifier#463
Implement integration tests for fields with set and notifier#463sahithi-nukala wants to merge 7 commits into
Conversation
8306eb3 to
38982b6
Compare
7bd4c90 to
a4435a5
Compare
0e981e5 to
5496cf0
Compare
5496cf0 to
4039570
Compare
There was a problem hiding this comment.
We usually consumer / provider instead of client / service. Could you please follow the same naming convention?
| using Parameters = score::mw::com::test::SctfTestRunner::RunParameters::Parameters; | ||
|
|
||
| const std::vector<Parameters> allowed_parameters{Parameters::CYCLE_TIME, Parameters::MODE}; | ||
| score::mw::com::test::SctfTestRunner test_runner(argc, argv, allowed_parameters); |
There was a problem hiding this comment.
SctfTestRunner is very old and we don't use it for new tests. Please look at how we do config parsing here: https://github.com/eclipse-score/communication/blob/brem_methods_sctfs/score/mw/com/test/methods/multiple_proxies/main_provider.cpp
|
|
||
| const std::vector<Parameters> allowed_parameters{Parameters::CYCLE_TIME, Parameters::MODE}; | ||
| score::mw::com::test::SctfTestRunner test_runner(argc, argv, allowed_parameters); | ||
| const auto& run_parameters = test_runner.GetRunParameters(); |
There was a problem hiding this comment.
Need to register a sig term handler like in https://github.com/eclipse-score/communication/blob/brem_methods_sctfs/score/mw/com/test/methods/multiple_proxies/main_provider.cpp
| return -17; | ||
| } | ||
|
|
||
| while (!stop_token.stop_requested()) |
There was a problem hiding this comment.
Use ProcessSynchronizer instead of a loop on the stop token like in
| } | ||
| auto instance_specifier = std::move(instance_specifier_result).value(); | ||
|
|
||
| auto service_result = SetEnabledSkeleton::Create(std::move(instance_specifier)); |
There was a problem hiding this comment.
Use SkeletonContainer instead of doing this yourself
|
|
||
| while (!stop_token.stop_requested()) | ||
| { | ||
| std::this_thread::sleep_for(cycle_time); |
There was a problem hiding this comment.
We don't need cycle_time to be passed in from python, we only want to pass in params that need to be changed when calling the binary from python (e.g. mode). Anyway, this won't be needed when using ProcessSynchronizer.
| if (!instance_specifier_result.has_value()) | ||
| { | ||
| std::cerr << "Unable to create instance specifier, terminating\n"; | ||
| return -3; |
There was a problem hiding this comment.
Instead of returning error codes and propagating this up through all the layers, we should instead use FailTest to immediately fail the test e.g.
There was a problem hiding this comment.
Same applies for the consumer
| auto instance_specifier = std::move(instance_specifier_result).value(); | ||
|
|
||
| std::promise<std::vector<InitialOnlyProxy::HandleType>> service_discovery_promise{}; | ||
| auto service_discovery_future = service_discovery_promise.get_future(); |
| }; | ||
|
|
||
| template <typename T> | ||
| class SetEnabledInterface : public T::Base |
There was a problem hiding this comment.
We should have one class per file.
| namespace score::mw::com::test | ||
| { | ||
|
|
||
| constexpr const char* const kInstanceSpecifierString = "test/fields/set_and_notifier"; |
There was a problem hiding this comment.
The shared constants should be in a different file, not with the interface classes.
| return target.wrap_exec("bin/main_service", args, cwd="/opt/MainServiceApp", **kwargs) | ||
|
|
||
|
|
||
| def test_field_notifier_initial_value(target): |
There was a problem hiding this comment.
We should have different python files per test configuration (e.g. https://github.com/eclipse-score/communication/tree/f6a14ef6f69482b404ec9392067fdd67c5126d51/score/mw/com/test/methods/mixed_criticality/integration_test). The configurations needed are mentioned in the ticket.
There was a problem hiding this comment.
Separate files per configuration have been added for 2 cases from the ticket. and for the 4 configurations requiring getter support (test_get.py, test_get_and_notifier.py, test_set_and_get.py, test_set_get_and_notifier.py)
655b99c to
e177601
Compare
39f0cd4 to
02408e2
Compare
| @@ -0,0 +1,33 @@ | |||
| /******************************************************************************* | |||
There was a problem hiding this comment.
all header files should have a corresponding cpp file, even if it's empty.
| public: | ||
| using T::Base::Base; | ||
|
|
||
| typename T::template Field<std::int32_t> test_field{*this, "test_field"}; |
There was a problem hiding this comment.
name it something like initial_only_field so it doesn't have the same name as the other field.
There was a problem hiding this comment.
We then would also need a differenet configuration file per test.
| public: | ||
| using T::Base::Base; | ||
|
|
||
| typename T::template Field<std::int32_t, false, true> test_field{*this, "test_field"}; |
There was a problem hiding this comment.
Name it set_enabled_field
| typename T::template Field<std::int32_t, false, true> test_field{*this, "test_field"}; | ||
| }; | ||
|
|
||
| using InitialOnlyProxy = score::mw::com::AsProxy<InitialOnlyInterface>; |
There was a problem hiding this comment.
This file should be removed and these aliases should go in the relevant interface files
|
|
||
| const std::string kInterprocessNotificationShmPath{"/field_initial_value_interprocess_notification"}; | ||
|
|
||
| int run_client(const std::size_t num_retries, const std::chrono::milliseconds retry_backoff_time) |
There was a problem hiding this comment.
Also use FailTest in this file and run_client should return void?
| run_notifier_consumer(num_retries, retry_backoff_time); | ||
| return; | ||
| } | ||
| if (mode == "set") |
There was a problem hiding this comment.
This should be set_and_notifier?
|
|
||
| auto& service = skeleton_container.GetSkeleton(); | ||
| const auto register_handler_result = service.test_field.RegisterSetHandler([](std::int32_t& value) noexcept { | ||
| if (value > kSetAcceptedValue) |
There was a problem hiding this comment.
I think that instead of doing clamping, we can simply have the set handler do some constant transformation, e.g. value * a + b; We can then check on proxy side that the value was transformed as expected. It means that we don't have to do 2 method calls.
There was a problem hiding this comment.
i replaced the clamping logic with a transformation ([value * 2 + 1] in the set handler. this way the consumer only needs to make one set call - it sends [kSetRequestValue] and checks that the received notification equals [kSetRequestValue * 2 + 1].
There was a problem hiding this comment.
mains should have main_ prefix
| constexpr auto kModeArg = "mode"; | ||
| constexpr auto kServiceInstanceManifestArg = "service-instance-manifest"; | ||
|
|
||
| const std::vector<std::pair<std::string, std::string>> parameter_description_pairs{ |
There was a problem hiding this comment.
please extract config parsing into a function like in the tests I sent you
| ], | ||
| ) | ||
|
|
||
| cc_library( |
There was a problem hiding this comment.
If this is now used not just in fields, it should be moved to common resources folder which is accessible by both. e.g. https://github.com/eclipse-score/communication/tree/main/score/mw/com/test/common_test_resources
There was a problem hiding this comment.
moved the process_synchronizer target to common_test_resources
7a0e916 to
02408e2
Compare
…on_test_resources
02408e2 to
0b7a081
Compare
Uh oh!
There was an error while loading. Please reload this page.