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 
34 {
35 public:
41  MpiTestCase (const std::string name,
42  const std::string program,
43  const std::string dataDir,
44  const int ranks,
45  const std::string args = "");
46 
48  virtual ~MpiTestCase (void) {};
49 
56  std::string GetCommandTemplate (void) const;
57 
64  std::string
65  GetPostProcessingCommand (void) const;
66 
67 private:
69  int m_ranks;
70 };
71 
72 MpiTestCase::MpiTestCase (const std::string name,
73  const std::string program,
74  const std::string dataDir,
75  const int ranks,
76  const std::string args /* = "" */)
77  : ExampleAsTestCase (name, program, dataDir, args),
78  m_ranks (ranks)
79 {
80 }
81 
82 std::string
84 {
85  std::stringstream ss;
86  ss << "mpiexec -n " << m_ranks << " %s --test " << m_args;
87  return ss.str ();
88 }
89 
90 std::string
92 {
93  std::string command ("| grep TEST | sort ");
94  return command;
95 }
96 
98 class MpiTestSuite : public TestSuite
99 {
100 public:
107  MpiTestSuite (const std::string name,
108  const std::string program,
109  const std::string dataDir,
110  const int ranks,
111  const std::string args = "",
112  const TestDuration duration=QUICK)
113  : TestSuite (name, EXAMPLE)
114  {
115  AddTestCase (new MpiTestCase (name, program, dataDir, ranks, args), duration);
116  }
117 
118 }; // class MpiTestSuite
119 
120 /* Tests using SimpleDistributedSimulatorImpl */
121 static MpiTestSuite g_mpiNms2 ("mpi-example-nms-2", "nms-p2p-nix-distributed", NS_TEST_SOURCEDIR, 2);
122 static MpiTestSuite g_mpiComm2 ("mpi-example-comm-2", "simple-distributed-mpi-comm", NS_TEST_SOURCEDIR, 2);
123 static MpiTestSuite g_mpiComm2comm ("mpi-example-comm-2-init", "simple-distributed-mpi-comm", NS_TEST_SOURCEDIR, 2, "--init");
124 static MpiTestSuite g_mpiComm3comm ("mpi-example-comm-3-init", "simple-distributed-mpi-comm", NS_TEST_SOURCEDIR, 3, "--init");
125 static MpiTestSuite g_mpiEmpty2 ("mpi-example-empty-2", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 2);
126 static MpiTestSuite g_mpiEmpty3 ("mpi-example-empty-3", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 3);
127 static MpiTestSuite g_mpiSimple2 ("mpi-example-simple-2", "simple-distributed", NS_TEST_SOURCEDIR, 2);
128 static MpiTestSuite g_mpiThird2 ("mpi-example-third-2", "third-distributed", NS_TEST_SOURCEDIR, 2);
129 
130 /* Tests using NullMessageSimulatorImpl */
131 static MpiTestSuite g_mpiSimple2NullMsg ("mpi-example-simple-2-nullmsg", "simple-distributed", NS_TEST_SOURCEDIR, 2, "--nullmsg");
132 static MpiTestSuite g_mpiEmpty2NullMsg ("mpi-example-empty-2-nullmsg", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 2, "-nullmsg");
133 static MpiTestSuite g_mpiEmpty3NullMsg ("mpi-example-empty-3-nullmsg", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 3, "-nullmsg");
134 
static MpiTestSuite g_mpiComm2comm("mpi-example-comm-2-init", "simple-distributed-mpi-comm", NS_TEST_SOURCEDIR, 2, "--init")
This version of ns3::ExampleTestCase is specialized for MPI by accepting the number of ranks as a par...
A suite of tests to run.
Definition: test.h:1343
static MpiTestSuite g_mpiEmpty2NullMsg("mpi-example-empty-2-nullmsg", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 2, "-nullmsg")
static MpiTestSuite g_mpiEmpty2("mpi-example-empty-2", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 2)
std::string m_args
Any additional arguments to the program.
static MpiTestSuite g_mpiEmpty3("mpi-example-empty-3", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 3)
std::string GetPostProcessingCommand(void) const
Sort the output from parallel execution.
static MpiTestSuite g_mpiSimple2("mpi-example-simple-2", "simple-distributed", NS_TEST_SOURCEDIR, 2)
virtual ~MpiTestCase(void)
Destructor.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
static MpiTestSuite g_mpiComm3comm("mpi-example-comm-3-init", "simple-distributed-mpi-comm", NS_TEST_SOURCEDIR, 3, "--init")
TestDuration
How long the test takes to execute.
Definition: test.h:1157
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Execute an example program as a test, by comparing the output to a reference file.
MPI specialization of ns3::ExampleTestSuite.
static MpiTestSuite g_mpiThird2("mpi-example-third-2", "third-distributed", NS_TEST_SOURCEDIR, 2)
Fast test.
Definition: test.h:1159
static MpiTestSuite g_mpiComm2("mpi-example-comm-2", "simple-distributed-mpi-comm", NS_TEST_SOURCEDIR, 2)
static MpiTestSuite g_mpiNms2("mpi-example-nms-2", "nms-p2p-nix-distributed", NS_TEST_SOURCEDIR, 2)
int m_ranks
The number of ranks.
This test suite implements an Example Test.
Definition: test.h:1355
MpiTestCase(const std::string name, const std::string program, const std::string dataDir, const int ranks, const std::string args="")
Constructor.
static MpiTestSuite g_mpiEmpty3NullMsg("mpi-example-empty-3-nullmsg", "simple-distributed-empty-node", NS_TEST_SOURCEDIR, 3, "-nullmsg")
std::string GetCommandTemplate(void) const
Produce the --command-template argument which will invoke mpiexec with the requested number of ranks...
static MpiTestSuite g_mpiSimple2NullMsg("mpi-example-simple-2-nullmsg", "simple-distributed", NS_TEST_SOURCEDIR, 2, "--nullmsg")
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.