mtp: Add example testing

This commit is contained in:
F5
2023-11-21 21:07:00 +08:00
parent b551804f91
commit 2f30ba37c4
8 changed files with 233 additions and 47 deletions

View File

@@ -1,3 +1,10 @@
set(example_as_test_suite)
if(${ENABLE_EXAMPLES})
set(example_as_test_suite
test/mtp-test-suite.cc
)
endif()
build_lib( build_lib(
LIBNAME mtp LIBNAME mtp
SOURCE_FILES SOURCE_FILES
@@ -10,6 +17,5 @@ build_lib(
model/multithreaded-simulator-impl.h model/multithreaded-simulator-impl.h
LIBRARIES_TO_LINK ${libcore} LIBRARIES_TO_LINK ${libcore}
${libnetwork} ${libnetwork}
TEST_SOURCES TEST_SOURCES ${example_as_test_suite}
test/mtp-test-suite.cc
) )

View File

@@ -0,0 +1,53 @@
- Setup the topology...
- Calculating routes...
Host NodeId System Address
0 20 0 10.0.0.1
1 21 0 10.0.0.3
2 22 0 10.0.1.1
3 23 0 10.0.1.3
4 24 0 10.1.0.1
5 25 0 10.1.0.3
6 26 0 10.1.1.1
7 27 0 10.1.1.3
8 28 0 10.2.0.1
9 29 0 10.2.0.3
10 30 0 10.2.1.1
11 31 0 10.2.1.3
12 32 0 10.3.0.1
13 33 0 10.3.0.3
14 34 0 10.3.1.1
15 35 0 10.3.1.3
- Generating traffic...
Expected data rate = 0.48Gbps
Generated data rate = 0.433455Gbps
Expected avg flow size = 1.71125MB
Generated avg flow size = 1.56604MB
Total flow count = 36
- Start simulation...
Progressed to 0.1s
Progressed to 0.2s
Progressed to 0.3s
Progressed to 0.4s
Progressed to 0.5s
Progressed to 0.6s
Progressed to 0.7s
Progressed to 0.8s
Progressed to 0.9s
Detected #flow = 70
Finished #flow = 66
Average FCT (all) = 208267us
Average FCT (finished) = 209978us
Average end to end delay = 23173us
Average flow throughput = 0.00944586Gbps
Network throughput = 0.0958292Gbps
Total Tx packets = 12007
Total Rx packets = 11904
Dropped packets = 0
- Done!
Event count = 172947

View File

@@ -0,0 +1,53 @@
- Setup the topology...
- Calculating routes...
Host NodeId System Address
0 20 0 10.0.0.1
1 21 0 10.0.0.3
2 22 0 10.0.1.1
3 23 0 10.0.1.3
4 24 0 10.1.0.1
5 25 0 10.1.0.3
6 26 0 10.1.1.1
7 27 0 10.1.1.3
8 28 0 10.2.0.1
9 29 0 10.2.0.3
10 30 0 10.2.1.1
11 31 0 10.2.1.3
12 32 0 10.3.0.1
13 33 0 10.3.0.3
14 34 0 10.3.1.1
15 35 0 10.3.1.3
- Generating traffic...
Expected data rate = 0.48Gbps
Generated data rate = 0.433455Gbps
Expected avg flow size = 1.71125MB
Generated avg flow size = 1.56604MB
Total flow count = 36
- Start simulation...
Progressed to 0.1s
Progressed to 0.2s
Progressed to 0.3s
Progressed to 0.4s
Progressed to 0.5s
Progressed to 0.6s
Progressed to 0.7s
Progressed to 0.8s
Progressed to 0.9s
Detected #flow = 70
Finished #flow = 65
Average FCT (all) = 92536.3us
Average FCT (finished) = 77992.9us
Average end to end delay = 66398.2us
Average flow throughput = 0.0312583Gbps
Network throughput = 0.246348Gbps
Total Tx packets = 29014
Total Rx packets = 25782
Dropped packets = 0
- Done!
Event count = 355408

View File

@@ -1,68 +1,142 @@
// TODO: Add multithreaded tests #include "ns3/example-as-test.h"
// Include a header file from your module to test.
#include "ns3/mtp-module.h" #include "ns3/mtp-module.h"
// An essential include is test.h
#include "ns3/test.h" #include "ns3/test.h"
// Do not put your test classes in namespace ns3. You may find it useful #include <sstream>
// to use the using directive to access the ns3 namespace directly
using namespace ns3; using namespace ns3;
// This is an example TestCase. class MtpTestCase : public ExampleAsTestCase
class MtpTestCase1 : public TestCase
{ {
public: public:
MtpTestCase1 (); /**
virtual ~MtpTestCase1 (); * \copydoc ns3::ExampleAsTestCase::ExampleAsTestCase
*
* \param [in] postCmd The post processing command
*/
MtpTestCase(const std::string name,
const std::string program,
const std::string dataDir,
const std::string args = "",
const std::string postCmd = "",
const bool shouldNotErr = true);
/** Destructor */
~MtpTestCase() override
{
}
/**
* Produce the `--command-template` argument
*
* \returns The `--command-template` string.
*/
std::string GetCommandTemplate() const override;
/**
* Remove time statistics
*
* \returns The post processing command
*/
std::string GetPostProcessingCommand() const override;
private: private:
virtual void DoRun (void); /** The post processing command. */
std::string m_postCmd;
}; };
// Add some help text to this case to describe what it is intended to test MtpTestCase::MtpTestCase(const std::string name,
MtpTestCase1::MtpTestCase1 () const std::string program,
: TestCase ("Mtp test case (does nothing)") const std::string dataDir,
const std::string args /* = "" */,
const std::string postCmd /* = "" */,
const bool shouldNotErr /* = true */)
: ExampleAsTestCase(name, program, dataDir, args, shouldNotErr),
m_postCmd(postCmd)
{ {
} }
// This destructor does nothing but we include it as a reminder that std::string
// the test case should clean up after itself MtpTestCase::GetCommandTemplate() const
MtpTestCase1::~MtpTestCase1 ()
{ {
std::stringstream ss;
ss << "%s " << m_args;
return ss.str();
} }
// std::string
// This method is the pure virtual method from class TestCase that every MtpTestCase::GetPostProcessingCommand() const
// TestCase must implement
//
void
MtpTestCase1::DoRun (void)
{ {
// A wide variety of test macros are available in src/core/test.h std::string command(m_postCmd);
NS_TEST_ASSERT_MSG_EQ (true, true, "true doesn't equal true for some reason"); return command;
// Use this one for floating point comparisons
NS_TEST_ASSERT_MSG_EQ_TOL (0.01, 0.01, 0.001, "Numbers are not equal within tolerance");
} }
// The TestSuite class names the TestSuite, identifies what type of TestSuite,
// and enables the TestCases to be run. Typically, only the constructor for
// this class must be defined
//
class MtpTestSuite : public TestSuite class MtpTestSuite : public TestSuite
{ {
public: public:
MtpTestSuite (); /**
}; * \copydoc MpiTestCase::MpiTestCase
*
MtpTestSuite::MtpTestSuite () * \param [in] duration Amount of time this test takes to execute
: TestSuite ("mtp", UNIT) * (defaults to QUICK).
*/
MtpTestSuite(const std::string name,
const std::string program,
const std::string dataDir,
const std::string args = "",
const std::string postCmd = "",
const TestDuration duration = QUICK,
const bool shouldNotErr = true)
: TestSuite(name, EXAMPLE)
{ {
// TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER AddTestCase(new MtpTestCase(name, program, dataDir, args, postCmd, shouldNotErr), duration);
AddTestCase (new MtpTestCase1, TestCase::QUICK);
} }
// Do not forget to allocate an instance of this TestSuite }; // class MtpTestSuite
static MtpTestSuite smtpTestSuite;
static MtpTestSuite g_mtpFatTree1("mtp-fat-tree",
"fat-tree-mtp",
NS_TEST_SOURCEDIR,
"--bandwidth=100Mbps --thread=4 --flowmon=true",
"| grep -v 'Simulation time'",
TestCase::TestDuration::QUICK);
static MtpTestSuite g_mtpFatTree2("mtp-fat-tree-incast",
"fat-tree-mtp",
NS_TEST_SOURCEDIR,
"--bandwidth=100Mbps --incast=1 --thread=4 --flowmon=true",
"| grep -v 'Simulation time'",
TestCase::TestDuration::QUICK);
static MtpTestSuite g_mtpTcpValidation1("mtp-tcp-validation-dctcp-10ms",
"tcp-validation-mtp",
NS_TEST_SOURCEDIR,
"--firstTcpType=dctcp --linkRate=50Mbps --baseRtt=10ms "
"--queueUseEcn=1 --stopTime=15s --validate=dctcp-10ms",
"",
TestCase::TestDuration::QUICK);
static MtpTestSuite g_mtpTcpValidation2("mtp-tcp-validation-dctcp-80ms",
"tcp-validation-mtp",
NS_TEST_SOURCEDIR,
"--firstTcpType=dctcp --linkRate=50Mbps --baseRtt=80ms "
"--queueUseEcn=1 --stopTime=40s --validate=dctcp-80ms",
"",
TestCase::TestDuration::QUICK);
static MtpTestSuite g_mtpTcpValidation3(
"mtp-tcp-validation-cubic-50ms-no-ecn",
"tcp-validation-mtp",
NS_TEST_SOURCEDIR,
"--firstTcpType=cubic --linkRate=50Mbps --baseRtt=50ms --queueUseEcn=0 --stopTime=20s "
"--validate=cubic-50ms-no-ecn",
"",
TestCase::TestDuration::QUICK);
static MtpTestSuite g_mtpTcpValidation4("mtp-tcp-validation-cubic-50ms-ecn",
"tcp-validation-mtp",
NS_TEST_SOURCEDIR,
"--firstTcpType=cubic --linkRate=50Mbps --baseRtt=50ms "
"--queueUseEcn=1 --stopTime=20s --validate=cubic-50ms-ecn",
"",
TestCase::TestDuration::QUICK);