blob: 33af39281124000a7cb827ad8a3fc4b8d0e65102 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Mark Slee9f0c6512007-02-28 23:58:26 +000019
Marc Slemko8a40a762006-07-19 17:46:50 +000020#include <iostream>
Marc Slemkoc7782972006-07-25 02:26:35 +000021#include <vector>
Marc Slemko8a40a762006-07-19 17:46:50 +000022#include <string>
23
24#include "ThreadFactoryTests.h"
25#include "TimerManagerTests.h"
Marc Slemkod466b212006-07-20 00:04:18 +000026#include "ThreadManagerTests.h"
Marc Slemko8a40a762006-07-19 17:46:50 +000027
28int main(int argc, char** argv) {
29
30 std::string arg;
31
Konrad Grochowski16a23a62014-11-13 15:33:38 +010032 std::vector<std::string> args(argc - 1 > 1 ? argc - 1 : 1);
Marc Slemko8a40a762006-07-19 17:46:50 +000033
Marc Slemkoc7782972006-07-25 02:26:35 +000034 args[0] = "all";
Marc Slemko8a40a762006-07-19 17:46:50 +000035
Mark Sleef5f2be42006-09-05 21:05:31 +000036 for (int ix = 1; ix < argc; ix++) {
Marc Slemkoc7782972006-07-25 02:26:35 +000037 args[ix - 1] = std::string(argv[ix]);
Marc Slemko8a40a762006-07-19 17:46:50 +000038 }
39
Marc Slemkoc7782972006-07-25 02:26:35 +000040 bool runAll = args[0].compare("all") == 0;
Marc Slemko8a40a762006-07-19 17:46:50 +000041
Mark Sleef5f2be42006-09-05 21:05:31 +000042 if (runAll || args[0].compare("thread-factory") == 0) {
Marc Slemko8a40a762006-07-19 17:46:50 +000043
44 ThreadFactoryTests threadFactoryTests;
Marc Slemko3a3b53b2007-05-22 23:59:54 +000045
Marc Slemko8a40a762006-07-19 17:46:50 +000046 std::cout << "ThreadFactory tests..." << std::endl;
Marc Slemko3a3b53b2007-05-22 23:59:54 +000047
James E. King, IIIdf899132016-11-12 15:16:30 -050048 int reapLoops = 20;
49 int reapCount = 1000;
50 size_t floodLoops = 3;
51 size_t floodCount = 20000;
Marc Slemko8a40a762006-07-19 17:46:50 +000052
James E. King, IIIdf899132016-11-12 15:16:30 -050053 std::cout << "\t\tThreadFactory reap N threads test: N = " << reapLoops << "x" << reapCount << std::endl;
Marc Slemko03dedd92006-07-20 00:58:47 +000054
James E. King, IIIdf899132016-11-12 15:16:30 -050055 if (!threadFactoryTests.reapNThreads(reapLoops, reapCount)) {
56 std::cerr << "\t\ttThreadFactory reap N threads FAILED" << std::endl;
57 return 1;
58 }
Marc Slemko8a40a762006-07-19 17:46:50 +000059
James E. King, IIIdf899132016-11-12 15:16:30 -050060 std::cout << "\t\tThreadFactory flood N threads test: N = " << floodLoops << "x" << floodCount << std::endl;
Marc Slemkoa6479032007-06-05 22:20:14 +000061
James E. King, IIIdf899132016-11-12 15:16:30 -050062 if (!threadFactoryTests.floodNTest(floodLoops, floodCount)) {
63 std::cerr << "\t\ttThreadFactory flood N threads FAILED" << std::endl;
64 return 1;
65 }
Marc Slemkoa6479032007-06-05 22:20:14 +000066
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000067 std::cout << "\t\tThreadFactory synchronous start test" << std::endl;
Marc Slemko8a40a762006-07-19 17:46:50 +000068
James E. King, IIIdf899132016-11-12 15:16:30 -050069 if (!threadFactoryTests.synchStartTest()) {
70 std::cerr << "\t\ttThreadFactory synchronous start FAILED" << std::endl;
71 return 1;
72 }
Marc Slemkoc7782972006-07-25 02:26:35 +000073
74 std::cout << "\t\tThreadFactory monitor timeout test" << std::endl;
75
James E. King, IIIdf899132016-11-12 15:16:30 -050076 if (!threadFactoryTests.monitorTimeoutTest()) {
77 std::cerr << "\t\ttThreadFactory monitor timeout FAILED" << std::endl;
78 return 1;
79 }
Marc Slemko8a40a762006-07-19 17:46:50 +000080 }
81
Mark Sleef5f2be42006-09-05 21:05:31 +000082 if (runAll || args[0].compare("util") == 0) {
Marc Slemkoc7782972006-07-25 02:26:35 +000083
84 std::cout << "Util tests..." << std::endl;
85
86 std::cout << "\t\tUtil minimum time" << std::endl;
87
Mark Slee9b82d272007-05-23 05:16:07 +000088 int64_t time00 = Util::currentTime();
89 int64_t time01 = Util::currentTime();
Marc Slemkoc7782972006-07-25 02:26:35 +000090
91 std::cout << "\t\t\tMinimum time: " << time01 - time00 << "ms" << std::endl;
92
93 time00 = Util::currentTime();
94 time01 = time00;
95 size_t count = 0;
Marc Slemko3a3b53b2007-05-22 23:59:54 +000096
Mark Sleef5f2be42006-09-05 21:05:31 +000097 while (time01 < time00 + 10) {
Marc Slemkoc7782972006-07-25 02:26:35 +000098 count++;
99 time01 = Util::currentTime();
100 }
101
102 std::cout << "\t\t\tscall per ms: " << count / (time01 - time00) << std::endl;
103 }
104
Mark Sleef5f2be42006-09-05 21:05:31 +0000105 if (runAll || args[0].compare("timer-manager") == 0) {
Marc Slemko8a40a762006-07-19 17:46:50 +0000106
107 std::cout << "TimerManager tests..." << std::endl;
108
109 std::cout << "\t\tTimerManager test00" << std::endl;
110
111 TimerManagerTests timerManagerTests;
112
James E. King, IIIdf899132016-11-12 15:16:30 -0500113 if (!timerManagerTests.test00()) {
114 std::cerr << "\t\tTimerManager tests FAILED" << std::endl;
115 return 1;
116 }
Marc Slemko8a40a762006-07-19 17:46:50 +0000117 }
Marc Slemkod466b212006-07-20 00:04:18 +0000118
Mark Sleef5f2be42006-09-05 21:05:31 +0000119 if (runAll || args[0].compare("thread-manager") == 0) {
Marc Slemkod466b212006-07-20 00:04:18 +0000120
121 std::cout << "ThreadManager tests..." << std::endl;
122
Marc Slemkoc7782972006-07-25 02:26:35 +0000123 {
Marc Slemkoc7782972006-07-25 02:26:35 +0000124 size_t workerCount = 100;
James E. King, IIIdf899132016-11-12 15:16:30 -0500125 size_t taskCount = 50000;
Mark Slee9b82d272007-05-23 05:16:07 +0000126 int64_t delay = 10LL;
Marc Slemkod466b212006-07-20 00:04:18 +0000127
James E. King, IIIdf899132016-11-12 15:16:30 -0500128 ThreadManagerTests threadManagerTests;
129
130 std::cout << "\t\tThreadManager api test:" << std::endl;
131
132 if (!threadManagerTests.apiTest()) {
133 std::cerr << "\t\tThreadManager apiTest FAILED" << std::endl;
134 return 1;
135 }
136
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100137 std::cout << "\t\tThreadManager load test: worker count: " << workerCount
138 << " task count: " << taskCount << " delay: " << delay << std::endl;
Marc Slemkod466b212006-07-20 00:04:18 +0000139
James E. King, IIIdf899132016-11-12 15:16:30 -0500140 if (!threadManagerTests.loadTest(taskCount, delay, workerCount)) {
141 std::cerr << "\t\tThreadManager loadTest FAILED" << std::endl;
142 return 1;
143 }
Marc Slemko3a3b53b2007-05-22 23:59:54 +0000144
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100145 std::cout << "\t\tThreadManager block test: worker count: " << workerCount
146 << " delay: " << delay << std::endl;
Marc Slemko3a3b53b2007-05-22 23:59:54 +0000147
James E. King, IIIdf899132016-11-12 15:16:30 -0500148 if (!threadManagerTests.blockTest(delay, workerCount)) {
149 std::cerr << "\t\tThreadManager blockTest FAILED" << std::endl;
150 return 1;
151 }
Marc Slemkoc7782972006-07-25 02:26:35 +0000152 }
153 }
154
Mark Sleef5f2be42006-09-05 21:05:31 +0000155 if (runAll || args[0].compare("thread-manager-benchmark") == 0) {
Marc Slemkoc7782972006-07-25 02:26:35 +0000156
157 std::cout << "ThreadManager benchmark tests..." << std::endl;
158
159 {
160
161 size_t minWorkerCount = 2;
162
James E. King, IIIdf899132016-11-12 15:16:30 -0500163 size_t maxWorkerCount = 64;
Marc Slemkoc7782972006-07-25 02:26:35 +0000164
165 size_t tasksPerWorker = 1000;
166
James E. King, IIIdf899132016-11-12 15:16:30 -0500167 int64_t delay = 5LL;
Marc Slemkoc7782972006-07-25 02:26:35 +0000168
James E. King, IIIdf899132016-11-12 15:16:30 -0500169 for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount *= 4) {
Marc Slemkoc7782972006-07-25 02:26:35 +0000170
David Reiss96d23882007-07-26 21:10:32 +0000171 size_t taskCount = workerCount * tasksPerWorker;
Marc Slemkoc7782972006-07-25 02:26:35 +0000172
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100173 std::cout << "\t\tThreadManager load test: worker count: " << workerCount
174 << " task count: " << taskCount << " delay: " << delay << std::endl;
Marc Slemkoc7782972006-07-25 02:26:35 +0000175
David Reiss96d23882007-07-26 21:10:32 +0000176 ThreadManagerTests threadManagerTests;
Marc Slemkoc7782972006-07-25 02:26:35 +0000177
James E. King, IIIdf899132016-11-12 15:16:30 -0500178 if (!threadManagerTests.loadTest(taskCount, delay, workerCount))
179 {
180 std::cerr << "\t\tThreadManager loadTest FAILED" << std::endl;
181 return 1;
182 }
Marc Slemkoc7782972006-07-25 02:26:35 +0000183 }
184 }
Marc Slemkod466b212006-07-20 00:04:18 +0000185 }
James E. King, IIIdf899132016-11-12 15:16:30 -0500186
187 std::cout << "ALL TESTS PASSED" << std::endl;
188 return 0;
Marc Slemko8a40a762006-07-19 17:46:50 +0000189}