A Discrete-Event Network Simulator
API
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
35{
36 public:
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
49 ~MpiTestCase() override
50 {
51 }
52
59 std::string GetCommandTemplate() const override;
60
67 std::string GetPostProcessingCommand() const override;
68
69 private:
72};
73
74MpiTestCase::MpiTestCase(const std::string name,
75 const std::string program,
76 const std::string dataDir,
77 const int ranks,
78 const std::string args /* = "" */)
79 : ExampleAsTestCase(name, program, dataDir, args),
80 m_ranks(ranks)
81{
82}
83
84std::string
86{
87 std::stringstream ss;
88 ss << "mpiexec -n " << m_ranks << " %s --test " << m_args;
89 return ss.str();
90}
91
92std::string
94{
95 std::string command("| grep TEST | sort ");
96 return command;
97}
98
104{
105 public:
112 MpiTestSuite(const std::string name,
113 const std::string program,
114 const std::string dataDir,
115 const int ranks,
116 const std::string args = "",
117 const TestDuration duration = QUICK)
118 : TestSuite(name, EXAMPLE)
119 {
120 AddTestCase(new MpiTestCase(name, program, dataDir, ranks, args), duration);
121 }
122
123}; // class MpiTestSuite
124
125/* Tests using SimpleDistributedSimulatorImpl */
126static MpiTestSuite g_mpiNms2("mpi-example-nms-2", "nms-p2p-nix-distributed", NS_TEST_SOURCEDIR, 2);
127static MpiTestSuite g_mpiComm2("mpi-example-comm-2",
128 "simple-distributed-mpi-comm",
129 NS_TEST_SOURCEDIR,
130 2);
131static MpiTestSuite g_mpiComm2comm("mpi-example-comm-2-init",
132 "simple-distributed-mpi-comm",
133 NS_TEST_SOURCEDIR,
134 2,
135 "--init");
136static MpiTestSuite g_mpiComm3comm("mpi-example-comm-3-init",
137 "simple-distributed-mpi-comm",
138 NS_TEST_SOURCEDIR,
139 3,
140 "--init");
141static MpiTestSuite g_mpiEmpty2("mpi-example-empty-2",
142 "simple-distributed-empty-node",
143 NS_TEST_SOURCEDIR,
144 2);
145static MpiTestSuite g_mpiEmpty3("mpi-example-empty-3",
146 "simple-distributed-empty-node",
147 NS_TEST_SOURCEDIR,
148 3);
149static MpiTestSuite g_mpiSimple2("mpi-example-simple-2",
150 "simple-distributed",
151 NS_TEST_SOURCEDIR,
152 2);
153static MpiTestSuite g_mpiThird2("mpi-example-third-2", "third-distributed", NS_TEST_SOURCEDIR, 2);
154
155/* Tests using NullMessageSimulatorImpl */
156static MpiTestSuite g_mpiSimple2NullMsg("mpi-example-simple-2-nullmsg",
157 "simple-distributed",
158 NS_TEST_SOURCEDIR,
159 2,
160 "--nullmsg");
161static MpiTestSuite g_mpiEmpty2NullMsg("mpi-example-empty-2-nullmsg",
162 "simple-distributed-empty-node",
163 NS_TEST_SOURCEDIR,
164 2,
165 "-nullmsg");
166static MpiTestSuite g_mpiEmpty3NullMsg("mpi-example-empty-3-nullmsg",
167 "simple-distributed-empty-node",
168 NS_TEST_SOURCEDIR,
169 3,
170 "-nullmsg");
This version of ns3::ExampleTestCase is specialized for MPI by accepting the number of ranks as a par...
MpiTestCase(const std::string name, const std::string program, const std::string dataDir, const int ranks, const std::string args="")
Constructor.
std::string GetCommandTemplate() const override
Produce the --command-template argument which will invoke mpiexec with the requested number of ranks.
~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 TestDuration duration=QUICK)
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.
TestDuration
How long the test takes to execute.
Definition: test.h:1064
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
@ EXAMPLE
This test suite implements an Example Test.
Definition: test.h:1267
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.