Extend test suite. Build with -O3 by default. (#42)

* Change benchmarks and add -O3 to build
* Extended test suite. Makefile now buidls with -O3 by default. Added Makefile flag (mode=debug) to build with -g instead.
This commit is contained in:
Pedro Flemming 2017-05-26 15:18:52 -07:00 committed by GitHub
parent 128cd74670
commit 5e6cd2d84f
5 changed files with 118 additions and 56 deletions

View File

@ -29,5 +29,11 @@ compiler:
script: script:
- make cleanall - make cleanall
- make - make -j4
- make test - make test
- make test_format
- make test_example
# Test if benchmark can be built.
# - make build_benchmark

View File

@ -1,9 +1,9 @@
# directories # Directories.
BIN = bin BIN = bin
SRC = src SRC = src
SRCPARSER = src/parser SRCPARSER = src/parser
# files # Files.
PARSERCPP = $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp PARSERCPP = $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp
LIBCPP = $(shell find $(SRC) -name '*.cpp' -not -path "$(SRCPARSER)/*") $(PARSERCPP) LIBCPP = $(shell find $(SRC) -name '*.cpp' -not -path "$(SRCPARSER)/*") $(PARSERCPP)
LIBOBJ = $(LIBCPP:%.cpp=%.o) LIBOBJ = $(LIBCPP:%.cpp=%.o)
@ -11,44 +11,54 @@ TESTCPP = $(shell find test/ -name '*.cpp')
ALLLIB = $(shell find $(SRC) -name '*.cpp' -not -path "$(SRCPARSER)/*") $(shell find $(SRC) -name '*.h' -not -path "$(SRCPARSER)/*") ALLLIB = $(shell find $(SRC) -name '*.cpp' -not -path "$(SRCPARSER)/*") $(shell find $(SRC) -name '*.h' -not -path "$(SRCPARSER)/*")
ALLTEST = $(shell find test/ -name '*.cpp') $(shell find test/ -name '*.h') ALLTEST = $(shell find test/ -name '*.cpp') $(shell find test/ -name '*.h')
EXAMPLESRC = $(shell find example/ -name '*.cpp') $(shell find example/ -name '*.h')
# compile & link flages # Compiler & linker flags.
CFLAGS = -std=c++11 -Wall -fPIC -g CFLAGS = -std=c++11 -Wall -fPIC
LIBFLAGS = -shared LIBFLAGS = -shared
TARGET = libsqlparser.so TARGET = libsqlparser.so
INSTALL = /usr/local INSTALL = /usr/local
CTESTFLAGS = -Wall -Isrc/ -Itest/ -L./ -std=c++11 -lstdc++ -g CTESTFLAGS = -Wall -Isrc/ -Itest/ -L./ -std=c++11 -lstdc++ -O3
# Set compile mode to -g or -O3.
mode ?= release
ifeq ($(mode), debug)
CFLAGS += -g
else
CFLAGS += -O3
endif
GMAKE = make mode=$(mode)
all: library all: library
library: $(TARGET) library: $(TARGET)
$(TARGET): $(LIBOBJ) $(TARGET): $(LIBOBJ)
echo $(mode)
$(CXX) $(LIBFLAGS) -o $(TARGET) $(LIBOBJ) $(CXX) $(LIBFLAGS) -o $(TARGET) $(LIBOBJ)
$(SRCPARSER)/flex_lexer.o: $(SRCPARSER)/flex_lexer.cpp $(SRCPARSER)/flex_lexer.o: $(SRCPARSER)/flex_lexer.cpp $(SRCPARSER)/bison_parser.cpp
$(CXX) $(CFLAGS) -c -o $@ $< -Wno-sign-compare -Wno-unneeded-internal-declaration -Wno-deprecated-register $(CXX) $(CFLAGS) -c -o $@ $< -Wno-sign-compare -Wno-unneeded-internal-declaration -Wno-deprecated-register
%.o: %.cpp $(PARSERCPP) %.o: %.cpp $(PARSERCPP)
$(CXX) $(CFLAGS) -c -o $@ $< $(CXX) $(CFLAGS) -c -o $@ $<
$(SRCPARSER)/bison_parser.cpp: $(SRCPARSER)/bison_parser.y $(SRCPARSER)/bison_parser.cpp: $(SRCPARSER)/bison_parser.y
make -C $(SRCPARSER)/ bison_parser.cpp $(GMAKE) -C $(SRCPARSER)/ bison_parser.cpp
$(SRCPARSER)/flex_lexer.cpp: $(SRCPARSER)/flex_lexer.l $(SRCPARSER)/flex_lexer.cpp: $(SRCPARSER)/flex_lexer.l
make -C $(SRCPARSER)/ flex_lexer.cpp $(GMAKE) -C $(SRCPARSER)/ flex_lexer.cpp
parser:
make -C $(SRCPARSER) all
clean: clean:
rm -f $(TARGET) rm -f $(TARGET)
rm -rf $(BIN) rm -rf $(BIN)
find $(SRC) -type f -name '*.o' -delete find $(SRC) -type f -name '*.o' -delete
$(GMAKE) -C benchmark/ clean
cleanparser: cleanparser:
make -C $(SRCPARSER)/ clean $(GMAKE) -C $(SRCPARSER)/ clean
cleanall: clean cleanparser cleanall: clean cleanparser
@ -58,12 +68,15 @@ install:
cp -r src $(INSTALL)/include/hsql cp -r src $(INSTALL)/include/hsql
find $(INSTALL)/include/hsql -not -name '*.h' -type f | xargs rm find $(INSTALL)/include/hsql -not -name '*.h' -type f | xargs rm
format: #################
astyle --options=astyle.options $(ALLLIB) ### Benchmark ###
astyle --options=astyle.options $(ALLTEST) #################
run_benchmark: benchmark: library
make -C benchmark/ clean run $(GMAKE) -C benchmark/ clean run
build_benchmark: library
$(GMAKE) -C benchmark/ parser_benchmark
############ ############
### Test ### ### Test ###
@ -72,11 +85,26 @@ run_benchmark:
test: $(BIN)/sql_tests test: $(BIN)/sql_tests
bash test/test.sh bash test/test.sh
# test whete test_example:
test_install: $(GMAKE) -C example/
make -C example/ LD_LIBRARY_PATH=./ \
./example/example "SELECT * FROM students WHERE name = 'Max Mustermann';" ./example/example "SELECT * FROM students WHERE name = 'Max Mustermann';"
test_format:
@! astyle --options=astyle.options $(ALLLIB) | grep -q "Formatted"
@! astyle --options=astyle.options $(ALLTEST) | grep -q "Formatted"
$(BIN)/sql_tests: library $(BIN)/sql_tests: library
@mkdir -p $(BIN)/ @mkdir -p $(BIN)/
$(CXX) $(CTESTFLAGS) $(TESTCPP) -o $(BIN)/sql_tests -lsqlparser $(CXX) $(CTESTFLAGS) $(TESTCPP) -o $(BIN)/sql_tests -lsqlparser
############
### Misc ###
############
format:
astyle --options=astyle.options $(ALLLIB)
astyle --options=astyle.options $(ALLTEST)
astyle --options=astyle.options $(EXAMPLESRC)

View File

@ -2,12 +2,13 @@
SRC = ./ SRC = ./
CPP = $(shell find $(SRC) -name '*.cpp') CPP = $(shell find $(SRC) -name '*.cpp')
CFLAGS = -std=c++11 -lstdc++ -Wall -I../src/ -L../ CFLAGS = -std=c++11 -lstdc++ -Wall -I../src/ -L../ -O3
all: parser_benchmark all: parser_benchmark
run: parser_benchmark run: parser_benchmark
@export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:../ && ./parser_benchmark @export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:../ &&\
./parser_benchmark
parser_benchmark: $(CPP) parser_benchmark: $(CPP)
$(CXX) $(CFLAGS) $(CPP) -o parser_benchmark -lbenchmark -lpthread -lsqlparser $(CXX) $(CFLAGS) $(CPP) -o parser_benchmark -lbenchmark -lpthread -lsqlparser

View File

@ -10,12 +10,39 @@
#include "benchmark_utils.h" #include "benchmark_utils.h"
PARSE_QUERY_BENCHMARK(BM_SimpleSelect, PARSE_QUERY_BENCHMARK(BM_Q1SimpleSelect,
"SELECT * FROM test;"); "SELECT * FROM test;");
PARSE_QUERY_BENCHMARK(BM_SimpleSubSelect, PARSE_QUERY_BENCHMARK(BM_Q2SimpleSubSelect,
"SELECT age, street AS address FROM (SELECT * FROM data);"); "SELECT a, b AS address FROM (SELECT * FROM test WHERE c < 100 AND b > 3) t1 WHERE a < 10 AND b < 100;");
PARSE_QUERY_BENCHMARK(BM_Q3SingleJoin,
"SELECT \"left\".a, \"left\".b, \"right\".a, \"right\".b FROM table_a AS \"left\" JOIN table_b AS \"right\" ON \"left\".a = \"right\".a;");
PARSE_QUERY_BENCHMARK(BM_Q4TPCHQuery,
"SELECT"
" l_orderkey,"
" SUM(l_extendedprice * (1 - l_discount)) AS revenue,"
" o_orderdate,"
" o_shippriority"
" FROM"
" customer,"
" orders,"
" lineitem"
" WHERE"
" c_mktsegment = '%s'"
" and c_custkey = o_custkey"
" and l_orderkey = o_orderkey"
" and o_orderdate < '%s'"
" and l_shipdate > '%s'"
" GROUP BY"
" l_orderkey,"
" o_orderdate,"
" o_shippriority"
" ORDER BY"
" revenue DESC,"
" o_orderdate;"
);
PARSE_QUERY_BENCHMARK(BM_TwoSelects, PARSE_QUERY_BENCHMARK(BM_TwoSelects,
"SELECT * FROM test; SELECT age, street AS address FROM data;"); "SELECT * FROM test; SELECT age, street AS address FROM data;");

View File

@ -8,34 +8,34 @@
// contains printing utilities // contains printing utilities
#include "util/sqlhelper.h" #include "util/sqlhelper.h"
int main(int argc, char *argv[]) { int main(int argc, char* argv[]) {
if (argc <= 1) { if (argc <= 1) {
fprintf(stderr, "Usage: ./example \"SELECT * FROM test;\"\n"); fprintf(stderr, "Usage: ./example \"SELECT * FROM test;\"\n");
return -1; return -1;
} }
std::string query = argv[1]; std::string query = argv[1];
// parse a given query // parse a given query
hsql::SQLParserResult result; hsql::SQLParserResult result;
hsql::SQLParser::parseSQLString(query, &result); hsql::SQLParser::parseSQLString(query, &result);
// check whether the parsing was successful // check whether the parsing was successful
if (result.isValid()) { if (result.isValid()) {
printf("Parsed successfully!\n"); printf("Parsed successfully!\n");
printf("Number of statements: %lu\n", result.size()); printf("Number of statements: %lu\n", result.size());
for (uint i = 0; i < result.size(); ++i) { for (uint i = 0; i < result.size(); ++i) {
// Print a statement summary. // Print a statement summary.
hsql::printStatementInfo(result.getStatement(i)); hsql::printStatementInfo(result.getStatement(i));
}
return 0;
} else {
fprintf(stderr, "Given string is not a valid SQL query.\n");
fprintf(stderr, "%s (L%d:%d)\n",
result.errorMsg(),
result.errorLine(),
result.errorColumn());
return -1;
} }
return 0;
} else {
fprintf(stderr, "Given string is not a valid SQL query.\n");
fprintf(stderr, "%s (L%d:%d)\n",
result.errorMsg(),
result.errorLine(),
result.errorColumn());
return -1;
}
} }