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
12#include <vector>
13
14using namespace ns3;
15
16/**
17 * \file
18 * \ingroup examples-as-tests
19 * Examples-as-tests test suite
20 */
21
22/**
23 * \ingroup core-tests
24 * \ingroup testing
25 * \defgroup examples-as-tests Examples as tests test suite
26 *
27 * Runs several examples as tests in order to test ExampleAsTestSuite and ExampleAsTestCase.
28 */
29namespace ns3
30{
31
32namespace tests
33{
34
35/**
36 * \ingroup examples-as-tests
37 * Run command line example as a test case
38 */
40{
41 public:
42 /**
43 * Default constructor
44 */
46
47 /**
48 * Destructor
49 */
51
52 /**
53 * Override this function to filter the version string from
54 * the command-line-example output.
55 * Since the version changes each time a commit is made it shouldn't
56 * be tested as part of the command-line-example output.
57 *
58 * \returns The string of post-processing commands.
59 */
60 std::string GetPostProcessingCommand() const override;
61};
62
64 : ExampleAsTestCase("core-example-command-line",
65 "command-line-example",
66 NS_TEST_SOURCEDIR,
67 "--intArg=2 --boolArg --strArg=deadbeef --anti=t "
68 "--cbArg=beefstew --charbuf=stewmeat 3 4 extraOne extraTwo")
69{
70}
71
75
76std::string
78{
79 // Delete the line that starts with Program Version:
80 return std::string(R"__(| sed -e "/^Program Version:.*$/d")__");
81}
82
83/**
84 * \ingroup examples-as-tests
85 * Run examples as tests, checking stdout for regressions.
86 */
88{
89 public:
91};
92
94 : TestSuite("examples-as-tests-test-suite", Type::UNIT)
95{
97 new ExampleAsTestCase("core-example-simulator", "sample-simulator", NS_TEST_SOURCEDIR));
98
99 AddTestCase(new ExampleAsTestCase("core-example-sample-random-variable",
100 "sample-random-variable",
101 NS_TEST_SOURCEDIR));
102
104}
105
106/**
107 * \ingroup examples-as-tests
108 * ExampleAsTestsTestSuite instance variable.
109 * Tests multiple examples in a single TestSuite using AddTestCase to add the examples to the suite.
110 */
112
113/**
114 * \ingroup examples-as-tests
115 * ExampleTestSuite instance variables.
116 *
117 * Tests ExampleTestSuite which runs a single example as test suite as specified in constructor
118 * arguments.
119 */
120
121static ExampleAsTestSuite g_exampleCommandLineTest("core-example-simulator",
122 "sample-simulator",
123 NS_TEST_SOURCEDIR);
124
125} // namespace tests
126
127} // 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:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
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.