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 
24 using 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  const bool shouldNotErr = true);
48 
50  ~MpiTestCase() override
51  {
52  }
53 
60  std::string GetCommandTemplate() const override;
61 
68  std::string GetPostProcessingCommand() const override;
69 
70  private:
72  int m_ranks;
73 };
74 
75 MpiTestCase::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 
86 std::string
88 {
89  std::stringstream ss;
90  ss << "mpiexec -n " << m_ranks << " %s --test " << m_args;
91  return ss.str();
92 }
93 
94 std::string
96 {
97  std::string command("| grep TEST | sort ");
98  return command;
99 }
100 
105 class MpiTestSuite : public TestSuite
106 {
107  public:
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 TestDuration duration = QUICK,
120  const bool shouldNotErr = true)
121  : TestSuite(name, EXAMPLE)
122  {
123  AddTestCase(new MpiTestCase(name, program, dataDir, ranks, args, shouldNotErr), duration);
124  }
125 
126 }; // class MpiTestSuite
127 
128 /* Tests using SimpleDistributedSimulatorImpl */
129 static MpiTestSuite g_mpiNms2("mpi-example-nms-2", "nms-p2p-nix-distributed", NS_TEST_SOURCEDIR, 2);
130 static MpiTestSuite g_mpiComm2("mpi-example-comm-2",
131  "simple-distributed-mpi-comm",
132  NS_TEST_SOURCEDIR,
133  2);
134 static MpiTestSuite g_mpiComm2comm("mpi-example-comm-2-init",
135  "simple-distributed-mpi-comm",
136  NS_TEST_SOURCEDIR,
137  2,
138  "--init");
139 static MpiTestSuite g_mpiComm3comm("mpi-example-comm-3-init",
140  "simple-distributed-mpi-comm",
141  NS_TEST_SOURCEDIR,
142  3,
143  "--init");
144 static MpiTestSuite g_mpiEmpty2("mpi-example-empty-2",
145  "simple-distributed-empty-node",
146  NS_TEST_SOURCEDIR,
147  2);
148 static MpiTestSuite g_mpiEmpty3("mpi-example-empty-3",
149  "simple-distributed-empty-node",
150  NS_TEST_SOURCEDIR,
151  3);
152 static MpiTestSuite g_mpiSimple2("mpi-example-simple-2",
153  "simple-distributed",
154  NS_TEST_SOURCEDIR,
155  2);
156 static MpiTestSuite g_mpiThird2("mpi-example-third-2", "third-distributed", NS_TEST_SOURCEDIR, 2);
157 
158 /* Tests using NullMessageSimulatorImpl */
159 static MpiTestSuite g_mpiSimple2NullMsg("mpi-example-simple-2-nullmsg",
160  "simple-distributed",
161  NS_TEST_SOURCEDIR,
162  2,
163  "--nullmsg");
164 static MpiTestSuite g_mpiEmpty2NullMsg("mpi-example-empty-2-nullmsg",
165  "simple-distributed-empty-node",
166  NS_TEST_SOURCEDIR,
167  2,
168  "-nullmsg");
169 static 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 TestDuration 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.
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:301
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.