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 * 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
12using 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 */
27namespace ns3
28{
29
30namespace tests
31{
32
33/**
34 * @ingroup examples-as-tests
35 * Run command line example as a test case
36 */
38{
39 public:
40 /**
41 * Default constructor
42 */
44
45 /**
46 * Destructor
47 */
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
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
73
74std::string
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 */
86{
87 public:
89};
90
92 : TestSuite("examples-as-tests-test-suite", Type::UNIT)
93{
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
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 */
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
119static ExampleAsTestSuite g_exampleCommandLineTest("core-example-simulator",
120 "sample-simulator",
121 NS_TEST_SOURCEDIR);
122
123} // namespace tests
124
125} // namespace ns3
Execute an example program as a test, by comparing the output to a reference file.
ExampleAsTestCase(const std::string name, const std::string program, const std::string dataDir, const std::string args="", const bool shouldNotErr=true)
Constructor.
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:296
Type
Type of test.
Definition test.h:1271
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
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.
Namespace for test files, TestCases and TestSuites.
Every class exported by the ns3 library is enclosed in the ns3 namespace.