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