A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mpi-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 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
22#include <sstream>
23
24using namespace ns3;
25
26/**
27 * \ingroup mpi-tests
28 *
29 * This version of ns3::ExampleTestCase is specialized for MPI
30 * by accepting the number of ranks as a parameter,
31 * then building a `--command-template` string which
32 * invokes `mpiexec` correctly to execute MPI examples.
33 */
35{
36 public:
37 /**
38 * \copydoc ns3::ExampleAsTestCase::ExampleAsTestCase
39 *
40 * \param [in] ranks The number of ranks to use
41 */
42 MpiTestCase(const std::string name,
43 const std::string program,
44 const std::string dataDir,
45 const int ranks,
46 const std::string args = "",
47 const bool shouldNotErr = true);
48
49 /** Destructor */
50 ~MpiTestCase() override
51 {
52 }
53
54 /**
55 * Produce the `--command-template` argument which will invoke
56 * `mpiexec` with the requested number of ranks.
57 *
58 * \returns The `--command-template` string.
59 */
60 std::string GetCommandTemplate() const override;
61
62 /**
63 * Sort the output from parallel execution.
64 * stdout from multiple ranks is not ordered.
65 *
66 * \returns Sort command
67 */
68 std::string GetPostProcessingCommand() const override;
69
70 private:
71 /** The number of ranks. */
73};
74
75MpiTestCase::MpiTestCase(const std::string name,
76 const std::string program,
77 const std::string dataDir,
78 const int ranks,
79 const std::string args /* = "" */,
80 const bool shouldNotErr /* = true */)
81 : ExampleAsTestCase(name, program, dataDir, args, shouldNotErr),
82 m_ranks(ranks)
83{
84}
85
86std::string
88{
89 std::stringstream ss;
90 ss << "mpiexec -n " << m_ranks << " %s --test " << m_args;
91 return ss.str();
92}
93
94std::string
96{
97 std::string command("| grep TEST | sort ");
98 return command;
99}
100
101/**
102 * \ingroup mpi-tests
103 * MPI specialization of ns3::ExampleTestSuite.
104 */
106{
107 public:
108 /**
109 * \copydoc MpiTestCase::MpiTestCase
110 *
111 * \param [in] duration Amount of time this test takes to execute
112 * (defaults to QUICK).
113 */
114 MpiTestSuite(const std::string name,
115 const std::string program,
116 const std::string dataDir,
117 const int ranks,
118 const std::string args = "",
119 const Duration duration = Duration::QUICK,
120 const bool shouldNotErr = true)
121 : TestSuite(name, Type::EXAMPLE)
122 {
123 AddTestCase(new MpiTestCase(name, program, dataDir, ranks, args, shouldNotErr), duration);
124 }
125
126}; // class MpiTestSuite
127
128/* Tests using SimpleDistributedSimulatorImpl */
129static MpiTestSuite g_mpiNms2("mpi-example-nms-2", "nms-p2p-nix-distributed", NS_TEST_SOURCEDIR, 2);
130static MpiTestSuite g_mpiComm2("mpi-example-comm-2",
131 "simple-distributed-mpi-comm",
132 NS_TEST_SOURCEDIR,
133 2);
134static MpiTestSuite g_mpiComm2comm("mpi-example-comm-2-init",
135 "simple-distributed-mpi-comm",
136 NS_TEST_SOURCEDIR,
137 2,
138 "--init");
139static MpiTestSuite g_mpiComm3comm("mpi-example-comm-3-init",
140 "simple-distributed-mpi-comm",
141 NS_TEST_SOURCEDIR,
142 3,
143 "--init");
144static MpiTestSuite g_mpiEmpty2("mpi-example-empty-2",
145 "simple-distributed-empty-node",
146 NS_TEST_SOURCEDIR,
147 2);
148static MpiTestSuite g_mpiEmpty3("mpi-example-empty-3",
149 "simple-distributed-empty-node",
150 NS_TEST_SOURCEDIR,
151 3);
152static MpiTestSuite g_mpiSimple2("mpi-example-simple-2",
153 "simple-distributed",
154 NS_TEST_SOURCEDIR,
155 2);
156static MpiTestSuite g_mpiThird2("mpi-example-third-2", "third-distributed", NS_TEST_SOURCEDIR, 2);
157
158/* Tests using NullMessageSimulatorImpl */
159static MpiTestSuite g_mpiSimple2NullMsg("mpi-example-simple-2-nullmsg",
160 "simple-distributed",
161 NS_TEST_SOURCEDIR,
162 2,
163 "--nullmsg");
164static MpiTestSuite g_mpiEmpty2NullMsg("mpi-example-empty-2-nullmsg",
165 "simple-distributed-empty-node",
166 NS_TEST_SOURCEDIR,
167 2,
168 "-nullmsg");
169static MpiTestSuite g_mpiEmpty3NullMsg("mpi-example-empty-3-nullmsg",
170 "simple-distributed-empty-node",
171 NS_TEST_SOURCEDIR,
172 3,
173 "-nullmsg");
This version of ns3::ExampleTestCase is specialized for MPI by accepting the number of ranks as a par...
std::string GetCommandTemplate() const override
Produce the --command-template argument which will invoke mpiexec with the requested number of ranks.
MpiTestCase(const std::string name, const std::string program, const std::string dataDir, const int ranks, const std::string args="", const bool shouldNotErr=true)
Constructor.
~MpiTestCase() override
Destructor.
std::string GetPostProcessingCommand() const override
Sort the output from parallel execution.
int m_ranks
The number of ranks.
MPI specialization of ns3::ExampleTestSuite.
MpiTestSuite(const std::string name, const std::string program, const std::string dataDir, const int ranks, const std::string args="", const Duration duration=Duration::QUICK, const bool shouldNotErr=true)
Constructor.
Execute an example program as a test, by comparing the output to a reference file.
std::string m_args
Any additional arguments to the program.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
Duration
How long the test takes to execute.
Definition: test.h:1065
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto EXAMPLE
Definition: test.h:1290
static MpiTestSuite g_mpiSimple2("mpi-example-simple-2", "simple-distributed", NS_TEST_SOURCEDIR, 2)
static MpiTestSuite g_mpiNms2("mpi-example-nms-2", "nms-p2p-nix-distributed", NS_TEST_SOURCEDIR, 2)
static MpiTestSuite g_mpiComm2("mpi-example-comm-2", "simple-distributed-mpi-comm", NS_TEST_SOURCEDIR, 2)
static MpiTestSuite g_mpiEmpty2NullMsg("mpi-example-empty-2-nullmsg", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 2, "-nullmsg")
static MpiTestSuite g_mpiEmpty3NullMsg("mpi-example-empty-3-nullmsg", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 3, "-nullmsg")
static MpiTestSuite g_mpiComm3comm("mpi-example-comm-3-init", "simple-distributed-mpi-comm", NS_TEST_SOURCEDIR, 3, "--init")
static MpiTestSuite g_mpiComm2comm("mpi-example-comm-2-init", "simple-distributed-mpi-comm", NS_TEST_SOURCEDIR, 2, "--init")
static MpiTestSuite g_mpiEmpty3("mpi-example-empty-3", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 3)
static MpiTestSuite g_mpiEmpty2("mpi-example-empty-2", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 2)
static MpiTestSuite g_mpiSimple2NullMsg("mpi-example-simple-2-nullmsg", "simple-distributed", NS_TEST_SOURCEDIR, 2, "--nullmsg")
static MpiTestSuite g_mpiThird2("mpi-example-third-2", "third-distributed", NS_TEST_SOURCEDIR, 2)
Every class exported by the ns3 library is enclosed in the ns3 namespace.