diff options
-rw-r--r-- | config/ax_boost_unit_test_framework.m4 | 132 | ||||
-rw-r--r-- | configure.ac | 44 | ||||
-rw-r--r-- | include/usrp_uhd/usrp/dboard/base.hpp | 4 | ||||
-rw-r--r-- | lib/device_addr.cpp | 11 | ||||
-rw-r--r-- | lib/usrp/dboard/base.cpp | 5 | ||||
-rw-r--r-- | test/Makefile.am | 12 | ||||
-rw-r--r-- | test/addr_test.cpp | 26 | ||||
-rw-r--r-- | test/cppunit_test.cpp | 25 | ||||
-rw-r--r-- | test/device_test.cpp | 22 | ||||
-rw-r--r-- | test/main_test.cpp | 3 | ||||
-rw-r--r-- | test/usrp_dboard_test.cpp | 26 | ||||
-rw-r--r-- | test/wax_test.cpp | 32 |
12 files changed, 210 insertions, 132 deletions
diff --git a/config/ax_boost_unit_test_framework.m4 b/config/ax_boost_unit_test_framework.m4 new file mode 100644 index 000000000..062ed72fb --- /dev/null +++ b/config/ax_boost_unit_test_framework.m4 @@ -0,0 +1,132 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/ax_boost_unit_test_framework.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_BOOST_UNIT_TEST_FRAMEWORK +# +# DESCRIPTION +# +# Test for Unit_Test_Framework library from the Boost C++ libraries. The +# macro requires a preceding call to AX_BOOST_BASE. Further documentation +# is available at <http://randspringer.de/boost/index.html>. +# +# This macro calls: +# +# AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) +# +# And sets: +# +# HAVE_BOOST_UNIT_TEST_FRAMEWORK +# +# LICENSE +# +# Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +AC_DEFUN([AX_BOOST_UNIT_TEST_FRAMEWORK], +[ + AC_ARG_WITH([boost-unit-test-framework], + AS_HELP_STRING([--with-boost-unit-test-framework@<:@=special-lib@:>@], + [use the Unit_Test_Framework library from boost - it is possible to specify a certain library for the linker + e.g. --with-boost-unit-test-framework=boost_unit_test_framework-gcc ]), + [ + if test "$withval" = "no"; then + want_boost="no" + elif test "$withval" = "yes"; then + want_boost="yes" + ax_boost_user_unit_test_framework_lib="" + else + want_boost="yes" + ax_boost_user_unit_test_framework_lib="$withval" + fi + ], + [want_boost="yes"] + ) + + if test "x$want_boost" = "xyes"; then + AC_REQUIRE([AC_PROG_CC]) + CPPFLAGS_SAVED="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + + LDFLAGS_SAVED="$LDFLAGS" + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + AC_CACHE_CHECK(whether the Boost::Unit_Test_Framework library is available, + ax_cv_boost_unit_test_framework, + [AC_LANG_PUSH([C++]) + AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/test/unit_test.hpp>]], + [[using boost::unit_test::test_suite; + test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" ); return 0;]]), + ax_cv_boost_unit_test_framework=yes, ax_cv_boost_unit_test_framework=no) + AC_LANG_POP([C++]) + ]) + if test "x$ax_cv_boost_unit_test_framework" = "xyes"; then + AC_DEFINE(HAVE_BOOST_UNIT_TEST_FRAMEWORK,,[define if the Boost::Unit_Test_Framework library is available]) + BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` + + if test "x$ax_boost_user_unit_test_framework_lib" = "x"; then + saved_ldflags="${LDFLAGS}" + for monitor_library in `ls $BOOSTLIBDIR/libboost_unit_test_framework*.{so,a}* 2>/dev/null` ; do + if test -r $monitor_library ; then + libextension=`echo $monitor_library | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a*$;\1;'` + ax_lib=${libextension} + link_unit_test_framework="yes" + else + link_unit_test_framework="no" + fi + + if test "x$link_unit_test_framework" = "xyes"; then + BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib" + AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) + break + fi + done + if test "x$link_unit_test_framework" != "xyes"; then + for libextension in `ls $BOOSTLIBDIR/boost_unit_test_framework*.{dll,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_unit_test_framework.*\)\.dll.*$;\1;' -e 's;^\(boost_unit_test_framework.*\)\.a*$;\1;'` ; do + ax_lib=${libextension} + AC_CHECK_LIB($ax_lib, exit, + [BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"; AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) link_unit_test_framework="yes"; break], + [link_unit_test_framework="no"]) + done + fi + else + link_unit_test_framework="no" + saved_ldflags="${LDFLAGS}" + for ax_lib in boost_unit_test_framework-$ax_boost_user_unit_test_framework_lib $ax_boost_user_unit_test_framework_lib ; do + if test "x$link_unit_test_framework" = "xyes"; then + break; + fi + for unittest_library in `ls $BOOSTLIBDIR/lib${ax_lib}.{so,a}* 2>/dev/null` ; do + if test -r $unittest_library ; then + libextension=`echo $unittest_library | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a*$;\1;'` + ax_lib=${libextension} + link_unit_test_framework="yes" + else + link_unit_test_framework="no" + fi + + if test "x$link_unit_test_framework" = "xyes"; then + BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib" + AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) + break + fi + done + done + fi + if test "x$link_unit_test_framework" != "xyes"; then + AC_MSG_ERROR(Could not link against $ax_lib !) + fi + fi + + CPPFLAGS="$CPPFLAGS_SAVED" + LDFLAGS="$LDFLAGS_SAVED" + fi +]) diff --git a/configure.ac b/configure.ac index c31aa363f..f2ccce656 100644 --- a/configure.ac +++ b/configure.ac @@ -10,23 +10,53 @@ AC_INIT AM_INIT_AUTOMAKE(usrp_uhd, 0) ################################################## -## Check Libs +## Setup C++ and Libtool ################################################## AC_PROG_CXX LT_INIT -AX_BOOST_BASE([1.36], [], AC_MSG_ERROR("cannot find boost")) -AX_BOOST_ASIO -AX_BOOST_THREAD +################################################## +## Check Boost +################################################## +AC_DEFUN([UHD_CHECK_BOOST],[$1 + AC_LANG_PUSH([C++]) + AC_COMPILE_IFELSE(AC_LANG_PROGRAM( + [[@%:@include <boost/static_assert.hpp>]], + [[ + #ifdef $2 + BOOST_STATIC_ASSERT(true); + #else + BOOST_STATIC_ASSERT(false); + #endif + return 0; + ]] + ), [$3], [$4]) + AC_LANG_POP([C++]) +]) -AM_PATH_CPPUNIT([1.9.6], [HAVE_CPPUNIT=true], [HAVE_CPPUNIT=false]) -AM_CONDITIONAL([HAVE_CPPUNIT], [$HAVE_CPPUNIT]) +UHD_CHECK_BOOST( + [AX_BOOST_BASE([1.36])], [HAVE_BOOST], + [], [AC_MSG_ERROR("cannot find boost")] +) +UHD_CHECK_BOOST( + [AX_BOOST_ASIO], [HAVE_BOOST_ASIO], + [], [AC_MSG_ERROR("cannot find boost asio")] +) +UHD_CHECK_BOOST( + [AX_BOOST_THREAD], [HAVE_BOOST_THREAD], + [], [AC_MSG_ERROR("cannot find boost thread")] +) +UHD_CHECK_BOOST( + [AX_BOOST_UNIT_TEST_FRAMEWORK], [HAVE_BOOST_UNIT_TEST_FRAMEWORK], + [HAVE_UNIT_TEST=true], [HAVE_UNIT_TEST=false] +) +AM_CONDITIONAL([HAVE_UNIT_TEST], [$HAVE_UNIT_TEST]) ################################################## ## Check Headers ################################################## AC_DEFUN([UHD_CHECK_HEADER],[ - AC_CHECK_HEADER([$1], [], AC_MSG_ERROR("cannot find header $1")) + AC_CHECK_HEADER([$1], [], [AC_MSG_ERROR("cannot find header $1")]) ]) UHD_CHECK_HEADER([arpa/inet.h]) diff --git a/include/usrp_uhd/usrp/dboard/base.hpp b/include/usrp_uhd/usrp/dboard/base.hpp index 82895ed59..0c207f564 100644 --- a/include/usrp_uhd/usrp/dboard/base.hpp +++ b/include/usrp_uhd/usrp/dboard/base.hpp @@ -27,7 +27,7 @@ public: //structors base(ctor_args_t const&); - ~base(void); + virtual ~base(void); //interface virtual void rx_get(const wax::type &key, wax::type &val) = 0; @@ -54,7 +54,7 @@ public: * Create a new xcvr dboard object, override in subclasses. */ xcvr_base(ctor_args_t const&); - ~xcvr_base(void); + virtual ~xcvr_base(void); }; /*! diff --git a/lib/device_addr.cpp b/lib/device_addr.cpp index b28082069..8f14a6ec1 100644 --- a/lib/device_addr.cpp +++ b/lib/device_addr.cpp @@ -10,7 +10,9 @@ #include <boost/algorithm/string.hpp> //----------------------- u2 mac addr wrapper ------------------------// -usrp_uhd::mac_addr_t::mac_addr_t(const std::string &mac_addr_str){ +usrp_uhd::mac_addr_t::mac_addr_t(const std::string &mac_addr_str_){ + std::string mac_addr_str = (mac_addr_str_ == "")? "ff:ff:ff:ff:ff:ff" : mac_addr_str_; + //ether_aton_r(str.c_str(), &mac_addr); uint8_t p[6] = {0x00, 0x50, 0xC2, 0x85, 0x30, 0x00}; // Matt's IAB @@ -56,7 +58,8 @@ std::ostream& operator<<(std::ostream &os, const usrp_uhd::mac_addr_t &x){ } //----------------------- u2 ipv4 wrapper ----------------------------// -usrp_uhd::ip_addr_t::ip_addr_t(const std::string &ip_addr_str){ +usrp_uhd::ip_addr_t::ip_addr_t(const std::string &ip_addr_str_){ + std::string ip_addr_str = (ip_addr_str_ == "")? "255.255.255.255" : ip_addr_str_; int ret = inet_pton(AF_INET, ip_addr_str.c_str(), &ip_addr); if (ret == 0) throw std::runtime_error("Invalid ip address: " + ip_addr_str); } @@ -81,8 +84,8 @@ usrp_uhd::device_addr_t::device_addr_t(device_addr_type_t device_addr_type){ usb_args.vendor_id = 0xffff; usb_args.product_id = 0xffff; eth_args.ifc = "eth0"; - eth_args.mac_addr = "ff:ff:ff:ff:ff:ff"; - udp_args.addr = "255.255.255.255"; + eth_args.mac_addr = ""; + udp_args.addr = ""; discovery_args.mboard_id = ~0; } diff --git a/lib/usrp/dboard/base.cpp b/lib/usrp/dboard/base.cpp index d8a6e66c2..c80cdadeb 100644 --- a/lib/usrp/dboard/base.cpp +++ b/lib/usrp/dboard/base.cpp @@ -9,9 +9,8 @@ using namespace usrp_uhd::usrp::dboard; /*********************************************************************** * base dboard base class **********************************************************************/ -base::base(ctor_args_t const& args) - : _subdev_index(args.get<0>()), _dboard_interface(args.get<1>()){ - /* NOP */ +base::base(ctor_args_t const& args){ + boost::tie(_subdev_index, _dboard_interface) = args; } base::~base(void){ diff --git a/test/Makefile.am b/test/Makefile.am index 0fbb18bf8..46b1de0e6 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -6,7 +6,7 @@ include $(top_srcdir)/Makefile.common SUBDIRS = -if HAVE_CPPUNIT +if HAVE_UNIT_TEST AM_CPPFLAGS = \ $(GENERAL_CPPFLAGS) \ @@ -14,15 +14,15 @@ AM_CPPFLAGS = \ LDADD = \ $(GENERAL_LDDFLAGS) \ - $(USRP_UHD_LA) \ - $(CPPUNIT_LIBS) + $(BOOST_UNIT_TEST_FRAMEWORK_LIB) \ + $(USRP_UHD_LA) -noinst_PROGRAMS = cppunit_test +noinst_PROGRAMS = main_test -cppunit_test_SOURCES = \ +main_test_SOURCES = \ + main_test.cpp \ addr_test.cpp \ device_test.cpp \ - cppunit_test.cpp \ usrp_dboard_test.cpp \ wax_test.cpp diff --git a/test/addr_test.cpp b/test/addr_test.cpp index 65792aabc..e2fc36f38 100644 --- a/test/addr_test.cpp +++ b/test/addr_test.cpp @@ -2,39 +2,23 @@ // Copyright 2010 Ettus Research LLC // +#include <boost/test/unit_test.hpp> #include <usrp_uhd/device_addr.hpp> -#include <cppunit/extensions/HelperMacros.h> -/*********************************************************************** - * cpp unit setup - **********************************************************************/ -class addr_test : public CppUnit::TestFixture{ - CPPUNIT_TEST_SUITE(addr_test); - CPPUNIT_TEST(test_mac_addr); - CPPUNIT_TEST(test_ip_addr); - CPPUNIT_TEST_SUITE_END(); - -public: - void test_mac_addr(void); - void test_ip_addr(void); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(addr_test); - -void addr_test::test_mac_addr(void){ +BOOST_AUTO_TEST_CASE(test_mac_addr){ std::cout << "Testing mac addr..." << std::endl; const std::string mac_addr_str("00:01:23:45:67:89"); usrp_uhd::mac_addr_t mac_addr(mac_addr_str); std::cout << "Input: " << mac_addr_str << std::endl; std::cout << "Output: " << mac_addr << std::endl; - CPPUNIT_ASSERT_EQUAL(mac_addr_str, mac_addr.to_string()); + BOOST_CHECK_EQUAL(mac_addr_str, mac_addr.to_string()); } -void addr_test::test_ip_addr(void){ +BOOST_AUTO_TEST_CASE(test_ip_addr){ std::cout << "Testing ip addr..." << std::endl; const std::string ip_addr_str("192.168.1.10"); usrp_uhd::ip_addr_t ip_addr(ip_addr_str); std::cout << "Input: " << ip_addr_str << std::endl; std::cout << "Output: " << ip_addr << std::endl; - CPPUNIT_ASSERT_EQUAL(ip_addr_str, ip_addr.to_string()); + BOOST_CHECK_EQUAL(ip_addr_str, ip_addr.to_string()); } diff --git a/test/cppunit_test.cpp b/test/cppunit_test.cpp deleted file mode 100644 index d4bfff9db..000000000 --- a/test/cppunit_test.cpp +++ /dev/null @@ -1,25 +0,0 @@ -//http://cppunit.sourceforge.net/doc/lastest/money_example.html - -#include <cppunit/CompilerOutputter.h> -#include <cppunit/extensions/TestFactoryRegistry.h> -#include <cppunit/ui/text/TestRunner.h> - - -int main(int, char* []) -{ - // Get the top level suite from the registry - CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); - - // Adds the test to the list of test to run - CppUnit::TextUi::TestRunner runner; - runner.addTest( suite ); - - // Change the default outputter to a compiler error format outputter - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - // Run the tests. - bool wasSucessful = runner.run(); - - // Return error code 1 if the one of test failed. - return wasSucessful ? 0 : 1; -} diff --git a/test/device_test.cpp b/test/device_test.cpp index 66256ba88..db305097b 100644 --- a/test/device_test.cpp +++ b/test/device_test.cpp @@ -2,26 +2,12 @@ // Copyright 2010 Ettus Research LLC // +#include <boost/test/unit_test.hpp> #include <usrp_uhd/device.hpp> -#include <cppunit/extensions/HelperMacros.h> - -/*********************************************************************** - * cpp unit setup - **********************************************************************/ -class device_test : public CppUnit::TestFixture{ - CPPUNIT_TEST_SUITE(device_test); - CPPUNIT_TEST(test); - CPPUNIT_TEST_SUITE_END(); - -public: - void test(void); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(device_test); using namespace usrp_uhd; -void device_test::test(void){ +BOOST_AUTO_TEST_CASE(test_device){ device_addr_t device_addr(DEVICE_ADDR_TYPE_VIRTUAL); device_addr.virtual_args.num_dboards = 2; device_addr.virtual_args.num_rx_dsps = 3; @@ -34,11 +20,11 @@ void device_test::test(void){ std::cout << "Access the mboard" << std::endl; wax::proxy mb0 = (*dev)[DEVICE_PROP_MBOARD]; std::cout << wax::cast<std::string>(mb0[MBOARD_PROP_NAME]) << std::endl; - CPPUNIT_ASSERT_EQUAL( + BOOST_CHECK_EQUAL( device_addr.virtual_args.num_dboards, wax::cast<size_t>(mb0[MBOARD_PROP_NUM_RX_DBOARDS]) ); - CPPUNIT_ASSERT_EQUAL( + BOOST_CHECK_EQUAL( device_addr.virtual_args.num_dboards, wax::cast<size_t>(mb0[MBOARD_PROP_NUM_TX_DBOARDS]) ); diff --git a/test/main_test.cpp b/test/main_test.cpp new file mode 100644 index 000000000..0b47303b7 --- /dev/null +++ b/test/main_test.cpp @@ -0,0 +1,3 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MAIN +#include <boost/test/unit_test.hpp> diff --git a/test/usrp_dboard_test.cpp b/test/usrp_dboard_test.cpp index 8d8b1de4a..1e89f36f9 100644 --- a/test/usrp_dboard_test.cpp +++ b/test/usrp_dboard_test.cpp @@ -2,8 +2,8 @@ // Copyright 2010 Ettus Research LLC // +#include <boost/test/unit_test.hpp> #include <usrp_uhd/usrp/dboard/manager.hpp> -#include <cppunit/extensions/HelperMacros.h> using namespace usrp_uhd::usrp::dboard; @@ -26,21 +26,7 @@ public: std::string read_spi (spi_dev_t, spi_latch_t, size_t){return "";} }; -/*********************************************************************** - * cpp unit setup - **********************************************************************/ -class dboard_test : public CppUnit::TestFixture{ - CPPUNIT_TEST_SUITE(dboard_test); - CPPUNIT_TEST(test_manager); - CPPUNIT_TEST_SUITE_END(); - -public: - void test_manager(void); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(dboard_test); - -void dboard_test::test_manager(void){ +BOOST_AUTO_TEST_CASE(test_manager){ std::cout << "Making a dummy usrp dboard interface..." << std::endl; interface::sptr ifc0(new dummy_interface()); @@ -48,12 +34,12 @@ void dboard_test::test_manager(void){ manager::sptr mgr0(new manager(0x0001, 0x0000, ifc0)); //basic rx, basic tx std::cout << "Testing the dboard manager..." << std::endl; - CPPUNIT_ASSERT_EQUAL(size_t(3), mgr0->get_num_rx_subdevs()); - CPPUNIT_ASSERT_EQUAL(size_t(1), mgr0->get_num_tx_subdevs()); + BOOST_CHECK_EQUAL(size_t(3), mgr0->get_num_rx_subdevs()); + BOOST_CHECK_EQUAL(size_t(1), mgr0->get_num_tx_subdevs()); std::cout << "Testing access (will fail later when db code filled in)..." << std::endl; - CPPUNIT_ASSERT_THROW(mgr0->get_rx_subdev(3), std::out_of_range); - CPPUNIT_ASSERT_THROW(mgr0->get_tx_subdev(1), std::out_of_range); + BOOST_CHECK_THROW(mgr0->get_rx_subdev(3), std::out_of_range); + BOOST_CHECK_THROW(mgr0->get_tx_subdev(1), std::out_of_range); (*mgr0->get_rx_subdev(0))[NULL]; (*mgr0->get_tx_subdev(0))[NULL]; } diff --git a/test/wax_test.cpp b/test/wax_test.cpp index 0221f13b8..353130410 100644 --- a/test/wax_test.cpp +++ b/test/wax_test.cpp @@ -2,8 +2,8 @@ // Copyright 2010 Ettus Research LLC // +#include <boost/test/unit_test.hpp> #include <usrp_uhd/wax.hpp> -#include <cppunit/extensions/HelperMacros.h> /*********************************************************************** * demo class for wax framework @@ -40,29 +40,9 @@ public: } }; -/*********************************************************************** - * cpp unit setup - **********************************************************************/ -class wax_test : public CppUnit::TestFixture{ - CPPUNIT_TEST_SUITE(wax_test); - CPPUNIT_TEST(test_chaining); - CPPUNIT_TEST(test_set_get); - CPPUNIT_TEST(test_proxy); - CPPUNIT_TEST(test_print); - CPPUNIT_TEST_SUITE_END(); - -public: - void test_chaining(void); - void test_set_get(void); - void test_proxy(void); - void test_print(void); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(wax_test); - static wax_demo wd(2, 10); -void wax_test::test_chaining(void){ +BOOST_AUTO_TEST_CASE(test_chaining){ std::cout << "chain 1" << std::endl; wd[size_t(0)]; std::cout << "chain 2" << std::endl; @@ -71,7 +51,7 @@ void wax_test::test_chaining(void){ wd[size_t(0)][size_t(0)][size_t(0)]; } -void wax_test::test_set_get(void){ +BOOST_AUTO_TEST_CASE(test_set_get){ std::cout << "set and get all" << std::endl; for (size_t i = 0; i < 10; i++){ for (size_t j = 0; j < 10; j++){ @@ -79,19 +59,19 @@ void wax_test::test_set_get(void){ float val = i * j * k + i + j + k; //std::cout << i << " " << j << " " << k << std::endl; wd[i][j][k] = val; - CPPUNIT_ASSERT_EQUAL(val, wax::cast<float>(wd[i][j][k])); + BOOST_CHECK_EQUAL(val, wax::cast<float>(wd[i][j][k])); } } } } -void wax_test::test_proxy(void){ +BOOST_AUTO_TEST_CASE(test_proxy){ std::cout << "store proxy" << std::endl; wax::proxy p = wd[size_t(0)][size_t(0)]; p[size_t(0)] = float(5); } -void wax_test::test_print(void){ +BOOST_AUTO_TEST_CASE(test_print){ std::cout << "print type" << std::endl; wax::type test_type = float(3.33); std::cout << test_type << std::endl; |