3 * Copyright 2006,2007 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
27 #include <qa_mblock_send.h>
28 #include <cppunit/TestAssert.h>
29 #include <mb_mblock.h>
30 #include <mb_runtime.h>
31 #include <mb_protocol_class.h>
32 #include <mb_exception.h>
33 #include <mb_msg_queue.h>
34 #include <mb_message.h>
35 #include <mb_mblock_impl.h>
36 #include <mb_msg_accepter.h>
39 static pmt_t s_data = pmt_intern("data");
40 static pmt_t s_status = pmt_intern("status");
41 static pmt_t s_control = pmt_intern("control");
42 static pmt_t s_p0 = pmt_intern("p0");
43 static pmt_t s_p1 = pmt_intern("p1");
44 static pmt_t s_p2 = pmt_intern("p2");
45 static pmt_t s_p3 = pmt_intern("p3");
46 static pmt_t s_e1 = pmt_intern("e1");
47 static pmt_t s_r1 = pmt_intern("r1");
50 define_protocol_classes()
52 // Defined from client point-of-view.
53 mb_make_protocol_class(pmt_intern("qa-send-cs"), // name
54 pmt_list1(s_status), // incoming
55 pmt_list1(s_control)); // outgoing
59 // ================================================================
60 // test_simple_routing
61 // ================================================================
63 // sub-block for test_simple_routing
65 class sr1 : public mb_mblock
79 d_p1 = define_port("p1", "qa-send-cs", true, mb_port::EXTERNAL);
80 d_p2 = define_port("p2", "qa-send-cs", true, mb_port::EXTERNAL);
81 d_p3 = define_port("p3", "qa-send-cs", false, mb_port::EXTERNAL);
89 // std::cout << fullname() << "[sr1]: init_fsm\n";
91 // send two messages to each port
92 pmt_t our_name = pmt_intern(fullname());
93 d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(0)));
94 d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(1)));
96 d_p2->send(s_status, pmt_list3(our_name, s_p2, pmt_from_long(0)));
97 d_p2->send(s_status, pmt_list3(our_name, s_p2, pmt_from_long(1)));
100 // ----------------------------------------------------------------
102 // top-level container block for test_simple_routing
103 class sr0 : public mb_mblock
115 d_p0 = define_port("p0", "qa-send-cs", false, mb_port::INTERNAL);
117 define_component("mb1", mb_mblock_sptr(new sr1()));
118 define_component("mb2", mb_mblock_sptr(new sr1()));
120 connect("self", "p0", "mb1", "p1");
121 connect("mb1", "p2", "mb2", "p3");
122 connect("mb1", "p3", "mb2", "p2");
130 // std::cout << fullname() << "[sr0]: init_fsm\n";
132 // send two messages to p0
133 pmt_t our_name = pmt_intern(fullname());
134 d_p0->send(s_control, pmt_list3(our_name, s_p0, pmt_from_long(0)));
135 d_p0->send(s_control, pmt_list3(our_name, s_p0, pmt_from_long(1)));
138 // ----------------------------------------------------------------
141 * This tests basic message routing using INTERNAL and EXTERNAL ports.
142 * It does not rely on the guts of the runtime being complete,
143 * which is good, because at the time this is being written, it isn't.
146 qa_mblock_send::test_simple_routing()
148 define_protocol_classes();
152 mb_runtime_sptr rt = mb_make_runtime();
153 mb_mblock_sptr mb0 = mb_mblock_sptr(new sr0());
156 // Reach into the guts and see if the messages ended up where they should have
158 // mb0 should have received two messages sent from mb1 via its p1
159 msg = mb0->impl()->msgq().get_highest_pri_msg();
161 // std::cerr << msg->data() << std::endl;
162 CPPUNIT_ASSERT_EQUAL(s_p0, msg->port_id());
163 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p1, pmt_from_long(0)),
166 msg = mb0->impl()->msgq().get_highest_pri_msg();
168 // std::cerr << msg->data() << std::endl;
169 CPPUNIT_ASSERT_EQUAL(s_p0, msg->port_id());
170 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p1, pmt_from_long(1)),
173 // mb1 should have received
174 // two messages from mb0 via its p0 and
175 // two messages from mb2 via its p3
177 mb_mblock_sptr mb1 = mb0->impl()->component("mb1");
179 msg = mb1->impl()->msgq().get_highest_pri_msg();
181 // std::cerr << msg->data() << std::endl;
182 CPPUNIT_ASSERT_EQUAL(s_p1, msg->port_id());
183 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top"), s_p0, pmt_from_long(0)),
186 msg = mb1->impl()->msgq().get_highest_pri_msg();
188 // std::cerr << msg->data() << std::endl;
189 CPPUNIT_ASSERT_EQUAL(s_p1, msg->port_id());
190 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top"), s_p0, pmt_from_long(1)),
193 msg = mb1->impl()->msgq().get_highest_pri_msg();
195 // std::cerr << msg->data() << std::endl;
196 CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id());
197 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb2"), s_p2, pmt_from_long(0)),
200 msg = mb1->impl()->msgq().get_highest_pri_msg();
202 // std::cerr << msg->data() << std::endl;
203 CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id());
204 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb2"), s_p2, pmt_from_long(1)),
208 // mb2 should have received
209 // two messages from mb2 via its p2
211 mb_mblock_sptr mb2 = mb0->impl()->component("mb2");
213 msg = mb2->impl()->msgq().get_highest_pri_msg();
215 // std::cerr << msg->data() << std::endl;
216 CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id());
217 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p2, pmt_from_long(0)),
220 msg = mb2->impl()->msgq().get_highest_pri_msg();
222 // std::cerr << msg->data() << std::endl;
223 CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id());
224 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p2, pmt_from_long(1)),
228 // ================================================================
229 // test_relay_routing_1
230 // ================================================================
232 // internal block for test_relay_routing
234 class rr2 : public mb_mblock
247 d_p1 = define_port("p1", "qa-send-cs", true, mb_port::EXTERNAL);
248 d_p2 = define_port("p2", "qa-send-cs", false, mb_port::EXTERNAL);
256 // std::cout << fullname() << "[rr2]: init_fsm\n";
258 // send two messages via p1
259 pmt_t our_name = pmt_intern(fullname());
260 d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(0)));
261 d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(1)));
264 // ----------------------------------------------------------------
266 // intermediate block for test_relay_routing
268 class rr1 : public mb_mblock
280 d_p1 = define_port("p1", "qa-send-cs", true, mb_port::RELAY);
281 d_p2 = define_port("p2", "qa-send-cs", false, mb_port::RELAY);
283 define_component("c0", mb_mblock_sptr(new rr2()));
285 connect("self", "p1", "c0", "p1");
286 connect("self", "p2", "c0", "p2");
291 // ----------------------------------------------------------------
293 // top-level container for test_relay_routing
295 class rr0_a : public mb_mblock
304 define_component("c0", mb_mblock_sptr(new rr1()));
305 define_component("c1", mb_mblock_sptr(new rr2()));
307 connect("c0", "p1", "c1", "p2");
308 connect("c0", "p2", "c1", "p1");
315 * This tests basic message routing using RELAY and EXTERNAL ports.
316 * It does not rely on the guts of the runtime being complete,
317 * which is good, because at the time this is being written, it isn't.
320 qa_mblock_send::test_relay_routing_1()
324 mb_runtime_sptr rt = mb_make_runtime();
325 mb_mblock_sptr top = mb_mblock_sptr(new rr0_a());
328 // Reach into the guts and see if the messages ended up where they should have
330 mb_mblock_sptr c0 = top->impl()->component("c0");
331 mb_mblock_sptr c0c0 = c0->impl()->component("c0");
333 mb_mblock_sptr c1 = top->impl()->component("c1");
335 // c0c0 should have received
336 // two message from c1 via its p2
338 msg = c0c0->impl()->msgq().get_highest_pri_msg();
340 //std::cerr << msg->data() << std::endl;
341 CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id());
342 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1"), s_p1, pmt_from_long(0)),
345 msg = c0c0->impl()->msgq().get_highest_pri_msg();
347 //std::cerr << msg->data() << std::endl;
348 CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id());
349 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1"), s_p1, pmt_from_long(1)),
352 // c1 should have received
353 // two message from c0c0 via its p2
355 msg = c1->impl()->msgq().get_highest_pri_msg();
357 //std::cerr << msg->data() << std::endl;
358 CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id());
359 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(0)),
362 msg = c1->impl()->msgq().get_highest_pri_msg();
364 //std::cerr << msg->data() << std::endl;
365 CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id());
366 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(1)),
370 // ================================================================
371 // test_relay_routing_2
372 // ================================================================
374 // top-level container for test_relay_routing_2
376 class rr0_b : public mb_mblock
385 define_component("c0", mb_mblock_sptr(new rr1()));
386 define_component("c1", mb_mblock_sptr(new rr1()));
388 connect("c0", "p1", "c1", "p2");
389 connect("c0", "p2", "c1", "p1");
396 * This tests basic message routing using RELAY and EXTERNAL ports.
397 * It does not rely on the guts of the runtime being complete,
398 * which is good, because at the time this is being written, it isn't.
401 qa_mblock_send::test_relay_routing_2()
405 mb_runtime_sptr rt = mb_make_runtime();
406 mb_mblock_sptr top = mb_mblock_sptr(new rr0_b());
409 // Reach into the guts and see if the messages ended up where they should have
411 mb_mblock_sptr c0 = top->impl()->component("c0");
412 mb_mblock_sptr c0c0 = c0->impl()->component("c0");
414 mb_mblock_sptr c1 = top->impl()->component("c1");
415 mb_mblock_sptr c1c0 = c1->impl()->component("c0");
417 // c0c0 should have received
418 // two message from c1c0 via its p2
420 msg = c0c0->impl()->msgq().get_highest_pri_msg();
422 // std::cerr << msg->data() << std::endl;
423 CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id());
424 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1/c0"), s_p1, pmt_from_long(0)),
427 msg = c0c0->impl()->msgq().get_highest_pri_msg();
429 // std::cerr << msg->data() << std::endl;
430 CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id());
431 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1/c0"), s_p1, pmt_from_long(1)),
434 // c1c0 should have received
435 // two message from c0c0 via its p2
437 msg = c1c0->impl()->msgq().get_highest_pri_msg();
439 // std::cerr << msg->data() << std::endl;
440 CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id());
441 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(0)),
444 msg = c1c0->impl()->msgq().get_highest_pri_msg();
446 // std::cerr << msg->data() << std::endl;
447 CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id());
448 CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(1)),