aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests
diff options
context:
space:
mode:
authorPaul David <paul.david@ettus.com>2016-09-23 10:48:32 -0700
committerMartin Braun <martin.braun@ettus.com>2016-11-29 15:02:16 -0800
commita9dfc903fa3c141d58a2575898b47c9592d51e98 (patch)
treee663a1918a3a66dccd5d40749eac8abf26ed69d9 /host/tests
parentfc54c27b48028c9c8139175d40b4b061800f32e3 (diff)
downloaduhd-a9dfc903fa3c141d58a2575898b47c9592d51e98.tar.gz
uhd-a9dfc903fa3c141d58a2575898b47c9592d51e98.tar.bz2
uhd-a9dfc903fa3c141d58a2575898b47c9592d51e98.zip
calibration: generic containers for datasets
- Includes a container for power calibration data - Unit tests to check underlying container functionality - Nearest neighbor and bilinear interpolation
Diffstat (limited to 'host/tests')
-rw-r--r--host/tests/CMakeLists.txt1
-rw-r--r--host/tests/cal_container_test.cpp200
2 files changed, 201 insertions, 0 deletions
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt
index 8f7fdcd7c..c691ce1fd 100644
--- a/host/tests/CMakeLists.txt
+++ b/host/tests/CMakeLists.txt
@@ -28,6 +28,7 @@ SET(test_sources
buffer_test.cpp
byteswap_test.cpp
cast_test.cpp
+ cal_container_test.cpp
chdr_test.cpp
convert_test.cpp
dict_test.cpp
diff --git a/host/tests/cal_container_test.cpp b/host/tests/cal_container_test.cpp
new file mode 100644
index 000000000..f45ca429d
--- /dev/null
+++ b/host/tests/cal_container_test.cpp
@@ -0,0 +1,200 @@
+//
+// Copyright 2016 Ettus Research
+//
+// This program 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 of the License, or
+// (at your option) any later version.
+//
+// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <uhd/cal/power_container.hpp>
+#include <uhd/exception.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/shared_ptr.hpp>
+#include <vector>
+#include <fstream>
+
+using namespace uhd;
+using namespace uhd::cal;
+
+static const double eps = 1e-8;
+
+////////////////////////////////////////////////////////////////////////
+BOOST_AUTO_TEST_CASE(test_power_container_bilinear){
+////////////////////////////////////////////////////////////////////////
+
+ // Create the data container
+ power_container::sptr container = power_container::make();
+
+ // Create some data points to add
+ std::vector<double> pt0(2, 0.0);
+ std::vector<double> pt1(2, 0.0);
+ std::vector<double> pt2(2, 0.0);
+ std::vector<double> pt3(2, 2.0);
+
+ pt1[0] = 2.0;
+ pt2[1] = 2.0;
+
+ container->add(1.0, pt0);
+ container->add(1.0, pt1);
+ container->add(0.0, pt2);
+ container->add(0.0, pt3);
+
+ // Add points to interpolate against
+ std::vector<double> test0(2, 1.0);
+ std::vector<double> test1(2, 1.5);
+ std::vector<double> test2(2, 0.0);
+ test2[1] = 1.0;
+
+ BOOST_CHECK_CLOSE(container->get(test0), 0.50, eps);
+ BOOST_CHECK_CLOSE(container->get(test1), 0.25, eps);
+ BOOST_CHECK_CLOSE(container->get(test2), 0.50, eps);
+}
+
+
+////////////////////////////////////////////////////////////////////////
+BOOST_AUTO_TEST_CASE(test_power_temp_container){
+////////////////////////////////////////////////////////////////////////
+
+ // Create the data container
+ power_container::sptr container = power_container::make();
+
+ // Create some data points to add
+ std::vector<double> pt0(3, 1.0);
+ std::vector<double> pt1(3, 2.0);
+ std::vector<double> pt2(3, 3.0);
+
+ container->add(1.0, pt0);
+ container->add(2.0, pt1);
+ container->add(5.0, pt2);
+
+ // Add points to interpolate against
+ std::vector<double> test0(3, 1.99);
+ std::vector<double> test1(3, 1.29);
+ std::vector<double> test2;
+ test2.push_back(2.59);
+ test2.push_back(1.29);
+ test2.push_back(2.99);
+
+ BOOST_CHECK_CLOSE(container->get(test0), 2.0, eps);
+ BOOST_CHECK_CLOSE(container->get(test1), 1.0, eps);
+ BOOST_CHECK_CLOSE(container->get(test2), 5.0, eps);
+}
+
+////////////////////////////////////////////////////////////////////////
+BOOST_AUTO_TEST_CASE(test_power_container_metadata){
+////////////////////////////////////////////////////////////////////////
+
+ // Create the data container
+ power_container::sptr container = power_container::make();
+
+ // Create some metadata to add
+ base_container::metadata_t data;
+
+ std::string fake_serial = "F2A432";
+ data["x300"] = fake_serial;
+
+ // Add some metadata
+ container->add_metadata(data);
+
+ // Check to see if the metadata matches
+ power_container::metadata_t recovered_data = container->get_metadata();
+
+ BOOST_CHECK_EQUAL(recovered_data["x300"], fake_serial);
+}
+
+////////////////////////////////////////////////////////////////////////
+BOOST_AUTO_TEST_CASE(test_power_serialization){
+////////////////////////////////////////////////////////////////////////
+
+ // Create the data container
+ power_container::sptr container = power_container::make();
+
+ // Create some metadata to add
+ base_container::metadata_t data;
+
+ std::string fake_serial = "F2A432";
+ data["x300"] = fake_serial;
+
+ // Add some metadata
+ container->add_metadata(data);
+
+ // Create some data points to add
+ std::vector<double> pt0(3, 1.0);
+ std::vector<double> pt1(3, 2.0);
+ std::vector<double> pt2(3, 3.0);
+
+ container->add(1.0, pt0);
+ container->add(2.0, pt1);
+ container->add(5.0, pt2);
+
+ std::string filename("test_power_serialization");
+
+ // Create/open a file to store the container
+ {
+ std::ofstream ofile(filename.c_str());
+
+ boost::archive::text_oarchive oarchive(ofile);
+ oarchive << *container;
+ }
+
+ // Restore to another data container
+ power_container::sptr new_container = power_container::make();
+
+ {
+ std::ifstream ifile(filename.c_str());
+ boost::archive::text_iarchive iarchive(ifile);
+
+ iarchive >> *new_container;
+ }
+
+ // Add points to interpolate against
+ std::vector<double> test0(3, 1.99);
+ std::vector<double> test1(3, 1.29);
+ std::vector<double> test2;
+ test2.push_back(2.59);
+ test2.push_back(1.29);
+ test2.push_back(2.99);
+
+ power_container::metadata_t recovered_data = new_container->get_metadata();
+
+ BOOST_CHECK_CLOSE(new_container->get(test0), 2.0, eps);
+ BOOST_CHECK_CLOSE(new_container->get(test1), 1.0, eps);
+ BOOST_CHECK_CLOSE(new_container->get(test2), 5.0, eps);
+
+ // Check to see if the metadata matches
+ BOOST_CHECK_EQUAL(recovered_data["x300"], fake_serial);
+
+ std::remove(filename.c_str());
+}
+
+////////////////////////////////////////////////////////////////////////
+BOOST_AUTO_TEST_CASE(test_interp_singular){
+////////////////////////////////////////////////////////////////////////
+
+ // Create the data container
+ power_container::sptr container = power_container::make();
+
+ // Create some data points to add
+ // that result in a singular matrix
+ std::vector<double> pt0(2, 1.0);
+ std::vector<double> pt1(2, 2.0);
+ std::vector<double> pt2(2, 3.0);
+ std::vector<double> pt3(2, 4.0);
+
+ container->add(1.0, pt0);
+ container->add(2.0, pt1);
+ container->add(3.0, pt2);
+ container->add(4.0, pt3);
+
+ std::vector<double> test(2, 2.5);
+ BOOST_CHECK_CLOSE(container->get(test), 2.5, eps);
+}