Mark Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006- Facebook |
| 2 | // Distributed under the Thrift Software License |
| 3 | // |
| 4 | // See accompanying file LICENSE or visit the Thrift site at: |
| 5 | // http://developers.facebook.com/thrift/ |
| 6 | |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 7 | #include <iostream> |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 8 | #include <vector> |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 9 | #include <string> |
| 10 | |
| 11 | #include "ThreadFactoryTests.h" |
| 12 | #include "TimerManagerTests.h" |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 13 | #include "ThreadManagerTests.h" |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 14 | |
| 15 | int main(int argc, char** argv) { |
| 16 | |
| 17 | std::string arg; |
| 18 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 19 | std::vector<std::string> args(argc - 1 > 1 ? argc - 1 : 1); |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 20 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 21 | args[0] = "all"; |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 22 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 23 | for (int ix = 1; ix < argc; ix++) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 24 | args[ix - 1] = std::string(argv[ix]); |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 27 | bool runAll = args[0].compare("all") == 0; |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 28 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 29 | if (runAll || args[0].compare("thread-factory") == 0) { |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 30 | |
| 31 | ThreadFactoryTests threadFactoryTests; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame^] | 32 | |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 33 | std::cout << "ThreadFactory tests..." << std::endl; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame^] | 34 | |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 35 | size_t count = 1000; |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 36 | |
Marc Slemko | 03dedd9 | 2006-07-20 00:58:47 +0000 | [diff] [blame] | 37 | std::cout << "\t\tThreadFactory reap N threads test: N = " << count << std::endl; |
| 38 | |
| 39 | assert(threadFactoryTests.reapNThreads(count)); |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 40 | |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 41 | std::cout << "\t\tThreadFactory synchronous start test" << std::endl; |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 42 | |
| 43 | assert(threadFactoryTests.synchStartTest()); |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 44 | |
| 45 | std::cout << "\t\tThreadFactory monitor timeout test" << std::endl; |
| 46 | |
| 47 | assert(threadFactoryTests.monitorTimeoutTest()); |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 50 | if (runAll || args[0].compare("util") == 0) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 51 | |
| 52 | std::cout << "Util tests..." << std::endl; |
| 53 | |
| 54 | std::cout << "\t\tUtil minimum time" << std::endl; |
| 55 | |
| 56 | long long time00 = Util::currentTime(); |
| 57 | long long time01 = Util::currentTime(); |
| 58 | |
| 59 | std::cout << "\t\t\tMinimum time: " << time01 - time00 << "ms" << std::endl; |
| 60 | |
| 61 | time00 = Util::currentTime(); |
| 62 | time01 = time00; |
| 63 | size_t count = 0; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame^] | 64 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 65 | while (time01 < time00 + 10) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 66 | count++; |
| 67 | time01 = Util::currentTime(); |
| 68 | } |
| 69 | |
| 70 | std::cout << "\t\t\tscall per ms: " << count / (time01 - time00) << std::endl; |
| 71 | } |
| 72 | |
| 73 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 74 | if (runAll || args[0].compare("timer-manager") == 0) { |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 75 | |
| 76 | std::cout << "TimerManager tests..." << std::endl; |
| 77 | |
| 78 | std::cout << "\t\tTimerManager test00" << std::endl; |
| 79 | |
| 80 | TimerManagerTests timerManagerTests; |
| 81 | |
| 82 | assert(timerManagerTests.test00()); |
| 83 | } |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 84 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 85 | if (runAll || args[0].compare("thread-manager") == 0) { |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 86 | |
| 87 | std::cout << "ThreadManager tests..." << std::endl; |
| 88 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 89 | { |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 90 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 91 | size_t workerCount = 100; |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 92 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 93 | size_t taskCount = 100000; |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 94 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 95 | long long delay = 10LL; |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 96 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 97 | 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] | 98 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 99 | ThreadManagerTests threadManagerTests; |
| 100 | |
| 101 | assert(threadManagerTests.loadTest(taskCount, delay, workerCount)); |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame^] | 102 | |
| 103 | std::cout << "\t\tThreadManager block test: worker count: " << workerCount << " delay: " << delay << std::endl; |
| 104 | |
| 105 | assert(threadManagerTests.blockTest(delay, workerCount)); |
| 106 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 110 | if (runAll || args[0].compare("thread-manager-benchmark") == 0) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 111 | |
| 112 | std::cout << "ThreadManager benchmark tests..." << std::endl; |
| 113 | |
| 114 | { |
| 115 | |
| 116 | size_t minWorkerCount = 2; |
| 117 | |
| 118 | size_t maxWorkerCount = 512; |
| 119 | |
| 120 | size_t tasksPerWorker = 1000; |
| 121 | |
| 122 | long long delay = 10LL; |
| 123 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 124 | for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount*= 2) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 125 | |
| 126 | size_t taskCount = workerCount * tasksPerWorker; |
| 127 | |
| 128 | std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl; |
| 129 | |
| 130 | ThreadManagerTests threadManagerTests; |
| 131 | |
| 132 | threadManagerTests.loadTest(taskCount, delay, workerCount); |
| 133 | } |
| 134 | } |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 135 | } |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 136 | } |
| 137 | |