mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 08:41:16 +00:00
Add unit tests for regions
This commit is contained in:
parent
e9318dd234
commit
8cfc04721e
|
@ -96,6 +96,19 @@ add_testsuite(Message
|
||||||
${definitions}
|
${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
|
add_testsuite(Device
|
||||||
SOURCES
|
SOURCES
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/runner.cxx
|
${CMAKE_CURRENT_BINARY_DIR}/runner.cxx
|
||||||
|
|
103
test/region/_region.cxx
Normal file
103
test/region/_region.cxx
Normal file
|
@ -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 <FairMQLogger.h>
|
||||||
|
#include <FairMQTransportFactory.h>
|
||||||
|
#include <fairmq/ProgOptions.h>
|
||||||
|
#include <fairmq/Tools.h>
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void RegionEventSubscriptions(const string& transport)
|
||||||
|
{
|
||||||
|
size_t session{fair::mq::tools::UuidHash()};
|
||||||
|
|
||||||
|
fair::mq::ProgOptions config;
|
||||||
|
config.SetProperty<string>("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
|
Loading…
Reference in New Issue
Block a user