blob: 2b7b7f3768aecf760dba80a9ef3d21733ab7f300 [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 Slemkoa6479032007-06-05 22:20:14 +000036 size_t floodLoops = 1;
37 size_t floodCount = 100000;
Marc Slemko8a40a762006-07-19 17:46:50 +000038
Marc Slemko03dedd92006-07-20 00:58:47 +000039 std::cout << "\t\tThreadFactory reap N threads test: N = " << count << std::endl;
40
41 assert(threadFactoryTests.reapNThreads(count));
Marc Slemko8a40a762006-07-19 17:46:50 +000042
Marc Slemkoa6479032007-06-05 22:20:14 +000043 std::cout << "\t\tThreadFactory floodN threads test: N = " << floodCount << std::endl;
44
45 assert(threadFactoryTests.floodNTest(floodLoops, floodCount));
46
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000047 std::cout << "\t\tThreadFactory synchronous start test" << std::endl;
Marc Slemko8a40a762006-07-19 17:46:50 +000048
49 assert(threadFactoryTests.synchStartTest());
Marc Slemkoc7782972006-07-25 02:26:35 +000050
51 std::cout << "\t\tThreadFactory monitor timeout test" << std::endl;
52
53 assert(threadFactoryTests.monitorTimeoutTest());
Marc Slemko8a40a762006-07-19 17:46:50 +000054 }
55
Mark Sleef5f2be42006-09-05 21:05:31 +000056 if (runAll || args[0].compare("util") == 0) {
Marc Slemkoc7782972006-07-25 02:26:35 +000057
58 std::cout << "Util tests..." << std::endl;
59
60 std::cout << "\t\tUtil minimum time" << std::endl;
61
Mark Slee9b82d272007-05-23 05:16:07 +000062 int64_t time00 = Util::currentTime();
63 int64_t time01 = Util::currentTime();
Marc Slemkoc7782972006-07-25 02:26:35 +000064
65 std::cout << "\t\t\tMinimum time: " << time01 - time00 << "ms" << std::endl;
66
67 time00 = Util::currentTime();
68 time01 = time00;
69 size_t count = 0;
Marc Slemko3a3b53b2007-05-22 23:59:54 +000070
Mark Sleef5f2be42006-09-05 21:05:31 +000071 while (time01 < time00 + 10) {
Marc Slemkoc7782972006-07-25 02:26:35 +000072 count++;
73 time01 = Util::currentTime();
74 }
75
76 std::cout << "\t\t\tscall per ms: " << count / (time01 - time00) << std::endl;
77 }
78
79
Mark Sleef5f2be42006-09-05 21:05:31 +000080 if (runAll || args[0].compare("timer-manager") == 0) {
Marc Slemko8a40a762006-07-19 17:46:50 +000081
82 std::cout << "TimerManager tests..." << std::endl;
83
84 std::cout << "\t\tTimerManager test00" << std::endl;
85
86 TimerManagerTests timerManagerTests;
87
88 assert(timerManagerTests.test00());
89 }
Marc Slemkod466b212006-07-20 00:04:18 +000090
Mark Sleef5f2be42006-09-05 21:05:31 +000091 if (runAll || args[0].compare("thread-manager") == 0) {
Marc Slemkod466b212006-07-20 00:04:18 +000092
93 std::cout << "ThreadManager tests..." << std::endl;
94
Marc Slemkoc7782972006-07-25 02:26:35 +000095 {
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000096
Marc Slemkoc7782972006-07-25 02:26:35 +000097 size_t workerCount = 100;
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000098
Marc Slemkoc7782972006-07-25 02:26:35 +000099 size_t taskCount = 100000;
Marc Slemkofe5ba12e2006-07-20 21:16:27 +0000100
Mark Slee9b82d272007-05-23 05:16:07 +0000101 int64_t delay = 10LL;
Marc Slemkod466b212006-07-20 00:04:18 +0000102
Marc Slemkoc7782972006-07-25 02:26:35 +0000103 std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl;
Marc Slemkod466b212006-07-20 00:04:18 +0000104
Marc Slemkoc7782972006-07-25 02:26:35 +0000105 ThreadManagerTests threadManagerTests;
106
107 assert(threadManagerTests.loadTest(taskCount, delay, workerCount));
Marc Slemko3a3b53b2007-05-22 23:59:54 +0000108
109 std::cout << "\t\tThreadManager block test: worker count: " << workerCount << " delay: " << delay << std::endl;
110
111 assert(threadManagerTests.blockTest(delay, workerCount));
112
Marc Slemkoc7782972006-07-25 02:26:35 +0000113 }
114 }
115
Mark Sleef5f2be42006-09-05 21:05:31 +0000116 if (runAll || args[0].compare("thread-manager-benchmark") == 0) {
Marc Slemkoc7782972006-07-25 02:26:35 +0000117
118 std::cout << "ThreadManager benchmark tests..." << std::endl;
119
120 {
121
122 size_t minWorkerCount = 2;
123
124 size_t maxWorkerCount = 512;
125
126 size_t tasksPerWorker = 1000;
127
Mark Slee9b82d272007-05-23 05:16:07 +0000128 int64_t delay = 10LL;
Marc Slemkoc7782972006-07-25 02:26:35 +0000129
Mark Sleef5f2be42006-09-05 21:05:31 +0000130 for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount*= 2) {
Marc Slemkoc7782972006-07-25 02:26:35 +0000131
David Reiss96d23882007-07-26 21:10:32 +0000132 size_t taskCount = workerCount * tasksPerWorker;
Marc Slemkoc7782972006-07-25 02:26:35 +0000133
David Reiss96d23882007-07-26 21:10:32 +0000134 std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl;
Marc Slemkoc7782972006-07-25 02:26:35 +0000135
David Reiss96d23882007-07-26 21:10:32 +0000136 ThreadManagerTests threadManagerTests;
Marc Slemkoc7782972006-07-25 02:26:35 +0000137
David Reiss96d23882007-07-26 21:10:32 +0000138 threadManagerTests.loadTest(taskCount, delay, workerCount);
Marc Slemkoc7782972006-07-25 02:26:35 +0000139 }
140 }
Marc Slemkod466b212006-07-20 00:04:18 +0000141 }
Marc Slemko8a40a762006-07-19 17:46:50 +0000142}