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
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
18
*/
19
20
#include "ns3/example-as-test.h"
21
#include "ns3/system-path.h"
22
23
#include <vector>
24
25
using namespace
ns3
;
26
27
/**
28
* \file
29
* \ingroup examples-as-tests
30
* Examples-as-tests test suite
31
*/
32
33
/**
34
* \ingroup core-tests
35
* \ingroup testing
36
* \defgroup examples-as-tests Examples as tests test suite
37
*
38
* Runs several examples as tests in order to test ExampleAsTestSuite and ExampleAsTestCase.
39
*/
40
namespace
ns3
41
{
42
43
namespace
tests
44
{
45
46
/**
47
* \ingroup examples-as-tests
48
* Run command line example as a test case
49
*/
50
class
CommandLineExampleTestCase
:
public
ExampleAsTestCase
51
{
52
public
:
53
/**
54
* Default constructor
55
*/
56
CommandLineExampleTestCase
();
57
58
/**
59
* Destructor
60
*/
61
~CommandLineExampleTestCase
()
override
;
62
63
/**
64
* Override this function to filter the version string from
65
* the command-line-example output.
66
* Since the version changes each time a commit is made it shouldn't
67
* be tested as part of the command-line-example output.
68
*
69
* \returns The string of post-processing commands.
70
*/
71
std::string
GetPostProcessingCommand
()
const override
;
72
};
73
74
CommandLineExampleTestCase::CommandLineExampleTestCase
()
75
:
ExampleAsTestCase
(
"core-example-command-line"
,
76
"command-line-example"
,
77
NS_TEST_SOURCEDIR,
78
"--intArg=2 --boolArg --strArg=deadbeef --anti=t "
79
"--cbArg=beefstew --charbuf=stewmeat 3 4 extraOne extraTwo"
)
80
{
81
}
82
83
CommandLineExampleTestCase::~CommandLineExampleTestCase
()
84
{
85
}
86
87
std::string
88
CommandLineExampleTestCase::GetPostProcessingCommand
()
const
89
{
90
// Delete the line that starts with Program Version:
91
return
std::string(R
"__(| sed -e "/^Program Version:.*$/d")__");
92
}
93
94
/**
95
* \ingroup examples-as-tests
96
* Run examples as tests, checking stdout for regressions.
97
*/
98
class
ExamplesAsTestsTestSuite
:
public
TestSuite
99
{
100
public
:
101
ExamplesAsTestsTestSuite
();
102
};
103
104
ExamplesAsTestsTestSuite::ExamplesAsTestsTestSuite
()
105
:
TestSuite
(
"examples-as-tests-test-suite"
,
Type
::UNIT)
106
{
107
AddTestCase
(
108
new
ExampleAsTestCase
(
"core-example-simulator"
,
"sample-simulator"
, NS_TEST_SOURCEDIR));
109
110
AddTestCase
(
new
ExampleAsTestCase
(
"core-example-sample-random-variable"
,
111
"sample-random-variable"
,
112
NS_TEST_SOURCEDIR));
113
114
AddTestCase
(
new
CommandLineExampleTestCase
());
115
}
116
117
/**
118
* \ingroup examples-as-tests
119
* ExampleAsTestsTestSuite instance variable.
120
* Tests multiple examples in a single TestSuite using AddTestCase to add the examples to the suite.
121
*/
122
static
ExamplesAsTestsTestSuite
g_examplesAsTestsTestSuite
;
123
124
/**
125
* \ingroup examples-as-tests
126
* ExampleTestSuite instance variables.
127
*
128
* Tests ExampleTestSuite which runs a single example as test suite as specified in constructor
129
* arguments.
130
*/
131
132
static
ExampleAsTestSuite
g_exampleCommandLineTest
(
"core-example-simulator"
,
133
"sample-simulator"
,
134
NS_TEST_SOURCEDIR);
135
136
}
// namespace tests
137
138
}
// namespace ns3
ns3::ExampleAsTestCase
Execute an example program as a test, by comparing the output to a reference file.
Definition:
example-as-test.h:49
ns3::ExampleAsTestSuite
Execute an example program as a test suite.
Definition:
example-as-test.h:210
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:302
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1273
ns3::TestSuite::Type
Type
Type of test.
Definition:
test.h:1280
ns3::tests::CommandLineExampleTestCase
Run command line example as a test case.
Definition:
examples-as-tests-test-suite.cc:51
ns3::tests::CommandLineExampleTestCase::CommandLineExampleTestCase
CommandLineExampleTestCase()
Default constructor.
Definition:
examples-as-tests-test-suite.cc:74
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:88
ns3::tests::CommandLineExampleTestCase::~CommandLineExampleTestCase
~CommandLineExampleTestCase() override
Destructor.
Definition:
examples-as-tests-test-suite.cc:83
ns3::tests::ExamplesAsTestsTestSuite
Run examples as tests, checking stdout for regressions.
Definition:
examples-as-tests-test-suite.cc:99
ns3::tests::ExamplesAsTestsTestSuite::ExamplesAsTestsTestSuite
ExamplesAsTestsTestSuite()
Definition:
examples-as-tests-test-suite.cc:104
ns3::tests::g_examplesAsTestsTestSuite
static ExamplesAsTestsTestSuite g_examplesAsTestsTestSuite
ExampleAsTestsTestSuite instance variable.
Definition:
examples-as-tests-test-suite.cc:122
ns3::tests::g_exampleCommandLineTest
static ExampleAsTestSuite g_exampleCommandLineTest("core-example-simulator", "sample-simulator", NS_TEST_SOURCEDIR)
ExampleTestSuite instance variables.
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 Tue May 28 2024 23:34:45 for ns-3 by
1.9.6