Skip to content

Commit

Permalink
tests: replace Boost.MPL with Mp11
Browse files Browse the repository at this point in the history
Change-Id: I2e8410f4acb7f25b5cb9d7846f05163414095cc7
  • Loading branch information
Pesa committed Jan 28, 2024
1 parent 2c9d2ca commit f56cf63
Show file tree
Hide file tree
Showing 23 changed files with 223 additions and 314 deletions.
6 changes: 3 additions & 3 deletions tests/daemon/face/datagram-transport.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand All @@ -26,7 +26,7 @@
#include "unicast-udp-transport-fixture.hpp"
#include "multicast-udp-transport-fixture.hpp"

#include <boost/mpl/vector.hpp>
#include <boost/mp11/list.hpp>

namespace nfd::tests {

Expand All @@ -35,7 +35,7 @@ using namespace nfd::face;
BOOST_AUTO_TEST_SUITE(Face)
BOOST_AUTO_TEST_SUITE(TestDatagramTransport)

using DatagramTransportFixtures = boost::mpl::vector<
using DatagramTransportFixtures = boost::mp11::mp_list<
GENERATE_IP_TRANSPORT_FIXTURE_INSTANTIATIONS(UnicastUdpTransportFixture),
IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V4, AddressScope::Global, MulticastInterface::Yes>,
IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::LinkLocal, MulticastInterface::Yes>,
Expand Down
6 changes: 3 additions & 3 deletions tests/daemon/face/multicast-udp-transport.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand All @@ -25,7 +25,7 @@

#include "multicast-udp-transport-fixture.hpp"

#include <boost/mpl/vector.hpp>
#include <boost/mp11/list.hpp>

namespace nfd::tests {

Expand All @@ -34,7 +34,7 @@ using namespace nfd::face;
BOOST_AUTO_TEST_SUITE(Face)
BOOST_AUTO_TEST_SUITE(TestMulticastUdpTransport)

using MulticastUdpTransportFixtures = boost::mpl::vector<
using MulticastUdpTransportFixtures = boost::mp11::mp_list<
IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V4, AddressScope::Global, MulticastInterface::Yes>,
IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::LinkLocal, MulticastInterface::Yes>,
IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::Global, MulticastInterface::Yes>
Expand Down
6 changes: 3 additions & 3 deletions tests/daemon/face/stream-transport.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand All @@ -27,7 +27,7 @@
#include "unix-stream-transport-fixture.hpp"

#include <boost/asio/read.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mp11/list.hpp>

namespace nfd::tests {

Expand All @@ -36,7 +36,7 @@ using namespace nfd::face;
BOOST_AUTO_TEST_SUITE(Face)
BOOST_AUTO_TEST_SUITE(TestStreamTransport)

using StreamTransportFixtures = boost::mpl::vector<
using StreamTransportFixtures = boost::mp11::mp_list<
GENERATE_IP_TRANSPORT_FIXTURE_INSTANTIATIONS(TcpTransportFixture),
UnixStreamTransportFixture
>;
Expand Down
8 changes: 3 additions & 5 deletions tests/daemon/face/tcp-channel.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand All @@ -27,16 +27,14 @@

#include "test-ip.hpp"

#include <boost/mpl/vector.hpp>
#include <boost/mp11/list.hpp>

namespace nfd::tests {

BOOST_AUTO_TEST_SUITE(Face)
BOOST_FIXTURE_TEST_SUITE(TestTcpChannel, TcpChannelFixture)

using AddressFamilies = boost::mpl::vector<
std::integral_constant<AddressFamily, AddressFamily::V4>,
std::integral_constant<AddressFamily, AddressFamily::V6>>;
using AddressFamilies = boost::mp11::mp_list_c<AddressFamily, AddressFamily::V4, AddressFamily::V6>;

BOOST_AUTO_TEST_CASE_TEMPLATE(ConnectTimeout, F, AddressFamilies)
{
Expand Down
6 changes: 3 additions & 3 deletions tests/daemon/face/tcp-transport.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand All @@ -25,7 +25,7 @@

#include "tcp-transport-fixture.hpp"

#include <boost/mpl/vector.hpp>
#include <boost/mp11/list.hpp>

namespace nfd::tests {

Expand All @@ -34,7 +34,7 @@ using namespace nfd::face;
BOOST_AUTO_TEST_SUITE(Face)
BOOST_FIXTURE_TEST_SUITE(TestTcpTransport, IpTransportFixture<TcpTransportFixture>)

using TcpTransportFixtures = boost::mpl::vector<
using TcpTransportFixtures = boost::mp11::mp_list<
GENERATE_IP_TRANSPORT_FIXTURE_INSTANTIATIONS(TcpTransportFixture)
>;

Expand Down
6 changes: 3 additions & 3 deletions tests/daemon/face/tcp-udp-channel.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -28,7 +28,7 @@

#include "test-ip.hpp"

#include <boost/mpl/vector.hpp>
#include <boost/mp11/list.hpp>

namespace nfd::tests {

Expand All @@ -43,7 +43,7 @@ struct FixtureAndAddress
using Address = IpAddressTypeFromFamily<AF>;
};

using FixtureAndAddressList = boost::mpl::vector<
using FixtureAndAddressList = boost::mp11::mp_list<
FixtureAndAddress<TcpChannelFixture, AddressFamily::V4>,
FixtureAndAddress<TcpChannelFixture, AddressFamily::V6>,
FixtureAndAddress<UdpChannelFixture, AddressFamily::V4>,
Expand Down
140 changes: 46 additions & 94 deletions tests/daemon/face/transport.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -31,18 +31,14 @@
#include "tests/daemon/face/dummy-link-service.hpp"
#include "tests/daemon/face/dummy-transport.hpp"

#include <boost/mpl/fold.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/lambda.hpp>
#include <boost/mpl/map.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/set.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mp11/algorithm.hpp>
#include <boost/mp11/bind.hpp>
#include <boost/mp11/map.hpp>
#include <boost/mp11/set.hpp>

namespace nfd::tests {

namespace mpl = boost::mpl;
using namespace boost::mp11;
using namespace nfd::face;

BOOST_AUTO_TEST_SUITE(Face)
Expand All @@ -68,90 +64,49 @@ BOOST_AUTO_TEST_CASE(PersistencyChange)
BOOST_CHECK_EQUAL(transport->persistencyHistory.back(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
}

/** \brief A macro to declare a TransportState as a integral constant.
* \note we cannot use mpl::integral_c because TransportState is not an integral type
*/
#define TRANSPORT_STATE_C(X) mpl::int_<static_cast<int>(TransportState::X)>

/** \brief A map from every TransportState to a valid state transition sequence
* for entering this state from UP.
*/
typedef mpl::map<
mpl::pair<TRANSPORT_STATE_C(UP),
mpl::vector<>>,
mpl::pair<TRANSPORT_STATE_C(DOWN),
mpl::vector<
TRANSPORT_STATE_C(DOWN)
>>,
mpl::pair<TRANSPORT_STATE_C(CLOSING),
mpl::vector<
TRANSPORT_STATE_C(CLOSING)
>>,
mpl::pair<TRANSPORT_STATE_C(FAILED),
mpl::vector<
TRANSPORT_STATE_C(FAILED)
>>,
mpl::pair<TRANSPORT_STATE_C(CLOSED),
mpl::vector<
TRANSPORT_STATE_C(CLOSING),
TRANSPORT_STATE_C(CLOSED)
>>
> StateEntering;

/** \brief A sequence of all valid TransportStates.
*/
typedef mpl::fold<StateEntering,
mpl::vector<>,
mpl::push_back<mpl::_1, mpl::first<mpl::_2>>
>::type States;

/** \brief A set of all valid state transitions.
*/
typedef mpl::set<
mpl::pair<TRANSPORT_STATE_C(UP), TRANSPORT_STATE_C(DOWN)>,
mpl::pair<TRANSPORT_STATE_C(DOWN), TRANSPORT_STATE_C(UP)>,
mpl::pair<TRANSPORT_STATE_C(UP), TRANSPORT_STATE_C(CLOSING)>,
mpl::pair<TRANSPORT_STATE_C(UP), TRANSPORT_STATE_C(FAILED)>,
mpl::pair<TRANSPORT_STATE_C(DOWN), TRANSPORT_STATE_C(CLOSING)>,
mpl::pair<TRANSPORT_STATE_C(DOWN), TRANSPORT_STATE_C(FAILED)>,
mpl::pair<TRANSPORT_STATE_C(CLOSING), TRANSPORT_STATE_C(CLOSED)>,
mpl::pair<TRANSPORT_STATE_C(FAILED), TRANSPORT_STATE_C(CLOSED)>
> ValidStateTransitions;

/** \brief A metafunction to generate a sequence of all state transitions
* from a specified state.
*/
template<typename FromState, typename Result>
struct StateTransitionsFrom : mpl::fold<
States,
Result,
mpl::push_back<mpl::_1, mpl::pair<FromState, mpl::_2>>>
{
};

/** \brief A sequence of all state transitions.
*/
typedef mpl::fold<
States,
mpl::vector<>,
mpl::lambda<StateTransitionsFrom<mpl::_2, mpl::_1>>
>::type AllStateTransitions;

#undef TRANSPORT_STATE_C
// Map from every TransportState to a valid state transition sequence
// for entering this state from UP.
using StateInitSequence = mp_list<
mp_list_c<TransportState, TransportState::UP /* nothing to do, state is already UP */>,
mp_list_c<TransportState, TransportState::DOWN, TransportState::DOWN>,
mp_list_c<TransportState, TransportState::CLOSING, TransportState::CLOSING>,
mp_list_c<TransportState, TransportState::FAILED, TransportState::FAILED>,
mp_list_c<TransportState, TransportState::CLOSED, TransportState::CLOSING, TransportState::CLOSED>
>;
static_assert(mp_is_map<StateInitSequence>());

using TransportStates = mp_map_keys<StateInitSequence>;

// The set of all state transitions (cartesian product of TransportStates)
using AllStateTransitions = mp_product<mp_list, TransportStates, TransportStates>;

// The set of *valid* state transitions
using ValidStateTransitions = mp_list<
mp_list_c<TransportState, TransportState::UP, TransportState::DOWN>,
mp_list_c<TransportState, TransportState::UP, TransportState::CLOSING>,
mp_list_c<TransportState, TransportState::UP, TransportState::FAILED>,
mp_list_c<TransportState, TransportState::DOWN, TransportState::UP>,
mp_list_c<TransportState, TransportState::DOWN, TransportState::CLOSING>,
mp_list_c<TransportState, TransportState::DOWN, TransportState::FAILED>,
mp_list_c<TransportState, TransportState::CLOSING, TransportState::CLOSED>,
mp_list_c<TransportState, TransportState::FAILED, TransportState::CLOSED>
>;
// Sanity check that there are no duplicates
static_assert(mp_is_set<ValidStateTransitions>());
// Sanity check that ValidStateTransitions is a proper subset of AllStateTransitions
static_assert(mp_all_of_q<ValidStateTransitions, mp_bind_front<mp_set_contains, AllStateTransitions>>());
static_assert(mp_size<ValidStateTransitions>() < mp_size<AllStateTransitions>());

BOOST_AUTO_TEST_CASE_TEMPLATE(SetState, T, AllStateTransitions)
{
auto transport = make_unique<DummyTransport>();

auto from = static_cast<TransportState>(T::first::value);
auto to = static_cast<TransportState>(T::second::value);
constexpr TransportState from = mp_first<T>::value;
constexpr TransportState to = mp_second<T>::value;
BOOST_TEST_INFO_SCOPE(from << " -> " << to);

// enter from state
using Steps = typename mpl::at<StateEntering, mpl::int_<T::first::value>>::type;
mpl::for_each<Steps>([&transport] (int state) {
transport->setState(static_cast<TransportState>(state));
});
auto transport = make_unique<DummyTransport>();
// initialize transport to the 'from' state
using Steps = mp_rest<mp_map_find<StateInitSequence, mp_first<T>>>;
mp_for_each<Steps>([&transport] (auto state) { transport->setState(state); });
BOOST_REQUIRE_EQUAL(transport->getState(), from);

bool hasSignal = false;
Expand All @@ -162,11 +117,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(SetState, T, AllStateTransitions)
});

// do transition
bool isValid = from == to ||
mpl::has_key<ValidStateTransitions,
mpl::pair<mpl::int_<T::first::value>, mpl::int_<T::second::value>>
>::value;
if (isValid) {
constexpr bool isValid = (from == to) || mp_set_contains<ValidStateTransitions, T>();
if constexpr (isValid) {
BOOST_REQUIRE_NO_THROW(transport->setState(to));
BOOST_CHECK_EQUAL(hasSignal, from != to);
}
Expand Down
8 changes: 3 additions & 5 deletions tests/daemon/face/udp-channel.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand All @@ -27,16 +27,14 @@

#include "test-ip.hpp"

#include <boost/mpl/vector.hpp>
#include <boost/mp11/list.hpp>

namespace nfd::tests {

BOOST_AUTO_TEST_SUITE(Face)
BOOST_FIXTURE_TEST_SUITE(TestUdpChannel, UdpChannelFixture)

using AddressFamilies = boost::mpl::vector<
std::integral_constant<AddressFamily, AddressFamily::V4>,
std::integral_constant<AddressFamily, AddressFamily::V6>>;
using AddressFamilies = boost::mp11::mp_list_c<AddressFamily, AddressFamily::V4, AddressFamily::V6>;

BOOST_AUTO_TEST_CASE_TEMPLATE(DefaultMtu, F, AddressFamilies)
{
Expand Down
13 changes: 6 additions & 7 deletions tests/daemon/face/unicast-udp-transport.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand All @@ -25,8 +25,7 @@

#include "unicast-udp-transport-fixture.hpp"

#include <boost/mpl/vector.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mp11/list.hpp>

namespace nfd::tests {

Expand All @@ -35,7 +34,7 @@ using namespace nfd::face;
BOOST_AUTO_TEST_SUITE(Face)
BOOST_FIXTURE_TEST_SUITE(TestUnicastUdpTransport, IpTransportFixture<UnicastUdpTransportFixture>)

using UnicastUdpTransportFixtures = boost::mpl::vector<
using UnicastUdpTransportFixtures = boost::mp11::mp_list<
GENERATE_IP_TRANSPORT_FIXTURE_INSTANTIATIONS(UnicastUdpTransportFixture)
>;

Expand Down Expand Up @@ -105,9 +104,9 @@ BOOST_AUTO_TEST_CASE(IdleClose)

using RemoteCloseFixture = IpTransportFixture<UnicastUdpTransportFixture,
AddressFamily::Any, AddressScope::Loopback>;
using RemoteClosePersistencies = boost::mpl::vector_c<ndn::nfd::FacePersistency,
ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
ndn::nfd::FACE_PERSISTENCY_PERSISTENT>;
using RemoteClosePersistencies = boost::mp11::mp_list_c<ndn::nfd::FacePersistency,
ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
ndn::nfd::FACE_PERSISTENCY_PERSISTENT>;

BOOST_FIXTURE_TEST_CASE_TEMPLATE(RemoteClose, Persistency, RemoteClosePersistencies, RemoteCloseFixture)
{
Expand Down
Loading

0 comments on commit f56cf63

Please sign in to comment.