diff options
Diffstat (limited to 'gr-analog/lib')
-rw-r--r-- | gr-analog/lib/CMakeLists.txt | 31 | ||||
-rw-r--r-- | gr-analog/lib/qa_analog.cc | 39 | ||||
-rw-r--r-- | gr-analog/lib/qa_analog.h | 38 | ||||
-rw-r--r-- | gr-analog/lib/qa_sincos.cc | 75 | ||||
-rw-r--r-- | gr-analog/lib/qa_sincos.h | 47 | ||||
-rw-r--r-- | gr-analog/lib/sincos.c | 86 | ||||
-rw-r--r-- | gr-analog/lib/test_gr_analog.cc | 43 |
7 files changed, 359 insertions, 0 deletions
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt index 93ab5e83e..e0e621d13 100644 --- a/gr-analog/lib/CMakeLists.txt +++ b/gr-analog/lib/CMakeLists.txt @@ -27,6 +27,8 @@ include_directories( ${GR_FFT_INCLUDE_DIRS} ${GR_FILTER_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}/../include + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} ) include_directories(${Boost_INCLUDE_DIRS}) @@ -136,3 +138,32 @@ add_library(gnuradio-analog SHARED ${analog_sources}) target_link_libraries(gnuradio-analog ${analog_libs}) GR_LIBRARY_FOO(gnuradio-analog RUNTIME_COMPONENT "analog_runtime" DEVEL_COMPONENT "analog_devel") add_dependencies(gnuradio-analog analog_generated_includes analog_generated_swigs gnuradio-filter) + + +######################################################################## +# QA C++ Code for gr-filter +######################################################################## +if(ENABLE_TESTING) + include(GrTest) + + include_directories(${CPPUNIT_INCLUDE_DIRS}) + link_directories(${CPPUNIT_LIBRARY_DIRS}) + + list(APPEND test_gr_analog_sources + ${CMAKE_CURRENT_SOURCE_DIR}/test_gr_analog.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_analog.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_sincos.cc + ) + + add_executable(test-gr-analog ${test_gr_analog_sources}) + + target_link_libraries( + test-gr-analog + gnuradio-core + gnuradio-analog + ${Boost_LIBRARIES} + ${CPPUNIT_LIBRARIES} + ) + + GR_ADD_TEST(test_gr_analog test-gr-analog) +endif(ENABLE_TESTING) diff --git a/gr-analog/lib/qa_analog.cc b/gr-analog/lib/qa_analog.cc new file mode 100644 index 000000000..ceecb096d --- /dev/null +++ b/gr-analog/lib/qa_analog.cc @@ -0,0 +1,39 @@ +/* + * 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. + */ + +/* + * This class gathers together all the test cases for the gr-analog + * directory into a single test suite. As you create new test cases, + * add them here. + */ + +#include <qa_analog.h> +#include <qa_sincos.h> + +CppUnit::TestSuite * +qa_gr_analog::suite() +{ + CppUnit::TestSuite *s = new CppUnit::TestSuite("gr-analog"); + + s->addTest(gr::analog::qa_sincos::suite()); + + return s; +} diff --git a/gr-analog/lib/qa_analog.h b/gr-analog/lib/qa_analog.h new file mode 100644 index 000000000..458861cc9 --- /dev/null +++ b/gr-analog/lib/qa_analog.h @@ -0,0 +1,38 @@ +/* -*- 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_GR_ANALOG_H_ +#define _QA_GR_ANALOG_H_ + +#include <gruel/attributes.h> +#include <cppunit/TestSuite.h> + +//! collect all the tests for the gr-analog directory + +class __GR_ATTR_EXPORT qa_gr_analog { + public: + //! return suite of tests for all of gr-analog directory + static CppUnit::TestSuite *suite(); +}; + + +#endif /* _QA_GR_ANALOG_H_ */ diff --git a/gr-analog/lib/qa_sincos.cc b/gr-analog/lib/qa_sincos.cc new file mode 100644 index 000000000..62642c117 --- /dev/null +++ b/gr-analog/lib/qa_sincos.cc @@ -0,0 +1,75 @@ +/* -*- 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qa_sincos.h> +#include <analog/sincos.h> +#include <gruel/attributes.h> +#include <cppunit/TestAssert.h> +#include <cmath> + +namespace gr { + namespace analog { + + void + qa_sincos::t1() + { + static const unsigned int N = 1000; + double c_sin, c_cos; + double gr_sin, gr_cos; + + for(unsigned i = 0; i < N; i++) { + double x = i/100.0; + c_sin = sin(x); + c_cos = cos(x); + + analog::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); + } + } + + void + qa_sincos::t2() + { + static const unsigned int N = 1000; + float c_sin, c_cos; + float gr_sin, gr_cos; + + for(unsigned i = 0; i < N; i++) { + float x = i/100.0; + c_sin = sinf(x); + c_cos = cosf(x); + + analog::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); + } + } + + } /* namespace analog */ +} /* namespace gr */ diff --git a/gr-analog/lib/qa_sincos.h b/gr-analog/lib/qa_sincos.h new file mode 100644 index 000000000..f18e879dd --- /dev/null +++ b/gr-analog/lib/qa_sincos.h @@ -0,0 +1,47 @@ +/* -*- 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_ANALOG_SINCOS_H_ +#define _QA_ANALOG_SINCOS_H_ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> + +namespace gr { + namespace analog { + + 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(); + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* _QA_ANALOG_SINCOS_H_ */ diff --git a/gr-analog/lib/sincos.c b/gr-analog/lib/sincos.c new file mode 100644 index 000000000..aa72b1cd4 --- /dev/null +++ b/gr-analog/lib/sincos.c @@ -0,0 +1,86 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2010,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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE // ask for GNU extensions if available +#endif + +#include <analog/sincos.h> +#include <math.h> + +namespace gr { + namespace analog { + +// ---------------------------------------------------------------- + +#if defined (HAVE_SINCOS) + + void + sincos(double x, double *sinx, double *cosx) + { + sincos(x, sinx, cosx); + } + +#else + + void + sincos(double x, double *sinx, double *cosx) + { + *sinx = sin(x); + *cosx = cos(x); + } + +#endif + +// ---------------------------------------------------------------- + +#if defined (HAVE_SINCOSF) + + void + sincosf(float x, float *sinx, float *cosx) + { + sincosf(x, sinx, cosx); + } + +#elif defined (HAVE_SINF) && defined (HAVE_COSF) + + void + sincosf(float x, float *sinx, float *cosx) + { + *sinx = sinf(x); + *cosx = cosf(x); + } + +#else + + void + sincosf(float x, float *sinx, float *cosx) + { + *sinx = sin(x); + *cosx = cos(x); + } + +#endif diff --git a/gr-analog/lib/test_gr_analog.cc b/gr-analog/lib/test_gr_analog.cc new file mode 100644 index 000000000..00d624269 --- /dev/null +++ b/gr-analog/lib/test_gr_analog.cc @@ -0,0 +1,43 @@ +/* -*- 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. + */ + +#include <cppunit/TextTestRunner.h> +#include <cppunit/XmlOutputter.h> + +#include <gr_unittests.h> +#include "qa_analog.h" +#include <iostream> + +int +main (int argc, char **argv) +{ + CppUnit::TextTestRunner runner; + std::ofstream xmlfile(get_unittest_path("gr_analog.xml").c_str()); + CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile); + + runner.addTest(qa_gr_analog::suite()); + runner.setOutputter(xmlout); + + bool was_successful = runner.run("", false); + + return was_successful ? 0 : 1; +} |