aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests/cal_database_test.cpp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-05-19 11:12:34 -0700
committerAaron Rossetto <aaron.rossetto@ni.com>2020-05-20 07:30:15 -0500
commitd7287678358b59993d5cace77ffbd0564ebe7593 (patch)
treec3729ae04412178a5b6cf004cec8f220f959f05d /host/tests/cal_database_test.cpp
parent746f9c7f0e3fb8c2f9e480ba2bad4527ce9eb34a (diff)
downloaduhd-d7287678358b59993d5cace77ffbd0564ebe7593.tar.gz
uhd-d7287678358b59993d5cace77ffbd0564ebe7593.tar.bz2
uhd-d7287678358b59993d5cace77ffbd0564ebe7593.zip
cal: database: Add option to register flash cal callbacks
This adds the possibility to read cal data from flash/EEPROM by adding callbacks to the database. Unlike the RC and FILESYSTEM data, this is very device-specific, but we can let devices register callbacks in the database so that reading cal data from flash can use the same APIs as from RC or filesystem. Note that this also gives a convenient way to inject call data during unit tests, if desired.
Diffstat (limited to 'host/tests/cal_database_test.cpp')
-rw-r--r--host/tests/cal_database_test.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/host/tests/cal_database_test.cpp b/host/tests/cal_database_test.cpp
index cd189138b..d53ca4576 100644
--- a/host/tests/cal_database_test.cpp
+++ b/host/tests/cal_database_test.cpp
@@ -6,10 +6,12 @@
#include <uhd/cal/database.hpp>
#include <uhd/utils/paths.hpp>
+#include <uhd/exception.hpp>
#include <stdlib.h> // putenv or _putenv
#include <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp>
#include <iostream>
+#include <numeric>
using namespace uhd::usrp::cal;
namespace fs = boost::filesystem;
@@ -86,3 +88,37 @@ BOOST_AUTO_TEST_CASE(test_fs)
std::cout << "WARNING: Could not remove temp cal path." << std::endl;
}
}
+
+BOOST_AUTO_TEST_CASE(test_flash)
+{
+ // 4 bytes of cal data
+ std::vector<uint8_t> mock_cal_data{42, 23, 1, 2};
+
+ database::register_lookup(
+ [&](const std::string& key, const std::string&) {
+ // Note: We're deliberately not checking the key here, but below, so
+ // we can check all code paths in database.cpp, even the ones we're
+ // not supposed to reach
+ return key == "MOCK_KEY";
+ },
+ [&](const std::string& key, const std::string& serial) {
+ if (key == "MOCK_KEY" && serial == "MOCK_SERIAL") {
+ return mock_cal_data;
+ }
+ throw uhd::runtime_error("no such mock data!");
+ });
+ BOOST_CHECK(database::has_cal_data("MOCK_KEY", "MOCK_SERIAL", source::FLASH));
+ BOOST_CHECK(!database::has_cal_data("FOO_KEY", "FOO_SERIAL", source::FLASH));
+ auto cal_data1 = database::read_cal_data("MOCK_KEY", "MOCK_SERIAL", source::FLASH);
+ BOOST_CHECK_EQUAL_COLLECTIONS(mock_cal_data.cbegin(),
+ mock_cal_data.cend(),
+ cal_data1.cbegin(),
+ cal_data1.cend());
+ auto cal_data2 = database::read_cal_data("MOCK_KEY", "MOCK_SERIAL", source::ANY);
+ BOOST_CHECK_EQUAL_COLLECTIONS(mock_cal_data.cbegin(),
+ mock_cal_data.cend(),
+ cal_data2.cbegin(),
+ cal_data2.cend());
+ BOOST_REQUIRE_THROW(database::read_cal_data("MOCK_KEY", "FOO_SERIAL", source::FLASH),
+ uhd::runtime_error);
+}