A Discrete-Event Network Simulator
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
25using 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 */
40namespace ns3
41{
42
43namespace tests
44{
45
46/**
47 * \ingroup examples-as-tests
48 * Run command line example as a test case
49 */
51{
52 public:
53 /**
54 * Default constructor
55 */
57
58 /**
59 * Destructor
60 */
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
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
84{
85}
86
87std::string
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 */
99{
100 public:
102};
103
105 : TestSuite("examples-as-tests-test-suite", Type::UNIT)
106{
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
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 */
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
132static ExampleAsTestSuite g_exampleCommandLineTest("core-example-simulator",
133 "sample-simulator",
134 NS_TEST_SOURCEDIR);
135
136} // namespace tests
137
138} // namespace ns3
Execute an example program as a test, by comparing the output to a reference file.
Execute an example program as a test suite.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
Run command line example as a test case.
std::string GetPostProcessingCommand() const override
Override this function to filter the version string from the command-line-example output.
Run examples as tests, checking stdout for regressions.
static ExamplesAsTestsTestSuite g_examplesAsTestsTestSuite
ExampleAsTestsTestSuite instance variable.
static ExampleAsTestSuite g_exampleCommandLineTest("core-example-simulator", "sample-simulator", NS_TEST_SOURCEDIR)
ExampleTestSuite instance variables.
Every class exported by the ns3 library is enclosed in the ns3 namespace.