diff options
Diffstat (limited to 'gnuradio-runtime')
58 files changed, 895 insertions, 1858 deletions
diff --git a/gnuradio-runtime/CMakeLists.txt b/gnuradio-runtime/CMakeLists.txt index 2f9c86173d..73d5fdd54c 100644 --- a/gnuradio-runtime/CMakeLists.txt +++ b/gnuradio-runtime/CMakeLists.txt @@ -23,6 +23,8 @@ include(GrBoost) include(GrPython) +find_package(MPLIB REQUIRED) + ######################################################################## # Setup compatibility checks and defines ######################################################################## @@ -37,7 +39,7 @@ GR_REGISTER_COMPONENT("gnuradio-runtime" ENABLE_GNURADIO_RUNTIME Boost_FOUND ENABLE_VOLK PYTHONINTERP_FOUND - LOG4CPP_FOUND + MPLIB_FOUND ) GR_SET_GLOBAL(GNURADIO_RUNTIME_INCLUDE_DIRS @@ -96,6 +98,9 @@ install(FILES DESTINATION ${GR_PREFSDIR} ) +set(PC_ADD_LIBS "${MPLIB_PC_ADD_LIBS} ${PC_ADD_LIBS}") +set(PC_ADD_CFLAGS ${MPLIB_PC_ADD_CFLAGS}) + ######################################################################## # Add subdirectories ######################################################################## diff --git a/gnuradio-runtime/gnuradio-runtime.pc.in b/gnuradio-runtime/gnuradio-runtime.pc.in index 59b1ff7af9..280adaddd1 100644 --- a/gnuradio-runtime/gnuradio-runtime.pc.in +++ b/gnuradio-runtime/gnuradio-runtime.pc.in @@ -7,5 +7,5 @@ Name: gnuradio-runtime Description: GNU Radio core runtime infrastructure Requires: Version: @LIBVER@ -Libs: -L${libdir} -lgnuradio-runtime -lgnuradio-pmt -llog4cpp -Cflags: -I${includedir} +Libs: -L${libdir} -lgnuradio-runtime -lgnuradio-pmt @PC_ADD_LIBS@ +Cflags: -I${includedir} @PC_ADD_CFLAGS@ diff --git a/gnuradio-runtime/include/gnuradio/basic_block.h b/gnuradio-runtime/include/gnuradio/basic_block.h index 4d8b228d73..1b36999f5a 100644 --- a/gnuradio-runtime/include/gnuradio/basic_block.h +++ b/gnuradio-runtime/include/gnuradio/basic_block.h @@ -162,17 +162,17 @@ namespace gr { /*! * True if the block has an alias (see set_block_alias). */ - bool alias_set() { return !d_symbol_alias.empty(); } + bool alias_set() const { return !d_symbol_alias.empty(); } /*! * Returns the block's alias as a string. */ - std::string alias(){ return alias_set()?d_symbol_alias:symbol_name(); } + std::string alias() const { return alias_set()?d_symbol_alias:symbol_name(); } /*! * Returns the block's alias as PMT. */ - pmt::pmt_t alias_pmt(){ return pmt::intern(alias()); } + pmt::pmt_t alias_pmt() const { return pmt::intern(alias()); } /*! * Set's a new alias for the block; also adds an entry into the diff --git a/gnuradio-runtime/include/gnuradio/block.h b/gnuradio-runtime/include/gnuradio/block.h index 82cd5b8512..e2b35309dc 100644 --- a/gnuradio-runtime/include/gnuradio/block.h +++ b/gnuradio-runtime/include/gnuradio/block.h @@ -23,10 +23,16 @@ #ifndef INCLUDED_GR_RUNTIME_BLOCK_H #define INCLUDED_GR_RUNTIME_BLOCK_H +#include <gnuradio/config.h> #include <gnuradio/api.h> #include <gnuradio/basic_block.h> #include <gnuradio/tags.h> #include <gnuradio/logger.h> +#ifdef GR_MPLIB_MPIR +#include <mpirxx.h> +#else +#include <gmpxx.h> +#endif namespace gr { @@ -281,10 +287,51 @@ namespace gr { void set_relative_rate(double relative_rate); /*! + * \brief Set the approximate output rate / input rate + * using its reciprocal + * + * This is a convenience function to avoid + * numerical problems with tag propagation that calling + * set_relative_rate(1.0/relative_rate) might introduce. + */ + void set_inverse_relative_rate(double inverse_relative_rate); + + /*! + * \brief Set the approximate output rate / input rate as an integer ratio + * + * Provide a hint to the buffer allocator and scheduler. + * The default relative_rate is interpolation / decimation = 1 / 1 + * + * decimators have relative_rates < 1.0 + * interpolators have relative_rates > 1.0 + */ + void set_relative_rate(uint64_t interpolation, uint64_t decimation); + + /*! * \brief return the approximate output rate / input rate */ double relative_rate() const { return d_relative_rate; } + /*! + * \brief return the numerator, or interpolation rate, of the + * approximate output rate / input rate + */ + uint64_t relative_rate_i() const { + return (uint64_t) d_mp_relative_rate.get_num().get_ui(); } + + /*! + * \brief return the denominator, or decimation rate, of the + * approximate output rate / input rate + */ + uint64_t relative_rate_d() const { + return (uint64_t) d_mp_relative_rate.get_den().get_ui(); } + + /*! + * \brief return a reference to the multiple precision rational + * represntation of the approximate output rate / input rate + */ + mpq_class &mp_relative_rate() { return d_mp_relative_rate; } + /* * The following two methods provide special case info to the * scheduler in the event that a block has a fixed input to output @@ -694,6 +741,7 @@ namespace gr { int d_unaligned; bool d_is_unaligned; double d_relative_rate; // approx output_rate / input_rate + mpq_class d_mp_relative_rate; block_detail_sptr d_detail; // implementation details unsigned d_history; unsigned d_attr_delay; // the block's sample delay @@ -885,6 +933,14 @@ namespace gr { // These are really only for internal use, but leaving them public avoids // having to work up an ever-varying list of friend GR_RUNTIME_APIs + /*! PMT Symbol for "hey, we're done here" + */ + const pmt::pmt_t d_pmt_done; + + /*! PMT Symbol of the system port, `pmt::mp("system")` + */ + const pmt::pmt_t d_system_port; + public: block_detail_sptr detail() const { return d_detail; } void set_detail(block_detail_sptr detail) { d_detail = detail; } diff --git a/gnuradio-runtime/include/gnuradio/block_gateway.h b/gnuradio-runtime/include/gnuradio/block_gateway.h index ef218ea662..28589f8f9f 100644 --- a/gnuradio-runtime/include/gnuradio/block_gateway.h +++ b/gnuradio-runtime/include/gnuradio/block_gateway.h @@ -177,10 +177,26 @@ namespace gr { return gr::block::set_relative_rate(relative_rate); } + void block__set_inverse_relative_rate(double inverse_relative_rate) { + return gr::block::set_inverse_relative_rate(inverse_relative_rate); + } + + void block__set_relative_rate(uint64_t interpolation, uint64_t decimation) { + return gr::block::set_relative_rate(interpolation, decimation); + } + double block__relative_rate(void) const { return gr::block::relative_rate(); } + uint64_t block__relative_rate_i(void) const { + return gr::block::relative_rate_i(); + } + + uint64_t block__relative_rate_d(void) const { + return gr::block::relative_rate_d(); + } + uint64_t block__nitems_read(unsigned int which_input) { return gr::block::nitems_read(which_input); } diff --git a/gnuradio-runtime/include/gnuradio/gr_complex.h b/gnuradio-runtime/include/gnuradio/gr_complex.h index bd94c0f0f8..807f208b41 100644 --- a/gnuradio-runtime/include/gnuradio/gr_complex.h +++ b/gnuradio-runtime/include/gnuradio/gr_complex.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -35,11 +35,5 @@ inline bool is_complex (int x) { (void) x; return false;} inline bool is_complex (char x) { (void) x; return false;} inline bool is_complex (short x) { (void) x; return false;} -// this doesn't really belong here, but there are worse places for it... - -#define CPPUNIT_ASSERT_COMPLEXES_EQUAL(expected,actual,delta) \ - CPPUNIT_ASSERT_DOUBLES_EQUAL (expected.real(), actual.real(), delta); \ - CPPUNIT_ASSERT_DOUBLES_EQUAL (expected.imag(), actual.imag(), delta); - #endif /* INCLUDED_GR_COMPLEX_H */ diff --git a/gnuradio-runtime/include/gnuradio/logger.h b/gnuradio-runtime/include/gnuradio/logger.h index 3cfa471a00..12585159be 100644 --- a/gnuradio-runtime/include/gnuradio/logger.h +++ b/gnuradio-runtime/include/gnuradio/logger.h @@ -562,7 +562,7 @@ namespace gr { { private: /*! \brief logger pointer to logger associated wiith this wrapper class */ - logger_ptr d_logger; + GR_LOG_DECLARE_LOGPTR(d_logger); public: /*! * \brief constructor Provide name of logger to associate with this class diff --git a/gnuradio-runtime/include/gnuradio/py_feval.h b/gnuradio-runtime/include/gnuradio/py_feval.h index cef168c8f0..89491af0b4 100644 --- a/gnuradio-runtime/include/gnuradio/py_feval.h +++ b/gnuradio-runtime/include/gnuradio/py_feval.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_PY_FEVAL_H #define INCLUDED_GR_PY_FEVAL_H +#include <Python.h> #include <pmt/pmt.h> #include <gnuradio/feval.h> diff --git a/gnuradio-runtime/include/gnuradio/sync_decimator.h b/gnuradio-runtime/include/gnuradio/sync_decimator.h index 129abdca79..f6306f169a 100644 --- a/gnuradio-runtime/include/gnuradio/sync_decimator.h +++ b/gnuradio-runtime/include/gnuradio/sync_decimator.h @@ -51,7 +51,7 @@ namespace gr { void set_decimation(unsigned decimation) { d_decimation = decimation; - set_relative_rate(1.0 / decimation); + set_relative_rate(1, (uint64_t) decimation); } // gr::sync_decimator overrides these to assist work diff --git a/gnuradio-runtime/include/gnuradio/sync_interpolator.h b/gnuradio-runtime/include/gnuradio/sync_interpolator.h index bfe79f902e..58351a51ea 100644 --- a/gnuradio-runtime/include/gnuradio/sync_interpolator.h +++ b/gnuradio-runtime/include/gnuradio/sync_interpolator.h @@ -51,7 +51,7 @@ namespace gr { void set_interpolation(unsigned interpolation) { d_interpolation = interpolation; - set_relative_rate(1.0 * interpolation); + set_relative_rate((uint64_t) interpolation, 1); set_output_multiple(interpolation); } diff --git a/gnuradio-runtime/include/gnuradio/xoroshiro128p.h b/gnuradio-runtime/include/gnuradio/xoroshiro128p.h new file mode 100644 index 0000000000..b3e6dcb12d --- /dev/null +++ b/gnuradio-runtime/include/gnuradio/xoroshiro128p.h @@ -0,0 +1,103 @@ +/* + * Copyright 2018 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +// Built on XOROSHIRO128+ by David Blackman and Sebastiano Vigna who put this +// under CC-0, colloquially known as "public domain (or as close you get to that +// in your local legislation)" see +// http://xoroshiro.di.unimi.it/xoroshiro128plus.c +// Conversion to a local state (original used global state) done by Marcus +// Müller, 2018. +#ifndef INCLUDED_XOROSHIRO128P_H +#define INCLUDED_XOROSHIRO128P_H +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +/*! \brief rotating left shift helper + * According to the original authors, this will on most platforms reduce to a single instruction + */ +static inline uint64_t rotl(const uint64_t x, const int k) { + return (x << k) | (x >> (64 - k)); +} + + +/*! \brief generate the next random number and update the state. + * This is the workhorse, here! + */ +static inline uint64_t xoroshiro128p_next(uint64_t *state) { + const uint64_t s0 = state[0]; + uint64_t s1 = state[1]; + const uint64_t result = s0 + s1; + + s1 ^= s0; + state[0] = rotl(s0, 55) ^ s1 ^ (s1 << 14); // a, b + state[1] = rotl(s1, 36); // c + + return result; +} + + +/*! \brief Advance the internal state by 2^64 steps; useful when coordinating multiple independent RNGs + This is the jump function for the generator. It is equivalent + to 2^64 calls to next(); it can be used to generate 2^64 + non-overlapping subsequences for parallel computations. */ +static inline void xoroshiro128p_jump(uint64_t *state) { + static const uint64_t JUMP[] = { 0xbeac0467eba5facb, 0xd86b048b86aa9922 }; + + uint64_t s0 = 0; + uint64_t s1 = 0; + for(unsigned int i = 0; i < sizeof (JUMP) / sizeof (*JUMP); ++i) { + for(unsigned int b = 0; b < 64; ++b) { + if (JUMP[i] & UINT64_C(1) << b) { + s0 ^= state[0]; + s1 ^= state[1]; + } + xoroshiro128p_next(state); + } + } + + state[0] = s0; + state[1] = s1; +} + +/*! \brief step of the SPLITMIX64 RNG; only used internally for seeding + * This RNG isn't as good as XOROSHIRO128+, so it's only used to initialize a 128 bit state from a seed. + */ +static inline uint64_t splitmix64_next(uint64_t *state) { + uint64_t z = (*state += 0x9e3779b97f4a7c15); + z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; + z = (z ^ (z >> 27)) * 0x94d049bb133111eb; + return z ^ (z >> 31); +} + +/*! \brief Seed the 128 bit state from a 64 bit seed + */ +static inline void xoroshiro128p_seed(uint64_t *state, const uint64_t seed) { + state[0] = seed; + state[1] = splitmix64_next(state); + xoroshiro128p_jump(state); +} +#ifdef __cplusplus +} +#endif +#endif // Include guard diff --git a/gnuradio-runtime/lib/CMakeLists.txt b/gnuradio-runtime/lib/CMakeLists.txt index 81b7efa766..58cd9866fa 100644 --- a/gnuradio-runtime/lib/CMakeLists.txt +++ b/gnuradio-runtime/lib/CMakeLists.txt @@ -51,6 +51,7 @@ include_directories(${GNURADIO_RUNTIME_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}/../include/ ${VOLK_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} + ${MPLIB_INCLUDE_DIRS} ) if(ENABLE_CTRLPORT_THRIFT) @@ -125,6 +126,7 @@ list(APPEND gnuradio_runtime_libs ${VOLK_LIBRARIES} ${Boost_LIBRARIES} ${LOG4CPP_LIBRARIES} + ${MPLIB_LIBRARIES} ) #Add libraries for winsock2.h on Windows @@ -136,7 +138,7 @@ IF(HAVE_WINDOWS_H) ENDIF(HAVE_WINDOWS_H) #need to link with librt on ubuntu 11.10 for shm_* -if(LINUX) +if((LINUX) OR (CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD")) list(APPEND gnuradio_runtime_libs rt) endif() @@ -227,40 +229,45 @@ endif(ENABLE_STATIC_LIBS) # Setup tests ######################################################################## if(ENABLE_TESTING) -include(GrTest) - -######################################################################## -# Append gnuradio-runtime test sources -######################################################################## -list(APPEND test_gnuradio_runtime_sources - math/qa_fxpt.cc - math/qa_fxpt_nco.cc - math/qa_fxpt_vco.cc - math/qa_math.cc - math/qa_sincos.cc - math/qa_fast_atan2f.cc - qa_buffer.cc - qa_io_signature.cc - qa_circular_file.cc - qa_logger.cc - qa_vmcircbuf.cc - qa_runtime.cc -) - -include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/math) -include_directories(${CPPUNIT_INCLUDE_DIRS}) -link_directories(${CPPUNIT_LIBRARY_DIRS}) - -add_library(test-gnuradio-runtime SHARED ${test_gnuradio_runtime_sources}) -target_link_libraries(test-gnuradio-runtime gnuradio-runtime gnuradio-pmt ${CPPUNIT_LIBRARIES} ${Boost_LIBRARIES} ${LOG4CPP_LIBRARIES}) + include(GrTest) + + # Regular runtime tests: + list(APPEND test_gnuradio_runtime_sources + qa_buffer.cc + qa_io_signature.cc + qa_circular_file.cc + qa_logger.cc + qa_vmcircbuf.cc + ) + list(APPEND GR_TEST_TARGET_DEPS gnuradio-runtime gnuradio-pmt) + + foreach(qa_file ${test_gnuradio_runtime_sources}) + GR_ADD_CPP_TEST("runtime_${qa_file}" + ${CMAKE_CURRENT_SOURCE_DIR}/${qa_file} + ) + endforeach(qa_file) + + # Math tests: + include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/math) + list(APPEND test_gnuradio_math_sources + qa_fxpt.cc + qa_fxpt_nco.cc + qa_fxpt_vco.cc + qa_math.cc + qa_sincos.cc + qa_fast_atan2f.cc + ) + + foreach(qa_file ${test_gnuradio_math_sources}) + GR_ADD_CPP_TEST("math_${qa_file}" + ${CMAKE_CURRENT_SOURCE_DIR}/math/${qa_file} + ) + endforeach(qa_file) -######################################################################## -# Build the test executable -# Set the test environment so the build libs will be found under MSVC. -######################################################################## -list(APPEND GR_TEST_TARGET_DEPS test-gnuradio-runtime) -add_executable(gr_runtime_test test_runtime.cc) -target_link_libraries(gr_runtime_test test-gnuradio-runtime) -GR_ADD_TEST(gr-runtime-test gr_runtime_test) + # PMT tests: + include_directories(${CMAKE_CURRENT_BINARY_DIR}/pmt) + GR_ADD_CPP_TEST("pmt_prims" ${CMAKE_CURRENT_SOURCE_DIR}/pmt/qa_pmt_prims.cc) + GR_ADD_CPP_TEST("pmt_unv" ${CMAKE_CURRENT_SOURCE_DIR}/pmt/qa_pmt_unv.cc) endif(ENABLE_TESTING) + diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc index e0cc0b6045..c86e792127 100644 --- a/gnuradio-runtime/lib/block.cc +++ b/gnuradio-runtime/lib/block.cc @@ -43,6 +43,7 @@ namespace gr { d_unaligned(0), d_is_unaligned(false), d_relative_rate (1.0), + d_mp_relative_rate(1.0), d_history(1), d_attr_delay(0), d_fixed_rate(false), @@ -54,11 +55,13 @@ namespace gr { d_pc_rpc_set(false), d_update_rate(false), d_max_output_buffer(std::max(output_signature->max_streams(),1), -1), - d_min_output_buffer(std::max(output_signature->max_streams(),1), -1) + d_min_output_buffer(std::max(output_signature->max_streams(),1), -1), + d_pmt_done(pmt::intern("done")), + d_system_port(pmt::intern("system")) { global_block_registry.register_primitive(alias(), this); - message_port_register_in(pmt::mp("system")); - set_msg_handler(pmt::mp("system"), boost::bind(&block::system_handler, this, _1)); + message_port_register_in(d_system_port); + set_msg_handler(d_system_port, boost::bind(&block::system_handler, this, _1)); configure_default_loggers(d_logger, d_debug_logger, symbol_name()); } @@ -170,10 +173,36 @@ namespace gr { void block::set_relative_rate(double relative_rate) { - if(relative_rate < 0.0) - throw std::invalid_argument("block::set_relative_rate"); + if(relative_rate <= 0.0) + throw std::invalid_argument("block::set_relative_rate: relative rate must be > 0.0"); d_relative_rate = relative_rate; + d_mp_relative_rate = mpq_class(relative_rate); + } + + void + block::set_inverse_relative_rate(double inverse_relative_rate) + { + if(inverse_relative_rate <= 0.0) + throw std::invalid_argument("block::set_inverse_relative_rate: inverse relative rate must be > 0.0"); + + mpq_class inv_rr_q(inverse_relative_rate); + set_relative_rate((uint64_t) inv_rr_q.get_den().get_ui(), + (uint64_t) inv_rr_q.get_num().get_ui()); + } + + void + block::set_relative_rate(uint64_t interpolation, uint64_t decimation) + { + if (interpolation < 1) + throw std::invalid_argument("block::set_relative_rate: interpolation rate cannot be 0"); + + if (decimation < 1) + throw std::invalid_argument("block::set_relative_rate: decimation rate cannot be 0"); + + d_mp_relative_rate = mpq_class(interpolation, decimation); + d_mp_relative_rate.canonicalize(); + d_relative_rate = d_mp_relative_rate.get_d(); } void @@ -706,8 +735,9 @@ namespace gr { { //std::cout << "system_handler " << msg << "\n"; pmt::pmt_t op = pmt::car(msg); - if(pmt::eqv(op, pmt::mp("done"))){ - d_finished = pmt::to_bool(pmt::cdr(msg)); + if(pmt::eqv(op, d_pmt_done)){ + d_finished = pmt::to_long(pmt::cdr(msg)); + global_block_registry.notify_blk(alias()); } else { std::cout << "WARNING: bad message op on system port!\n"; pmt::print(msg); @@ -746,16 +776,10 @@ namespace gr { pmt::pmt_t target = pmt::car(currlist); pmt::pmt_t block = pmt::car(target); - pmt::pmt_t port = pmt::mp("system"); currlist = pmt::cdr(currlist); basic_block_sptr blk = global_block_registry.block_lookup(block); - blk->post(port, pmt::cons(pmt::mp("done"), pmt::PMT_T)); - - //std::cout << "notify finished --> "; - //pmt::print(pmt::cons(block,port)); - //std::cout << "\n"; - + blk->post(d_system_port, pmt::cons(d_pmt_done, pmt::mp(true))); } } } diff --git a/gnuradio-runtime/lib/block_executor.cc b/gnuradio-runtime/lib/block_executor.cc index 754744449a..6152ff6765 100644 --- a/gnuradio-runtime/lib/block_executor.cc +++ b/gnuradio-runtime/lib/block_executor.cc @@ -94,8 +94,11 @@ namespace gr { static bool propagate_tags(block::tag_propagation_policy_t policy, block_detail *d, const std::vector<uint64_t> &start_nitems_read, double rrate, + mpq_class &mp_rrate, bool use_fp_rrate, std::vector<tag_t> &rtags, long block_id) { + static const mpq_class one_half(1, 2); + // Move tags downstream // if a sink, we don't need to move downstream if(d->sink_p()) { @@ -131,7 +134,7 @@ namespace gr { out_buf[o]->add_item_tag(*t); } } - else { + else if(use_fp_rrate) { for(t = rtags.begin(); t != rtags.end(); t++) { tag_t new_tag = *t; new_tag.offset = ((double)new_tag.offset * rrate) + 0.5; @@ -139,6 +142,16 @@ namespace gr { out_buf[o]->add_item_tag(new_tag); } } + else { + mpz_class offset; + for(t = rtags.begin(); t != rtags.end(); t++) { + tag_t new_tag = *t; + offset = new_tag.offset * mp_rrate + one_half; + new_tag.offset = offset.get_ui(); + for(int o = 0; o < d->noutputs(); o++) + out_buf[o]->add_item_tag(new_tag); + } + } } } break; @@ -159,10 +172,26 @@ namespace gr { out_buf = d->output(i); std::vector<tag_t>::iterator t; - for(t = rtags.begin(); t != rtags.end(); t++) { - tag_t new_tag = *t; - new_tag.offset = ((double)new_tag.offset * rrate) + 0.5; - out_buf->add_item_tag(new_tag); + if(rrate == 1.0) { + for(t = rtags.begin(); t != rtags.end(); t++) { + out_buf->add_item_tag(*t); + } + } + else if(use_fp_rrate) { + for(t = rtags.begin(); t != rtags.end(); t++) { + tag_t new_tag = *t; + new_tag.offset = ((double)new_tag.offset * rrate) + 0.5; + out_buf->add_item_tag(new_tag); + } + } + else { + mpz_class offset; + for(t = rtags.begin(); t != rtags.end(); t++) { + tag_t new_tag = *t; + offset = new_tag.offset * mp_rrate + one_half; + new_tag.offset = offset.get_ui(); + out_buf->add_item_tag(new_tag); + } } } } @@ -212,7 +241,6 @@ namespace gr { int max_noutput_items; int new_alignment = 0; int alignment_state = -1; - double rrate; block *m = d_block.get(); block_detail *d = m->detail().get(); @@ -321,10 +349,8 @@ namespace gr { noutput_items = min_available_space(d, m->output_multiple(), m->min_noutput_items()); if(ENABLE_LOGGING) { *d_log << " regular "; - if(m->relative_rate() >= 1.0) - *d_log << "1:" << m->relative_rate() << std::endl; - else - *d_log << 1.0/m->relative_rate() << ":1\n"; + *d_log << m->relative_rate_i() << ":" + << m->relative_rate_d() << std::endl; *d_log << " max_items_avail = " << max_items_avail << std::endl; *d_log << " noutput_items = " << noutput_items << std::endl; } @@ -490,6 +516,7 @@ namespace gr { // Now propagate the tags based on the new relative rate if(!propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read, m->relative_rate(), + m->mp_relative_rate(), m->update_rate(), d_returned_tags, m->unique_id())) goto were_done; @@ -505,9 +532,10 @@ namespace gr { // In the block constructor, use enable_update_rate(true). if(m->update_rate()) { //rrate = ((double)(m->nitems_written(0))) / ((double)m->nitems_read(0)); - rrate = (double)n / (double)d->consumed(); - if(rrate > 0) - m->set_relative_rate(rrate); + //if(rrate > 0.0) + // m->set_relative_rate(rrate); + if((n > 0) && (d->consumed() > 0)) + m->set_relative_rate((uint64_t)n, (uint64_t)d->consumed()); } if(d->d_produce_or > 0) // block produced something diff --git a/gnuradio-runtime/lib/logger.cc b/gnuradio-runtime/lib/logger.cc index 12b63354b1..064b74b3ed 100644 --- a/gnuradio-runtime/lib/logger.cc +++ b/gnuradio-runtime/lib/logger.cc @@ -347,12 +347,13 @@ namespace gr { GR_LOG_GETLOGGER(LOG, "gr_log." + name); GR_LOG_SET_LEVEL(LOG, log_level); + if(log_file.size() > 0) { if(log_file == "stdout") { - GR_LOG_SET_CONSOLE_APPENDER(LOG, "cout","gr::log :%p: %c{1} - %m%n"); + GR_LOG_SET_CONSOLE_APPENDER(LOG, "stdout","gr::log :%p: %c{1} - %m%n"); } else if(log_file == "stderr") { - GR_LOG_SET_CONSOLE_APPENDER(LOG, "cerr","gr::log :%p: %c{1} - %m%n"); + GR_LOG_SET_CONSOLE_APPENDER(LOG, "stderr","gr::log :%p: %c{1} - %m%n"); } else { GR_LOG_SET_FILE_APPENDER(LOG, log_file , true,"%r :%p: %c{1} - %m%n"); @@ -364,10 +365,10 @@ namespace gr { GR_LOG_SET_LEVEL(DLOG, debug_level); if(debug_file.size() > 0) { if(debug_file == "stdout") { - GR_LOG_SET_CONSOLE_APPENDER(DLOG, "cout","gr::debug :%p: %c{1} - %m%n"); + GR_LOG_SET_CONSOLE_APPENDER(DLOG, "stdout","gr::debug :%p: %c{1} - %m%n"); } else if(debug_file == "stderr") { - GR_LOG_SET_CONSOLE_APPENDER(DLOG, "cerr", "gr::debug :%p: %c{1} - %m%n"); + GR_LOG_SET_CONSOLE_APPENDER(DLOG, "stderr", "gr::debug :%p: %c{1} - %m%n"); } else { GR_LOG_SET_FILE_APPENDER(DLOG, debug_file, true, "%r :%p: %c{1} - %m%n"); @@ -388,11 +389,11 @@ namespace gr { if(log_file.size() > 0) { if(log_file == "stdout") { boost::format str("gr::log :%%p: %1% - %%m%%n"); - GR_LOG_SET_CONSOLE_APPENDER(LOG, "cout", boost::str(str % alias)); + GR_LOG_SET_CONSOLE_APPENDER(LOG, "stdout", boost::str(str % alias)); } else if(log_file == "stderr") { boost::format str("gr::log :%%p: %1% - %%m%%n"); - GR_LOG_SET_CONSOLE_APPENDER(LOG, "cerr", boost::str(str % alias)); + GR_LOG_SET_CONSOLE_APPENDER(LOG, "stderr", boost::str(str % alias)); } else { boost::format str("%%r :%%p: %1% - %%m%%n"); diff --git a/gnuradio-runtime/lib/math/qa_fast_atan2f.cc b/gnuradio-runtime/lib/math/qa_fast_atan2f.cc index 9584a578a1..423a8bc415 100644 --- a/gnuradio-runtime/lib/math/qa_fast_atan2f.cc +++ b/gnuradio-runtime/lib/math/qa_fast_atan2f.cc @@ -24,9 +24,8 @@ #include <config.h> #endif -#include <qa_fast_atan2f.h> #include <gnuradio/math.h> -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <cmath> #include <limits> @@ -36,9 +35,7 @@ #define ISNAN std::isnan #endif -void -qa_fast_atan2f::t1() -{ +BOOST_AUTO_TEST_CASE(t1) { static const unsigned int N = 100; float c_atan2; float gr_atan2f; @@ -51,14 +48,12 @@ qa_fast_atan2f::t1() gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0); + BOOST_CHECK_CLOSE(c_atan2, gr_atan2f, 0.0); } } } -void -qa_fast_atan2f::t2() -{ +BOOST_AUTO_TEST_CASE(t2) { float c_atan2; float gr_atan2f; float x, y; @@ -71,13 +66,13 @@ qa_fast_atan2f::t2() y = 0; c_atan2 = atan2(y, x); gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0); + BOOST_CHECK_CLOSE(c_atan2, gr_atan2f, 0.0); x = -inf; y = 0; c_atan2 = atan2(y, x); gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0); + BOOST_CHECK_CLOSE(c_atan2, gr_atan2f, 0.0); /* Test y as INF */ @@ -85,53 +80,53 @@ qa_fast_atan2f::t2() y = inf; c_atan2 = atan2(y, x); gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0); + BOOST_CHECK_CLOSE(c_atan2, gr_atan2f, 0.0); x = 0; y = -inf; c_atan2 = atan2(y, x); gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0); + BOOST_CHECK_CLOSE(c_atan2, gr_atan2f, 0.0); /* Test x and y as INF */ x = inf; y = inf; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT(ISNAN(gr_atan2f)); + BOOST_CHECK(ISNAN(gr_atan2f)); /* Test x as NAN */ x = nan; y = 0; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001); + BOOST_CHECK_CLOSE(0.0f, gr_atan2f, 0.0001); x = -nan; y = 0; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001); + BOOST_CHECK_CLOSE(0.0f, gr_atan2f, 0.0001); /* Test y as NAN */ x = 0; y = nan; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001); + BOOST_CHECK_CLOSE(0.0f, gr_atan2f, 0.0001); x = 0; y = -nan; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001); + BOOST_CHECK_CLOSE(0.0f, gr_atan2f, 0.0001); /* Test mixed NAN and INF */ x = inf; y = nan; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT(ISNAN(gr_atan2f)); + BOOST_CHECK(ISNAN(gr_atan2f)); x = nan; y = inf; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT(ISNAN(gr_atan2f)); + BOOST_CHECK(ISNAN(gr_atan2f)); } diff --git a/gnuradio-runtime/lib/math/qa_fast_atan2f.h b/gnuradio-runtime/lib/math/qa_fast_atan2f.h deleted file mode 100644 index d72ad671d7..0000000000 --- a/gnuradio-runtime/lib/math/qa_fast_atan2f.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef _QA_FAST_ATAN2F_H_ -#define _QA_FAST_ATAN2F_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_fast_atan2f : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_fast_atan2f); - CPPUNIT_TEST(t1); - CPPUNIT_TEST(t2); - CPPUNIT_TEST_SUITE_END(); - -private: - void t1(); - void t2(); -}; - -#endif /* _QA_FAST_ATAN2F_H_ */ diff --git a/gnuradio-runtime/lib/math/qa_fxpt.cc b/gnuradio-runtime/lib/math/qa_fxpt.cc index 5b045a69a1..5073df6e39 100644 --- a/gnuradio-runtime/lib/math/qa_fxpt.cc +++ b/gnuradio-runtime/lib/math/qa_fxpt.cc @@ -24,10 +24,8 @@ #include <config.h> #endif -#include <qa_fxpt.h> #include <gnuradio/fxpt.h> -#include <gnuradio/math.h> -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <iostream> #include <stdio.h> #include <unistd.h> @@ -35,12 +33,10 @@ static const float SIN_COS_TOLERANCE = 1e-5; -void -qa_fxpt::t0() -{ - CPPUNIT_ASSERT_DOUBLES_EQUAL(GR_M_PI/2, gr::fxpt::fixed_to_float(0x40000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gr::fxpt::fixed_to_float(0x00000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-GR_M_PI, gr::fxpt::fixed_to_float(0x80000000), SIN_COS_TOLERANCE); +BOOST_AUTO_TEST_CASE(t0) { + BOOST_CHECK(std::abs(GR_M_PI/2 - gr::fxpt::fixed_to_float(0x40000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(0.0 - gr::fxpt::fixed_to_float(0x00000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(-GR_M_PI - gr::fxpt::fixed_to_float(0x80000000)) <= SIN_COS_TOLERANCE); if(0) { /* @@ -52,52 +48,46 @@ qa_fxpt::t0() * sometimes the answer is off by a few bits at the bottom. * Hence, the disabled check. */ - CPPUNIT_ASSERT_EQUAL((int32_t)0x40000000, gr::fxpt::float_to_fixed(GR_M_PI/2)); - CPPUNIT_ASSERT_EQUAL((int32_t)0, gr::fxpt::float_to_fixed(0)); - CPPUNIT_ASSERT_EQUAL((int32_t)0x80000000, gr::fxpt::float_to_fixed(-GR_M_PI)); + BOOST_CHECK_EQUAL((int32_t)0x40000000, gr::fxpt::float_to_fixed(GR_M_PI/2)); + BOOST_CHECK_EQUAL((int32_t)0, gr::fxpt::float_to_fixed(0)); + BOOST_CHECK_EQUAL((int32_t)0x80000000, gr::fxpt::float_to_fixed(-GR_M_PI)); } } -void -qa_fxpt::t1() -{ - CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, gr::fxpt::sin(0x00000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.707106781, gr::fxpt::sin(0x20000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 1, gr::fxpt::sin(0x40000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.707106781, gr::fxpt::sin(0x60000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, gr::fxpt::sin(0x7fffffff), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, gr::fxpt::sin(0x80000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, gr::fxpt::sin(0x80000001), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-1, gr::fxpt::sin(-0x40000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.707106781, gr::fxpt::sin(-0x20000000), SIN_COS_TOLERANCE); +BOOST_AUTO_TEST_CASE(t1) { + BOOST_CHECK(std::abs( 0 - gr::fxpt::sin(0x00000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs( 0.707106781 - gr::fxpt::sin(0x20000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs( 1 - gr::fxpt::sin(0x40000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs( 0.707106781 - gr::fxpt::sin(0x60000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs( 0 - gr::fxpt::sin(0x7fffffff)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs( 0 - gr::fxpt::sin(0x80000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs( 0 - gr::fxpt::sin(0x80000001)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(-1 - gr::fxpt::sin(-0x40000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(-0.707106781 - gr::fxpt::sin(-0x20000000)) <= SIN_COS_TOLERANCE); for(float p = -GR_M_PI; p < GR_M_PI; p += 2 * GR_M_PI / 3600) { float expected = sin(p); float actual = gr::fxpt::sin(gr::fxpt::float_to_fixed (p)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(expected - actual) <= SIN_COS_TOLERANCE); } } -void -qa_fxpt::t2() -{ +BOOST_AUTO_TEST_CASE(t2) { for(float p = -GR_M_PI; p < GR_M_PI; p += 2 * GR_M_PI / 3600) { float expected = cos(p); float actual = gr::fxpt::cos(gr::fxpt::float_to_fixed(p)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(expected - actual) <= SIN_COS_TOLERANCE); } } -void -qa_fxpt::t3() -{ +BOOST_AUTO_TEST_CASE(t3) { for(float p = -GR_M_PI; p < GR_M_PI; p += 2 * GR_M_PI / 3600) { float expected_sin = sin(p); float expected_cos = cos(p); float actual_sin; float actual_cos; gr::fxpt::sincos(gr::fxpt::float_to_fixed (p), &actual_sin, &actual_cos); - CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_sin, actual_sin, SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_cos, actual_cos, SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(expected_sin - actual_sin) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(expected_cos - actual_cos) <= SIN_COS_TOLERANCE); } } diff --git a/gnuradio-runtime/lib/math/qa_fxpt.h b/gnuradio-runtime/lib/math/qa_fxpt.h deleted file mode 100644 index 58a6f02d1b..0000000000 --- a/gnuradio-runtime/lib/math/qa_fxpt.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_QA_GR_FXPT_H -#define INCLUDED_QA_GR_FXPT_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_fxpt : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_fxpt); - CPPUNIT_TEST(t0); - CPPUNIT_TEST(t1); - CPPUNIT_TEST(t2); - CPPUNIT_TEST(t3); - CPPUNIT_TEST_SUITE_END(); - - private: - void t0(); - void t1(); - void t2(); - void t3(); -}; - -#endif /* INCLUDED_QA_GR_FXPT_H */ - - diff --git a/gnuradio-runtime/lib/math/qa_fxpt_nco.cc b/gnuradio-runtime/lib/math/qa_fxpt_nco.cc index 0b1ef16dd9..da10f49c92 100644 --- a/gnuradio-runtime/lib/math/qa_fxpt_nco.cc +++ b/gnuradio-runtime/lib/math/qa_fxpt_nco.cc @@ -24,12 +24,9 @@ #include <config.h> #endif -#include <qa_fxpt_nco.h> #include <gnuradio/fxpt_nco.h> #include <gnuradio/nco.h> -#include <gnuradio/math.h> - -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <iostream> #include <stdio.h> #include <unistd.h> @@ -47,9 +44,8 @@ static double max_d(double a, double b) return fabs(a) > fabs(b) ? a : b; } -void -qa_fxpt_nco::t0() -{ + +BOOST_AUTO_TEST_CASE(t0) { gr::nco<float,float> ref_nco; gr::fxpt_nco new_nco; double max_error = 0, max_phase_error = 0; @@ -57,35 +53,33 @@ qa_fxpt_nco::t0() ref_nco.set_freq((float)(2 * GR_M_PI / SIN_COS_FREQ)); new_nco.set_freq((float)(2 * GR_M_PI / SIN_COS_FREQ)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_nco.get_freq(), new_nco.get_freq(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_nco.get_freq() - new_nco.get_freq()) <= SIN_COS_TOLERANCE); for(int i = 0; i < SIN_COS_BLOCK_SIZE; i++) { float ref_sin = ref_nco.sin(); float new_sin = new_nco.sin(); //printf ("i = %6d\n", i); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_sin, new_sin, SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_sin - new_sin) <= SIN_COS_TOLERANCE); max_error = max_d(max_error, ref_sin-new_sin); float ref_cos = ref_nco.cos(); float new_cos = new_nco.cos(); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_cos, new_cos, SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_cos - new_cos) <= SIN_COS_TOLERANCE); max_error = max_d(max_error, ref_cos-new_cos); ref_nco.step(); new_nco.step(); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_nco.get_phase(), new_nco.get_phase(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_nco.get_phase() - new_nco.get_phase()) <= SIN_COS_TOLERANCE); max_phase_error = max_d(max_phase_error, ref_nco.get_phase()-new_nco.get_phase()); } // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, max_phase_error); } -void -qa_fxpt_nco::t1() -{ +BOOST_AUTO_TEST_CASE(t1) { gr::nco<float,float> ref_nco; gr::fxpt_nco new_nco; gr_complex* ref_block = new gr_complex[SIN_COS_BLOCK_SIZE]; @@ -95,30 +89,21 @@ qa_fxpt_nco::t1() ref_nco.set_freq((float)(2 * GR_M_PI / SIN_COS_FREQ)); new_nco.set_freq((float)(2 * GR_M_PI / SIN_COS_FREQ)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_nco.get_freq(), new_nco.get_freq(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_nco.get_freq() - new_nco.get_freq()) <= SIN_COS_TOLERANCE); ref_nco.sincos((gr_complex*)ref_block, SIN_COS_BLOCK_SIZE); new_nco.sincos((gr_complex*)new_block, SIN_COS_BLOCK_SIZE); for(int i = 0; i < SIN_COS_BLOCK_SIZE; i++) { - CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_block[i].real(), new_block[i].real(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_block[i].real() - new_block[i].real()) <= SIN_COS_TOLERANCE); max_error = max_d (max_error, ref_block[i].real()-new_block[i].real()); - CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_block[i].imag(), new_block[i].imag(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_block[i].imag() - new_block[i].imag()) <= SIN_COS_TOLERANCE); max_error = max_d (max_error, ref_block[i].imag()-new_block[i].imag()); } - CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_nco.get_phase(), new_nco.get_phase(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_nco.get_phase() - new_nco.get_phase()) <= SIN_COS_TOLERANCE); // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, max_phase_error); delete[] ref_block; delete[] new_block; } -void -qa_fxpt_nco::t2() -{ -} - -void -qa_fxpt_nco::t3() -{ -} diff --git a/gnuradio-runtime/lib/math/qa_fxpt_nco.h b/gnuradio-runtime/lib/math/qa_fxpt_nco.h deleted file mode 100644 index 1b2cdaede6..0000000000 --- a/gnuradio-runtime/lib/math/qa_fxpt_nco.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_QA_GR_FXPT_NCO_H -#define INCLUDED_QA_GR_FXPT_NCO_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_fxpt_nco : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_fxpt_nco); - CPPUNIT_TEST(t0); - CPPUNIT_TEST(t1); - CPPUNIT_TEST(t2); - CPPUNIT_TEST(t3); - CPPUNIT_TEST_SUITE_END(); - -private: - void t0(); - void t1(); - void t2(); - void t3(); -}; - -#endif /* INCLUDED_QA_GR_FXPT_NCO_H */ - - diff --git a/gnuradio-runtime/lib/math/qa_fxpt_vco.cc b/gnuradio-runtime/lib/math/qa_fxpt_vco.cc index a406c12c0f..d4952fe25c 100644 --- a/gnuradio-runtime/lib/math/qa_fxpt_vco.cc +++ b/gnuradio-runtime/lib/math/qa_fxpt_vco.cc @@ -24,10 +24,9 @@ #include <config.h> #endif -#include <qa_fxpt_vco.h> +#include "vco.h" #include <gnuradio/fxpt_vco.h> -#include <vco.h> -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <iostream> #include <stdio.h> #include <unistd.h> @@ -45,9 +44,7 @@ static double max_d(double a, double b) return fabs(a) > fabs(b) ? a : b; } -void -qa_fxpt_vco::t0() -{ +BOOST_AUTO_TEST_CASE(t0) { gr::vco<float,float> ref_vco; gr::fxpt_vco new_vco; double max_error = 0, max_phase_error = 0; @@ -60,23 +57,21 @@ qa_fxpt_vco::t0() for(int i = 0; i < SIN_COS_BLOCK_SIZE; i++) { float ref_cos = ref_vco.cos(); float new_cos = new_vco.cos(); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_cos, new_cos, SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_cos - new_cos) <= SIN_COS_TOLERANCE); max_error = max_d(max_error, ref_cos-new_cos); ref_vco.adjust_phase(input[i]); new_vco.adjust_phase(input[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_vco.get_phase(), new_vco.get_phase(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_vco.get_phase() - new_vco.get_phase()) <= SIN_COS_TOLERANCE); max_phase_error = max_d(max_phase_error, ref_vco.get_phase()-new_vco.get_phase()); } // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, max_phase_error); } -void -qa_fxpt_vco::t1() -{ +BOOST_AUTO_TEST_CASE(t1) { gr::vco<float,float> ref_vco; gr::fxpt_vco new_vco; float *ref_block = new float[SIN_COS_BLOCK_SIZE]; @@ -92,19 +87,18 @@ qa_fxpt_vco::t1() new_vco.cos(new_block, input, SIN_COS_BLOCK_SIZE, SIN_COS_K, SIN_COS_AMPL); for(int i = 0; i < SIN_COS_BLOCK_SIZE; i++) { - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_block[i], new_block[i], SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_block[i] - new_block[i]) <= SIN_COS_TOLERANCE); max_error = max_d(max_error, ref_block[i]-new_block[i]); } - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_vco.get_phase(), new_vco.get_phase(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_vco.get_phase() - new_vco.get_phase()) <= SIN_COS_TOLERANCE); // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, ref_vco.get_phase()-new_vco.get_phase()); delete[] ref_block; delete[] new_block; delete[] input; } -void -qa_fxpt_vco::t2() -{ + +BOOST_AUTO_TEST_CASE(t2) { gr::vco<gr_complex,float> ref_vco; gr::fxpt_vco new_vco; gr_complex *ref_block = new gr_complex[SIN_COS_BLOCK_SIZE]; @@ -120,17 +114,15 @@ qa_fxpt_vco::t2() new_vco.sincos(new_block, input, SIN_COS_BLOCK_SIZE, SIN_COS_K, SIN_COS_AMPL); for(int i = 0; i < SIN_COS_BLOCK_SIZE; i++) { - CPPUNIT_ASSERT_COMPLEXES_EQUAL(ref_block[i], new_block[i], SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_block[i] - new_block[i]) <= SIN_COS_TOLERANCE); max_error = max_d(max_error, abs(ref_block[i]-new_block[i])); } - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_vco.get_phase(), new_vco.get_phase(), SIN_COS_TOLERANCE); + BOOST_CHECK( + std::abs(ref_vco.get_phase() - new_vco.get_phase()) <= SIN_COS_TOLERANCE + ); // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, ref_vco.get_phase()-new_vco.get_phase()); delete[] ref_block; delete[] new_block; delete[] input; } -void -qa_fxpt_vco::t3() -{ -} diff --git a/gnuradio-runtime/lib/math/qa_fxpt_vco.h b/gnuradio-runtime/lib/math/qa_fxpt_vco.h deleted file mode 100644 index 72693f32e2..0000000000 --- a/gnuradio-runtime/lib/math/qa_fxpt_vco.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2005,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_QA_GR_FXPT_VCO_H -#define INCLUDED_QA_GR_FXPT_VCO_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_fxpt_vco : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_fxpt_vco); - CPPUNIT_TEST(t0); - CPPUNIT_TEST(t1); - CPPUNIT_TEST(t2); - CPPUNIT_TEST(t3); - CPPUNIT_TEST_SUITE_END(); - -private: - void t0(); - void t1(); - void t2(); - void t3(); -}; - -#endif /* INCLUDED_QA_GR_FXPT_VCO_H */ - - diff --git a/gnuradio-runtime/lib/math/qa_math.cc b/gnuradio-runtime/lib/math/qa_math.cc index 1fb43cc67f..da8322059c 100644 --- a/gnuradio-runtime/lib/math/qa_math.cc +++ b/gnuradio-runtime/lib/math/qa_math.cc @@ -20,13 +20,11 @@ */ #include <gnuradio/math.h> -#include <qa_math.h> -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <stdio.h> +#include <cmath> -void -qa_math::test_binary_slicer1() -{ +BOOST_AUTO_TEST_CASE(test_binary_slicer1) { float x[5] = {-1, -0.5, 0, 0.5, 1.0}; unsigned int z[5] = {0, 0, 1, 1, 1}; unsigned int y; @@ -36,7 +34,7 @@ qa_math::test_binary_slicer1() y = gr::binary_slicer(x[i]); //printf("in: %f out: %d desired: %d\n", x[i], y, z[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9); + BOOST_CHECK_EQUAL(y, z[i]); } //printf("\nBranchless Binary\n"); @@ -44,13 +42,11 @@ qa_math::test_binary_slicer1() y = gr::branchless_binary_slicer(x[i]); //printf("in: %f out: %d desired: %d\n", x[i], y, z[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9); + BOOST_CHECK_EQUAL(y, z[i]); } } -void -qa_math::test_quad_0deg_slicer1() -{ +BOOST_AUTO_TEST_CASE(test_quad_0deg_slicer1) { gr_complex x[4] = {gr_complex(1, 0), gr_complex(0, 1), gr_complex(-1, 0), @@ -64,7 +60,7 @@ qa_math::test_quad_0deg_slicer1() y = gr::quad_0deg_slicer(x[i]); //printf("in: %.4f+j%.4f out: %d desired: %d\n", x[i].real(), x[i].imag(), y, z[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9); + BOOST_CHECK_EQUAL(y, z[i]); } //printf("\nBranchless Quad0\n"); @@ -72,13 +68,11 @@ qa_math::test_quad_0deg_slicer1() y = gr::branchless_quad_0deg_slicer(x[i]); //printf("in: %.4f+j%.4f out: %d desired: %d\n", x[i].real(), x[i].imag(), y, z[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9); + BOOST_CHECK_EQUAL(y, z[i]); } } -void -qa_math::test_quad_45deg_slicer1() -{ +BOOST_AUTO_TEST_CASE(test_quad_45deg_slicer1) { gr_complex x[4] = {gr_complex(0.707, 0.707), gr_complex(-0.707, 0.707), gr_complex(-0.707, -0.707), @@ -92,7 +86,7 @@ qa_math::test_quad_45deg_slicer1() y = gr::quad_45deg_slicer(x[i]); //printf("in: %.4f+j%.4f out: %d desired: %d\n", x[i].real(), x[i].imag(), y, z[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9); + BOOST_CHECK_EQUAL(y, z[i]); } //printf("\nBranchless Quad45\n"); @@ -100,6 +94,6 @@ qa_math::test_quad_45deg_slicer1() y = gr::branchless_quad_45deg_slicer(x[i]); //printf("in: %.4f+j%.4f out: %d desired: %d\n", x[i].real(), x[i].imag(), y, z[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9); + BOOST_CHECK_EQUAL(y, z[i]); } } diff --git a/gnuradio-runtime/lib/math/qa_math.h b/gnuradio-runtime/lib/math/qa_math.h deleted file mode 100644 index 3621283b37..0000000000 --- a/gnuradio-runtime/lib/math/qa_math.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ -#ifndef _QA_GR_MATH_H_ -#define _QA_GR_MATH_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_math : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_math); - CPPUNIT_TEST(test_binary_slicer1); - CPPUNIT_TEST(test_quad_0deg_slicer1); - CPPUNIT_TEST(test_quad_45deg_slicer1); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_binary_slicer1(); - void test_quad_0deg_slicer1(); - void test_quad_45deg_slicer1(); -}; - -#endif /* _QA_GR_MATH_H_ */ diff --git a/gnuradio-runtime/lib/math/qa_sincos.cc b/gnuradio-runtime/lib/math/qa_sincos.cc index a6234d19d6..4ce81fb4f8 100644 --- a/gnuradio-runtime/lib/math/qa_sincos.cc +++ b/gnuradio-runtime/lib/math/qa_sincos.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2012 Free Software Foundation, Inc. + * Copyright 2012,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,14 +24,11 @@ #include <config.h> #endif -#include <qa_sincos.h> #include <gnuradio/sincos.h> -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <cmath> -void -qa_sincos::t1() -{ +BOOST_AUTO_TEST_CASE(t1) { static const unsigned int N = 1000; double c_sin, c_cos; double gr_sin, gr_cos; @@ -43,14 +40,12 @@ qa_sincos::t1() gr::sincos(x, &gr_sin, &gr_cos); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_sin, gr_sin, 0.0001); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_cos, gr_cos, 0.0001); + BOOST_CHECK_CLOSE(c_sin, gr_sin, 0.0001); + BOOST_CHECK_CLOSE(c_cos, gr_cos, 0.0001); } } -void -qa_sincos::t2() -{ +BOOST_AUTO_TEST_CASE(t2) { static const unsigned int N = 1000; float c_sin, c_cos; float gr_sin, gr_cos; @@ -62,7 +57,7 @@ qa_sincos::t2() gr::sincosf(x, &gr_sin, &gr_cos); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_sin, gr_sin, 0.0001); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_cos, gr_cos, 0.0001); + BOOST_CHECK_CLOSE(c_sin, gr_sin, 0.0001); + BOOST_CHECK_CLOSE(c_cos, gr_cos, 0.0001); } } diff --git a/gnuradio-runtime/lib/math/qa_sincos.h b/gnuradio-runtime/lib/math/qa_sincos.h deleted file mode 100644 index 9fec5958c0..0000000000 --- a/gnuradio-runtime/lib/math/qa_sincos.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef _QA_SINCOS_H_ -#define _QA_SINCOS_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_sincos : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_sincos); - CPPUNIT_TEST(t1); - CPPUNIT_TEST(t2); - CPPUNIT_TEST_SUITE_END(); - -private: - void t1(); - void t2(); -}; - -#endif /* _QA_SINCOS_H_ */ diff --git a/gnuradio-runtime/lib/math/random.cc b/gnuradio-runtime/lib/math/random.cc index 152db77b78..6a509f1796 100644 --- a/gnuradio-runtime/lib/math/random.cc +++ b/gnuradio-runtime/lib/math/random.cc @@ -75,9 +75,12 @@ namespace gr { void random::reseed(unsigned int seed) { - if(seed==0) d_seed = static_cast<unsigned int>(std::time(0)); - else d_seed = seed; - d_rng->seed(d_seed); + d_seed = seed; + if (d_seed == 0){ + d_rng->seed(); + } else { + d_rng->seed(d_seed); + } // reinstantiate generators. Otherwise reseed doesn't take effect. delete d_generator; d_generator = new boost::variate_generator<boost::mt19937&, boost::uniform_real<float> > (*d_rng,*d_uniform); // create number generator in [0,1) from boost.random @@ -140,11 +143,12 @@ namespace gr { float random::laplacian() { - float z = ran1()-0.5; - if(z>0) return -logf(1-2*z); - else return logf(1+2*z); + float z = ran1(); + if (z > 0.5f){ + return -logf(2.0f * (1.0f - z) ); + } + return logf(2 * z); } - /* * Copied from The KC7WW / OH2BNS Channel Simulator * FIXME Need to check how good this is at some point diff --git a/gnuradio-runtime/lib/pmt/pmt.cc b/gnuradio-runtime/lib/pmt/pmt.cc index da2a7e5cc2..763007132f 100644 --- a/gnuradio-runtime/lib/pmt/pmt.cc +++ b/gnuradio-runtime/lib/pmt/pmt.cc @@ -1150,12 +1150,12 @@ equal(const pmt_t& x, const pmt_t& y) return false; size_t len_x, len_y; - if (memcmp(xv->uniform_elements(len_x), - yv->uniform_elements(len_y), - len_x) == 0) + const void *x_m = xv->uniform_elements(len_x); + const void *y_m = yv->uniform_elements(len_y); + if (memcmp(x_m, y_m, len_x) == 0) return true; - return true; + return false; } // FIXME add other cases here... diff --git a/gnuradio-runtime/lib/pmt/qa_pmt.cc b/gnuradio-runtime/lib/pmt/qa_pmt.cc deleted file mode 100644 index a87f97e570..0000000000 --- a/gnuradio-runtime/lib/pmt/qa_pmt.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2006 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -/* - * This class gathers together all the test cases for pmt into - * a single test suite. As you create new test cases, add them here. - */ - -#include <qa_pmt.h> -#include <qa_pmt_prims.h> -#include <qa_pmt_unv.h> - -CppUnit::TestSuite * -qa_pmt::suite() -{ - CppUnit::TestSuite *s = new CppUnit::TestSuite("pmt"); - - s->addTest(qa_pmt_prims::suite()); - s->addTest(qa_pmt_unv::suite()); - - return s; -} diff --git a/gnuradio-runtime/lib/pmt/qa_pmt.h b/gnuradio-runtime/lib/pmt/qa_pmt.h deleted file mode 100644 index 9293a076a6..0000000000 --- a/gnuradio-runtime/lib/pmt/qa_pmt.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_QA_PMT_H -#define INCLUDED_QA_PMT_H - -#include <gnuradio/attributes.h> -#include <cppunit/TestSuite.h> - -//! collect all the tests for pmt - -class __GR_ATTR_EXPORT qa_pmt { - public: - //! return suite of tests for all of pmt - static CppUnit::TestSuite *suite (); -}; - -#endif /* INCLUDED_QA_PMT_H */ diff --git a/gnuradio-runtime/lib/pmt/qa_pmt_prims.cc b/gnuradio-runtime/lib/pmt/qa_pmt_prims.cc index 2b3ca32293..356cf95203 100644 --- a/gnuradio-runtime/lib/pmt/qa_pmt_prims.cc +++ b/gnuradio-runtime/lib/pmt/qa_pmt_prims.cc @@ -20,32 +20,30 @@ * Boston, MA 02110-1301, USA. */ -#include <qa_pmt_prims.h> -#include <cppunit/TestAssert.h> +#include <pmt/api.h> //reason: suppress warnings #include <gnuradio/messages/msg_passing.h> +#include <boost/test/unit_test.hpp> #include <boost/format.hpp> #include <cstdio> #include <cstring> #include <sstream> -void -qa_pmt_prims::test_symbols() -{ - CPPUNIT_ASSERT(!pmt::is_symbol(pmt::PMT_T)); - CPPUNIT_ASSERT(!pmt::is_symbol(pmt::PMT_F)); - CPPUNIT_ASSERT_THROW(pmt::symbol_to_string(pmt::PMT_F), pmt::wrong_type); +BOOST_AUTO_TEST_CASE(test_symbols) { + BOOST_CHECK(!pmt::is_symbol(pmt::PMT_T)); + BOOST_CHECK(!pmt::is_symbol(pmt::PMT_F)); + BOOST_CHECK_THROW(pmt::symbol_to_string(pmt::PMT_F), pmt::wrong_type); pmt::pmt_t sym1 = pmt::mp("test"); - CPPUNIT_ASSERT(pmt::is_symbol(sym1)); - CPPUNIT_ASSERT_EQUAL(std::string("test"), pmt::symbol_to_string(sym1)); - CPPUNIT_ASSERT(pmt::is_true(sym1)); - CPPUNIT_ASSERT(!pmt::is_false(sym1)); + BOOST_CHECK(pmt::is_symbol(sym1)); + BOOST_CHECK_EQUAL(std::string("test"), pmt::symbol_to_string(sym1)); + BOOST_CHECK(pmt::is_true(sym1)); + BOOST_CHECK(!pmt::is_false(sym1)); pmt::pmt_t sym2 = pmt::mp("foo"); pmt::pmt_t sym3 = pmt::mp("test"); - CPPUNIT_ASSERT_EQUAL(sym1, sym3); - CPPUNIT_ASSERT(sym1 != sym2); - CPPUNIT_ASSERT(sym1 == sym3); + BOOST_CHECK_EQUAL(sym1, sym3); + BOOST_CHECK(sym1 != sym2); + BOOST_CHECK(sym1 == sym3); static const int N = 2048; std::vector<pmt::pmt_t> v1(N); @@ -60,7 +58,7 @@ qa_pmt_prims::test_symbols() // confirm that they are all unique for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) - CPPUNIT_ASSERT(v1[i] != v1[j]); + BOOST_CHECK(v1[i] != v1[j]); // generate the same symbols again for (int i = 0; i < N; i++){ @@ -70,141 +68,127 @@ qa_pmt_prims::test_symbols() // confirm that we get the same ones back for (int i = 0; i < N; i++) - CPPUNIT_ASSERT(v1[i] == v2[i]); + BOOST_CHECK(v1[i] == v2[i]); } -void -qa_pmt_prims::test_booleans() -{ +BOOST_AUTO_TEST_CASE(test_booleans) { pmt::pmt_t sym = pmt::mp("test"); - CPPUNIT_ASSERT(pmt::is_bool(pmt::PMT_T)); - CPPUNIT_ASSERT(pmt::is_bool(pmt::PMT_F)); - CPPUNIT_ASSERT(!pmt::is_bool(sym)); - CPPUNIT_ASSERT_EQUAL(pmt::from_bool(false), pmt::PMT_F); - CPPUNIT_ASSERT_EQUAL(pmt::from_bool(true), pmt::PMT_T); - CPPUNIT_ASSERT_EQUAL(false, pmt::to_bool(pmt::PMT_F)); - CPPUNIT_ASSERT_EQUAL(true, pmt::to_bool(pmt::PMT_T)); - CPPUNIT_ASSERT_THROW(pmt::to_bool(sym), pmt::wrong_type); + BOOST_CHECK(pmt::is_bool(pmt::PMT_T)); + BOOST_CHECK(pmt::is_bool(pmt::PMT_F)); + BOOST_CHECK(!pmt::is_bool(sym)); + BOOST_CHECK_EQUAL(pmt::from_bool(false), pmt::PMT_F); + BOOST_CHECK_EQUAL(pmt::from_bool(true), pmt::PMT_T); + BOOST_CHECK_EQUAL(false, pmt::to_bool(pmt::PMT_F)); + BOOST_CHECK_EQUAL(true, pmt::to_bool(pmt::PMT_T)); + BOOST_CHECK_THROW(pmt::to_bool(sym), pmt::wrong_type); } -void -qa_pmt_prims::test_integers() -{ +BOOST_AUTO_TEST_CASE(test_integers) { pmt::pmt_t p1 = pmt::from_long(1); pmt::pmt_t m1 = pmt::from_long(-1); - CPPUNIT_ASSERT(!pmt::is_integer(pmt::PMT_T)); - CPPUNIT_ASSERT(pmt::is_integer(p1)); - CPPUNIT_ASSERT(pmt::is_integer(m1)); - CPPUNIT_ASSERT_THROW(pmt::to_long(pmt::PMT_T), pmt::wrong_type); - CPPUNIT_ASSERT_EQUAL(-1L, pmt::to_long(m1)); - CPPUNIT_ASSERT_EQUAL(1L, pmt::to_long(p1)); + BOOST_CHECK(!pmt::is_integer(pmt::PMT_T)); + BOOST_CHECK(pmt::is_integer(p1)); + BOOST_CHECK(pmt::is_integer(m1)); + BOOST_CHECK_THROW(pmt::to_long(pmt::PMT_T), pmt::wrong_type); + BOOST_CHECK_EQUAL(-1L, pmt::to_long(m1)); + BOOST_CHECK_EQUAL(1L, pmt::to_long(p1)); } -void -qa_pmt_prims::test_uint64s() -{ +BOOST_AUTO_TEST_CASE(test_uint64s) { pmt::pmt_t p1 = pmt::from_uint64((uint64_t)1); pmt::pmt_t m1 = pmt::from_uint64((uint64_t)8589934592ULL); - CPPUNIT_ASSERT(!pmt::is_uint64(pmt::PMT_T)); - CPPUNIT_ASSERT(pmt::is_uint64(p1)); - CPPUNIT_ASSERT(pmt::is_uint64(m1)); - CPPUNIT_ASSERT_THROW(pmt::to_uint64(pmt::PMT_T), pmt::wrong_type); - CPPUNIT_ASSERT_EQUAL((uint64_t)8589934592ULL, (uint64_t)pmt::to_uint64(m1)); - CPPUNIT_ASSERT_EQUAL((uint64_t)1ULL, (uint64_t)pmt::to_uint64(p1)); + BOOST_CHECK(!pmt::is_uint64(pmt::PMT_T)); + BOOST_CHECK(pmt::is_uint64(p1)); + BOOST_CHECK(pmt::is_uint64(m1)); + BOOST_CHECK_THROW(pmt::to_uint64(pmt::PMT_T), pmt::wrong_type); + BOOST_CHECK_EQUAL((uint64_t)8589934592ULL, (uint64_t)pmt::to_uint64(m1)); + BOOST_CHECK_EQUAL((uint64_t)1ULL, (uint64_t)pmt::to_uint64(p1)); } -void -qa_pmt_prims::test_reals() -{ +BOOST_AUTO_TEST_CASE(test_reals) { pmt::pmt_t p1 = pmt::from_double(1); pmt::pmt_t m1 = pmt::from_double(-1); - CPPUNIT_ASSERT(!pmt::is_real(pmt::PMT_T)); - CPPUNIT_ASSERT(pmt::is_real(p1)); - CPPUNIT_ASSERT(pmt::is_real(m1)); - CPPUNIT_ASSERT_THROW(pmt::to_double(pmt::PMT_T), pmt::wrong_type); - CPPUNIT_ASSERT_EQUAL(-1.0, pmt::to_double(m1)); - CPPUNIT_ASSERT_EQUAL(1.0, pmt::to_double(p1)); - CPPUNIT_ASSERT_EQUAL(1.0, pmt::to_double(pmt::from_long(1))); + BOOST_CHECK(!pmt::is_real(pmt::PMT_T)); + BOOST_CHECK(pmt::is_real(p1)); + BOOST_CHECK(pmt::is_real(m1)); + BOOST_CHECK_THROW(pmt::to_double(pmt::PMT_T), pmt::wrong_type); + BOOST_CHECK_EQUAL(-1.0, pmt::to_double(m1)); + BOOST_CHECK_EQUAL(1.0, pmt::to_double(p1)); + BOOST_CHECK_EQUAL(1.0, pmt::to_double(pmt::from_long(1))); pmt::pmt_t p2 = pmt::from_float(1); pmt::pmt_t m2 = pmt::from_float(-1); - CPPUNIT_ASSERT(pmt::is_real(p2)); - CPPUNIT_ASSERT(pmt::is_real(m2)); - CPPUNIT_ASSERT_THROW(pmt::to_float(pmt::PMT_T), pmt::wrong_type); - CPPUNIT_ASSERT_EQUAL(float(-1.0), pmt::to_float(m2)); - CPPUNIT_ASSERT_EQUAL(float(1.0), pmt::to_float(p2)); - CPPUNIT_ASSERT_EQUAL(float(1.0), pmt::to_float(pmt::from_long(1))); + BOOST_CHECK(pmt::is_real(p2)); + BOOST_CHECK(pmt::is_real(m2)); + BOOST_CHECK_THROW(pmt::to_float(pmt::PMT_T), pmt::wrong_type); + BOOST_CHECK_EQUAL(float(-1.0), pmt::to_float(m2)); + BOOST_CHECK_EQUAL(float(1.0), pmt::to_float(p2)); + BOOST_CHECK_EQUAL(float(1.0), pmt::to_float(pmt::from_long(1))); } -void -qa_pmt_prims::test_complexes() -{ +BOOST_AUTO_TEST_CASE(test_complexes) { pmt::pmt_t p1 = pmt::make_rectangular(2, -3); pmt::pmt_t m1 = pmt::make_rectangular(-3, 2); pmt::pmt_t p2 = pmt::from_complex(2, -3); pmt::pmt_t m2 = pmt::from_complex(-3, 2); pmt::pmt_t p3 = pmt::from_complex(std::complex<double>(2, -3)); pmt::pmt_t m3 = pmt::from_complex(std::complex<double>(-3, 2)); - CPPUNIT_ASSERT(!pmt::is_complex(pmt::PMT_T)); - CPPUNIT_ASSERT(pmt::is_complex(p1)); - CPPUNIT_ASSERT(pmt::is_complex(m1)); - CPPUNIT_ASSERT(pmt::is_complex(p2)); - CPPUNIT_ASSERT(pmt::is_complex(m2)); - CPPUNIT_ASSERT(pmt::is_complex(p3)); - CPPUNIT_ASSERT(pmt::is_complex(m3)); - CPPUNIT_ASSERT_THROW(pmt::to_complex(pmt::PMT_T), pmt::wrong_type); - CPPUNIT_ASSERT_EQUAL(std::complex<double>(2, -3), pmt::to_complex(p1)); - CPPUNIT_ASSERT_EQUAL(std::complex<double>(-3, 2), pmt::to_complex(m1)); - CPPUNIT_ASSERT_EQUAL(std::complex<double>(2, -3), pmt::to_complex(p2)); - CPPUNIT_ASSERT_EQUAL(std::complex<double>(-3, 2), pmt::to_complex(m2)); - CPPUNIT_ASSERT_EQUAL(std::complex<double>(2, -3), pmt::to_complex(p3)); - CPPUNIT_ASSERT_EQUAL(std::complex<double>(-3, 2), pmt::to_complex(m3)); - CPPUNIT_ASSERT_EQUAL(std::complex<double>(1.0, 0), pmt::to_complex(pmt::from_long(1))); - CPPUNIT_ASSERT_EQUAL(std::complex<double>(1.0, 0), pmt::to_complex(pmt::from_double(1.0))); + BOOST_CHECK(!pmt::is_complex(pmt::PMT_T)); + BOOST_CHECK(pmt::is_complex(p1)); + BOOST_CHECK(pmt::is_complex(m1)); + BOOST_CHECK(pmt::is_complex(p2)); + BOOST_CHECK(pmt::is_complex(m2)); + BOOST_CHECK(pmt::is_complex(p3)); + BOOST_CHECK(pmt::is_complex(m3)); + BOOST_CHECK_THROW(pmt::to_complex(pmt::PMT_T), pmt::wrong_type); + BOOST_CHECK_EQUAL(std::complex<double>(2, -3), pmt::to_complex(p1)); + BOOST_CHECK_EQUAL(std::complex<double>(-3, 2), pmt::to_complex(m1)); + BOOST_CHECK_EQUAL(std::complex<double>(2, -3), pmt::to_complex(p2)); + BOOST_CHECK_EQUAL(std::complex<double>(-3, 2), pmt::to_complex(m2)); + BOOST_CHECK_EQUAL(std::complex<double>(2, -3), pmt::to_complex(p3)); + BOOST_CHECK_EQUAL(std::complex<double>(-3, 2), pmt::to_complex(m3)); + BOOST_CHECK_EQUAL(std::complex<double>(1.0, 0), pmt::to_complex(pmt::from_long(1))); + BOOST_CHECK_EQUAL(std::complex<double>(1.0, 0), pmt::to_complex(pmt::from_double(1.0))); } -void -qa_pmt_prims::test_pairs() -{ - CPPUNIT_ASSERT(pmt::is_null(pmt::PMT_NIL)); - CPPUNIT_ASSERT(!pmt::is_pair(pmt::PMT_NIL)); +BOOST_AUTO_TEST_CASE(test_pairs) { + BOOST_CHECK(pmt::is_null(pmt::PMT_NIL)); + BOOST_CHECK(!pmt::is_pair(pmt::PMT_NIL)); pmt::pmt_t s1 = pmt::mp("s1"); pmt::pmt_t s2 = pmt::mp("s2"); pmt::pmt_t s3 = pmt::mp("s3"); - CPPUNIT_ASSERT_EQUAL((size_t)0, pmt::length(pmt::PMT_NIL)); - CPPUNIT_ASSERT_THROW(pmt::length(s1), pmt::wrong_type); - CPPUNIT_ASSERT_THROW(pmt::length(pmt::from_double(42)), pmt::wrong_type); + BOOST_CHECK_EQUAL((size_t)0, pmt::length(pmt::PMT_NIL)); + BOOST_CHECK_THROW(pmt::length(s1), pmt::wrong_type); + BOOST_CHECK_THROW(pmt::length(pmt::from_double(42)), pmt::wrong_type); pmt::pmt_t c1 = pmt::cons(s1, pmt::PMT_NIL); - CPPUNIT_ASSERT(pmt::is_pair(c1)); - CPPUNIT_ASSERT(!pmt::is_pair(s1)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::car(c1)); - CPPUNIT_ASSERT_EQUAL(pmt::PMT_NIL, pmt::cdr(c1)); - CPPUNIT_ASSERT_EQUAL((size_t) 1, pmt::length(c1)); + BOOST_CHECK(pmt::is_pair(c1)); + BOOST_CHECK(!pmt::is_pair(s1)); + BOOST_CHECK_EQUAL(s1, pmt::car(c1)); + BOOST_CHECK_EQUAL(pmt::PMT_NIL, pmt::cdr(c1)); + BOOST_CHECK_EQUAL((size_t) 1, pmt::length(c1)); pmt::pmt_t c3 = pmt::cons(s3, pmt::PMT_NIL); pmt::pmt_t c2 = pmt::cons(s2, c3); pmt::set_cdr(c1, c2); - CPPUNIT_ASSERT_EQUAL(c2, pmt::cdr(c1)); + BOOST_CHECK_EQUAL(c2, pmt::cdr(c1)); pmt::set_car(c1, s3); - CPPUNIT_ASSERT_EQUAL(s3, pmt::car(c1)); - CPPUNIT_ASSERT_EQUAL((size_t)1, pmt::length(c3)); - CPPUNIT_ASSERT_EQUAL((size_t)2, pmt::length(c2)); - - CPPUNIT_ASSERT_THROW(pmt::cdr(pmt::PMT_NIL), pmt::wrong_type); - CPPUNIT_ASSERT_THROW(pmt::car(pmt::PMT_NIL), pmt::wrong_type); - CPPUNIT_ASSERT_THROW(pmt::set_car(s1, pmt::PMT_NIL), pmt::wrong_type); - CPPUNIT_ASSERT_THROW(pmt::set_cdr(s1, pmt::PMT_NIL), pmt::wrong_type); + BOOST_CHECK_EQUAL(s3, pmt::car(c1)); + BOOST_CHECK_EQUAL((size_t)1, pmt::length(c3)); + BOOST_CHECK_EQUAL((size_t)2, pmt::length(c2)); + + BOOST_CHECK_THROW(pmt::cdr(pmt::PMT_NIL), pmt::wrong_type); + BOOST_CHECK_THROW(pmt::car(pmt::PMT_NIL), pmt::wrong_type); + BOOST_CHECK_THROW(pmt::set_car(s1, pmt::PMT_NIL), pmt::wrong_type); + BOOST_CHECK_THROW(pmt::set_cdr(s1, pmt::PMT_NIL), pmt::wrong_type); } -void -qa_pmt_prims::test_vectors() -{ +BOOST_AUTO_TEST_CASE(test_vectors) { static const size_t N = 3; pmt::pmt_t v1 = pmt::make_vector(N, pmt::PMT_NIL); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); + BOOST_CHECK_EQUAL(N, pmt::length(v1)); pmt::pmt_t s0 = pmt::mp("s0"); pmt::pmt_t s1 = pmt::mp("s1"); pmt::pmt_t s2 = pmt::mp("s2"); @@ -213,32 +197,30 @@ qa_pmt_prims::test_vectors() pmt::vector_set(v1, 1, s1); pmt::vector_set(v1, 2, s2); - CPPUNIT_ASSERT_EQUAL(s0, pmt::vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::vector_ref(v1, 2)); + BOOST_CHECK_EQUAL(s0, pmt::vector_ref(v1, 0)); + BOOST_CHECK_EQUAL(s1, pmt::vector_ref(v1, 1)); + BOOST_CHECK_EQUAL(s2, pmt::vector_ref(v1, 2)); - CPPUNIT_ASSERT_THROW(pmt::vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::vector_set(v1, N, pmt::PMT_NIL), pmt::out_of_range); + BOOST_CHECK_THROW(pmt::vector_ref(v1, N), pmt::out_of_range); + BOOST_CHECK_THROW(pmt::vector_set(v1, N, pmt::PMT_NIL), pmt::out_of_range); pmt::vector_fill(v1, s0); for (size_t i = 0; i < N; i++) - CPPUNIT_ASSERT_EQUAL(s0, pmt::vector_ref(v1, i)); + BOOST_CHECK_EQUAL(s0, pmt::vector_ref(v1, i)); } static void check_tuple(size_t len, const std::vector<pmt::pmt_t> &s, pmt::pmt_t t) { - CPPUNIT_ASSERT_EQUAL(true, pmt::is_tuple(t)); - CPPUNIT_ASSERT_EQUAL(len, pmt::length(t)); + BOOST_CHECK_EQUAL(true, pmt::is_tuple(t)); + BOOST_CHECK_EQUAL(len, pmt::length(t)); for (size_t i = 0; i < len; i++) - CPPUNIT_ASSERT_EQUAL(s[i], pmt::tuple_ref(t, i)); + BOOST_CHECK_EQUAL(s[i], pmt::tuple_ref(t, i)); } -void -qa_pmt_prims::test_tuples() -{ +BOOST_AUTO_TEST_CASE(test_tuples) { pmt::pmt_t v = pmt::make_vector(10, pmt::PMT_NIL); std::vector<pmt::pmt_t> s(10); for (size_t i = 0; i < 10; i++){ @@ -257,10 +239,10 @@ qa_pmt_prims::test_tuples() t = pmt::make_tuple(s[0]); check_tuple(1, s, t); - CPPUNIT_ASSERT(pmt::is_vector(v)); - CPPUNIT_ASSERT(!pmt::is_tuple(v)); - CPPUNIT_ASSERT(pmt::is_tuple(t)); - CPPUNIT_ASSERT(!pmt::is_vector(t)); + BOOST_CHECK(pmt::is_vector(v)); + BOOST_CHECK(!pmt::is_tuple(v)); + BOOST_CHECK(pmt::is_tuple(t)); + BOOST_CHECK(!pmt::is_vector(t)); t = pmt::make_tuple(s[0], s[1]); check_tuple(2, s, t); @@ -290,29 +272,27 @@ qa_pmt_prims::test_tuples() check_tuple(10, s, t); t = pmt::make_tuple(s[0], s[1], s[2]); - CPPUNIT_ASSERT_THROW(pmt::tuple_ref(t, 3), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::vector_ref(t, 0), pmt::wrong_type); - CPPUNIT_ASSERT_THROW(pmt::tuple_ref(v, 0), pmt::wrong_type); + BOOST_CHECK_THROW(pmt::tuple_ref(t, 3), pmt::out_of_range); + BOOST_CHECK_THROW(pmt::vector_ref(t, 0), pmt::wrong_type); + BOOST_CHECK_THROW(pmt::tuple_ref(v, 0), pmt::wrong_type); t = pmt::make_tuple(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9]); pmt::pmt_t t2 = pmt::to_tuple(v); - CPPUNIT_ASSERT_EQUAL(size_t(10), pmt::length(v)); - CPPUNIT_ASSERT(pmt::equal(t, t2)); + BOOST_CHECK_EQUAL(size_t(10), pmt::length(v)); + BOOST_CHECK(pmt::equal(t, t2)); //std::cout << v << std::endl; //std::cout << t2 << std::endl; t = pmt::make_tuple(s[0], s[1], s[2]); pmt::pmt_t list0 = pmt::list3(s[0], s[1], s[2]); - CPPUNIT_ASSERT_EQUAL(size_t(3), pmt::length(list0)); + BOOST_CHECK_EQUAL(size_t(3), pmt::length(list0)); t2 = pmt::to_tuple(list0); - CPPUNIT_ASSERT_EQUAL(size_t(3), pmt::length(t2)); - CPPUNIT_ASSERT(pmt::equal(t, t2)); + BOOST_CHECK_EQUAL(size_t(3), pmt::length(t2)); + BOOST_CHECK(pmt::equal(t, t2)); } -void -qa_pmt_prims::test_equivalence() -{ +BOOST_AUTO_TEST_CASE(test_equivalence) { pmt::pmt_t s0 = pmt::mp("s0"); pmt::pmt_t s1 = pmt::mp("s1"); pmt::pmt_t s2 = pmt::mp("s2"); @@ -324,37 +304,35 @@ qa_pmt_prims::test_equivalence() pmt::pmt_t r1 = pmt::from_double(42); pmt::pmt_t r2 = pmt::from_double(43); - CPPUNIT_ASSERT(pmt::eq(s0, s0)); - CPPUNIT_ASSERT(!pmt::eq(s0, s1)); - CPPUNIT_ASSERT(pmt::eqv(s0, s0)); - CPPUNIT_ASSERT(!pmt::eqv(s0, s1)); + BOOST_CHECK(pmt::eq(s0, s0)); + BOOST_CHECK(!pmt::eq(s0, s1)); + BOOST_CHECK(pmt::eqv(s0, s0)); + BOOST_CHECK(!pmt::eqv(s0, s1)); - CPPUNIT_ASSERT(pmt::eqv(i0, i1)); - CPPUNIT_ASSERT(pmt::eqv(r0, r1)); - CPPUNIT_ASSERT(!pmt::eqv(r0, r2)); - CPPUNIT_ASSERT(!pmt::eqv(i0, r0)); + BOOST_CHECK(pmt::eqv(i0, i1)); + BOOST_CHECK(pmt::eqv(r0, r1)); + BOOST_CHECK(!pmt::eqv(r0, r2)); + BOOST_CHECK(!pmt::eqv(i0, r0)); - CPPUNIT_ASSERT(!pmt::eq(list0, list1)); - CPPUNIT_ASSERT(!pmt::eqv(list0, list1)); - CPPUNIT_ASSERT(pmt::equal(list0, list1)); + BOOST_CHECK(!pmt::eq(list0, list1)); + BOOST_CHECK(!pmt::eqv(list0, list1)); + BOOST_CHECK(pmt::equal(list0, list1)); pmt::pmt_t v0 = pmt::make_vector(3, s0); pmt::pmt_t v1 = pmt::make_vector(3, s0); pmt::pmt_t v2 = pmt::make_vector(4, s0); - CPPUNIT_ASSERT(!pmt::eqv(v0, v1)); - CPPUNIT_ASSERT(pmt::equal(v0, v1)); - CPPUNIT_ASSERT(!pmt::equal(v0, v2)); + BOOST_CHECK(!pmt::eqv(v0, v1)); + BOOST_CHECK(pmt::equal(v0, v1)); + BOOST_CHECK(!pmt::equal(v0, v2)); pmt::vector_set(v0, 0, list0); pmt::vector_set(v0, 1, list0); pmt::vector_set(v1, 0, list1); pmt::vector_set(v1, 1, list1); - CPPUNIT_ASSERT(pmt::equal(v0, v1)); + BOOST_CHECK(pmt::equal(v0, v1)); } -void -qa_pmt_prims::test_misc() -{ +BOOST_AUTO_TEST_CASE(test_misc) { pmt::pmt_t k0 = pmt::mp("k0"); pmt::pmt_t k1 = pmt::mp("k1"); pmt::pmt_t k2 = pmt::mp("k2"); @@ -367,20 +345,18 @@ qa_pmt_prims::test_misc() pmt::pmt_t p2 = pmt::cons(k2, v2); pmt::pmt_t alist = pmt::cons(p0, pmt::cons(p1, pmt::cons(p2, pmt::PMT_NIL))); - CPPUNIT_ASSERT(pmt::eq(p1, pmt::assv(k1, alist))); - CPPUNIT_ASSERT(pmt::eq(pmt::PMT_F, pmt::assv(k3, alist))); + BOOST_CHECK(pmt::eq(p1, pmt::assv(k1, alist))); + BOOST_CHECK(pmt::eq(pmt::PMT_F, pmt::assv(k3, alist))); pmt::pmt_t keys = pmt::cons(k0, pmt::cons(k1, pmt::cons(k2, pmt::PMT_NIL))); pmt::pmt_t vals = pmt::cons(v0, pmt::cons(v1, pmt::cons(v2, pmt::PMT_NIL))); - CPPUNIT_ASSERT(pmt::equal(keys, pmt::map(pmt::car, alist))); - CPPUNIT_ASSERT(pmt::equal(vals, pmt::map(pmt::cdr, alist))); + BOOST_CHECK(pmt::equal(keys, pmt::map(pmt::car, alist))); + BOOST_CHECK(pmt::equal(vals, pmt::map(pmt::cdr, alist))); } -void -qa_pmt_prims::test_dict() -{ +BOOST_AUTO_TEST_CASE(test_dict) { pmt::pmt_t dict = pmt::make_dict(); - CPPUNIT_ASSERT(pmt::is_dict(dict)); + BOOST_CHECK(pmt::is_dict(dict)); pmt::pmt_t k0 = pmt::mp("k0"); pmt::pmt_t k1 = pmt::mp("k1"); @@ -392,39 +368,35 @@ qa_pmt_prims::test_dict() pmt::pmt_t v3 = pmt::mp("v3"); pmt::pmt_t not_found = pmt::cons(pmt::PMT_NIL, pmt::PMT_NIL); - CPPUNIT_ASSERT(!pmt::dict_has_key(dict, k0)); + BOOST_CHECK(!pmt::dict_has_key(dict, k0)); dict = pmt::dict_add(dict, k0, v0); - CPPUNIT_ASSERT(pmt::dict_has_key(dict, k0)); - CPPUNIT_ASSERT(pmt::eqv(pmt::dict_ref(dict, k0, not_found), v0)); - CPPUNIT_ASSERT(pmt::eqv(pmt::dict_ref(dict, k1, not_found), not_found)); + BOOST_CHECK(pmt::dict_has_key(dict, k0)); + BOOST_CHECK(pmt::eqv(pmt::dict_ref(dict, k0, not_found), v0)); + BOOST_CHECK(pmt::eqv(pmt::dict_ref(dict, k1, not_found), not_found)); dict = pmt::dict_add(dict, k1, v1); dict = pmt::dict_add(dict, k2, v2); - CPPUNIT_ASSERT(pmt::eqv(pmt::dict_ref(dict, k1, not_found), v1)); + BOOST_CHECK(pmt::eqv(pmt::dict_ref(dict, k1, not_found), v1)); dict = pmt::dict_add(dict, k1, v3); - CPPUNIT_ASSERT(pmt::eqv(pmt::dict_ref(dict, k1, not_found), v3)); + BOOST_CHECK(pmt::eqv(pmt::dict_ref(dict, k1, not_found), v3)); pmt::pmt_t keys = pmt::list3(k1, k2, k0); pmt::pmt_t vals = pmt::list3(v3, v2, v0); //std::cout << "pmt::dict_keys: " << pmt::dict_keys(dict) << std::endl; //std::cout << "pmt::dict_values: " << pmt::dict_values(dict) << std::endl; - CPPUNIT_ASSERT(pmt::equal(keys, pmt::dict_keys(dict))); - CPPUNIT_ASSERT(pmt::equal(vals, pmt::dict_values(dict))); + BOOST_CHECK(pmt::equal(keys, pmt::dict_keys(dict))); + BOOST_CHECK(pmt::equal(vals, pmt::dict_values(dict))); } -void -qa_pmt_prims::test_io() -{ +BOOST_AUTO_TEST_CASE(test_io) { pmt::pmt_t k0 = pmt::mp("k0"); pmt::pmt_t k1 = pmt::mp("k1"); pmt::pmt_t k2 = pmt::mp("k2"); pmt::pmt_t k3 = pmt::mp("k3"); - CPPUNIT_ASSERT_EQUAL(std::string("k0"), pmt::write_string(k0)); + BOOST_CHECK_EQUAL(std::string("k0"), pmt::write_string(k0)); } -void -qa_pmt_prims::test_lists() -{ +BOOST_AUTO_TEST_CASE(test_lists) { pmt::pmt_t s0 = pmt::mp("s0"); pmt::pmt_t s1 = pmt::mp("s1"); pmt::pmt_t s2 = pmt::mp("s2"); @@ -433,7 +405,7 @@ qa_pmt_prims::test_lists() pmt::pmt_t l1 = pmt::list4(s0, s1, s2, s3); pmt::pmt_t l2 = pmt::list3(s0, s1, s2); pmt::pmt_t l3 = pmt::list_add(l2, s3); - CPPUNIT_ASSERT(pmt::equal(l1, l3)); + BOOST_CHECK(pmt::equal(l1, l3)); } // ------------------------------------------------------------------------ @@ -460,9 +432,7 @@ std::ostream& operator<<(std::ostream &os, const foo obj) return os; } -void -qa_pmt_prims::test_any() -{ +BOOST_AUTO_TEST_CASE(test_any) { boost::any a0; boost::any a1; boost::any a2; @@ -475,13 +445,13 @@ qa_pmt_prims::test_any() pmt::pmt_t p1 = pmt::make_any(a1); pmt::pmt_t p2 = pmt::make_any(a2); - CPPUNIT_ASSERT_EQUAL(std::string("Hello!"), + BOOST_CHECK_EQUAL(std::string("Hello!"), boost::any_cast<std::string>(pmt::any_ref(p0))); - CPPUNIT_ASSERT_EQUAL(42, + BOOST_CHECK_EQUAL(42, boost::any_cast<int>(pmt::any_ref(p1))); - CPPUNIT_ASSERT_EQUAL(foo(3.250, 21), + BOOST_CHECK_EQUAL(foo(3.250, 21), boost::any_cast<foo>(pmt::any_ref(p2))); } @@ -490,16 +460,14 @@ qa_pmt_prims::test_any() class qa_pmt_msg_accepter_nop : public gr::messages::msg_accepter { public: - qa_pmt_msg_accepter_nop(){}; + qa_pmt_msg_accepter_nop(){} ~qa_pmt_msg_accepter_nop(); - void post(pmt::pmt_t,pmt::pmt_t){}; + void post(pmt::pmt_t,pmt::pmt_t){} }; qa_pmt_msg_accepter_nop::~qa_pmt_msg_accepter_nop(){} -void -qa_pmt_prims::test_msg_accepter() -{ +BOOST_AUTO_TEST_CASE(test_msg_accepter) { pmt::pmt_t sym = pmt::mp("my-symbol"); boost::any a0; @@ -510,10 +478,10 @@ qa_pmt_prims::test_msg_accepter() gr::messages::msg_accepter_sptr(new qa_pmt_msg_accepter_nop()); pmt::pmt_t p1 = pmt::make_msg_accepter(ma0); - CPPUNIT_ASSERT_EQUAL(ma0.get(), pmt::msg_accepter_ref(p1).get()); + BOOST_CHECK_EQUAL(ma0.get(), pmt::msg_accepter_ref(p1).get()); - CPPUNIT_ASSERT_THROW(pmt::msg_accepter_ref(sym), pmt::wrong_type); - CPPUNIT_ASSERT_THROW(pmt::msg_accepter_ref(p0), pmt::wrong_type); + BOOST_CHECK_THROW(pmt::msg_accepter_ref(sym), pmt::wrong_type); + BOOST_CHECK_THROW(pmt::msg_accepter_ref(p0), pmt::wrong_type); // just confirm interfaces on send are OK pmt::pmt_t port(pmt::intern("port")); @@ -525,9 +493,7 @@ qa_pmt_prims::test_msg_accepter() // ------------------------------------------------------------------------ -void -qa_pmt_prims::test_serialize() -{ +BOOST_AUTO_TEST_CASE(test_serialize) { std::stringbuf sb; // fake channel pmt::pmt_t a = pmt::mp("a"); pmt::pmt_t b = pmt::mp("b"); @@ -552,20 +518,20 @@ qa_pmt_prims::test_serialize() // read it back - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::PMT_NIL)); - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::mp("foobarvia"))); - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::from_long(123456789))); - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::from_long(-123456789))); - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::cons(pmt::PMT_NIL, pmt::PMT_NIL))); - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::cons(a, b))); - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::list1(a))); - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::list2(a, b))); - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::list3(a, b, c))); - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::list3(a, pmt::list3(c, b, a), c))); - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::PMT_T)); - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::PMT_F)); + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::PMT_NIL)); + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::mp("foobarvia"))); + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::from_long(123456789))); + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::from_long(-123456789))); + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::cons(pmt::PMT_NIL, pmt::PMT_NIL))); + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::cons(a, b))); + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::list1(a))); + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::list2(a, b))); + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::list3(a, b, c))); + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::list3(a, pmt::list3(c, b, a), c))); + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::PMT_T)); + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::PMT_F)); - CPPUNIT_ASSERT(pmt::equal(pmt::deserialize(sb), pmt::PMT_EOF)); // last item + BOOST_CHECK(pmt::equal(pmt::deserialize(sb), pmt::PMT_EOF)); // last item // FIXME add tests for real, complex, vector, uniform-vector, dict @@ -573,9 +539,7 @@ qa_pmt_prims::test_serialize() } -void -qa_pmt_prims::test_sets() -{ +BOOST_AUTO_TEST_CASE(test_sets) { pmt::pmt_t s1 = pmt::mp("s1"); pmt::pmt_t s2 = pmt::mp("s2"); pmt::pmt_t s3 = pmt::mp("s3"); @@ -584,29 +548,28 @@ qa_pmt_prims::test_sets() pmt::pmt_t l2 = pmt::list2(s2,s3); pmt::pmt_t l3 = pmt::list3(s1,s2,s3); - CPPUNIT_ASSERT(pmt::is_pair(pmt::memq(s1,l1))); - CPPUNIT_ASSERT(pmt::is_false(pmt::memq(s3,l1))); + BOOST_CHECK(pmt::is_pair(pmt::memq(s1,l1))); + BOOST_CHECK(pmt::is_false(pmt::memq(s3,l1))); - CPPUNIT_ASSERT(pmt::subsetp(l1,l3)); - CPPUNIT_ASSERT(pmt::subsetp(l2,l3)); - CPPUNIT_ASSERT(!pmt::subsetp(l1,l2)); - CPPUNIT_ASSERT(!pmt::subsetp(l2,l1)); - CPPUNIT_ASSERT(!pmt::subsetp(l3,l2)); + BOOST_CHECK(pmt::subsetp(l1,l3)); + BOOST_CHECK(pmt::subsetp(l2,l3)); + BOOST_CHECK(!pmt::subsetp(l1,l2)); + BOOST_CHECK(!pmt::subsetp(l2,l1)); + BOOST_CHECK(!pmt::subsetp(l3,l2)); } -void -qa_pmt_prims::test_sugar() -{ - CPPUNIT_ASSERT(pmt::is_symbol(pmt::mp("my-symbol"))); - CPPUNIT_ASSERT_EQUAL((long) 10, pmt::to_long(pmt::mp(10))); - CPPUNIT_ASSERT_EQUAL((double) 1e6, pmt::to_double(pmt::mp(1e6))); - CPPUNIT_ASSERT_EQUAL(std::complex<double>(2, 3), +BOOST_AUTO_TEST_CASE(test_sugar) { + BOOST_CHECK(pmt::is_symbol(pmt::mp("my-symbol"))); + BOOST_CHECK_EQUAL((long) 10, pmt::to_long(pmt::mp(10))); + BOOST_CHECK_EQUAL((double) 1e6, pmt::to_double(pmt::mp(1e6))); + BOOST_CHECK_EQUAL(std::complex<double>(2, 3), pmt::to_complex(pmt::mp(std::complex<double>(2, 3)))); int buf[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; pmt::pmt_t blob = pmt::mp(buf, sizeof(buf)); const void *data = pmt::blob_data(blob); size_t nbytes = pmt::blob_length(blob); - CPPUNIT_ASSERT_EQUAL(sizeof(buf), nbytes); - CPPUNIT_ASSERT(memcmp(buf, data, nbytes) == 0); + BOOST_CHECK_EQUAL(sizeof(buf), nbytes); + BOOST_CHECK(memcmp(buf, data, nbytes) == 0); } + diff --git a/gnuradio-runtime/lib/pmt/qa_pmt_prims.h b/gnuradio-runtime/lib/pmt/qa_pmt_prims.h deleted file mode 100644 index f2f3dd77f7..0000000000 --- a/gnuradio-runtime/lib/pmt/qa_pmt_prims.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDED_QA_PMT_PRIMS_H -#define INCLUDED_QA_PMT_PRIMS_H - -#include <gnuradio/attributes.h> -#include <pmt/api.h> //reason: suppress warnings -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class __GR_ATTR_EXPORT qa_pmt_prims : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_pmt_prims); - CPPUNIT_TEST(test_symbols); - CPPUNIT_TEST(test_booleans); - CPPUNIT_TEST(test_integers); - CPPUNIT_TEST(test_uint64s); - CPPUNIT_TEST(test_reals); - CPPUNIT_TEST(test_complexes); - CPPUNIT_TEST(test_pairs); - CPPUNIT_TEST(test_vectors); - CPPUNIT_TEST(test_tuples); - CPPUNIT_TEST(test_equivalence); - CPPUNIT_TEST(test_misc); - CPPUNIT_TEST(test_dict); - CPPUNIT_TEST(test_any); - CPPUNIT_TEST(test_msg_accepter); - CPPUNIT_TEST(test_io); - CPPUNIT_TEST(test_lists); - CPPUNIT_TEST(test_serialize); - CPPUNIT_TEST(test_sets); - CPPUNIT_TEST(test_sugar); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_symbols(); - void test_booleans(); - void test_integers(); - void test_uint64s(); - void test_reals(); - void test_complexes(); - void test_pairs(); - void test_vectors(); - void test_tuples(); - void test_equivalence(); - void test_misc(); - void test_dict(); - void test_any(); - void test_msg_accepter(); - void test_io(); - void test_lists(); - void test_serialize(); - void test_sets(); - void test_sugar(); -}; - -#endif /* INCLUDED_QA_PMT_PRIMS_H */ - diff --git a/gnuradio-runtime/lib/pmt/qa_pmt_unv.cc b/gnuradio-runtime/lib/pmt/qa_pmt_unv.cc index 9751f5e610..66d0d6d438 100644 --- a/gnuradio-runtime/lib/pmt/qa_pmt_unv.cc +++ b/gnuradio-runtime/lib/pmt/qa_pmt_unv.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2009 Free Software Foundation, Inc. + * Copyright 2006,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -20,429 +20,15 @@ * Boston, MA 02110-1301, USA. */ -#include <qa_pmt_unv.h> -#include <cppunit/TestAssert.h> -#include <pmt/pmt.h> -#include <stdio.h> +// We need a non-generated C++ file for CMake, all the actual test cases are +// generated from the template and written to qa_pmt_unv.h -using namespace pmt; -void -qa_pmt_unv::test_u8vector() -{ - static const size_t N = 3; - pmt::pmt_t v1 = pmt::make_u8vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); - uint8_t s0 = uint8_t(10); - uint8_t s1 = uint8_t(20); - uint8_t s2 = uint8_t(30); +#include <pmt/api.h> //reason: suppress warnings +#include <gnuradio/messages/msg_passing.h> +#include <boost/test/unit_test.hpp> +#include <boost/format.hpp> +#include <cstdio> +#include <cstring> +#include <sstream> - pmt::u8vector_set(v1, 0, s0); - pmt::u8vector_set(v1, 1, s1); - pmt::u8vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt::u8vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::u8vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::u8vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt::u8vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::u8vector_set(v1, N, uint8_t(0)), pmt::out_of_range); - - size_t len; - const uint8_t *rd = pmt::u8vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - uint8_t *wr = pmt::u8vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = uint8_t(0); - CPPUNIT_ASSERT_EQUAL(uint8_t(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} -void -qa_pmt_unv::test_s8vector() -{ - static const size_t N = 3; - pmt::pmt_t v1 = pmt::make_s8vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); - int8_t s0 = int8_t(10); - int8_t s1 = int8_t(20); - int8_t s2 = int8_t(30); - - pmt::s8vector_set(v1, 0, s0); - pmt::s8vector_set(v1, 1, s1); - pmt::s8vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt::s8vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::s8vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::s8vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt::s8vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::s8vector_set(v1, N, int8_t(0)), pmt::out_of_range); - - size_t len; - const int8_t *rd = pmt::s8vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - int8_t *wr = pmt::s8vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = int8_t(0); - CPPUNIT_ASSERT_EQUAL(int8_t(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} -void -qa_pmt_unv::test_u16vector() -{ - static const size_t N = 3; - pmt::pmt_t v1 = pmt::make_u16vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); - uint16_t s0 = uint16_t(10); - uint16_t s1 = uint16_t(20); - uint16_t s2 = uint16_t(30); - - pmt::u16vector_set(v1, 0, s0); - pmt::u16vector_set(v1, 1, s1); - pmt::u16vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt::u16vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::u16vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::u16vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt::u16vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::u16vector_set(v1, N, uint16_t(0)), pmt::out_of_range); - - size_t len; - const uint16_t *rd = pmt::u16vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - uint16_t *wr = pmt::u16vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = uint16_t(0); - CPPUNIT_ASSERT_EQUAL(uint16_t(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} -void -qa_pmt_unv::test_s16vector() -{ - static const size_t N = 3; - pmt::pmt_t v1 = pmt::make_s16vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); - int16_t s0 = int16_t(10); - int16_t s1 = int16_t(20); - int16_t s2 = int16_t(30); - - pmt::s16vector_set(v1, 0, s0); - pmt::s16vector_set(v1, 1, s1); - pmt::s16vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt::s16vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::s16vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::s16vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt::s16vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::s16vector_set(v1, N, int16_t(0)), pmt::out_of_range); - - size_t len; - const int16_t *rd = pmt::s16vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - int16_t *wr = pmt::s16vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = int16_t(0); - CPPUNIT_ASSERT_EQUAL(int16_t(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} -void -qa_pmt_unv::test_u32vector() -{ - static const size_t N = 3; - pmt::pmt_t v1 = pmt::make_u32vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); - uint32_t s0 = uint32_t(10); - uint32_t s1 = uint32_t(20); - uint32_t s2 = uint32_t(30); - - pmt::u32vector_set(v1, 0, s0); - pmt::u32vector_set(v1, 1, s1); - pmt::u32vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt::u32vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::u32vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::u32vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt::u32vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::u32vector_set(v1, N, uint32_t(0)), pmt::out_of_range); - - size_t len; - const uint32_t *rd = pmt::u32vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - uint32_t *wr = pmt::u32vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = uint32_t(0); - CPPUNIT_ASSERT_EQUAL(uint32_t(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} -void -qa_pmt_unv::test_s32vector() -{ - static const size_t N = 3; - pmt::pmt_t v1 = pmt::make_s32vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); - int32_t s0 = int32_t(10); - int32_t s1 = int32_t(20); - int32_t s2 = int32_t(30); - - pmt::s32vector_set(v1, 0, s0); - pmt::s32vector_set(v1, 1, s1); - pmt::s32vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt::s32vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::s32vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::s32vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt::s32vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::s32vector_set(v1, N, int32_t(0)), pmt::out_of_range); - - size_t len; - const int32_t *rd = pmt::s32vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - int32_t *wr = pmt::s32vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = int32_t(0); - CPPUNIT_ASSERT_EQUAL(int32_t(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} -void -qa_pmt_unv::test_u64vector() -{ - static const size_t N = 3; - pmt::pmt_t v1 = pmt::make_u64vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); - uint64_t s0 = uint64_t(10); - uint64_t s1 = uint64_t(20); - uint64_t s2 = uint64_t(30); - - pmt::u64vector_set(v1, 0, s0); - pmt::u64vector_set(v1, 1, s1); - pmt::u64vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt::u64vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::u64vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::u64vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt::u64vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::u64vector_set(v1, N, uint64_t(0)), pmt::out_of_range); - - size_t len; - const uint64_t *rd = pmt::u64vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - uint64_t *wr = pmt::u64vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = uint64_t(0); - CPPUNIT_ASSERT_EQUAL(uint64_t(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} -void -qa_pmt_unv::test_s64vector() -{ - static const size_t N = 3; - pmt::pmt_t v1 = pmt::make_s64vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); - int64_t s0 = int64_t(10); - int64_t s1 = int64_t(20); - int64_t s2 = int64_t(30); - - pmt::s64vector_set(v1, 0, s0); - pmt::s64vector_set(v1, 1, s1); - pmt::s64vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt::s64vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::s64vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::s64vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt::s64vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::s64vector_set(v1, N, int64_t(0)), pmt::out_of_range); - - size_t len; - const int64_t *rd = pmt::s64vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - int64_t *wr = pmt::s64vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = int64_t(0); - CPPUNIT_ASSERT_EQUAL(int64_t(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} -void -qa_pmt_unv::test_f32vector() -{ - static const size_t N = 3; - pmt::pmt_t v1 = pmt::make_f32vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); - float s0 = float(10); - float s1 = float(20); - float s2 = float(30); - - pmt::f32vector_set(v1, 0, s0); - pmt::f32vector_set(v1, 1, s1); - pmt::f32vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt::f32vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::f32vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::f32vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt::f32vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::f32vector_set(v1, N, float(0)), pmt::out_of_range); - - size_t len; - const float *rd = pmt::f32vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - float *wr = pmt::f32vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = float(0); - CPPUNIT_ASSERT_EQUAL(float(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} -void -qa_pmt_unv::test_f64vector() -{ - static const size_t N = 3; - pmt::pmt_t v1 = pmt::make_f64vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); - double s0 = double(10); - double s1 = double(20); - double s2 = double(30); - - pmt::f64vector_set(v1, 0, s0); - pmt::f64vector_set(v1, 1, s1); - pmt::f64vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt::f64vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::f64vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::f64vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt::f64vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::f64vector_set(v1, N, double(0)), pmt::out_of_range); - - size_t len; - const double *rd = pmt::f64vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - double *wr = pmt::f64vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = double(0); - CPPUNIT_ASSERT_EQUAL(double(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} -void -qa_pmt_unv::test_c32vector() -{ - static const size_t N = 3; - pmt::pmt_t v1 = pmt::make_c32vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); - std::complex<float> s0 = std::complex<float>(10); - std::complex<float> s1 = std::complex<float>(20); - std::complex<float> s2 = std::complex<float>(30); - - pmt::c32vector_set(v1, 0, s0); - pmt::c32vector_set(v1, 1, s1); - pmt::c32vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt::c32vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::c32vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::c32vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt::c32vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::c32vector_set(v1, N, std::complex<float>(0)), pmt::out_of_range); - - size_t len; - const std::complex<float> *rd = pmt::c32vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - std::complex<float> *wr = pmt::c32vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = std::complex<float>(0); - CPPUNIT_ASSERT_EQUAL(std::complex<float>(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} -void -qa_pmt_unv::test_c64vector() -{ - static const size_t N = 3; - pmt::pmt_t v1 = pmt::make_c64vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt::length(v1)); - std::complex<double> s0 = std::complex<double>(10); - std::complex<double> s1 = std::complex<double>(20); - std::complex<double> s2 = std::complex<double>(30); - - pmt::c64vector_set(v1, 0, s0); - pmt::c64vector_set(v1, 1, s1); - pmt::c64vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt::c64vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt::c64vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt::c64vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt::c64vector_ref(v1, N), pmt::out_of_range); - CPPUNIT_ASSERT_THROW(pmt::c64vector_set(v1, N, std::complex<double>(0)), pmt::out_of_range); - - size_t len; - const std::complex<double> *rd = pmt::c64vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - std::complex<double> *wr = pmt::c64vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = std::complex<double>(0); - CPPUNIT_ASSERT_EQUAL(std::complex<double>(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} +#include "qa_pmt_unv.h" diff --git a/gnuradio-runtime/lib/pmt/test_pmt.cc b/gnuradio-runtime/lib/pmt/test_pmt.cc deleted file mode 100644 index 403bf64cd0..0000000000 --- a/gnuradio-runtime/lib/pmt/test_pmt.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <cppunit/TextTestRunner.h> -#include <cppunit/XmlOutputter.h> - -#include <gnuradio/unittests.h> -#include <qa_pmt.h> -#include <fstream> - -int -main (int argc, char **argv) -{ - CppUnit::TextTestRunner runner; - std::ofstream xmlfile(get_unittest_path("gnuradio_runtime_runtime.xml").c_str()); - CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile); - - runner.addTest(qa_pmt::suite()); - runner.setOutputter(xmlout); - - bool was_successful = runner.run("", false); - - return was_successful ? 0 : 1; -} diff --git a/gnuradio-runtime/lib/pmt/unv_qa_template.h.t b/gnuradio-runtime/lib/pmt/unv_qa_template.h.t new file mode 100644 index 0000000000..5a498f482c --- /dev/null +++ b/gnuradio-runtime/lib/pmt/unv_qa_template.h.t @@ -0,0 +1,33 @@ +BOOST_AUTO_TEST_CASE(test_@TAG@vector) { + static const size_t N = 3; + pmt::pmt_t v1 = pmt::make_@TAG@vector(N, 0); + BOOST_CHECK_EQUAL(N, pmt::length(v1)); + @TYPE@ s0 = @TYPE@(10); + @TYPE@ s1 = @TYPE@(20); + @TYPE@ s2 = @TYPE@(30); + + pmt::@TAG@vector_set(v1, 0, s0); + pmt::@TAG@vector_set(v1, 1, s1); + pmt::@TAG@vector_set(v1, 2, s2); + + BOOST_CHECK_EQUAL(s0, pmt::@TAG@vector_ref(v1, 0)); + BOOST_CHECK_EQUAL(s1, pmt::@TAG@vector_ref(v1, 1)); + BOOST_CHECK_EQUAL(s2, pmt::@TAG@vector_ref(v1, 2)); + + BOOST_CHECK_THROW(pmt::@TAG@vector_ref(v1, N), pmt::out_of_range); + BOOST_CHECK_THROW(pmt::@TAG@vector_set(v1, N, @TYPE@(0)), pmt::out_of_range); + + size_t len; + const @TYPE@ *rd = pmt::@TAG@vector_elements(v1, len); + BOOST_CHECK_EQUAL(len, N); + BOOST_CHECK_EQUAL(s0, rd[0]); + BOOST_CHECK_EQUAL(s1, rd[1]); + BOOST_CHECK_EQUAL(s2, rd[2]); + + @TYPE@ *wr = pmt::@TAG@vector_writable_elements(v1, len); + BOOST_CHECK_EQUAL(len, N); + wr[0] = @TYPE@(0); + BOOST_CHECK_EQUAL(@TYPE@(0), wr[0]); + BOOST_CHECK_EQUAL(s1, wr[1]); + BOOST_CHECK_EQUAL(s2, wr[2]); +} diff --git a/gnuradio-runtime/lib/qa_buffer.cc b/gnuradio-runtime/lib/qa_buffer.cc index 5f1dece0ad..0d995f2084 100644 --- a/gnuradio-runtime/lib/qa_buffer.cc +++ b/gnuradio-runtime/lib/qa_buffer.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,22 +24,26 @@ #include <config.h> #endif -#include <qa_buffer.h> + +#include <gnuradio/random.h> #include <gnuradio/buffer.h> -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <stdlib.h> -#include <gnuradio/random.h> + static void leak_check(void f()) { - long buffer_count = gr::buffer_ncurrently_allocated(); - long buffer_reader_count = gr::buffer_reader_ncurrently_allocated(); + long buffer_count = gr::buffer_ncurrently_allocated(); + long buffer_reader_count = gr::buffer_reader_ncurrently_allocated(); f(); - CPPUNIT_ASSERT_EQUAL(buffer_reader_count, gr::buffer_reader_ncurrently_allocated()); - CPPUNIT_ASSERT_EQUAL(buffer_count, gr::buffer_ncurrently_allocated()); + BOOST_CHECK_EQUAL( + buffer_reader_count, + gr::buffer_reader_ncurrently_allocated() + ); + BOOST_CHECK_EQUAL(buffer_count, gr::buffer_ncurrently_allocated()); } @@ -59,16 +63,16 @@ t0_body() int sa; sa = buf->space_available(); - CPPUNIT_ASSERT(sa > 0); + BOOST_CHECK(sa > 0); last_sa = sa; for(int i = 0; i < 5; i++) { sa = buf->space_available(); - CPPUNIT_ASSERT_EQUAL(last_sa, sa); + BOOST_CHECK_EQUAL(last_sa, sa); last_sa = sa; int *p = (int*)buf->write_pointer(); - CPPUNIT_ASSERT(p != 0); + BOOST_CHECK(p != 0); for(int j = 0; j < sa; j++) *p++ = counter++; @@ -96,10 +100,10 @@ t1_body() // write 1/3 of buffer sa = buf->space_available(); - CPPUNIT_ASSERT(sa > 0); + BOOST_CHECK(sa > 0); int *p = (int*)buf->write_pointer(); - CPPUNIT_ASSERT(p != 0); + BOOST_CHECK(p != 0); for(int j = 0; j < sa/3; j++) { *p++ = write_counter++; @@ -109,10 +113,10 @@ t1_body() // write the next 1/3 (1/2 of what's left) sa = buf->space_available(); - CPPUNIT_ASSERT(sa > 0); + BOOST_CHECK(sa > 0); p = (int*)buf->write_pointer(); - CPPUNIT_ASSERT(p != 0); + BOOST_CHECK(p != 0); for(int j = 0; j < sa/2; j++) { *p++ = write_counter++; @@ -122,13 +126,13 @@ t1_body() // check that we can read it OK int ia = r1->items_available(); - CPPUNIT_ASSERT_EQUAL(write_counter, ia); + BOOST_CHECK_EQUAL(write_counter, ia); int *rp = (int*)r1->read_pointer(); - CPPUNIT_ASSERT(rp != 0); + BOOST_CHECK(rp != 0); for(int i = 0; i < ia/2; i++) { - CPPUNIT_ASSERT_EQUAL(read_counter, *rp); + BOOST_CHECK_EQUAL(read_counter, *rp); read_counter++; rp++; } @@ -138,10 +142,10 @@ t1_body() ia = r1->items_available(); rp = (int *) r1->read_pointer(); - CPPUNIT_ASSERT(rp != 0); + BOOST_CHECK(rp != 0); for(int i = 0; i < ia; i++) { - CPPUNIT_ASSERT_EQUAL(read_counter, *rp); + BOOST_CHECK_EQUAL(read_counter, *rp); read_counter++; rp++; } @@ -181,11 +185,11 @@ t2_body() // Now read it all int m = r1->items_available(); - CPPUNIT_ASSERT_EQUAL(n, m); + BOOST_CHECK_EQUAL(n, m); rp = (int*)r1->read_pointer(); for(int i = 0; i < m; i++) { - CPPUNIT_ASSERT_EQUAL(read_counter, *rp); + BOOST_CHECK_EQUAL(read_counter, *rp); read_counter++; rp++; } @@ -195,7 +199,7 @@ t2_body() // This will wrap around the buffer n = buf->space_available(); - CPPUNIT_ASSERT_EQUAL(nitems - 1, n); // white box test + BOOST_CHECK_EQUAL(nitems - 1, n); // white box test wp = (int*)buf->write_pointer(); for(int i = 0; i < n; i++) @@ -205,11 +209,11 @@ t2_body() // now read it all m = r1->items_available(); - CPPUNIT_ASSERT_EQUAL(n, m); + BOOST_CHECK_EQUAL(n, m); rp = (int*)r1->read_pointer(); for(int i = 0; i < m; i++) { - CPPUNIT_ASSERT_EQUAL(read_counter, *rp); + BOOST_CHECK_EQUAL(read_counter, *rp); read_counter++; rp++; } @@ -252,13 +256,13 @@ t3_body() // pick a random reader and read some int r = (int)(N * random.ran1()); - CPPUNIT_ASSERT(0 <= r && r < N); + BOOST_CHECK(0 <= r && r < N); int m = reader[r]->items_available(); int *rp = (int*)reader[r]->read_pointer(); for(int i = 0; i < m; i++) { - CPPUNIT_ASSERT_EQUAL(read_counter[r], *rp); + BOOST_CHECK_EQUAL(read_counter[r], *rp); read_counter[r]++; rp++; } @@ -268,37 +272,19 @@ t3_body() // ---------------------------------------------------------------------------- - -void -qa_buffer::t0() -{ +BOOST_AUTO_TEST_CASE(t0) { leak_check(t0_body); } -void -qa_buffer::t1() -{ +BOOST_AUTO_TEST_CASE(t1) { leak_check(t1_body); } -void -qa_buffer::t2() -{ +BOOST_AUTO_TEST_CASE(t2) { leak_check(t2_body); } -void -qa_buffer::t3() -{ +BOOST_AUTO_TEST_CASE(t3) { leak_check(t3_body); } -void -qa_buffer::t4() -{ -} - -void -qa_buffer::t5() -{ -} diff --git a/gnuradio-runtime/lib/qa_buffer.h b/gnuradio-runtime/lib/qa_buffer.h deleted file mode 100644 index a41e69dd48..0000000000 --- a/gnuradio-runtime/lib/qa_buffer.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_QA_GR_BUFFER_H -#define INCLUDED_QA_GR_BUFFER_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_buffer : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_buffer); - CPPUNIT_TEST(t0); - CPPUNIT_TEST(t1); - CPPUNIT_TEST(t2); - CPPUNIT_TEST(t3); - CPPUNIT_TEST(t4); - CPPUNIT_TEST(t5); - CPPUNIT_TEST_SUITE_END(); - - private: - void t0(); - void t1(); - void t2(); - void t3(); - void t4(); - void t5(); -}; - -#endif /* INCLUDED_QA_GR_BUFFER_H */ diff --git a/gnuradio-runtime/lib/qa_circular_file.cc b/gnuradio-runtime/lib/qa_circular_file.cc index d80831b4b9..06599caaab 100644 --- a/gnuradio-runtime/lib/qa_circular_file.cc +++ b/gnuradio-runtime/lib/qa_circular_file.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2002,2013 Free Software Foundation, Inc. + * Copyright 2002,2013,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,20 +24,15 @@ #include "config.h" #endif -#include "qa_circular_file.h" #include "circular_file.h" -#include <cppunit/TestAssert.h> -#include <iostream> -#include <stdio.h> +#include <boost/test/unit_test.hpp> #include <unistd.h> static const char *test_file = "qa_gr_circular_file.data"; static const int BUFFER_SIZE = 8192; static const int NWRITE = 8192 * 9 / 8; -void -qa_circular_file::t1() -{ +BOOST_AUTO_TEST_CASE(t1) { #ifdef HAVE_MMAP gr::circular_file *cf_writer; gr::circular_file *cf_reader; @@ -58,12 +53,12 @@ qa_circular_file::t1() cf_reader = new gr::circular_file(test_file); for(int i = 0; i < BUFFER_SIZE; i++) { int n = cf_reader->read (&sd, sizeof(sd)); - CPPUNIT_ASSERT_EQUAL((int) sizeof (sd), n); - CPPUNIT_ASSERT_EQUAL(NWRITE - BUFFER_SIZE + i, (int)sd); + BOOST_CHECK_EQUAL((int) sizeof (sd), n); + BOOST_CHECK_EQUAL(NWRITE - BUFFER_SIZE + i, (int)sd); } int n = cf_reader->read(&sd, sizeof(sd)); - CPPUNIT_ASSERT_EQUAL(0, n); + BOOST_CHECK_EQUAL(0, n); delete cf_reader; unlink(test_file); diff --git a/gnuradio-runtime/lib/qa_circular_file.h b/gnuradio-runtime/lib/qa_circular_file.h deleted file mode 100644 index fd5c156b56..0000000000 --- a/gnuradio-runtime/lib/qa_circular_file.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2002,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef QA_GR_CIRCULAR_FILE_H -#define QA_GR_CIRCULAR_FILE_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_circular_file : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_circular_file); - CPPUNIT_TEST(t1); - CPPUNIT_TEST_SUITE_END(); - -private: - void t1(); -}; - -#endif /* QA_GR_CIRCULAR_FILE_H */ diff --git a/gnuradio-runtime/lib/qa_io_signature.cc b/gnuradio-runtime/lib/qa_io_signature.cc index bc3509a260..d09188ed74 100644 --- a/gnuradio-runtime/lib/qa_io_signature.cc +++ b/gnuradio-runtime/lib/qa_io_signature.cc @@ -24,42 +24,37 @@ #include <config.h> #endif -#include <qa_io_signature.h> #include <gnuradio/io_signature.h> +#include <boost/test/unit_test.hpp> +#include <stdexcept> -void -qa_io_signature::t0() -{ - gr::io_signature::make(1, 1, sizeof(int)); +BOOST_AUTO_TEST_CASE(t0) { + gr::io_signature::make(1, 1, sizeof(int)); } -void -qa_io_signature::t1() -{ - gr::io_signature::make(3, 1, sizeof(int)); // throws std::invalid_argument +BOOST_AUTO_TEST_CASE(t1) { + BOOST_REQUIRE_THROW( + gr::io_signature::make(3, 1, sizeof(int)), + std::invalid_argument + ); } -void -qa_io_signature::t2() -{ - gr::io_signature::sptr p = - gr::io_signature::make(3, gr::io_signature::IO_INFINITE, sizeof(int)); +BOOST_AUTO_TEST_CASE(t2) { + gr::io_signature::sptr p = + gr::io_signature::make(3, gr::io_signature::IO_INFINITE, sizeof(int)); - CPPUNIT_ASSERT_EQUAL(p->min_streams(), 3); - CPPUNIT_ASSERT_EQUAL(p->sizeof_stream_item(0), (int)sizeof(int)); + BOOST_CHECK_EQUAL(p->min_streams(), 3); + BOOST_CHECK_EQUAL(p->sizeof_stream_item(0), (int)sizeof(int)); } -void -qa_io_signature::t3() -{ - gr::io_signature::sptr p = - gr::io_signature::make3(0, 5, 1, 2, 3); +BOOST_AUTO_TEST_CASE(t3) { + gr::io_signature::sptr p = gr::io_signature::make3(0, 5, 1, 2, 3); - CPPUNIT_ASSERT_EQUAL(p->min_streams(), 0); - CPPUNIT_ASSERT_EQUAL(p->max_streams(), 5); - CPPUNIT_ASSERT_EQUAL(p->sizeof_stream_item(0), 1); - CPPUNIT_ASSERT_EQUAL(p->sizeof_stream_item(1), 2); - CPPUNIT_ASSERT_EQUAL(p->sizeof_stream_item(2), 3); - CPPUNIT_ASSERT_EQUAL(p->sizeof_stream_item(3), 3); - CPPUNIT_ASSERT_EQUAL(p->sizeof_stream_item(4), 3); + BOOST_CHECK_EQUAL(p->min_streams(), 0); + BOOST_CHECK_EQUAL(p->max_streams(), 5); + BOOST_CHECK_EQUAL(p->sizeof_stream_item(0), 1); + BOOST_CHECK_EQUAL(p->sizeof_stream_item(1), 2); + BOOST_CHECK_EQUAL(p->sizeof_stream_item(2), 3); + BOOST_CHECK_EQUAL(p->sizeof_stream_item(3), 3); + BOOST_CHECK_EQUAL(p->sizeof_stream_item(4), 3); } diff --git a/gnuradio-runtime/lib/qa_io_signature.h b/gnuradio-runtime/lib/qa_io_signature.h deleted file mode 100644 index 981ad03b59..0000000000 --- a/gnuradio-runtime/lib/qa_io_signature.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_QA_GR_IO_SIGNATURE_H -#define INCLUDED_QA_GR_IO_SIGNATURE_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> -#include <stdexcept> - -class qa_io_signature : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_io_signature); - CPPUNIT_TEST(t0); - CPPUNIT_TEST_EXCEPTION(t1, std::invalid_argument); - CPPUNIT_TEST(t2); - CPPUNIT_TEST(t3); - CPPUNIT_TEST_SUITE_END(); - - private: - void t0(); - void t1(); - void t2(); - void t3(); -}; - -#endif /* INCLUDED_QA_GR_IO_SIGNATURE_H */ diff --git a/gnuradio-runtime/lib/qa_logger.cc b/gnuradio-runtime/lib/qa_logger.cc index 20d7392143..dc47b53cef 100644 --- a/gnuradio-runtime/lib/qa_logger.cc +++ b/gnuradio-runtime/lib/qa_logger.cc @@ -1,5 +1,5 @@ /* - * Copyright 2012 Free Software Foundation, Inc. + * Copyright 2012, 2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -29,12 +29,14 @@ #include <config.h> #endif -#include <qa_logger.h> #include <gnuradio/logger.h> +#include <boost/test/unit_test.hpp> + +BOOST_AUTO_TEST_CASE(t1) { +#ifdef ENABLE_GR_LOG + // This doesn't really test anything, more just + // making sure nothing's gone horribly wrong. -void -qa_logger::t1() -{ GR_LOG_GETLOGGER(LOG,"main"); GR_ADD_CONSOLE_APPENDER("main","cout","%d{%H:%M:%S} : %m%n"); GR_LOG_NOTICE(LOG,"test from c++ NOTICE"); @@ -43,5 +45,6 @@ qa_logger::t1() GR_LOG_WARN(LOG,"test from c++ WARN"); GR_LOG_ERROR(LOG,"test from c++ ERROR"); GR_LOG_FATAL(LOG,"test from c++ FATAL"); - CPPUNIT_ASSERT(true); + BOOST_CHECK(true); +#endif } diff --git a/gnuradio-runtime/lib/qa_logger.h b/gnuradio-runtime/lib/qa_logger.h deleted file mode 100644 index 2e237eebf8..0000000000 --- a/gnuradio-runtime/lib/qa_logger.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU Example Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Example Public License for more details. - * - * You should have received a copy of the GNU Example Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_QA_GR_LOG_H -#define INCLUDED_QA_GR_LOG_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestSuite.h> - -//! collect all the tests for the example directory - -class qa_logger : public CppUnit::TestCase -{ -public: - CPPUNIT_TEST_SUITE(qa_logger); - CPPUNIT_TEST(t1); - CPPUNIT_TEST_SUITE_END(); - - private: - void t1(); -}; - -#endif /* INCLUDED_QA_GR_LOG_H */ diff --git a/gnuradio-runtime/lib/qa_runtime.cc b/gnuradio-runtime/lib/qa_runtime.cc deleted file mode 100644 index 886ef0d476..0000000000 --- a/gnuradio-runtime/lib/qa_runtime.cc +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2002,2007,2011 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -/* - * This class gathers together all the test cases for the gr - * directory into a single test suite. As you create new test cases, - * add them here. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <qa_runtime.h> -#include <qa_buffer.h> -#include <qa_io_signature.h> -#include <qa_circular_file.h> -#include <qa_fxpt.h> -#include <qa_fxpt_nco.h> -#include <qa_fxpt_vco.h> -#include <qa_logger.h> -#include <qa_math.h> -#include <qa_vmcircbuf.h> -#include <qa_sincos.h> -#include <qa_fast_atan2f.h> - -CppUnit::TestSuite * -qa_runtime::suite() -{ - CppUnit::TestSuite *s = new CppUnit::TestSuite("runtime"); - - s->addTest(qa_buffer::suite()); - s->addTest(qa_io_signature::suite()); - s->addTest(qa_circular_file::suite()); - s->addTest(qa_fxpt::suite()); - s->addTest(qa_fxpt_nco::suite()); - s->addTest(qa_fxpt_vco::suite()); - s->addTest(qa_logger::suite()); - s->addTest(qa_math::suite()); - s->addTest(qa_vmcircbuf::suite()); - s->addTest(qa_sincos::suite()); - s->addTest(qa_fast_atan2f::suite()); - - return s; -} diff --git a/gnuradio-runtime/lib/qa_runtime.h b/gnuradio-runtime/lib/qa_runtime.h deleted file mode 100644 index a1e58190d6..0000000000 --- a/gnuradio-runtime/lib/qa_runtime.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2002 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef _QA_RUNTIME_H_ -#define _QA_RUNTIME_H_ - -#include <gnuradio/attributes.h> -#include <cppunit/TestSuite.h> - -//! collect all the tests for the runtime directory - -class __GR_ATTR_EXPORT qa_runtime { - public: - //! return suite of tests for all of runtime directory - static CppUnit::TestSuite *suite (); -}; - - -#endif /* _QA_RUNTIME_H_ */ diff --git a/gnuradio-runtime/lib/qa_vmcircbuf.cc b/gnuradio-runtime/lib/qa_vmcircbuf.cc index 7301b4cf17..4b8b8273fb 100644 --- a/gnuradio-runtime/lib/qa_vmcircbuf.cc +++ b/gnuradio-runtime/lib/qa_vmcircbuf.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2002,2013 Free Software Foundation, Inc. + * Copyright 2002,2013,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,17 +24,11 @@ #include <config.h> #endif -#include <qa_vmcircbuf.h> -#include <cppunit/TestAssert.h> #include "vmcircbuf.h" -#include <stdio.h> +#include <boost/test/unit_test.hpp> -void -qa_vmcircbuf::test_all() -{ +BOOST_AUTO_TEST_CASE(test_all) { int verbose = 1; // summary - bool ok = gr::vmcircbuf_sysconfig::test_all_factories(verbose); - - CPPUNIT_ASSERT_EQUAL(true, ok); + BOOST_REQUIRE(gr::vmcircbuf_sysconfig::test_all_factories(verbose)); } diff --git a/gnuradio-runtime/lib/qa_vmcircbuf.h b/gnuradio-runtime/lib/qa_vmcircbuf.h deleted file mode 100644 index 93f46cf4a8..0000000000 --- a/gnuradio-runtime/lib/qa_vmcircbuf.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef QA_GR_VMCIRCBUF_H -#define QA_GR_VMCIRCBUF_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_vmcircbuf : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_vmcircbuf); - CPPUNIT_TEST(test_all); - CPPUNIT_TEST_SUITE_END(); - -private: - void test_all(); -}; - -#endif /* QA_GR_VMCIRCBUF_H */ diff --git a/gnuradio-runtime/lib/test_runtime.cc b/gnuradio-runtime/lib/test_runtime.cc deleted file mode 100644 index 6f75bcc1b1..0000000000 --- a/gnuradio-runtime/lib/test_runtime.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2002,2010,2011 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <cppunit/TextTestRunner.h> -#include <cppunit/XmlOutputter.h> - -#include <gnuradio/unittests.h> -#include <qa_runtime.h> -#include <fstream> - -int -main (int argc, char **argv) -{ - CppUnit::TextTestRunner runner; - std::ofstream xmlfile(get_unittest_path("gnuradio_runtime_runtime.xml").c_str()); - CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile); - - runner.addTest(qa_runtime::suite()); - runner.setOutputter(xmlout); - - bool was_successful = runner.run("", false); - - return was_successful ? 0 : 1; -} diff --git a/gnuradio-runtime/lib/thread/thread.cc b/gnuradio-runtime/lib/thread/thread.cc index f2606c71ae..4db91d4dbe 100644 --- a/gnuradio-runtime/lib/thread/thread.cc +++ b/gnuradio-runtime/lib/thread/thread.cc @@ -166,7 +166,7 @@ namespace gr { #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) || \ - defined(__FreeBSD__) + defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__GNU__) namespace gr { namespace thread { diff --git a/gnuradio-runtime/lib/tpb_thread_body.cc b/gnuradio-runtime/lib/tpb_thread_body.cc index 404d9a0055..fa9de60ae3 100644 --- a/gnuradio-runtime/lib/tpb_thread_body.cc +++ b/gnuradio-runtime/lib/tpb_thread_body.cc @@ -64,10 +64,10 @@ namespace gr { GR_CONFIG_LOGGER(config_file); if(log_file.size() > 0) { if(log_file == "stdout") { - GR_LOG_SET_CONSOLE_APPENDER(LOG, "cout","gr::log :%p: %c{1} - %m%n"); + GR_LOG_SET_CONSOLE_APPENDER(LOG, "stdout","gr::log :%p: %c{1} - %m%n"); } else if(log_file == "stderr") { - GR_LOG_SET_CONSOLE_APPENDER(LOG, "cerr","gr::log :%p: %c{1} - %m%n"); + GR_LOG_SET_CONSOLE_APPENDER(LOG, "stderr","gr::log :%p: %c{1} - %m%n"); } else { GR_LOG_SET_FILE_APPENDER(LOG, log_file , true,"%r :%p: %c{1} - %m%n"); diff --git a/gnuradio-runtime/python/gnuradio/eng_notation.py b/gnuradio-runtime/python/gnuradio/eng_notation.py index 5a3a216ee4..391dc5838f 100644 --- a/gnuradio-runtime/python/gnuradio/eng_notation.py +++ b/gnuradio-runtime/python/gnuradio/eng_notation.py @@ -37,29 +37,30 @@ scale_factor['p'] = 1e-12 scale_factor['f'] = 1e-15 scale_factor['a'] = 1e-18 -def num_to_str (n): +def num_to_str (n, precision=6): '''Convert a number to a string in engineering notation. E.g., 5e-9 -> 5n''' m = abs(n) + format_spec = '%.' + repr(int(precision)) + 'g' if m >= 1e9: - return "%gG" % (n * 1e-9) + return '%sG' % float(format_spec % (n * 1e-9)) elif m >= 1e6: - return "%gM" % (n * 1e-6) + return '%sM' % float(format_spec % (n * 1e-6)) elif m >= 1e3: - return "%gk" % (n * 1e-3) + return '%sk' % float(format_spec % (n * 1e-3)) elif m >= 1: - return "%g" % (n) + return '%s' % float(format_spec % (n)) elif m >= 1e-3: - return "%gm" % (n * 1e3) + return '%sm' % float(format_spec % (n * 1e3)) elif m >= 1e-6: - return "%gu" % (n * 1e6) # where's that mu when you need it (unicode?) + return '%su' % float(format_spec % (n * 1e6)) elif m >= 1e-9: - return "%gn" % (n * 1e9) + return '%sn' % float(format_spec % (n * 1e9)) elif m >= 1e-12: - return "%gp" % (n * 1e12) + return '%sp' % float(format_spec % (n * 1e12)) elif m >= 1e-15: - return "%gf" % (n * 1e15) + return '%sf' % float(format_spec % (n * 1e15)) else: - return "%g" % (n) + return '%s' % float(format_spec % (n)) def str_to_num (value): diff --git a/gnuradio-runtime/python/gnuradio/gr/CMakeLists.txt b/gnuradio-runtime/python/gnuradio/gr/CMakeLists.txt index 7c82b1df35..1b535ef997 100644 --- a/gnuradio-runtime/python/gnuradio/gr/CMakeLists.txt +++ b/gnuradio-runtime/python/gnuradio/gr/CMakeLists.txt @@ -44,6 +44,11 @@ if(ENABLE_TESTING) set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/gruel/src/python ${CMAKE_BINARY_DIR}/gnuradio-runtime/python + ${CMAKE_BINARY_DIR}/gnuradio-runtime/swig + ${CMAKE_BINARY_DIR}/gr-blocks/swig + ${CMAKE_BINARY_DIR}/gr-fft/swig + ${CMAKE_BINARY_DIR}/gr-filter/swig + ${CMAKE_BINARY_DIR}/gr-analog/swig ) include(GrTest) file(GLOB py_qa_test_files "qa_*.py") diff --git a/gnuradio-runtime/python/gnuradio/gr/__init__.py b/gnuradio-runtime/python/gnuradio/gr/__init__.py index 72f54e9f42..6ec5074fff 100644 --- a/gnuradio-runtime/python/gnuradio/gr/__init__.py +++ b/gnuradio-runtime/python/gnuradio/gr/__init__.py @@ -1,5 +1,5 @@ # -# Copyright 2003-2012 Free Software Foundation, Inc. +# Copyright 2003-2012, 2018 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -46,7 +46,7 @@ from .exceptions import * from .top_block import * from .hier_block2 import * from .tag_utils import * -from .gateway import basic_block, sync_block, decim_block, interp_block +from .gateway import basic_block, sync_block, decim_block, interp_block, py_io_signature # Force the preference database to be initialized prefs = prefs.singleton diff --git a/gnuradio-runtime/python/gnuradio/gr/gateway.py b/gnuradio-runtime/python/gnuradio/gr/gateway.py index 1acf900f84..4eaa8745ac 100644 --- a/gnuradio-runtime/python/gnuradio/gr/gateway.py +++ b/gnuradio-runtime/python/gnuradio/gr/gateway.py @@ -1,5 +1,5 @@ # -# Copyright 2011-2012 Free Software Foundation, Inc. +# Copyright 2011-2012, 2018 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -83,35 +83,89 @@ class msg_handler(gr.feval_p): return 0 ######################################################################## +# io_signature for Python +######################################################################## +class py_io_signature(object): + """ + Describes the type/number of ports for block input or output. + """ + + # Minimum and maximum number of ports, and a list of numpy types. + def __init__(self, min_ports, max_ports, type_list): + """ + Args: + + min_ports (int): mininum number of connected ports. + + max_ports (int): maximum number of connected ports. -1 indicates + no limit. + + type_list (list[str]): numpy type names for each port. If the + number of connected ports is greater than the number of types + provided, the last type in the list is repeated. + """ + self.__min_ports = min_ports + self.__max_ports = max_ports + self.__types = tuple( numpy.dtype(t) for t in type_list ) + + def gr_io_signature(self): + """ + Make/return a gr.io_signature. A non-empty list of sizes is + required, even if there are no ports. + """ + return io_signaturev(self.__min_ports, self.__max_ports, + [t.itemsize for t in self.__types] or [0]) + + def port_types(self, nports): + """ + Return data types for the first nports ports. If nports is + smaller than the provided type list, return a truncated list. If + larger, fill with the last type. + """ + ntypes = len(self.__types) + if ntypes == 0: + return () + if nports <= ntypes: + return self.__types[:nports] + return self.__types + [self.__types[-1]]*(nports-ntypes) + + def __iter__(self): + """ + Return the iterator over the maximum ports type list. + """ + return iter(self.port_types(self.__max_ports)) + + def __hash__(self): + return hash((self.__min_ports, self.__max_ports, self.__types)) + +######################################################################## # The guts that make this into a gr block ######################################################################## class gateway_block(object): def __init__(self, name, in_sig, out_sig, work_type, factor): - #ensure that the sigs are iterable dtypes - def sig_to_dtype_sig(sig): - if sig is None: sig = () - return list(map(numpy.dtype, sig)) - self.__in_sig = sig_to_dtype_sig(in_sig) - self.__out_sig = sig_to_dtype_sig(out_sig) - - #cache the ranges to iterate when dispatching work - self.__in_indexes = list(range(len(self.__in_sig))) - self.__out_indexes = list(range(len(self.__out_sig))) + # Normalize the many Python ways of saying 'nothing' to '()' + in_sig = in_sig or () + out_sig = out_sig or () - #convert the signatures into gr.io_signatures - def sig_to_gr_io_sigv(sig): - if not len(sig): return io_signature(0, 0, 0) - return io_signaturev(len(sig), len(sig), [s.itemsize for s in sig]) - gr_in_sig = sig_to_gr_io_sigv(self.__in_sig) - gr_out_sig = sig_to_gr_io_sigv(self.__out_sig) + # Backward compatibility: array of type strings -> py_io_signature + if type(in_sig) is py_io_signature: + self.__in_sig = in_sig + else: + self.__in_sig = py_io_signature(len(in_sig), len(in_sig), in_sig) + if type(out_sig) is py_io_signature: + self.__out_sig = out_sig + else: + self.__out_sig = py_io_signature(len(out_sig), len(out_sig), out_sig) #create internal gateway block self.__handler = gateway_handler() self.__handler.init(self.__gr_block_handle) self.__gateway = block_gateway( - self.__handler, name, gr_in_sig, gr_out_sig, work_type, factor) + self.__handler, name, + self.__in_sig.gr_io_signature(), self.__out_sig.gr_io_signature(), + work_type, factor) self.__message = self.__gateway.block_message() #dict to keep references to all message handlers @@ -133,36 +187,47 @@ class gateway_block(object): """ Dispatch tasks according to the action type specified in the message. """ + if self.__message.action == gr.block_gw_message_type.ACTION_GENERAL_WORK: + # Actual number of inputs/output from scheduler + ninputs = len(self.__message.general_work_args_input_items) + noutputs = len(self.__message.general_work_args_output_items) + in_types = self.__in_sig.port_types(ninputs) + out_types = self.__out_sig.port_types(noutputs) self.__message.general_work_args_return_value = self.general_work( input_items=[pointer_to_ndarray( self.__message.general_work_args_input_items[i], - self.__in_sig[i], + in_types[i], self.__message.general_work_args_ninput_items[i] - ) for i in self.__in_indexes], + ) for i in range(ninputs)], output_items=[pointer_to_ndarray( self.__message.general_work_args_output_items[i], - self.__out_sig[i], + out_types[i], self.__message.general_work_args_noutput_items - ) for i in self.__out_indexes], + ) for i in range(noutputs)], ) elif self.__message.action == gr.block_gw_message_type.ACTION_WORK: + # Actual number of inputs/output from scheduler + ninputs = len(self.__message.work_args_input_items) + noutputs = len(self.__message.work_args_output_items) + in_types = self.__in_sig.port_types(ninputs) + out_types = self.__out_sig.port_types(noutputs) self.__message.work_args_return_value = self.work( input_items=[pointer_to_ndarray( self.__message.work_args_input_items[i], - self.__in_sig[i], + in_types[i], self.__message.work_args_ninput_items - ) for i in self.__in_indexes], + ) for i in range(ninputs)], output_items=[pointer_to_ndarray( self.__message.work_args_output_items[i], - self.__out_sig[i], + out_types[i], self.__message.work_args_noutput_items - ) for i in self.__out_indexes], + ) for i in range(noutputs)], ) elif self.__message.action == gr.block_gw_message_type.ACTION_FORECAST: @@ -217,6 +282,17 @@ class gateway_block(object): # Wrappers for the user to inherit from ######################################################################## class basic_block(gateway_block): + """Args: + name (str): block name + + in_sig (gr.py_io_signature): input port signature + + out_sig (gr.py_io_signature): output port signature + + For backward compatibility, a sequence of numpy type names is also + accepted as an io signature. + + """ def __init__(self, name, in_sig, out_sig): gateway_block.__init__(self, name=name, @@ -227,6 +303,17 @@ class basic_block(gateway_block): ) class sync_block(gateway_block): + """ + Args: + name (str): block name + + in_sig (gr.py_io_signature): input port signature + + out_sig (gr.py_io_signature): output port signature + + For backward compatibility, a sequence of numpy type names is also + accepted as an io signature. + """ def __init__(self, name, in_sig, out_sig): gateway_block.__init__(self, name=name, @@ -237,6 +324,17 @@ class sync_block(gateway_block): ) class decim_block(gateway_block): + """ + Args: + name (str): block name + + in_sig (gr.py_io_signature): input port signature + + out_sig (gr.py_io_signature): output port signature + + For backward compatibility, a sequence of numpy type names is also + accepted as an io signature. + """ def __init__(self, name, in_sig, out_sig, decim): gateway_block.__init__(self, name=name, @@ -247,6 +345,17 @@ class decim_block(gateway_block): ) class interp_block(gateway_block): + """ + Args: + name (str): block name + + in_sig (gr.py_io_signature): input port signature + + out_sig (gr.py_io_signature): output port signature + + For backward compatibility, a sequence of numpy type names is also + accepted as an io signature. + """ def __init__(self, name, in_sig, out_sig, interp): gateway_block.__init__(self, name=name, diff --git a/gnuradio-runtime/python/gnuradio/gr_unittest.py b/gnuradio-runtime/python/gnuradio/gr_unittest.py index 1b8323ad7a..190ea63354 100644 --- a/gnuradio-runtime/python/gnuradio/gr_unittest.py +++ b/gnuradio-runtime/python/gnuradio/gr_unittest.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2004,2010 Free Software Foundation, Inc. +# Copyright 2004,2010,2018 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -33,6 +33,7 @@ import unittest from . import gr_xmlrunner + class TestCase(unittest.TestCase): """A subclass of unittest.TestCase that adds additional assertions @@ -121,7 +122,8 @@ TextTestRunner = unittest.TextTestRunner TestProgram = unittest.TestProgram main = TestProgram -def run(PUT, filename=None): + +def run(PUT, filename=None, verbosity=1): ''' Runs the unittest on a TestCase and produces an optional XML report PUT: the program under test and should be a gr_unittest.TestCase @@ -152,7 +154,7 @@ def run(PUT, filename=None): fout = open(path+"/"+filename, "w") xmlrunner = gr_xmlrunner.XMLTestRunner(fout) - txtrunner = TextTestRunner(verbosity=1) + txtrunner = TextTestRunner(verbosity=verbosity) # Run the test; runner also creates XML output file # FIXME: make xmlrunner output to screen so we don't have to do run and main @@ -162,7 +164,7 @@ def run(PUT, filename=None): if xmlrunner is not None: xmlrunner.run(suite) - main() + main(verbosity=verbosity) # This will run and fail make check if problem # but does not output to screen. @@ -170,7 +172,7 @@ def run(PUT, filename=None): else: # If no filename is given, just run the test - main() + main(verbosity=verbosity) ############################################################################## diff --git a/gnuradio-runtime/python/pmt/CMakeLists.txt b/gnuradio-runtime/python/pmt/CMakeLists.txt index 7afac956cb..e635663924 100644 --- a/gnuradio-runtime/python/pmt/CMakeLists.txt +++ b/gnuradio-runtime/python/pmt/CMakeLists.txt @@ -39,6 +39,7 @@ foreach(py_qa_test_file ${py_qa_test_files}) set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/gnuradio-runtime/python ${CMAKE_BINARY_DIR}/gnuradio-runtime/swig + ${CMAKE_BINARY_DIR}/gnuradio-blocks/swig ) set(GR_TEST_TARGET_DEPS gnuradio-runtime) GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} -B ${py_qa_test_file}) diff --git a/gnuradio-runtime/swig/block.i b/gnuradio-runtime/swig/block.i index 64500575fb..808e62f9dd 100644 --- a/gnuradio-runtime/swig/block.i +++ b/gnuradio-runtime/swig/block.i @@ -48,8 +48,11 @@ class gr::block : public gr::basic_block void declare_sample_delay(unsigned int delay); unsigned sample_delay(int which) const; + void set_output_multiple(int multiple); int output_multiple () const; double relative_rate () const; + uint64_t relative_rate_i () const; + uint64_t relative_rate_d () const; bool start(); bool stop(); |