LEFT | RIGHT |
1 #include "ns3/test.h" | 1 #include "ns3/test.h" |
2 #include "ns3/node.h" | 2 #include "ns3/node.h" |
3 #include "ns3/simulator.h" | 3 #include "ns3/simulator.h" |
4 #include "ns3/uinteger.h" | 4 #include "ns3/uinteger.h" |
5 #include "process-manager.h" | 5 #include "process-manager.h" |
6 #include "process-delay-model.h" | 6 #include "process-delay-model.h" |
7 #include "rr-scheduler.h" | 7 #include "rr-scheduler.h" |
8 #include "ns3/netlink-socket-factory.h" | 8 #include "ns3/netlink-socket-factory.h" |
9 #include "ns3/arp-l3-protocol.h" | 9 #include "ns3/arp-l3-protocol.h" |
10 #include "ns3/ipv4-l3-protocol.h" | 10 #include "ns3/ipv4-l3-protocol.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 | 29 |
30 class ProcessManagerTestCase : public TestCase | 30 class ProcessManagerTestCase : public TestCase |
31 { | 31 { |
32 public: | 32 public: |
33 ProcessManagerTestCase (std::string filename); | 33 ProcessManagerTestCase (std::string filename); |
34 private: | 34 private: |
35 virtual bool DoRun (void); | 35 virtual bool DoRun (void); |
36 Ptr<ProcessManager> CreateManager (void); | 36 Ptr<ProcessManager> CreateManager (void); |
37 static void Finished (int *pstatus, uint16_t pid, int status); | 37 static void Finished (int *pstatus, uint16_t pid, int status); |
| 38 void DoStartRun (Ptr<ProcessManager> manager); |
38 | 39 |
39 std::string m_filename; | 40 std::string m_filename; |
| 41 int m_status; |
40 }; | 42 }; |
41 | 43 |
42 ProcessManagerTestCase::ProcessManagerTestCase (std::string filename) | 44 ProcessManagerTestCase::ProcessManagerTestCase (std::string filename) |
43 : TestCase ("Check that process \"" + filename + "\" completes correctly."), | 45 : TestCase ("Check that process \"" + filename + "\" completes correctly."), |
44 m_filename (filename) | 46 m_filename (filename), |
| 47 m_status (-1) |
45 {} | 48 {} |
46 Ptr<ProcessManager>· | 49 Ptr<ProcessManager>· |
47 ProcessManagerTestCase::CreateManager (void) | 50 ProcessManagerTestCase::CreateManager (void) |
48 { | 51 { |
49 Ptr<Node> a = CreateObject<Node> (); | 52 Ptr<Node> a = CreateObject<Node> (); |
50 Ptr<ProcessScheduler> sched = CreateObject<RrScheduler> (); | 53 Ptr<ProcessScheduler> sched = CreateObject<RrScheduler> (); |
51 Ptr<ProcessDelayModel> delay = CreateObject<RandomProcessDelayModel> (); | 54 Ptr<ProcessDelayModel> delay = CreateObject<RandomProcessDelayModel> (); |
52 Ptr<ProcessManager> aManager = CreateObject<ProcessManager> (); | 55 Ptr<ProcessManager> aManager = CreateObject<ProcessManager> (); |
53 aManager->SetScheduler (sched); | 56 aManager->SetScheduler (sched); |
54 aManager->SetDelayModel (delay); | 57 aManager->SetDelayModel (delay); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 return aManager; | 90 return aManager; |
88 } | 91 } |
89 void | 92 void |
90 ProcessManagerTestCase::Finished (int *pstatus, uint16_t pid, int status) | 93 ProcessManagerTestCase::Finished (int *pstatus, uint16_t pid, int status) |
91 { | 94 { |
92 *pstatus = status; | 95 *pstatus = status; |
93 } | 96 } |
94 bool | 97 bool |
95 ProcessManagerTestCase::DoRun (void) | 98 ProcessManagerTestCase::DoRun (void) |
96 { | 99 { |
| 100 Ptr<ProcessManager> a = CreateManager (); |
| 101 |
| 102 Simulator::ScheduleWithContext (a->GetObject<Node> ()->GetId (), Seconds (0), |
| 103 &ProcessManagerTestCase::DoStartRun, |
| 104 this, a); |
| 105 Simulator::Run (); |
| 106 Simulator::Destroy (); |
| 107 NS_TEST_ASSERT_MSG_EQ (m_status, 0, "Process did not return successfully: " <<
g_testError); |
| 108 return m_status != 0; |
| 109 } |
| 110 |
| 111 |
| 112 void |
| 113 ProcessManagerTestCase::DoStartRun (Ptr<ProcessManager> manager) |
| 114 { |
97 std::vector<std::string> noargs; | 115 std::vector<std::string> noargs; |
98 std::vector<std::pair<std::string,std::string> > noenv; | 116 std::vector<std::pair<std::string,std::string> > noenv; |
99 int status = - 1; | 117 uint16_t pid = manager->CreateWithStack (m_filename, 1<<20, noargs, |
100 Ptr<ProcessManager> a = CreateManager (); | 118 noenv); |
101 uint16_t pid = a->CreateWithStack (m_filename, 1<<20, noargs, noenv); | 119 manager->SetFinishedCallback (pid, MakeBoundCallback |
102 a->SetFinishedCallback (pid, MakeBoundCallback (&ProcessManagerTestCase::Finis
hed, &status)); | 120 (&ProcessManagerTestCase::Finished, &m_status)); |
103 Simulator::Run (); | 121 return; |
104 Simulator::Destroy (); | |
105 NS_TEST_ASSERT_MSG_EQ (status, 0, "Process did not return successfully: " << g
_testError); | |
106 return status != 0; | |
107 } | 122 } |
| 123 |
108 | 124 |
109 static class ProcessManagerTestSuite : public TestSuite | 125 static class ProcessManagerTestSuite : public TestSuite |
110 { | 126 { |
111 public: | 127 public: |
112 ProcessManagerTestSuite (); | 128 ProcessManagerTestSuite (); |
113 private: | 129 private: |
114 } g_processTests; | 130 } g_processTests; |
115 | 131 |
116 ProcessManagerTestSuite::ProcessManagerTestSuite () | 132 ProcessManagerTestSuite::ProcessManagerTestSuite () |
117 : TestSuite ("process-manager", UNIT) | 133 : TestSuite ("process-manager", UNIT) |
(...skipping 17 matching lines...) Expand all Loading... |
135 "test-cond", | 151 "test-cond", |
136 "test-socket", | 152 "test-socket", |
137 }; | 153 }; |
138 for (unsigned int i = 0; i < sizeof(tests)/sizeof(char*);i++) | 154 for (unsigned int i = 0; i < sizeof(tests)/sizeof(char*);i++) |
139 { | 155 { |
140 AddTestCase (new ProcessManagerTestCase (tests[i])); | 156 AddTestCase (new ProcessManagerTestCase (tests[i])); |
141 } | 157 } |
142 } | 158 } |
143 | 159 |
144 } // namespace ns3 | 160 } // namespace ns3 |
LEFT | RIGHT |