DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DAPHNEEth_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_header_properties ()
int test_set_geoid ()
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 = 1
int ADCS_PER_CHANNEL = 1024
tuple ADC_MAX = (1 << 14) - 1

Function Documentation

◆ main()

int main ( )

Definition at line 256 of file DAPHNEEth_binding_test.py.

256def main() -> int:
257 tests = [
258 test_construction_and_size,
259 test_static_members,
260 test_bytes_roundtrip,
261 test_less_than_operator,
262 test_timestamp,
263 test_channel,
264 test_daqheader_accessible,
265 test_set_geoid,
266 test_header_properties,
267 test_adc_single,
268 test_adc_max_value,
269 test_adc_independence,
270 test_adc_all_channels_one_sample,
271 test_adc_out_of_range,
272 ]
273
274 failures = 0
275 for test in tests:
276 failures += test()
277
278 print()
279 if failures == 0:
280 print("All DAPHNEEthFrame Python binding tests passed")
281 else:
282 print(f"{failures} DAPHNEEthFrame Python binding test(s) FAILED")
283 return failures
284
285
int main(int argc, char *argv[])

◆ test_adc_all_channels_one_sample()

int test_adc_all_channels_one_sample ( )

Definition at line 231 of file DAPHNEEth_binding_test.py.

231def test_adc_all_channels_one_sample() -> int:
232 frame = DAPHNEEthFrame()
233 for adc_idx in range(ADCS_PER_CHANNEL):
234 frame.set_adc(adc_idx, adc_idx * 100 % (ADC_MAX + 1))
235 for adc_idx in range(ADCS_PER_CHANNEL):
236 expected = adc_idx * 100 % (ADC_MAX + 1)
237 got = frame.get_adc(adc_idx)
238 if got != expected:
239 print(f"FAIL: all-adcs test: adc index {adc_idx}: expected {expected}, got {got}")
240 return 1
241 print(f"PASS: all {ADCS_PER_CHANNEL} ADC values read back correctly")
242 return 0
243
244

◆ test_adc_independence()

int test_adc_independence ( )

Definition at line 212 of file DAPHNEEth_binding_test.py.

212def test_adc_independence() -> int:
213 frame = DAPHNEEthFrame()
214 test_cases = [
215 (0, 100),
216 (1, 200),
217 (2, 300),
218 (ADCS_PER_CHANNEL - 1, 9999),
219 ]
220 for adc_idx, val in test_cases:
221 frame.set_adc(adc_idx, val)
222 for adc_idx, expected in test_cases:
223 got = frame.get_adc(adc_idx)
224 if got != expected:
225 print(f"FAIL: ADC independence: index={adc_idx}: expected {expected}, got {got}")
226 return 1
227 print("PASS: ADC cell independence across multiple indices")
228 return 0
229
230

◆ test_adc_max_value()

int test_adc_max_value ( )

Definition at line 201 of file DAPHNEEth_binding_test.py.

201def test_adc_max_value() -> int:
202 frame = DAPHNEEthFrame()
203 frame.set_adc(0, ADC_MAX)
204 got = frame.get_adc(0)
205 if got != ADC_MAX:
206 print(f"FAIL: max ADC value {ADC_MAX}: got {got}")
207 return 1
208 print(f"PASS: max ADC value ({ADC_MAX}) preserved")
209 return 0
210
211

◆ test_adc_out_of_range()

int test_adc_out_of_range ( )

Definition at line 245 of file DAPHNEEth_binding_test.py.

245def test_adc_out_of_range() -> int:
246 frame = DAPHNEEthFrame()
247 try:
248 frame.get_adc(ADCS_PER_CHANNEL)
249 print("FAIL: get_adc with out-of-range index should have raised an exception")
250 return 1
251 except Exception:
252 pass
253 print("PASS: out-of-range ADC index raises exception as expected")
254 return 0
255

◆ test_adc_single()

int test_adc_single ( )

Definition at line 191 of file DAPHNEEth_binding_test.py.

191def test_adc_single() -> int:
192 frame = DAPHNEEthFrame()
193 frame.set_adc(0, 321)
194 if frame.get_adc(0) != 321:
195 print(f"FAIL: set_adc(0,321) -> get_adc(0) returned {frame.get_adc(0)}")
196 return 1
197 print("PASS: single ADC set/get (adc index 0)")
198 return 0
199
200

◆ test_bytes_roundtrip()

int test_bytes_roundtrip ( )

Definition at line 48 of file DAPHNEEth_binding_test.py.

48def test_bytes_roundtrip() -> int:
49 frame = DAPHNEEthFrame()
50 frame.set_timestamp(0x112233445566)
51 frame.set_channel(9)
52 raw = frame.get_bytes()
53 if len(raw) != DAPHNEEthFrame.sizeof():
54 print(f"FAIL: get_bytes() length {len(raw)} != sizeof() {DAPHNEEthFrame.sizeof()}")
55 return 1
56
57 clone = DAPHNEEthFrame(raw)
58 if clone.get_timestamp() != 0x112233445566:
59 print(f"FAIL: bytes round-trip timestamp mismatch: got {clone.get_timestamp():#x}")
60 return 1
61 if clone.get_channel() != 9:
62 print(f"FAIL: bytes round-trip channel mismatch: got {clone.get_channel()}")
63 return 1
64
65 print("PASS: DAPHNEEthFrame bytes constructor roundtrip")
66 return 0
67
68

◆ test_channel()

int test_channel ( )

Definition at line 96 of file DAPHNEEth_binding_test.py.

96def test_channel() -> int:
97 frame = DAPHNEEthFrame()
98 for val in (0, 1, 127, 255):
99 frame.set_channel(val)
100 got = frame.get_channel()
101 if got != val:
102 print(f"FAIL: set_channel({val}), get_channel() returned {got}")
103 return 1
104 print("PASS: set_channel / get_channel")
105 return 0
106
107

◆ test_construction_and_size()

int test_construction_and_size ( )

Definition at line 12 of file DAPHNEEth_binding_test.py.

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

◆ test_daqheader_accessible()

int test_daqheader_accessible ( )

Definition at line 108 of file DAPHNEEth_binding_test.py.

108def test_daqheader_accessible() -> int:
109 frame = DAPHNEEthFrame()
110 hdr = frame.daq_header
111 if hdr is None:
112 print("FAIL: daq_header returned None")
113 return 1
114 hdr_alias = frame.get_daqheader()
115 if hdr_alias is None:
116 print("FAIL: get_daqheader() returned None")
117 return 1
118 print("PASS: daq_header accessible")
119 return 0
120
121

◆ test_header_properties()

int test_header_properties ( )

Definition at line 122 of file DAPHNEEth_binding_test.py.

122def test_header_properties() -> int:
123 frame = DAPHNEEthFrame()
124 hdr = frame.header
125 hdr_alias = frame.get_daphneheader()
126
127 if hdr_alias is None:
128 print("FAIL: get_daphneheader() returned None")
129 return 1
130
131 hdr.channel = 5
132 hdr.version = 1
133 hdr.trigger_sample_value = 123
134 hdr.threshold = 456
135 hdr.baseline = 789
136 hdr.w1 = 11
137 hdr.w2 = 22
138 hdr.w3 = 33
139 hdr.w4 = 44
140 hdr.w5 = 55
141 hdr.w6 = 66
142
143 if hdr.channel != 5 or frame.get_channel() != 5:
144 print("FAIL: header.channel mismatch")
145 return 1
146 if hdr.version != 1:
147 print("FAIL: header.version mismatch")
148 return 1
149 if hdr.trigger_sample_value != 123:
150 print("FAIL: header.trigger_sample_value mismatch")
151 return 1
152 if hdr.threshold != 456:
153 print("FAIL: header.threshold mismatch")
154 return 1
155 if hdr.baseline != 789:
156 print("FAIL: header.baseline mismatch")
157 return 1
158 if (hdr.w1, hdr.w2, hdr.w3, hdr.w4, hdr.w5, hdr.w6) != (11, 22, 33, 44, 55, 66):
159 print("FAIL: w1..w6 mismatch")
160 return 1
161 if hdr_alias.w6 != 66:
162 print(f"FAIL: get_daphneheader alias mismatch, got {hdr_alias.w6}")
163 return 1
164
165 print("PASS: DAPHNEEthHeader properties")
166 return 0
167
168

◆ test_less_than_operator()

int test_less_than_operator ( )

Definition at line 69 of file DAPHNEEth_binding_test.py.

69def test_less_than_operator() -> int:
70 earlier = DAPHNEEthFrame()
71 later = DAPHNEEthFrame()
72 earlier.set_timestamp(100)
73 later.set_timestamp(200)
74 if not (earlier < later):
75 print("FAIL: __lt__ expected earlier < later")
76 return 1
77 if later < earlier:
78 print("FAIL: __lt__ expected later !< earlier")
79 return 1
80 print("PASS: __lt__ ordering by timestamp/channel tuple")
81 return 0
82
83

◆ test_set_geoid()

int test_set_geoid ( )

Definition at line 169 of file DAPHNEEth_binding_test.py.

169def test_set_geoid() -> int:
170 frame = DAPHNEEthFrame()
171 crate_id = 5
172 slot_id = 3
173 stream_id = 12
174 hdr = frame.daq_header
175 hdr.crate_id = crate_id
176 hdr.slot_id = slot_id
177 hdr.stream_id = stream_id
178 if hdr.crate_id != crate_id:
179 print(f"FAIL: crate_id mismatch, got {hdr.crate_id}")
180 return 1
181 if hdr.slot_id != slot_id:
182 print(f"FAIL: slot_id mismatch, got {hdr.slot_id}")
183 return 1
184 if hdr.stream_id != stream_id:
185 print(f"FAIL: stream_id mismatch, got {hdr.stream_id}")
186 return 1
187 print("PASS: DAQEthHeader geoid fields can be set directly")
188 return 0
189
190

◆ test_static_members()

int test_static_members ( )

Definition at line 25 of file DAPHNEEth_binding_test.py.

25def test_static_members() -> int:
26 if DAPHNEEthFrame.version != 1:
27 print(f"FAIL: DAPHNEEthFrame.version expected 1, got {DAPHNEEthFrame.version}")
28 return 1
29 if DAPHNEEthFrame.s_num_adcs != ADCS_PER_CHANNEL:
30 print(
31 "FAIL: DAPHNEEthFrame.s_num_adcs expected "
32 f"{ADCS_PER_CHANNEL}, got {DAPHNEEthFrame.s_num_adcs}"
33 )
34 return 1
35 if DAPHNEEthFrame.s_bits_per_adc != 14:
36 print(f"FAIL: DAPHNEEthFrame.s_bits_per_adc expected 14, got {DAPHNEEthFrame.s_bits_per_adc}")
37 return 1
38 if DAPHNEEthFrame.s_expected_bytes != DAPHNEEthFrame.sizeof():
39 print(f"FAIL: DAPHNEEthFrame.s_expected_bytes {DAPHNEEthFrame.s_expected_bytes} != sizeof {DAPHNEEthFrame.sizeof()}")
40 return 1
41 if DAPHNEEthHeader.s_expected_bytes <= 0:
42 print(f"FAIL: DAPHNEEthHeader.s_expected_bytes invalid: {DAPHNEEthHeader.s_expected_bytes}")
43 return 1
44 print("PASS: DAPHNEEthFrame/DAPHNEEthHeader static members")
45 return 0
46
47

◆ test_timestamp()

int test_timestamp ( )

Definition at line 84 of file DAPHNEEth_binding_test.py.

84def test_timestamp() -> int:
85 frame = DAPHNEEthFrame()
86 test_ts = 0xAABBCCDDEEFF
87 frame.set_timestamp(test_ts)
88 got = frame.get_timestamp()
89 if got != test_ts:
90 print(f"FAIL: set/get_timestamp: set {test_ts:#x}, got {got:#x}")
91 return 1
92 print("PASS: set_timestamp / get_timestamp")
93 return 0
94
95

Variable Documentation

◆ ADC_MAX

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

Definition at line 9 of file DAPHNEEth_binding_test.py.

◆ ADCS_PER_CHANNEL

int DAPHNEEth_binding_test.ADCS_PER_CHANNEL = 1024

Definition at line 8 of file DAPHNEEth_binding_test.py.

◆ NUM_CHANNELS

int DAPHNEEth_binding_test.NUM_CHANNELS = 1

Definition at line 7 of file DAPHNEEth_binding_test.py.