From b185c9447a4a33bff14fd697dc294b9ee5d298b3 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 10 Jul 2018 22:24:49 -0700 Subject: soft_register: Remove compiler warning, add unit test --- host/tests/soft_reg_test.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 host/tests/soft_reg_test.cpp (limited to 'host/tests/soft_reg_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 +#include + +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(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(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(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(test_reg4), ~size_t(0) & 0x1FFFFFFFF); +} -- cgit v1.2.3