diff options
Diffstat (limited to 'gr-digital/lib/qa_header_format.cc')
-rw-r--r-- | gr-digital/lib/qa_header_format.cc | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/gr-digital/lib/qa_header_format.cc b/gr-digital/lib/qa_header_format.cc index 19d84fb65c..072f241062 100644 --- a/gr-digital/lib/qa_header_format.cc +++ b/gr-digital/lib/qa_header_format.cc @@ -19,7 +19,7 @@ #include <gnuradio/expj.h> #include <gnuradio/xoroshiro128p.h> #include <stdio.h> -#include <volk/volk.h> +#include <volk/volk_alloc.hh> #include <boost/test/unit_test.hpp> #include <cmath> @@ -50,16 +50,15 @@ BOOST_AUTO_TEST_CASE(test_default_format) int lower8 = N & 0xFF; std::string ac = "1010101010101010"; // 0xAAAA - unsigned char* data = - (unsigned char*)volk_malloc(N * sizeof(unsigned char), volk_get_alignment()); - xoroshiro_fill_buffer(data, N); + volk::vector<unsigned char> data(N); + xoroshiro_fill_buffer(data.data(), N); gr::digital::header_format_default::sptr hdr_format; hdr_format = gr::digital::header_format_default::make(ac, 0); pmt::pmt_t output; pmt::pmt_t info = pmt::make_dict(); - bool ret = hdr_format->format(N, data, output, info); + bool ret = hdr_format->format(N, data.data(), output, info); size_t length = pmt::length(output); BOOST_REQUIRE(ret); @@ -81,8 +80,6 @@ BOOST_AUTO_TEST_CASE(test_default_format) BOOST_REQUIRE_EQUAL(lower8, (int)h3); BOOST_REQUIRE_EQUAL(upper8, (int)h4); BOOST_REQUIRE_EQUAL(lower8, (int)h5); - - volk_free(data); } @@ -90,12 +87,11 @@ BOOST_AUTO_TEST_CASE(test_default_parse) { static const int nbytes = 106; static const int nbits = 8 * nbytes; - unsigned char* bytes = - (unsigned char*)volk_malloc(nbytes * sizeof(unsigned char), volk_get_alignment()); - unsigned char* bits = - (unsigned char*)volk_malloc(nbits * sizeof(unsigned char), volk_get_alignment()); - xoroshiro_fill_buffer(bytes, nbytes); + volk::vector<unsigned char> bytes(nbytes); + volk::vector<unsigned char> bits(nbits); + + xoroshiro_fill_buffer(bytes.data(), nbytes); int index = 0; bytes[index + 0] = 0xAA; @@ -106,7 +102,7 @@ BOOST_AUTO_TEST_CASE(test_default_parse) bytes[index + 5] = 0x64; gr::blocks::kernel::unpack_k_bits unpacker = gr::blocks::kernel::unpack_k_bits(8); - unpacker.unpack(bits, bytes, nbytes); + unpacker.unpack(bits.data(), bytes.data(), nbytes); std::string ac = "1010101010101010"; // 0xAAAA gr::digital::header_format_default::sptr hdr_format; @@ -114,7 +110,7 @@ BOOST_AUTO_TEST_CASE(test_default_parse) int count = 0; std::vector<pmt::pmt_t> info; - bool ret = hdr_format->parse(nbits, bits, info, count); + bool ret = hdr_format->parse(nbits, bits.data(), info, count); BOOST_REQUIRE(ret); BOOST_REQUIRE_EQUAL((size_t)1, info.size()); @@ -126,9 +122,6 @@ BOOST_AUTO_TEST_CASE(test_default_parse) int hdr_bits = (int)hdr_format->header_nbits(); int expected_bits = nbits - hdr_bits; BOOST_REQUIRE_EQUAL(expected_bits, payload_bits); - - volk_free(bytes); - volk_free(bits); } BOOST_AUTO_TEST_CASE(test_counter_format) @@ -138,9 +131,8 @@ BOOST_AUTO_TEST_CASE(test_counter_format) int lower8 = N & 0xFF; std::string ac = "1010101010101010"; // 0xAAAA - unsigned char* data = - (unsigned char*)volk_malloc(N * sizeof(unsigned char), volk_get_alignment()); - xoroshiro_fill_buffer(data, N); + volk::vector<unsigned char> data(N); + xoroshiro_fill_buffer(data.data(), N); uint16_t expected_bps = 2; gr::digital::header_format_counter::sptr hdr_format; @@ -149,7 +141,7 @@ BOOST_AUTO_TEST_CASE(test_counter_format) pmt::pmt_t output; pmt::pmt_t info = pmt::make_dict(); - bool ret = hdr_format->format(N, data, output, info); + bool ret = hdr_format->format(N, data.data(), output, info); size_t length = pmt::length(output); BOOST_REQUIRE(ret); @@ -183,13 +175,11 @@ BOOST_AUTO_TEST_CASE(test_counter_format) BOOST_REQUIRE_EQUAL((uint16_t)0, counter); // Run another format to increment the counter to 1 and test. - ret = hdr_format->format(N, data, output, info); + ret = hdr_format->format(N, data.data(), output, info); h8 = pmt::u8vector_ref(output, 8); h9 = pmt::u8vector_ref(output, 9); counter = ((h8 << 8) & 0xFF00) | (h9 & 0x00FF); BOOST_REQUIRE_EQUAL((uint16_t)1, counter); - - volk_free(data); } @@ -197,11 +187,9 @@ BOOST_AUTO_TEST_CASE(test_counter_parse) { static const int nbytes = 110; static const int nbits = 8 * nbytes; - unsigned char* bytes = - (unsigned char*)volk_malloc(nbytes * sizeof(unsigned char), volk_get_alignment()); - unsigned char* bits = - (unsigned char*)volk_malloc(nbits * sizeof(unsigned char), volk_get_alignment()); - xoroshiro_fill_buffer(bytes, nbytes); + volk::vector<unsigned char> bytes(nbytes); + volk::vector<unsigned char> bits(nbits); + xoroshiro_fill_buffer(bytes.data(), nbytes); int index = 0; bytes[index + 0] = 0xAA; bytes[index + 1] = 0xAA; @@ -215,7 +203,7 @@ BOOST_AUTO_TEST_CASE(test_counter_parse) bytes[index + 9] = 0x00; gr::blocks::kernel::unpack_k_bits unpacker = gr::blocks::kernel::unpack_k_bits(8); - unpacker.unpack(bits, bytes, nbytes); + unpacker.unpack(bits.data(), bytes.data(), nbytes); uint16_t expected_bps = 2; std::string ac = "1010101010101010"; // 0xAAAA @@ -224,7 +212,7 @@ BOOST_AUTO_TEST_CASE(test_counter_parse) int count = 0; std::vector<pmt::pmt_t> info; - bool ret = hdr_format->parse(nbits, bits, info, count); + bool ret = hdr_format->parse(nbits, bits.data(), info, count); BOOST_REQUIRE(ret); BOOST_REQUIRE_EQUAL((size_t)1, info.size()); @@ -241,7 +229,4 @@ BOOST_AUTO_TEST_CASE(test_counter_parse) BOOST_REQUIRE_EQUAL(expected_bits, payload_syms * bps); BOOST_REQUIRE_EQUAL(expected_bps, (uint16_t)bps); BOOST_REQUIRE_EQUAL(0, counter); - - volk_free(bytes); - volk_free(bits); } |