aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests
diff options
context:
space:
mode:
Diffstat (limited to 'host/tests')
-rw-r--r--host/tests/CMakeLists.txt3
-rw-r--r--host/tests/soft_reg_test.cpp33
2 files changed, 35 insertions, 1 deletions
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt
index 7d53b50c4..ba0484e86 100644
--- a/host/tests/CMakeLists.txt
+++ b/host/tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-#
+
# Copyright 2010-2015 Ettus Research LLC
# Copyright 2018 Ettus Research, a National Instruments Company
#
@@ -34,6 +34,7 @@ SET(test_sources
ranges_test.cpp
sid_t_test.cpp
sensors_test.cpp
+ soft_reg_test.cpp
sph_recv_test.cpp
sph_send_test.cpp
subdev_spec_test.cpp
diff --git a/host/tests/soft_reg_test.cpp b/host/tests/soft_reg_test.cpp
new file mode 100644
index 000000000..8e53c61ca
--- /dev/null
+++ b/host/tests/soft_reg_test.cpp
@@ -0,0 +1,33 @@
+//
+// Copyright 2018 Ettus Research, a National Instruments Company
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#include <uhd/utils/soft_register.hpp>
+#include <boost/test/unit_test.hpp>
+
+using namespace uhd;
+
+BOOST_AUTO_TEST_CASE(test_soft_reg_field) {
+ UHD_DEFINE_SOFT_REG_FIELD(test_reg1, /* width */ 1, /* shift */ 0);
+ BOOST_CHECK_EQUAL(soft_reg_field::width(test_reg1), 1);
+ BOOST_CHECK_EQUAL(soft_reg_field::shift(test_reg1), 0);
+ BOOST_CHECK_EQUAL(soft_reg_field::mask<uint32_t>(test_reg1), 1<<0);
+
+ UHD_DEFINE_SOFT_REG_FIELD(test_reg2, /* width */ 5, /* shift */ 4);
+ BOOST_CHECK_EQUAL(soft_reg_field::width(test_reg2), 5);
+ BOOST_CHECK_EQUAL(soft_reg_field::shift(test_reg2), 4);
+ BOOST_CHECK_EQUAL(soft_reg_field::mask<uint32_t>(test_reg2), 0x1F<<4);
+
+ UHD_DEFINE_SOFT_REG_FIELD(test_reg3, /* width */ 9, /* shift */ 0);
+ BOOST_CHECK_EQUAL(soft_reg_field::width(test_reg3), 9);
+ BOOST_CHECK_EQUAL(soft_reg_field::shift(test_reg3), 0);
+ BOOST_CHECK_EQUAL(soft_reg_field::mask<uint8_t>(test_reg3), 0xFF);
+
+ // This one is platform dependent:
+ UHD_DEFINE_SOFT_REG_FIELD(test_reg4, /* width */ 33, /* shift */ 0);
+ BOOST_CHECK_EQUAL(soft_reg_field::width(test_reg4), 33);
+ BOOST_CHECK_EQUAL(soft_reg_field::shift(test_reg4), 0);
+ BOOST_CHECK_EQUAL(soft_reg_field::mask<size_t>(test_reg4), ~size_t(0) & 0x1FFFFFFFF);
+}