diff --git a/src/test/traced/traced-callback-typedef-test-suite.cc b/src/test/traced/traced-callback-typedef-test-suite.cc index 21cabee47..4706e4702 100644 --- a/src/test/traced/traced-callback-typedef-test-suite.cc +++ b/src/test/traced/traced-callback-typedef-test-suite.cc @@ -44,6 +44,23 @@ using namespace ns3; +/** + * \file + * \ingroup system-tests-traced + * + * TracedCallback tests to verify if they are called with + * the right type and number of arguments. + */ + + +/** + * \ingroup system-tests-traced + * + * TracedCallback Testcase. + * + * This test verifies that the TracedCallback is called with + * the right type and number of arguments. + */ class TracedCallbackTypedefTestCase : public TestCase { public: @@ -60,30 +77,14 @@ public: * in the \c m_nArgs public value, then inspect it * in the CheckType() method. */ - static int m_nArgs; + static std::size_t m_nArgs; private: - /** Invoker boilerplate. */ - template - class CheckerBase; /** Callback checkers. */ - template + template class Checker; - template - class Checker; - - template - class Checker; - - - template - class Checker; - - template - class Checker; - virtual void DoRun (void); }; // TracedCallbackTypedefTestCase @@ -96,7 +97,12 @@ private: namespace { -/** Record typedefs which are identical to previously declared. */ +/** + * \ingroup system-tests-traced + * + * Record typedefs which are identical to previously declared. + * \return a container of strings representing the duplicates. + */ std::set Duplicates (void) { @@ -112,12 +118,16 @@ Duplicates (void) } /** + * \ingroup system-tests-traced + * * Container for duplicate types. */ std::set g_dupes = Duplicates (); /** + * \ingroup system-tests-traced + * * Stringify the known TracedCallback type names. * * \tparam T \explicit The typedef name. @@ -131,6 +141,11 @@ std::string TypeName (int N) return "unknown"; } +/** + * \ingroup system-tests-traced + * + * Returns a sting representing the type of a class. +*/ #define TYPENAME(T) \ template <> \ inline std::string \ @@ -142,8 +157,13 @@ std::string TypeName (int N) } /** + * \ingroup system-tests-traced + * * \name Stringify known typename. +*/ +/** * @{ + * \brief Stringify a known typename */ TYPENAME (dsr::DsrOptionSRHeader::TracedCallback); TYPENAME (EpcUeNas::StateTracedCallback); @@ -156,7 +176,7 @@ TYPENAME (Ipv6L3Protocol::TxRxTracedCallback); TYPENAME (LrWpanMac::SentTracedCallback); TYPENAME (LrWpanMac::StateTracedCallback); TYPENAME (LrWpanPhy::StateTracedCallback); -// TYPENAME (LteEnbMac::DlSchedulingTracedCallback); +TYPENAME (LteEnbMac::DlSchedulingTracedCallback); TYPENAME (LteEnbMac::UlSchedulingTracedCallback); TYPENAME (LteEnbPhy::ReportInterferenceTracedCallback); TYPENAME (LteEnbPhy::ReportUeSinrTracedCallback); @@ -205,6 +225,8 @@ TYPENAME (WifiRemoteStationManager::RateChangeTracedCallback); /** + * \ingroup system-tests-traced + * * Log that a callback was invoked. * * We can't actually do anything with any of the arguments, @@ -212,67 +234,32 @@ TYPENAME (WifiRemoteStationManager::RateChangeTracedCallback); * * \param [in] N The number of arguments passed to the callback. */ -void SinkIt (unsigned int N) +void SinkIt (std::size_t N) { std::cout << "with " << N << " args." << std::endl; TracedCallbackTypedefTestCase::m_nArgs = N; } /** + * \ingroup system-tests-traced + * * Sink functions. - * @{ */ -template +template class TracedCbSink { public: - static void Sink (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) + /** + * \brief Sink function, called by a TracedCallback. + * \tparam Ts prameters of the TracedCallback. + */ + static void Sink (Ts...) { - SinkIt (5); + const std::size_t n = sizeof...(Ts); + SinkIt (n); } }; -template -class TracedCbSink -{ -public: - static void Sink (T1 a1, T2 a2, T3 a3, T4 a4) - { - SinkIt (4); - } -}; - -template -class TracedCbSink -{ -public: - static void Sink (T1 a1, T2 a2, T3 a3) - { - SinkIt (3); - } -}; - -template -class TracedCbSink -{ -public: - static void Sink (T1 a1, T2 a2) - { - SinkIt (2); - } -}; - -template -class TracedCbSink< T1, empty, empty, empty, empty> -{ -public: - static void Sink (T1 a1) - { - SinkIt (1); - } -}; -/** @} */ - } // unnamed namespace @@ -286,142 +273,65 @@ public: -------------------------------------------------------------------- */ -int TracedCallbackTypedefTestCase::m_nArgs = 0; +std::size_t TracedCallbackTypedefTestCase::m_nArgs = 0; -template -class TracedCallbackTypedefTestCase::CheckerBase : public Object +template +class TracedCallbackTypedefTestCase::Checker : public Object { + /// TracedCallback to be called. + TracedCallback m_cb; public: - typename TypeTraits::BaseType m1; - typename TypeTraits::BaseType m2; - typename TypeTraits::BaseType m3; - typename TypeTraits::BaseType m4; - typename TypeTraits::BaseType m5; + Checker () {}; + virtual ~Checker () {}; + + /// Arguments of the TracedCallback. + std::tuple::BaseType...> m_items; - void Cleanup (int N) + /// Number of arguments of the TracedCallback. + const std::size_t m_nItems = sizeof...(Ts); + + /** + * Invoke a TracedCallback. + */ + template + void Invoke (void) + { + U sink = TracedCbSink::Sink; + Callback cb = MakeCallback (sink); + + std::cout << TypeName (m_nItems) << " invoked "; + m_cb.ConnectWithoutContext (cb); + std::apply(m_cb, m_items); + Cleanup (); + } + + /** + * Cleanup the test. + */ + void Cleanup () { if (m_nArgs == 0) { std::cout << std::endl; } - NS_ASSERT_MSG (m_nArgs && m_nArgs == N, "failed."); + NS_ASSERT_MSG (m_nArgs && m_nArgs == m_nItems, "failed, m_nArgs: " << m_nArgs << " N: " << m_nItems); m_nArgs = 0; } -}; // TracedCallbackTypedefTestCase::CheckerBase -template -class TracedCallbackTypedefTestCase::Checker : public CheckerBase -{ - TracedCallback m_cb; +}; -public: - template - void Invoke (void) - { - const int N = 5; - U sink = TracedCbSink::Sink; - Callback cb = MakeCallback (sink); - - std::cout << TypeName (N) << " invoked "; - m_cb.ConnectWithoutContext (cb); - m_cb (this->m1, this->m2, this->m3, this->m4, this->m5); - this->Cleanup (N); - } -}; // Checker<5> - -template -class TracedCallbackTypedefTestCase::Checker - : public CheckerBase -{ - TracedCallback m_cb; - -public: - template - void Invoke (void) - { - const int N = 4; - U sink = TracedCbSink::Sink; - Callback cb = MakeCallback (sink); - - std::cout << TypeName (N) << " invoked "; - m_cb.ConnectWithoutContext (cb); - m_cb (this->m1, this->m2, this->m3, this->m4); - this->Cleanup (N); - } -}; // Checker <4> - -template -class TracedCallbackTypedefTestCase::Checker - : public CheckerBase -{ - TracedCallback m_cb; - -public: - template - void Invoke (void) - { - const int N = 3; - U sink = TracedCbSink::Sink; - Callback cb = MakeCallback (sink); - - std::cout << TypeName (N) << " invoked "; - m_cb.ConnectWithoutContext (cb); - m_cb (this->m1, this->m2, this->m3); - this->Cleanup (N); - } -}; // Checker<3> - -template -class TracedCallbackTypedefTestCase::Checker - : public CheckerBase -{ - TracedCallback m_cb; - -public: - template - void Invoke (void) - { - const int N = 2; - U sink = TracedCbSink::Sink; - Callback cb = MakeCallback (sink); - - std::cout << TypeName (N) << " invoked "; - m_cb.ConnectWithoutContext (cb); - m_cb (this->m1, this->m2); - this->Cleanup (N); - } -}; // Checker<2> - -template -class TracedCallbackTypedefTestCase::Checker - : public CheckerBase -{ - TracedCallback m_cb; - -public: - template - void Invoke (void) - { - const int N = 1; - U sink = TracedCbSink::Sink; - Callback cb = MakeCallback (sink); - - std::cout << TypeName (N) << " invoked "; - m_cb.ConnectWithoutContext (cb); - m_cb (this->m1); - this->Cleanup (N); - } -}; // Checker<1> TracedCallbackTypedefTestCase::TracedCallbackTypedefTestCase () : TestCase ("Check basic TracedCallback operation") { } -void -TracedCallbackTypedefTestCase::DoRun (void) -{ - +/** + * \ingroup system-tests-traced + * + * Check the TracedCallback duplicate by checking if it maches the TracedCallback + * it is supposed to be equal to. + */ #define DUPE(U, T1) \ if (g_dupes.find ( # U ) == g_dupes.end ()) { \ NS_TEST_ASSERT_MSG_NE (0, 1, \ @@ -435,95 +345,85 @@ TracedCallbackTypedefTestCase::DoRun (void) " used to match the typedef " << # T1 << \ " but no longer does. Please add a new CHECK call.") -#define CHECK(U, T1, T2, T3, T4, T5) \ - CreateObject< Checker > ()->Invoke () + +/** + * \ingroup system-tests-traced + * + * Check the TracedCallback by calling its Invoke function. + */ +#define CHECK(U, ...) \ + CreateObject< Checker< __VA_ARGS__ > > ()->Invoke () + + +void +TracedCallbackTypedefTestCase::DoRun (void) +{ CHECK (dsr::DsrOptionSRHeader::TracedCallback, - const dsr::DsrOptionSRHeader &, - empty, empty, empty, empty); + const dsr::DsrOptionSRHeader &); CHECK (EpcUeNas::StateTracedCallback, - EpcUeNas::State, EpcUeNas::State, - empty, empty, empty); + EpcUeNas::State, EpcUeNas::State); CHECK (Ipv4L3Protocol::DropTracedCallback, const Ipv4Header &, Ptr, Ipv4L3Protocol::DropReason, Ptr, uint32_t ); CHECK (Ipv4L3Protocol::SentTracedCallback, - const Ipv4Header &, Ptr, uint32_t, - empty, empty); + const Ipv4Header &, Ptr, uint32_t); CHECK (Ipv4L3Protocol::TxRxTracedCallback, - Ptr, Ptr, uint32_t, - empty, empty); + Ptr, Ptr, uint32_t); CHECK (Ipv6L3Protocol::DropTracedCallback, const Ipv6Header &, Ptr, - Ipv6L3Protocol::DropReason, Ptr, uint32_t - ); + Ipv6L3Protocol::DropReason, Ptr, uint32_t); CHECK (Ipv6L3Protocol::SentTracedCallback, - const Ipv6Header &, Ptr, uint32_t, - empty, empty); + const Ipv6Header &, Ptr, uint32_t); CHECK (Ipv6L3Protocol::TxRxTracedCallback, - Ptr, Ptr, uint32_t, - empty, empty); + Ptr, Ptr, uint32_t); CHECK (LrWpanMac::SentTracedCallback, - Ptr, uint8_t, uint8_t, - empty, empty); + Ptr, uint8_t, uint8_t); CHECK (LrWpanMac::StateTracedCallback, - LrWpanMacState, LrWpanMacState, - empty, empty, empty); + LrWpanMacState, LrWpanMacState); CHECK (LrWpanPhy::StateTracedCallback, - Time, LrWpanPhyEnumeration, LrWpanPhyEnumeration, - empty, empty); + Time, LrWpanPhyEnumeration, LrWpanPhyEnumeration); - - /* Too many args :( CHECK (LteEnbMac::DlSchedulingTracedCallback, uint32_t, uint32_t, uint16_t, - uint8_t, uint16_t, uint8_t, uint16_t); - */ + uint8_t, uint16_t, uint8_t, uint16_t, uint8_t); CHECK (LteEnbMac::UlSchedulingTracedCallback, uint32_t, uint32_t, uint16_t, uint8_t, uint16_t); CHECK (LteEnbPhy::ReportUeSinrTracedCallback, - uint16_t, uint16_t, double, uint8_t, - empty); + uint16_t, uint16_t, double, uint8_t); CHECK (LteEnbPhy::ReportInterferenceTracedCallback, - uint16_t, Ptr, - empty, empty, empty); + uint16_t, Ptr); CHECK (LteEnbRrc::ConnectionHandoverTracedCallback, - uint64_t, uint16_t, uint16_t, - empty, empty); + uint64_t, uint16_t, uint16_t); CHECK (LteEnbRrc::HandoverStartTracedCallback, - uint64_t, uint16_t, uint16_t, uint16_t, - empty); + uint64_t, uint16_t, uint16_t, uint16_t); CHECK (LteEnbRrc::NewUeContextTracedCallback, - uint16_t, uint16_t, - empty, empty, empty); + uint16_t, uint16_t); CHECK (LteEnbRrc::ReceiveReportTracedCallback, - uint64_t, uint16_t, uint16_t, LteRrcSap::MeasurementReport, - empty); + uint64_t, uint16_t, uint16_t, LteRrcSap::MeasurementReport); CHECK (LtePdcp::PduRxTracedCallback, - uint16_t, uint8_t, uint32_t, uint64_t, - empty); + uint16_t, uint8_t, uint32_t, uint64_t); CHECK (LtePdcp::PduTxTracedCallback, - uint16_t, uint8_t, uint32_t, - empty, empty); + uint16_t, uint8_t, uint32_t); DUPE (LteRlc::NotifyTxTracedCallback, LtePdcp::PduTxTracedCallback); @@ -533,12 +433,10 @@ TracedCallbackTypedefTestCase::DoRun (void) uint16_t, uint16_t, double, double, uint8_t); CHECK (LteUePhy::StateTracedCallback, - uint16_t, uint16_t, LteUePhy::State, LteUePhy::State, - empty); + uint16_t, uint16_t, LteUePhy::State, LteUePhy::State); CHECK (LteUeRrc::CellSelectionTracedCallback, - uint64_t, uint16_t, - empty, empty, empty); + uint64_t, uint16_t); DUPE (LteUeRrc::ImsiCidRntiTracedCallback, LteEnbRrc::ConnectionHandoverTracedCallback); @@ -548,130 +446,105 @@ TracedCallbackTypedefTestCase::DoRun (void) uint64_t, uint16_t, uint16_t, LteUeRrc::State, LteUeRrc::State); CHECK (Mac48Address::TracedCallback, - Mac48Address, - empty, empty, empty, empty); + Mac48Address); CHECK (MobilityModel::TracedCallback, - Ptr, - empty, empty, empty, empty); + Ptr); CHECK (olsr::RoutingProtocol::PacketTxRxTracedCallback, - const olsr::PacketHeader &, const olsr::MessageList &, - empty, empty, empty); + const olsr::PacketHeader &, const olsr::MessageList &); CHECK (olsr::RoutingProtocol::TableChangeTracedCallback, - uint32_t, - empty, empty, empty, empty); + uint32_t); CHECK (Packet::AddressTracedCallback, - Ptr, const Address &, - empty, empty, empty); + Ptr, const Address &); CHECK (Packet::Mac48AddressTracedCallback, - Ptr, Mac48Address, - empty, empty, empty); + Ptr, Mac48Address); CHECK (Packet::SinrTracedCallback, - Ptr, double, - empty, empty, empty); + Ptr, double); CHECK (Packet::SizeTracedCallback, - uint32_t, uint32_t, - empty, empty, empty); + uint32_t, uint32_t); CHECK (Packet::TracedCallback, - Ptr, - empty, empty, empty, empty); + Ptr); CHECK (PacketBurst::TracedCallback, - Ptr, - empty, empty, empty, empty); + Ptr); CHECK (dot11s::PeerManagementProtocol::LinkOpenCloseTracedCallback, - Mac48Address, Mac48Address, - empty, empty, empty); + Mac48Address, Mac48Address); CHECK (PhyReceptionStatParameters::TracedCallback, - PhyReceptionStatParameters, - empty, empty, empty, empty); + PhyReceptionStatParameters); CHECK (PhyTransmissionStatParameters::TracedCallback, - PhyTransmissionStatParameters, - empty, empty, empty, empty); + PhyTransmissionStatParameters); CHECK (SixLowPanNetDevice::DropTracedCallback, SixLowPanNetDevice::DropReason, Ptr, - Ptr, uint32_t, - empty); + Ptr, uint32_t); CHECK (SixLowPanNetDevice::RxTxTracedCallback, - Ptr, Ptr, uint32_t, - empty, empty); + Ptr, Ptr, uint32_t); CHECK (SpectrumChannel::LossTracedCallback, - Ptr, Ptr, double, - empty, empty); + Ptr, Ptr, double); CHECK (SpectrumValue::TracedCallback, - Ptr, - empty, empty, empty, empty); + Ptr); CHECK (TimeSeriesAdaptor::OutputTracedCallback, - double, double, - empty, empty, empty); + double, double); CHECK (UanMac::PacketModeTracedCallback, - Ptr, UanTxMode, - empty, empty, empty); + Ptr, UanTxMode); CHECK (UanMacCw::QueueTracedCallback, - Ptr, uint16_t, - empty, empty, empty); + Ptr, uint16_t); CHECK (UanMacRc::QueueTracedCallback, - Ptr, uint32_t, - empty, empty, empty); + Ptr, uint32_t); CHECK (UanNetDevice::RxTxTracedCallback, - Ptr, Mac8Address, - empty, empty, empty); + Ptr, Mac8Address); CHECK (UanPhy::TracedCallback, - Ptr, double, UanTxMode, - empty, empty); + Ptr, double, UanTxMode); CHECK (UeManager::StateTracedCallback, uint64_t, uint16_t, uint16_t, UeManager::State, UeManager::State); CHECK (WifiMacHeader::TracedCallback, - const WifiMacHeader &, - empty, empty, empty, empty); + const WifiMacHeader &); CHECK (WifiPhyStateHelper::RxEndErrorTracedCallback, - Ptr, double, - empty, empty, empty); + Ptr, double); CHECK (WifiPhyStateHelper::RxOkTracedCallback, - Ptr, double, WifiMode, WifiPreamble, - empty); + Ptr, double, WifiMode, WifiPreamble); CHECK (WifiPhyStateHelper::StateTracedCallback, - Time, Time, WifiPhyState, - empty, empty); + Time, Time, WifiPhyState); CHECK (WifiPhyStateHelper::TxTracedCallback, - Ptr, WifiMode, WifiPreamble, uint8_t, - empty); + Ptr, WifiMode, WifiPreamble, uint8_t); CHECK (WifiRemoteStationManager::PowerChangeTracedCallback, - double, double, Mac48Address, - empty, empty); + double, double, Mac48Address); CHECK (WifiRemoteStationManager::RateChangeTracedCallback, - DataRate, DataRate, Mac48Address, - empty, empty); + DataRate, DataRate, Mac48Address); } +/** + * \ingroup system-tests-traced + * + * \brief TracedCallback typedef TestSuite + */ class TracedCallbackTypedefTestSuite : public TestSuite { public: @@ -684,4 +557,5 @@ TracedCallbackTypedefTestSuite::TracedCallbackTypedefTestSuite () AddTestCase (new TracedCallbackTypedefTestCase, TestCase::QUICK); } +/// Static variable for test initialization static TracedCallbackTypedefTestSuite tracedCallbackTypedefTestSuite; diff --git a/src/test/traced/traced-value-callback-typedef-test-suite.cc b/src/test/traced/traced-value-callback-typedef-test-suite.cc index f5af3628f..8e6754701 100644 --- a/src/test/traced/traced-value-callback-typedef-test-suite.cc +++ b/src/test/traced/traced-value-callback-typedef-test-suite.cc @@ -24,17 +24,30 @@ using namespace ns3; +/** + * \file + * \ingroup system-tests-traced + * + * TracedValueCallback tests to verify that they work with different types + * of classes - it tests bool, double, various types of integers types, + * Time, and SequenceNumber32. + */ + namespace { /** + * \ingroup system-tests-traced + * * \name Stringify the known TracedValue type names. - * - * \returns The \c TracedValueCallback type name. - * @{ + */ +/** + * Generic template for unknown classes. + * + * \returns The \c TracedValueCallback type name, or "unknown" for unknown classes. */ template inline std::string TypeName (void) { return "unknown"; } - +/** @{ */ template <> inline std::string TypeName (void) { return "Bool" ; } template <> inline std::string TypeName (void) { return "Int8_t" ; } template <> inline std::string TypeName (void) { return "Int16_t" ; } @@ -51,6 +64,8 @@ template <> inline std::string TypeName (void) { return "Sequ /** + * \ingroup system-tests-traced + * * Result of callback test. * * Since the sink function is outside the invoking class, @@ -63,6 +78,8 @@ std::string g_Result = ""; /** + * \ingroup system-tests-traced + * * Template for TracedValue sink functions. * * This generates a sink function for any underlying type. @@ -88,7 +105,11 @@ void TracedValueCbSink (T oldValue, T newValue) } // TracedValueCbSink<>() /** + * \ingroup system-tests-traced + * * TracedValueCbSink specialization for Time. + * \param oldValue The old value, + * \param newValue The new value. */ template <> void TracedValueCbSink