added multithreading test

This commit is contained in:
Pedro 2014-10-17 16:25:55 +02:00
parent b97ae3545f
commit 75a4bed720
2 changed files with 36 additions and 5 deletions

View File

@ -13,7 +13,7 @@ EXECUTION_MAIN = sql_execution.cpp
EXECUTION_BIN = bin/sql_execution EXECUTION_BIN = bin/sql_execution
CC = g++ CC = g++
CFLAGS = -g -O3 -Ilib/ -I./ -Ibison/ CFLAGS = -g -O3 -Ilib/ -I./ -I$(PARSER)/ -std=c++11 -pthread
tests: $(LIB_FILES) $(TESTS_MAIN) tests: $(LIB_FILES) $(TESTS_MAIN)
@ -27,7 +27,11 @@ execution: $(LIB_FILES) $(EXECUTION_MAIN)
bison/bison_parser.c: bison/bison_parser.c:
make -C bison/ make -C bison/
lemon/lemon_parser.c:
make -C lemon/
clean: clean:
rm -f *.o *~ $(EXECUTION_BIN) $(TESTS_BIN) rm -f *.o *~ $(EXECUTION_BIN) $(TESTS_BIN)
make clean -C bison/ make clean -C bison/
make clean -C lemon/

View File

@ -6,6 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>
#include <cassert> #include <cassert>
#include <thread>
#define STREQUALS(str1, str2) std::string(str1).compare(std::string(str2)) == 0 #define STREQUALS(str1, str2) std::string(str1).compare(std::string(str2)) == 0
@ -70,12 +71,19 @@ void SelectTest2() {
printf("passed!\n"); printf("passed!\n");
} }
void SelectTest3() { int parse_count = 0;
printf("Test: SelectTest3... "); void SelectTest3(bool print) {
if (print) printf("Test: SelectTest3... ");
fflush(stdout); fflush(stdout);
const char* sql = "SELECT name, AVG(age) FROM table GROUP BY name"; const char* sql = "SELECT name, AVG(age) FROM table GROUP BY name";
parse_count++;
Statement* stmt = SQLParser::parseSQL(sql); Statement* stmt = SQLParser::parseSQL(sql);
if (parse_count != 1) printf("+");
parse_count--;
ASSERT(stmt != NULL); ASSERT(stmt != NULL);
ASSERT(stmt->_type == eSelect); ASSERT(stmt->_type == eSelect);
@ -92,10 +100,28 @@ void SelectTest3() {
ASSERT(select->_group_by->size() == 1); ASSERT(select->_group_by->size() == 1);
ASSERT_STR("name", select->_group_by->at(0)->name); ASSERT_STR("name", select->_group_by->at(0)->name);
printf("passed!\n"); if (print) printf("passed!\n");
} }
/** Multithread Test **/
void multithreadTest(int numberOfRuns, int id) {
for (int n = 0; n < numberOfRuns; ++n) {
SelectTest3(false);
}
}
void ThreadSafeTest(uint numThreads, uint runsPerThread) {
printf("Starting multithread-test... ");
std::thread* threads = new std::thread[numThreads];
for (int n = 0; n < numThreads; ++n) {
threads[n] = std::thread(multithreadTest, runsPerThread, n);
}
for (int n = 0; n < numThreads; ++n) {
threads[n].join();
}
printf("finished!\n");
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -104,7 +130,8 @@ int main(int argc, char *argv[]) {
SelectTest1(); SelectTest1();
SelectTest2(); SelectTest2();
SelectTest3(); SelectTest3(true);
ThreadSafeTest(10, 1000);
printf("\n## Finished running all tests...\n"); printf("\n## Finished running all tests...\n");
printf("######################################\n"); printf("######################################\n");