A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
examples-as-tests-test-suite.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Lawrence Livermore National Laboratory
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
7
*/
8
9
#include "ns3/example-as-test.h"
10
#include "ns3/system-path.h"
11
12
using namespace
ns3
;
13
14
/**
15
* @file
16
* @ingroup examples-as-tests
17
* Examples-as-tests test suite
18
*/
19
20
/**
21
* @ingroup core-tests
22
* @ingroup testing
23
* @defgroup examples-as-tests Examples as tests test suite
24
*
25
* Runs several examples as tests in order to test ExampleAsTestSuite and ExampleAsTestCase.
26
*/
27
namespace
ns3
28
{
29
30
namespace
tests
31
{
32
33
/**
34
* @ingroup examples-as-tests
35
* Run command line example as a test case
36
*/
37
class
CommandLineExampleTestCase
:
public
ExampleAsTestCase
38
{
39
public
:
40
/**
41
* Default constructor
42
*/
43
CommandLineExampleTestCase
();
44
45
/**
46
* Destructor
47
*/
48
~CommandLineExampleTestCase
()
override
;
49
50
/**
51
* Override this function to filter the version string from
52
* the command-line-example output.
53
* Since the version changes each time a commit is made it shouldn't
54
* be tested as part of the command-line-example output.
55
*
56
* @returns The string of post-processing commands.
57
*/
58
std::string
GetPostProcessingCommand
()
const override
;
59
};
60
61
CommandLineExampleTestCase::CommandLineExampleTestCase
()
62
:
ExampleAsTestCase
(
"core-example-command-line"
,
63
"command-line-example"
,
64
NS_TEST_SOURCEDIR,
65
"--intArg=2 --boolArg --strArg=deadbeef --anti=t "
66
"--cbArg=beefstew --charbuf=stewmeat 3 4 extraOne extraTwo"
)
67
{
68
}
69
70
CommandLineExampleTestCase::~CommandLineExampleTestCase
()
71
{
72
}
73
74
std::string
75
CommandLineExampleTestCase::GetPostProcessingCommand
()
const
76
{
77
// Delete the line that starts with Program Version:
78
return
std::string(R
"__(| sed -e "/^Program Version:.*$/d")__");
79
}
80
81
/**
82
* @ingroup examples-as-tests
83
* Run examples as tests, checking stdout for regressions.
84
*/
85
class
ExamplesAsTestsTestSuite
:
public
TestSuite
86
{
87
public
:
88
ExamplesAsTestsTestSuite
();
89
};
90
91
ExamplesAsTestsTestSuite::ExamplesAsTestsTestSuite
()
92
:
TestSuite
(
"examples-as-tests-test-suite"
,
Type
::UNIT)
93
{
94
AddTestCase
(
95
new
ExampleAsTestCase
(
"core-example-simulator"
,
"sample-simulator"
, NS_TEST_SOURCEDIR));
96
97
AddTestCase
(
new
ExampleAsTestCase
(
"core-example-sample-random-variable"
,
98
"sample-random-variable"
,
99
NS_TEST_SOURCEDIR));
100
101
AddTestCase
(
new
CommandLineExampleTestCase
());
102
}
103
104
/**
105
* @ingroup examples-as-tests
106
* ExampleAsTestsTestSuite instance variable.
107
* Tests multiple examples in a single TestSuite using AddTestCase to add the examples to the suite.
108
*/
109
static
ExamplesAsTestsTestSuite
g_examplesAsTestsTestSuite
;
110
111
/**
112
* @ingroup examples-as-tests
113
* ExampleTestSuite instance variables.
114
*
115
* Tests ExampleTestSuite which runs a single example as test suite as specified in constructor
116
* arguments.
117
*/
118
119
static
ExampleAsTestSuite
g_exampleCommandLineTest
(
"core-example-simulator"
,
120
"sample-simulator"
,
121
NS_TEST_SOURCEDIR);
122
123
}
// namespace tests
124
125
}
// namespace ns3
ns3::ExampleAsTestCase
Execute an example program as a test, by comparing the output to a reference file.
Definition
example-as-test.h:38
ns3::ExampleAsTestCase::ExampleAsTestCase
ExampleAsTestCase(const std::string name, const std::string program, const std::string dataDir, const std::string args="", const bool shouldNotErr=true)
Constructor.
Definition
example-as-test.cc:33
ns3::ExampleAsTestSuite
Execute an example program as a test suite.
Definition
example-as-test.h:200
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:296
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1271
ns3::TestSuite::TestSuite
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition
test.cc:494
ns3::tests::CommandLineExampleTestCase
Run command line example as a test case.
Definition
examples-as-tests-test-suite.cc:38
ns3::tests::CommandLineExampleTestCase::CommandLineExampleTestCase
CommandLineExampleTestCase()
Default constructor.
Definition
examples-as-tests-test-suite.cc:61
ns3::tests::CommandLineExampleTestCase::GetPostProcessingCommand
std::string GetPostProcessingCommand() const override
Override this function to filter the version string from the command-line-example output.
Definition
examples-as-tests-test-suite.cc:75
ns3::tests::CommandLineExampleTestCase::~CommandLineExampleTestCase
~CommandLineExampleTestCase() override
Destructor.
Definition
examples-as-tests-test-suite.cc:70
ns3::tests::ExamplesAsTestsTestSuite
Run examples as tests, checking stdout for regressions.
Definition
examples-as-tests-test-suite.cc:86
ns3::tests::ExamplesAsTestsTestSuite::ExamplesAsTestsTestSuite
ExamplesAsTestsTestSuite()
Definition
examples-as-tests-test-suite.cc:91
ns3::tests::g_examplesAsTestsTestSuite
static ExamplesAsTestsTestSuite g_examplesAsTestsTestSuite
ExampleAsTestsTestSuite instance variable.
Definition
examples-as-tests-test-suite.cc:109
ns3::tests::g_exampleCommandLineTest
static ExampleAsTestSuite g_exampleCommandLineTest("core-example-simulator", "sample-simulator", NS_TEST_SOURCEDIR)
ExampleTestSuite instance variables.
ns3::tests
Namespace for test files, TestCases and TestSuites.
Definition
environment-variable.h:32
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
core
test
examples-as-tests-test-suite.cc
Generated on
for ns-3 by
1.15.0