Subversion Repositories SmartDukaan

Rev

Rev 30 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements. See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership. The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License. You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied. See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
 
20
#include <iostream>
21
#include <vector>
22
#include <string>
23
 
24
#include "ThreadFactoryTests.h"
25
#include "TimerManagerTests.h"
26
#include "ThreadManagerTests.h"
27
 
28
int main(int argc, char** argv) {
29
 
30
  std::string arg;
31
 
32
  std::vector<std::string>  args(argc - 1 > 1 ? argc - 1 : 1);
33
 
34
  args[0] = "all";
35
 
36
  for (int ix = 1; ix < argc; ix++) {
37
    args[ix - 1] = std::string(argv[ix]);
38
  }
39
 
40
  bool runAll = args[0].compare("all") == 0;
41
 
42
  if (runAll || args[0].compare("thread-factory") == 0) {
43
 
44
    ThreadFactoryTests threadFactoryTests;
45
 
46
    std::cout << "ThreadFactory tests..." << std::endl;
47
 
48
    size_t count =  1000;
49
    size_t floodLoops =  1;
50
    size_t floodCount =  100000;
51
 
52
    std::cout << "\t\tThreadFactory reap N threads test: N = " << count << std::endl;
53
 
54
    assert(threadFactoryTests.reapNThreads(count));
55
 
56
    std::cout << "\t\tThreadFactory floodN threads test: N = " << floodCount << std::endl;
57
 
58
    assert(threadFactoryTests.floodNTest(floodLoops, floodCount));
59
 
60
    std::cout << "\t\tThreadFactory synchronous start test" << std::endl;
61
 
62
    assert(threadFactoryTests.synchStartTest());
63
 
64
    std::cout << "\t\tThreadFactory monitor timeout test" << std::endl;
65
 
66
    assert(threadFactoryTests.monitorTimeoutTest());
67
  }
68
 
69
  if (runAll || args[0].compare("util") == 0) {
70
 
71
    std::cout << "Util tests..." << std::endl;
72
 
73
    std::cout << "\t\tUtil minimum time" << std::endl;
74
 
75
    int64_t time00 = Util::currentTime();
76
    int64_t time01 = Util::currentTime();
77
 
78
    std::cout << "\t\t\tMinimum time: " << time01 - time00 << "ms" << std::endl;
79
 
80
    time00 = Util::currentTime();
81
    time01 = time00;
82
    size_t count = 0;
83
 
84
    while (time01 < time00 + 10) {
85
      count++;
86
      time01 = Util::currentTime();
87
    }
88
 
89
    std::cout << "\t\t\tscall per ms: " << count / (time01 - time00) << std::endl;
90
  }
91
 
92
 
93
  if (runAll || args[0].compare("timer-manager") == 0) {
94
 
95
    std::cout << "TimerManager tests..." << std::endl;
96
 
97
    std::cout << "\t\tTimerManager test00" << std::endl;
98
 
99
    TimerManagerTests timerManagerTests;
100
 
101
    assert(timerManagerTests.test00());
102
  }
103
 
104
  if (runAll || args[0].compare("thread-manager") == 0) {
105
 
106
    std::cout << "ThreadManager tests..." << std::endl;
107
 
108
    {
109
 
110
      size_t workerCount = 100;
111
 
112
      size_t taskCount = 100000;
113
 
114
      int64_t delay = 10LL;
115
 
116
      std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl;
117
 
118
      ThreadManagerTests threadManagerTests;
119
 
120
      assert(threadManagerTests.loadTest(taskCount, delay, workerCount));
121
 
122
      std::cout << "\t\tThreadManager block test: worker count: " << workerCount << " delay: " << delay << std::endl;
123
 
124
      assert(threadManagerTests.blockTest(delay, workerCount));
125
 
126
    }
127
  }
128
 
129
  if (runAll || args[0].compare("thread-manager-benchmark") == 0) {
130
 
131
    std::cout << "ThreadManager benchmark tests..." << std::endl;
132
 
133
    {
134
 
135
      size_t minWorkerCount = 2;
136
 
137
      size_t maxWorkerCount = 512;
138
 
139
      size_t tasksPerWorker = 1000;
140
 
141
      int64_t delay = 10LL;
142
 
143
      for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount*= 2) {
144
 
145
        size_t taskCount = workerCount * tasksPerWorker;
146
 
147
        std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl;
148
 
149
        ThreadManagerTests threadManagerTests;
150
 
151
        threadManagerTests.loadTest(taskCount, delay, workerCount);
152
      }
153
    }
154
  }
155
}