From dd142d359d13794684e7ec349aaddb8505d83dc5 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 18 Oct 2024 04:40:21 -0700 Subject: [PATCH 01/11] start work on adding the ability to pass a file/json string into the broker or core for configuration --- src/helics/core/BrokerBase.cpp | 57 ++++++++++++++++++++++ src/helics/shared_api_library/helicsCore.h | 3 +- tests/helics/core/CoreFactory-tests.cpp | 2 +- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/helics/core/BrokerBase.cpp b/src/helics/core/BrokerBase.cpp index baa4ba4c73..a76e1d1bfa 100644 --- a/src/helics/core/BrokerBase.cpp +++ b/src/helics/core/BrokerBase.cpp @@ -327,6 +327,63 @@ int BrokerBase::parseArgs(std::string_view initializationString) auto app = generateBaseCLI(); auto sApp = generateCLI(); app->add_subcommand(sApp); + /* + auto type = fileops::getConfigType(configString); + switch (type) { + case fileops::ConfigType::JSON_FILE: + ret.fileInUse = true; + ret.loadInfoFromJson(configString); + ret.configString = configString; + break; + case fileops::ConfigType::JSON_STRING: + try { + ret.loadInfoFromJson(configString); + ret.configString = configString; + } + catch (const helics::InvalidParameter&) { + if (fileops::looksLikeConfigToml(configString)) { + try { + ret.loadInfoFromToml(configString); + ret.configString = configString; + } + catch (const helics::InvalidParameter&) { + if (fileops::looksLikeCommandLine(configString)) { + ret.loadInfoFromArgsIgnoreOutput(configString); + break; + } + throw; + } + } + throw; + } + break; + case fileops::ConfigType::TOML_FILE: + ret.fileInUse = true; + ret.loadInfoFromToml(configString); + ret.configString = configString; + break; + case fileops::ConfigType::TOML_STRING: + try { + ret.loadInfoFromToml(configString); + ret.configString = configString; + } + catch (const helics::InvalidParameter&) { + if (fileops::looksLikeCommandLine(configString)) { + ret.loadInfoFromArgsIgnoreOutput(configString); + break; + } + throw; + } + break; + case fileops::ConfigType::CMD_LINE: + ret.loadInfoFromArgsIgnoreOutput(configString); + break; + case fileops::ConfigType::NONE: + ret.defName = configString; + } + + return ret; + */ auto res = app->helics_parse(std::string(initializationString)); return static_cast(res); } diff --git a/src/helics/shared_api_library/helicsCore.h b/src/helics/shared_api_library/helicsCore.h index 506885bed6..2a59c26409 100644 --- a/src/helics/shared_api_library/helicsCore.h +++ b/src/helics/shared_api_library/helicsCore.h @@ -110,7 +110,7 @@ HELICS_EXPORT HelicsBool helicsIsCoreTypeAvailable(const char* type); * @param type The type of the core to create. * @param name The name of the core. It can be a nullptr or empty string to have a name automatically assigned. * @param initString An initialization string to send to the core. The format is similar to command line arguments. - * Typical options include a broker name, the broker address, the number of federates, etc. + * Typical options include a broker name, the broker address, the number of federates, etc. Can also be a file(toml,ini,json) or json object containing the core configuration * * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. @@ -166,6 +166,7 @@ HELICS_EXPORT HelicsBool helicsCoreIsValid(HelicsCore core); * @param name The name of the broker. It can be a nullptr or empty string to have a name automatically assigned. * @param initString An initialization string to send to the core-the format is similar to command line arguments. * Typical options include a broker address such as --broker="XSSAF" if this is a subbroker, or the number of federates, + * can also be a json or toml file with broker configuration * or the address. * * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. diff --git a/tests/helics/core/CoreFactory-tests.cpp b/tests/helics/core/CoreFactory-tests.cpp index b96bb2d66d..cc95bf44d9 100644 --- a/tests/helics/core/CoreFactory-tests.cpp +++ b/tests/helics/core/CoreFactory-tests.cpp @@ -139,7 +139,7 @@ TEST(CoreFactory_tests, udpCore_test) } #endif -/** This test should be removed once log levels with numbers is re-enabled ~helics 3.3 */ +/** This test should be removed once log levels with numbers is re-enabled if ever */ TEST(core, core_log_command_failures) { EXPECT_THROW(helics::CoreFactory::create(helics::CoreType::TEST, From 674571ad618503b84107d524a27db857fae8d095 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Sun, 24 Nov 2024 14:26:53 -0800 Subject: [PATCH 02/11] add file test --- src/helics/core/BrokerBase.cpp | 182 +++++++++++++++--- src/helics/core/BrokerBase.hpp | 13 ++ src/helics/core/BrokerFactory.cpp | 43 +++++ src/helics/core/BrokerFactory.hpp | 3 +- src/helics/core/CoreFactory.cpp | 69 +++++-- src/helics/core/CoreTypes.hpp | 3 +- src/helics/core/coreTypeOperations.cpp | 118 ++++++++++++ src/helics/core/coreTypeOperations.hpp | 8 + src/helics/helics_enums.h | 4 +- tests/helics/core/BrokerClassTests.cpp | 61 ++++++ tests/helics/test_files/broker_test_core.json | 5 + .../test_files/broker_test_subbroker.json | 7 + .../test_files/broker_test_subbroker2.toml | 4 + 13 files changed, 469 insertions(+), 51 deletions(-) create mode 100644 tests/helics/test_files/broker_test_core.json create mode 100644 tests/helics/test_files/broker_test_subbroker.json create mode 100644 tests/helics/test_files/broker_test_subbroker2.toml diff --git a/src/helics/core/BrokerBase.cpp b/src/helics/core/BrokerBase.cpp index a76e1d1bfa..ae5e2f6a3b 100644 --- a/src/helics/core/BrokerBase.cpp +++ b/src/helics/core/BrokerBase.cpp @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-3-Clause #include "BrokerBase.hpp" #include "../common/logging.hpp" +#include "../common/configFileHelpers.hpp" #include "AsyncTimeCoordinator.hpp" #include "ForwardingTimeCoordinator.hpp" #include "GlobalTimeCoordinator.hpp" @@ -22,6 +23,7 @@ SPDX-License-Identifier: BSD-3-Clause #include "helics/core/helicsCLI11JsonConfig.hpp" #include "helicsCLI11.hpp" #include "loggingHelper.hpp" +#include "core-exceptions.hpp" #include @@ -324,31 +326,32 @@ int BrokerBase::parseArgs(std::vector args) int BrokerBase::parseArgs(std::string_view initializationString) { - auto app = generateBaseCLI(); - auto sApp = generateCLI(); - app->add_subcommand(sApp); - /* - auto type = fileops::getConfigType(configString); + + auto type = fileops::getConfigType(initializationString); + + switch (type) { case fileops::ConfigType::JSON_FILE: - ret.fileInUse = true; - ret.loadInfoFromJson(configString); - ret.configString = configString; - break; + fileInUse = true; + loadInfoFromJson(std::string(initializationString)); + configString = initializationString; + return 0; case fileops::ConfigType::JSON_STRING: try { - ret.loadInfoFromJson(configString); - ret.configString = configString; + loadInfoFromJson(std::string(initializationString)); + configString = initializationString; + return 0; } catch (const helics::InvalidParameter&) { - if (fileops::looksLikeConfigToml(configString)) { + if (fileops::looksLikeConfigToml(initializationString)) { try { - ret.loadInfoFromToml(configString); - ret.configString = configString; + loadInfoFromToml(std::string(initializationString)); + configString = initializationString; + return 0; } catch (const helics::InvalidParameter&) { - if (fileops::looksLikeCommandLine(configString)) { - ret.loadInfoFromArgsIgnoreOutput(configString); + if (fileops::looksLikeCommandLine(initializationString)) { + break; } throw; @@ -358,34 +361,159 @@ int BrokerBase::parseArgs(std::string_view initializationString) } break; case fileops::ConfigType::TOML_FILE: - ret.fileInUse = true; - ret.loadInfoFromToml(configString); - ret.configString = configString; - break; + fileInUse = true; + loadInfoFromToml(std::string(initializationString)); + configString = initializationString; + return 0; case fileops::ConfigType::TOML_STRING: try { - ret.loadInfoFromToml(configString); - ret.configString = configString; + loadInfoFromToml(std::string(initializationString)); + configString = initializationString; + return 0; } catch (const helics::InvalidParameter&) { if (fileops::looksLikeCommandLine(configString)) { - ret.loadInfoFromArgsIgnoreOutput(configString); break; } throw; } break; case fileops::ConfigType::CMD_LINE: - ret.loadInfoFromArgsIgnoreOutput(configString); break; case fileops::ConfigType::NONE: - ret.defName = configString; + return 0; } - return ret; - */ + auto app = generateBaseCLI(); + auto sApp = generateCLI(); + app->add_subcommand(sApp); auto res = app->helics_parse(std::string(initializationString)); return static_cast(res); + +} + + + +void BrokerBase::loadInfoFromJson(const std::string& jsonString, bool runArgParser) +{ + nlohmann::json doc; + try { + doc = fileops::loadJson(jsonString); + } + catch (const std::invalid_argument& iarg) { + throw(helics::InvalidParameter(iarg.what())); + } + const bool hasHelicsSection = doc.contains("helics"); + bool hasHelicsSubSection{false}; + bool hasHelicsBrokerSubSection{ false }; + if (hasHelicsSection) { + hasHelicsSubSection = doc["helics"].contains("helics"); + hasHelicsBrokerSubSection = doc["helics"].contains("broker"); + } + const bool hasBrokerSection = doc.contains("broker"); + + if (runArgParser) { + auto app = generateBaseCLI(); + auto sApp = generateCLI(); + app->add_subcommand(sApp); + app->allow_extras(); + try { + if (jsonString.find('{') != std::string::npos) { + std::istringstream jstring(jsonString); + app->parse_from_stream(jstring); + if (hasHelicsSection) { + app->get_config_formatter_base()->section("helics"); + std::istringstream jstringHelics(jsonString); + app->parse_from_stream(jstringHelics); + if (hasHelicsSubSection) { + app->get_config_formatter_base()->section("helics.helics"); + std::istringstream jstringHelicsSub(jsonString); + app->parse_from_stream(jstringHelicsSub); + } + if (hasHelicsBrokerSubSection) + { + app->get_config_formatter_base()->section("helics.broker"); + std::istringstream jstringHelicsSub(jsonString); + app->parse_from_stream(jstringHelicsSub); + } + } + if (hasBrokerSection) + { + app->get_config_formatter_base()->section("broker"); + std::istringstream jstringBroker(jsonString); + app->parse_from_stream(jstringBroker); + } + } else { + std::ifstream file(jsonString); + app->parse_from_stream(file); + if (hasHelicsSection) { + file.clear(); + file.seekg(0); + app->get_config_formatter_base()->section("helics"); + app->parse_from_stream(file); + if (hasHelicsSubSection) { + file.clear(); + file.seekg(0); + app->get_config_formatter_base()->section("helics.helics"); + app->parse_from_stream(file); + } + if (hasHelicsBrokerSubSection) + { + file.clear(); + file.seekg(0); + app->get_config_formatter_base()->section("helics.broker"); + app->parse_from_stream(file); + } + } + if (hasBrokerSection) + { + file.clear(); + file.seekg(0); + app->get_config_formatter_base()->section("broker"); + app->parse_from_stream(file); + } + } + } + catch (const CLI::Error& clierror) { + throw(InvalidIdentifier(clierror.what())); + } + } +} + + +void BrokerBase::loadInfoFromToml(const std::string& tomlString, bool runArgParser) +{ + toml::value doc; + try { + doc = fileops::loadToml(tomlString); + } + catch (const std::invalid_argument& iarg) { + throw(helics::InvalidParameter(iarg.what())); + } + + + if (runArgParser) { + auto app = generateBaseCLI(); + auto sApp = generateCLI(); + app->add_subcommand(sApp); + app->allow_extras(); + auto dptr = std::static_pointer_cast(app->get_config_formatter_base()); + if (dptr) { + dptr->skipJson(true); + } + try { + if (tomlString.find('=') != std::string::npos) { + std::istringstream tstring(tomlString); + app->parse_from_stream(tstring); + } else { + std::ifstream file(tomlString); + app->parse_from_stream(file); + } + } + catch (const CLI::Error& e) { + throw(InvalidIdentifier(e.what())); + } + } } void BrokerBase::configureBase() diff --git a/src/helics/core/BrokerBase.hpp b/src/helics/core/BrokerBase.hpp index 65a5f9cfbf..327c3f506b 100644 --- a/src/helics/core/BrokerBase.hpp +++ b/src/helics/core/BrokerBase.hpp @@ -154,6 +154,8 @@ class BrokerBase { decltype(std::chrono::steady_clock::now()) disconnectTime; std::atomic lastErrorCode{0}; //!< storage for last error code std::string lastErrorString; //!< storage for last error string + std::string configString; //!< storage for a config file location + bool fileInUse{false}; private: /// buffer for profiling messages std::shared_ptr prBuff; @@ -170,6 +172,17 @@ class BrokerBase { explicit BrokerBase(std::string_view broker_name, bool DisableQueue = false); virtual ~BrokerBase(); + + /** load broker information object from a toml string either a file or toml string + @param toml a string containing the name of the toml file or toml contents + */ + void loadInfoFromToml(const std::string& toml, bool runArgParser = true); + + /** load broker information from a JSON string either a file or JSON string + @param json a string containing the name of the JSON file or JSON contents + */ + void loadInfoFromJson(const std::string& json, bool runArgParser = true); + /** parse configuration information from command line arguments @return 0 for OK, positive numbers for expected information calls and negative number for error */ diff --git a/src/helics/core/BrokerFactory.cpp b/src/helics/core/BrokerFactory.cpp index e233d7ca02..0f8c815c9e 100644 --- a/src/helics/core/BrokerFactory.cpp +++ b/src/helics/core/BrokerFactory.cpp @@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-3-Clause #include "CoreBroker.hpp" #include "CoreTypes.hpp" +#include "coreTypeOperations.hpp" #include "core-exceptions.hpp" #include "gmlc/concurrency/DelayedDestructor.hpp" #include "gmlc/concurrency/SearchableObjectHolder.hpp" @@ -109,6 +110,20 @@ std::shared_ptr create(CoreType type, std::string_view configureString) std::shared_ptr create(CoreType type, std::string_view brokerName, std::string_view configureString) { + std::string newName; + CoreType newType; + if (type == CoreType::EXTRACT || brokerName.empty()) + { + std::tie(newType,newName) = core::extractCoreType(std::string{configureString}); + if (brokerName.empty() && !newName.empty()) + { + brokerName=newName; + } + if (type == CoreType::EXTRACT) + { + type=newType; + } + } auto broker = makeBroker(type, brokerName); if (!broker) { throw(helics::RegistrationFailure("unable to create broker")); @@ -129,6 +144,20 @@ std::shared_ptr create(CoreType type, int argc, char* argv[]) std::shared_ptr create(CoreType type, std::string_view brokerName, int argc, char* argv[]) { + std::string newName; + CoreType newType; + if (type == CoreType::EXTRACT || brokerName.empty()) + { + std::tie(newType,newName) = core::extractCoreType(argc,argv); + if (brokerName.empty() && !newName.empty()) + { + brokerName=newName; + } + if (type == CoreType::EXTRACT) + { + type=newType; + } + } auto broker = makeBroker(type, brokerName); broker->configureFromArgs(argc, argv); if (!registerBroker(broker, type)) { @@ -147,6 +176,20 @@ std::shared_ptr create(CoreType type, std::vector args) std::shared_ptr create(CoreType type, std::string_view brokerName, std::vector args) { + std::string newName; + CoreType newType; + if (type == CoreType::EXTRACT || brokerName.empty()) + { + std::tie(newType,newName) = core::extractCoreType(args); + if (brokerName.empty() && !newName.empty()) + { + brokerName=newName; + } + if (type == CoreType::EXTRACT) + { + type=newType; + } + } auto broker = makeBroker(type, brokerName); broker->configureFromVector(std::move(args)); if (!registerBroker(broker, type)) { diff --git a/src/helics/core/BrokerFactory.hpp b/src/helics/core/BrokerFactory.hpp index f0c287c2a0..e79bf2e944 100644 --- a/src/helics/core/BrokerFactory.hpp +++ b/src/helics/core/BrokerFactory.hpp @@ -32,7 +32,7 @@ namespace BrokerFactory { class BrokerTypeBuilder final: public BrokerBuilder { public: static_assert(std::is_base_of::value, - "Type does not inherit from helics::Core"); + "Type does not inherit from helics::Broker"); using broker_build_type = BrokerTYPE; virtual std::shared_ptr build(std::string_view name) override @@ -55,6 +55,7 @@ namespace BrokerFactory { defineBrokerBuilder(bbld, brokerTypeName, code); return bbld; } + /** * Creates a Broker object of the specified type. * diff --git a/src/helics/core/CoreFactory.cpp b/src/helics/core/CoreFactory.cpp index 4dc7c3110e..ad8793e4ac 100644 --- a/src/helics/core/CoreFactory.cpp +++ b/src/helics/core/CoreFactory.cpp @@ -11,13 +11,13 @@ SPDX-License-Identifier: BSD-3-Clause #include "CommonCore.hpp" #include "CoreTypes.hpp" +#include "coreTypeOperations.hpp" #include "EmptyCore.hpp" #include "core-exceptions.hpp" #include "gmlc/concurrency/DelayedDestructor.hpp" #include "gmlc/concurrency/SearchableObjectHolder.hpp" #include "gmlc/libguarded/shared_guarded.hpp" #include "helics/helics-config.h" -#include "helicsCLI11.hpp" #include #include @@ -134,12 +134,7 @@ Core* getEmptyCorePtr() std::shared_ptr create(std::string_view initializationString) { - helicsCLI11App tparser; - tparser.remove_helics_specifics(); - tparser.addTypeOption(); - tparser.allow_extras(); - tparser.parse(std::string(initializationString)); - return create(tparser.getCoreType(), gHelicsEmptyString, tparser.remaining_for_passthrough()); + return create(CoreType::EXTRACT, gHelicsEmptyString, initializationString); } std::shared_ptr create(CoreType type, std::string_view configureString) @@ -150,6 +145,20 @@ std::shared_ptr create(CoreType type, std::string_view configureString) std::shared_ptr create(CoreType type, std::string_view coreName, std::string_view configureString) { + std::string newName; + CoreType newType; + if (type == CoreType::EXTRACT || coreName.empty()) + { + std::tie(newType,newName) = core::extractCoreType(std::string{configureString}); + if (coreName.empty() && !newName.empty()) + { + coreName=newName; + } + if (type == CoreType::EXTRACT) + { + type=newType; + } + } auto core = makeCore(type, coreName); if (!core) { throw(helics::RegistrationFailure("unable to create core")); @@ -165,13 +174,7 @@ std::shared_ptr std::shared_ptr create(std::vector args) { - helicsCLI11App tparser; - tparser.remove_helics_specifics(); - tparser.addTypeOption(); - - tparser.allow_extras(); - tparser.parse(std::move(args)); - return create(tparser.getCoreType(), gHelicsEmptyString, tparser.remaining_for_passthrough()); + return create(CoreType::EXTRACT, gHelicsEmptyString, args); } std::shared_ptr create(CoreType type, std::vector args) @@ -182,6 +185,22 @@ std::shared_ptr create(CoreType type, std::vector args) std::shared_ptr create(CoreType type, std::string_view coreName, std::vector args) { + + std::string newName; + CoreType newType; + if (type == CoreType::EXTRACT || coreName.empty()) + { + std::tie(newType,newName) = core::extractCoreType(args); + if (coreName.empty() && !newName.empty()) + { + coreName=newName; + } + if (type == CoreType::EXTRACT) + { + type=newType; + } + } + auto core = makeCore(type, coreName); core->configureFromVector(std::move(args)); if (!registerCore(core, type)) { @@ -194,13 +213,7 @@ std::shared_ptr std::shared_ptr create(int argc, char* argv[]) { - helicsCLI11App tparser; - tparser.remove_helics_specifics(); - tparser.addTypeOption(); - - tparser.allow_extras(); - tparser.parse(argc, argv); - return create(tparser.getCoreType(), tparser.remaining_for_passthrough()); + return create(CoreType::EXTRACT, gHelicsEmptyString, argc,argv); } std::shared_ptr create(CoreType type, int argc, char* argv[]) @@ -210,6 +223,20 @@ std::shared_ptr create(CoreType type, int argc, char* argv[]) std::shared_ptr create(CoreType type, std::string_view coreName, int argc, char* argv[]) { + std::string newName; + CoreType newType; + if (type == CoreType::EXTRACT || coreName.empty()) + { + std::tie(newType,newName) = core::extractCoreType(argc,argv); + if (coreName.empty() && !newName.empty()) + { + coreName=newName; + } + if (type == CoreType::EXTRACT) + { + type=newType; + } + } auto core = makeCore(type, coreName); core->configureFromArgs(argc, argv); if (!registerCore(core, type)) { diff --git a/src/helics/core/CoreTypes.hpp b/src/helics/core/CoreTypes.hpp index 05fb024e13..5ffb04e419 100644 --- a/src/helics/core/CoreTypes.hpp +++ b/src/helics/core/CoreTypes.hpp @@ -67,7 +67,8 @@ enum class CoreType : int { NULLCORE = HELICS_CORE_TYPE_NULL, //!< explicit core type that doesn't exist EMPTY = HELICS_CORE_TYPE_EMPTY, //!< core type that does nothing and can't communicate UNRECOGNIZED = 22, //!< unknown - MULTI = 45 //!< use the multi-broker + MULTI = 45, //!< use the multi-broker + EXTRACT=HELICS_CORE_TYPE_EXTRACT //!< extract core type from later arguments/files }; /** enumeration of the possible message processing results*/ diff --git a/src/helics/core/coreTypeOperations.cpp b/src/helics/core/coreTypeOperations.cpp index 415b54517a..e1872c1727 100644 --- a/src/helics/core/coreTypeOperations.cpp +++ b/src/helics/core/coreTypeOperations.cpp @@ -9,6 +9,8 @@ SPDX-License-Identifier: BSD-3-Clause #include "CoreTypes.hpp" #include "core-exceptions.hpp" #include "helics/helics-config.h" +#include "helicsCLI11JsonConfig.hpp" +#include "../common/configFileHelpers.hpp" #include #include @@ -19,6 +21,7 @@ SPDX-License-Identifier: BSD-3-Clause #include #include #include +#include namespace frozen { template<> @@ -309,6 +312,121 @@ bool matchingTypes(std::string_view type1, std::string_view type2) return (res != global_match_strings.end()); } +namespace +{ + std::unique_ptr makeCLITypeApp(std::string &corestring,std::string &namestring) + { + auto app = std::make_unique("type extraction app"); + app->remove_helics_specifics(); + app->option_defaults()->ignore_case()->ignore_underscore(); + app->allow_config_extras(CLI::config_extras_mode::ignore_all); + app->allow_extras(); + app->set_config("--config-file,--config,config", + "helicsConfig.ini", + "specify a configuration file"); + app->add_option("--name,--identifier",namestring); + auto* fmtr = addJsonConfig(app.get()); + fmtr->maxLayers(0); + fmtr->promoteSection("helics"); + auto* networking = app->add_option_group("network type")->immediate_callback(); + networking + ->add_option( + "--core",corestring); + networking + ->add_option( + "--coretype,-t",corestring) + ->envname("HELICS_CORE_TYPE"); + app->add_subcommand("broker")->fallthrough(); + app->add_subcommand("core")->fallthrough(); + return app; +} +} + + +std::pair extractCoreType(const std::string & configureString) +{ + std::string corestring; + std::string namestring; + auto app=makeCLITypeApp(corestring,namestring); + auto type = fileops::getConfigType(configureString); + try { + switch (type) { + case fileops::ConfigType::JSON_FILE: { + std::ifstream file{configureString}; + app->parse_from_stream(file); + break; + } + case fileops::ConfigType::JSON_STRING: { + std::istringstream jstring{configureString}; + app->parse_from_stream(jstring); + break; } + case fileops::ConfigType::TOML_FILE: { + app->allow_extras(); + auto dptr = std::static_pointer_cast(app->get_config_formatter_base()); + if (dptr) { + dptr->skipJson(true); + } + std::ifstream file{configureString}; + app->parse_from_stream(file); + break; + } + case fileops::ConfigType::TOML_STRING: + { + app->allow_extras(); + auto dptr = std::static_pointer_cast(app->get_config_formatter_base()); + if (dptr) { + dptr->skipJson(true); + } + std::istringstream tstring{configureString}; + app->parse_from_stream(tstring); + break; + } + case fileops::ConfigType::CMD_LINE: + app->helics_parse(configureString); + break; + case fileops::ConfigType::NONE: + break; + } + } + catch (const std::exception&) + { + corestring.clear(); + } + if (corestring.empty()) + { + return { CoreType::DEFAULT,namestring }; + } + return { coreTypeFromString(corestring),namestring }; + } + +std::pair extractCoreType(const std::vector& args) +{ + std::string corestring; + std::string namestring; + auto app=makeCLITypeApp(corestring,namestring); + auto vec=args; + app->helics_parse(vec); + if (corestring.empty()) + { + return { CoreType::DEFAULT,namestring }; + } + return { coreTypeFromString(corestring),namestring }; + +} + +std::pair extractCoreType(int argc, char* argv[]) +{ + std::string corestring; + std::string namestring; + auto app=makeCLITypeApp(corestring,namestring); + app->helics_parse(argc,argv); + if (corestring.empty()) + { + return { CoreType::DEFAULT,namestring }; + } + return { coreTypeFromString(corestring),namestring }; +} + } // namespace helics::core namespace helics { diff --git a/src/helics/core/coreTypeOperations.hpp b/src/helics/core/coreTypeOperations.hpp index dbf74ee1f7..c09827987a 100644 --- a/src/helics/core/coreTypeOperations.hpp +++ b/src/helics/core/coreTypeOperations.hpp @@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-3-Clause #include #include +#include /** @file @details function definitions for operations on core types @@ -40,4 +41,11 @@ bool matchingTypes(std::string_view type1, std::string_view type2); /** generate an extended version and system info string in json format*/ std::string systemInfo(); + +/** methods to extract the core type and name from various forms of arguments*/ +std::pair extractCoreType(const std::string &configureString); +std::pair extractCoreType(const std::vector &args); +std::pair extractCoreType(int argc, char *argv[]); + + } // namespace helics::core diff --git a/src/helics/helics_enums.h b/src/helics/helics_enums.h index e8f29e1e79..e69985fd23 100644 --- a/src/helics/helics_enums.h +++ b/src/helics/helics_enums.h @@ -58,7 +58,9 @@ typedef enum { /* NOLINT */ HELICS_CORE_TYPE_NULL = 66, /** an explicit core type exists but does nothing but return empty values or sink calls*/ - HELICS_CORE_TYPE_EMPTY = 77 + HELICS_CORE_TYPE_EMPTY = 77, + /** core type specification to allow extraction from later arguments or files*/ + HELICS_CORE_TYPE_EXTRACT=101 } HelicsCoreTypes; /** enumeration of allowable data types for publications and inputs*/ diff --git a/tests/helics/core/BrokerClassTests.cpp b/tests/helics/core/BrokerClassTests.cpp index 3d9fbbf047..eabdf4e763 100644 --- a/tests/helics/core/BrokerClassTests.cpp +++ b/tests/helics/core/BrokerClassTests.cpp @@ -88,6 +88,67 @@ TEST(brokers, subbroker_min) brk->disconnect(); + EXPECT_TRUE(brk3->waitForDisconnect()); + +} + + +/** test the assignment and retrieval of global value from a broker object*/ +TEST(brokers, subbroker_min_files) +{ + auto brk = helics::BrokerFactory::create(helics::CoreType::EXTRACT, + "", + std::string(TEST_DIR)+"broker_test_subbroker.json"); + + EXPECT_EQ(brk->getIdentifier(),"gbroker_f1"); + + auto brk2 = helics::BrokerFactory::create(helics::CoreType::EXTRACT, "", std::string(TEST_DIR)+"broker_test_subbroker2.toml"); + + auto cr1 = helics::CoreFactory::create(helics::CoreType::TEST, "--name=cf1 --broker=gbf2"); + + helics::CoreFederateInfo cf1; + auto fid1 = cr1->registerFederate("fed1", cf1); + auto fid2 = cr1->registerFederate("fed2", cf1); + + auto fut1 = + std::async(std::launch::async, [fid1, &cr1]() { cr1->enterInitializingMode(fid1); }); + + auto fut2 = + std::async(std::launch::async, [fid2, &cr1]() { cr1->enterInitializingMode(fid2); }); + + auto res = fut1.wait_for(std::chrono::milliseconds(100)); + // this should not allow initializingMode entry since only 1 subbroker + EXPECT_EQ(res, std::future_status::timeout); + + auto cr2 = helics::CoreFactory::create(helics::CoreType::EXTRACT,std::string(TEST_DIR)+"broker_test_core.json"); + auto fid3 = cr2->registerFederate("fed3", cf1); + + auto fut3 = + std::async(std::launch::async, [fid3, &cr2]() { cr2->enterInitializingMode(fid3); }); + + res = fut1.wait_for(std::chrono::milliseconds(100)); + // this should still not allow initializingMode entry since still only 1 subbroker + EXPECT_EQ(res, std::future_status::timeout); + + auto brk3 = helics::BrokerFactory::create(helics::CoreType::TEST, "gbf3", "{\"broker\":\"gbroker_f1\"}"); + + auto cr3 = helics::CoreFactory::create(helics::CoreType::TEST, "cf3", "broker=\"gbf3\""); + auto fid4 = cr3->registerFederate("fed4", cf1); + + auto fut4 = + std::async(std::launch::async, [fid4, &cr3]() { cr3->enterInitializingMode(fid4); }); + + // now it should grant + fut1.get(); + fut2.get(); + fut3.get(); + fut4.get(); + + EXPECT_FALSE(brk->isOpenToNewFederates()); + EXPECT_FALSE(cr3->isOpenToNewFederates()); + + brk->disconnect(); + EXPECT_TRUE(brk3->waitForDisconnect()); } diff --git a/tests/helics/test_files/broker_test_core.json b/tests/helics/test_files/broker_test_core.json new file mode 100644 index 0000000000..3233a72d96 --- /dev/null +++ b/tests/helics/test_files/broker_test_core.json @@ -0,0 +1,5 @@ +{ +"name":"cf2", +"coretype":"test", +"broker":"gbf2" +} \ No newline at end of file diff --git a/tests/helics/test_files/broker_test_subbroker.json b/tests/helics/test_files/broker_test_subbroker.json new file mode 100644 index 0000000000..e3fd913bc1 --- /dev/null +++ b/tests/helics/test_files/broker_test_subbroker.json @@ -0,0 +1,7 @@ +{ +"name":"gbroker_f1", +"coretype":"test", +"sub_brokers":2, +"federates":2, +"root":true +} \ No newline at end of file diff --git a/tests/helics/test_files/broker_test_subbroker2.toml b/tests/helics/test_files/broker_test_subbroker2.toml new file mode 100644 index 0000000000..712a2ee3d6 --- /dev/null +++ b/tests/helics/test_files/broker_test_subbroker2.toml @@ -0,0 +1,4 @@ +name="gbf2" +coretype="test" +sub_brokers=2 +broker="gbroker_f1" \ No newline at end of file From 422a8534a025684dd11d839fdf8a52818be0954f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 24 Nov 2024 22:28:03 +0000 Subject: [PATCH 03/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/helics/core/BrokerBase.cpp | 114 ++++++++-------- src/helics/core/BrokerBase.hpp | 3 +- src/helics/core/BrokerFactory.cpp | 47 +++---- src/helics/core/CoreFactory.cpp | 50 +++---- src/helics/core/CoreTypes.hpp | 2 +- src/helics/core/coreTypeOperations.cpp | 122 ++++++++---------- src/helics/core/coreTypeOperations.hpp | 8 +- src/helics/helics_enums.h | 2 +- src/helics/shared_api_library/helicsCore.h | 3 +- tests/helics/core/BrokerClassTests.cpp | 20 +-- tests/helics/test_files/broker_test_core.json | 8 +- .../test_files/broker_test_subbroker.json | 12 +- .../test_files/broker_test_subbroker2.toml | 2 +- 13 files changed, 178 insertions(+), 215 deletions(-) diff --git a/src/helics/core/BrokerBase.cpp b/src/helics/core/BrokerBase.cpp index ae5e2f6a3b..4e2fbc67f4 100644 --- a/src/helics/core/BrokerBase.cpp +++ b/src/helics/core/BrokerBase.cpp @@ -7,13 +7,14 @@ SPDX-License-Identifier: BSD-3-Clause #include "BrokerBase.hpp" -#include "../common/logging.hpp" #include "../common/configFileHelpers.hpp" +#include "../common/logging.hpp" #include "AsyncTimeCoordinator.hpp" #include "ForwardingTimeCoordinator.hpp" #include "GlobalTimeCoordinator.hpp" #include "LogManager.hpp" #include "ProfilerBuffer.hpp" +#include "core-exceptions.hpp" #include "flagOperations.hpp" #include "gmlc/libguarded/guarded.hpp" #include "gmlc/utilities/stringOps.h" @@ -23,7 +24,6 @@ SPDX-License-Identifier: BSD-3-Clause #include "helics/core/helicsCLI11JsonConfig.hpp" #include "helicsCLI11.hpp" #include "loggingHelper.hpp" -#include "core-exceptions.hpp" #include @@ -326,62 +326,59 @@ int BrokerBase::parseArgs(std::vector args) int BrokerBase::parseArgs(std::string_view initializationString) { - auto type = fileops::getConfigType(initializationString); - - + switch (type) { - case fileops::ConfigType::JSON_FILE: - fileInUse = true; - loadInfoFromJson(std::string(initializationString)); - configString = initializationString; - return 0; - case fileops::ConfigType::JSON_STRING: - try { - loadInfoFromJson(std::string(initializationString)); - configString = initializationString; - return 0; - } - catch (const helics::InvalidParameter&) { - if (fileops::looksLikeConfigToml(initializationString)) { - try { - loadInfoFromToml(std::string(initializationString)); - configString = initializationString; - return 0; - } - catch (const helics::InvalidParameter&) { - if (fileops::looksLikeCommandLine(initializationString)) { - - break; + case fileops::ConfigType::JSON_FILE: + fileInUse = true; + loadInfoFromJson(std::string(initializationString)); + configString = initializationString; + return 0; + case fileops::ConfigType::JSON_STRING: + try { + loadInfoFromJson(std::string(initializationString)); + configString = initializationString; + return 0; + } + catch (const helics::InvalidParameter&) { + if (fileops::looksLikeConfigToml(initializationString)) { + try { + loadInfoFromToml(std::string(initializationString)); + configString = initializationString; + return 0; + } + catch (const helics::InvalidParameter&) { + if (fileops::looksLikeCommandLine(initializationString)) { + break; + } + throw; } - throw; } + throw; } - throw; - } - break; - case fileops::ConfigType::TOML_FILE: - fileInUse = true; - loadInfoFromToml(std::string(initializationString)); - configString = initializationString; - return 0; - case fileops::ConfigType::TOML_STRING: - try { + break; + case fileops::ConfigType::TOML_FILE: + fileInUse = true; loadInfoFromToml(std::string(initializationString)); configString = initializationString; return 0; - } - catch (const helics::InvalidParameter&) { - if (fileops::looksLikeCommandLine(configString)) { - break; + case fileops::ConfigType::TOML_STRING: + try { + loadInfoFromToml(std::string(initializationString)); + configString = initializationString; + return 0; } - throw; - } - break; - case fileops::ConfigType::CMD_LINE: - break; - case fileops::ConfigType::NONE: - return 0; + catch (const helics::InvalidParameter&) { + if (fileops::looksLikeCommandLine(configString)) { + break; + } + throw; + } + break; + case fileops::ConfigType::CMD_LINE: + break; + case fileops::ConfigType::NONE: + return 0; } auto app = generateBaseCLI(); @@ -389,11 +386,8 @@ int BrokerBase::parseArgs(std::string_view initializationString) app->add_subcommand(sApp); auto res = app->helics_parse(std::string(initializationString)); return static_cast(res); - } - - void BrokerBase::loadInfoFromJson(const std::string& jsonString, bool runArgParser) { nlohmann::json doc; @@ -405,7 +399,7 @@ void BrokerBase::loadInfoFromJson(const std::string& jsonString, bool runArgPars } const bool hasHelicsSection = doc.contains("helics"); bool hasHelicsSubSection{false}; - bool hasHelicsBrokerSubSection{ false }; + bool hasHelicsBrokerSubSection{false}; if (hasHelicsSection) { hasHelicsSubSection = doc["helics"].contains("helics"); hasHelicsBrokerSubSection = doc["helics"].contains("broker"); @@ -430,15 +424,13 @@ void BrokerBase::loadInfoFromJson(const std::string& jsonString, bool runArgPars std::istringstream jstringHelicsSub(jsonString); app->parse_from_stream(jstringHelicsSub); } - if (hasHelicsBrokerSubSection) - { + if (hasHelicsBrokerSubSection) { app->get_config_formatter_base()->section("helics.broker"); std::istringstream jstringHelicsSub(jsonString); app->parse_from_stream(jstringHelicsSub); } } - if (hasBrokerSection) - { + if (hasBrokerSection) { app->get_config_formatter_base()->section("broker"); std::istringstream jstringBroker(jsonString); app->parse_from_stream(jstringBroker); @@ -457,16 +449,14 @@ void BrokerBase::loadInfoFromJson(const std::string& jsonString, bool runArgPars app->get_config_formatter_base()->section("helics.helics"); app->parse_from_stream(file); } - if (hasHelicsBrokerSubSection) - { + if (hasHelicsBrokerSubSection) { file.clear(); file.seekg(0); app->get_config_formatter_base()->section("helics.broker"); app->parse_from_stream(file); } } - if (hasBrokerSection) - { + if (hasBrokerSection) { file.clear(); file.seekg(0); app->get_config_formatter_base()->section("broker"); @@ -480,7 +470,6 @@ void BrokerBase::loadInfoFromJson(const std::string& jsonString, bool runArgPars } } - void BrokerBase::loadInfoFromToml(const std::string& tomlString, bool runArgParser) { toml::value doc; @@ -491,7 +480,6 @@ void BrokerBase::loadInfoFromToml(const std::string& tomlString, bool runArgPars throw(helics::InvalidParameter(iarg.what())); } - if (runArgParser) { auto app = generateBaseCLI(); auto sApp = generateCLI(); diff --git a/src/helics/core/BrokerBase.hpp b/src/helics/core/BrokerBase.hpp index 327c3f506b..39a0a0f4bb 100644 --- a/src/helics/core/BrokerBase.hpp +++ b/src/helics/core/BrokerBase.hpp @@ -154,8 +154,9 @@ class BrokerBase { decltype(std::chrono::steady_clock::now()) disconnectTime; std::atomic lastErrorCode{0}; //!< storage for last error code std::string lastErrorString; //!< storage for last error string - std::string configString; //!< storage for a config file location + std::string configString; //!< storage for a config file location bool fileInUse{false}; + private: /// buffer for profiling messages std::shared_ptr prBuff; diff --git a/src/helics/core/BrokerFactory.cpp b/src/helics/core/BrokerFactory.cpp index 0f8c815c9e..14cb4677ea 100644 --- a/src/helics/core/BrokerFactory.cpp +++ b/src/helics/core/BrokerFactory.cpp @@ -11,8 +11,8 @@ SPDX-License-Identifier: BSD-3-Clause #include "CoreBroker.hpp" #include "CoreTypes.hpp" -#include "coreTypeOperations.hpp" #include "core-exceptions.hpp" +#include "coreTypeOperations.hpp" #include "gmlc/concurrency/DelayedDestructor.hpp" #include "gmlc/concurrency/SearchableObjectHolder.hpp" #include "gmlc/concurrency/TripWire.hpp" @@ -112,16 +112,13 @@ std::shared_ptr { std::string newName; CoreType newType; - if (type == CoreType::EXTRACT || brokerName.empty()) - { - std::tie(newType,newName) = core::extractCoreType(std::string{configureString}); - if (brokerName.empty() && !newName.empty()) - { - brokerName=newName; + if (type == CoreType::EXTRACT || brokerName.empty()) { + std::tie(newType, newName) = core::extractCoreType(std::string{configureString}); + if (brokerName.empty() && !newName.empty()) { + brokerName = newName; } - if (type == CoreType::EXTRACT) - { - type=newType; + if (type == CoreType::EXTRACT) { + type = newType; } } auto broker = makeBroker(type, brokerName); @@ -146,16 +143,13 @@ std::shared_ptr create(CoreType type, std::string_view brokerName, int a { std::string newName; CoreType newType; - if (type == CoreType::EXTRACT || brokerName.empty()) - { - std::tie(newType,newName) = core::extractCoreType(argc,argv); - if (brokerName.empty() && !newName.empty()) - { - brokerName=newName; + if (type == CoreType::EXTRACT || brokerName.empty()) { + std::tie(newType, newName) = core::extractCoreType(argc, argv); + if (brokerName.empty() && !newName.empty()) { + brokerName = newName; } - if (type == CoreType::EXTRACT) - { - type=newType; + if (type == CoreType::EXTRACT) { + type = newType; } } auto broker = makeBroker(type, brokerName); @@ -178,16 +172,13 @@ std::shared_ptr { std::string newName; CoreType newType; - if (type == CoreType::EXTRACT || brokerName.empty()) - { - std::tie(newType,newName) = core::extractCoreType(args); - if (brokerName.empty() && !newName.empty()) - { - brokerName=newName; + if (type == CoreType::EXTRACT || brokerName.empty()) { + std::tie(newType, newName) = core::extractCoreType(args); + if (brokerName.empty() && !newName.empty()) { + brokerName = newName; } - if (type == CoreType::EXTRACT) - { - type=newType; + if (type == CoreType::EXTRACT) { + type = newType; } } auto broker = makeBroker(type, brokerName); diff --git a/src/helics/core/CoreFactory.cpp b/src/helics/core/CoreFactory.cpp index ad8793e4ac..4dd4201901 100644 --- a/src/helics/core/CoreFactory.cpp +++ b/src/helics/core/CoreFactory.cpp @@ -11,9 +11,9 @@ SPDX-License-Identifier: BSD-3-Clause #include "CommonCore.hpp" #include "CoreTypes.hpp" -#include "coreTypeOperations.hpp" #include "EmptyCore.hpp" #include "core-exceptions.hpp" +#include "coreTypeOperations.hpp" #include "gmlc/concurrency/DelayedDestructor.hpp" #include "gmlc/concurrency/SearchableObjectHolder.hpp" #include "gmlc/libguarded/shared_guarded.hpp" @@ -147,16 +147,13 @@ std::shared_ptr { std::string newName; CoreType newType; - if (type == CoreType::EXTRACT || coreName.empty()) - { - std::tie(newType,newName) = core::extractCoreType(std::string{configureString}); - if (coreName.empty() && !newName.empty()) - { - coreName=newName; + if (type == CoreType::EXTRACT || coreName.empty()) { + std::tie(newType, newName) = core::extractCoreType(std::string{configureString}); + if (coreName.empty() && !newName.empty()) { + coreName = newName; } - if (type == CoreType::EXTRACT) - { - type=newType; + if (type == CoreType::EXTRACT) { + type = newType; } } auto core = makeCore(type, coreName); @@ -185,19 +182,15 @@ std::shared_ptr create(CoreType type, std::vector args) std::shared_ptr create(CoreType type, std::string_view coreName, std::vector args) { - std::string newName; CoreType newType; - if (type == CoreType::EXTRACT || coreName.empty()) - { - std::tie(newType,newName) = core::extractCoreType(args); - if (coreName.empty() && !newName.empty()) - { - coreName=newName; + if (type == CoreType::EXTRACT || coreName.empty()) { + std::tie(newType, newName) = core::extractCoreType(args); + if (coreName.empty() && !newName.empty()) { + coreName = newName; } - if (type == CoreType::EXTRACT) - { - type=newType; + if (type == CoreType::EXTRACT) { + type = newType; } } @@ -213,7 +206,7 @@ std::shared_ptr std::shared_ptr create(int argc, char* argv[]) { - return create(CoreType::EXTRACT, gHelicsEmptyString, argc,argv); + return create(CoreType::EXTRACT, gHelicsEmptyString, argc, argv); } std::shared_ptr create(CoreType type, int argc, char* argv[]) @@ -225,16 +218,13 @@ std::shared_ptr create(CoreType type, std::string_view coreName, int argc, { std::string newName; CoreType newType; - if (type == CoreType::EXTRACT || coreName.empty()) - { - std::tie(newType,newName) = core::extractCoreType(argc,argv); - if (coreName.empty() && !newName.empty()) - { - coreName=newName; + if (type == CoreType::EXTRACT || coreName.empty()) { + std::tie(newType, newName) = core::extractCoreType(argc, argv); + if (coreName.empty() && !newName.empty()) { + coreName = newName; } - if (type == CoreType::EXTRACT) - { - type=newType; + if (type == CoreType::EXTRACT) { + type = newType; } } auto core = makeCore(type, coreName); diff --git a/src/helics/core/CoreTypes.hpp b/src/helics/core/CoreTypes.hpp index 5ffb04e419..490b28555d 100644 --- a/src/helics/core/CoreTypes.hpp +++ b/src/helics/core/CoreTypes.hpp @@ -68,7 +68,7 @@ enum class CoreType : int { EMPTY = HELICS_CORE_TYPE_EMPTY, //!< core type that does nothing and can't communicate UNRECOGNIZED = 22, //!< unknown MULTI = 45, //!< use the multi-broker - EXTRACT=HELICS_CORE_TYPE_EXTRACT //!< extract core type from later arguments/files + EXTRACT = HELICS_CORE_TYPE_EXTRACT //!< extract core type from later arguments/files }; /** enumeration of the possible message processing results*/ diff --git a/src/helics/core/coreTypeOperations.cpp b/src/helics/core/coreTypeOperations.cpp index e1872c1727..1ccc9a1c8d 100644 --- a/src/helics/core/coreTypeOperations.cpp +++ b/src/helics/core/coreTypeOperations.cpp @@ -6,22 +6,22 @@ SPDX-License-Identifier: BSD-3-Clause */ #include "coreTypeOperations.hpp" +#include "../common/configFileHelpers.hpp" #include "CoreTypes.hpp" #include "core-exceptions.hpp" #include "helics/helics-config.h" #include "helicsCLI11JsonConfig.hpp" -#include "../common/configFileHelpers.hpp" #include #include #include #include #include +#include #include #include #include #include -#include namespace frozen { template<> @@ -312,45 +312,38 @@ bool matchingTypes(std::string_view type1, std::string_view type2) return (res != global_match_strings.end()); } -namespace -{ - std::unique_ptr makeCLITypeApp(std::string &corestring,std::string &namestring) +namespace { + std::unique_ptr makeCLITypeApp(std::string& corestring, std::string& namestring) { - auto app = std::make_unique("type extraction app"); - app->remove_helics_specifics(); - app->option_defaults()->ignore_case()->ignore_underscore(); - app->allow_config_extras(CLI::config_extras_mode::ignore_all); - app->allow_extras(); - app->set_config("--config-file,--config,config", - "helicsConfig.ini", - "specify a configuration file"); - app->add_option("--name,--identifier",namestring); - auto* fmtr = addJsonConfig(app.get()); - fmtr->maxLayers(0); - fmtr->promoteSection("helics"); - auto* networking = app->add_option_group("network type")->immediate_callback(); - networking - ->add_option( - "--core",corestring); - networking - ->add_option( - "--coretype,-t",corestring) - ->envname("HELICS_CORE_TYPE"); - app->add_subcommand("broker")->fallthrough(); - app->add_subcommand("core")->fallthrough(); - return app; -} -} - + auto app = std::make_unique("type extraction app"); + app->remove_helics_specifics(); + app->option_defaults()->ignore_case()->ignore_underscore(); + app->allow_config_extras(CLI::config_extras_mode::ignore_all); + app->allow_extras(); + app->set_config("--config-file,--config,config", + "helicsConfig.ini", + "specify a configuration file"); + app->add_option("--name,--identifier", namestring); + auto* fmtr = addJsonConfig(app.get()); + fmtr->maxLayers(0); + fmtr->promoteSection("helics"); + auto* networking = app->add_option_group("network type")->immediate_callback(); + networking->add_option("--core", corestring); + networking->add_option("--coretype,-t", corestring)->envname("HELICS_CORE_TYPE"); + app->add_subcommand("broker")->fallthrough(); + app->add_subcommand("core")->fallthrough(); + return app; + } +} // namespace -std::pair extractCoreType(const std::string & configureString) +std::pair extractCoreType(const std::string& configureString) { std::string corestring; std::string namestring; - auto app=makeCLITypeApp(corestring,namestring); - auto type = fileops::getConfigType(configureString); - try { - switch (type) { + auto app = makeCLITypeApp(corestring, namestring); + auto type = fileops::getConfigType(configureString); + try { + switch (type) { case fileops::ConfigType::JSON_FILE: { std::ifstream file{configureString}; app->parse_from_stream(file); @@ -359,10 +352,12 @@ std::pair extractCoreType(const std::string & configureStr case fileops::ConfigType::JSON_STRING: { std::istringstream jstring{configureString}; app->parse_from_stream(jstring); - break; } + break; + } case fileops::ConfigType::TOML_FILE: { app->allow_extras(); - auto dptr = std::static_pointer_cast(app->get_config_formatter_base()); + auto dptr = + std::static_pointer_cast(app->get_config_formatter_base()); if (dptr) { dptr->skipJson(true); } @@ -370,10 +365,10 @@ std::pair extractCoreType(const std::string & configureStr app->parse_from_stream(file); break; } - case fileops::ConfigType::TOML_STRING: - { + case fileops::ConfigType::TOML_STRING: { app->allow_extras(); - auto dptr = std::static_pointer_cast(app->get_config_formatter_base()); + auto dptr = + std::static_pointer_cast(app->get_config_formatter_base()); if (dptr) { dptr->skipJson(true); } @@ -386,45 +381,40 @@ std::pair extractCoreType(const std::string & configureStr break; case fileops::ConfigType::NONE: break; - } - } - catch (const std::exception&) - { - corestring.clear(); } - if (corestring.empty()) - { - return { CoreType::DEFAULT,namestring }; - } - return { coreTypeFromString(corestring),namestring }; } + catch (const std::exception&) { + corestring.clear(); + } + if (corestring.empty()) { + return {CoreType::DEFAULT, namestring}; + } + return {coreTypeFromString(corestring), namestring}; +} -std::pair extractCoreType(const std::vector& args) +std::pair extractCoreType(const std::vector& args) { std::string corestring; std::string namestring; - auto app=makeCLITypeApp(corestring,namestring); - auto vec=args; + auto app = makeCLITypeApp(corestring, namestring); + auto vec = args; app->helics_parse(vec); - if (corestring.empty()) - { - return { CoreType::DEFAULT,namestring }; + if (corestring.empty()) { + return {CoreType::DEFAULT, namestring}; } - return { coreTypeFromString(corestring),namestring }; - + return {coreTypeFromString(corestring), namestring}; } -std::pair extractCoreType(int argc, char* argv[]) +std::pair extractCoreType(int argc, char* argv[]) { std::string corestring; std::string namestring; - auto app=makeCLITypeApp(corestring,namestring); - app->helics_parse(argc,argv); - if (corestring.empty()) - { - return { CoreType::DEFAULT,namestring }; + auto app = makeCLITypeApp(corestring, namestring); + app->helics_parse(argc, argv); + if (corestring.empty()) { + return {CoreType::DEFAULT, namestring}; } - return { coreTypeFromString(corestring),namestring }; + return {coreTypeFromString(corestring), namestring}; } } // namespace helics::core diff --git a/src/helics/core/coreTypeOperations.hpp b/src/helics/core/coreTypeOperations.hpp index c09827987a..93a95d6fb7 100644 --- a/src/helics/core/coreTypeOperations.hpp +++ b/src/helics/core/coreTypeOperations.hpp @@ -41,11 +41,9 @@ bool matchingTypes(std::string_view type1, std::string_view type2); /** generate an extended version and system info string in json format*/ std::string systemInfo(); - /** methods to extract the core type and name from various forms of arguments*/ -std::pair extractCoreType(const std::string &configureString); -std::pair extractCoreType(const std::vector &args); -std::pair extractCoreType(int argc, char *argv[]); - +std::pair extractCoreType(const std::string& configureString); +std::pair extractCoreType(const std::vector& args); +std::pair extractCoreType(int argc, char* argv[]); } // namespace helics::core diff --git a/src/helics/helics_enums.h b/src/helics/helics_enums.h index e69985fd23..7a2913dbe6 100644 --- a/src/helics/helics_enums.h +++ b/src/helics/helics_enums.h @@ -60,7 +60,7 @@ typedef enum { /* NOLINT */ calls*/ HELICS_CORE_TYPE_EMPTY = 77, /** core type specification to allow extraction from later arguments or files*/ - HELICS_CORE_TYPE_EXTRACT=101 + HELICS_CORE_TYPE_EXTRACT = 101 } HelicsCoreTypes; /** enumeration of allowable data types for publications and inputs*/ diff --git a/src/helics/shared_api_library/helicsCore.h b/src/helics/shared_api_library/helicsCore.h index 2a59c26409..4d4a5d4ba2 100644 --- a/src/helics/shared_api_library/helicsCore.h +++ b/src/helics/shared_api_library/helicsCore.h @@ -110,7 +110,8 @@ HELICS_EXPORT HelicsBool helicsIsCoreTypeAvailable(const char* type); * @param type The type of the core to create. * @param name The name of the core. It can be a nullptr or empty string to have a name automatically assigned. * @param initString An initialization string to send to the core. The format is similar to command line arguments. - * Typical options include a broker name, the broker address, the number of federates, etc. Can also be a file(toml,ini,json) or json object containing the core configuration + * Typical options include a broker name, the broker address, the number of federates, etc. Can also be a + file(toml,ini,json) or json object containing the core configuration * * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. diff --git a/tests/helics/core/BrokerClassTests.cpp b/tests/helics/core/BrokerClassTests.cpp index eabdf4e763..20fd1a8018 100644 --- a/tests/helics/core/BrokerClassTests.cpp +++ b/tests/helics/core/BrokerClassTests.cpp @@ -89,20 +89,21 @@ TEST(brokers, subbroker_min) brk->disconnect(); EXPECT_TRUE(brk3->waitForDisconnect()); - } - /** test the assignment and retrieval of global value from a broker object*/ TEST(brokers, subbroker_min_files) { auto brk = helics::BrokerFactory::create(helics::CoreType::EXTRACT, - "", - std::string(TEST_DIR)+"broker_test_subbroker.json"); + "", + std::string(TEST_DIR) + "broker_test_subbroker.json"); - EXPECT_EQ(brk->getIdentifier(),"gbroker_f1"); + EXPECT_EQ(brk->getIdentifier(), "gbroker_f1"); - auto brk2 = helics::BrokerFactory::create(helics::CoreType::EXTRACT, "", std::string(TEST_DIR)+"broker_test_subbroker2.toml"); + auto brk2 = + helics::BrokerFactory::create(helics::CoreType::EXTRACT, + "", + std::string(TEST_DIR) + "broker_test_subbroker2.toml"); auto cr1 = helics::CoreFactory::create(helics::CoreType::TEST, "--name=cf1 --broker=gbf2"); @@ -120,7 +121,8 @@ TEST(brokers, subbroker_min_files) // this should not allow initializingMode entry since only 1 subbroker EXPECT_EQ(res, std::future_status::timeout); - auto cr2 = helics::CoreFactory::create(helics::CoreType::EXTRACT,std::string(TEST_DIR)+"broker_test_core.json"); + auto cr2 = helics::CoreFactory::create(helics::CoreType::EXTRACT, + std::string(TEST_DIR) + "broker_test_core.json"); auto fid3 = cr2->registerFederate("fed3", cf1); auto fut3 = @@ -130,7 +132,9 @@ TEST(brokers, subbroker_min_files) // this should still not allow initializingMode entry since still only 1 subbroker EXPECT_EQ(res, std::future_status::timeout); - auto brk3 = helics::BrokerFactory::create(helics::CoreType::TEST, "gbf3", "{\"broker\":\"gbroker_f1\"}"); + auto brk3 = helics::BrokerFactory::create(helics::CoreType::TEST, + "gbf3", + "{\"broker\":\"gbroker_f1\"}"); auto cr3 = helics::CoreFactory::create(helics::CoreType::TEST, "cf3", "broker=\"gbf3\""); auto fid4 = cr3->registerFederate("fed4", cf1); diff --git a/tests/helics/test_files/broker_test_core.json b/tests/helics/test_files/broker_test_core.json index 3233a72d96..b19900a635 100644 --- a/tests/helics/test_files/broker_test_core.json +++ b/tests/helics/test_files/broker_test_core.json @@ -1,5 +1,5 @@ { -"name":"cf2", -"coretype":"test", -"broker":"gbf2" -} \ No newline at end of file + "name": "cf2", + "coretype": "test", + "broker": "gbf2" +} diff --git a/tests/helics/test_files/broker_test_subbroker.json b/tests/helics/test_files/broker_test_subbroker.json index e3fd913bc1..5902af95c1 100644 --- a/tests/helics/test_files/broker_test_subbroker.json +++ b/tests/helics/test_files/broker_test_subbroker.json @@ -1,7 +1,7 @@ { -"name":"gbroker_f1", -"coretype":"test", -"sub_brokers":2, -"federates":2, -"root":true -} \ No newline at end of file + "name": "gbroker_f1", + "coretype": "test", + "sub_brokers": 2, + "federates": 2, + "root": true +} diff --git a/tests/helics/test_files/broker_test_subbroker2.toml b/tests/helics/test_files/broker_test_subbroker2.toml index 712a2ee3d6..e43346aa83 100644 --- a/tests/helics/test_files/broker_test_subbroker2.toml +++ b/tests/helics/test_files/broker_test_subbroker2.toml @@ -1,4 +1,4 @@ name="gbf2" coretype="test" sub_brokers=2 -broker="gbroker_f1" \ No newline at end of file +broker="gbroker_f1" From 8a05a32e22ec139ef8dc63780568d121f7c693ec Mon Sep 17 00:00:00 2001 From: Philip Top Date: Sun, 24 Nov 2024 14:33:28 -0800 Subject: [PATCH 04/11] cpplint fixes --- src/helics/core/coreTypeOperations.cpp | 47 ++++++++++++++------------ src/helics/core/coreTypeOperations.hpp | 1 + tests/helics/core/BrokerClassTests.cpp | 1 + 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/helics/core/coreTypeOperations.cpp b/src/helics/core/coreTypeOperations.cpp index 1ccc9a1c8d..34d6d1e352 100644 --- a/src/helics/core/coreTypeOperations.cpp +++ b/src/helics/core/coreTypeOperations.cpp @@ -22,6 +22,9 @@ SPDX-License-Identifier: BSD-3-Clause #include #include #include +#include +#include +#include namespace frozen { template<> @@ -315,24 +318,24 @@ bool matchingTypes(std::string_view type1, std::string_view type2) namespace { std::unique_ptr makeCLITypeApp(std::string& corestring, std::string& namestring) { - auto app = std::make_unique("type extraction app"); - app->remove_helics_specifics(); - app->option_defaults()->ignore_case()->ignore_underscore(); - app->allow_config_extras(CLI::config_extras_mode::ignore_all); - app->allow_extras(); - app->set_config("--config-file,--config,config", - "helicsConfig.ini", - "specify a configuration file"); + auto app = std::make_unique("type extraction app"); + app->remove_helics_specifics(); + app->option_defaults()->ignore_case()->ignore_underscore(); + app->allow_config_extras(CLI::config_extras_mode::ignore_all); + app->allow_extras(); + app->set_config("--config-file,--config,config", + "helicsConfig.ini", + "specify a configuration file"); app->add_option("--name,--identifier", namestring); - auto* fmtr = addJsonConfig(app.get()); - fmtr->maxLayers(0); - fmtr->promoteSection("helics"); - auto* networking = app->add_option_group("network type")->immediate_callback(); + auto* fmtr = addJsonConfig(app.get()); + fmtr->maxLayers(0); + fmtr->promoteSection("helics"); + auto* networking = app->add_option_group("network type")->immediate_callback(); networking->add_option("--core", corestring); networking->add_option("--coretype,-t", corestring)->envname("HELICS_CORE_TYPE"); - app->add_subcommand("broker")->fallthrough(); - app->add_subcommand("core")->fallthrough(); - return app; + app->add_subcommand("broker")->fallthrough(); + app->add_subcommand("core")->fallthrough(); + return app; } } // namespace @@ -341,9 +344,9 @@ std::pair extractCoreType(const std::string& configureStr std::string corestring; std::string namestring; auto app = makeCLITypeApp(corestring, namestring); - auto type = fileops::getConfigType(configureString); - try { - switch (type) { + auto type = fileops::getConfigType(configureString); + try { + switch (type) { case fileops::ConfigType::JSON_FILE: { std::ifstream file{configureString}; app->parse_from_stream(file); @@ -381,14 +384,14 @@ std::pair extractCoreType(const std::string& configureStr break; case fileops::ConfigType::NONE: break; + } } - } catch (const std::exception&) { - corestring.clear(); - } + corestring.clear(); + } if (corestring.empty()) { return {CoreType::DEFAULT, namestring}; - } + } return {coreTypeFromString(corestring), namestring}; } diff --git a/src/helics/core/coreTypeOperations.hpp b/src/helics/core/coreTypeOperations.hpp index 93a95d6fb7..96e29a9b21 100644 --- a/src/helics/core/coreTypeOperations.hpp +++ b/src/helics/core/coreTypeOperations.hpp @@ -10,6 +10,7 @@ SPDX-License-Identifier: BSD-3-Clause #include #include #include +#include /** @file @details function definitions for operations on core types diff --git a/tests/helics/core/BrokerClassTests.cpp b/tests/helics/core/BrokerClassTests.cpp index 20fd1a8018..ce09ddf975 100644 --- a/tests/helics/core/BrokerClassTests.cpp +++ b/tests/helics/core/BrokerClassTests.cpp @@ -12,6 +12,7 @@ SPDX-License-Identifier: BSD-3-Clause #include "gtest/gtest.h" #include +#include /** test the assignment and retrieval of global value from a broker object*/ TEST(brokers, global_value) From b6774b80332efde5abbe4cc2e968afbf185e6d15 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Mon, 25 Nov 2024 05:07:26 -0800 Subject: [PATCH 05/11] fix system tests --- src/helics/core/BrokerBase.cpp | 8 ++++---- src/helics/core/CoreFactory.cpp | 2 +- src/helics/core/coreTypeOperations.cpp | 7 +++---- tests/helics/core/BrokerClassTests.cpp | 2 +- tests/helics/system_tests/ErrorTests.cpp | 7 ++++--- tests/helics/system_tests/networkTests.cpp | 9 +++++---- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/helics/core/BrokerBase.cpp b/src/helics/core/BrokerBase.cpp index 4e2fbc67f4..bfac325bcc 100644 --- a/src/helics/core/BrokerBase.cpp +++ b/src/helics/core/BrokerBase.cpp @@ -83,7 +83,7 @@ BrokerBase::~BrokerBase() joinAllThreads(); } catch (...) { - // no exceptions in the destructor + ;// no exceptions in the destructor } } } @@ -376,9 +376,9 @@ int BrokerBase::parseArgs(std::string_view initializationString) } break; case fileops::ConfigType::CMD_LINE: - break; case fileops::ConfigType::NONE: - return 0; + //with NONE there are default command line and environment possibilities + break; } auto app = generateBaseCLI(); @@ -842,7 +842,7 @@ static void bbase->addActionMessage(CMD_TICK); } catch (std::exception& e) { - std::cerr << "exception caught from addActionMessage" << e.what() << std::endl; + std::cerr << "exception caught from addActionMessage" << e.what() << '\n'; } } else { ActionMessage tick(CMD_TICK); diff --git a/src/helics/core/CoreFactory.cpp b/src/helics/core/CoreFactory.cpp index 4dd4201901..4ea28bb2a6 100644 --- a/src/helics/core/CoreFactory.cpp +++ b/src/helics/core/CoreFactory.cpp @@ -171,7 +171,7 @@ std::shared_ptr std::shared_ptr create(std::vector args) { - return create(CoreType::EXTRACT, gHelicsEmptyString, args); + return create(CoreType::EXTRACT, gHelicsEmptyString, std::move(args)); } std::shared_ptr create(CoreType type, std::vector args) diff --git a/src/helics/core/coreTypeOperations.cpp b/src/helics/core/coreTypeOperations.cpp index 34d6d1e352..192f64494c 100644 --- a/src/helics/core/coreTypeOperations.cpp +++ b/src/helics/core/coreTypeOperations.cpp @@ -71,7 +71,7 @@ std::string to_string(CoreType type) case CoreType::EMPTY: return "empty_"; default: - return std::string(); + return {}; } } static constexpr frozen::unordered_map coreTypes{ @@ -323,9 +323,8 @@ namespace { app->option_defaults()->ignore_case()->ignore_underscore(); app->allow_config_extras(CLI::config_extras_mode::ignore_all); app->allow_extras(); - app->set_config("--config-file,--config,config", - "helicsConfig.ini", - "specify a configuration file"); + app->set_config("--config-file,--config", + ""); app->add_option("--name,--identifier", namestring); auto* fmtr = addJsonConfig(app.get()); fmtr->maxLayers(0); diff --git a/tests/helics/core/BrokerClassTests.cpp b/tests/helics/core/BrokerClassTests.cpp index ce09ddf975..9e48f68892 100644 --- a/tests/helics/core/BrokerClassTests.cpp +++ b/tests/helics/core/BrokerClassTests.cpp @@ -135,7 +135,7 @@ TEST(brokers, subbroker_min_files) auto brk3 = helics::BrokerFactory::create(helics::CoreType::TEST, "gbf3", - "{\"broker\":\"gbroker_f1\"}"); + R"({"broker":"gbroker_f1"})"); auto cr3 = helics::CoreFactory::create(helics::CoreType::TEST, "cf3", "broker=\"gbf3\""); auto fid4 = cr3->registerFederate("fed4", cf1); diff --git a/tests/helics/system_tests/ErrorTests.cpp b/tests/helics/system_tests/ErrorTests.cpp index 03dd2ef5e5..2ad6c39bf8 100644 --- a/tests/helics/system_tests/ErrorTests.cpp +++ b/tests/helics/system_tests/ErrorTests.cpp @@ -597,11 +597,12 @@ TEST_F(error_tests, missing_required_ept) class error_tests_type: public ::testing::TestWithParam, public FederateTestFixture {}; /** test simple creation and destruction*/ -TEST_P(error_tests_type, test_duplicate_broker_name) +TEST_P(error_tests_type, duplicate_broker_name) { - auto broker = AddBroker(GetParam(), "--name=brk1"); + std::string bname=std::string("brk_dup_")+GetParam(); + auto broker = AddBroker(GetParam(), std::string("--name=")+bname); EXPECT_TRUE(broker->isConnected()); - EXPECT_THROW(AddBroker(GetParam(), "--name=brk1 --timeout=500"), helics::RegistrationFailure); + EXPECT_THROW(AddBroker(GetParam(), std::string("--name=")+bname+" --timeout=500"), helics::RegistrationFailure); broker->disconnect(); helics::cleanupHelicsLibrary(); } diff --git a/tests/helics/system_tests/networkTests.cpp b/tests/helics/system_tests/networkTests.cpp index 6f800298a6..510da2893f 100644 --- a/tests/helics/system_tests/networkTests.cpp +++ b/tests/helics/system_tests/networkTests.cpp @@ -158,7 +158,7 @@ TEST_F(network_tests, test_otherport2) } } -TEST_F(network_tests, test_otherport_fail) +TEST_F(network_tests, otherport_fail) { const std::string brokerArgs = "--local_interface=tcp://127.0.0.1:33100"; auto broker = helics::BrokerFactory::create(helics::CoreType::ZMQ, brokerArgs); @@ -172,17 +172,18 @@ TEST_F(network_tests, test_otherport_fail) } } -TEST_F(network_tests, test_otherport_env) +TEST_F(network_tests, otherport_env) { setEnvironmentVariable("HELICS_CONNECTION_PORT", "33102"); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); const std::string brokerArgs = "-f 2"; auto broker = helics::BrokerFactory::create(helics::CoreType::ZMQ, brokerArgs); EXPECT_TRUE(broker->isConnected()); - helics::FederateInfo fedInfo("--core_type=ZMQ --corename=c1"); + helics::FederateInfo fedInfo("--core_type=ZMQ --corename=cop1"); helics::ValueFederate fed1("fed1", fedInfo); - helics::FederateInfo fi2("--core_type=ZMQ --broker=tcp://127.0.0.1:33102 --corename=c2"); + helics::FederateInfo fi2("--core_type=ZMQ --broker=tcp://127.0.0.1:33102 --corename=cop2"); helics::ValueFederate fed2("fed2", fi2); fed2.enterExecutingModeAsync(); From 8005190994b687241f6aecf84c00d3a98ecc5ec9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:09:10 +0000 Subject: [PATCH 06/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/helics/core/BrokerBase.cpp | 4 +-- src/helics/core/coreTypeOperations.cpp | 45 ++++++++++++------------ src/helics/core/coreTypeOperations.hpp | 2 +- tests/helics/core/BrokerClassTests.cpp | 5 ++- tests/helics/system_tests/ErrorTests.cpp | 7 ++-- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/helics/core/BrokerBase.cpp b/src/helics/core/BrokerBase.cpp index bfac325bcc..57eae392a3 100644 --- a/src/helics/core/BrokerBase.cpp +++ b/src/helics/core/BrokerBase.cpp @@ -83,7 +83,7 @@ BrokerBase::~BrokerBase() joinAllThreads(); } catch (...) { - ;// no exceptions in the destructor + ; // no exceptions in the destructor } } } @@ -377,7 +377,7 @@ int BrokerBase::parseArgs(std::string_view initializationString) break; case fileops::ConfigType::CMD_LINE: case fileops::ConfigType::NONE: - //with NONE there are default command line and environment possibilities + // with NONE there are default command line and environment possibilities break; } diff --git a/src/helics/core/coreTypeOperations.cpp b/src/helics/core/coreTypeOperations.cpp index 192f64494c..11536cb2b8 100644 --- a/src/helics/core/coreTypeOperations.cpp +++ b/src/helics/core/coreTypeOperations.cpp @@ -19,12 +19,12 @@ SPDX-License-Identifier: BSD-3-Clause #include #include #include +#include #include #include #include -#include -#include #include +#include namespace frozen { template<> @@ -318,23 +318,22 @@ bool matchingTypes(std::string_view type1, std::string_view type2) namespace { std::unique_ptr makeCLITypeApp(std::string& corestring, std::string& namestring) { - auto app = std::make_unique("type extraction app"); - app->remove_helics_specifics(); - app->option_defaults()->ignore_case()->ignore_underscore(); - app->allow_config_extras(CLI::config_extras_mode::ignore_all); - app->allow_extras(); - app->set_config("--config-file,--config", - ""); + auto app = std::make_unique("type extraction app"); + app->remove_helics_specifics(); + app->option_defaults()->ignore_case()->ignore_underscore(); + app->allow_config_extras(CLI::config_extras_mode::ignore_all); + app->allow_extras(); + app->set_config("--config-file,--config", ""); app->add_option("--name,--identifier", namestring); - auto* fmtr = addJsonConfig(app.get()); - fmtr->maxLayers(0); - fmtr->promoteSection("helics"); - auto* networking = app->add_option_group("network type")->immediate_callback(); + auto* fmtr = addJsonConfig(app.get()); + fmtr->maxLayers(0); + fmtr->promoteSection("helics"); + auto* networking = app->add_option_group("network type")->immediate_callback(); networking->add_option("--core", corestring); networking->add_option("--coretype,-t", corestring)->envname("HELICS_CORE_TYPE"); - app->add_subcommand("broker")->fallthrough(); - app->add_subcommand("core")->fallthrough(); - return app; + app->add_subcommand("broker")->fallthrough(); + app->add_subcommand("core")->fallthrough(); + return app; } } // namespace @@ -343,9 +342,9 @@ std::pair extractCoreType(const std::string& configureStr std::string corestring; std::string namestring; auto app = makeCLITypeApp(corestring, namestring); - auto type = fileops::getConfigType(configureString); - try { - switch (type) { + auto type = fileops::getConfigType(configureString); + try { + switch (type) { case fileops::ConfigType::JSON_FILE: { std::ifstream file{configureString}; app->parse_from_stream(file); @@ -383,14 +382,14 @@ std::pair extractCoreType(const std::string& configureStr break; case fileops::ConfigType::NONE: break; - } } + } catch (const std::exception&) { - corestring.clear(); - } + corestring.clear(); + } if (corestring.empty()) { return {CoreType::DEFAULT, namestring}; - } + } return {coreTypeFromString(corestring), namestring}; } diff --git a/src/helics/core/coreTypeOperations.hpp b/src/helics/core/coreTypeOperations.hpp index 96e29a9b21..0502436d45 100644 --- a/src/helics/core/coreTypeOperations.hpp +++ b/src/helics/core/coreTypeOperations.hpp @@ -9,8 +9,8 @@ SPDX-License-Identifier: BSD-3-Clause #include #include -#include #include +#include /** @file @details function definitions for operations on core types diff --git a/tests/helics/core/BrokerClassTests.cpp b/tests/helics/core/BrokerClassTests.cpp index 9e48f68892..fa3beb767e 100644 --- a/tests/helics/core/BrokerClassTests.cpp +++ b/tests/helics/core/BrokerClassTests.cpp @@ -133,9 +133,8 @@ TEST(brokers, subbroker_min_files) // this should still not allow initializingMode entry since still only 1 subbroker EXPECT_EQ(res, std::future_status::timeout); - auto brk3 = helics::BrokerFactory::create(helics::CoreType::TEST, - "gbf3", - R"({"broker":"gbroker_f1"})"); + auto brk3 = + helics::BrokerFactory::create(helics::CoreType::TEST, "gbf3", R"({"broker":"gbroker_f1"})"); auto cr3 = helics::CoreFactory::create(helics::CoreType::TEST, "cf3", "broker=\"gbf3\""); auto fid4 = cr3->registerFederate("fed4", cf1); diff --git a/tests/helics/system_tests/ErrorTests.cpp b/tests/helics/system_tests/ErrorTests.cpp index 2ad6c39bf8..852ed481d5 100644 --- a/tests/helics/system_tests/ErrorTests.cpp +++ b/tests/helics/system_tests/ErrorTests.cpp @@ -599,10 +599,11 @@ class error_tests_type: public ::testing::TestWithParam, public Fed /** test simple creation and destruction*/ TEST_P(error_tests_type, duplicate_broker_name) { - std::string bname=std::string("brk_dup_")+GetParam(); - auto broker = AddBroker(GetParam(), std::string("--name=")+bname); + std::string bname = std::string("brk_dup_") + GetParam(); + auto broker = AddBroker(GetParam(), std::string("--name=") + bname); EXPECT_TRUE(broker->isConnected()); - EXPECT_THROW(AddBroker(GetParam(), std::string("--name=")+bname+" --timeout=500"), helics::RegistrationFailure); + EXPECT_THROW(AddBroker(GetParam(), std::string("--name=") + bname + " --timeout=500"), + helics::RegistrationFailure); broker->disconnect(); helics::cleanupHelicsLibrary(); } From bcbdff23fe21f26c6dfb2180a3da266da39aaad0 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Mon, 25 Nov 2024 07:54:30 -0800 Subject: [PATCH 07/11] Test file pass through for globals and connections --- src/helics/core/BrokerBase.cpp | 1 + src/helics/core/CommonCore.cpp | 20 +++++++++-- src/helics/core/CoreBroker.cpp | 21 ++++++++++-- .../helics/application_api/FederateTests.cpp | 33 +++++++++++++++++++ tests/helics/system_tests/ErrorTests.cpp | 12 +++---- .../test_files/example_global_broker.json | 11 +++++++ 6 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 tests/helics/test_files/example_global_broker.json diff --git a/src/helics/core/BrokerBase.cpp b/src/helics/core/BrokerBase.cpp index 57eae392a3..2e68a55217 100644 --- a/src/helics/core/BrokerBase.cpp +++ b/src/helics/core/BrokerBase.cpp @@ -601,6 +601,7 @@ void BrokerBase::writeProfilingData() prBuff->writeFile(); } catch (const std::ios_base::failure&) { + sendToLogger(parent_broker_id,LogLevels::ERROR_LEVEL,identifier,"Unable to write profiling buffer data"); } } } diff --git a/src/helics/core/CommonCore.cpp b/src/helics/core/CommonCore.cpp index ae5eda64b2..59aefab566 100644 --- a/src/helics/core/CommonCore.cpp +++ b/src/helics/core/CommonCore.cpp @@ -163,6 +163,10 @@ bool CommonCore::connect() transmit(parent_route_id, reg); setBrokerState(BrokerState::CONNECTED); disconnection.activate(); + if (!configString.empty()) + { + makeConnections(configString); + } } else { setBrokerState(BrokerState::CONFIGURED); } @@ -2017,10 +2021,20 @@ InterfaceHandle CommonCore::getTranslator(std::string_view name) const void CommonCore::makeConnections(const std::string& file) { - if (fileops::hasTomlExtension(file)) { - fileops::makeConnectionsToml(this, file); - } else { + auto type = fileops::getConfigType(file); + + switch (type) { + case fileops::ConfigType::JSON_FILE: + case fileops::ConfigType::JSON_STRING: fileops::makeConnectionsJson(this, file); + break; + case fileops::ConfigType::TOML_FILE: + case fileops::ConfigType::TOML_STRING: + fileops::makeConnectionsToml(this, file); + case fileops::ConfigType::CMD_LINE: + case fileops::ConfigType::NONE: + // with NONE there are default command line and environment possibilities + break; } } diff --git a/src/helics/core/CoreBroker.cpp b/src/helics/core/CoreBroker.cpp index 3c9222badd..b96bc3b450 100644 --- a/src/helics/core/CoreBroker.cpp +++ b/src/helics/core/CoreBroker.cpp @@ -169,10 +169,20 @@ bool CoreBroker::verifyBrokerKey(std::string_view key) const void CoreBroker::makeConnections(const std::string& file) { - if (fileops::hasTomlExtension(file)) { - fileops::makeConnectionsToml(this, file); - } else { + auto type = fileops::getConfigType(file); + + switch (type) { + case fileops::ConfigType::JSON_FILE: + case fileops::ConfigType::JSON_STRING: fileops::makeConnectionsJson(this, file); + break; + case fileops::ConfigType::TOML_FILE: + case fileops::ConfigType::TOML_STRING: + fileops::makeConnectionsToml(this, file); + case fileops::ConfigType::CMD_LINE: + case fileops::ConfigType::NONE: + // with NONE there are default command line and environment possibilities + break; } } @@ -2409,6 +2419,10 @@ bool CoreBroker::connect() fmt::format("Broker {} connected on {}", getIdentifier(), getAddress())); + if (!configString.empty()) + { + makeConnections(configString); + } } else { setBrokerState(BrokerState::CONFIGURED); } @@ -2419,6 +2433,7 @@ bool CoreBroker::connect() std::this_thread::sleep_for(std::chrono::milliseconds(20)); } } + } return isConnected(); } diff --git a/tests/helics/application_api/FederateTests.cpp b/tests/helics/application_api/FederateTests.cpp index ffdf31c502..217d2ba89f 100644 --- a/tests/helics/application_api/FederateTests.cpp +++ b/tests/helics/application_api/FederateTests.cpp @@ -1440,6 +1440,39 @@ TEST_P(FederateGlobalFiles, global_file_ci_skip) brk->waitForDisconnect(); } +TEST(federate, broker_global_file_ci_skip) +{ + auto testFile = std::string(TEST_DIR) + "example_global_broker.json"; + auto brk = helics::BrokerFactory::create(helics::CoreType::EXTRACT, "", testFile); + brk->connect(); + + helics::FederateInfo fedInfo(CORE_TYPE_TO_TEST); + fedInfo.coreName = "core_globalc"; + fedInfo.coreInitString = "-f 2 --broker=brk_globalb"; + + auto Fed1 = std::make_shared("fed1", fedInfo); + + auto Fed2 = std::make_shared("fed2", fedInfo); + + Fed1->enterInitializingModeAsync(); + Fed2->enterInitializingMode(); + + Fed1->enterInitializingModeComplete(); + + auto str1 = Fed1->query("global_value", "global1"); + EXPECT_EQ(str1, "this is a global1 value"); + str1 = Fed2->query("global_value", "global1"); + EXPECT_EQ(str1, "this is a global1 value"); + + str1 = Fed1->query("global_value", "global2"); + EXPECT_EQ(str1, "this is another global value"); + str1 = Fed2->query("global_value", "global2"); + EXPECT_EQ(str1, "this is another global value"); + Fed1->finalize(); + Fed2->finalize(); + brk->waitForDisconnect(); +} + TEST_P(FederateGlobalFiles, core_global_file_ci_skip) { auto brk = helics::BrokerFactory::create(helics::CoreType::TEST, "b1", "-f2"); diff --git a/tests/helics/system_tests/ErrorTests.cpp b/tests/helics/system_tests/ErrorTests.cpp index 852ed481d5..6c6f21b354 100644 --- a/tests/helics/system_tests/ErrorTests.cpp +++ b/tests/helics/system_tests/ErrorTests.cpp @@ -147,8 +147,8 @@ TEST_F(error_tests, single_thread_fed) EXPECT_THROW(fed1->requestTimeAsync(3.2), helics::InvalidFunctionCall); EXPECT_THROW(fed1->requestTimeComplete(), helics::InvalidFunctionCall); - auto t1 = fed1->requestTime(2.0); - EXPECT_EQ(t1, 2.0); + auto time = fed1->requestTime(2.0); + EXPECT_EQ(time, 2.0); EXPECT_THROW(fed1->requestTimeIterativeAsync(3.2, helics::IterationRequest::FORCE_ITERATION), helics::InvalidFunctionCall); @@ -483,8 +483,8 @@ TEST_F(error_tests, missing_required_pub) auto fed2 = GetFederateAs(1); fed1->registerGlobalPublication("t1", ""); - auto& i2 = fed2->registerSubscription("abcd", ""); - i2.setOption(helics::defs::Options::CONNECTION_REQUIRED); + auto& sub1 = fed2->registerSubscription("abcd", ""); + sub1.setOption(helics::defs::Options::CONNECTION_REQUIRED); fed1->enterInitializingModeAsync(); EXPECT_THROW(fed2->enterInitializingMode(), helics::ConnectionFailure); @@ -584,8 +584,8 @@ TEST_F(error_tests, missing_required_ept) auto fed2 = GetFederateAs(1); fed1->registerGlobalTargetedEndpoint("t1", ""); - auto& e2 = fed2->registerGlobalTargetedEndpoint("abcd", ""); - e2.setOption(helics::defs::Options::CONNECTION_REQUIRED); + auto& ept2 = fed2->registerGlobalTargetedEndpoint("abcd", ""); + ept2.setOption(helics::defs::Options::CONNECTION_REQUIRED); fed1->enterInitializingModeAsync(); EXPECT_THROW(fed2->enterInitializingMode(), helics::ConnectionFailure); diff --git a/tests/helics/test_files/example_global_broker.json b/tests/helics/test_files/example_global_broker.json new file mode 100644 index 0000000000..a464f1c6b3 --- /dev/null +++ b/tests/helics/test_files/example_global_broker.json @@ -0,0 +1,11 @@ +//this should be a valid json file (except comments are not recognized in standard JSON) +{ +"coretype":"test", +"federates":2, +"name":"brk_globalb", + //example json file with globals [, ] + "globals": [ + ["global1", "this is a global1 value"], + ["global2", "this is another global value"] + ] +} From ba9605d6946387499928cf3cd7c6a146df3a8914 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:55:05 +0000 Subject: [PATCH 08/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/helics/core/BrokerBase.cpp | 5 +++- src/helics/core/CommonCore.cpp | 25 +++++++++--------- src/helics/core/CoreBroker.cpp | 26 +++++++++---------- .../test_files/example_global_broker.json | 6 ++--- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/helics/core/BrokerBase.cpp b/src/helics/core/BrokerBase.cpp index 2e68a55217..76e61c2add 100644 --- a/src/helics/core/BrokerBase.cpp +++ b/src/helics/core/BrokerBase.cpp @@ -601,7 +601,10 @@ void BrokerBase::writeProfilingData() prBuff->writeFile(); } catch (const std::ios_base::failure&) { - sendToLogger(parent_broker_id,LogLevels::ERROR_LEVEL,identifier,"Unable to write profiling buffer data"); + sendToLogger(parent_broker_id, + LogLevels::ERROR_LEVEL, + identifier, + "Unable to write profiling buffer data"); } } } diff --git a/src/helics/core/CommonCore.cpp b/src/helics/core/CommonCore.cpp index 59aefab566..effe9bed72 100644 --- a/src/helics/core/CommonCore.cpp +++ b/src/helics/core/CommonCore.cpp @@ -163,8 +163,7 @@ bool CommonCore::connect() transmit(parent_route_id, reg); setBrokerState(BrokerState::CONNECTED); disconnection.activate(); - if (!configString.empty()) - { + if (!configString.empty()) { makeConnections(configString); } } else { @@ -2024,17 +2023,17 @@ void CommonCore::makeConnections(const std::string& file) auto type = fileops::getConfigType(file); switch (type) { - case fileops::ConfigType::JSON_FILE: - case fileops::ConfigType::JSON_STRING: - fileops::makeConnectionsJson(this, file); - break; - case fileops::ConfigType::TOML_FILE: - case fileops::ConfigType::TOML_STRING: - fileops::makeConnectionsToml(this, file); - case fileops::ConfigType::CMD_LINE: - case fileops::ConfigType::NONE: - // with NONE there are default command line and environment possibilities - break; + case fileops::ConfigType::JSON_FILE: + case fileops::ConfigType::JSON_STRING: + fileops::makeConnectionsJson(this, file); + break; + case fileops::ConfigType::TOML_FILE: + case fileops::ConfigType::TOML_STRING: + fileops::makeConnectionsToml(this, file); + case fileops::ConfigType::CMD_LINE: + case fileops::ConfigType::NONE: + // with NONE there are default command line and environment possibilities + break; } } diff --git a/src/helics/core/CoreBroker.cpp b/src/helics/core/CoreBroker.cpp index b96bc3b450..addc9b5612 100644 --- a/src/helics/core/CoreBroker.cpp +++ b/src/helics/core/CoreBroker.cpp @@ -172,17 +172,17 @@ void CoreBroker::makeConnections(const std::string& file) auto type = fileops::getConfigType(file); switch (type) { - case fileops::ConfigType::JSON_FILE: - case fileops::ConfigType::JSON_STRING: - fileops::makeConnectionsJson(this, file); - break; - case fileops::ConfigType::TOML_FILE: - case fileops::ConfigType::TOML_STRING: - fileops::makeConnectionsToml(this, file); - case fileops::ConfigType::CMD_LINE: - case fileops::ConfigType::NONE: - // with NONE there are default command line and environment possibilities - break; + case fileops::ConfigType::JSON_FILE: + case fileops::ConfigType::JSON_STRING: + fileops::makeConnectionsJson(this, file); + break; + case fileops::ConfigType::TOML_FILE: + case fileops::ConfigType::TOML_STRING: + fileops::makeConnectionsToml(this, file); + case fileops::ConfigType::CMD_LINE: + case fileops::ConfigType::NONE: + // with NONE there are default command line and environment possibilities + break; } } @@ -2419,8 +2419,7 @@ bool CoreBroker::connect() fmt::format("Broker {} connected on {}", getIdentifier(), getAddress())); - if (!configString.empty()) - { + if (!configString.empty()) { makeConnections(configString); } } else { @@ -2433,7 +2432,6 @@ bool CoreBroker::connect() std::this_thread::sleep_for(std::chrono::milliseconds(20)); } } - } return isConnected(); } diff --git a/tests/helics/test_files/example_global_broker.json b/tests/helics/test_files/example_global_broker.json index a464f1c6b3..f4b60b7a40 100644 --- a/tests/helics/test_files/example_global_broker.json +++ b/tests/helics/test_files/example_global_broker.json @@ -1,8 +1,8 @@ //this should be a valid json file (except comments are not recognized in standard JSON) { -"coretype":"test", -"federates":2, -"name":"brk_globalb", + "coretype": "test", + "federates": 2, + "name": "brk_globalb", //example json file with globals [, ] "globals": [ ["global1", "this is a global1 value"], From 575213bf2fc5c115effd78834d2c159a2a1189bf Mon Sep 17 00:00:00 2001 From: Philip Top Date: Tue, 26 Nov 2024 06:11:55 -0800 Subject: [PATCH 09/11] make some includes system includes --- CMakeLists.txt | 12 +++++++----- config/cmake/addBoost.cmake | 2 +- src/helics/apps/CMakeLists.txt | 6 +++++- tests/helics/CMakeLists.txt | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d08dcd14cc..b4352bf4e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -488,15 +488,17 @@ target_include_directories( INTERFACE $ $ $/${CMAKE_INSTALL_INCLUDE_DIR}> - $ - $ - $ - $ + ) # the utilities/gmlc is to account for the transfer of the header to a known location on install target_include_directories( - helics_base SYSTEM INTERFACE $ + helics_base + SYSTEM INTERFACE $ + $ + $ + $ + $ ) target_link_libraries(helics_base INTERFACE toml11::toml11) diff --git a/config/cmake/addBoost.cmake b/config/cmake/addBoost.cmake index 6a9abc3f6e..ef6ae1ca50 100644 --- a/config/cmake/addBoost.cmake +++ b/config/cmake/addBoost.cmake @@ -163,7 +163,7 @@ if(NOT Boost_FOUND) if(Boost_VERSION_MINOR GREATER_EQUAL ${BOOST_MINIMUM_VERSION}) add_library(Boost::headers INTERFACE IMPORTED) set_target_properties( - Boost::headers PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIR}" + Boost::headers PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIR}" ) add_library(Boost::boost INTERFACE IMPORTED) set_target_properties(Boost::boost PROPERTIES INTERFACE_LINK_LIBRARIES Boost::headers) diff --git a/src/helics/apps/CMakeLists.txt b/src/helics/apps/CMakeLists.txt index a9c122efa3..613e51cadc 100644 --- a/src/helics/apps/CMakeLists.txt +++ b/src/helics/apps/CMakeLists.txt @@ -190,11 +190,15 @@ if(HELICS_BUILD_APP_LIBRARY) target_include_directories( helicscpp-apps INTERFACE $ - $ $/${CMAKE_INSTALL_INCLUDEDIR}> PRIVATE $ ) + target_include_directories( + helicscpp-apps + SYSTEM INTERFACE $ + ) + set_target_properties( helicscpp-apps PROPERTIES VERSION ${HELICS_VERSION} SOVERSION ${HELICS_VERSION_MAJOR} ) diff --git a/tests/helics/CMakeLists.txt b/tests/helics/CMakeLists.txt index ba39cfed93..188348c44f 100644 --- a/tests/helics/CMakeLists.txt +++ b/tests/helics/CMakeLists.txt @@ -15,7 +15,7 @@ include(AddGoogletest) add_library(helics_test_base INTERFACE) target_link_libraries(helics_test_base INTERFACE gtest gtest_main gmock) target_link_libraries(helics_test_base INTERFACE compile_flags_target spdlog::spdlog) -target_include_directories(helics_test_base INTERFACE ${PROJECT_SOURCE_DIR}/ThirdParty) +target_include_directories(helics_test_base SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/ThirdParty) add_subdirectory(core) add_subdirectory(network) From 48111b365c8d0311e55a08d8e6d8debcd8ac0ef8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:12:32 +0000 Subject: [PATCH 10/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CMakeLists.txt | 5 ++--- config/cmake/addBoost.cmake | 3 ++- src/helics/apps/CMakeLists.txt | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4352bf4e1..26cd020d8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -488,13 +488,12 @@ target_include_directories( INTERFACE $ $ $/${CMAKE_INSTALL_INCLUDE_DIR}> - ) # the utilities/gmlc is to account for the transfer of the header to a known location on install target_include_directories( - helics_base - SYSTEM INTERFACE $ + helics_base SYSTEM + INTERFACE $ $ $ $ diff --git a/config/cmake/addBoost.cmake b/config/cmake/addBoost.cmake index ef6ae1ca50..88a812187e 100644 --- a/config/cmake/addBoost.cmake +++ b/config/cmake/addBoost.cmake @@ -163,7 +163,8 @@ if(NOT Boost_FOUND) if(Boost_VERSION_MINOR GREATER_EQUAL ${BOOST_MINIMUM_VERSION}) add_library(Boost::headers INTERFACE IMPORTED) set_target_properties( - Boost::headers PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIR}" + Boost::headers PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES + "${Boost_INCLUDE_DIR}" ) add_library(Boost::boost INTERFACE IMPORTED) set_target_properties(Boost::boost PROPERTIES INTERFACE_LINK_LIBRARIES Boost::headers) diff --git a/src/helics/apps/CMakeLists.txt b/src/helics/apps/CMakeLists.txt index 613e51cadc..ef51b51075 100644 --- a/src/helics/apps/CMakeLists.txt +++ b/src/helics/apps/CMakeLists.txt @@ -195,8 +195,7 @@ if(HELICS_BUILD_APP_LIBRARY) ) target_include_directories( - helicscpp-apps - SYSTEM INTERFACE $ + helicscpp-apps SYSTEM INTERFACE $ ) set_target_properties( From 8bf700b23f222372b103a522ee8268bad4138cba Mon Sep 17 00:00:00 2001 From: Philip Top Date: Tue, 26 Nov 2024 09:17:50 -0800 Subject: [PATCH 11/11] Apply suggestions from code review Co-authored-by: Ryan Mast <3969255+nightlark@users.noreply.github.com> --- src/helics/shared_api_library/helicsCore.h | 4 ++-- tests/helics/system_tests/ErrorTests.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/helics/shared_api_library/helicsCore.h b/src/helics/shared_api_library/helicsCore.h index 4d4a5d4ba2..f565bbdf6b 100644 --- a/src/helics/shared_api_library/helicsCore.h +++ b/src/helics/shared_api_library/helicsCore.h @@ -111,7 +111,7 @@ HELICS_EXPORT HelicsBool helicsIsCoreTypeAvailable(const char* type); * @param name The name of the core. It can be a nullptr or empty string to have a name automatically assigned. * @param initString An initialization string to send to the core. The format is similar to command line arguments. * Typical options include a broker name, the broker address, the number of federates, etc. Can also be a - file(toml,ini,json) or json object containing the core configuration + * file (toml, ini, json) or json object containing the core configuration. * * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. @@ -167,7 +167,7 @@ HELICS_EXPORT HelicsBool helicsCoreIsValid(HelicsCore core); * @param name The name of the broker. It can be a nullptr or empty string to have a name automatically assigned. * @param initString An initialization string to send to the core-the format is similar to command line arguments. * Typical options include a broker address such as --broker="XSSAF" if this is a subbroker, or the number of federates, - * can also be a json or toml file with broker configuration + * or it can also be a json or toml file with broker configuration. * or the address. * * @param[in,out] err An error object that will contain an error code and string if any error occurred during the execution of the function. diff --git a/tests/helics/system_tests/ErrorTests.cpp b/tests/helics/system_tests/ErrorTests.cpp index 6c6f21b354..88c0887403 100644 --- a/tests/helics/system_tests/ErrorTests.cpp +++ b/tests/helics/system_tests/ErrorTests.cpp @@ -584,8 +584,8 @@ TEST_F(error_tests, missing_required_ept) auto fed2 = GetFederateAs(1); fed1->registerGlobalTargetedEndpoint("t1", ""); - auto& ept2 = fed2->registerGlobalTargetedEndpoint("abcd", ""); - ept2.setOption(helics::defs::Options::CONNECTION_REQUIRED); + auto& ept1 = fed2->registerGlobalTargetedEndpoint("abcd", ""); + ept1.setOption(helics::defs::Options::CONNECTION_REQUIRED); fed1->enterInitializingModeAsync(); EXPECT_THROW(fed2->enterInitializingMode(), helics::ConnectionFailure);