Dawn Framework 1.0
Universal data acquisition framework for embedded systems
test_bitsplit.cxx
1// dawn/tests/prog/test_bitsplit.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/prog/bitsplit.hxx"
7#include "test_common.hxx"
8
9#include "dawn/io/sdata.hxx"
10#include "dawn/io/virt.hxx"
11
12using namespace dawn;
13
14static constexpr auto BITSPLIT_SRC = CIOVirt::objectId(SObjectId::DTYPE_UINT32, false, 60);
15static constexpr auto BITSPLIT_D0 = CIOVirt::objectId(SObjectId::DTYPE_UINT32, false, 61);
16static constexpr auto BITSPLIT_D1 = CIOVirt::objectId(SObjectId::DTYPE_UINT32, false, 62);
17
18static uint32_t g_cfg_src[] = {BITSPLIT_SRC, 0};
19static uint32_t g_cfg_d0[] = {BITSPLIT_D0, 0};
20static uint32_t g_cfg_d1[] = {BITSPLIT_D1, 0};
21
22static uint32_t g_bin_bitsplit[] = {
23 CProgBitSplit::objectId(0),
24 2,
25 CProgBitSplit::cfgIdIOBind(4),
26 BITSPLIT_SRC,
27 BITSPLIT_D0,
28 BITSPLIT_SRC,
29 BITSPLIT_D1,
30 CProgBitSplit::cfgIdBits(2),
31 0, // bit 0 → d0
32 1, // bit 1 → d1
33};
34
35static void test_bitsplit_extracts_bits()
36{
37 CDescObject srcDesc(g_cfg_src);
38 CIOVirt src(srcDesc);
39 CDescObject d0Desc(g_cfg_d0);
40 CIOVirt d0(d0Desc);
41 CDescObject d1Desc(g_cfg_d1);
42 CIOVirt d1(d1Desc);
43 CDescObject progDesc(g_bin_bitsplit);
44 CProgBitSplit prog(progDesc);
45
49
50 TEST_ASSERT_EQUAL(OK, src.init());
51 TEST_ASSERT_EQUAL(OK, d0.init());
52 TEST_ASSERT_EQUAL(OK, d1.init());
53 TEST_ASSERT_EQUAL(OK, src.initialize(1, 1, true));
54
55 TEST_ASSERT_EQUAL(OK, prog.configure());
56 prog.setObjectMapItem(BITSPLIT_SRC, &src);
57 prog.setObjectMapItem(BITSPLIT_D0, &d0);
58 prog.setObjectMapItem(BITSPLIT_D1, &d1);
59 TEST_ASSERT_EQUAL(OK, prog.init());
60 TEST_ASSERT_EQUAL(OK, prog.start());
61
62 // Input 0b11: bit0=1, bit1=1
63 in(0) = 3;
64 TEST_ASSERT_EQUAL(OK, src.setData(in));
65 TEST_ASSERT_EQUAL(OK, d0.getData(o0, 1));
66 TEST_ASSERT_EQUAL(OK, d1.getData(o1, 1));
67 TEST_ASSERT_EQUAL(1, o0(0));
68 TEST_ASSERT_EQUAL(1, o1(0));
69
70 // Input 0b10: bit0=0, bit1=1
71 in(0) = 2;
72 TEST_ASSERT_EQUAL(OK, src.setData(in));
73 TEST_ASSERT_EQUAL(OK, d0.getData(o0, 1));
74 TEST_ASSERT_EQUAL(OK, d1.getData(o1, 1));
75 TEST_ASSERT_EQUAL(0, o0(0));
76 TEST_ASSERT_EQUAL(1, o1(0));
77
78 // Input 0: both bits 0
79 in(0) = 0;
80 TEST_ASSERT_EQUAL(OK, src.setData(in));
81 TEST_ASSERT_EQUAL(OK, d0.getData(o0, 1));
82 TEST_ASSERT_EQUAL(OK, d1.getData(o1, 1));
83 TEST_ASSERT_EQUAL(0, o0(0));
84 TEST_ASSERT_EQUAL(0, o1(0));
85
86 TEST_ASSERT_EQUAL(OK, prog.stop());
87}
88
89extern "C"
90{
91 int test_prog_bitsplit()
92 {
93 UNITY_BEGIN();
94 DAWN_RUN_TEST(test_bitsplit_extracts_bits);
95 return UNITY_END();
96 }
97}
Descriptor wrapper for individual object configuration.
Virtual I/O type for user-provided data and callbacks.
Definition virt.hxx:26
Bit demultiplexer: extracts configurable bit slices from the input into separate outputs.
Definition bitsplit.hxx:30
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
Definition objectid.hxx:96
Static (compile-time) I/O data buffer (no timestamp).
Definition sdata.hxx:39