Line data Source code
1 : #ifndef DTCLibTest_H
2 : #define DTCLibTest_H
3 :
4 : #include "DTC.h"
5 :
6 : #include <atomic>
7 : #include <thread>
8 :
9 : namespace DTCLib
10 : {
11 : /// <summary>
12 : /// Unit tests for DTC Library
13 : /// </summary>
14 : class DTCLibTest
15 : {
16 : public:
17 : /// <summary>
18 : /// Construct the test adapter
19 : /// </summary>
20 : DTCLibTest();
21 : virtual ~DTCLibTest();
22 :
23 : // Test Control
24 : /// <summary>
25 : /// Run the specified tests
26 : /// </summary>
27 : /// <param name="classEnabled">Run class constructor/destructor test</param>
28 : /// <param name="regIOEnabled">Run register I/O test</param>
29 : /// <param name="daqEnabled">Run DAQ data test</param>
30 : /// <param name="dcsEnabled">Run DCS read/write test</param>
31 : /// <param name="nTests">Number of times to repeat tests</param>
32 : /// <param name="printMessages">Print debuffing messages (Default: false)</param>
33 : void startTest(bool classEnabled, bool regIOEnabled, bool daqEnabled, bool dcsEnabled, int nTests, bool printMessages = false);
34 : /// <summary>
35 : /// Abort testing
36 : /// </summary>
37 : void stopTests();
38 :
39 : // Accessors
40 : /// <summary>
41 : /// Determine whether tests are running
42 : /// </summary>
43 : /// <returns>Whether tests are running</returns>
44 0 : bool isRunning() const { return running_; }
45 :
46 : /// <summary>
47 : /// Get the number of instances of the Class test that passed
48 : /// </summary>
49 : /// <returns>The number of instances of the Class test that passed</returns>
50 : int classPassed();
51 : /// <summary>
52 : /// Get the number of instances of the Class test that failed
53 : /// </summary>
54 : /// <returns>The number of instances of the Class test that failed</returns>
55 : int classFailed();
56 : /// <summary>
57 : /// Get the number of instances of the Register test that passed
58 : /// </summary>
59 : /// <returns>The number of instances of the Register test that passed</returns>
60 : int regPassed();
61 : /// <summary>
62 : /// Get the number of instances of the Register test that failed
63 : /// </summary>
64 : /// <returns>The number of instances of the Register test that failed</returns>
65 : int regFailed();
66 : /// <summary>
67 : /// Get the number of instances of the DAQ test that passed
68 : /// </summary>
69 : /// <returns>The number of instances of the DAQ test that passed</returns>
70 : int daqPassed();
71 : /// <summary>
72 : /// Get the number of instances of the DAQ test that failed
73 : /// </summary>
74 : /// <returns>The number of instances of the DAQ test that failed</returns>
75 : int daqFailed();
76 : /// <summary>
77 : /// Get the number of instances of the DCS test that passed
78 : /// </summary>
79 : /// <returns>The number of instances of the DCS test that passed</returns>
80 : int dcsPassed();
81 : /// <summary>
82 : /// Get the number of instances of the DCS test that failed
83 : /// </summary>
84 : /// <returns>The number of instances of the DCS test that failed</returns>
85 : int dcsFailed();
86 :
87 : private:
88 : // Test Worker
89 : void doTests();
90 : void doClassTest();
91 : void doRegTest();
92 : void doDCSTest();
93 : void doDAQTest();
94 :
95 : static bool DataPacketIntegrityCheck(DTC_DataPacket*);
96 :
97 : // Test Status
98 : std::atomic<bool> running_;
99 :
100 : std::atomic<int> classPassed_;
101 : std::atomic<int> classFailed_;
102 : std::atomic<int> regPassed_;
103 : std::atomic<int> regFailed_;
104 : std::atomic<int> daqPassed_;
105 : std::atomic<int> daqFailed_;
106 : std::atomic<int> dcsPassed_;
107 : std::atomic<int> dcsFailed_;
108 :
109 : int classPassedTemp_;
110 : int classFailedTemp_;
111 : int regPassedTemp_;
112 : int regFailedTemp_;
113 : int daqPassedTemp_;
114 : int daqFailedTemp_;
115 : int dcsPassedTemp_;
116 : int dcsFailedTemp_;
117 :
118 : // Test Internals
119 : DTC* thisDTC_;
120 : int nTests_;
121 :
122 : bool runClassTest_;
123 : bool runRegTest_;
124 : bool runDAQTest_;
125 : bool runDCSTest_;
126 :
127 : bool printMessages_;
128 : std::thread workerThread_;
129 : };
130 : } // namespace DTCLib
131 : #endif // ifndef DTCLibTest_H
|