blob: f4b0b627e0d1768473c6ca4fd1ac1e791207767d [file] [log] [blame]
Mark Slee9f0c6512007-02-28 23:58:26 +00001// 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 Slemko8a40a762006-07-19 17:46:50 +00007#include <iostream>
Marc Slemkoc7782972006-07-25 02:26:35 +00008#include <vector>
Marc Slemko8a40a762006-07-19 17:46:50 +00009#include <string>
10
11#include "ThreadFactoryTests.h"
12#include "TimerManagerTests.h"
Marc Slemkod466b212006-07-20 00:04:18 +000013#include "ThreadManagerTests.h"
Marc Slemko8a40a762006-07-19 17:46:50 +000014
15int main(int argc, char** argv) {
16
17 std::string arg;
18
Marc Slemkoc7782972006-07-25 02:26:35 +000019 std::vector<std::string> args(argc - 1 > 1 ? argc - 1 : 1);
Marc Slemko8a40a762006-07-19 17:46:50 +000020
Marc Slemkoc7782972006-07-25 02:26:35 +000021 args[0] = "all";
Marc Slemko8a40a762006-07-19 17:46:50 +000022
Mark Sleef5f2be42006-09-05 21:05:31 +000023 for (int ix = 1; ix < argc; ix++) {
Marc Slemkoc7782972006-07-25 02:26:35 +000024 args[ix - 1] = std::string(argv[ix]);
Marc Slemko8a40a762006-07-19 17:46:50 +000025 }
26
Marc Slemkoc7782972006-07-25 02:26:35 +000027 bool runAll = args[0].compare("all") == 0;
Marc Slemko8a40a762006-07-19 17:46:50 +000028
Mark Sleef5f2be42006-09-05 21:05:31 +000029 if (runAll || args[0].compare("thread-factory") == 0) {
Marc Slemko8a40a762006-07-19 17:46:50 +000030
31 ThreadFactoryTests threadFactoryTests;
Marc Slemko3a3b53b2007-05-22 23:59:54 +000032
Marc Slemko8a40a762006-07-19 17:46:50 +000033 std::cout << "ThreadFactory tests..." << std::endl;
Marc Slemko3a3b53b2007-05-22 23:59:54 +000034
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000035 size_t count = 1000;
Marc Slemko8a40a762006-07-19 17:46:50 +000036
Marc Slemko03dedd92006-07-20 00:58:47 +000037 std::cout << "\t\tThreadFactory reap N threads test: N = " << count << std::endl;
38
39 assert(threadFactoryTests.reapNThreads(count));
Marc Slemko8a40a762006-07-19 17:46:50 +000040
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000041 std::cout << "\t\tThreadFactory synchronous start test" << std::endl;
Marc Slemko8a40a762006-07-19 17:46:50 +000042
43 assert(threadFactoryTests.synchStartTest());
Marc Slemkoc7782972006-07-25 02:26:35 +000044
45 std::cout << "\t\tThreadFactory monitor timeout test" << std::endl;
46
47 assert(threadFactoryTests.monitorTimeoutTest());
Marc Slemko8a40a762006-07-19 17:46:50 +000048 }
49
Mark Sleef5f2be42006-09-05 21:05:31 +000050 if (runAll || args[0].compare("util") == 0) {
Marc Slemkoc7782972006-07-25 02:26:35 +000051
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 Slemko3a3b53b2007-05-22 23:59:54 +000064
Mark Sleef5f2be42006-09-05 21:05:31 +000065 while (time01 < time00 + 10) {
Marc Slemkoc7782972006-07-25 02:26:35 +000066 count++;
67 time01 = Util::currentTime();
68 }
69
70 std::cout << "\t\t\tscall per ms: " << count / (time01 - time00) << std::endl;
71 }
72
73
Mark Sleef5f2be42006-09-05 21:05:31 +000074 if (runAll || args[0].compare("timer-manager") == 0) {
Marc Slemko8a40a762006-07-19 17:46:50 +000075
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 Slemkod466b212006-07-20 00:04:18 +000084
Mark Sleef5f2be42006-09-05 21:05:31 +000085 if (runAll || args[0].compare("thread-manager") == 0) {
Marc Slemkod466b212006-07-20 00:04:18 +000086
87 std::cout << "ThreadManager tests..." << std::endl;
88
Marc Slemkoc7782972006-07-25 02:26:35 +000089 {
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000090
Marc Slemkoc7782972006-07-25 02:26:35 +000091 size_t workerCount = 100;
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000092
Marc Slemkoc7782972006-07-25 02:26:35 +000093 size_t taskCount = 100000;
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000094
Marc Slemkoc7782972006-07-25 02:26:35 +000095 long long delay = 10LL;
Marc Slemkod466b212006-07-20 00:04:18 +000096
Marc Slemkoc7782972006-07-25 02:26:35 +000097 std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl;
Marc Slemkod466b212006-07-20 00:04:18 +000098
Marc Slemkoc7782972006-07-25 02:26:35 +000099 ThreadManagerTests threadManagerTests;
100
101 assert(threadManagerTests.loadTest(taskCount, delay, workerCount));
Marc Slemko3a3b53b2007-05-22 23:59:54 +0000102
103 std::cout << "\t\tThreadManager block test: worker count: " << workerCount << " delay: " << delay << std::endl;
104
105 assert(threadManagerTests.blockTest(delay, workerCount));
106
Marc Slemkoc7782972006-07-25 02:26:35 +0000107 }
108 }
109
Mark Sleef5f2be42006-09-05 21:05:31 +0000110 if (runAll || args[0].compare("thread-manager-benchmark") == 0) {
Marc Slemkoc7782972006-07-25 02:26:35 +0000111
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 Sleef5f2be42006-09-05 21:05:31 +0000124 for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount*= 2) {
Marc Slemkoc7782972006-07-25 02:26:35 +0000125
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 Slemkod466b212006-07-20 00:04:18 +0000135 }
Marc Slemko8a40a762006-07-19 17:46:50 +0000136}
137