diff --git a/CMakeLists.txt b/CMakeLists.txt index 40abce24..350021f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -450,7 +450,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") set(CMAKE_CXX_FLAGS_RELEASE "/Zi -DNDEBUG -DYGG_DEBUG${BUILD_FLAGS}${YGG_BUILD_FLAGS}") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Zi -DNDEBUG -DYGG_DEBUG${BUILD_FLAGS}${YGG_BUILD_FLAGS}") else () - set(CMAKE_CXX_FLAGS_DEBUG "-g -DNDEBUG -DYGG_DEBUG${BUILD_FLAGS}${YGG_BUILD_FLAGS} ") + set(CMAKE_CXX_FLAGS_DEBUG "-g3 -ggdb -DYGG_DEBUG${BUILD_FLAGS}${YGG_BUILD_FLAGS} ") set(CMAKE_CXX_FLAGS_RELEASE "-g -DNDEBUG -DYGG_DEBUG${BUILD_FLAGS}${YGG_BUILD_FLAGS} ") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -DNDEBUG -DYGG_DEBUG${BUILD_FLAGS}${YGG_BUILD_FLAGS} ") endif () @@ -535,7 +535,7 @@ if(YGG_ENABLE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang|A set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-instr-generate -fcoverage-mapping") else() - target_link_libraries(YggInterface PRIVATE gcov) + target_link_libraries(${YGG_TARGET_CPP} PRIVATE gcov) set(CTEST_COVERAGE_COMMAND "gcov") set(CTEST_COVERAGE_EXTRA_FLAGS "") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-inline-small-functions -fno-default-inline") @@ -562,8 +562,8 @@ if(YGG_BUILD_TESTS) set(SUBLIBFILE ${CMAKE_BINARY_DIR}/library_path.txt) add_custom_command( OUTPUT ${SUBLIBFILE} - COMMAND echo "$" > "${SUBLIBFILE}" - DEPENDS YggInterface + COMMAND echo "$" > "${SUBLIBFILE}" + DEPENDS ${YGG_TARGET_CPP} VERBATIM) add_custom_target(make_sublib ALL DEPENDS ${SUBLIBFILE}) diff --git a/communication/communicators/AsyncComm.cpp b/communication/communicators/AsyncComm.cpp index 5b0f1dfe..34031842 100644 --- a/communication/communicators/AsyncComm.cpp +++ b/communication/communicators/AsyncComm.cpp @@ -34,13 +34,14 @@ bool AsyncBacklog::on_thread(Comm_t* parent) { { const std::lock_guard comm_lock(comm_mutex); int flgs_comm = (parent->getFlags() & ~COMM_FLAG_ASYNC) | COMM_FLAG_ASYNC_WRAPPED; + Address addr(parent->getAddress()); comm = new_Comm_t(direction, parent->getCommType(), parent->getName(), - new utils::Address(parent->getAddress()), + addr, flgs_comm); parent->updateMaxMsgSize(comm->getMaxMsgSize()); - parent->address->address(comm->getAddress()); + parent->address.address(comm->getAddress()); parent->updateMsgBufSize(comm->getMsgBufSize()); parent->getFlags() |= (comm->getFlags() & ~flgs_comm); opened.store(true); @@ -138,7 +139,7 @@ AsyncLockGuard::~AsyncLockGuard() { /////////////// AsyncComm::AsyncComm(const std::string name, - utils::Address *address, + utils::Address& address, const DIRECTION direction, int flgs, const COMM_TYPE type) : CommBase(name, address, direction, type, flgs | COMM_FLAG_ASYNC) { @@ -153,9 +154,17 @@ AsyncComm::AsyncComm(const std::string name, AsyncComm::AsyncComm(const std::string nme, const DIRECTION dirn, int flgs, const COMM_TYPE type) : - AsyncComm(nme, nullptr, dirn, flgs, type) {} + CommBase(nme, dirn, type, flgs | COMM_FLAG_ASYNC) { + if (type == SERVER_COMM) + this->direction = RECV; + else if (type == CLIENT_COMM) + this->direction = SEND; + if (!global_comm) { + handle = new AsyncBacklog(this); + } +} -AsyncComm::AsyncComm(utils::Address *addr, +AsyncComm::AsyncComm(utils::Address &addr, const DIRECTION dirn, int flgs, const COMM_TYPE type) : AsyncComm("", addr, dirn, flgs, type) {} @@ -251,7 +260,7 @@ bool AsyncComm::create_header_send(Header& header) { return handle->comm->create_header_send(header); } -Comm_t* AsyncComm::create_worker(utils::Address* address, +Comm_t* AsyncComm::create_worker(utils::Address& address, const DIRECTION& dir, int flgs) { return new AsyncComm("", address, dir, flgs | COMM_FLAG_WORKER, type); } diff --git a/communication/communicators/AsyncComm.hpp b/communication/communicators/AsyncComm.hpp index b028afa5..59b99065 100644 --- a/communication/communicators/AsyncComm.hpp +++ b/communication/communicators/AsyncComm.hpp @@ -51,14 +51,14 @@ namespace communication { * @param flgs Bitwise flags describing the communicator * @param type Enumerated communicator type **/ - explicit AsyncComm(const std::string name = "", - utils::Address *address = new utils::Address(), + explicit AsyncComm(const std::string name, + utils::Address& address, const DIRECTION direction = NONE, int flgs = 0, const COMM_TYPE type = DEFAULT_COMM); explicit AsyncComm(const std::string nme, const DIRECTION dirn, int flgs = 0, const COMM_TYPE type = DEFAULT_COMM); - explicit AsyncComm(utils::Address *addr, + explicit AsyncComm(utils::Address &addr, const DIRECTION dirn, int flgs = 0, const COMM_TYPE type = DEFAULT_COMM); @@ -81,7 +81,7 @@ namespace communication { int send_single(utils::Header& header) override; long recv_single(utils::Header& header) override; bool create_header_send(utils::Header& header) override; - Comm_t* create_worker(utils::Address* address, + Comm_t* create_worker(utils::Address& address, const DIRECTION& dir, int flgs) override; }; diff --git a/communication/communicators/ClientComm.cpp b/communication/communicators/ClientComm.cpp index b221727f..052b0715 100644 --- a/communication/communicators/ClientComm.cpp +++ b/communication/communicators/ClientComm.cpp @@ -8,16 +8,23 @@ using namespace communication::utils; unsigned ClientComm::_client_rand_seeded = 0; -ClientComm::ClientComm(const std::string nme, Address *addr, +ClientComm::ClientComm(const std::string nme, Address& addr, int flgs, const COMM_TYPE type) : RPCComm(nme, addr, flgs | COMM_FLAG_CLIENT | COMM_ALWAYS_SEND_HEADER, SEND, RECV, type) { // Called to create temp comm for send/recv - if (!(global_comm || (name.empty() && address && address->valid()))) + if (!(global_comm || (name.empty() && address.valid()))) init(); } +ClientComm::ClientComm(const std::string nme, int flgs, const COMM_TYPE type) : + RPCComm(nme, flgs | COMM_FLAG_CLIENT | COMM_ALWAYS_SEND_HEADER, + SEND, RECV, type) { + if (!(global_comm || (name.empty() && address.valid()))) + init(); +} + ADD_CONSTRUCTORS_RPC_DEF(ClientComm) void ClientComm::set_timeout_recv(int new_timeout) { @@ -44,7 +51,7 @@ void ClientComm::init() { } } YGG_THREAD_SAFE_END; if (name.empty()) { - this->name = "client_request." + this->address->address(); + this->name = "client_request." + this->address.address(); } } @@ -91,7 +98,7 @@ bool ClientComm::signon(const Header& header, Comm_t* async_comm) { ygglog_debug << "ClientComm(" << name << ")::signon: Received response to signon" << std::endl; break; } else { - ygglog_debug << "ClientComm(" << name << ")::signon: No response to signon (address = " << requests.activeComm()->address->address() << "), sleeping" << std::endl; + ygglog_debug << "ClientComm(" << name << ")::signon: No response to signon (address = " << requests.activeComm()->address.address() << "), sleeping" << std::endl; // Sleep outside lock on async if (flags & COMM_FLAG_ASYNC_WRAPPED) return true; @@ -185,7 +192,7 @@ long ClientComm::recv_single(utils::Header& header) { requests.transferSchemaFrom(response_comm); } } else { - ygglog_debug << "ClientComm(" << name << ")::recv_single: No response to oldest request (address = " << response_comm->address->address() << "), sleeping" << std::endl; + ygglog_debug << "ClientComm(" << name << ")::recv_single: No response to oldest request (address = " << response_comm->address.address() << "), sleeping" << std::endl; std::this_thread::sleep_for(std::chrono::microseconds(YGG_SLEEP_TIME)); } diff --git a/communication/communicators/ClientComm.hpp b/communication/communicators/ClientComm.hpp index 2985518d..23dde7fb 100644 --- a/communication/communicators/ClientComm.hpp +++ b/communication/communicators/ClientComm.hpp @@ -19,8 +19,8 @@ class ClientComm : public RPCComm { * then an address will be created. * @param flgs Bitwise flags describing the communicator */ - explicit ClientComm(const std::string name = "", - utils::Address *address = nullptr, + explicit ClientComm(const std::string name, + utils::Address &address, int flgs = 0, const COMM_TYPE type = CLIENT_COMM); ADD_CONSTRUCTORS_RPC(ClientComm, CLIENT_COMM) diff --git a/communication/communicators/CommBase.cpp b/communication/communicators/CommBase.cpp index 9764fdce..23f7d460 100644 --- a/communication/communicators/CommBase.cpp +++ b/communication/communicators/CommBase.cpp @@ -58,7 +58,9 @@ void Comm_t::_ygg_cleanup() { ZMQContext::destroy(); #endif #ifndef YGGDRASIL_DISABLE_PYTHON_C_API +#ifndef YGG_TEST rapidjson::finalize_python("_ygg_cleanup"); +#endif // YGG_TEST #endif // YGGDRASIL_DISABLE_PYTHON_C_API } YGG_THREAD_SAFE_END; #ifndef YGG_TEST @@ -80,47 +82,56 @@ void Comm_t::_ygg_cleanup() { int Comm_t::_ygg_initialized = 0; int Comm_t::_ygg_finalized = 0; -Comm_t::Comm_t(const std::string &nme, Address *addr, +void Comm_t::init() { + _ygg_init(); + + flags |= COMM_FLAG_VALID; + if (direction == NONE) + flags &= ~COMM_FLAG_VALID; + + thread_id = get_thread_id(); + char *allow_threading = getenv("YGG_THREADING"); + if (allow_threading) + flags |= COMM_ALLOW_MULTIPLE_COMMS; + char *model_name = std::getenv("YGG_MODEL_NAME"); + if (model_name) { + std::string prefix(model_name); + prefix += ":"; + if (name.rfind(prefix, 0) != 0) { + prefix += name; + name = prefix; + } + } + + get_global_scope_comm(); + + Comm_t::register_comm(this); + + if (!address.valid()) { + address = addressFromEnv(name, direction); + if ((flags & COMM_FLAG_INTERFACE) && (!address.valid())) { + ygglog_error << "CommBase: " << name << " not registered as environment variable.\n" << std::endl; + flags &= ~COMM_FLAG_VALID; + } + } + ygglog_debug << "CommBase(" << name << "): Done" << std::endl; +} +Comm_t::Comm_t(const std::string &nme, Address &addr, DIRECTION dirn, const COMM_TYPE &t, int flgs) : type(t), name(nme), address(addr), direction(dirn), flags(flgs), maxMsgSize(COMM_BASE_MAX_MSG_SIZE), msgBufSize(0), index_in_register(-1), thread_id(-1), metadata(), timeout_recv(YGG_MAX_TIME), workers(), global_comm(nullptr) { + init(); +} - _ygg_init(); - - flags |= COMM_FLAG_VALID; - if (direction == NONE) - flags &= ~COMM_FLAG_VALID; - - thread_id = get_thread_id(); - char *allow_threading = getenv("YGG_THREADING"); - if (allow_threading) - flags |= COMM_ALLOW_MULTIPLE_COMMS; - char *model_name = std::getenv("YGG_MODEL_NAME"); - if (model_name) { - std::string prefix(model_name); - prefix += ":"; - if (name.rfind(prefix, 0) != 0) { - prefix += name; - name = prefix; - } - } - - get_global_scope_comm(); - - Comm_t::register_comm(this); - - if (!(address && address->valid())) { - if (address) - delete address; - address = addressFromEnv(name, direction); - if ((flags & COMM_FLAG_INTERFACE) && (!address->valid())) { - ygglog_error << "CommBase: " << name << " not registered as environment variable.\n" << std::endl; - flags &= ~COMM_FLAG_VALID; - } - } - ygglog_debug << "CommBase(" << name << "): Done" << std::endl; +Comm_t::Comm_t(const std::string &nme, + DIRECTION dirn, const COMM_TYPE &t, int flgs) : + type(t), name(nme), direction(dirn), flags(flgs), + maxMsgSize(COMM_BASE_MAX_MSG_SIZE), msgBufSize(0), + index_in_register(-1), thread_id(-1), metadata(), + timeout_recv(YGG_MAX_TIME), workers(), global_comm(nullptr) { + init(); } Comm_t::~Comm_t() { @@ -129,8 +140,7 @@ Comm_t::~Comm_t() { Comm_t::registry[index_in_register] = NULL; } YGG_THREAD_SAFE_END; ygglog_debug << "~Comm_t: Started" << std::endl; - if (address) - delete address; + ygglog_debug << "~Comm_t: Finished" << std::endl; } @@ -159,7 +169,6 @@ bool Comm_t::get_global_scope_comm() { if (!model_name) model_name = std::getenv("YGG_SERVER_INPUT"); } - assert(model_name); if (model_name) global_name.assign(model_name); global_scope_comm = 1; @@ -179,9 +188,9 @@ bool Comm_t::get_global_scope_comm() { if (!global_comm) { ygglog_debug << "CommBase: Creating global comm \"" << global_name << "\"" << std::endl; - Address* global_address = new Address(); - if (address) - global_address->address(address->address()); + Address global_address; + if (address.valid()) + global_address.address(address.address()); global_comm = new_Comm_t(global_direction, global_type, global_name, global_address, flags | COMM_FLAG_GLOBAL); ygglog_debug << "CommBase: Created global comm \"" << global_name @@ -190,9 +199,7 @@ bool Comm_t::get_global_scope_comm() { ygglog_debug << "CommBase: Found global comm \"" << global_name << "\"" << std::endl; } - if (!address) - address = new Address(); - address->address(global_comm->address->address()); + address.address(global_comm->address.address()); flags = global_comm->flags & ~COMM_FLAG_GLOBAL; if (is_server) global_scope_comm = 0; @@ -228,21 +235,24 @@ bool Comm_t::check_size(const size_t &len) const { } Comm_t* communication::communicator::new_Comm_t(const DIRECTION dir, const COMM_TYPE type, const std::string &name, char* address, int flags) { - Address* addr = nullptr; + Address addr; if (address) - addr = new Address(address); - else - addr = new Address(); + addr.address(address); return communication::communicator::new_Comm_t(dir, type, name, addr, flags); } -Comm_t* communication::communicator::new_Comm_t(const DIRECTION dir, const COMM_TYPE type, const std::string &name, Address* addr, int flags) { + +Comm_t* communication::communicator::new_Comm_t(const DIRECTION dir, const COMM_TYPE type, const std::string &name, int flags) { + Address addr; + return communication::communicator::new_Comm_t(dir, type, name, addr, flags); +} + +Comm_t* communication::communicator::new_Comm_t(const DIRECTION dir, const COMM_TYPE type, const std::string &name, Address &addr, int flags) { flags |= COMM_FLAG_DELETE; if (flags & COMM_FLAG_ASYNC) { return new AsyncComm(name, addr, dir, flags, type); } switch(type) { case NULL_COMM: - delete addr; break; case DEFAULT_COMM: return new COMM_BASE(name, addr, dir, flags); @@ -285,8 +295,8 @@ Comm_t* Comm_t::create_worker_send(Header& head) { // return global_comm->create_worker_send(head); assert(!global_comm); Comm_t* worker = workers.get(this, SEND); - if (worker && worker->address) { - head.SetMetaString("address", worker->address->address()); + if (worker && worker->address.valid()) { + head.SetMetaString("address", worker->address.address()); } return worker; } @@ -298,8 +308,8 @@ Comm_t* Comm_t::create_worker_recv(Header& head) { assert(!global_comm); ygglog_debug << "CommBase(" << name << ")::create_worker_recv: begin" << std::endl; try { - const char* address = head.GetMetaString("address"); - Address* adr = new Address(address); + const char* address_str = head.GetMetaString("address"); + Address adr(address_str); return workers.get(this, RECV, adr); } catch (...) { return nullptr; @@ -313,7 +323,7 @@ int Comm_t::send(const char *data, const size_t &len) { ygglog_debug << "CommBase(" << name << ")::send: Attempt to send though a communicator set up to receive" << std::endl; return -1; } - ygglog_debug << "CommBase(" << name << ")::send: Sending " << len << " bytes to " << address->address() << std::endl; + ygglog_debug << "CommBase(" << name << ")::send: Sending " << len << " bytes to " << address.address() << std::endl; if (is_closed()) { ygglog_error << "CommBase(" << name << ")::send: Communicator closed." << std::endl; return -1; @@ -353,7 +363,7 @@ int Comm_t::send(const char *data, const size_t &len) { ygglog_error << "CommBase(" << name << ")::send: send interupted at " << head.offset << " of " << head.size_curr << " bytes" << std::endl; return -1; } - ygglog_debug << "CommBase(" << name << ")::send: " << head.offset << " of " << head.size_curr << " bytes sent to " << address->address() << std::endl; + ygglog_debug << "CommBase(" << name << ")::send: " << head.offset << " of " << head.size_curr << " bytes sent to " << address.address() << std::endl; } ygglog_debug << "CommBase(" << name << ")::send: returns " << head.size_curr << std::endl; setFlags(head, SEND); @@ -394,7 +404,7 @@ long Comm_t::recv(char*& data, const size_t &len, bool allow_realloc) { if (global_comm) return global_comm->recv(data, len, allow_realloc); - ygglog_debug << "CommBase(" << name << ")::recv: Receiving from " << address->address() << std::endl; + ygglog_debug << "CommBase(" << name << ")::recv: Receiving from " << address.address() << std::endl; if (direction != RECV && type != CLIENT_COMM) { ygglog_debug << "CommBase(" << name << ")::recv: Attempt to receive from communicator set up to send" << std::endl; return -1; @@ -404,7 +414,7 @@ long Comm_t::recv(char*& data, const size_t &len, if (!allow_realloc) { char* tmp = NULL; size_t tmp_len = 0; - long ret = recv(tmp, tmp_len, true); + ret = recv(tmp, tmp_len, true); if (ret >= 0 || ret == -2) { if (ret >= 0) { tmp_len = static_cast(ret); @@ -480,7 +490,7 @@ long Comm_t::recv(char*& data, const size_t &len, update_datatype(head.schema[0], RECV); } } - ygglog_debug << "CommBase(" << name << ")::recv: Received " << head.size_curr << " bytes from " << address->address() << std::endl; + ygglog_debug << "CommBase(" << name << ")::recv: Received " << head.size_curr << " bytes from " << address.address() << std::endl; ret = head.size_data; setFlags(head, RECV); return ret; diff --git a/communication/communicators/CommBase.hpp b/communication/communicators/CommBase.hpp index e7d1c28d..09683b61 100644 --- a/communication/communicators/CommBase.hpp +++ b/communication/communicators/CommBase.hpp @@ -47,7 +47,7 @@ const int COMM_FLAG_RPC = COMM_FLAG_SERVER | COMM_FLAG_CLIENT; explicit T ## Comm(const std::string nme, \ const DIRECTION dirn, \ int flgs = 0, const COMM_TYPE type = T ## _COMM); \ - explicit T ## Comm(utils::Address *addr, \ + explicit T ## Comm(utils::Address &addr, \ const DIRECTION dirn, \ int flgs = 0, const COMM_TYPE type = T ## _COMM); \ static bool isInstalled() { return T ## _INSTALLED_FLAG; } \ @@ -61,36 +61,29 @@ const int COMM_FLAG_RPC = COMM_FLAG_SERVER | COMM_FLAG_CLIENT; } #define ADD_CONSTRUCTORS_DEF(cls) \ - cls::cls(const std::string nme, \ - const DIRECTION dirn, \ - int flgs, const COMM_TYPE type) : \ - cls(nme, nullptr, dirn, flgs, type) {} \ - cls::cls(utils::Address *addr, \ + cls::cls(utils::Address &addr, \ const DIRECTION dirn, \ int flgs, const COMM_TYPE type) : \ cls("", addr, dirn, flgs, type) {} #define ADD_CONSTRUCTORS_RPC(cls, defT) \ explicit cls(const std::string nme, \ int flgs = 0, const COMM_TYPE type = defT); \ - explicit cls(utils::Address *addr, \ + explicit cls(utils::Address &addr, \ int flgs = 0, const COMM_TYPE type = defT); #define ADD_CONSTRUCTORS_RPC_DEF(cls) \ - cls::cls(const std::string nme, \ - int flgs, const COMM_TYPE type) : \ - cls(nme, nullptr, flgs, type) {} \ - cls::cls(utils::Address *addr, \ + cls::cls(utils::Address &addr, \ int flgs, const COMM_TYPE type) : \ cls("", addr, flgs, type) {} #define WORKER_METHOD_DECS(cls) \ - Comm_t* create_worker(utils::Address* address, \ + Comm_t* create_worker(utils::Address& address, \ const DIRECTION&, int flgs) override #define WORKER_METHOD_DEFS(cls) \ - Comm_t* cls::create_worker(utils::Address* address, \ + Comm_t* cls::create_worker(utils::Address& address, \ const DIRECTION& dir, int flgs) { \ return new cls("", address, dir, flgs | COMM_FLAG_WORKER); \ } #define WORKER_METHOD_DUMMY(cls, abbr) \ - Comm_t* cls::create_worker(utils::Address*, \ + Comm_t* cls::create_worker(utils::Address&, \ const DIRECTION&, int) { \ abbr ## _install_error(); \ return NULL; \ @@ -514,9 +507,9 @@ class Comm_t { @returns Address. */ std::string getAddress() const { - if (address) - return address->address(); - return ""; + if (address.valid()) + return address.address(); + return ""; } /*! @brief Get the communicator's direction. @@ -562,6 +555,7 @@ class Comm_t { int deserialize(const char* buf, rapidjson::VarArgList& ap); int serialize(char*& buf, size_t& buf_siz, rapidjson::VarArgList& ap); + void init(); protected: friend AsyncComm; @@ -602,9 +596,9 @@ class Comm_t { } } - static utils::Address* addressFromEnv(const std::string& name, + static utils::Address addressFromEnv(const std::string& name, DIRECTION direction) { - utils::Address* out = new utils::Address(); + utils::Address out; if (name.empty()) return out; std::string full_name; @@ -620,22 +614,22 @@ class Comm_t { } char *addr = std::getenv(full_name.c_str()); if (!addr) { - std::string temp_name(full_name); - size_t loc; - while ((loc = temp_name.find(":")) != std::string::npos) { - temp_name.replace(loc, 1, "__COLON__"); - } - addr = getenv(temp_name.c_str()); + std::string temp_name(full_name); + size_t loc; + while ((loc = temp_name.find(":")) != std::string::npos) { + temp_name.replace(loc, 1, "__COLON__"); + } + addr = getenv(temp_name.c_str()); } - std::string addr_str = "null"; - if (addr) - addr_str.assign(addr_str); - ygglog_debug << "CommBase::addressFromEnv: full_name = " << - full_name << ", address = " << addr_str << std::endl; - ygglog_debug << std::endl; - if (addr) - out->address(addr); - return out; + std::string addr_str = "null"; + if (addr) + addr_str.assign(addr_str); + ygglog_debug << "CommBase::addressFromEnv: full_name = " << + full_name << ", address = " << addr_str << std::endl; + ygglog_debug << std::endl; + if (addr) + out.address(addr); + return out; } int update_datatype(const rapidjson::Value& new_schema, @@ -664,7 +658,7 @@ class Comm_t { rapidjson::Value& getSchema(const DIRECTION dir=NONE) { return getMetadata(dir).getSchema(); } - virtual Comm_t* create_worker(utils::Address* address, + virtual Comm_t* create_worker(utils::Address& address, const DIRECTION&, int flgs) VIRT_END; virtual Comm_t* create_worker_send(utils::Header& head); virtual Comm_t* create_worker_recv(utils::Header& head); @@ -691,10 +685,12 @@ class Comm_t { * @see utils::Address() */ explicit Comm_t(const std::string &name, - utils::Address *address = nullptr, + utils::Address &address, DIRECTION direction = NONE, const COMM_TYPE &t = NULL_COMM, int flgs = 0); + Comm_t(const std::string& name, DIRECTION direction = NONE, + const COMM_TYPE &t = NULL_COMM, int flgs = 0); /** * Checks the size of the message to see if it exceeds the maximum allowable size as define by YGG_MSG_MAX * @param len The length of the message to check @@ -705,7 +701,7 @@ class Comm_t { COMM_TYPE type; //!< Comm type. //void *other; //!< Pointer to additional information for the comm. std::string name; //!< Comm name. - utils::Address *address; //!< Comm address. + utils::Address address; //!< Comm address. DIRECTION direction; //!< send or recv for direction messages will go. int flags; //!< Flags describing the status of the comm. size_t maxMsgSize; //!< The maximum message size. @@ -737,7 +733,8 @@ class Comm_t { * @return */ Comm_t* new_Comm_t(const DIRECTION dir, const COMM_TYPE type, const std::string &name="", char* address=nullptr, int flags=0); -Comm_t* new_Comm_t(const DIRECTION dir, const COMM_TYPE type, const std::string &name, utils::Address* address, int flags=0); +Comm_t* new_Comm_t(const DIRECTION dir, const COMM_TYPE type, const std::string &name, utils::Address& address, int flags=0); +Comm_t* new_Comm_t(const DIRECTION dir, const COMM_TYPE type, const std::string &name, int flags=0); /** * Determine if a communicator type is installed. @@ -794,9 +791,12 @@ class CommBase : public Comm_t { * @param t The enumerated type of the communicator * @param flags Bitwise flags describing the communicator */ - explicit CommBase(const std::string &name, utils::Address *address = nullptr, DIRECTION direction = NONE, const COMM_TYPE &t = NULL_COMM, int flags = 0); + explicit CommBase(const std::string &name, utils::Address& address, DIRECTION direction = NONE, const COMM_TYPE &t = NULL_COMM, int flags = 0); - Comm_t* create_worker(utils::Address*, const DIRECTION&, + CommBase(const std::string &name, DIRECTION direction = NONE, + const COMM_TYPE &t = NULL_COMM, int flags = 0); + + Comm_t* create_worker(utils::Address&, const DIRECTION&, int) override { utils::ygglog_throw_error("create_worker of base class called, must be overridden"); return NULL; // GCOVR_EXCL_LINE @@ -825,13 +825,21 @@ class CommBase : public Comm_t { }; template -CommBase::CommBase(const std::string &nme, utils::Address *addr, +CommBase::CommBase(const std::string &nme, utils::Address &addr, DIRECTION dirn, const COMM_TYPE &t, int flgs) : Comm_t(nme, addr, dirn, t, flgs), handle(nullptr) { if (global_comm) handle = dynamic_cast*>(global_comm)->handle; } +template +CommBase::CommBase(const std::string &nme, DIRECTION dirn, + const COMM_TYPE &t, int flgs) : + Comm_t(nme, dirn, t, flgs), handle(nullptr) { + if (global_comm) + handle = dynamic_cast *>(global_comm)->handle; +} + template void CommBase::close() { if (handle) { diff --git a/communication/communicators/IPCComm.cpp b/communication/communicators/IPCComm.cpp index ad9e6419..4cb66157 100644 --- a/communication/communicators/IPCComm.cpp +++ b/communication/communicators/IPCComm.cpp @@ -9,13 +9,19 @@ unsigned IPCComm::_yggChannelsUsed = 0; int IPCComm::_yggChannelNames[_yggTrackChannels]; bool IPCComm::_ipc_rand_seeded = false; -IPCComm::IPCComm(const std::string name, Address *address, +IPCComm::IPCComm(const std::string name, Address& address, DIRECTION direction, int flgs, const COMM_TYPE type) : CommBase(name, address, direction, type, flgs) { if (!global_comm) init(); } +IPCComm::IPCComm(const std::string nme, const DIRECTION dirn, + int flgs, const COMM_TYPE type) : + CommBase(nme, dirn, type, flgs) { + if (!global_comm) + init(); +} ADD_CONSTRUCTORS_DEF(IPCComm) @@ -24,7 +30,7 @@ ADD_CONSTRUCTORS_DEF(IPCComm) void IPCComm::init() { updateMaxMsgSize(2048); int key = 0; - bool created = ((!address) || address->address().empty()); + bool created = ((!address.valid()) || address.address().empty()); if (created) { YGG_THREAD_SAFE_BEGIN(ipc) { if (!_ipc_rand_seeded) { @@ -35,16 +41,12 @@ void IPCComm::init() { while (key == 0 || check_key(key) < 0) { key = std::rand(); } - if (!address) { - address = new utils::Address(std::to_string(key)); - } else { - address->address(std::to_string(key)); - } + address.address(std::to_string(key)); } else { - key = this->address->key(); + key = this->address.key(); } if (name.empty()) { - this->name = "tempnewIPC." + this->address->address(); + this->name = "tempnewIPC." + this->address.address(); } else { this->name = name; } @@ -63,7 +65,7 @@ void IPCComm::init() { } handle = fid; add_channel(); - ygglog_debug << "IPCComm(" << name << ")::init: address = " << this->address->address() << ", created = " << created << std::endl; + ygglog_debug << "IPCComm(" << name << ")::init: address = " << this->address.address() << ", created = " << created << std::endl; } void IPCComm::close() { @@ -113,7 +115,7 @@ void IPCComm::add_channel() { if (IPCComm::_yggChannelsUsed++ >= _yggTrackChannels) { ygglog_error << "Too many channels in use, max: " << _yggTrackChannels << std::endl; } - IPCComm::_yggChannelNames[IPCComm::_yggChannelsUsed] = address->key(); + IPCComm::_yggChannelNames[IPCComm::_yggChannelsUsed] = address.key(); } YGG_THREAD_SAFE_END; } @@ -133,7 +135,7 @@ int IPCComm::remove_comm(bool close_comm) { } // ret = -1; unsigned i; - int ich = address->key(); + int ich = address.key(); YGG_THREAD_SAFE_BEGIN(ipc) { for (i = 0; i < IPCComm::_yggChannelsUsed; i++) { if (ich == IPCComm::_yggChannelNames[i]) { diff --git a/communication/communicators/IPCComm.hpp b/communication/communicators/IPCComm.hpp index 10afe958..67708309 100644 --- a/communication/communicators/IPCComm.hpp +++ b/communication/communicators/IPCComm.hpp @@ -35,10 +35,10 @@ class IPCComm : public CommBase { * @param direction Enuerated direction for this instance * @param flags Bitwise flags describing the communicator */ - explicit IPCComm(const std::string name = "", - utils::Address *address = new utils::Address(), - const DIRECTION direction = NONE, - int flgs = 0, const COMM_TYPE type = IPC_COMM); + IPCComm(const std::string name, + utils::Address& address, + const DIRECTION direction = NONE, + int flgs = 0, const COMM_TYPE type = IPC_COMM); ADD_CONSTRUCTORS(IPC) #ifdef IPCINSTALLED diff --git a/communication/communicators/MPIComm.cpp b/communication/communicators/MPIComm.cpp index acd2c2c9..7bf688c3 100644 --- a/communication/communicators/MPIComm.cpp +++ b/communication/communicators/MPIComm.cpp @@ -50,7 +50,7 @@ void mpi_registry_t::CheckReturn(int code, std::string method, int rank) const { ygglog_error << method << "(" << tag << "): Invalid count" << std::endl; } -MPIComm::MPIComm(const std::string name, utils::Address *address, +MPIComm::MPIComm(const std::string name, utils::Address& address, const DIRECTION direction, int flgs, const COMM_TYPE type) : CommBase(name, address, direction, type, flgs) { @@ -58,6 +58,14 @@ MPIComm::MPIComm(const std::string name, utils::Address *address, init(); } +MPIComm::MPIComm(const std::string name, + const DIRECTION direction, int flgs, + const COMM_TYPE type) : + CommBase(name, direction, type, flgs) { + if (!global_comm) + init(); +} + ADD_CONSTRUCTORS_DEF(MPIComm) #if defined(MPIINSTALLED) && defined(MPI_COMM_WORLD) @@ -65,29 +73,25 @@ ADD_CONSTRUCTORS_DEF(MPIComm) void MPIComm::init() { updateMaxMsgSize(2147483647); assert(!handle); - if (!(this->address && this->address->valid())) { + if (!this->address.valid()) { #ifdef YGG_TEST - if (!address) { - address = new utils::Address(std::to_string(0)); - } else { // GCOVR_EXCL_LINE - address->address(std::to_string(0)); - } + address.address(std::to_string(0)); #else // YGG_TEST throw std::runtime_error("No address specified for MPIComm constructor"); #endif // YGG_TEST } if (this->name.empty()) { - this->name = "tempinitMPI." + address->address(); + this->name = "tempinitMPI." + address.address(); } handle = new mpi_registry_t(MPI_COMM_WORLD); handle->procs.clear(); handle->tag = 0; - std::vector adrs = communication::utils::split(this->address->address(), ","); - addresses.push_back(this->address); + std::vector adrs = communication::utils::split(this->address.address(), ","); + addresses.emplace_back(this->address.address()); if (adrs.size() > 1) { - addresses[0]->address(adrs[0]); + addresses[0].address(adrs[0]); for (size_t i = 1; i < adrs.size(); i++) { - addresses.push_back(new communication::utils::Address(adrs[i])); + addresses.emplace_back(adrs[i]); } } @@ -104,13 +108,6 @@ void MPIComm::init() { } } -void MPIComm::close() { - for (size_t i = 1; i < addresses.size(); i++) - delete addresses[i]; - addresses.clear(); - CommBase::close(); -} - int MPIComm::mpi_comm_source_id() const { #if defined(MPIINSTALLED) && defined(MPI_COMM_WORLD) if (direction == SEND) diff --git a/communication/communicators/MPIComm.hpp b/communication/communicators/MPIComm.hpp index 945322f1..428f4846 100644 --- a/communication/communicators/MPIComm.hpp +++ b/communication/communicators/MPIComm.hpp @@ -1,6 +1,7 @@ #pragma once #ifdef MPIINSTALLED +#define OMPI_SKIP_MPICXX 1 #include #endif /*MPIINSTALLED*/ #include "CommBase.hpp" @@ -59,15 +60,13 @@ class MPIComm : public CommBase { * @param direction Enumerated direction for the communicator * @param flags Bitwise flags describing the communicator */ - MPIComm(const std::string name = "", - utils::Address *address = new utils::Address(), + MPIComm(const std::string name, + utils::Address& address, const DIRECTION direction = NONE, int flgs = 0, const COMM_TYPE type = MPI_COMM); ADD_CONSTRUCTORS(MPI) #if defined(MPIINSTALLED) && defined(MPI_COMM_WORLD) - /*! \copydoc Comm_t::close */ - void close() override; /*! \copydoc Comm_t::comm_nmsg */ int comm_nmsg(DIRECTION dir=NONE) const override; @@ -90,11 +89,11 @@ class MPIComm : public CommBase { #ifdef YGG_TEST public: - std::vector& getAddresses() { return addresses; } + std::vector& getAddresses() { return addresses; } #endif private: - std::vector addresses; + std::vector addresses; }; } diff --git a/communication/communicators/RPCComm.cpp b/communication/communicators/RPCComm.cpp index 7d1bdbc7..7733c495 100644 --- a/communication/communicators/RPCComm.cpp +++ b/communication/communicators/RPCComm.cpp @@ -6,12 +6,18 @@ using namespace communication::communicator; using namespace communication::utils; -RPCComm::RPCComm(const std::string &name, Address *address, +RPCComm::RPCComm(const std::string &name, Address& address, int flgs, DIRECTION dir, DIRECTION req_dir, const COMM_TYPE type) : COMM_BASE(name, address, dir, flgs, type), requests(req_dir, flgs & COMM_FLAG_ASYNC_WRAPPED) {} +RPCComm::RPCComm(const std::string &name, + int flgs, DIRECTION dir, DIRECTION req_dir, + const COMM_TYPE type) : + COMM_BASE(name, dir, flgs, type), + requests(req_dir, flgs & COMM_FLAG_ASYNC_WRAPPED) {} + void RPCComm::close() { requests.destroy(); COMM_BASE::close(); diff --git a/communication/communicators/RPCComm.hpp b/communication/communicators/RPCComm.hpp index fd97bbd3..cb780897 100644 --- a/communication/communicators/RPCComm.hpp +++ b/communication/communicators/RPCComm.hpp @@ -11,9 +11,11 @@ namespace communicator { // @brief Structure for storing requests class RPCComm : public COMM_BASE { public: - explicit RPCComm(const std::string &name, utils::Address *address, + explicit RPCComm(const std::string &name, utils::Address& address, int flgs, DIRECTION dir, DIRECTION req_dir, const COMM_TYPE type); + RPCComm(const std::string& name, int flgs, DIRECTION dir, + DIRECTION req_dir, const COMM_TYPE type); using Comm_t::send; using Comm_t::recv; diff --git a/communication/communicators/Requests.hpp b/communication/communicators/Requests.hpp index 6ef8dbf0..2e6d6845 100644 --- a/communication/communicators/Requests.hpp +++ b/communication/communicators/Requests.hpp @@ -97,7 +97,7 @@ class RequestList { } int hasComm(const std::string& response_address) const { for (size_t i = 0; i < comms.size(); i++) { - if (comms[i] && *(comms[i]->address) == response_address) + if (comms[i] && comms[i]->address.address() == response_address) return (int)i; } return -1; @@ -144,28 +144,29 @@ class RequestList { // initClientSignon(); } if (request_id.empty()) { - if (!stashed_request.empty()) { - request_id = stashed_request; - stashed_request.clear(); - header.SetMetaString("request_id", request_id); - } else { - header.SetMetaID("request_id", request_id); - } - ygglog_debug << "addRequestClient: request_id = " - << request_id << std::endl; + if (!stashed_request.empty()) { + request_id = stashed_request; + stashed_request.clear(); + header.SetMetaString("request_id", request_id); + } else { + header.SetMetaID("request_id", request_id); + } + ygglog_debug << "addRequestClient: request_id = " + << request_id << std::endl; } else { - header.SetMetaString("request_id", request_id); + header.SetMetaString("request_id", request_id); } - header.SetMetaString("response_address", - comms[0]->address->address()); - if (existing_idx < 0) { - size_t idx = requests.size(); - if (hasRequest(request_id) >= 0) { - ygglog_error - << "addRequestClient: Client already has request with id '" - << request_id << "'" << std::endl; - return -1; - } + header.SetMetaString("response_address", + comms[0]->address.address()); + if (existing_idx < 0) { + size_t idx = requests.size(); + if (hasRequest(request_id) >= 0) { + ygglog_error + << "addRequestClient: Client already has request with id '" + << request_id << "'" << std::endl; + return -1; + } + Request req(request_id, 0, is_signon); requests.emplace_back(request_id, 0, is_signon); // requests.resize(requests.size() + 1); // requests[idx].request_id = request_id; @@ -174,7 +175,7 @@ class RequestList { existing_idx = static_cast(idx); } ygglog_debug << "addRequestClient: done response_address = " - << comms[0]->address->address() << ", request_id = " + << comms[0]->address.address() << ", request_id = " << request_id << std::endl; return existing_idx; } @@ -193,7 +194,7 @@ class RequestList { (header.flags & HEAD_FLAG_CLIENT_SIGNON)); ygglog_debug << "addRequestServer: done idx = " << idx << ", response_address = " - << comms[requests[idx].comm_idx]->address->address() + << comms[requests[idx].comm_idx]->address.address() << ", request_id = " << requests[idx].request_id << std::endl; return static_cast(idx); @@ -333,7 +334,7 @@ class RequestList { if (idx >= 0) return idx; } - utils::Address* response_adr = new utils::Address(response_address); + utils::Address response_adr(response_address); COMM_TYPE response_type = DEFAULT_COMM; Comm_t* x = new_Comm_t(response_dir, response_type, "", response_adr, response_flags); diff --git a/communication/communicators/ServerComm.cpp b/communication/communicators/ServerComm.cpp index 98d2d91a..2f071c02 100644 --- a/communication/communicators/ServerComm.cpp +++ b/communication/communicators/ServerComm.cpp @@ -6,12 +6,18 @@ using namespace communication::communicator; using namespace communication::utils; -ServerComm::ServerComm(const std::string nme, Address *addr, +ServerComm::ServerComm(const std::string nme, Address& addr, int flgs, const COMM_TYPE type) : RPCComm(nme, addr, flgs | COMM_FLAG_SERVER | COMM_ALWAYS_SEND_HEADER, RECV, SEND, type) {} +ServerComm::ServerComm(const std::string nme, + int flgs, const COMM_TYPE type) : + RPCComm(nme, + flgs | COMM_FLAG_SERVER | COMM_ALWAYS_SEND_HEADER, + RECV, SEND, type) {} + ADD_CONSTRUCTORS_RPC_DEF(ServerComm) bool ServerComm::signon(const Header& header) { diff --git a/communication/communicators/ServerComm.hpp b/communication/communicators/ServerComm.hpp index d6d79f94..31548228 100644 --- a/communication/communicators/ServerComm.hpp +++ b/communication/communicators/ServerComm.hpp @@ -21,8 +21,8 @@ class ServerComm : public RPCComm { * then an address will be created. * @param flgs Bitwise flags describing the communicator */ - explicit ServerComm(const std::string name = "", - utils::Address *address = nullptr, + explicit ServerComm(const std::string name, + utils::Address& address, int flgs = 0, const COMM_TYPE type = SERVER_COMM); ADD_CONSTRUCTORS_RPC(ServerComm, SERVER_COMM) diff --git a/communication/communicators/Workers.cpp b/communication/communicators/Workers.cpp index f0d5137d..87742082 100644 --- a/communication/communicators/Workers.cpp +++ b/communication/communicators/Workers.cpp @@ -4,7 +4,7 @@ using namespace communication::communicator; using namespace communication::utils; -Worker::Worker(Comm_t* parent, DIRECTION dir, Address* adr) : +Worker::Worker(Comm_t* parent, DIRECTION dir, Address& adr) : comm(nullptr), request() { try { if (parent) { @@ -25,9 +25,9 @@ Worker& Worker::operator=(Worker&& rhs) { // GCOVR_EXCL_START new (this) Worker(std::move(rhs)); return *this; } // GCOVR_EXCL_STOP -bool Worker::matches(DIRECTION dir, Address* adr) { +bool Worker::matches(DIRECTION dir, Address& adr) { return (request.empty() && comm && comm->direction == dir && - ((!adr) || (adr->address() == comm->address->address()))); + ((!adr.valid()) || (adr.address() == comm->address.address()))); } Worker::~Worker() { if (comm) { @@ -44,7 +44,7 @@ WorkerList::~WorkerList() { } Comm_t* WorkerList::add_worker(Comm_t* parent, DIRECTION dir, - Address* adr) { + Address& adr) { if (!parent) { ygglog_error << "WorkerList::add_worker: No parent provided" << std::endl; return nullptr; @@ -62,7 +62,7 @@ void WorkerList::remove_worker(Comm_t*& worker) { workers.erase(workers.begin() + static_cast(idx)); worker = nullptr; } -Comm_t* WorkerList::find_worker(DIRECTION dir, Address* adr, size_t* idx) { +Comm_t* WorkerList::find_worker(DIRECTION dir, Address& adr, size_t* idx) { for (size_t i = 0; i < workers.size(); i++) { if (workers[i].matches(dir, adr)) { if (idx) @@ -81,12 +81,12 @@ int WorkerList::find_worker(Comm_t* worker) { return -1; return static_cast(idx); } -Comm_t* WorkerList::get(Comm_t* parent, DIRECTION dir, Address* adr) { + +Comm_t* WorkerList::get(Comm_t* parent, DIRECTION dir, Address& adr) { Comm_t* out = find_worker(dir, adr); if (!out) { out = add_worker(parent, dir, adr); - } else if (adr) { - delete out->address; + } else if (adr.valid()) { out->address = adr; } if (!out) { @@ -94,6 +94,16 @@ Comm_t* WorkerList::get(Comm_t* parent, DIRECTION dir, Address* adr) { } return out; } + +Comm_t* WorkerList::get(Comm_t* parent, DIRECTION dir) { + Address tempAdr; + return get(parent, dir, tempAdr); +} +Comm_t* WorkerList::get(Comm_t* parent, DIRECTION dir, std::string adr) { + Address addrs(adr); + return get(parent, dir, addrs); +} + bool WorkerList::setRequest(Comm_t* worker, std::string request) { int idx = find_worker(worker); if (idx < 0) diff --git a/communication/communicators/Workers.hpp b/communication/communicators/Workers.hpp index 39493807..d4639a3f 100644 --- a/communication/communicators/Workers.hpp +++ b/communication/communicators/Workers.hpp @@ -16,10 +16,10 @@ namespace communicator { Worker(const Worker& rhs) = delete; Worker& operator=(const Worker& rhs) = delete; public: - Worker(Comm_t* parent, DIRECTION dir, utils::Address* adr = nullptr); + Worker(Comm_t* parent, DIRECTION dir, utils::Address& adr); Worker(Worker&& rhs); Worker& operator=(Worker&& rhs); - bool matches(DIRECTION dir, utils::Address* adr = nullptr); + bool matches(DIRECTION dir, utils::Address& adr); ~Worker(); Comm_t* comm; std::string request; @@ -32,13 +32,15 @@ namespace communicator { WorkerList() : workers() {} ~WorkerList(); Comm_t* add_worker(Comm_t* parent, DIRECTION dir, - utils::Address* adr = nullptr); + utils::Address& adr); void remove_worker(Comm_t*& worker); - Comm_t* find_worker(DIRECTION dir, utils::Address* adr = nullptr, + Comm_t* find_worker(DIRECTION dir, utils::Address& adr, size_t* idx = nullptr); int find_worker(Comm_t* worker); Comm_t* get(Comm_t* parent, DIRECTION dir, - utils::Address* adr = nullptr); + utils::Address& adr); + Comm_t* get(Comm_t* parent, DIRECTION dir); + Comm_t* get(Comm_t* parent, DIRECTION dir, std::string adr); bool setRequest(Comm_t* worker, std::string request); bool setResponse(std::string request); std::vector workers; diff --git a/communication/communicators/ZMQComm.cpp b/communication/communicators/ZMQComm.cpp index cee392e6..fcfec79a 100644 --- a/communication/communicators/ZMQComm.cpp +++ b/communication/communicators/ZMQComm.cpp @@ -77,21 +77,27 @@ ZMQSocket::ZMQSocket() : handle(NULL), endpoint(), type(0), ctx() {} ZMQSocket::ZMQSocket(const ZMQSocket& rhs) : handle(NULL), endpoint(), type(rhs.type), ctx() {} -ZMQSocket::ZMQSocket(int type0, utils::Address* address, +ZMQSocket::ZMQSocket(int type0, utils::Address& address, int linger, int immediate, int sndtimeo) : handle(NULL), endpoint(), type(type0), ctx() { init(type0, address, linger, immediate, sndtimeo); } +ZMQSocket::ZMQSocket(int type0, int linger, int immediate, + int sndtimeo) : + handle(NULL), endpoint(), type(type0), ctx() { + utils::Address adr; + init(type0, adr, linger, immediate, sndtimeo); +} + -void ZMQSocket::init(int type0, std::string address, +void ZMQSocket::init(int type0, const std::string& address, int linger, int immediate, int sndtimeo) { - if (address.empty()) { - init(type0, NULL, linger, immediate, sndtimeo); - } else { - utils::Address address_; - address_.address(address); - init(type0, &address_, linger, immediate, sndtimeo); - } +//if (address.empty()) { + // init(type0, NULL, linger, immediate, sndtimeo); + //} else { + utils::Address address_(address); + init(type0, address_, linger, immediate, sndtimeo); + //} } #ifdef ZMQINSTALLED @@ -103,7 +109,7 @@ int ZMQSocket::set(int member, const T& data) { } return 1; } -void ZMQSocket::init(int type0, utils::Address* address, +void ZMQSocket::init(int type0, utils::Address& addr, int linger, int immediate, int sndtimeo) { type = type0; std::string except_msg; @@ -127,8 +133,8 @@ void ZMQSocket::init(int type0, utils::Address* address, destroy(); throw std::runtime_error(except_msg); } - if (address && !address->address().empty()) { - endpoint = address->address(); + if (addr.valid() && !addr.address().empty()) { + endpoint = addr.address(); if (zmq_connect(handle, endpoint.c_str()) != 0) { destroy(); ygglog_throw_error("ZMQSocket::init: Error connecting to endpoint '" + endpoint + "'"); @@ -139,7 +145,6 @@ void ZMQSocket::init(int type0, utils::Address* address, std::string host = "localhost"; if (host == "localhost") host = "127.0.0.1"; - std::string address; YGG_THREAD_SAFE_BEGIN(zmqport) { if (_last_port_set == 0) { const char *model_index = getenv("YGG_MODEL_INDEX"); @@ -183,7 +188,6 @@ void ZMQSocket::init(int type0, utils::Address* address, endpoint.assign(endpoint_c, endpoint_len - 1); // Remove newline char ygglog_debug << "ZMQSocket::init: Bound to endpoint '" << endpoint << "'" << std::endl; size_t idx_port = endpoint.find_last_of(':'); - assert(idx_port != std::string::npos); if (idx_port == std::string::npos) { except_msg = "ZMQSocket::init: Error getting port from endpoing"; } else { @@ -235,7 +239,7 @@ int ZMQSocket::poll(int method, int tout) { return out; } -int ZMQSocket::send(const std::string msg) { +int ZMQSocket::send(const std::string& msg) { zmq_msg_t part; if (zmq_msg_init_size (&part, msg.size()) != 0) return -1; @@ -504,7 +508,7 @@ bool ZMQReply::send_stage2(const std::string msg_data) { // ZMQComm // ///////////// -ZMQComm::ZMQComm(const std::string name, utils::Address *address, +ZMQComm::ZMQComm(const std::string name, utils::Address& address, const DIRECTION direction, int flgs, const COMM_TYPE type) : CommBase(name, address, direction, type, flgs), reply(direction) { @@ -512,6 +516,14 @@ ZMQComm::ZMQComm(const std::string name, utils::Address *address, init(); } +ZMQComm::ZMQComm(const std::string name, + const DIRECTION direction, int flgs, + const COMM_TYPE type) : + CommBase(name, direction, type, flgs), reply(direction) { + if (!global_comm) + init(); +} + ADD_CONSTRUCTORS_DEF(ZMQComm) #ifdef ZMQINSTALLED @@ -529,7 +541,7 @@ void ZMQComm::init() { // } else { handle = new ZMQSocket(ZMQ_PAIR, address); // } - address->address(handle->endpoint); + address.address(handle->endpoint); if (this->name.empty()) this->name = "tempnewZMQ-" + handle->endpoint.substr(handle->endpoint.find_last_of(':') + 1); if (direction == SEND) diff --git a/communication/communicators/ZMQComm.hpp b/communication/communicators/ZMQComm.hpp index 6edb526c..b38cf192 100644 --- a/communication/communicators/ZMQComm.hpp +++ b/communication/communicators/ZMQComm.hpp @@ -43,24 +43,26 @@ class ZMQSocket { public: ZMQSocket(); ZMQSocket(const ZMQSocket& rhs); - ZMQSocket(int type0, utils::Address* address = NULL, + ZMQSocket(int type0, int linger = 0, int immediate = 1, + int sndtimeo = -1); + ZMQSocket(int type0, utils::Address& address, int linger = 0, int immediate = 1, int sndtimeo = -1); - void init(int type0, std::string address, + void init(int type0, const std::string& address, int linger = 0, int immediate = 1, int sndtimeo = -1); #ifdef ZMQINSTALLED - void init(int type0, utils::Address* address = NULL, + void init(int type0, utils::Address& address, int linger = 0, int immediate = 1, int sndtimeo = -1); int poll(int method, int tout); - int send(const std::string msg); + int send(const std::string& msg); template int set(int member, const T& data); int recv(std::string& msg, bool for_identity=false); void destroy(); #else - void init(int, utils::Address* = NULL, int = 0, int = 1, int = -1) { + void init(int, utils::Address&, int = 0, int = 1, int = -1) { UNINSTALLED_ERROR(ZMQ); } void destroy() {} @@ -121,10 +123,10 @@ class ZMQComm : public CommBase { * @param direction Enumerated direction for communicator * @param flgs Bitwise flags describing the communicator */ - explicit ZMQComm(const std::string name = "", - utils::Address *address = new utils::Address(), + explicit ZMQComm(const std::string name, + utils::Address& address, const DIRECTION direction = NONE, - int flgs = 0, const COMM_TYPE type = ZMQ_COMM); + int flgs = 0, const COMM_TYPE type = ZMQ_COMM); ADD_CONSTRUCTORS(ZMQ) #ifdef ZMQINSTALLED diff --git a/communication/rapidjson b/communication/rapidjson index 92d0f8fb..3dda647a 160000 --- a/communication/rapidjson +++ b/communication/rapidjson @@ -1 +1 @@ -Subproject commit 92d0f8fbd70cebf8c5f9c83af26bbe0923f87c7d +Subproject commit 3dda647a92829926c80a6195f6fa30286d9efddd diff --git a/communication/utils/Address.cpp b/communication/utils/Address.cpp index 7cd6cb62..862384e6 100644 --- a/communication/utils/Address.cpp +++ b/communication/utils/Address.cpp @@ -3,18 +3,22 @@ using namespace communication::utils; -Address::Address(const std::string &adr) { +Address::Address(const std::string &adr): _key(-1), _valid(false) { address(adr); } -Address::Address(const char *adr) { +Address::Address(const char *adr): _key(-1), _valid(false) { std::string sadr; if (adr != NULL) - sadr.assign(adr); + sadr.assign(adr); address(sadr); } -Address::Address(Address *adr) : Address(adr->address()){} +Address::Address(const Address& adr): _valid(false) { + address(adr.address()); +} + +Address::Address(const Address* adr): Address(*adr) {} void Address::address(const std::string &addr) { _address = addr; @@ -45,6 +49,11 @@ bool Address::operator==(const Address &adr) { return this->_address == adr._address; } +Address& Address::operator=(const Address& adr) { + address(adr.address()); + return *this; +} + bool Address::valid() const { return _valid; } diff --git a/communication/utils/Address.hpp b/communication/utils/Address.hpp index 3fa31049..c41dead9 100644 --- a/communication/utils/Address.hpp +++ b/communication/utils/Address.hpp @@ -6,7 +6,7 @@ namespace communication { namespace utils { -static std::string blank = ""; +static std::string blank; /** * Class for holding an address, used by the communicators @@ -17,19 +17,20 @@ class Address { * Create a new instance of the Address class with the given input * @param adr The address to use, as a std::string, defaults to empy string. */ - Address(const std::string &adr = blank); + explicit Address(const std::string &adr = blank); /** * Create a new instance of the Address class with the given input * @param adr The address to use, as a char* */ - Address(const char *adr); + explicit Address(const char *adr); /** * Copy constructor of the Address class * @param adr The instance to copy */ - Address(Address *adr); + Address(const Address &adr); + Address(const Address* adr); /** * Get the address from the class as a std::string @@ -56,19 +57,25 @@ class Address { */ bool operator==(const Address &adr); + Address& operator=(const Address& adr); /** * Whether or not this instance is has a valid address * @return bool */ bool valid() const; + + void invalidate() { + _valid = false; + _address.clear(); + } friend std::ostream &operator<<(std::ostream &out, const Address &addr) { out << addr._address; return out; } private: - std::string _address = ""; // the address - int _key; // the unique key + std::string _address; // the address + int _key{}; // the unique key bool _valid; // validity flag }; diff --git a/communication/utils/serialization.cpp b/communication/utils/serialization.cpp index 7058c799..885b97fd 100644 --- a/communication/utils/serialization.cpp +++ b/communication/utils/serialization.cpp @@ -765,7 +765,8 @@ void Metadata::Display(const char* indent) const { std::cout << document2string(metadata, indent) << std::endl; } void Metadata::_update_schema() { - if (metadata.HasMember("serializer") && + if (metadata.IsObject() && + metadata.HasMember("serializer") && metadata["serializer"].IsObject() && metadata["serializer"].HasMember("datatype") && metadata["serializer"]["datatype"].IsObject()) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d174ffb0..33b0e9e3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -38,7 +38,7 @@ if(GTESTSRC_FOUND) endif() -set(TEST_LIBRARIES ${TEST_LIBRARIES} YggInterface ${DEPS_LIB_NAMES} ${DEPS_LIBRARIES}) +set(TEST_LIBRARIES ${TEST_LIBRARIES} ${YGG_TARGET_CPP} ${DEPS_LIB_NAMES} ${DEPS_LIBRARIES}) set(TEST_INCLUDE_DIRS ${DEPS_INCLUDE_DIRS}) option(YGG_ENABLE_ELF "Enable ELF replacements when available" ON) diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 5dfd046c..b80e8c86 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -86,14 +86,14 @@ if (WIN32) add_custom_command( TARGET unittest POST_BUILD - COMMAND dumpbin /dependents $ + COMMAND dumpbin /dependents $ COMMAND_EXPAND_LISTS ) if (CONDA_PREFIX) add_custom_command( TARGET unittest POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND ${CMAKE_COMMAND} -E copy $ $ COMMAND_EXPAND_LISTS ) else() diff --git a/test/unittest/mock.cpp b/test/unittest/mock.cpp index 18613845..55630e69 100644 --- a/test/unittest/mock.cpp +++ b/test/unittest/mock.cpp @@ -204,7 +204,7 @@ ::zmq::detail::trivial_optional recv_multipart(::zmq::socket_ref, Output return -1; } void *zmq_socket (void *, int) { - assert(RETVAL_CREATE < 0); + assert(RETVAL_CREATE <= 0); return NULL; } int zmq_connect (void *, const char *) { diff --git a/test/unittest/tests/communicators/clientcommtest.cpp b/test/unittest/tests/communicators/clientcommtest.cpp index ad7d3029..66356610 100644 --- a/test/unittest/tests/communicators/clientcommtest.cpp +++ b/test/unittest/tests/communicators/clientcommtest.cpp @@ -19,11 +19,18 @@ class ClientComm_tester : public ClientComm { ClientComm_tester(const ClientComm_tester&) = delete; ClientComm_tester& operator=(const ClientComm_tester&) = delete; public: - ClientComm_tester(const std::string &name = "", utils::Address *address = nullptr) : + ClientComm_tester(const std::string &name, utils::Address& address) : ClientComm(name, address), server_comm(NULL) { - server_comm = new ServerComm("", new utils::Address(this->address->address())); + utils::Address addr(this->address.address()); + server_comm = new ServerComm("", addr); } - ~ClientComm_tester() override { + ClientComm_tester(const std::string &name) : + ClientComm(name), server_comm(NULL) { + utils::Address addr(this->address.address()); + server_comm = new ServerComm("", addr); + } + + ~ClientComm_tester() override { delete server_comm; server_comm = NULL; } @@ -76,11 +83,11 @@ class ClientComm_tester : public ClientComm { } void addResponseWorkers() { Comm_t* worker = server_comm->getWorkers().get(server_comm, SEND); - this->getWorkers().get(this, RECV, new utils::Address(worker->getAddress())); + this->getWorkers().get(this, RECV, worker->getAddress()); } void addWorkers() { Comm_t* worker = this->getWorkers().get(this, SEND); - server_comm->getWorkers().get(server_comm, RECV, new utils::Address(worker->getAddress())); + server_comm->getWorkers().get(server_comm, RECV, worker->getAddress()); } ServerComm* server_comm; }; @@ -89,13 +96,13 @@ class ClientComm_tester : public ClientComm { TEST(ClientComm, constructor) { std::string name = "MyComm"; - communication::testing::ClientComm_tester cc(name, nullptr); - communication::testing::ClientComm_tester cc1("", nullptr); + communication::testing::ClientComm_tester cc(name); + communication::testing::ClientComm_tester cc1(""); } TEST(ClientComm, send) { std::string name = "MyComm"; - communication::testing::ClientComm_tester cc(name, nullptr); + communication::testing::ClientComm_tester cc(name); std::string msg = "This is a test message"; EXPECT_TRUE(cc.addSignon()); EXPECT_GE(cc.send(msg.c_str(), msg.size()), 0); @@ -103,7 +110,7 @@ TEST(ClientComm, send) { TEST(ClientComm, sendLarge) { std::string name = "MyComm"; - communication::testing::ClientComm_tester cc(name, nullptr); + communication::testing::ClientComm_tester cc(name); cc.addWorkers(); std::string msg(cc.getMaxMsgSize(), 'A'); EXPECT_TRUE(cc.addSignon()); @@ -122,7 +129,7 @@ TEST(ClientComm, sendLarge) { TEST(ClientComm, recv) { std::string name = "MyComm"; - communication::testing::ClientComm_tester cc(name, nullptr); + communication::testing::ClientComm_tester cc(name); std::string req_send = "REQUEST"; std::string res_send = "RESPONSE"; std::string req_recv; @@ -176,7 +183,7 @@ TEST(ClientComm, recv) { TEST(ClientComm, async) { std::string name = "MyComm"; - AsyncComm sComm(name, nullptr, SEND, COMM_FLAG_ASYNC, CLIENT_COMM); + AsyncComm sComm(name, SEND, COMM_FLAG_ASYNC, CLIENT_COMM); std::string key_env = name + "_IN"; std::string val_env = sComm.getAddress(); setenv(key_env.c_str(), val_env.c_str(), 1); @@ -197,7 +204,7 @@ TEST(ClientComm, async) { TEST(ClientComm, recvLarge) { std::string name = "MyComm"; - communication::testing::ClientComm_tester cc(name, nullptr); + communication::testing::ClientComm_tester cc(name); std::string bigMsg(cc.getMaxMsgSize(), 'A'); std::string req_send = "REQUEST" + bigMsg; std::string res_send = "RESPONSE" + bigMsg; @@ -218,7 +225,7 @@ TEST(ClientComm, recvLarge) { TEST(ClientComm, call) { std::string name = "MyComm"; - communication::testing::ClientComm_tester cc(name, nullptr); + communication::testing::ClientComm_tester cc(name); cc.addSchema("{\"type\": \"string\"}"); std::string req_send = "REQUEST1"; std::string res_send = "RESPONSE1"; @@ -273,14 +280,14 @@ TEST(ClientComm, call) { TEST(ClientComm, global) { std::string name = "test_name"; { - ServerComm rComm(name, nullptr); + ServerComm rComm(name); rComm.set_timeout_recv(10000); std::string key_env = name + "_OUT"; std::string val_env = rComm.getAddress(); setenv(key_env.c_str(), val_env.c_str(), 1); { global_scope_comm_on(); - ClientComm sComm(name, nullptr); + ClientComm sComm(name); sComm.set_timeout_recv(10000); global_scope_comm_off(); sComm.addResponseFormat("%s"); @@ -308,7 +315,7 @@ TEST(ClientComm, global) { } { global_scope_comm_on(); - ClientComm sComm(name, nullptr); + ClientComm sComm(name); global_scope_comm_off(); std::string req_send = "REQUEST"; std::string res_send = "RESPONSE"; diff --git a/test/unittest/tests/communicators/commbasetest.cpp b/test/unittest/tests/communicators/commbasetest.cpp index 59e8cdfc..3f390868 100644 --- a/test/unittest/tests/communicators/commbasetest.cpp +++ b/test/unittest/tests/communicators/commbasetest.cpp @@ -8,10 +8,10 @@ using namespace communication::communicator; class Comm_tTest: public Comm_t { public: - Comm_tTest(utils::Address *address, DIRECTION dirn, const COMM_TYPE &t, int flgs = 0) : + Comm_tTest(utils::Address& address, DIRECTION dirn, const COMM_TYPE &t, int flgs = 0) : Comm_t("", address, dirn, t, flgs), _closed(false) {} Comm_tTest(const std::string &name, DIRECTION direction, const COMM_TYPE &t) : - Comm_t(name, nullptr, direction, t, COMM_FLAG_INTERFACE), _closed(false) {} + Comm_t(name, direction, t, COMM_FLAG_INTERFACE), _closed(false) {} int comm_nmsg(DIRECTION=NONE) const override {return 1;} int get_flags() const {return flags;} void close() override { _closed = true; } @@ -29,7 +29,7 @@ class Comm_tTest: public Comm_t { // return static_cast(msg.size()); return 0; } - Comm_t* create_worker(utils::Address* adr, + Comm_t* create_worker(utils::Address& adr, const DIRECTION& dir, int flgs) override { return new Comm_tTest(adr, dir, this->type, flgs); } @@ -40,7 +40,7 @@ class Comm_tTest: public Comm_t { class EmptyComm : public CommBase { public: EmptyComm() : - CommBase("", nullptr, SEND, ZMQ_COMM, 0), nmsg_(-1) { + CommBase("", SEND, ZMQ_COMM, 0), nmsg_(-1) { handle = new int(); updateMaxMsgSize(1000); } @@ -54,14 +54,14 @@ class EmptyComm : public CommBase { TEST(Commt, Constructors) { unsetenv("YGG_MODEL_NAME"); - utils::Address *adr = new utils::Address("this.is.a.test"); + utils::Address adr("this.is.a.test"); Comm_tTest *ctest = new Comm_tTest(adr, SEND, NULL_COMM); EXPECT_EQ(ctest->getType(), NULL_COMM); EXPECT_TRUE(ctest->valid()); EXPECT_FALSE(ctest->get_flags() & COMM_ALLOW_MULTIPLE_COMMS); std::cout << ctest << std::endl; delete ctest; - adr = new utils::Address("this.is.a.test"); + //adr = new utils::Address("this.is.a.test"); ctest = new Comm_tTest(adr, NONE, NULL_COMM); EXPECT_EQ(ctest->getType(), NULL_COMM); EXPECT_FALSE(ctest->valid()); @@ -69,7 +69,7 @@ TEST(Commt, Constructors) { delete ctest; const char* ygg = getenv("YGG_THREADING"); setenv("YGG_THREADING", "TRUE", true); - adr = new utils::Address("this.is.a.test"); + //adr = new utils::Address("this.is.a.test"); ctest = new Comm_tTest(adr, RECV, NULL_COMM); EXPECT_EQ(ctest->getType(), NULL_COMM); EXPECT_TRUE(ctest->valid()); diff --git a/test/unittest/tests/communicators/commtest.hpp b/test/unittest/tests/communicators/commtest.hpp index 98a61191..a80d848c 100644 --- a/test/unittest/tests/communicators/commtest.hpp +++ b/test/unittest/tests/communicators/commtest.hpp @@ -255,14 +255,15 @@ } #define TESTER_METHODS(cls) \ - cls ## _tester(const std::string name = "", \ - utils::Address *address = new utils::Address(), \ + cls ## _tester(const std::string name, \ + utils::Address& address, \ const DIRECTION direction = NONE) : \ - cls(name, address, direction) {} \ + cls(name, address, direction) {} \ + cls ## _tester(const std::string name="", \ + const DIRECTION direction = NONE) : \ + cls(name, direction) {} \ cls ## _tester(DIRECTION dir) : \ - cls("", nullptr, dir) {} \ - cls ## _tester(const std::string name, DIRECTION dir) : \ - cls(name, dir) {} + cls("", dir) {} #define COMM_SERI_TEST_TYPE(cls, type, value, schema, init) \ TEST(cls, type) { \ @@ -365,7 +366,7 @@ std::string name = "test_name"; \ global_scope_comm_on(); \ { \ - cls ## _tester sComm(name, nullptr, SEND); \ + cls ## _tester sComm(name, SEND); \ sComm.addSchema("{\"type\": \"number\"}"); \ std::string key_env = name + "_IN"; \ std::string val_env = sComm.getAddress(); \ @@ -378,7 +379,7 @@ recvVar, (data_recv)); \ } \ { \ - cls ## _tester sComm(name, nullptr, SEND); \ + cls ## _tester sComm(name, SEND); \ cls ## _tester rComm(name, RECV); \ DO_SEND_RECV_EXCHANGE(INIT_DATA_SINGLE(double, 1.5), \ COMP_DATA_SINGLE, \ @@ -393,7 +394,7 @@ TEST(cls, async) { \ std::string name = "test_name"; \ COMM_TYPE typ = cls::defaultCommType(); \ - AsyncComm sComm(name, nullptr, SEND, COMM_FLAG_ASYNC, typ); \ + AsyncComm sComm(name, SEND, COMM_FLAG_ASYNC, typ); \ sComm.addSchema("{\"type\": \"number\"}"); \ std::string key_env = name + "_IN"; \ std::string val_env = sComm.getAddress(); \ @@ -410,7 +411,7 @@ global_scope_comm_on(); \ COMM_TYPE typ = cls::defaultCommType(); \ { \ - AsyncComm sComm(name, nullptr, SEND, COMM_FLAG_ASYNC, typ); \ + AsyncComm sComm(name, SEND, COMM_FLAG_ASYNC, typ); \ sComm.addSchema("{\"type\": \"number\"}"); \ std::string key_env = name + "_IN"; \ std::string val_env = sComm.getAddress(); \ @@ -423,7 +424,7 @@ recvVar, (data_recv)); \ } \ { \ - AsyncComm sComm(name, nullptr, SEND, COMM_FLAG_ASYNC, typ); \ + AsyncComm sComm(name, SEND, COMM_FLAG_ASYNC, typ); \ AsyncComm rComm(name, RECV, COMM_FLAG_ASYNC, typ); \ DO_SEND_RECV_EXCHANGE(INIT_DATA_SINGLE(double, 1.5), \ COMP_DATA_SINGLE, \ @@ -448,8 +449,9 @@ unsetenv(key_env.c_str()); \ if (sComm.getMaxMsgSize() > 0) { \ /* Add worker in advance so that send is successful */ \ - Comm_t* sComm_worker = sComm.getWorkers().get(&sComm, SEND); \ - rComm.getWorkers().get(&rComm, RECV, new utils::Address(sComm_worker->getAddress())); \ + Comm_t* sComm_worker = sComm.getWorkers().get(&sComm, SEND); \ + utils::Address addr(sComm_worker->getAddress()); \ + rComm.getWorkers().get(&rComm, RECV, addr); \ EXPECT_EQ(rComm.getWorkers().find_worker(sComm_worker), -1); \ rComm.getWorkers().remove_worker(sComm_worker); \ sComm_worker = nullptr; \ diff --git a/test/unittest/tests/communicators/defaultcommtest.cpp b/test/unittest/tests/communicators/defaultcommtest.cpp index 3c1cbfa7..90b40ef3 100644 --- a/test/unittest/tests/communicators/defaultcommtest.cpp +++ b/test/unittest/tests/communicators/defaultcommtest.cpp @@ -11,7 +11,7 @@ using namespace communication::communicator; using namespace communication::mock; TEST(DefaultCommu, checkTypeErrors) { - DefaultComm x("", nullptr, SEND); + DefaultComm x("", SEND); x.addSchema("{\"type\": \"boolean\"}"); { double data = 5.0; @@ -42,8 +42,9 @@ TEST(DefaultCommu, checkTypeErrors) { } TEST(DefaultCommu, seriErrors) { - DefaultComm sComm("", nullptr, SEND); - DefaultComm rComm("", new utils::Address(sComm.getAddress().c_str()), RECV); + DefaultComm sComm("", SEND); + utils::Address addr(sComm.getAddress().c_str()); + DefaultComm rComm("", addr, RECV); int a, b; EXPECT_EQ(sComm.send(2, 1, 1), -1); // EXPECT_EQ(rComm.recv(2, &a, &b), -1); @@ -52,10 +53,9 @@ TEST(DefaultCommu, seriErrors) { } TEST(DefaultCommu, workerErrors) { - DefaultComm sComm("", nullptr, SEND); + DefaultComm sComm("", SEND); EXPECT_FALSE(sComm.getWorkers().setRequest(nullptr, "invalid")); EXPECT_FALSE(sComm.getWorkers().setResponse("invalid")); - utils::Address* addr = new utils::Address(sComm.getAddress().c_str()); + utils::Address addr(sComm.getAddress().c_str()); EXPECT_EQ(sComm.getWorkers().get(nullptr, RECV, addr), nullptr); - delete addr; } diff --git a/test/unittest/tests/communicators/interfacetest_c.cpp b/test/unittest/tests/communicators/interfacetest_c.cpp index 810674d3..2cbb05aa 100644 --- a/test/unittest/tests/communicators/interfacetest_c.cpp +++ b/test/unittest/tests/communicators/interfacetest_c.cpp @@ -18,18 +18,18 @@ using namespace communication::communicator; unsetenv("output_OUT") #define INIT_INPUT_NOARGS(cls) \ INIT_INPUT_BASE(ygg ## cls ## Input, ("input"), COMM_BASE, \ - ("", nullptr, SEND)) + ("", SEND)) #define INIT_OUTPUT_NOARGS(cls) \ INIT_OUTPUT_BASE(ygg ## cls ## Output, ("output"), COMM_BASE, \ - ("", nullptr, RECV)) + ("", RECV)) #define INIT_INPUT(cls, ...) \ INIT_INPUT_BASE(ygg ## cls ## Input, ("input", __VA_ARGS__), \ COMM_BASE, \ - ("", nullptr, SEND)) + ("", SEND)) #define INIT_OUTPUT(cls, ...) \ INIT_OUTPUT_BASE(ygg ## cls ## Output, ("output", __VA_ARGS__), \ COMM_BASE, \ - ("", nullptr, RECV)) + ("", RECV)) #define DO_SEND_RECV_BASE_C(init_data, comp_data, send_method, recv_method, send_eof, afterSendRecv, finally) \ init_data; \ EXPECT_GE(send_method, 0); \ @@ -86,9 +86,9 @@ using namespace communication::communicator; INTERFACE_TEST(Base, INIT_INPUT_BASE(yggInput, ("input"), COMM_BASE, - ("", nullptr, SEND)), + ("", SEND)), INIT_OUTPUT_BASE(yggOutput, ("output"), COMM_BASE, - ("", nullptr, RECV)), + ("", RECV)), INIT_DATA_CHAR, COMP_DATA_CHAR, ygg_send, (data_send, n_send), (data_send), ygg_recv, (data_recv, n_recv), (data_recv)) @@ -99,12 +99,12 @@ INTERFACE_TEST( yggInputType, ("input", create_dtype_from_schema("{\"type\": \"number\"}", false)), COMM_BASE, - ("", nullptr, SEND)); sComm.addSchema("{\"type\": \"number\"}"), + ("", SEND)); sComm.addSchema("{\"type\": \"number\"}"), INIT_OUTPUT_BASE( yggOutputType, ("output", create_dtype_from_schema("{\"type\": \"number\"}", false)), COMM_BASE, - ("", nullptr, RECV)), + ("", RECV)), INIT_DATA_SINGLE(double, 1.5), COMP_DATA_SINGLE, yggSend, (data_send), (1, data_send), yggRecv, (&data_recv), (1, &data_recv)) @@ -115,12 +115,12 @@ INTERFACE_TEST( yggInputFmt, ("input", "%d\t%lf\t%5s"), COMM_BASE, - ("", nullptr, SEND)); sComm.addFormat("%d\t%lf\t%5s"), + ("", SEND)); sComm.addFormat("%d\t%lf\t%5s"), INIT_OUTPUT_BASE( yggOutputFmt, ("output", "%d\t%lf\t%5s"), COMM_BASE, - ("", nullptr, RECV)), + ("", RECV)), INIT_DATA_TRIPLE, COMP_DATA_TRIPLE, yggSend, (a_send, b_send, c_send, nc_send), SEND_NARGS_TRIPLE, yggRecv, (&a_recv, &b_recv, &c_recv, &nc_recv), RECV_NARGS_TRIPLE) @@ -158,7 +158,7 @@ INTERFACE_TEST_SCHEMA(JSONObject, "{\"type\": \"object\", \"properties\": {\"a\" TEST(YggInterface_C, Server) { - ClientComm sComm("", nullptr); + ClientComm sComm(""); setenv("input_IN", sComm.getAddress().c_str(), 1); comm_t rComm_c = yggRpcServer("input", "%s", "%s"); unsetenv("input_IN"); @@ -197,7 +197,7 @@ TEST(YggInterface_C, Server) { } TEST(YggInterface_C, Client) { - ServerComm rComm("", nullptr); + ServerComm rComm(""); setenv("output_OUT", rComm.getAddress().c_str(), 1); comm_t sComm_c = yggRpcClient("output", "%s", "%s"); unsetenv("output_OUT"); @@ -238,7 +238,7 @@ TEST(YggInterface_C, ServerAny) { dtype_t dtype_req = {0}; dtype_t dtype_res = {0}; INIT_DATA_SCHEMA_C("{\"type\": \"array\", \"items\": [{\"type\": \"integer\"}]}"); - ClientComm sComm("", nullptr); + ClientComm sComm(""); setenv("input_IN", sComm.getAddress().c_str(), 1); comm_t rComm_c = yggRpcServerType("input", dtype_req, dtype_res); unsetenv("input_IN"); @@ -270,7 +270,7 @@ TEST(YggInterface_C, ClientAny) { dtype_t dtype_req = {0}; dtype_t dtype_res = {0}; INIT_DATA_SCHEMA_C("{\"type\": \"array\", \"items\": [{\"type\": \"integer\"}]}"); - ServerComm rComm("", nullptr); + ServerComm rComm(""); setenv("output_OUT", rComm.getAddress().c_str(), 1); comm_t sComm_c = yggRpcClientType("output", dtype_req, dtype_res); unsetenv("output_OUT"); @@ -299,7 +299,7 @@ TEST(YggInterface_C, ClientAny) { } TEST(YggInterface_C, ClientPointers) { - ServerComm rComm("", nullptr); + ServerComm rComm(""); setenv("output_OUT", rComm.getAddress().c_str(), 1); comm_t sComm_c = yggRpcClient("output", "%s", "%s"); EXPECT_EQ(set_response_format(sComm_c, "%s"), 1); @@ -366,21 +366,21 @@ TEST(comm_t, Errors) { tmp = yggRpcServerType("invalid", tmp_dtype, tmp_dtype); EXPECT_FALSE(tmp.comm); { - COMM_BASE alt("", nullptr, RECV); + COMM_BASE alt("", RECV); setenv("output_OUT", alt.getAddress().c_str(), 1); tmp = yggOutputFmt("output", "%j"); EXPECT_FALSE(tmp.comm); unsetenv("output_OUT"); } { - COMM_BASE alt("", nullptr, SEND); + COMM_BASE alt("", SEND); setenv("input_IN", alt.getAddress().c_str(), 1); tmp = yggInputFmt("input", "%j"); EXPECT_FALSE(tmp.comm); unsetenv("input_IN"); } { - COMM_BASE alt("", nullptr, RECV); + COMM_BASE alt("", RECV); setenv("output_OUT", alt.getAddress().c_str(), 1); tmp = yggAsciiArrayOutput("output", "%j"); EXPECT_FALSE(tmp.comm); @@ -398,9 +398,9 @@ TEST(comm_t, Errors) { INTERFACE_TEST_BASE( Pointers, INIT_INPUT_BASE(yggInput, ("input"), COMM_BASE, - ("", nullptr, SEND)), + ("", SEND)), INIT_OUTPUT_BASE(yggOutputFmt, ("output", "%lf"), COMM_BASE, - ("", nullptr, RECV)), + ("", RECV)), INIT_DATA_PTRS, COMP_DATA_SINGLE, pcommSend, (1, pp_send, 0), sendVar, (data_send), pcommRecv, (0, 1, pp_recv, 0), recvVar, (data_recv), @@ -409,7 +409,7 @@ INTERFACE_TEST_BASE( TEST(YggInterface_C, GlobalServer) { { std::string name = "test_name"; - ClientComm sComm(name, nullptr); + ClientComm sComm(name); sComm.set_timeout_recv(1000); std::string key_env = name + "_IN"; std::string val_env = sComm.getAddress(); diff --git a/test/unittest/tests/communicators/interfacetest_cpp.cpp b/test/unittest/tests/communicators/interfacetest_cpp.cpp index db6ff67a..11325888 100644 --- a/test/unittest/tests/communicators/interfacetest_cpp.cpp +++ b/test/unittest/tests/communicators/interfacetest_cpp.cpp @@ -14,26 +14,26 @@ unsetenv("output_OUT") #define INIT_INPUT_NOARGS(cls) \ INIT_INPUT_BASE(cls ## Input, ("input"), COMM_BASE, \ - ("", nullptr, SEND)) + ("", SEND)) #define INIT_OUTPUT_NOARGS(cls) \ INIT_OUTPUT_BASE(cls ## Output, ("output"), COMM_BASE, \ - ("", nullptr, RECV)) + ("", RECV)) #define INIT_INPUT(cls, ...) \ INIT_INPUT_BASE(cls ## Input, ("input", __VA_ARGS__), COMM_BASE, \ - ("", nullptr, SEND)) + ("", SEND)) #define INIT_OUTPUT(cls, ...) \ INIT_OUTPUT_BASE(cls ## Output, ("output", __VA_ARGS__), COMM_BASE, \ - ("", nullptr, RECV)) + ("", RECV)) #define INIT_INPUT_RPC_NOARGS(cls) \ - INIT_INPUT_BASE(cls, ("input"), ClientComm, ("", nullptr)) + INIT_INPUT_BASE(cls, ("input"), ClientComm, ("")) #define INIT_OUTPUT_RPC_NOARGS(cls) \ - INIT_OUTPUT_BASE(cls, ("output"), ServerComm, ("", nullptr)) + INIT_OUTPUT_BASE(cls, ("output"), ServerComm, ("")) #define INIT_INPUT_RPC(cls, ...) \ INIT_INPUT_BASE(cls, ("input", __VA_ARGS__), ClientComm, \ - ("", nullptr)) + ("")) #define INIT_OUTPUT_RPC(cls, ...) \ INIT_OUTPUT_BASE(cls, ("output", __VA_ARGS__), ServerComm, \ - ("", nullptr)) + ("")) #define TRANSFER_INPUT_TYPE(init) \ sComm.copySchema(&rComm); \ init @@ -302,7 +302,7 @@ INTERFACE_TEST_NOARGS(JSONObject, YggJSONObject, TEST(YggInterface, GlobalServerPiecemeal) { { std::string name = "test_name"; - ClientComm sComm(name, nullptr); + ClientComm sComm(name); sComm.set_timeout_recv(1000); std::string name_req = name + "_input"; std::string name_res = name + "_output"; diff --git a/test/unittest/tests/communicators/ipccommtest.cpp b/test/unittest/tests/communicators/ipccommtest.cpp index a258100e..ab1216d7 100644 --- a/test/unittest/tests/communicators/ipccommtest.cpp +++ b/test/unittest/tests/communicators/ipccommtest.cpp @@ -22,13 +22,13 @@ COMM_SERI_TEST(IPCComm) TEST(IPCComm, constructor) { IPCComm_tester ipc; std::string name = ""; - IPCComm_tester ipc2(name, nullptr, SEND); + IPCComm_tester ipc2(name, SEND); EXPECT_TRUE(ipc2.getName().find("tempnewIPC") != std::string::npos); - utils::Address *adr = new utils::Address("this.is.a.test"); + utils::Address adr("this.is.a.test"); IPCComm_tester ipc3(name, adr, RECV); - utils::Address *adr2 = new utils::Address("12345"); + utils::Address adr2("12345"); name = "TestName"; EXPECT_THROW(IPCComm_tester ipc4(name, adr2, RECV), std::runtime_error); @@ -36,10 +36,10 @@ TEST(IPCComm, constructor) { name = ""; ELF_BEGIN; ELF_CREATE_T(IPC, 0); // To allow connection to non-existed queue - utils::Address *adr3 = new utils::Address("12345"); + utils::Address adr3("12345"); IPCComm_tester ipc5(name, adr3, RECV); RETVAL_CREATE = -1; - EXPECT_THROW(IPCComm_tester ipc6(name, nullptr, SEND), std::runtime_error); + EXPECT_THROW(IPCComm_tester ipc6(name, SEND), std::runtime_error); ELF_CREATE_REVERT_T(IPC); ELF_END; #endif // ELF_AVAILABLE @@ -49,16 +49,16 @@ TEST(IPCComm, send) { std::string message = "Hello world"; std::string name = ""; std::string msg_recv; - IPCComm_tester ipc_r(name, nullptr, RECV); + IPCComm_tester ipc_r(name, RECV); EXPECT_EQ(ipc_r.send(message.c_str(), message.size()), -1); - IPCComm_tester ipc(name, nullptr, SEND); + IPCComm_tester ipc(name, SEND); EXPECT_EQ(ipc.recv(msg_recv), -1); EXPECT_GT(ipc.send(message.c_str(), message.size()), 0); #ifdef ELF_AVAILABLE ELF_BEGIN; ELF_CREATE_T(IPC, 0); std::string data = "abcdef12345"; - utils::Address *adr2 = new utils::Address("12345678"); + utils::Address adr2("12345678"); IPCComm_tester ipc2(data, adr2, SEND); // Replace msgsnd and msgctl so that send fails, but msgctl succeeds ELF_REPLACE_SEND_IPC; @@ -91,7 +91,7 @@ TEST(IPCComm, send) { TEST(IPCComm, commnmsg) { std::string name = "Comm_nsg_test"; - IPCComm_tester ipc(name, NULL, SEND); + IPCComm_tester ipc(name, SEND); int res = ipc.comm_nmsg(); EXPECT_EQ(res, 0); @@ -118,7 +118,8 @@ TEST(IPCComm, sendLarge) { // Replace msgsnd to test sending long message ELF_REPLACE_SEND_IPC; ELF_SET_SUCCESS; - IPCComm_tester ipc(name, new utils::Address("2468"), SEND); + utils::Address adr("2468"); + IPCComm_tester ipc(name, adr, SEND); std::string msg(ipc.getMaxMsgSize() - 1, 'A'); EXPECT_GT(ipc.send(msg), 0); EXPECT_EQ(SENDCOUNT, 2); @@ -151,7 +152,8 @@ TEST(IPCComm, recv) { ELF_BEGIN; ELF_CREATE_T(IPC, 0); // To allow connection to non-existed queue ELF_SET_SUCCESS; - IPCComm_tester ipc(name, new utils::Address("13579"), RECV); + utils::Address adr("13579"); + IPCComm_tester ipc(name, adr, RECV); // Replace msgrcv to test different size messages ELF_RECV_T(IPC, 0); char* data = (char*)malloc(sizeof(char)); diff --git a/test/unittest/tests/communicators/mpicommtest.cpp b/test/unittest/tests/communicators/mpicommtest.cpp index a33f4ee9..56a13ef6 100644 --- a/test/unittest/tests/communicators/mpicommtest.cpp +++ b/test/unittest/tests/communicators/mpicommtest.cpp @@ -81,12 +81,12 @@ std::string mpi_registry_mock::msg = "This is a message"; class MPIComm_tester : public MPIComm { public: - MPIComm_tester(const std::string name = "", - utils::Address *address = new utils::Address(), + MPIComm_tester(const std::string name, + utils::Address& address, const DIRECTION direction = NONE) : MPIComm(name, address, direction), tmp(0) { init(); } MPIComm_tester(DIRECTION dir) : - MPIComm("", nullptr, dir), tmp(0) { init(); } + MPIComm("", dir), tmp(0) { init(); } MPIComm_tester(const std::string name, DIRECTION dir) : MPIComm(name, dir), tmp(0) { init(); } private: @@ -122,26 +122,31 @@ TEST(MPIComm, constructor) { INIT_MPI_TEST; std::string name = "TestMPIComm"; // EXPECT_THROW(MPIComm mpic(name, nullptr, SEND), std::runtime_error); - MPIComm_tester mpic(name, new utils::Address("50000,51000"), SEND); + utils::Address adr("50000,51000"); + MPIComm_tester mpic(name, adr, SEND); EXPECT_EQ(mpic.getAddresses().size(), 2); name = ""; - MPIComm mpic2(name, new utils::Address("50000,51000"), SEND); + utils::Address adr2("50000,51000"); + MPIComm mpic2(name, adr2, SEND); EXPECT_NE(mpic2.getName().find("tempinitMPI"), std::string::npos); - MPIComm_tester mpic3(name, new utils::Address("[50000], 51000"), RECV); - std::vector adrlist = mpic3.getAddresses(); + utils::Address adr3("[50000], 51000"); + MPIComm_tester mpic3(name, adr3, RECV); + std::vector adrlist = mpic3.getAddresses(); EXPECT_EQ(adrlist.size(), 2); - EXPECT_EQ(adrlist[0]->address(), "[50000]"); - EXPECT_EQ(adrlist[1]->address(), "51000"); + EXPECT_EQ(adrlist[0].address(), "[50000]"); + EXPECT_EQ(adrlist[1].address(), "51000"); } TEST(MPIComm, sourceID) { INIT_MPI_TEST; std::string name = ""; - MPIComm mpic(name, new utils::Address("50000"), SEND); + utils::Address adr("50000"); + MPIComm mpic(name, adr, SEND); mpi_registry_mock::MPIPROC = 0; EXPECT_EQ(mpic.mpi_comm_source_id(), 0); - MPIComm_tester mpic2(name, new utils::Address("51000,50000"), RECV); + utils::Address adr2("51000,50000"); + MPIComm_tester mpic2(name, adr2, RECV); mpi_registry_mock::MPIPROC = 0; EXPECT_EQ(mpic2.mpi_comm_source_id(), 0); @@ -167,7 +172,8 @@ TEST(MPIComm, sourceID) { TEST(MPIComm, commnmsg) { INIT_MPI_TEST; - MPIComm_tester mpic("", new utils::Address("51000,50000"), RECV); + utils::Address adr("51000,50000"); + MPIComm_tester mpic("", adr, RECV); mpi_registry_mock::MPIPROC = 0; EXPECT_EQ(mpic.comm_nmsg(), 0); @@ -180,7 +186,8 @@ TEST(MPIComm, commnmsg) { TEST(MPIComm, send) { INIT_MPI_TEST; - MPIComm_tester mpic("", new utils::Address("51000,50000"), SEND); + utils::Address adr("51000,50000"); + MPIComm_tester mpic("", adr, SEND); EXPECT_GT(mpic.send("Hello", 6), 0); mpi_registry_mock::MPISTATUS = 2; @@ -207,7 +214,8 @@ TEST(MPIComm, send) { TEST(MPIComm, recv) { INIT_MPI_TEST; - MPIComm_tester mpic("", new utils::Address("51000,50000"), RECV); + utils::Address adr("51000,50000"); + MPIComm_tester mpic("", adr, RECV); char* data = (char*)malloc(sizeof(char) * 1); size_t len = 1; mpic.set_timeout_recv(1000); @@ -264,9 +272,9 @@ TEST(MPIComm, recv) { #else // MPIINSTALLED TEST(MPIComm, errors) { - EXPECT_THROW(MPIComm mpi, std::exception); - std::string name = ""; - EXPECT_THROW(MPIComm mpi2(name, nullptr, SEND), std::exception); + //EXPECT_THROW(MPIComm mpi, std::exception); + //std::string name = ""; + //EXPECT_THROW(MPIComm mpi2(name, nullptr, SEND), std::exception); } #endif // MPIINSTALLED diff --git a/test/unittest/tests/communicators/servercommtest.cpp b/test/unittest/tests/communicators/servercommtest.cpp index 20ff53b2..6a98bb55 100644 --- a/test/unittest/tests/communicators/servercommtest.cpp +++ b/test/unittest/tests/communicators/servercommtest.cpp @@ -16,8 +16,11 @@ namespace communication { namespace testing { class ServerComm_tester : public ServerComm { public: - ServerComm_tester(const std::string &name = "", utils::Address *address = nullptr) : + ServerComm_tester(const std::string &name, utils::Address& address) : ServerComm(name, address), client_requests(RECV) {} + ServerComm_tester(const std::string &name="") : + ServerComm(name), client_requests(RECV) {} + bool addRequest() { utils::Header header(NULL, 0, this); if (client_requests.addRequestClient(header) < 0) @@ -38,14 +41,14 @@ class ServerComm_tester : public ServerComm { TEST(ServerComm, constructor) { std::string name = "MyComm"; - ServerComm sc(name, nullptr); - ServerComm sc1("", nullptr); + ServerComm sc(name); + ServerComm sc1(""); } TEST(ServerComm, send) { std::string msg = "my message"; std::string name = "MyComm"; - communication::testing::ServerComm_tester sc(name, nullptr); + communication::testing::ServerComm_tester sc(name); EXPECT_EQ(sc.send(msg.c_str(), msg.size()), -1); sc.addRequest(); EXPECT_GE(sc.send(msg.c_str(), msg.size()), 0); @@ -65,12 +68,14 @@ TEST(ServerComm, recv) { char* data = (char*)malloc(sizeof(char)); size_t len = 1; - communication::testing::ServerComm_tester sc(name, nullptr); + communication::testing::ServerComm_tester sc(name); + utils::Address addr(sc.getAddress()); + ClientComm cc(name, addr); ELF_BEGIN; ELF_RECV(0); RETMSG_META = "\"request_id\": \"12345\", \"response_address\": \"\""; - ELF_META(sc); + ELF_META(cc); // Failure in realloc EXPECT_EQ(sc.recv(data, len, false), -RETMSG.size()); // Success @@ -87,8 +92,9 @@ TEST(ServerComm, recv) { TEST(ServerComm, signon) { std::string name = "MyComm"; - ServerComm sc(name, nullptr); - ClientComm cc(name, new utils::Address(sc.getAddress())); + ServerComm sc(name); + utils::Address addr(sc.getAddress()); + ClientComm cc(name, addr); // Send signon then message std::string msg_send = "Hello world"; std::string msg_recv; diff --git a/test/unittest/tests/communicators/zmqcommtest.cpp b/test/unittest/tests/communicators/zmqcommtest.cpp index c759012f..6943138d 100644 --- a/test/unittest/tests/communicators/zmqcommtest.cpp +++ b/test/unittest/tests/communicators/zmqcommtest.cpp @@ -31,7 +31,7 @@ class ZMQComm_tester : public ZMQComm { public: TESTER_METHODS(ZMQComm) - std::string getAdr() { return address->address();} + std::string getAdr() { return address.address();} void setReply() { // this->getReply()->addresses.push_back(new communication::utils::Address("ABCDE")); @@ -70,9 +70,9 @@ COMM_SERI_TEST(ZMQComm) TEST(ZMQComm, constructor) { std::string name = ""; ZMQSocket::resetPort(); - ZMQComm_tester zmqc(name, nullptr, SEND); + ZMQComm_tester zmqc(name, SEND); EXPECT_EQ(zmqc.comm_nmsg(), 0); - auto *adrs = new utils::Address(); + utils::Address adrs; ZMQComm_tester zmqr(name, adrs, RECV); EXPECT_EQ(zmqr.comm_nmsg(), 0); #ifdef ELF_AVAILABLE @@ -89,19 +89,20 @@ TEST(ZMQComm, constructor) { // Failure to create socket { ELF_CREATE_T(ZMQ, -1); - EXPECT_THROW(ZMQComm zmqc(name, nullptr, SEND), std::exception); + EXPECT_THROW(ZMQComm zmqc1(name, SEND), std::exception); ELF_CREATE_REVERT_T(ZMQ); } // Failure to set socket options { ELF_BEGIN_F(zmq_setsockopt); - EXPECT_THROW(ZMQComm zmqc(name, nullptr, SEND), std::runtime_error); + EXPECT_THROW(ZMQComm zmqc2(name, SEND), std::runtime_error); ELF_END_F(zmq_setsockopt); } // Failure to connect { ELF_BEGIN_F(zmq_connect); - EXPECT_THROW(ZMQComm zmqc("", new utils::Address("1.2.3.4"), RECV), + utils::Address adr("1.2.3.4"); + EXPECT_THROW(ZMQComm zmqc3("", adr, RECV), std::exception); ELF_END_F(zmq_connect); } @@ -110,7 +111,7 @@ TEST(ZMQComm, constructor) { RETVAL = EADDRINUSE; ELF_BEGIN_F(zmq_bind); ELF_BEGIN_F(zmq_errno); - EXPECT_THROW(ZMQComm zmqc(name, nullptr, SEND), std::runtime_error); + EXPECT_THROW(ZMQComm zmqc4(name, SEND), std::runtime_error); ELF_END_F(zmq_bind); ELF_END_F(zmq_errno); } @@ -118,10 +119,10 @@ TEST(ZMQComm, constructor) { // Failure to get socket options ELF_BEGIN_F(zmq_getsockopt); RETMSG = ""; - EXPECT_THROW(ZMQComm zmqc(name, nullptr, SEND), std::runtime_error); + EXPECT_THROW(ZMQComm zmqc5(name, SEND), std::runtime_error); // Failure to get endpoint RETMSG = "invalid"; - EXPECT_THROW(ZMQComm zmqc(name, nullptr, SEND), std::runtime_error); + EXPECT_THROW(ZMQComm zmqc6(name, SEND), std::runtime_error); ELF_END_F(zmq_getsockopt); } ELF_END; @@ -130,8 +131,9 @@ TEST(ZMQComm, constructor) { TEST(ZMQComm, exchange) { std::string name = "TestZMQ"; - ZMQComm sComm(name, nullptr, SEND); - ZMQComm rComm(name, new utils::Address(sComm.getAddress()), RECV); + ZMQComm sComm(name, SEND); + utils::Address adr(sComm.getAddress()); + ZMQComm rComm(name, adr, RECV); std::string msg_send = "This is a test message"; std::string msg_recv; EXPECT_GT(sComm.sendVar(msg_send), 0); @@ -184,7 +186,7 @@ TEST(ZMQComm, send) { #ifdef ELF_AVAILABLE std::string name = "TestZMQSend"; std::string mmsg = "This is a test message"; - ZMQComm_tester zmq(name, nullptr, SEND); + ZMQComm_tester zmq(name, SEND); zmq.setReply(); ELF_BEGIN; // Failure to create message @@ -211,8 +213,8 @@ TEST(ZMQComm, send) { TEST(ZMQComm, recv) { std::string name = "TestZMQSend"; - ZMQComm_tester zmq_recv(name, nullptr, RECV); - ZMQComm_tester zmq_send(name, nullptr, SEND); + ZMQComm_tester zmq_recv(name, RECV); + ZMQComm_tester zmq_send(name, SEND); #ifdef ELF_AVAILABLE ELF_BEGIN; char* data = NULL; @@ -260,7 +262,7 @@ TEST(ZMQComm, recv) { } TEST(ZMQComm, errors) { - ZMQComm comm("", nullptr, SEND); + ZMQComm comm("", SEND); std::string msg; comm.getReply().clear(); EXPECT_FALSE(comm.getReply().recv_stage1(msg)); diff --git a/test/unittest/tests/datatypes/dtypetest.cpp b/test/unittest/tests/datatypes/dtypetest.cpp index 8d76b394..f7b6c070 100644 --- a/test/unittest/tests/datatypes/dtypetest.cpp +++ b/test/unittest/tests/datatypes/dtypetest.cpp @@ -557,9 +557,14 @@ TEST(dtype, PythonInit) { } #ifndef YGGDRASIL_DISABLE_PYTHON_C_API +#ifdef RAPIDJSON_DONT_IMPORT_NUMPY +#define CHECK_ARRAY_API EXPECT_FALSE(rapidjson_ARRAY_API) +#else // RAPIDJSON_DONT_IMPORT_NUMPY +#define CHECK_ARRAY_API EXPECT_TRUE(rapidjson_ARRAY_API) +#endif // RAPIDJSON_DONT_IMPORT_NUMPY #define DO_PYTHON(name) \ TEST(generic_t, name) { \ - EXPECT_TRUE(rapidjson_ARRAY_API); \ + CHECK_ARRAY_API; \ generic_t v = init_generic_generate("{\"type\": \"" #name "\"}"); \ generic_t x = init_generic_null(); \ python_t data; \ diff --git a/test/unittest/tests/utils/testutils.cpp b/test/unittest/tests/utils/testutils.cpp index 984d2864..70333a9f 100644 --- a/test/unittest/tests/utils/testutils.cpp +++ b/test/unittest/tests/utils/testutils.cpp @@ -54,7 +54,7 @@ TEST(ADDRESS, Init) { EXPECT_EQ(0, adrc.key()); EXPECT_NE(adrc.address(), adr->address()); - auto* adrcmp = new Address(adr); + auto* adrcmp = new Address(*adr); EXPECT_TRUE(adrcmp->valid()); EXPECT_EQ(adrcmp->address(), adr->address()); EXPECT_NE(adr, adrcmp);