Skip to content

Commit

Permalink
add some tests with filter config files and make sure the cloning fil… (
Browse files Browse the repository at this point in the history
#2676)

### Git Log Summary

- **Added Tests**
  - Implemented tests with filter config files.
  - Ensured that cloning filters default to clone as the operation.

- **Clang-Tidy Fixes**
  - Fixed various clang-tidy warnings and issues.
  - Applied clang-tidy checks and made necessary fixes.

- **Pre-commit Auto Fixes**
  - Applied auto-fixes from pre-commit.com hooks multiple times.
  - For more information, see [pre-commit.ci](https://pre-commit.ci).

- **Code Review Suggestions**
  - Incorporated suggestions from code review.

### Co-authors
Co-authored-by: Ryan Mast [email protected]
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
phlptp authored Oct 10, 2024
1 parent 194ec85 commit ce55368
Show file tree
Hide file tree
Showing 11 changed files with 1,301 additions and 996 deletions.
35 changes: 21 additions & 14 deletions src/helics/application_api/Federate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,12 +1252,10 @@ static Translator& generateTranslator(Federate* fed,
}
return trans;
}

static Filter& generateFilter(Federate* fed,
static Filter& registerFilter(Federate* fed,
bool global,
bool cloning,
std::string_view name,
FilterTypes operation,
std::string_view inputType,
std::string_view outputType)
{
Expand All @@ -1271,14 +1269,20 @@ static Filter& generateFilter(Federate* fed,
fed->registerFilter(name, inputType, outputType);
}
if (cloning) {
Filter& filt =
(global) ? fed->registerGlobalCloningFilter(name) : fed->registerCloningFilter(name);
if (operation != FilterTypes::CUSTOM) {
filt.setFilterType(static_cast<std::int32_t>(operation));
}
return filt;
return (global) ? fed->registerGlobalCloningFilter(name) : fed->registerCloningFilter(name);
}
Filter& filt = (global) ? fed->registerCloningFilter(name) : fed->registerFilter(name);
return (global) ? fed->registerGlobalFilter(name) : fed->registerFilter(name);
}

static Filter& generateFilter(Federate* fed,
bool global,
bool cloning,
std::string_view name,
FilterTypes operation,
std::string_view inputType,
std::string_view outputType)
{
auto& filt = registerFilter(fed, global, cloning, name, inputType, outputType);
if (operation != FilterTypes::CUSTOM) {
filt.setFilterType(static_cast<std::int32_t>(operation));
}
Expand Down Expand Up @@ -1436,17 +1440,20 @@ void Federate::registerConnectorInterfacesJsonDetail(const fileops::JsonBuffer&
const std::string key = getOrDefault(filt, "name", emptyStr);
const std::string inputType = getOrDefault(filt, "inputType", emptyStr);
const std::string outputType = getOrDefault(filt, "outputType", emptyStr);
const bool cloningflag = getOrDefault(filt, "cloning", false);
const bool cloningFlag = getOrDefault(filt, "cloning", false);
const bool useTypes = !((inputType.empty()) && (outputType.empty()));
const bool global = fileops::getOrDefault(filt, "global", defaultGlobal);
const std::string operation = getOrDefault(filt, "operation", std::string("custom"));
const std::string operation =
getOrDefault(filt,
"operation",
(cloningFlag) ? std::string("clone") : std::string("custom"));

auto opType = filterTypeFromString(operation);
if (!checkValidFilterType(useTypes, opType, operation)) {
continue;
}
auto& filter =
generateFilter(this, global, cloningflag, key, opType, inputType, outputType);
generateFilter(this, global, cloningFlag, key, opType, inputType, outputType);
loadOptions(this, filt, filter);

addTargetVariations(filt, "source", "endpoints", [&filter](const std::string& target) {
Expand All @@ -1459,7 +1466,7 @@ void Federate::registerConnectorInterfacesJsonDetail(const fileops::JsonBuffer&
filter.addDestinationTarget(target);
});

if (cloningflag) {
if (cloningFlag) {
addTargets(filt, "delivery", [&filter](const std::string& target) {
static_cast<CloningFilter&>(filter).addDeliveryEndpoint(target);
});
Expand Down
1 change: 1 addition & 0 deletions src/helics/application_api/Filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SPDX-License-Identifier: BSD-3-Clause
namespace helics {
static const std::map<std::string_view, FilterTypes> filterTypes{
{"clone", FilterTypes::CLONE},
{"cloning", FilterTypes::CLONE},
{"delay", FilterTypes::DELAY},
{"randomdelay", FilterTypes::RANDOM_DELAY},
{"random_delay", FilterTypes::RANDOM_DELAY},
Expand Down
6 changes: 6 additions & 0 deletions src/helics/application_api/MessageFederate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ static void loadOptions(MessageFederate* fed, const Inp& data, Endpoint& ept)
addTargetVariations(data, "destination", "endpoints", [&ept](std::string_view endpoint) {
ept.addDestinationEndpoint(endpoint);
});
addTargetVariations(data, "source", "targets", [&ept](std::string_view endpoint) {
ept.addSourceEndpoint(endpoint);
});
addTargetVariations(data, "destination", "targets", [&ept](std::string_view endpoint) {
ept.addDestinationEndpoint(endpoint);
});
addTargets(data, "destFilters", [&ept](std::string_view filt) {
ept.addDestinationFilter(filt);
});
Expand Down
36 changes: 21 additions & 15 deletions src/helics/application_api/MessageFederateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ SPDX-License-Identifier: BSD-3-Clause
namespace helics {
MessageFederateManager::MessageFederateManager(Core* coreOb,
MessageFederate* fed,
LocalFederateId id,
LocalFederateId fedid,
bool singleThreaded):
mLocalEndpoints(!singleThreaded), coreObject(coreOb), mFed(fed), fedID(id),
mLocalEndpoints(!singleThreaded), coreObject(coreOb), mFed(fed), fedID(fedid),
eptData(!singleThreaded), messageOrder(!singleThreaded)
{
}
Expand Down Expand Up @@ -113,11 +113,12 @@ bool MessageFederateManager::hasMessage() const

bool MessageFederateManager::hasMessage(const Endpoint& ept)
{
bool result{false};
if (ept.dataReference != nullptr) {
auto* eptDat = reinterpret_cast<EndpointData*>(ept.dataReference);
return (!eptDat->messages.empty());
auto* eptDat = static_cast<EndpointData*>(ept.dataReference);
result = (!eptDat->messages.empty());
}
return false;
return result;
}

/**
Expand All @@ -126,7 +127,7 @@ bool MessageFederateManager::hasMessage(const Endpoint& ept)
uint64_t MessageFederateManager::pendingMessageCount(const Endpoint& ept)
{
if (ept.dataReference != nullptr) {
auto* eptDat = reinterpret_cast<EndpointData*>(ept.dataReference);
auto* eptDat = static_cast<EndpointData*>(ept.dataReference);
return eptDat->messages.size();
}
return 0;
Expand All @@ -139,20 +140,25 @@ prefer to just use getMessage until it returns an invalid Message.
uint64_t MessageFederateManager::pendingMessageCount() const
{
auto eptDat = eptData.lock_shared();
uint64_t sz = 0;
return std::accumulate(eptDat.begin(), eptDat.end(), 0, [](uint64_t count, const auto& ept) {
return count + static_cast<uint64_t>(ept.messages.size());
});
/*
uint64_t size{ 0 };
for (const auto& mq : eptDat) {
sz += mq.messages.size();
size = size + mq.messages.size();
}
return sz;
return size;
*/
}

std::unique_ptr<Message> MessageFederateManager::getMessage(const Endpoint& ept)
{
if (ept.dataReference != nullptr) {
auto* eptDat = reinterpret_cast<EndpointData*>(ept.dataReference);
auto mv = eptDat->messages.pop();
if (mv) {
return std::move(*mv);
auto message = eptDat->messages.pop();
if (message) {
return std::move(*message);
}
}
return nullptr;
Expand All @@ -164,9 +170,9 @@ std::unique_ptr<Message> MessageFederateManager::getMessage()
auto eptDat = eptData.lock();
for (auto& edat : eptDat) {
if (!edat.messages.empty()) {
auto ms = edat.messages.pop();
if (ms) {
return std::move(*ms);
auto message = edat.messages.pop();
if (message) {
return std::move(*message);
}
}
}
Expand Down
Loading

0 comments on commit ce55368

Please sign in to comment.