aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests/soft_reg_test.cpp
blob: 2c1766cfe7ebbe01785c64b6e68aadb6c686f1f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// 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);
}