36 const std::string program,
37 const std::string dataDir,
38 const std::string args ,
39 const bool shouldNotErr )
44 m_shouldNotErr(shouldNotErr)
58 std::string command(
"%s ");
67 std::string command(
"");
86 post +=
" | sed '1,/" + std::string(
NS_FATAL_MSG) +
"/!d' ";
91 ss <<
"python3 ./ns3 run " <<
m_program <<
" --no-build --command-template=\""
97 ss <<
" > " << testFile <<
" 2>&1";
101 ss <<
" 2>&1 " << post <<
" > " << testFile;
104 int status = std::system(ss.str().c_str());
108 <<
" command: " << ss.str() <<
"\n"
109 <<
" status: " << status <<
"\n"
110 <<
" refFile: " << refFile <<
"\n"
111 <<
" testFile: " << testFile <<
"\n"
112 <<
" testFile contents:" << std::endl;
114 std::ifstream logF(testFile);
116 while (getline(logF, line))
118 std::cout <<
"--- " << line <<
"\n";
141 const std::string program,
142 const std::string dataDir,
143 const std::string args ,
145 const bool shouldNotErr )
148 NS_LOG_FUNCTION(
this << name << program << dataDir << args << duration << shouldNotErr);
#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.
static KeyFoundType Get(const std::string &envvar, const std::string &key="", const std::string &delim=";")
Get the value corresponding to a key from an environment variable.
Execute an example program as a test, by comparing the output to a reference file.
virtual std::string GetCommandTemplate() const
Customization point for more complicated patterns to invoke the example program.
bool m_shouldNotErr
Whether error return status is a test failure.
virtual std::string GetPostProcessingCommand() const
Customization point for tests requiring post-processing of stdout.
void DoRun() override
Implementation to actually run this TestCase.
ExampleAsTestCase(const std::string name, const std::string program, const std::string dataDir, const std::string args="", const bool shouldNotErr=true)
Constructor.
std::string m_args
Any additional arguments to the program.
std::string m_dataDir
The source directory for the test.
std::string m_program
The program to run.
~ExampleAsTestCase() override
Destructor.
ExampleAsTestSuite(const std::string name, const std::string program, const std::string dataDir, const std::string args="", const Duration duration=Duration::QUICK, const bool shouldNotErr=true)
Constructor.
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Duration
How long the test takes to execute.
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
std::string GetName() const
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.