Line data Source code
1 : #include <ctype.h>
2 : #include <iostream>
3 :
4 : #include "dtcInterfaceLib/DTCLibTest.h"
5 :
6 0 : void usage()
7 : {
8 0 : std::cout << "This program runs several functionality tests of libDTCInterface." << std::endl
9 0 : << "If run with no options, it will run all 4 tests." << std::endl
10 0 : << "Otherwise, it accepts a space-delimited list of the tests to run," << std::endl
11 0 : << "defined either by test number {0,1,4,5}, or test name {class, reg, dcs, daq}" << std::endl
12 0 : << "It also accepts a -n argument indicating how many iterations of the tests it should run" << std::endl;
13 0 : }
14 :
15 0 : int main(int argc, char* argv[])
16 : {
17 0 : auto testCount = 1;
18 0 : auto classTest = false, registerTest = false, dcsTest = false, daqTest = false;
19 0 : auto testsSpecified = false;
20 :
21 0 : if (argc == 1)
22 : {
23 0 : std::cout << "Running all DTC Tests." << std::endl
24 0 : << std::endl;
25 : }
26 : else
27 : {
28 0 : for (auto i = 1; i < argc; ++i)
29 : {
30 0 : auto firstChar = 0;
31 0 : if (argv[i][0] == '-')
32 : {
33 0 : firstChar = 1;
34 0 : if (argv[i][1] == 'n' && argc >= i + 1)
35 : {
36 0 : ++i;
37 0 : testCount = atoi(argv[i]);
38 0 : continue;
39 : }
40 0 : if (argv[i][1] == 'h' || argc == i + 1)
41 : {
42 0 : usage();
43 0 : exit(0);
44 : }
45 : }
46 0 : if (isdigit(static_cast<unsigned char>(argv[i][firstChar])))
47 : {
48 0 : testsSpecified = true;
49 0 : switch (argv[i][firstChar] - '0')
50 : {
51 0 : case 0:
52 0 : classTest = true;
53 0 : break;
54 0 : case 1:
55 0 : registerTest = true;
56 0 : break;
57 0 : case 4:
58 0 : dcsTest = true;
59 0 : break;
60 0 : case 5:
61 0 : daqTest = true;
62 0 : break;
63 0 : default:
64 0 : break;
65 : }
66 : }
67 : else
68 : {
69 0 : std::string arg(argv[i]);
70 0 : arg = arg.substr(firstChar);
71 0 : if (arg.find("class") != std::string::npos)
72 : {
73 0 : testsSpecified = true;
74 0 : classTest = true;
75 : }
76 0 : else if (arg.find("reg") != std::string::npos)
77 : {
78 0 : testsSpecified = true;
79 0 : registerTest = true;
80 : }
81 0 : else if (arg.find("dcs") != std::string::npos)
82 : {
83 0 : testsSpecified = true;
84 0 : dcsTest = true;
85 : }
86 0 : else if (arg.find("daq") != std::string::npos || arg.find("dma") != std::string::npos)
87 : {
88 0 : daqTest = true;
89 0 : testsSpecified = true;
90 : }
91 : else
92 : {
93 0 : usage();
94 0 : exit(0);
95 : }
96 0 : }
97 : }
98 : }
99 0 : if (!testsSpecified)
100 : {
101 0 : classTest = true;
102 0 : registerTest = true;
103 0 : dcsTest = true;
104 0 : daqTest = true;
105 : }
106 :
107 : std::cout << "Running tests: " << (classTest ? "Class Construction/Destruction " : "")
108 : << (registerTest ? "Register I/O " : "") << (dcsTest ? "DCS DMA I/O " : "")
109 0 : << (daqTest ? "DAQ DMA I/O " : "") << ", " << testCount << " times." << std::endl;
110 :
111 0 : auto tester = new DTCLib::DTCLibTest();
112 :
113 0 : tester->startTest(classTest, registerTest, daqTest, dcsTest, testCount, true);
114 :
115 0 : while (tester->isRunning())
116 : {
117 0 : usleep(500000);
118 : }
119 0 : delete tester;
120 0 : }
|