blob: 77e5551f4f4179ce6ae720fbd3fb78d71cc1eccf [file] [log] [blame]
Marc Slemko8a40a762006-07-19 17:46:50 +00001#include <iostream>
Marc Slemkoc7782972006-07-25 02:26:35 +00002#include <vector>
Marc Slemko8a40a762006-07-19 17:46:50 +00003#include <string>
4
5#include "ThreadFactoryTests.h"
6#include "TimerManagerTests.h"
Marc Slemkod466b212006-07-20 00:04:18 +00007#include "ThreadManagerTests.h"
Marc Slemko8a40a762006-07-19 17:46:50 +00008
9int main(int argc, char** argv) {
10
11 std::string arg;
12
Marc Slemkoc7782972006-07-25 02:26:35 +000013 std::vector<std::string> args(argc - 1 > 1 ? argc - 1 : 1);
Marc Slemko8a40a762006-07-19 17:46:50 +000014
Marc Slemkoc7782972006-07-25 02:26:35 +000015 args[0] = "all";
Marc Slemko8a40a762006-07-19 17:46:50 +000016
Mark Sleef5f2be42006-09-05 21:05:31 +000017 for (int ix = 1; ix < argc; ix++) {
Marc Slemkoc7782972006-07-25 02:26:35 +000018 args[ix - 1] = std::string(argv[ix]);
Marc Slemko8a40a762006-07-19 17:46:50 +000019 }
20
Marc Slemkoc7782972006-07-25 02:26:35 +000021 bool runAll = args[0].compare("all") == 0;
Marc Slemko8a40a762006-07-19 17:46:50 +000022
Mark Sleef5f2be42006-09-05 21:05:31 +000023 if (runAll || args[0].compare("thread-factory") == 0) {
Marc Slemko8a40a762006-07-19 17:46:50 +000024
25 ThreadFactoryTests threadFactoryTests;
26
27 std::cout << "ThreadFactory tests..." << std::endl;
28
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000029 size_t count = 1000;
Marc Slemko8a40a762006-07-19 17:46:50 +000030
Marc Slemko03dedd92006-07-20 00:58:47 +000031 std::cout << "\t\tThreadFactory reap N threads test: N = " << count << std::endl;
32
33 assert(threadFactoryTests.reapNThreads(count));
Marc Slemko8a40a762006-07-19 17:46:50 +000034
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000035 std::cout << "\t\tThreadFactory synchronous start test" << std::endl;
Marc Slemko8a40a762006-07-19 17:46:50 +000036
37 assert(threadFactoryTests.synchStartTest());
Marc Slemkoc7782972006-07-25 02:26:35 +000038
39 std::cout << "\t\tThreadFactory monitor timeout test" << std::endl;
40
41 assert(threadFactoryTests.monitorTimeoutTest());
Marc Slemko8a40a762006-07-19 17:46:50 +000042 }
43
Mark Sleef5f2be42006-09-05 21:05:31 +000044 if (runAll || args[0].compare("util") == 0) {
Marc Slemkoc7782972006-07-25 02:26:35 +000045
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 Sleef5f2be42006-09-05 21:05:31 +000059 while (time01 < time00 + 10) {
Marc Slemkoc7782972006-07-25 02:26:35 +000060 count++;
61 time01 = Util::currentTime();
62 }
63
64 std::cout << "\t\t\tscall per ms: " << count / (time01 - time00) << std::endl;
65 }
66
67
Mark Sleef5f2be42006-09-05 21:05:31 +000068 if (runAll || args[0].compare("timer-manager") == 0) {
Marc Slemko8a40a762006-07-19 17:46:50 +000069
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 Slemkod466b212006-07-20 00:04:18 +000078
Mark Sleef5f2be42006-09-05 21:05:31 +000079 if (runAll || args[0].compare("thread-manager") == 0) {
Marc Slemkod466b212006-07-20 00:04:18 +000080
81 std::cout << "ThreadManager tests..." << std::endl;
82
Marc Slemkoc7782972006-07-25 02:26:35 +000083 {
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000084
Marc Slemkoc7782972006-07-25 02:26:35 +000085 size_t workerCount = 100;
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000086
Marc Slemkoc7782972006-07-25 02:26:35 +000087 size_t taskCount = 100000;
Marc Slemkofe5ba12e2006-07-20 21:16:27 +000088
Marc Slemkoc7782972006-07-25 02:26:35 +000089 long long delay = 10LL;
Marc Slemkod466b212006-07-20 00:04:18 +000090
Marc Slemkoc7782972006-07-25 02:26:35 +000091 std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl;
Marc Slemkod466b212006-07-20 00:04:18 +000092
Marc Slemkoc7782972006-07-25 02:26:35 +000093 ThreadManagerTests threadManagerTests;
94
95 assert(threadManagerTests.loadTest(taskCount, delay, workerCount));
96 }
97 }
98
Mark Sleef5f2be42006-09-05 21:05:31 +000099 if (runAll || args[0].compare("thread-manager-benchmark") == 0) {
Marc Slemkoc7782972006-07-25 02:26:35 +0000100
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 Sleef5f2be42006-09-05 21:05:31 +0000113 for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount*= 2) {
Marc Slemkoc7782972006-07-25 02:26:35 +0000114
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 Slemkod466b212006-07-20 00:04:18 +0000124 }
Marc Slemko8a40a762006-07-19 17:46:50 +0000125}
126