43#if defined(NS3_ENABLE_EXAMPLES)
46 const std::string program,
47 const std::string dataDir,
48 const std::string
args )
57ExampleAsTestCase::~ExampleAsTestCase()
63ExampleAsTestCase::GetCommandTemplate()
const
66 std::string command(
"%s ");
72ExampleAsTestCase::GetPostProcessingCommand()
const
75 std::string command(
"");
80ExampleAsTestCase::DoRun()
84 SetDataDir(m_dataDir);
85 std::string refFile = CreateDataDirFilename(GetName() +
".reflog");
86 std::string testFile = CreateTempDirFilename(GetName() +
".reflog");
90 ss <<
"python3 ./ns3 run " << m_program <<
" --no-build --command-template=\""
91 << GetCommandTemplate()
98 <<
" " << GetPostProcessingCommand() <<
" > " << testFile;
100 int status = std::system(ss.str().c_str());
102 std::cout <<
"command: " << ss.str() <<
"\n"
103 <<
"status: " << status <<
"\n"
104 <<
"refFile: " << refFile <<
"\n"
105 <<
"testFile: " << testFile <<
"\n"
107 std::cout <<
"testFile contents:" << std::endl;
109 std::ifstream logF(testFile);
111 while (getline(logF, line))
113 std::cout << line <<
"\n";
121 const char* envVar = std::getenv(
"NS_COMMANDLINE_INTROSPECTION");
122 if (envVar !=
nullptr && std::strlen(envVar) != 0)
131ExampleAsTestSuite::ExampleAsTestSuite(
const std::string name,
132 const std::string program,
133 const std::string dataDir,
134 const std::string
args ,
135 const TestDuration duration )
136 : TestSuite(name, EXAMPLE)
139 AddTestCase(
new ExampleAsTestCase(name, program, dataDir,
args), duration);
#define NS_ASCII_TEST_EXPECT_EQ(gotFilename, expectedFilename)
Test that a pair of new/reference ascii files are equal.
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
ExampleAsTestCase(const std::string name, const std::string program, const std::string dataDir, const std::string args="")
Constructor.
Enable examples to be run as meaningful tests.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Every class exported by the ns3 library is enclosed in the ns3 namespace.