From 56f910714c1736fd745ec960c7ccecf255fef63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez?= Date: Tue, 1 Jun 2021 11:10:14 +0200 Subject: [PATCH] Explicitly enable/disable datasharing on Throughtput test [11646] (#1987) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refs #11645. Add new enabler option Signed-off-by: Ricardo González Moreno * Refs #11645. Fix compilation error Signed-off-by: Ricardo González Moreno * Refs #11645. Add enable/disable shared memory Signed-off-by: Ricardo González Moreno * Apply suggestions from code review Co-authored-by: Miguel Company * Refs #11645. Fix error in latency tests * Refs #11645. Fix errors in CI Co-authored-by: Miguel Company --- test/performance/latency/CMakeLists.txt | 4 +- .../latency/LatencyTestPublisher.cpp | 38 +++++- .../latency/LatencyTestPublisher.hpp | 8 +- .../latency/LatencyTestSubscriber.cpp | 38 +++++- .../latency/LatencyTestSubscriber.hpp | 8 +- test/performance/latency/latency_tests.py | 33 +++-- test/performance/latency/main_LatencyTest.cpp | 123 +++++------------- test/performance/optionarg.hpp | 115 ++++++++++++++++ test/performance/throughput/CMakeLists.txt | 4 +- .../throughput/ThroughputPublisher.cpp | 33 ++++- .../throughput/ThroughputPublisher.hpp | 8 +- .../throughput/ThroughputSubscriber.cpp | 35 ++++- .../throughput/ThroughputSubscriber.hpp | 8 +- .../throughput/main_ThroughputTest.cpp | 120 +++++------------ .../throughput/throughput_tests.py | 34 +++-- 15 files changed, 387 insertions(+), 222 deletions(-) create mode 100644 test/performance/optionarg.hpp diff --git a/test/performance/latency/CMakeLists.txt b/test/performance/latency/CMakeLists.txt index 989771bdcff..b5010ad8fe3 100644 --- a/test/performance/latency/CMakeLists.txt +++ b/test/performance/latency/CMakeLists.txt @@ -199,7 +199,7 @@ if(PYTHONINTERP_FOUND) --xml_file ${CMAKE_CURRENT_SOURCE_DIR}/xml/${latency_test_name}.xml --demands_file ${CMAKE_CURRENT_SOURCE_DIR}/payloads_demands.csv ${interproces_flag} - --data_sharing + --data_sharing=on ${reliability_flag} ) @@ -267,7 +267,7 @@ if(PYTHONINTERP_FOUND) --demands_file ${CMAKE_CURRENT_SOURCE_DIR}/payloads_demands.csv ${interproces_flag} --data_loans - --data_sharing + --data_sharing=on ${reliability_flag} ) diff --git a/test/performance/latency/LatencyTestPublisher.cpp b/test/performance/latency/LatencyTestPublisher.cpp index a57b3cf5d3b..64ed2aca633 100644 --- a/test/performance/latency/LatencyTestPublisher.cpp +++ b/test/performance/latency/LatencyTestPublisher.cpp @@ -33,6 +33,8 @@ #include #include #include +#include +#include #define TIME_LIMIT_US 10000 @@ -96,8 +98,9 @@ bool LatencyTestPublisher::init( const PropertyPolicy& property_policy, const std::string& xml_config_file, bool dynamic_data, - bool data_sharing, + Arg::EnablerValue data_sharing, bool data_loans, + Arg::EnablerValue shared_memory, int forced_domain, LatencyDataSizes& latency_data_sizes) { @@ -111,6 +114,7 @@ bool LatencyTestPublisher::init( dynamic_types_ = dynamic_data; data_sharing_ = data_sharing; data_loans_ = data_loans; + shared_memory_ = shared_memory; forced_domain_ = forced_domain; raw_data_file_ = raw_data_file; pid_ = pid; @@ -185,6 +189,25 @@ bool LatencyTestPublisher::init( pqos.properties(part_property_policy); } + // Set shared memory transport if it was enable/disable explicitly. + if (Arg::EnablerValue::ON == shared_memory_) + { + std::shared_ptr shm_transport = + std::make_shared(); + std::shared_ptr udp_transport = + std::make_shared(); + pqos.transport().user_transports.push_back(shm_transport); + pqos.transport().user_transports.push_back(udp_transport); + pqos.transport().use_builtin_transports = false; + } + else if (Arg::EnablerValue::OFF == shared_memory_) + { + std::shared_ptr udp_transport = + std::make_shared(); + pqos.transport().user_transports.push_back(udp_transport); + pqos.transport().use_builtin_transports = false; + } + // Create the participant participant_ = DomainParticipantFactory::get_instance()->create_participant(domainId, pqos); @@ -265,17 +288,20 @@ bool LatencyTestPublisher::init( } // Set data sharing according with cli. - DataSharingQosPolicy dsp; - if (data_sharing_) + if (Arg::EnablerValue::ON == data_sharing_) { + DataSharingQosPolicy dsp; dsp.on(""); + dw_qos_.data_sharing(dsp); + dr_qos_.data_sharing(dsp); } - else + else if (Arg::EnablerValue::OFF == data_sharing_) { + DataSharingQosPolicy dsp; dsp.off(); + dw_qos_.data_sharing(dsp); + dr_qos_.data_sharing(dsp); } - dw_qos_.data_sharing(dsp); - dr_qos_.data_sharing(dsp); // Increase payload pool size to prevent loan failures due to outages if (data_loans_) diff --git a/test/performance/latency/LatencyTestPublisher.hpp b/test/performance/latency/LatencyTestPublisher.hpp index fa74c2861f1..9d68cac2ee0 100644 --- a/test/performance/latency/LatencyTestPublisher.hpp +++ b/test/performance/latency/LatencyTestPublisher.hpp @@ -41,6 +41,8 @@ #include #include "LatencyTestTypes.hpp" +#include "../optionarg.hpp" + class TimeStats { public: @@ -97,8 +99,9 @@ class LatencyTestPublisher const eprosima::fastrtps::rtps::PropertyPolicy& property_policy, const std::string& xml_config_file, bool dynamic_data, - bool data_sharing, + Arg::EnablerValue data_sharing, bool data_loans, + Arg::EnablerValue shared_memory, int forced_domain, LatencyDataSizes& latency_data_sizes); @@ -199,8 +202,9 @@ class LatencyTestPublisher bool export_csv_ = false; bool reliable_ = false; bool dynamic_types_ = false; - bool data_sharing_ = false; + Arg::EnablerValue data_sharing_ = Arg::EnablerValue::NO_SET; bool data_loans_ = false; + Arg::EnablerValue shared_memory_ = Arg::EnablerValue::NO_SET; int forced_domain_ = -1; int subscribers_ = 0; unsigned int samples_ = 0; diff --git a/test/performance/latency/LatencyTestSubscriber.cpp b/test/performance/latency/LatencyTestSubscriber.cpp index 8266e76bfaa..1cde228a424 100644 --- a/test/performance/latency/LatencyTestSubscriber.cpp +++ b/test/performance/latency/LatencyTestSubscriber.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include using namespace eprosima::fastrtps::rtps; using namespace eprosima::fastrtps::types; @@ -85,8 +87,9 @@ bool LatencyTestSubscriber::init( const PropertyPolicy& property_policy, const std::string& xml_config_file, bool dynamic_data, - bool data_sharing, + Arg::EnablerValue data_sharing, bool data_loans, + Arg::EnablerValue shared_memory, int forced_domain, LatencyDataSizes& latency_data_sizes) { @@ -97,6 +100,7 @@ bool LatencyTestSubscriber::init( dynamic_types_ = dynamic_data; data_sharing_ = data_sharing; data_loans_ = data_loans; + shared_memory_ = shared_memory; forced_domain_ = forced_domain; pid_ = pid; hostname_ = hostname; @@ -139,6 +143,25 @@ bool LatencyTestSubscriber::init( pqos.properties(part_property_policy); } + // Set shared memory transport if it was enable/disable explicitly. + if (Arg::EnablerValue::ON == shared_memory_) + { + std::shared_ptr shm_transport = + std::make_shared(); + std::shared_ptr udp_transport = + std::make_shared(); + pqos.transport().user_transports.push_back(shm_transport); + pqos.transport().user_transports.push_back(udp_transport); + pqos.transport().use_builtin_transports = false; + } + else if (Arg::EnablerValue::OFF == shared_memory_) + { + std::shared_ptr udp_transport = + std::make_shared(); + pqos.transport().user_transports.push_back(udp_transport); + pqos.transport().use_builtin_transports = false; + } + // Create the participant participant_ = DomainParticipantFactory::get_instance()->create_participant(domainId, pqos); if (participant_ == nullptr) @@ -217,17 +240,20 @@ bool LatencyTestSubscriber::init( } // Set data sharing according with cli. - DataSharingQosPolicy dsp; - if (data_sharing_) + if (Arg::EnablerValue::ON == data_sharing_) { + DataSharingQosPolicy dsp; dsp.on(""); + dw_qos_.data_sharing(dsp); + dr_qos_.data_sharing(dsp); } - else + else if (Arg::EnablerValue::OFF == data_sharing_) { + DataSharingQosPolicy dsp; dsp.off(); + dw_qos_.data_sharing(dsp); + dr_qos_.data_sharing(dsp); } - dw_qos_.data_sharing(dsp); - dr_qos_.data_sharing(dsp); // Increase payload pool size to prevent loan failures due to outages if (data_loans_) diff --git a/test/performance/latency/LatencyTestSubscriber.hpp b/test/performance/latency/LatencyTestSubscriber.hpp index 6957d338b85..958f7e94cbc 100644 --- a/test/performance/latency/LatencyTestSubscriber.hpp +++ b/test/performance/latency/LatencyTestSubscriber.hpp @@ -40,6 +40,8 @@ #include #include "LatencyTestTypes.hpp" +#include "../optionarg.hpp" + class LatencyTestSubscriber { public: @@ -58,8 +60,9 @@ class LatencyTestSubscriber const eprosima::fastrtps::rtps::PropertyPolicy& property_policy, const std::string& xml_config_file, bool dynamic_data, - bool data_sharing, + Arg::EnablerValue data_sharing, bool data_loans, + Arg::EnablerValue shared_memory, int forced_domain, LatencyDataSizes& latency_data_sizes); @@ -128,8 +131,9 @@ class LatencyTestSubscriber bool echo_ = true; int samples_ = 0; bool dynamic_types_ = false; - bool data_sharing_ = false; + Arg::EnablerValue data_sharing_ = Arg::EnablerValue::NO_SET; bool data_loans_ = false; + Arg::EnablerValue shared_memory_ = Arg::EnablerValue::NO_SET; int forced_domain_ = -1; bool hostname_ = false; uint32_t pid_ = 0; diff --git a/test/performance/latency/latency_tests.py b/test/performance/latency/latency_tests.py index 3121385be8f..1a5e5ac1646 100644 --- a/test/performance/latency/latency_tests.py +++ b/test/performance/latency/latency_tests.py @@ -52,29 +52,35 @@ '--interprocess', action='store_true', help='Publisher and subscribers in separate processes. Defaults:False', - required=False, + required=False ) parser.add_argument( '-d', '--data_sharing', - action='store_true', - help='Enable data sharing (Defaults: disable)', - required=False, + choices=['on', 'off'], + help='Explicitly enable/disable data sharing. (Defaults: Fast-DDS default settings)', + required=False ) parser.add_argument( '-l', '--data_loans', action='store_true', help='Enable the use of the loan sample API (Defaults: disable)', - required=False, + required=False ) parser.add_argument( '-r', '--reliability', action='store_true', help='Run with RELIABLE reliability (Defaults: disable)', - required=False, + required=False ) + parser.add_argument( + '--shared_memory', + choices=['on', 'off'], + help='Explicitly enable/disable shared memory transport. (Defaults: Fast-DDS default settings)', + required=False + ) # Parse arguments args = parser.parse_args() @@ -125,9 +131,9 @@ # Data sharing and loans options # modify output file names - if args.data_sharing and args.data_loans: + if args.data_sharing and 'on' == args.data_sharing and args.data_loans: filename_options += '_data_loans_and_sharing' - elif args.data_sharing: + elif args.data_sharing and 'on' == args.data_sharing: filename_options += '_data_sharing' elif args.data_loans: filename_options += '_data_loans' @@ -136,7 +142,10 @@ data_options = [] if args.data_sharing: - data_options += ['--data_sharing'] + if 'on' == args.data_sharing: + data_options += ['--data_sharing=on'] + else: + data_options += ['--data_sharing=off'] if args.data_loans: data_options += ['--data_loans'] @@ -147,6 +156,12 @@ else: reliability_options = ['--reliability=besteffort'] + if args.shared_memory: + if 'on' == args.shared_memory: + data_options += ['--shared_memory=on'] + else: + data_options += ['--shared_memory=off'] + # Environment variables executable = os.environ.get('LATENCY_TEST_BIN') certs_path = os.environ.get('CERTS_PATH') diff --git a/test/performance/latency/main_LatencyTest.cpp b/test/performance/latency/main_LatencyTest.cpp index 4120f88e6d9..857c9b2257d 100644 --- a/test/performance/latency/main_LatencyTest.cpp +++ b/test/performance/latency/main_LatencyTest.cpp @@ -14,7 +14,7 @@ #include "LatencyTestPublisher.hpp" #include "LatencyTestSubscriber.hpp" -#include "../optionparser.h" +#include "../optionarg.hpp" #include #include @@ -44,83 +44,6 @@ using namespace eprosima::fastrtps::rtps; #define COPYSTR strcpy #endif // if defined(_WIN32) - -struct Arg : public option::Arg -{ - static void printError( - const char* msg1, - const option::Option& opt, - const char* msg2) - { - fprintf(stderr, "%s", msg1); - fwrite(opt.name, opt.namelen, 1, stderr); - fprintf(stderr, "%s", msg2); - } - - static option::ArgStatus Unknown( - const option::Option& option, - bool msg) - { - if (msg) - { - printError("Unknown option '", option, "'\n"); - } - return option::ARG_ILLEGAL; - } - - static option::ArgStatus Required( - const option::Option& option, - bool msg) - { - if (option.arg != 0 && option.arg[0] != 0) - { - return option::ARG_OK; - } - - if (msg) - { - printError("Option '", option, "' requires an argument\n"); - } - return option::ARG_ILLEGAL; - } - - static option::ArgStatus Numeric( - const option::Option& option, - bool msg) - { - char* endptr = 0; - if (option.arg != 0 && strtol(option.arg, &endptr, 10)) - { - } - if (endptr != option.arg && *endptr == 0) - { - return option::ARG_OK; - } - - if (msg) - { - printError("Option '", option, "' requires a numeric argument\n"); - } - return option::ARG_ILLEGAL; - } - - static option::ArgStatus String( - const option::Option& option, - bool msg) - { - if (option.arg != 0) - { - return option::ARG_OK; - } - if (msg) - { - printError("Option '", option, "' requires a numeric argument\n"); - } - return option::ARG_ILLEGAL; - } - -}; - enum optionIndex { UNKNOWN_OPT, @@ -141,7 +64,8 @@ enum optionIndex FORCED_DOMAIN, FILE_R, DATA_SHARING, - DATA_LOAN + DATA_LOAN, + SHARED_MEMORY }; enum TestAgent @@ -193,10 +117,12 @@ const option::Descriptor usage[] = { " -e , --echo= Echo mode (\"true\"/\"false\")." }, { FILE_R, 0, "f", "file", Arg::Required, " -f , --file= File to read the payload demands from." }, - { DATA_SHARING, 0, "d", "data_sharing", Arg::None, - " --data_sharing Enable data sharing feature." }, + { DATA_SHARING, 0, "d", "data_sharing", Arg::Enabler, + " --data_sharing=[on|off] Explicitly enable/disable data sharing feature." }, { DATA_LOAN, 0, "l", "data_loans", Arg::None, " --data_loans Use loan sample API." }, + { SHARED_MEMORY, 0, "", "shared_memory", Arg::Enabler, + " --shared_memory=[on|off] Explicitly enable/disable shared memory transport." }, { 0, 0, 0, 0, 0, 0 } }; @@ -301,8 +227,9 @@ int main( bool dynamic_types = false; int forced_domain = -1; std::string demands_file = ""; - bool data_sharing = false; + Arg::EnablerValue data_sharing = Arg::EnablerValue::NO_SET; bool data_loans = false; + Arg::EnablerValue shared_memory = Arg::EnablerValue::NO_SET; argc -= (argc > 0); argv += (argc > 0); // skip program name argv[0] if present @@ -457,11 +384,29 @@ int main( demands_file = opt.arg; break; case DATA_SHARING: - data_sharing = true; + if (0 == strncasecmp(opt.arg, "on", 2)) + { + data_sharing = Arg::EnablerValue::ON; + } + else + { + data_sharing = Arg::EnablerValue::OFF; + } + break; break; case DATA_LOAN: data_loans = true; break; + case SHARED_MEMORY: + if (0 == strncasecmp(opt.arg, "on", 2)) + { + shared_memory = Arg::EnablerValue::ON; + } + else + { + shared_memory = Arg::EnablerValue::OFF; + } + break; case UNKNOWN_OPT: default: option::printUsage(fwrite, stdout, usage, columns); @@ -479,7 +424,7 @@ int main( logError(LatencyTest, "Intra-process delivery NOT supported with security"); return 1; } - else if (data_sharing) + else if (Arg::EnablerValue::ON == data_sharing) { logError(LatencyTest, "Sharing sample APIs NOT supported with RTPS encryption"); return 1; @@ -487,7 +432,7 @@ int main( } #endif // if HAVE_SECURITY - if ((data_sharing || data_loans) && dynamic_types) + if ((Arg::EnablerValue::ON == data_sharing || data_loans) && dynamic_types) { logError(LatencyTest, "Sharing sample APIs NOT supported with dynamic types"); return 1; @@ -556,7 +501,7 @@ int main( LatencyTestPublisher latency_publisher; if (latency_publisher.init(subscribers, samples, reliable, seed, hostname, export_csv, export_prefix, raw_data_file, pub_part_property_policy, pub_property_policy, xml_config_file, - dynamic_types, data_sharing, data_loans, forced_domain, data_sizes)) + dynamic_types, data_sharing, data_loans, shared_memory, forced_domain, data_sizes)) { latency_publisher.run(); } @@ -571,7 +516,7 @@ int main( LatencyTestSubscriber latency_subscriber; if (latency_subscriber.init(echo, samples, reliable, seed, hostname, sub_part_property_policy, sub_property_policy, - xml_config_file, dynamic_types, data_sharing, data_loans, forced_domain, data_sizes)) + xml_config_file, dynamic_types, data_sharing, data_loans, shared_memory, forced_domain, data_sizes)) { latency_subscriber.run(); } @@ -590,7 +535,8 @@ int main( LatencyTestPublisher latency_publisher; bool pub_init = latency_publisher.init(subscribers, samples, reliable, seed, hostname, export_csv, export_prefix, raw_data_file, pub_part_property_policy, pub_property_policy, - xml_config_file, dynamic_types, data_sharing, data_loans, forced_domain, data_sizes); + xml_config_file, dynamic_types, data_sharing, data_loans, shared_memory, forced_domain, + data_sizes); // Initialize subscribers std::vector> latency_subscribers; @@ -602,6 +548,7 @@ int main( sub_init &= latency_subscribers.back()->init(echo, samples, reliable, seed, hostname, sub_part_property_policy, sub_property_policy, xml_config_file, dynamic_types, data_sharing, data_loans, + shared_memory, forced_domain, data_sizes); } diff --git a/test/performance/optionarg.hpp b/test/performance/optionarg.hpp new file mode 100644 index 00000000000..f74eaf97599 --- /dev/null +++ b/test/performance/optionarg.hpp @@ -0,0 +1,115 @@ +#ifndef _TEST_PERFORMANCE_OPTIONARG_HPP_ +#define _TEST_PERFORMANCE_OPTIONARG_HPP_ + +#include "optionparser.h" + +#include +#include +#include +#include + +#ifdef WIN32 +#define strncasecmp _strnicmp +#endif // ifdef WIN32 + +struct Arg : public option::Arg +{ + enum class EnablerValue : int32_t + { + NO_SET, + ON, + OFF + }; + + static void print_error( + const char* msg1, + const option::Option& opt, + const char* msg2) + { + fprintf(stderr, "%s", msg1); + fwrite(opt.name, opt.namelen, 1, stderr); + fprintf(stderr, "%s", msg2); + } + + static option::ArgStatus Unknown( + const option::Option& option, + bool msg) + { + if (msg) + { + print_error("Unknown option '", option, "'\n"); + } + return option::ARG_ILLEGAL; + } + + static option::ArgStatus Required( + const option::Option& option, + bool msg) + { + if (option.arg != 0 && option.arg[0] != 0) + { + return option::ARG_OK; + } + + if (msg) + { + print_error("Option '", option, "' requires an argument\n"); + } + return option::ARG_ILLEGAL; + } + + static option::ArgStatus Numeric( + const option::Option& option, + bool msg) + { + char* endptr = 0; + if (option.arg != 0 && strtol(option.arg, &endptr, 10)) + { + } + if (endptr != option.arg && *endptr == 0) + { + return option::ARG_OK; + } + + if (msg) + { + print_error("Option '", option, "' requires a numeric argument\n"); + } + return option::ARG_ILLEGAL; + } + + static option::ArgStatus String( + const option::Option& option, + bool msg) + { + if (option.arg != 0) + { + return option::ARG_OK; + } + if (msg) + { + print_error("Option '", option, "' requires a numeric argument\n"); + } + return option::ARG_ILLEGAL; + } + + static option::ArgStatus Enabler( + const option::Option& option, + bool msg) + { + if (nullptr == option.arg || + (0 == strncasecmp(option.arg, "on", 2) || + 0 == strncasecmp(option.arg, "off", 3))) + { + return option::ARG_OK; + } + if (msg) + { + print_error("Option '", option, "' supports values 'on' or 'off'\n"); + } + return option::ARG_ILLEGAL; + } + +}; + +#endif // _TEST_PERFORMANCE_OPTIONARG_HPP_ diff --git a/test/performance/throughput/CMakeLists.txt b/test/performance/throughput/CMakeLists.txt index b9101db487e..d778f5c25db 100644 --- a/test/performance/throughput/CMakeLists.txt +++ b/test/performance/throughput/CMakeLists.txt @@ -198,7 +198,7 @@ if(PYTHONINTERP_FOUND) --xml_file ${CMAKE_CURRENT_SOURCE_DIR}/xml/${throughput_test_name}.xml --recoveries_file ${CMAKE_CURRENT_SOURCE_DIR}/recoveries.csv --demands_file ${CMAKE_CURRENT_SOURCE_DIR}/payloads_demands.csv - --data_sharing + --data_sharing=on ${interproces_flag} ${reliability_flag} ) @@ -265,7 +265,7 @@ if(PYTHONINTERP_FOUND) --recoveries_file ${CMAKE_CURRENT_SOURCE_DIR}/recoveries.csv --demands_file ${CMAKE_CURRENT_SOURCE_DIR}/payloads_demands.csv --data_loans - --data_sharing + --data_sharing=on ${interproces_flag} ${reliability_flag} ) diff --git a/test/performance/throughput/ThroughputPublisher.cpp b/test/performance/throughput/ThroughputPublisher.cpp index 134b35d5842..eaf48076e1f 100644 --- a/test/performance/throughput/ThroughputPublisher.cpp +++ b/test/performance/throughput/ThroughputPublisher.cpp @@ -33,6 +33,8 @@ #include #include #include +#include +#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; @@ -120,8 +122,9 @@ bool ThroughputPublisher::init( const std::string& demands_file, const std::string& recoveries_file, bool dynamic_types, - bool data_sharing, + Arg::EnablerValue data_sharing, bool data_loans, + Arg::EnablerValue shared_memory, int forced_domain) { pid_ = pid; @@ -129,6 +132,7 @@ bool ThroughputPublisher::init( dynamic_types_ = dynamic_types; data_sharing_ = data_sharing; data_loans_ = data_loans; + shared_memory_ = shared_memory; reliable_ = reliable; forced_domain_ = forced_domain; demands_file_ = demands_file; @@ -172,6 +176,25 @@ bool ThroughputPublisher::init( pqos.properties(part_property_policy); } + // Set shared memory transport if it was enable/disable explicitly. + if (Arg::EnablerValue::ON == shared_memory_) + { + std::shared_ptr shm_transport = + std::make_shared(); + std::shared_ptr udp_transport = + std::make_shared(); + pqos.transport().user_transports.push_back(shm_transport); + pqos.transport().user_transports.push_back(udp_transport); + pqos.transport().use_builtin_transports = false; + } + else if (Arg::EnablerValue::OFF == shared_memory_) + { + std::shared_ptr udp_transport = + std::make_shared(); + pqos.transport().user_transports.push_back(udp_transport); + pqos.transport().use_builtin_transports = false; + } + // Create the participant participant_ = DomainParticipantFactory::get_instance()->create_participant(domainId, pqos); @@ -245,12 +268,18 @@ bool ThroughputPublisher::init( } // Set data sharing according with cli. Is disabled by default in all xml profiles - if (data_sharing_) + if (Arg::EnablerValue::ON == data_sharing_) { DataSharingQosPolicy dsp; dsp.on(""); dw_qos_.data_sharing(dsp); } + else if (Arg::EnablerValue::OFF == data_sharing_) + { + DataSharingQosPolicy dsp; + dsp.off(); + dw_qos_.data_sharing(dsp); + } // Create Command topic { diff --git a/test/performance/throughput/ThroughputPublisher.hpp b/test/performance/throughput/ThroughputPublisher.hpp index b2937f8cbb0..d9cd89f48b3 100644 --- a/test/performance/throughput/ThroughputPublisher.hpp +++ b/test/performance/throughput/ThroughputPublisher.hpp @@ -47,6 +47,8 @@ #include #include "ThroughputTypes.hpp" +#include "../optionarg.hpp" + class ThroughputPublisher { public: @@ -64,8 +66,9 @@ class ThroughputPublisher const std::string& demands_file, const std::string& recoveries_file, bool dynamic_types, - bool data_sharing, + Arg::EnablerValue data_sharing, bool data_loans, + Arg::EnablerValue shared_memory, int forced_domain); ~ThroughputPublisher(); @@ -142,8 +145,9 @@ class ThroughputPublisher // Flags bool dynamic_types_ = false; - bool data_sharing_ = false; + Arg::EnablerValue data_sharing_ = Arg::EnablerValue::NO_SET; bool data_loans_ = false; + Arg::EnablerValue shared_memory_ = Arg::EnablerValue::NO_SET; bool ready_ = true; bool reliable_ = false; bool hostname_ = false; diff --git a/test/performance/throughput/ThroughputSubscriber.cpp b/test/performance/throughput/ThroughputSubscriber.cpp index 77633c2f7a3..c9b9e4ff5c7 100644 --- a/test/performance/throughput/ThroughputSubscriber.cpp +++ b/test/performance/throughput/ThroughputSubscriber.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; @@ -106,7 +108,7 @@ void ThroughputSubscriber::DataReaderListener::on_data_available( for (int32_t i = 0; i < size; ++i) { uint32_t seq_num = std::max(data_seq[i].seqnum, last_seq_num); - if (sub.data_sharing_ && seq_num > last_seq_num + 1) + if (seq_num > last_seq_num + 1) { if (!reader->is_sample_valid(&data_seq[i], &infos[i])) { @@ -260,14 +262,16 @@ bool ThroughputSubscriber::init( const eprosima::fastrtps::rtps::PropertyPolicy& property_policy, const std::string& xml_config_file, bool dynamic_types, - bool data_sharing, + Arg::EnablerValue data_sharing, bool data_loans, + Arg::EnablerValue shared_memory, int forced_domain) { pid_ = pid; hostname_ = hostname; dynamic_types_ = dynamic_types; data_sharing_ = data_sharing; + shared_memory_ = shared_memory; data_loans_ = data_loans; reliable_ = reliable; forced_domain_ = forced_domain; @@ -309,6 +313,25 @@ bool ThroughputSubscriber::init( pqos.properties(part_property_policy); } + // Set shared memory transport if it was enable/disable explicitly. + if (Arg::EnablerValue::ON == shared_memory_) + { + std::shared_ptr shm_transport = + std::make_shared(); + std::shared_ptr udp_transport = + std::make_shared(); + pqos.transport().user_transports.push_back(shm_transport); + pqos.transport().user_transports.push_back(udp_transport); + pqos.transport().use_builtin_transports = false; + } + else if (Arg::EnablerValue::OFF == shared_memory_) + { + std::shared_ptr udp_transport = + std::make_shared(); + pqos.transport().user_transports.push_back(udp_transport); + pqos.transport().use_builtin_transports = false; + } + // Create the participant participant_ = DomainParticipantFactory::get_instance()->create_participant(domainId, pqos); @@ -365,12 +388,18 @@ bool ThroughputSubscriber::init( dr_qos_.reliability(rp); // Set data sharing according with cli. Is disabled by default in all xml profiles - if (data_sharing_) + if (Arg::EnablerValue::ON == data_sharing_) { DataSharingQosPolicy dsp; dsp.on(""); dr_qos_.data_sharing(dsp); } + else if (Arg::EnablerValue::OFF == data_sharing_) + { + DataSharingQosPolicy dsp; + dsp.off(); + dr_qos_.data_sharing(dsp); + } // Create Command topic { diff --git a/test/performance/throughput/ThroughputSubscriber.hpp b/test/performance/throughput/ThroughputSubscriber.hpp index a8e327b1219..5169652608d 100644 --- a/test/performance/throughput/ThroughputSubscriber.hpp +++ b/test/performance/throughput/ThroughputSubscriber.hpp @@ -44,6 +44,8 @@ #include #include "ThroughputTypes.hpp" +#include "../optionarg.hpp" + class ThroughputSubscriber { public: @@ -58,8 +60,9 @@ class ThroughputSubscriber const eprosima::fastrtps::rtps::PropertyPolicy& property_policy, const std::string& xml_config_file, bool dynamic_types, - bool data_sharing, + Arg::EnablerValue data_sharing, bool data_loans, + Arg::EnablerValue shared_memory, int forced_domain); ~ThroughputSubscriber(); @@ -123,8 +126,9 @@ class ThroughputSubscriber // Flags bool dynamic_types_ = false; - bool data_sharing_ = false; + Arg::EnablerValue data_sharing_ = Arg::EnablerValue::NO_SET; bool data_loans_ = false; + Arg::EnablerValue shared_memory_ = Arg::EnablerValue::NO_SET; bool ready_ = true; bool reliable_ = false; bool hostname_ = false; diff --git a/test/performance/throughput/main_ThroughputTest.cpp b/test/performance/throughput/main_ThroughputTest.cpp index 716c58c70e1..728897bdf43 100644 --- a/test/performance/throughput/main_ThroughputTest.cpp +++ b/test/performance/throughput/main_ThroughputTest.cpp @@ -16,9 +16,8 @@ #include "ThroughputPublisher.hpp" #include "ThroughputSubscriber.hpp" -#include "../optionparser.h" +#include "../optionarg.hpp" -#include #include #include #include @@ -43,84 +42,6 @@ using namespace eprosima::fastrtps::rtps; #define COPYSTR strcpy #endif // if defined(_WIN32) - -struct Arg : public option::Arg -{ - - static void print_error( - const char* msg1, - const option::Option& opt, - const char* msg2) - { - fprintf(stderr, "%s", msg1); - fwrite(opt.name, opt.namelen, 1, stderr); - fprintf(stderr, "%s", msg2); - } - - static option::ArgStatus Unknown( - const option::Option& option, - bool msg) - { - if (msg) - { - print_error("Unknown option '", option, "'\n"); - } - return option::ARG_ILLEGAL; - } - - static option::ArgStatus Required( - const option::Option& option, - bool msg) - { - if (option.arg != 0 && option.arg[0] != 0) - { - return option::ARG_OK; - } - - if (msg) - { - print_error("Option '", option, "' requires an argument\n"); - } - return option::ARG_ILLEGAL; - } - - static option::ArgStatus Numeric( - const option::Option& option, - bool msg) - { - char* endptr = 0; - if (option.arg != 0 && strtol(option.arg, &endptr, 10)) - { - } - if (endptr != option.arg && *endptr == 0) - { - return option::ARG_OK; - } - - if (msg) - { - print_error("Option '", option, "' requires a numeric argument\n"); - } - return option::ARG_ILLEGAL; - } - - static option::ArgStatus String( - const option::Option& option, - bool msg) - { - if (option.arg != 0) - { - return option::ARG_OK; - } - if (msg) - { - print_error("Option '", option, "' requires a numeric argument\n"); - } - return option::ARG_ILLEGAL; - } - -}; - enum optionIndex { UNKNOWN_OPT, @@ -142,7 +63,8 @@ enum optionIndex FORCED_DOMAIN, SUBSCRIBERS, DATA_SHARING, - DATA_LOAN + DATA_LOAN, + SHARED_MEMORY }; enum TestAgent @@ -198,10 +120,12 @@ const option::Descriptor usage[] = { " --export_csv Flag to export a CVS file." }, { UNKNOWN_OPT, 0, "", "", Arg::None, "\nNote:\nIf no demand or msg_size is provided the .csv file is used.\n"}, - { DATA_SHARING, 0, "d", "data_sharing", Arg::None, - " --data_sharing Enable data sharing feature." }, + { DATA_SHARING, 0, "d", "data_sharing", Arg::Enabler, + " --data_sharing=[on|off] Explicitly enable/disable data sharing feature." }, { DATA_LOAN, 0, "l", "data_loans", Arg::None, " --data_loans Use loan sample API." }, + { SHARED_MEMORY, 0, "", "shared_memory", Arg::Enabler, + " --shared_memory=[on|off] Explicitly enable/disable shared memory transport." }, { 0, 0, 0, 0, 0, 0 } }; @@ -247,8 +171,9 @@ int main( bool use_security = false; std::string certs_path; #endif // if HAVE_SECURITY - bool data_sharing = false; + Arg::EnablerValue data_sharing = Arg::EnablerValue::NO_SET; bool data_loans = false; + Arg::EnablerValue shared_memory = Arg::EnablerValue::NO_SET; argc -= (argc > 0); argv += (argc > 0); // skip program name argv[0] if present if (argc) @@ -406,11 +331,28 @@ int main( break; #endif // if HAVE_SECURITY case DATA_SHARING: - data_sharing = true; + if (0 == strncasecmp(opt.arg, "on", 2)) + { + data_sharing = Arg::EnablerValue::ON; + } + else + { + data_sharing = Arg::EnablerValue::OFF; + } break; case DATA_LOAN: data_loans = true; break; + case SHARED_MEMORY: + if (0 == strncasecmp(opt.arg, "on", 2)) + { + shared_memory = Arg::EnablerValue::ON; + } + else + { + shared_memory = Arg::EnablerValue::OFF; + } + break; case UNKNOWN_OPT: option::printUsage(fwrite, stdout, usage, columns); return 0; @@ -425,14 +367,14 @@ int main( logError(ThroughputTest, "Intra-process delivery NOT supported with security"); return 1; } - else if ( data_sharing && use_security ) + else if ( Arg::EnablerValue::ON == data_sharing && use_security ) { logError(ThroughputTest, "Sharing sample APIs NOT supported with RTPS encryption"); return 1; } #endif // if HAVE_SECURITY - if ((data_sharing || data_loans) && dynamic_types) + if ((Arg::EnablerValue::ON == data_sharing || data_loans) && dynamic_types) { logError(ThroughputTest, "Sharing sample APIs NOT supported with dynamic types"); return 1; @@ -539,6 +481,7 @@ int main( dynamic_types, data_sharing, data_loans, + shared_memory, forced_domain) ) { @@ -564,6 +507,7 @@ int main( dynamic_types, data_sharing, data_loans, + shared_memory, forced_domain)) { throughput_subscriber.run(); @@ -594,6 +538,7 @@ int main( dynamic_types, data_sharing, data_loans, + shared_memory, forced_domain)) { return_code = 1; @@ -618,6 +563,7 @@ int main( dynamic_types, data_sharing, data_loans, + shared_memory, forced_domain); } diff --git a/test/performance/throughput/throughput_tests.py b/test/performance/throughput/throughput_tests.py index 65d65bb53a5..57aa556116f 100644 --- a/test/performance/throughput/throughput_tests.py +++ b/test/performance/throughput/throughput_tests.py @@ -16,6 +16,7 @@ import os import subprocess + if __name__ == '__main__': parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter @@ -59,29 +60,35 @@ '--interprocess', action='store_true', help='Publisher and subscribers in separate processes. Defaults:False', - required=False, + required=False ) parser.add_argument( '-d', '--data_sharing', - action='store_true', - help='Enable data sharing (Defaults: disable)', - required=False, + choices=['on', 'off'], + help='Explicitly enable/disable data sharing. (Defaults: Fast-DDS default settings)', + required=False ) parser.add_argument( '-l', '--data_loans', action='store_true', help='Enable the use of the loan sample API (Defaults: disable)', - required=False, + required=False ) parser.add_argument( '-R', '--reliability', action='store_true', help='Run with RELIABLE reliability (Defaults: disable)', - required=False, + required=False ) + parser.add_argument( + '--shared_memory', + choices=['on', 'off'], + help='Explicitly enable/disable shared memory transport. (Defaults: Fast-DDS default settings)', + required=False + ) # Parse arguments args = parser.parse_args() @@ -121,9 +128,9 @@ # Data sharing and loans options # modify output file names - if args.data_sharing and args.data_loans: + if args.data_sharing and 'on' == args.data_sharing and args.data_loans: filename_options += '_data_loans_and_sharing' - elif args.data_sharing: + elif args.data_sharing and 'on' == args.data_sharing: filename_options += '_data_sharing' elif args.data_loans: filename_options += '_data_loans' @@ -144,7 +151,10 @@ data_options = [] if args.data_sharing: - data_options += ['--data_sharing'] + if 'on' == args.data_sharing: + data_options += ['--data_sharing=on'] + else: + data_options += ['--data_sharing=off'] if args.data_loans: data_options += ['--data_loans'] @@ -155,6 +165,12 @@ else: reliability_options = ['--reliability=besteffort'] + if args.shared_memory: + if 'on' == args.shared_memory: + data_options += ['--shared_memory=on'] + else: + data_options += ['--shared_memory=off'] + # Recoveries files options recoveries_options = [] if args.recoveries_file: