diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b919e8a9..d84fbaac 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -96,6 +96,19 @@ add_testsuite(Message ${definitions} ) +add_testsuite(Region + SOURCES + ${CMAKE_CURRENT_BINARY_DIR}/runner.cxx + region/_region.cxx + + LINKS FairMQ + INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/region + ${CMAKE_CURRENT_BINARY_DIR} + TIMEOUT 5 + ${definitions} +) + add_testsuite(Device SOURCES ${CMAKE_CURRENT_BINARY_DIR}/runner.cxx diff --git a/test/region/_region.cxx b/test/region/_region.cxx new file mode 100644 index 00000000..f7d8bd1f --- /dev/null +++ b/test/region/_region.cxx @@ -0,0 +1,103 @@ +/******************************************************************************** + * Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +#include +#include +#include +#include + +#include + +#include + +namespace +{ + +using namespace std; + +void RegionEventSubscriptions(const string& transport) +{ + size_t session{fair::mq::tools::UuidHash()}; + + fair::mq::ProgOptions config; + config.SetProperty("session", to_string(session)); + + auto factory = FairMQTransportFactory::CreateTransportFactory(transport, fair::mq::tools::Uuid(), &config); + + constexpr int size1 = 1000000; + constexpr int size2 = 5000000; + constexpr int64_t userFlags = 12345; + fair::mq::tools::SharedSemaphore blocker; + + { + auto region1 = factory->CreateUnmanagedRegion(size1, [](void*, size_t, void*) {}); + void* ptr1 = region1->GetData(); + uint64_t id1 = region1->GetId(); + ASSERT_EQ(region1->GetSize(), size1); + + auto region2 = factory->CreateUnmanagedRegion(size2, userFlags, [](void*, size_t, void*) {}); + void* ptr2 = region2->GetData(); + uint64_t id2 = region2->GetId(); + ASSERT_EQ(region2->GetSize(), size2); + + ASSERT_EQ(factory->SubscribedToRegionEvents(), false); + factory->SubscribeToRegionEvents([&](FairMQRegionInfo info) { + LOG(warn) << ">>>" << info.event; + LOG(warn) << "id: " << info.id; + LOG(warn) << "ptr: " << info.ptr; + LOG(warn) << "size: " << info.size; + LOG(warn) << "flags: " << info.flags; + if (info.event == FairMQRegionEvent::created) { + if (info.id == id1) { + ASSERT_EQ(info.size, size1); + ASSERT_EQ(info.ptr, ptr1); + blocker.Signal(); + } else if (info.id == id2) { + ASSERT_EQ(info.size, size2); + ASSERT_EQ(info.ptr, ptr2); + ASSERT_EQ(info.flags, userFlags); + blocker.Signal(); + } + } else if (info.event == FairMQRegionEvent::destroyed) { + if (info.id == id1) { + blocker.Signal(); + } else if (info.id == id2) { + blocker.Signal(); + } + } + }); + ASSERT_EQ(factory->SubscribedToRegionEvents(), true); + + LOG(info) << "waiting for blockers..."; + blocker.Wait(); + LOG(info) << "1 done."; + blocker.Wait(); + LOG(info) << "2 done."; + } + + blocker.Wait(); + LOG(info) << "3 done."; + blocker.Wait(); + LOG(info) << "4 done."; + LOG(info) << "All done."; + + factory->UnsubscribeFromRegionEvents(); + ASSERT_EQ(factory->SubscribedToRegionEvents(), false); +} + +TEST(EventSubscriptions, zeromq) +{ + RegionEventSubscriptions("zeromq"); +} + +TEST(EventSubscriptions, shmem) +{ + RegionEventSubscriptions("shmem"); +} + +} // namespace