summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-01-15 17:49:35 -0800
committerJosh Blum <josh@joshknows.com>2010-01-15 17:49:35 -0800
commit379d486ed21aace7f8b37d61f713bdc6088b39e5 (patch)
treee0093e4ad60ea9f87780c03a5883eded755b51c2 /test
parent92c76e574773e99d1bfb5c3a833217b8644779f4 (diff)
downloaduhd-379d486ed21aace7f8b37d61f713bdc6088b39e5.tar.gz
uhd-379d486ed21aace7f8b37d61f713bdc6088b39e5.tar.bz2
uhd-379d486ed21aace7f8b37d61f713bdc6088b39e5.zip
Integrated cppunit into the build system.
Added new test for the usrp dboard stuff.
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am22
-rw-r--r--test/addr_test.cpp61
-rw-r--r--test/cppunit_test.cpp25
-rw-r--r--test/usrp_dboard_test.cpp59
-rw-r--r--test/wax_test.cpp93
5 files changed, 184 insertions, 76 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 31deb7391..bd32206bf 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -6,17 +6,25 @@ include $(top_srcdir)/Makefile.common
SUBDIRS =
-AM_CPPFLAGS = $(GENERAL_CPPFLAGS)
+if HAVE_CPPUNIT
+
+AM_CPPFLAGS = \
+ $(GENERAL_CPPFLAGS) \
+ $(CPPUNIT_CFLAGS)
LDADD = \
$(GENERAL_LDDFLAGS) \
- $(USRP_UHD_LA)
+ $(USRP_UHD_LA) \
+ $(CPPUNIT_LIBS)
-noinst_PROGRAMS = \
- addr_test \
- wax_test
+noinst_PROGRAMS = cppunit_test
-addr_test_SOURCES = addr_test.cpp
-wax_test_SOURCES = wax_test.cpp
+cppunit_test_SOURCES = \
+ cppunit_test.cpp \
+ addr_test.cpp \
+ usrp_dboard_test.cpp \
+ wax_test.cpp
TESTS = $(noinst_PROGRAMS)
+
+endif
diff --git a/test/addr_test.cpp b/test/addr_test.cpp
index 11fe8c1dd..65792aabc 100644
--- a/test/addr_test.cpp
+++ b/test/addr_test.cpp
@@ -3,39 +3,38 @@
//
#include <usrp_uhd/device_addr.hpp>
-#include <iostream>
-#include <stdexcept>
-#include <boost/format.hpp>
-#include <boost/current_function.hpp>
+#include <cppunit/extensions/HelperMacros.h>
-#define THROW_ASSERT(expr) \
-if (not (expr)){ \
- throw std::runtime_error(str( \
- boost::format("%s %s %s %s") \
- % #expr % BOOST_CURRENT_FUNCTION % __FILE__ % __LINE__ \
- )); \
-}
+/***********************************************************************
+ * 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);
+};
-int main(void){
- try{
- 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;
- THROW_ASSERT(mac_addr.to_string() == mac_addr_str);
+CPPUNIT_TEST_SUITE_REGISTRATION(addr_test);
- 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;
- THROW_ASSERT(ip_addr.to_string() == ip_addr_str);
+void addr_test::test_mac_addr(void){
+ 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());
+}
- std::cout << "done" << std::endl;
- }catch(std::exception const& e){
- std::cerr << "Exception: " << e.what() << std::endl;
- return ~0;
- }
- return 0;
+void addr_test::test_ip_addr(void){
+ 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());
}
diff --git a/test/cppunit_test.cpp b/test/cppunit_test.cpp
new file mode 100644
index 000000000..d4bfff9db
--- /dev/null
+++ b/test/cppunit_test.cpp
@@ -0,0 +1,25 @@
+//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/usrp_dboard_test.cpp b/test/usrp_dboard_test.cpp
new file mode 100644
index 000000000..8d8b1de4a
--- /dev/null
+++ b/test/usrp_dboard_test.cpp
@@ -0,0 +1,59 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+
+#include <usrp_uhd/usrp/dboard/manager.hpp>
+#include <cppunit/extensions/HelperMacros.h>
+
+using namespace usrp_uhd::usrp::dboard;
+
+/***********************************************************************
+ * dummy interface for dboards
+ **********************************************************************/
+class dummy_interface : public interface{
+public:
+ dummy_interface(void){}
+ ~dummy_interface(void){}
+ void write_aux_dac(int, int){}
+ int read_aux_adc(int){return 0;}
+ void set_atr_reg(gpio_bank_t, uint16_t, uint16_t, uint16_t){}
+ void set_gpio_ddr(gpio_bank_t, uint16_t, uint16_t){}
+ void write_gpio(gpio_bank_t, uint16_t, uint16_t){}
+ uint16_t read_gpio(gpio_bank_t){return 0;}
+ void write_i2c (int, const std::string &){}
+ std::string read_i2c (int, size_t){return "";}
+ void write_spi (spi_dev_t, spi_push_t, const std::string &){}
+ 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){
+ std::cout << "Making a dummy usrp dboard interface..." << std::endl;
+ interface::sptr ifc0(new dummy_interface());
+
+ std::cout << "Making a usrp dboard manager..." << std::endl;
+ 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());
+
+ 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);
+ (*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 06f17b9b7..0221f13b8 100644
--- a/test/wax_test.cpp
+++ b/test/wax_test.cpp
@@ -3,11 +3,11 @@
//
#include <usrp_uhd/wax.hpp>
-#include <iostream>
-#include <stdexcept>
-#include <vector>
-#include <boost/assert.hpp>
+#include <cppunit/extensions/HelperMacros.h>
+/***********************************************************************
+ * demo class for wax framework
+ **********************************************************************/
class wax_demo : public wax::obj{
private:
std::vector<float> d_nums;
@@ -40,42 +40,59 @@ public:
}
};
-#define transform(i, j, k) float(i * j * k + i + j + k);
+/***********************************************************************
+ * 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();
-int main(void){
- try{
- wax_demo wd(2, 10);
- //test chained access
- std::cout << "chain 1" << std::endl;
- wd[size_t(0)];
- std::cout << "chain 2" << std::endl;
- wd[size_t(0)][size_t(0)];
- std::cout << "chain 3" << std::endl;
- wd[size_t(0)][size_t(0)][size_t(0)];
- //set a bunch of values
- std::cout << "set and get all" << std::endl;
- for (size_t i = 0; i < 10; i++){
- for (size_t j = 0; j < 10; j++){
- for (size_t k = 0; k < 10; k++){
- float val = transform(i, j, k);
- //std::cout << i << " " << j << " " << k << std::endl;
- wd[i][j][k] = val;
- BOOST_ASSERT(wax::cast<float>(wd[i][j][k]) == val);
- }
+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){
+ std::cout << "chain 1" << std::endl;
+ wd[size_t(0)];
+ std::cout << "chain 2" << std::endl;
+ wd[size_t(0)][size_t(0)];
+ std::cout << "chain 3" << std::endl;
+ wd[size_t(0)][size_t(0)][size_t(0)];
+}
+
+void wax_test::test_set_get(void){
+ std::cout << "set and get all" << std::endl;
+ for (size_t i = 0; i < 10; i++){
+ for (size_t j = 0; j < 10; j++){
+ for (size_t k = 0; k < 10; k++){
+ 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]));
}
}
- //test storing a proxy
- std::cout << "store proxy" << std::endl;
- wax::proxy p = wd[size_t(0)][size_t(0)];
- p[size_t(0)] = float(5);
- //test printing a type
- std::cout << "print type" << std::endl;
- wax::type test_type = float(3.33);
- std::cout << test_type << std::endl;
- std::cout << "done" << std::endl;
- }catch(std::exception const& e){
- std::cerr << "Exception: " << e.what() << std::endl;
- return ~0;
}
- return 0;
+}
+
+void wax_test::test_proxy(void){
+ 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){
+ std::cout << "print type" << std::endl;
+ wax::type test_type = float(3.33);
+ std::cout << test_type << std::endl;
}