From d7287678358b59993d5cace77ffbd0564ebe7593 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 19 May 2020 11:12:34 -0700 Subject: 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. --- host/tests/cal_database_test.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'host/tests') 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 #include +#include #include // putenv or _putenv #include #include #include +#include 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 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); +} -- cgit v1.2.3