A Discrete-Event Network Simulator
API
mpi-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 Lawrence Livermore National Laboratory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
19  */
20 
21 #include "ns3/example-as-test.h"
22 
23 #include <sstream>
24 
25 using namespace ns3;
26 
36 {
37 public:
43  MpiTestCase (const std::string name,
44  const std::string program,
45  const std::string dataDir,
46  const int ranks,
47  const std::string args = "");
48 
50  virtual ~MpiTestCase (void) {};
51 
58  std::string GetCommandTemplate (void) const;
59 
66  std::string
67  GetPostProcessingCommand (void) const;
68 
69 private:
71  int m_ranks;
72 };
73 
74 MpiTestCase::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 
84 std::string
86 {
87  std::stringstream ss;
88  ss << "mpiexec -n " << m_ranks << " %s --test " << m_args;
89  return ss.str ();
90 }
91 
92 std::string
94 {
95  std::string command ("| grep TEST | sort ");
96  return command;
97 }
98 
103 class MpiTestSuite : public TestSuite
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 */
126 static MpiTestSuite g_mpiNms2 ("mpi-example-nms-2", "nms-p2p-nix-distributed", NS_TEST_SOURCEDIR, 2);
127 static MpiTestSuite g_mpiComm2 ("mpi-example-comm-2", "simple-distributed-mpi-comm", NS_TEST_SOURCEDIR, 2);
128 static MpiTestSuite g_mpiComm2comm ("mpi-example-comm-2-init", "simple-distributed-mpi-comm", NS_TEST_SOURCEDIR, 2, "--init");
129 static MpiTestSuite g_mpiComm3comm ("mpi-example-comm-3-init", "simple-distributed-mpi-comm", NS_TEST_SOURCEDIR, 3, "--init");
130 static MpiTestSuite g_mpiEmpty2 ("mpi-example-empty-2", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 2);
131 static MpiTestSuite g_mpiEmpty3 ("mpi-example-empty-3", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 3);
132 static MpiTestSuite g_mpiSimple2 ("mpi-example-simple-2", "simple-distributed", NS_TEST_SOURCEDIR, 2);
133 static MpiTestSuite g_mpiThird2 ("mpi-example-third-2", "third-distributed", NS_TEST_SOURCEDIR, 2);
134 
135 /* Tests using NullMessageSimulatorImpl */
136 static MpiTestSuite g_mpiSimple2NullMsg ("mpi-example-simple-2-nullmsg", "simple-distributed", NS_TEST_SOURCEDIR, 2, "--nullmsg");
137 static MpiTestSuite g_mpiEmpty2NullMsg ("mpi-example-empty-2-nullmsg", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 2, "-nullmsg");
138 static MpiTestSuite g_mpiEmpty3NullMsg ("mpi-example-empty-3-nullmsg", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 3, "-nullmsg");
139 
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(void) const
Produce the --command-template argument which will invoke mpiexec with the requested number of ranks.
std::string GetPostProcessingCommand(void) const
Sort the output from parallel execution.
virtual ~MpiTestCase(void)
Destructor.
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:998
@ QUICK
Fast test.
Definition: test.h:999
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
@ EXAMPLE
This test suite implements an Example Test.
Definition: test.h:1199
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.