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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
7 */
8
9#include "ns3/example-as-test.h"
10
11#include <sstream>
12
13using namespace ns3;
14
15/**
16 * \ingroup mpi-tests
17 *
18 * This version of ns3::ExampleTestCase is specialized for MPI
19 * by accepting the number of ranks as a parameter,
20 * then building a `--command-template` string which
21 * invokes `mpiexec` correctly to execute MPI examples.
22 */
24{
25 public:
26 /**
27 * \copydoc ns3::ExampleAsTestCase::ExampleAsTestCase
28 *
29 * \param [in] ranks The number of ranks to use
30 */
31 MpiTestCase(const std::string name,
32 const std::string program,
33 const std::string dataDir,
34 const int ranks,
35 const std::string args = "",
36 const bool shouldNotErr = true);
37
38 /** Destructor */
39 ~MpiTestCase() override
40 {
41 }
42
43 /**
44 * Produce the `--command-template` argument which will invoke
45 * `mpiexec` with the requested number of ranks.
46 *
47 * \returns The `--command-template` string.
48 */
49 std::string GetCommandTemplate() const override;
50
51 /**
52 * Sort the output from parallel execution.
53 * stdout from multiple ranks is not ordered.
54 *
55 * \returns Sort command
56 */
57 std::string GetPostProcessingCommand() const override;
58
59 private:
60 /** The number of ranks. */
62};
63
64MpiTestCase::MpiTestCase(const std::string name,
65 const std::string program,
66 const std::string dataDir,
67 const int ranks,
68 const std::string args /* = "" */,
69 const bool shouldNotErr /* = true */)
70 : ExampleAsTestCase(name, program, dataDir, args, shouldNotErr),
71 m_ranks(ranks)
72{
73}
74
75std::string
77{
78 std::stringstream ss;
79 ss << "mpiexec -n " << m_ranks << " %s --test " << m_args;
80 return ss.str();
81}
82
83std::string
85{
86 std::string command("| grep TEST | sort ");
87 return command;
88}
89
90/**
91 * \ingroup mpi-tests
92 * MPI specialization of ns3::ExampleTestSuite.
93 */
94class MpiTestSuite : public TestSuite
95{
96 public:
97 /**
98 * \copydoc MpiTestCase::MpiTestCase
99 *
100 * \param [in] duration Amount of time this test takes to execute
101 * (defaults to QUICK).
102 */
103 MpiTestSuite(const std::string name,
104 const std::string program,
105 const std::string dataDir,
106 const int ranks,
107 const std::string args = "",
108 const Duration duration = Duration::QUICK,
109 const bool shouldNotErr = true)
110 : TestSuite(name, Type::EXAMPLE)
111 {
112 AddTestCase(new MpiTestCase(name, program, dataDir, ranks, args, shouldNotErr), duration);
113 }
114
115}; // class MpiTestSuite
116
117/* Tests using SimpleDistributedSimulatorImpl */
118static MpiTestSuite g_mpiNms2("mpi-example-nms-2", "nms-p2p-nix-distributed", NS_TEST_SOURCEDIR, 2);
119static MpiTestSuite g_mpiComm2("mpi-example-comm-2",
120 "simple-distributed-mpi-comm",
121 NS_TEST_SOURCEDIR,
122 2);
123static MpiTestSuite g_mpiComm2comm("mpi-example-comm-2-init",
124 "simple-distributed-mpi-comm",
125 NS_TEST_SOURCEDIR,
126 2,
127 "--init");
128static MpiTestSuite g_mpiComm3comm("mpi-example-comm-3-init",
129 "simple-distributed-mpi-comm",
130 NS_TEST_SOURCEDIR,
131 3,
132 "--init");
133static MpiTestSuite g_mpiEmpty2("mpi-example-empty-2",
134 "simple-distributed-empty-node",
135 NS_TEST_SOURCEDIR,
136 2);
137static MpiTestSuite g_mpiEmpty3("mpi-example-empty-3",
138 "simple-distributed-empty-node",
139 NS_TEST_SOURCEDIR,
140 3);
141static MpiTestSuite g_mpiSimple2("mpi-example-simple-2",
142 "simple-distributed",
143 NS_TEST_SOURCEDIR,
144 2);
145static MpiTestSuite g_mpiThird2("mpi-example-third-2", "third-distributed", NS_TEST_SOURCEDIR, 2);
146
147/* Tests using NullMessageSimulatorImpl */
148static MpiTestSuite g_mpiSimple2NullMsg("mpi-example-simple-2-nullmsg",
149 "simple-distributed",
150 NS_TEST_SOURCEDIR,
151 2,
152 "--nullmsg");
153static MpiTestSuite g_mpiEmpty2NullMsg("mpi-example-empty-2-nullmsg",
154 "simple-distributed-empty-node",
155 NS_TEST_SOURCEDIR,
156 2,
157 "-nullmsg");
158static MpiTestSuite g_mpiEmpty3NullMsg("mpi-example-empty-3-nullmsg",
159 "simple-distributed-empty-node",
160 NS_TEST_SOURCEDIR,
161 3,
162 "-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:292
Duration
How long the test takes to execute.
Definition test.h:1054
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto EXAMPLE
Definition test.h:1295
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.