Skip to content

Commit

Permalink
✅ add threadpool and log test
Browse files Browse the repository at this point in the history
  • Loading branch information
markparticle committed Jun 29, 2020
1 parent 225dd3c commit b3b1326
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
6 changes: 3 additions & 3 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
CXX = g++
CFLAGS = -std=c++14 -O2 -Wall -g

TARGET = server
TARGET = test
OBJS = ../code/log/*.cpp ../code/pool/*.cpp ../code/timer/*.cpp \
../code/http/*.cpp ../code/server/*.cpp \
../code/buffer/*.cpp ../code/main.cpp
../code/buffer/*.cpp ../test/test.cpp

all: $(OBJS)
$(CXX) $(CFLAGS) $(OBJS) -o ../bin/$(TARGET) -pthread -lmysqlclient
$(CXX) $(CFLAGS) $(OBJS) -o $(TARGET) -pthread -lmysqlclient

clean:
rm -rf ../bin/$(OBJS) $(TARGET)
Expand Down
File renamed without changes.
29 changes: 23 additions & 6 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,47 @@
* @copyleft GPL 2.0
*/
#include "../code/log/log.h"
#include "../code/pool/threadpool.h"

void TestLog() {
int cnt = 0, level = 0;
Log::Instance()->init(level, "./log//testlog1", ".log", 0);
Log::Instance()->init(level, "./testlog1", ".log", 0);
for(level = 3; level >= 0; level--) {
Log::Instance()->SetLevel(level);
for(int j = 0; j < 100000; j++ ){
for(int j = 0; j < 10000; j++ ){
for(int i = 0; i < 4; i++) {
LOG_BASE(i,"%s============%d 2222222222 ", "Test", cnt++);
LOG_BASE(i,"%s 111111111 %d ============= ", "Test", cnt++);
}
}
}
cnt = 0;
Log::Instance()->init(level, "./log/testlog2", ".log", 5000);
Log::Instance()->init(level, "./testlog2", ".log", 5000);
for(level = 0; level < 4; level++) {
Log::Instance()->SetLevel(level);
for(int j = 0; j < 100000; j++ ){
for(int j = 0; j < 10000; j++ ){
for(int i = 0; i < 4; i++) {
LOG_BASE(i,"%s 111111111 %d ============= ", "Test", cnt++);
LOG_BASE(i,"%s 222222222 %d ============= ", "Test", cnt++);
}
}
}
}

void ThreadLogTask(int i, int cnt) {
for(int j = 0; j < 10000; j++ ){
LOG_BASE(i,"PID:[%04d]======= %05d ========= ", gettid(), cnt++);
}
}

void TestThreadPool() {
Log::Instance()->init(0, "./testThreadpool", ".log", 5000);
ThreadPool threadpool(6);
for(int i = 0; i < 18; i++) {
threadpool.addTask(std::bind(ThreadLogTask, i % 4, i * 10000));
}
getchar();
}

int main() {
TestLog();
TestThreadPool();
}

0 comments on commit b3b1326

Please sign in to comment.