blob: c80bb883f704651530ef2f0cec027fb28841200e [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
Marc Slemkoc7782972006-07-25 02:26:35 +000032 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
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000048 size_t count = 1000;
Marc Slemkoa6479032007-06-05 22:20:14 +000049 size_t floodLoops = 1;
50 size_t floodCount = 100000;
Marc Slemko8a40a762006-07-19 17:46:50 +000051
Marc Slemko03dedd92006-07-20 00:58:47 +000052 std::cout << "\t\tThreadFactory reap N threads test: N = " << count << std::endl;
53
54 assert(threadFactoryTests.reapNThreads(count));
Marc Slemko8a40a762006-07-19 17:46:50 +000055
Marc Slemkoa6479032007-06-05 22:20:14 +000056 std::cout << "\t\tThreadFactory floodN threads test: N = " << floodCount << std::endl;
57
58 assert(threadFactoryTests.floodNTest(floodLoops, floodCount));
59
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000060 std::cout << "\t\tThreadFactory synchronous start test" << std::endl;
Marc Slemko8a40a762006-07-19 17:46:50 +000061
62 assert(threadFactoryTests.synchStartTest());
Marc Slemkoc7782972006-07-25 02:26:35 +000063
64 std::cout << "\t\tThreadFactory monitor timeout test" << std::endl;
65
66 assert(threadFactoryTests.monitorTimeoutTest());
Marc Slemko8a40a762006-07-19 17:46:50 +000067 }
68
Mark Sleef5f2be42006-09-05 21:05:31 +000069 if (runAll || args[0].compare("util") == 0) {
Marc Slemkoc7782972006-07-25 02:26:35 +000070
71 std::cout << "Util tests..." << std::endl;
72
73 std::cout << "\t\tUtil minimum time" << std::endl;
74
Mark Slee9b82d272007-05-23 05:16:07 +000075 int64_t time00 = Util::currentTime();
76 int64_t time01 = Util::currentTime();
Marc Slemkoc7782972006-07-25 02:26:35 +000077
78 std::cout << "\t\t\tMinimum time: " << time01 - time00 << "ms" << std::endl;
79
80 time00 = Util::currentTime();
81 time01 = time00;
82 size_t count = 0;
Marc Slemko3a3b53b2007-05-22 23:59:54 +000083
Mark Sleef5f2be42006-09-05 21:05:31 +000084 while (time01 < time00 + 10) {
Marc Slemkoc7782972006-07-25 02:26:35 +000085 count++;
86 time01 = Util::currentTime();
87 }
88
89 std::cout << "\t\t\tscall per ms: " << count / (time01 - time00) << std::endl;
90 }
91
92
Mark Sleef5f2be42006-09-05 21:05:31 +000093 if (runAll || args[0].compare("timer-manager") == 0) {
Marc Slemko8a40a762006-07-19 17:46:50 +000094
95 std::cout << "TimerManager tests..." << std::endl;
96
97 std::cout << "\t\tTimerManager test00" << std::endl;
98
99 TimerManagerTests timerManagerTests;
100
101 assert(timerManagerTests.test00());
102 }
Marc Slemkod466b212006-07-20 00:04:18 +0000103
Mark Sleef5f2be42006-09-05 21:05:31 +0000104 if (runAll || args[0].compare("thread-manager") == 0) {
Marc Slemkod466b212006-07-20 00:04:18 +0000105
106 std::cout << "ThreadManager tests..." << std::endl;
107
Marc Slemkoc7782972006-07-25 02:26:35 +0000108 {
Marc Slemkofe5ba12e2006-07-20 21:16:27 +0000109
Marc Slemkoc7782972006-07-25 02:26:35 +0000110 size_t workerCount = 100;
Marc Slemkofe5ba12e2006-07-20 21:16:27 +0000111
Marc Slemkoc7782972006-07-25 02:26:35 +0000112 size_t taskCount = 100000;
Marc Slemkofe5ba12e2006-07-20 21:16:27 +0000113
Mark Slee9b82d272007-05-23 05:16:07 +0000114 int64_t delay = 10LL;
Marc Slemkod466b212006-07-20 00:04:18 +0000115
Marc Slemkoc7782972006-07-25 02:26:35 +0000116 std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl;
Marc Slemkod466b212006-07-20 00:04:18 +0000117
Marc Slemkoc7782972006-07-25 02:26:35 +0000118 ThreadManagerTests threadManagerTests;
119
120 assert(threadManagerTests.loadTest(taskCount, delay, workerCount));
Marc Slemko3a3b53b2007-05-22 23:59:54 +0000121
122 std::cout << "\t\tThreadManager block test: worker count: " << workerCount << " delay: " << delay << std::endl;
123
124 assert(threadManagerTests.blockTest(delay, workerCount));
125
Marc Slemkoc7782972006-07-25 02:26:35 +0000126 }
127 }
128
Mark Sleef5f2be42006-09-05 21:05:31 +0000129 if (runAll || args[0].compare("thread-manager-benchmark") == 0) {
Marc Slemkoc7782972006-07-25 02:26:35 +0000130
131 std::cout << "ThreadManager benchmark tests..." << std::endl;
132
133 {
134
135 size_t minWorkerCount = 2;
136
137 size_t maxWorkerCount = 512;
138
139 size_t tasksPerWorker = 1000;
140
Mark Slee9b82d272007-05-23 05:16:07 +0000141 int64_t delay = 10LL;
Marc Slemkoc7782972006-07-25 02:26:35 +0000142
Mark Sleef5f2be42006-09-05 21:05:31 +0000143 for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount*= 2) {
Marc Slemkoc7782972006-07-25 02:26:35 +0000144
David Reiss96d23882007-07-26 21:10:32 +0000145 size_t taskCount = workerCount * tasksPerWorker;
Marc Slemkoc7782972006-07-25 02:26:35 +0000146
David Reiss96d23882007-07-26 21:10:32 +0000147 std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl;
Marc Slemkoc7782972006-07-25 02:26:35 +0000148
David Reiss96d23882007-07-26 21:10:32 +0000149 ThreadManagerTests threadManagerTests;
Marc Slemkoc7782972006-07-25 02:26:35 +0000150
David Reiss96d23882007-07-26 21:10:32 +0000151 threadManagerTests.loadTest(taskCount, delay, workerCount);
Marc Slemkoc7782972006-07-25 02:26:35 +0000152 }
153 }
Marc Slemkod466b212006-07-20 00:04:18 +0000154 }
Marc Slemko8a40a762006-07-19 17:46:50 +0000155}