-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add an interoperability test to HELICS and fix some issue with JSON generation Co-authored-by: Philip Top <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
c7aae79
commit 3715e65
Showing
10 changed files
with
224 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Copyright (c) 2017-2021, Battelle Memorial Institute; Lawrence Livermore | ||
# National Security, LLC; Alliance for Sustainable Energy, LLC. | ||
# See the top-level NOTICE for additional details. | ||
# All rights reserved. | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
add_executable(interopFed1 InterOpFed1.cpp) | ||
|
||
target_link_libraries(interopFed1 PUBLIC helics_application_api) | ||
target_link_libraries(interopFed1 PRIVATE compile_flags_target) | ||
set_target_properties(interopFed1 PROPERTIES FOLDER examples) | ||
|
||
add_executable(interopFed2 InterOpFed2.cpp) | ||
|
||
target_link_libraries(interopFed2 PUBLIC helics_application_api) | ||
target_link_libraries(interopFed2 PRIVATE compile_flags_target) | ||
set_target_properties(interopFed2 PROPERTIES FOLDER examples) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
Copyright (c) 2017-2021, | ||
Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable | ||
Energy, LLC. See the top-level NOTICE for additional details. All rights reserved. | ||
SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
#include "helics/application_api/BrokerApp.hpp" | ||
#include "helics/application_api/CombinationFederate.hpp" | ||
#include "helics/application_api/Endpoints.hpp" | ||
#include "helics/application_api/Publications.hpp" | ||
#include "helics/application_api/Subscriptions.hpp" | ||
|
||
#include <iostream> | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
helics::FederateInfo fi(argc, argv); | ||
fi.setProperty(helics_property_time_period, 1.0); | ||
helics::BrokerApp brk(fi.coreType, fi.brokerInitString + " -f 2"); | ||
|
||
auto cFed = std::make_unique<helics::CombinationFederate>("ioFed1", fi); | ||
auto name = cFed->getName(); | ||
|
||
helics::data_block mbuf(256, 0); | ||
for (int ii = 0; ii < 256; ++ii) { | ||
mbuf[ii] = char(ii); | ||
} | ||
// this line actually creates an endpoint | ||
auto& ept = cFed->registerEndpoint("ept"); | ||
|
||
auto& pubid = cFed->registerPublication("pub", "double"); | ||
|
||
auto& subid = cFed->registerSubscription("ioFed2/pub"); | ||
|
||
cFed->enterInitializingMode(); | ||
cFed->enterExecutingMode(); | ||
bool passed{true}; | ||
for (int i = 1; i < 10; ++i) { | ||
std::string mback = std::string(" at time ") + std::to_string(i); | ||
std::string message = std::string("message sent from ioFed1 to ioFed2"); | ||
message.append(mback); | ||
ept.send("ioFed2/ept", message.data(), message.size()); | ||
ept.send("ioFed2/ept", mbuf); | ||
|
||
pubid.publish(i); | ||
|
||
auto newTime = cFed->requestTime(i); | ||
|
||
if (cFed->isUpdated(subid)) { | ||
auto val = subid.getValue<int>(); | ||
if (val != i) { | ||
passed = false; | ||
} | ||
} else { | ||
passed = false; | ||
} | ||
if (ept.pendingMessages() != 2) { | ||
passed = false; | ||
} else { | ||
auto m1 = ept.getMessage(); | ||
if (m1->data.to_string().find(mback) == std::string::npos) { | ||
passed = false; | ||
} | ||
auto m2 = ept.getMessage(); | ||
if (mbuf != m2->data) { | ||
passed = false; | ||
} | ||
} | ||
} | ||
cFed->finalize(); | ||
brk.waitForDisconnect(); | ||
if (passed) { | ||
std::cout << "Federate1 has PASSED the test"; | ||
} else { | ||
std::cout << "Federate1 has FAILED the test"; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
Copyright (c) 2017-2021, | ||
Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable | ||
Energy, LLC. See the top-level NOTICE for additional details. All rights reserved. | ||
SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#include "helics/application_api/CombinationFederate.hpp" | ||
#include "helics/application_api/Endpoints.hpp" | ||
#include "helics/application_api/Publications.hpp" | ||
#include "helics/application_api/Subscriptions.hpp" | ||
|
||
#include <iostream> | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
helics::FederateInfo fi(argc, argv); | ||
fi.setProperty(helics_property_time_period, 1.0); | ||
|
||
auto cFed = std::make_unique<helics::CombinationFederate>("ioFed2", fi); | ||
auto name = cFed->getName(); | ||
|
||
helics::data_block mbuf(256, 0); | ||
for (int ii = 0; ii < 256; ++ii) { | ||
mbuf[ii] = char(ii); | ||
} | ||
// this line actually creates an endpoint | ||
auto& ept = cFed->registerEndpoint("ept"); | ||
|
||
auto& pubid = cFed->registerPublication("pub", "double"); | ||
|
||
auto& subid = cFed->registerSubscription("ioFed1/pub"); | ||
|
||
cFed->enterInitializingMode(); | ||
cFed->enterExecutingMode(); | ||
bool passed{true}; | ||
for (int i = 1; i < 10; ++i) { | ||
std::string mback = std::string(" at time ") + std::to_string(i); | ||
std::string message = std::string("message sent from ioFed2 to ioFed1"); | ||
message.append(mback); | ||
ept.send("ioFed1/ept", message.data(), message.size()); | ||
ept.send("ioFed1/ept", mbuf); | ||
pubid.publish(i); | ||
|
||
auto newTime = cFed->requestTime(i); | ||
|
||
if (cFed->isUpdated(subid)) { | ||
auto val = subid.getValue<int>(); | ||
if (val != i) { | ||
passed = false; | ||
} | ||
} else { | ||
passed = false; | ||
} | ||
if (ept.pendingMessages() != 2) { | ||
passed = false; | ||
} else { | ||
auto m1 = ept.getMessage(); | ||
if (m1->data.to_string().find(mback) == std::string::npos) { | ||
passed = false; | ||
} | ||
auto m2 = ept.getMessage(); | ||
if (mbuf != m2->data) { | ||
auto s1 = std::string(mbuf.to_string()); | ||
auto s2 = std::string(m2->to_string()); | ||
passed = false; | ||
} | ||
} | ||
} | ||
cFed->finalize(); | ||
|
||
if (passed) { | ||
std::cout << "Federate 2 has PASSED the test"; | ||
} else { | ||
std::cout << "Federate 2 has FAILED the test"; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters