David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 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 Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 19 | |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 20 | #include <iostream> |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 21 | #include <vector> |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 22 | #include <string> |
| 23 | |
| 24 | #include "ThreadFactoryTests.h" |
| 25 | #include "TimerManagerTests.h" |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 26 | #include "ThreadManagerTests.h" |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 27 | |
| 28 | int main(int argc, char** argv) { |
| 29 | |
| 30 | std::string arg; |
| 31 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 32 | std::vector<std::string> args(argc - 1 > 1 ? argc - 1 : 1); |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 33 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 34 | args[0] = "all"; |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 35 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 36 | for (int ix = 1; ix < argc; ix++) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 37 | args[ix - 1] = std::string(argv[ix]); |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 40 | bool runAll = args[0].compare("all") == 0; |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 41 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 42 | if (runAll || args[0].compare("thread-factory") == 0) { |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 43 | |
| 44 | ThreadFactoryTests threadFactoryTests; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 45 | |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 46 | std::cout << "ThreadFactory tests..." << std::endl; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 47 | |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 48 | size_t count = 1000; |
Marc Slemko | a647903 | 2007-06-05 22:20:14 +0000 | [diff] [blame] | 49 | size_t floodLoops = 1; |
| 50 | size_t floodCount = 100000; |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 51 | |
Marc Slemko | 03dedd9 | 2006-07-20 00:58:47 +0000 | [diff] [blame] | 52 | std::cout << "\t\tThreadFactory reap N threads test: N = " << count << std::endl; |
| 53 | |
| 54 | assert(threadFactoryTests.reapNThreads(count)); |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 55 | |
Marc Slemko | a647903 | 2007-06-05 22:20:14 +0000 | [diff] [blame] | 56 | std::cout << "\t\tThreadFactory floodN threads test: N = " << floodCount << std::endl; |
| 57 | |
| 58 | assert(threadFactoryTests.floodNTest(floodLoops, floodCount)); |
| 59 | |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 60 | std::cout << "\t\tThreadFactory synchronous start test" << std::endl; |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 61 | |
| 62 | assert(threadFactoryTests.synchStartTest()); |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 63 | |
| 64 | std::cout << "\t\tThreadFactory monitor timeout test" << std::endl; |
| 65 | |
| 66 | assert(threadFactoryTests.monitorTimeoutTest()); |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 69 | if (runAll || args[0].compare("util") == 0) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 70 | |
| 71 | std::cout << "Util tests..." << std::endl; |
| 72 | |
| 73 | std::cout << "\t\tUtil minimum time" << std::endl; |
| 74 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 75 | int64_t time00 = Util::currentTime(); |
| 76 | int64_t time01 = Util::currentTime(); |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 77 | |
| 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 Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 83 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 84 | while (time01 < time00 + 10) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 85 | count++; |
| 86 | time01 = Util::currentTime(); |
| 87 | } |
| 88 | |
| 89 | std::cout << "\t\t\tscall per ms: " << count / (time01 - time00) << std::endl; |
| 90 | } |
| 91 | |
| 92 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 93 | if (runAll || args[0].compare("timer-manager") == 0) { |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 94 | |
| 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 Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 103 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 104 | if (runAll || args[0].compare("thread-manager") == 0) { |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 105 | |
| 106 | std::cout << "ThreadManager tests..." << std::endl; |
| 107 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 108 | { |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 109 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 110 | size_t workerCount = 100; |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 111 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 112 | size_t taskCount = 100000; |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 113 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 114 | int64_t delay = 10LL; |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 115 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 116 | std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl; |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 117 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 118 | ThreadManagerTests threadManagerTests; |
| 119 | |
| 120 | assert(threadManagerTests.loadTest(taskCount, delay, workerCount)); |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 121 | |
| 122 | std::cout << "\t\tThreadManager block test: worker count: " << workerCount << " delay: " << delay << std::endl; |
| 123 | |
| 124 | assert(threadManagerTests.blockTest(delay, workerCount)); |
| 125 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 129 | if (runAll || args[0].compare("thread-manager-benchmark") == 0) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 130 | |
| 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 Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 141 | int64_t delay = 10LL; |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 142 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 143 | for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount*= 2) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 144 | |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 145 | size_t taskCount = workerCount * tasksPerWorker; |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 146 | |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 147 | std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl; |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 148 | |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 149 | ThreadManagerTests threadManagerTests; |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 150 | |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 151 | threadManagerTests.loadTest(taskCount, delay, workerCount); |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 152 | } |
| 153 | } |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 154 | } |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 155 | } |