Skip to content

Commit 15d1a84

Browse files
committed
[test] Re-enable unit tests
1 parent f550526 commit 15d1a84

File tree

6 files changed

+66
-85
lines changed

6 files changed

+66
-85
lines changed

CMakeLists.txt

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -274,44 +274,44 @@ endforeach()
274274
# Tests
275275
####################################
276276

277-
#enable_testing()
278-
#
279-
#set(TEST_SRCS
280-
# #test/TestChannelFactoryUtils.cxx
281-
# test/TestChannelPaths.cxx
282-
# test/TestCruDataFormat.cxx
283-
# test/TestEnums.cxx
284-
# #test/TestInterprocessLock.cxx
285-
# test/TestMemoryMappedFile.cxx
286-
# #test/TestParameters.cxx
287-
# test/TestPciAddress.cxx
288-
# test/TestProgramOptions.cxx
289-
# test/TestRorcException.cxx
290-
# test/TestSuperpageQueue.cxx
291-
#)
292-
#
293-
#if(PDA_FOUND)
294-
# list(APPEND TEST_SRCS test/TestCruBar.cxx)
295-
#endif()
296-
#
297-
#foreach (test ${TEST_SRCS})
298-
# get_filename_component(test_name ${test} NAME)
299-
# string(REGEX REPLACE ".cxx" "" test_name ${test_name})
300-
#
301-
# add_executable(${test_name} ${test} src/CommandLineUtilities/Options.cxx)
302-
# target_include_directories(${test_name}
303-
# PRIVATE
304-
# ${CMAKE_CURRENT_SOURCE_DIR}/src
305-
# )
306-
# target_link_libraries(${test_name}
307-
# PRIVATE
308-
# ReadoutCard
309-
# Boost::unit_test_framework
310-
# $<$<BOOL:${PDA_FOUND}>:pda::pda>
311-
# )
312-
# add_test(NAME ${test_name} COMMAND ${test_name})
313-
# set_tests_properties(${test_name} PROPERTIES TIMEOUT 15)
314-
#endforeach()
277+
enable_testing()
278+
279+
set(TEST_SRCS
280+
test/TestChannelFactoryUtils.cxx
281+
test/TestChannelPaths.cxx
282+
test/TestCruDataFormat.cxx
283+
test/TestEnums.cxx
284+
test/TestInterprocessLock.cxx
285+
test/TestMemoryMappedFile.cxx
286+
test/TestParameters.cxx
287+
test/TestPciAddress.cxx
288+
test/TestProgramOptions.cxx
289+
test/TestRorcException.cxx
290+
test/TestSuperpageQueue.cxx
291+
)
292+
293+
if(PDA_FOUND)
294+
list(APPEND TEST_SRCS test/TestCruBar.cxx)
295+
endif()
296+
297+
foreach (test ${TEST_SRCS})
298+
get_filename_component(test_name ${test} NAME)
299+
string(REGEX REPLACE ".cxx" "" test_name ${test_name})
300+
301+
add_executable(${test_name} ${test} src/CommandLineUtilities/Options.cxx)
302+
target_include_directories(${test_name}
303+
PRIVATE
304+
${CMAKE_CURRENT_SOURCE_DIR}/src
305+
)
306+
target_link_libraries(${test_name}
307+
PRIVATE
308+
ReadoutCard
309+
Boost::unit_test_framework
310+
$<$<BOOL:${PDA_FOUND}>:pda::pda>
311+
)
312+
add_test(NAME ${test_name} COMMAND ${test_name})
313+
set_tests_properties(${test_name} PROPERTIES TIMEOUT 15)
314+
endforeach()
315315

316316

317317
####################################

include/ReadoutCard/Exception.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct LockException : virtual Exception {
4646
};
4747
struct FileLockException : virtual LockException {
4848
};
49-
struct NamedMutexLockException : virtual LockException {
49+
struct SocketLockException : virtual LockException {
5050
};
5151
struct DeviceFinderException : virtual Exception {
5252
};

src/ExceptionInternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ DEFINE_ERRINFO(GeneratorEventLength, size_t);
6868
DEFINE_ERRINFO(Index, size_t);
6969
DEFINE_ERRINFO(LinkId, uint32_t);
7070
DEFINE_ERRINFO(DataSource, ::AliceO2::roc::DataSource::type);
71-
DEFINE_ERRINFO(NamedMutexName, std::string);
7271
DEFINE_ERRINFO(Offset, size_t);
7372
DEFINE_ERRINFO(PageIndex, int);
7473
DEFINE_ERRINFO(Pages, size_t);
@@ -98,6 +97,7 @@ DEFINE_ERRINFO(SharedLockFile, std::string);
9897
DEFINE_ERRINFO(SharedObjectName, std::string);
9998
DEFINE_ERRINFO(SharedStateFile, std::string);
10099
DEFINE_ERRINFO(SiuCommand, int);
100+
DEFINE_ERRINFO(SocketLockName, std::string);
101101
DEFINE_ERRINFO(String, std::string);
102102
DEFINE_ERRINFO(StwExpected, std::string);
103103
DEFINE_ERRINFO(StwReceived, std::string);

test/TestChannelFactoryUtils.cxx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
///
44
/// \author Pascal Boeschoten ([email protected])
55

6-
#include "ReadoutCard/CardType.h"
6+
#include "Dummy/DummyBar.h"
7+
#include "Dummy/DummyDmaChannel.h"
8+
#include "ReadoutCard/BarInterface.h"
79
#include "ReadoutCard/ChannelFactory.h"
10+
#include "ReadoutCard/DmaChannelInterface.h"
811
#include "Factory/ChannelFactoryUtils.h"
9-
#include <map>
1012
#include <memory>
1113

1214
#define BOOST_TEST_MODULE RORC_TestChannelFactoryUtils
@@ -21,31 +23,27 @@ using namespace ::AliceO2::roc;
2123
namespace
2224
{
2325

24-
struct TestInterface {
25-
TestInterface() {}
26-
virtual ~TestInterface() {}
27-
};
28-
29-
struct DummyImpl : public TestInterface {
30-
};
31-
struct CrorcImpl : public TestInterface {
32-
};
33-
struct CruImpl : public TestInterface {
34-
};
26+
// Helper function for calling the DMA channel factory
27+
std::unique_ptr<DmaChannelInterface> produceDma()
28+
{
29+
auto parameters = Parameters::makeParameters(ChannelFactory::getDummySerialId(), 0);
30+
return ChannelFactoryUtils::dmaChannelFactoryHelper<DmaChannelInterface>(parameters);
31+
}
3532

36-
// Helper function for calling the factory make function
37-
std::unique_ptr<TestInterface> callMake()
33+
// Helper function for calling the BAR factory
34+
std::unique_ptr<BarInterface> produceBar()
3835
{
3936
auto parameters = Parameters::makeParameters(ChannelFactory::getDummySerialId(), 0);
40-
return ChannelFactoryUtils::channelFactoryHelper<TestInterface>(parameters, ChannelFactory::getDummySerialId(), { { CardType::Dummy, [] { return std::make_unique<DummyImpl>(); } }, { CardType::Crorc, [] { return std::make_unique<CrorcImpl>(); } }, { CardType::Cru, [] { return std::make_unique<CruImpl>(); } } });
37+
return ChannelFactoryUtils::barFactoryHelper<BarInterface>(parameters);
4138
}
4239

43-
// This tests if the FactoryHelper::make() function maps to the expected types.
40+
// This tests if the FactoryHelper functions for the DMA channel and the BAR maps to the expected types.
4441
// Unfortunately, we can't test the entire make function, since it depends on having actual PCI cards installed, so
4542
// we test only part of its implementation.
4643
BOOST_AUTO_TEST_CASE(ChannelFactoryHelperTest)
4744
{
48-
BOOST_CHECK(nullptr != dynamic_cast<DummyImpl*>(callMake().get()));
45+
BOOST_CHECK(nullptr != dynamic_cast<DummyDmaChannel*>(produceDma().get()));
46+
BOOST_CHECK(nullptr != dynamic_cast<DummyBar*>(produceBar().get()));
4947
}
5048

5149
} // Anonymous namespace

test/TestInterprocessLock.cxx

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
///
44
/// \author Pascal Boeschoten ([email protected])
55

6-
//TODO: Update this for the socket lock
76
#define BOOST_TEST_MODULE RORC_TestFileSharedObject
87
#define BOOST_TEST_MAIN
98
#define BOOST_TEST_DYN_LINK
@@ -16,37 +15,26 @@
1615
#include <condition_variable>
1716
#include <iostream>
1817
#include <boost/test/unit_test.hpp>
19-
#include <boost/filesystem.hpp>
2018
#include <boost/exception/all.hpp>
21-
#include "InterprocessLock.h"
19+
#include "ReadoutCard/InterprocessLock.h"
2220

2321
#include "ReadoutCard/Exception.h"
2422

2523
namespace
2624
{
2725

2826
using namespace ::AliceO2::roc;
29-
namespace b = boost;
30-
namespace bip = boost::interprocess;
31-
namespace bfs = boost::filesystem;
3227

3328
struct TestObject {
3429
TestObject(const std::string& s, int i) : string(s), integer(i) {}
3530
std::string string;
3631
int integer;
3732
};
3833

39-
const std::string namedMutexName("AliceO2_InterprocessMutex_Test");
40-
const bfs::path lockFilePath("/tmp/AliceO2_InterprocessMutex_Test.lock");
41-
42-
void cleanupFiles()
43-
{
44-
bip::named_mutex::remove(namedMutexName.c_str());
45-
bfs::remove(lockFilePath);
46-
}
34+
const std::string lockName("AliceO2_InterprocessMutex_Test");
4735

4836
#define CONSTRUCT_LOCK() \
49-
Interprocess::Lock _test_lock { lockFilePath, namedMutexName }
37+
Interprocess::Lock _test_lock { lockName }
5038

5139
void doLock()
5240
{
@@ -56,8 +44,6 @@ void doLock()
5644
// Test the intraprocess locking
5745
BOOST_AUTO_TEST_CASE(InterprocessMutexTestIntraprocess)
5846
{
59-
cleanupFiles();
60-
6147
std::condition_variable conditionVariable;
6248
std::atomic<bool> childAcquired(false);
6349

@@ -68,7 +54,7 @@ BOOST_AUTO_TEST_CASE(InterprocessMutexTestIntraprocess)
6854
childAcquired = true;
6955
conditionVariable.notify_all();
7056
std::this_thread::sleep_for(std::chrono::milliseconds(100));
71-
} catch (const LockException& e) {
57+
} catch (const SocketLockException& e) {
7258
BOOST_FAIL("Child failed to acquire FileSharedObject");
7359
}
7460
});
@@ -80,7 +66,7 @@ BOOST_AUTO_TEST_CASE(InterprocessMutexTestIntraprocess)
8066
if (!status) {
8167
BOOST_FAIL("Timed out or child failed to acquire lock");
8268
}
83-
BOOST_CHECK_THROW(doLock(), NamedMutexLockException);
69+
BOOST_CHECK_THROW(doLock(), SocketLockException);
8470

8571
// Wait on child thread
8672
future.get();
@@ -93,8 +79,6 @@ BOOST_AUTO_TEST_CASE(InterprocessMutexTestIntraprocess)
9379
// - The parent tries to acquire while the child has it -> it should fail
9480
BOOST_AUTO_TEST_CASE(InterprocessMutexTestInterprocess)
9581
{
96-
cleanupFiles();
97-
9882
pid_t pid = fork();
9983

10084
if (pid == 0) {
@@ -103,7 +87,6 @@ BOOST_AUTO_TEST_CASE(InterprocessMutexTestInterprocess)
10387
CONSTRUCT_LOCK();
10488
std::this_thread::sleep_for(std::chrono::milliseconds(100));
10589
}
106-
cleanupFiles();
10790
exit(0);
10891
} else if (pid > 0) {
10992
// Parent

test/TestParameters.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ BOOST_AUTO_TEST_CASE(ParametersConstructors)
2626
Parameters p;
2727
Parameters p2 = p;
2828
Parameters p3 = std::move(p2);
29-
Parameters p4 = Parameters::makeParameters({ SERIAL_NUMBER, ENDPOINT_NUMBER }, CHANNEL_NUMBER); //TODO: Check makeParameters
29+
Parameters p4 = Parameters::makeParameters(SerialId{ SERIAL_NUMBER, ENDPOINT_NUMBER }, CHANNEL_NUMBER); //TODO: Check makeParameters
3030
}
3131

3232
BOOST_AUTO_TEST_CASE(ParametersPutGetTest)
3333
{
34-
Parameters p = Parameters::makeParameters({ SERIAL_NUMBER, ENDPOINT_NUMBER }, CHANNEL_NUMBER)
34+
Parameters p = Parameters::makeParameters(SerialId{ SERIAL_NUMBER, ENDPOINT_NUMBER }, CHANNEL_NUMBER)
3535
.setDmaPageSize(DMA_PAGE_SIZE)
3636
.setDataSource(DATA_SOURCE)
3737
.setBufferParameters(buffer_parameters::File{ "/my/file.shm", 0 });
3838

39-
BOOST_REQUIRE(boost::get<int>(p.getCardId().get()) == SERIAL_NUMBER);
39+
BOOST_REQUIRE(boost::get<SerialId>(p.getCardId().get()) == (SerialId{ SERIAL_NUMBER, ENDPOINT_NUMBER }));
4040
BOOST_REQUIRE(p.getChannelNumber().get_value_or(0) == CHANNEL_NUMBER);
4141
BOOST_REQUIRE(p.getDmaPageSize().get_value_or(0) == DMA_PAGE_SIZE);
4242
BOOST_REQUIRE(p.getDataSource().get_value_or(DataSource::Fee) == DATA_SOURCE);
4343

44-
BOOST_REQUIRE(boost::get<int>(p.getCardIdRequired()) == SERIAL_NUMBER);
44+
BOOST_REQUIRE(boost::get<SerialId>(p.getCardIdRequired()) == (SerialId{ SERIAL_NUMBER, ENDPOINT_NUMBER }));
4545
BOOST_REQUIRE(p.getChannelNumberRequired() == CHANNEL_NUMBER);
4646
BOOST_REQUIRE(p.getDmaPageSizeRequired() == DMA_PAGE_SIZE);
4747
BOOST_REQUIRE(p.getDataSourceRequired() == DATA_SOURCE);
@@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(ParametersPutGetTest)
5252

5353
BOOST_AUTO_TEST_CASE(ParametersThrowTest)
5454
{
55-
auto p = Parameters::makeParameters({ SERIAL_NUMBER, ENDPOINT_NUMBER }, CHANNEL_NUMBER);
55+
auto p = Parameters::makeParameters(SerialId{ SERIAL_NUMBER, ENDPOINT_NUMBER }, CHANNEL_NUMBER);
5656
}
5757

5858
BOOST_AUTO_TEST_CASE(ParametersLinkMaskFromString)

0 commit comments

Comments
 (0)