45 #if defined(NS3_ENABLE_EXAMPLES)
48 const std::string program,
49 const std::string dataDir,
50 const std::string
args ,
51 const bool shouldNotErr )
56 m_shouldNotErr(shouldNotErr)
61 ExampleAsTestCase::~ExampleAsTestCase()
67 ExampleAsTestCase::GetCommandTemplate()
const
70 std::string command(
"%s ");
76 ExampleAsTestCase::GetPostProcessingCommand()
const
79 std::string command(
"");
84 ExampleAsTestCase::DoRun()
88 SetDataDir(m_dataDir);
89 std::string refFile = CreateDataDirFilename(GetName() +
".reflog");
90 std::string testFile = CreateTempDirFilename(GetName() +
".reflog");
91 std::string post = GetPostProcessingCommand();
98 post +=
" | sed '1,/" + std::string(
NS_FATAL_MSG) +
"/!d' ";
101 std::stringstream ss;
103 ss <<
"python3 ./ns3 run " << m_program <<
" --no-build --command-template=\""
104 << GetCommandTemplate() <<
"\"";
109 ss <<
" > " << testFile <<
" 2>&1";
113 ss <<
" 2>&1 " << post <<
" > " << testFile;
116 int status = std::system(ss.str().c_str());
119 << GetName() <<
":\n"
120 <<
" command: " << ss.str() <<
"\n"
121 <<
" status: " << status <<
"\n"
122 <<
" refFile: " << refFile <<
"\n"
123 <<
" testFile: " << testFile <<
"\n"
124 <<
" testFile contents:" << std::endl;
126 std::ifstream logF(testFile);
128 while (getline(logF, line))
130 std::cout <<
"--- " << line <<
"\n";
142 auto [found, intro] = EnvironmentVariable::Get(
"NS_COMMANDLINE_INTROSPECTION");
152 ExampleAsTestSuite::ExampleAsTestSuite(
const std::string name,
153 const std::string program,
154 const std::string dataDir,
155 const std::string
args ,
156 const TestDuration duration ,
157 const bool shouldNotErr )
158 : TestSuite(name, EXAMPLE)
161 AddTestCase(
new ExampleAsTestCase(name, program, dataDir,
args, shouldNotErr), 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="", const bool shouldNotErr=true)
Constructor.
Class Environment declaration.
Enable examples to be run as meaningful tests.
NS_FATAL_x macro definitions.
constexpr std::string_view NS_FATAL_MSG
Output string marking imminent invocation of std::terminate.
#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.