summaryrefslogtreecommitdiff
path: root/gr-blocks/lib
diff options
context:
space:
mode:
authorDavid Winter <david.winter@analog.com>2021-09-28 13:42:54 +0200
committermormj <34754695+mormj@users.noreply.github.com>2021-10-21 10:59:16 -0400
commitdb01027fd99c882cf8b3a7dad854606499778e3b (patch)
tree2b2acc3584dc36668ef3fb2493598e7abf7abd3c /gr-blocks/lib
parent61709059f2e40a04ada73785812f19a5fc89cb8a (diff)
global: Replace stdio logging with logger
This commit replaces many uses of std::c{out,err} and printf with the appropriate GR_LOG_* directives. Signed-off-by: David Winter <david.winter@analog.com>
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r--gr-blocks/lib/check_lfsr_32k_s_impl.cc38
-rw-r--r--gr-blocks/lib/qa_block_tags.cc79
2 files changed, 63 insertions, 54 deletions
diff --git a/gr-blocks/lib/check_lfsr_32k_s_impl.cc b/gr-blocks/lib/check_lfsr_32k_s_impl.cc
index 443b01ce70..48c8493d97 100644
--- a/gr-blocks/lib/check_lfsr_32k_s_impl.cc
+++ b/gr-blocks/lib/check_lfsr_32k_s_impl.cc
@@ -17,6 +17,8 @@
#include <cstdio>
#include <cstdlib>
+static constexpr bool CHECK_LFSR_DEBUG = false;
+
namespace gr {
namespace blocks {
@@ -112,11 +114,11 @@ void check_lfsr_32k_s_impl::enter_SEARCHING()
d_runlength = 0;
d_index = 0; // reset LFSR to beginning
- if (0)
- fprintf(stdout,
- "check_lfsr_32k: enter_SEARCHING at offset %8ld (0x%08lx)\n",
- d_ntotal,
- d_ntotal);
+ if (CHECK_LFSR_DEBUG)
+ GR_LOG_DEBUG(
+ d_debug_logger,
+ boost::format("check_lfsr_32k: enter_SEARCHING at offset %8ld (0x%08lx)") %
+ d_ntotal % d_ntotal);
enter_MATCH0();
}
@@ -136,25 +138,21 @@ void check_lfsr_32k_s_impl::enter_LOCKED()
d_index = 3; // already matched first 3 items
- if (0)
- fprintf(stdout,
- "check_lfsr_32k: enter_LOCKED at offset %8ld (0x%08lx)\n",
- d_ntotal,
- d_ntotal);
+ if (CHECK_LFSR_DEBUG)
+ GR_LOG_DEBUG(
+ d_debug_logger,
+ boost::format("check_lfsr_32k: enter_LOCKED at offset %8ld (0x%08lx)") %
+ d_ntotal % d_ntotal);
}
void check_lfsr_32k_s_impl::log_error(unsigned short expected, unsigned short actual)
{
- if (0)
- fprintf(stdout,
- "check_lfsr_32k: expected %5d (0x%04x) got %5d (0x%04x) offset %8ld "
- "(0x%08lx)\n",
- expected,
- expected,
- actual,
- actual,
- d_ntotal,
- d_ntotal);
+ if (CHECK_LFSR_DEBUG)
+ GR_LOG_DEBUG(
+ d_debug_logger,
+ boost::format("check_lfsr_32k: expected %5d (0x%04x) got %5d (0x%04x) "
+ "offset %8ld (0x%08lx)") %
+ expected % expected % actual % actual % d_ntotal % d_ntotal);
}
} /* namespace blocks */
diff --git a/gr-blocks/lib/qa_block_tags.cc b/gr-blocks/lib/qa_block_tags.cc
index 091eb3c65c..65f4c9a070 100644
--- a/gr-blocks/lib/qa_block_tags.cc
+++ b/gr-blocks/lib/qa_block_tags.cc
@@ -19,11 +19,12 @@
#include <gnuradio/blocks/keep_one_in_n.h>
#include <gnuradio/blocks/null_sink.h>
#include <gnuradio/blocks/null_source.h>
+#include <gnuradio/logger.h>
#include <gnuradio/top_block.h>
+
+#include <boost/format.hpp>
#include <boost/test/unit_test.hpp>
-// FIXME use logging
-#include <iostream>
// ----------------------------------------------------------------
@@ -113,6 +114,8 @@ BOOST_AUTO_TEST_CASE(t1)
BOOST_REQUIRE_EQUAL(tags4.size(), (size_t)8);
#if QA_TAGS_DEBUG
+ GR_LOG_GET_CONFIGURED_LOGGER(logger, "qa_block_tags::t1");
+
// Kludge together the tags that we know should result from the above graph
std::stringstream str0, str1, str2;
str0 << ann0->name() << ann0->unique_id();
@@ -139,20 +142,20 @@ BOOST_AUTO_TEST_CASE(t1)
expected_tags4[6] = make_tag(30000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(3));
expected_tags4[7] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(7));
- std::cout << std::endl << "qa_block_tags::t1" << std::endl;
-
// For annotator 3, we know it gets tags from ann0 and ann1, test this
for (size_t i = 0; i < tags3.size(); i++) {
- std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i]
- << std::endl;
+ GR_LOG_INFO(logger,
+ boost::format("tags3[%d] = %s\t\t%s") % i % tags3[i] %
+ expected_tags3[i]);
BOOST_REQUIRE_EQUAL(tags3[i], expected_tags3[i]);
}
// For annotator 4, we know it gets tags from ann0 and ann2, test this
- std::cout << std::endl;
+ GR_LOG_INFO(logger, "");
for (size_t i = 0; i < tags4.size(); i++) {
- std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i]
- << std::endl;
+ GR_LOG_INFO(logger,
+ boost::format("tags4[%d] = %s\t\t%s") % i % tags4[i] %
+ expected_tags4);
BOOST_REQUIRE_EQUAL(tags4[i], expected_tags4[i]);
}
#endif
@@ -210,6 +213,8 @@ BOOST_AUTO_TEST_CASE(t2)
#if QA_TAGS_DEBUG
+ GR_LOG_GET_CONFIGURED_LOGGER(logger, "qa_block_tags::t2");
+
// Kludge together the tags that we know should result from the above graph
std::stringstream str0, str1;
str0 << ann0->name() << ann0->unique_id();
@@ -243,22 +248,22 @@ BOOST_AUTO_TEST_CASE(t2)
expected_tags4[10] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(6));
expected_tags4[11] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(7));
- std::cout << std::endl << "qa_block_tags::t2" << std::endl;
-
// For annotator[2-4], we know it gets tags from ann0 and ann1
// but the tags from the different outputs of ann1 are different for each.
// Just testing ann2 and ann4; if they are correct it would be
// inconceivable for ann3 to have it wrong.
for (size_t i = 0; i < tags2.size(); i++) {
- std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i]
- << std::endl;
+ GR_LOG_INFO(logger,
+ boost::format("tags2[%d] = %s\t\t%s") % i % tags2[i] %
+ expected_tags2[i]);
BOOST_REQUIRE_EQUAL(tags2[i], expected_tags2[i]);
}
- std::cout << std::endl;
+ GR_LOG_INFO(logger, "");
for (size_t i = 0; i < tags4.size(); i++) {
- std::cout << "tags2[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i]
- << std::endl;
+ GR_LOG_INFO(logger,
+ boost::format("tags4[%d] = %s\t\t%s") % i % tags4[i] %
+ expected_tags4[i]);
BOOST_REQUIRE_EQUAL(tags4[i], expected_tags4[i]);
}
#endif
@@ -309,6 +314,8 @@ BOOST_AUTO_TEST_CASE(t3)
BOOST_REQUIRE_EQUAL(tags4.size(), (size_t)8);
#if QA_TAGS_DEBUG
+ GR_LOG_GET_CONFIGURED_LOGGER(logger, "qa_block_tags::t3");
+
// Kludge together the tags that we know should result from the above graph
std::stringstream str0, str1, str2;
str0 << ann0->name() << ann0->unique_id();
@@ -335,20 +342,20 @@ BOOST_AUTO_TEST_CASE(t3)
expected_tags4[6] = make_tag(30000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(3));
expected_tags4[7] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(7));
- std::cout << std::endl << "qa_block_tags::t3" << std::endl;
-
// For annotator 3, we know it gets tags from ann0 and ann1, test this
for (size_t i = 0; i < tags3.size(); i++) {
- std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i]
- << std::endl;
+ GR_LOG_INFO(logger,
+ boost::format("tags3[%d] = %s\t\t%s") % i % tags3[i] %
+ expected_tags3[i]);
BOOST_REQUIRE_EQUAL(tags3[i], expected_tags3[i]);
}
// For annotator 4, we know it gets tags from ann0 and ann2, test this
- std::cout << std::endl;
+ GR_LOG_INFO(logger, "");
for (size_t i = 0; i < tags4.size(); i++) {
- std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i]
- << std::endl;
+ GR_LOG_INFO(logger,
+ boost::format("tags4[%d] = %s\t\t%s") % i % tags4[i] %
+ expected_tags4[i]);
BOOST_REQUIRE_EQUAL(tags4[i], expected_tags4[i]);
}
#endif
@@ -370,6 +377,8 @@ BOOST_AUTO_TEST_CASE(t4)
gr::block_sptr snk0(gr::blocks::null_sink::make(sizeof(int)));
gr::block_sptr snk1(gr::blocks::null_sink::make(sizeof(int)));
+ GR_LOG_GET_CONFIGURED_LOGGER(logger, "qa_block_tags::t4");
+
// using 1-to-1 tag propagation without having equal number of
// ins and outs. Make sure this works; will just exit run early.
tb->connect(src, 0, head, 0);
@@ -379,9 +388,8 @@ BOOST_AUTO_TEST_CASE(t4)
tb->connect(ann1, 0, snk0, 0);
tb->connect(ann2, 0, snk1, 0);
- std::cerr << std::endl
- << "NOTE: This is supposed to produce an error from block_executor"
- << std::endl;
+ GR_LOG_INFO(logger,
+ "NOTE: This is supposed to produce an error from block_executor!");
tb->run();
}
@@ -424,6 +432,8 @@ BOOST_AUTO_TEST_CASE(t5)
#if QA_TAGS_DEBUG
+ GR_LOG_GET_CONFIGURED_LOGGER(logger, "qa_block_tags::t5");
+
// Kludge together the tags that we know should result from the above graph
std::stringstream str0, str1, str2;
str0 << ann0->name() << ann0->unique_id();
@@ -448,22 +458,23 @@ BOOST_AUTO_TEST_CASE(t5)
expected_tags2[8] = make_tag(4000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(4));
expected_tags2[9] = make_tag(4000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(4));
- std::cout << std::endl << "qa_block_tags::t5" << std::endl;
+ GR_LOG_INFO(logger, boost::format("tags1.size(): %d") % tags1.size());
// annotator 1 gets tags from annotator 0
- std::cout << "tags1.size(): " << tags1.size() << std::endl;
for (size_t i = 0; i < tags1.size(); i++) {
- std::cout << "tags1[" << i << "] = " << tags1[i] << "\t\t" << expected_tags1[i]
- << std::endl;
+ GR_LOG_INFO(logger,
+ boost::format("tags1[%d] = %s\t\t%s") % i % tags1[i] %
+ expected_tags1[i]);
BOOST_REQUIRE_EQUAL(tags1[i], expected_tags1[i]);
}
// annotator 2 gets tags from annotators 0 and 1
- std::cout << std::endl;
- std::cout << "tags2.size(): " << tags2.size() << std::endl;
+ GR_LOG_INFO(logger, "");
+ GR_LOG_INFO(logger, boost::format("tags2.size(): %d") % tags2.size());
for (size_t i = 0; i < tags2.size(); i++) {
- std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i]
- << std::endl;
+ GR_LOG_INFO(logger,
+ boost::format("tags2[%d] = %s\t\t%s") % i % tags2[i] %
+ expected_tags2[i]);
BOOST_REQUIRE_EQUAL(tags2[i], expected_tags2[i]);
}
#endif