DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DAPHNEEthStream_binding_test Namespace Reference

Functions

int test_construction_and_size ()
int test_static_members ()
int test_bytes_roundtrip ()
int test_less_than_operator ()
int test_timestamp ()
int test_channel ()
int test_daqheader_accessible ()
int test_set_geoid ()
int test_channelword_properties ()
int test_header_channel_words_property ()
int test_adc_single ()
int test_adc_max_value ()
int test_adc_independence ()
int test_adc_all_channels_one_sample ()
int test_adc_out_of_range ()
int main ()

Variables

int NUM_CHANNELS = 4
int ADCS_PER_CHANNEL = 280
tuple ADC_MAX = (1 << 14) - 1

Function Documentation

◆ main()

int main ( )

Definition at line 290 of file DAPHNEEthStream_binding_test.py.

290def main() -> int:
291 tests = [
292 test_construction_and_size,
293 test_static_members,
294 test_bytes_roundtrip,
295 test_less_than_operator,
296 test_timestamp,
297 test_channel,
298 test_daqheader_accessible,
299 test_set_geoid,
300 test_channelword_properties,
301 test_header_channel_words_property,
302 test_adc_single,
303 test_adc_max_value,
304 test_adc_independence,
305 test_adc_all_channels_one_sample,
306 test_adc_out_of_range,
307 ]
308
309 failures = 0
310 for test in tests:
311 failures += test()
312
313 print()
314 if failures == 0:
315 print("All DAPHNEEthStreamFrame Python binding tests passed")
316 else:
317 print(f"{failures} DAPHNEEthStreamFrame Python binding test(s) FAILED")
318 return failures
319
320
int main(int argc, char *argv[])

◆ test_adc_all_channels_one_sample()

int test_adc_all_channels_one_sample ( )

Definition at line 256 of file DAPHNEEthStream_binding_test.py.

256def test_adc_all_channels_one_sample() -> int:
257 frame = DAPHNEEthStreamFrame()
258 adc_index = 0
259 for channel_idx in range(NUM_CHANNELS):
260 frame.set_adc(adc_index, channel_idx, (channel_idx + 1) * 100)
261 for channel_idx in range(NUM_CHANNELS):
262 expected = (channel_idx + 1) * 100
263 got = frame.get_adc(adc_index, channel_idx)
264 if got != expected:
265 print(f"FAIL: all-channels test: channel {channel_idx}: expected {expected}, got {got}")
266 return 1
267 print(f"PASS: all {NUM_CHANNELS} channels read back correctly for adc index {adc_index}")
268 return 0
269
270

◆ test_adc_independence()

int test_adc_independence ( )

Definition at line 237 of file DAPHNEEthStream_binding_test.py.

237def test_adc_independence() -> int:
238 frame = DAPHNEEthStreamFrame()
239 test_cases = [
240 (0, 0, 100),
241 (1, 0, 200),
242 (0, 1, 300),
243 (ADCS_PER_CHANNEL - 1, NUM_CHANNELS - 1, 9999),
244 ]
245 for adc_idx, channel_idx, val in test_cases:
246 frame.set_adc(adc_idx, channel_idx, val)
247 for adc_idx, channel_idx, expected in test_cases:
248 got = frame.get_adc(adc_idx, channel_idx)
249 if got != expected:
250 print(f"FAIL: ADC independence: adc={adc_idx}, channel={channel_idx}: expected {expected}, got {got}")
251 return 1
252 print("PASS: ADC cell independence across multiple (adc, channel) pairs")
253 return 0
254
255

◆ test_adc_max_value()

int test_adc_max_value ( )

Definition at line 226 of file DAPHNEEthStream_binding_test.py.

226def test_adc_max_value() -> int:
227 frame = DAPHNEEthStreamFrame()
228 frame.set_adc(0, 0, ADC_MAX)
229 got = frame.get_adc(0, 0)
230 if got != ADC_MAX:
231 print(f"FAIL: max ADC value {ADC_MAX}: got {got}")
232 return 1
233 print(f"PASS: max ADC value ({ADC_MAX}) preserved")
234 return 0
235
236

◆ test_adc_out_of_range()

int test_adc_out_of_range ( )

Definition at line 271 of file DAPHNEEthStream_binding_test.py.

271def test_adc_out_of_range() -> int:
272 frame = DAPHNEEthStreamFrame()
273 try:
274 frame.get_adc(ADCS_PER_CHANNEL, 0)
275 print("FAIL: get_adc with out-of-range adc index should have raised an exception")
276 return 1
277 except Exception:
278 pass
279 try:
280 frame.get_channel(NUM_CHANNELS)
281 print("FAIL: get_channel with out-of-range channel index should have raised an exception")
282 return 1
283 except Exception:
284 pass
285
286 print("PASS: out-of-range channel/adc indices raise exceptions as expected")
287 return 0
288
289

◆ test_adc_single()

int test_adc_single ( )

Definition at line 215 of file DAPHNEEthStream_binding_test.py.

215def test_adc_single() -> int:
216 frame = DAPHNEEthStreamFrame()
217 frame.set_adc(0, 0, 111)
218 got = frame.get_adc(0, 0)
219 if got != 111:
220 print(f"FAIL: set_adc(0,0,111) -> get_adc(0,0) returned {got}")
221 return 1
222 print("PASS: single ADC set/get (adc index 0, channel 0)")
223 return 0
224
225

◆ test_bytes_roundtrip()

int test_bytes_roundtrip ( )

Definition at line 60 of file DAPHNEEthStream_binding_test.py.

60def test_bytes_roundtrip() -> int:
61 frame = DAPHNEEthStreamFrame()
62 frame.set_timestamp(0x1234ABCD)
63 frame.set_channel(0, 7)
64 frame.set_channel(1, 8)
65
66 raw = frame.get_bytes()
67 if len(raw) != DAPHNEEthStreamFrame.sizeof():
68 print(f"FAIL: get_bytes() length {len(raw)} != sizeof() {DAPHNEEthStreamFrame.sizeof()}")
69 return 1
70
71 clone = DAPHNEEthStreamFrame(raw)
72 if clone.get_timestamp() != 0x1234ABCD:
73 print(f"FAIL: bytes round-trip timestamp mismatch: got {clone.get_timestamp():#x}")
74 return 1
75 if (clone.get_channel(0), clone.get_channel(1)) != (7, 8):
76 print("FAIL: bytes round-trip channel mismatch")
77 return 1
78
79 print("PASS: DAPHNEEthStreamFrame bytes constructor roundtrip")
80 return 0
81
82

◆ test_channel()

int test_channel ( )

Definition at line 110 of file DAPHNEEthStream_binding_test.py.

110def test_channel() -> int:
111 frame = DAPHNEEthStreamFrame()
112 set_vals = [30, 31, 32, 33]
113
114 for idx, val in enumerate(set_vals):
115 frame.set_channel(idx, val)
116
117 for idx, val in enumerate(set_vals):
118 got = frame.get_channel(idx)
119 if got != val:
120 print(f"FAIL: get_channel({idx}) expected {val}, got {got}")
121 return 1
122
123 if (frame.get_channel0(), frame.get_channel1(), frame.get_channel2(), frame.get_channel3()) != tuple(set_vals):
124 print("FAIL: get_channel0..3 mismatch")
125 return 1
126
127 print("PASS: set_channel / get_channel and get_channel0..3")
128 return 0
129
130

◆ test_channelword_properties()

int test_channelword_properties ( )

Definition at line 169 of file DAPHNEEthStream_binding_test.py.

169def test_channelword_properties() -> int:
170 frame = DAPHNEEthStreamFrame()
171 frame.set_channel(0, 33)
172 frame.set_channel(1, 34)
173 frame.set_channel(2, 35)
174 frame.set_channel(3, 36)
175
176 words = frame.header.channel_words
177 header_alias = frame.get_daphneheader()
178 if header_alias is None:
179 print("FAIL: get_daphneheader() returned None")
180 return 1
181 if len(words) != NUM_CHANNELS:
182 print(f"FAIL: expected {NUM_CHANNELS} channel words, got {len(words)}")
183 return 1
184
185 expected = [33, 34, 35, 36]
186 for idx, exp in enumerate(expected):
187 if words[idx].channel != exp:
188 print(f"FAIL: ChannelWord[{idx}].channel mismatch, got {words[idx].channel}, expected {exp}")
189 return 1
190 if not isinstance(words[idx].version, int) or not isinstance(words[idx].tbd, int):
191 print("FAIL: ChannelWord.version/tbd should be int")
192 return 1
193
194 print("PASS: DAPHNEEthStreamChannelWord properties via frame/header")
195 return 0
196
197

◆ test_construction_and_size()

int test_construction_and_size ( )

Definition at line 12 of file DAPHNEEthStream_binding_test.py.

12def test_construction_and_size() -> int:
13 frame = DAPHNEEthStreamFrame()
14 if frame is None:
15 print("FAIL: DAPHNEEthStreamFrame default construction returned None")
16 return 1
17 size = DAPHNEEthStreamFrame.sizeof()
18 if size <= 0:
19 print(f"FAIL: DAPHNEEthStreamFrame.sizeof() returned {size}, expected > 0")
20 return 1
21 print(f"PASS: DAPHNEEthStreamFrame construction and sizeof={size}")
22 return 0
23
24

◆ test_daqheader_accessible()

int test_daqheader_accessible ( )

Definition at line 131 of file DAPHNEEthStream_binding_test.py.

131def test_daqheader_accessible() -> int:
132 frame = DAPHNEEthStreamFrame()
133 hdr = frame.daq_header
134 if hdr is None:
135 print("FAIL: daq_header returned None")
136 return 1
137 hdr_alias = frame.get_daqheader()
138 if hdr_alias is None:
139 print("FAIL: get_daqheader() returned None")
140 return 1
141 print("PASS: daq_header accessible")
142 return 0
143
144

◆ test_header_channel_words_property()

int test_header_channel_words_property ( )

Definition at line 198 of file DAPHNEEthStream_binding_test.py.

198def test_header_channel_words_property() -> int:
199 frame = DAPHNEEthStreamFrame()
200 hdr = frame.header
201 hdr_alias = frame.get_header()
202 if hdr_alias is None:
203 print("FAIL: get_header() returned None")
204 return 1
205
206 words = hdr.channel_words
207 if len(words) != NUM_CHANNELS:
208 print(f"FAIL: expected {NUM_CHANNELS} channel words, got {len(words)}")
209 return 1
210
211 print("PASS: DAPHNEEthStreamHeader.channel_words readable list property")
212 return 0
213
214

◆ test_less_than_operator()

int test_less_than_operator ( )

Definition at line 83 of file DAPHNEEthStream_binding_test.py.

83def test_less_than_operator() -> int:
84 earlier = DAPHNEEthStreamFrame()
85 later = DAPHNEEthStreamFrame()
86 earlier.set_timestamp(100)
87 later.set_timestamp(200)
88 if not (earlier < later):
89 print("FAIL: __lt__ expected earlier < later")
90 return 1
91 if later < earlier:
92 print("FAIL: __lt__ expected later !< earlier")
93 return 1
94 print("PASS: __lt__ ordering by timestamp")
95 return 0
96
97

◆ test_set_geoid()

int test_set_geoid ( )

Definition at line 145 of file DAPHNEEthStream_binding_test.py.

145def test_set_geoid() -> int:
146 frame = DAPHNEEthStreamFrame()
147 crate_id = 6
148 slot_id = 4
149 stream_id = 21
150 hdr = frame.daq_header
151 hdr.crate_id = crate_id
152 hdr.slot_id = slot_id
153 hdr.stream_id = stream_id
154
155 if hdr.crate_id != crate_id:
156 print(f"FAIL: crate_id mismatch, got {hdr.crate_id}")
157 return 1
158 if hdr.slot_id != slot_id:
159 print(f"FAIL: slot_id mismatch, got {hdr.slot_id}")
160 return 1
161 if hdr.stream_id != stream_id:
162 print(f"FAIL: stream_id mismatch, got {hdr.stream_id}")
163 return 1
164
165 print("PASS: DAQEthHeader geoid fields can be set directly")
166 return 0
167
168

◆ test_static_members()

int test_static_members ( )

Definition at line 25 of file DAPHNEEthStream_binding_test.py.

25def test_static_members() -> int:
26 if DAPHNEEthStreamFrame.version != 1:
27 print(f"FAIL: DAPHNEEthStreamFrame.version expected 1, got {DAPHNEEthStreamFrame.version}")
28 return 1
29 if DAPHNEEthStreamFrame.s_num_channels != NUM_CHANNELS:
30 print(
31 "FAIL: DAPHNEEthStreamFrame.s_num_channels expected "
32 f"{NUM_CHANNELS}, got {DAPHNEEthStreamFrame.s_num_channels}"
33 )
34 return 1
35 if DAPHNEEthStreamFrame.s_adcs_per_channel != ADCS_PER_CHANNEL:
36 print(
37 "FAIL: DAPHNEEthStreamFrame.s_adcs_per_channel expected "
38 f"{ADCS_PER_CHANNEL}, got {DAPHNEEthStreamFrame.s_adcs_per_channel}"
39 )
40 return 1
41 if DAPHNEEthStreamFrame.s_expected_bytes != DAPHNEEthStreamFrame.sizeof():
42 print(
43 "FAIL: DAPHNEEthStreamFrame.s_expected_bytes "
44 f"{DAPHNEEthStreamFrame.s_expected_bytes} != sizeof {DAPHNEEthStreamFrame.sizeof()}"
45 )
46 return 1
47 if DAPHNEEthStreamHeader.s_expected_bytes <= 0:
48 print(f"FAIL: DAPHNEEthStreamHeader.s_expected_bytes invalid: {DAPHNEEthStreamHeader.s_expected_bytes}")
49 return 1
50 if DAPHNEEthStreamChannelWord.s_expected_bytes != 8:
51 print(
52 "FAIL: DAPHNEEthStreamChannelWord.s_expected_bytes expected 8, "
53 f"got {DAPHNEEthStreamChannelWord.s_expected_bytes}"
54 )
55 return 1
56 print("PASS: DAPHNEEthStreamFrame nested/static members")
57 return 0
58
59

◆ test_timestamp()

int test_timestamp ( )

Definition at line 98 of file DAPHNEEthStream_binding_test.py.

98def test_timestamp() -> int:
99 frame = DAPHNEEthStreamFrame()
100 test_ts = 0x998877665544
101 frame.set_timestamp(test_ts)
102 got = frame.get_timestamp()
103 if got != test_ts:
104 print(f"FAIL: set/get_timestamp: set {test_ts:#x}, got {got:#x}")
105 return 1
106 print("PASS: set_timestamp / get_timestamp")
107 return 0
108
109

Variable Documentation

◆ ADC_MAX

tuple DAPHNEEthStream_binding_test.ADC_MAX = (1 << 14) - 1

Definition at line 9 of file DAPHNEEthStream_binding_test.py.

◆ ADCS_PER_CHANNEL

int DAPHNEEthStream_binding_test.ADCS_PER_CHANNEL = 280

Definition at line 8 of file DAPHNEEthStream_binding_test.py.

◆ NUM_CHANNELS

int DAPHNEEthStream_binding_test.NUM_CHANNELS = 4

Definition at line 7 of file DAPHNEEthStream_binding_test.py.