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

View File

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