DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DAQHeader_binding_test.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3import sys
4from detdataformats import DAQHeader
5
6
7def main() -> int:
8
9 header = DAQHeader()
10
11 header.version = 5
12 if header.version != 5:
13 print("DAQHeader version property test failed")
14 return 1
15
16 header.det_id = 3
17 if header.det_id != 3:
18 print("DAQHeader det_id property test failed")
19 return 1
20
21 header.crate_id = 100
22 if header.crate_id != 100:
23 print("DAQHeader crate_id property test failed")
24 return 1
25
26 header.slot_id = 7
27 if header.slot_id != 7:
28 print("DAQHeader slot_id property test failed")
29 return 1
30
31 header.link_id = 15
32 if header.link_id != 15:
33 print("DAQHeader link_id property test failed")
34 return 1
35
36 print("DAQHeader basic read/write property tests passed")
37
38 timestamp_1 = 0x3E8
39 header.timestamp_1 = timestamp_1
40
41 timestamp_2 = 0x7D0
42 header.timestamp_2 = timestamp_2
43
44 try:
45 _ = header.timestamp_1
46 print("DAQHeader timestamp_1 read should have raised an exception")
47 return 1
48 except Exception:
49 print("DAQHeader timestamp_1 attempted read correctly raised an exception")
50
51 try:
52 _ = header.timestamp_2
53 print("DAQHeader timestamp_2 read should have raised an exception")
54 return 1
55 except Exception:
56 print("DAQHeader timestamp_2 attempted read correctly raised an exception")
57
58 # Test get_timestamp method returns combined timestamp
59 timestamp = header.get_timestamp()
60 expected_timestamp = 0x000007D0000003E8
61 if timestamp != expected_timestamp:
62 print(f"DAQHeader get_timestamp() test failed: got {timestamp}, expected {expected_timestamp}")
63 return 1
64 else:
65 print("DAQHeader get_timestamp() test passed")
66
67 print("\nAll DAQHeader Python binding tests passed")
68 return 0
69
70
71if __name__ == "__main__":
72 sys.exit(main())