diff --git a/Snakefile b/Snakefile index 3c35de3..75da378 100644 --- a/Snakefile +++ b/Snakefile @@ -92,7 +92,7 @@ SUPPRESSED_CC_WARNINGS = ( CFLAGS = '-march=native -O2 -g -Wall -Wextra ' + ' '.join(map(lambda s: '-Wno-' + s, SUPPRESSED_CC_WARNINGS)) + ' -Iinclude' if os.getenv('DEBUG', 0): CFLAGS = '-march=native -Og -g3 -Wall -Wextra ' + ' '.join(map(lambda s: '-Wno-' + s, SUPPRESSED_CC_WARNINGS)) + ' -Iinclude -DDEBUG' -LIBS = '-lnuma -pthread -lpcre -lrt' +LIBS = '-pthread -lpcre -lrt' if USE_CUDA: CFLAGS += ' -DUSE_CUDA' if USE_PHI: CFLAGS += ' -DUSE_PHI' if USE_OPENSSL_EVP: CFLAGS += ' -DUSE_OPENSSL_EVP' @@ -197,7 +197,7 @@ LIBS += ' -L{DPDK_PATH}/lib' \ + ' -Wl,--no-whole-archive' # Other dependencies -LIBS += ' -ldl' +LIBS += ' -lnuma -ldl' # Expand variables CFLAGS = fmt(CFLAGS) @@ -217,7 +217,7 @@ logger.set_level(logging.INFO) # Build rules rule main: - input: OBJ_FILES + [lib.target for lib in THIRD_PARTY_LIBS] + input: OBJ_FILES, [lib.target for lib in THIRD_PARTY_LIBS] output: 'bin/main' shell: '{CXX} -o {output} -Wl,--whole-archive {OBJ_FILES} -Wl,--no-whole-archive {LIBS}' @@ -232,17 +232,35 @@ rule clean: shell: _clean_cmds _test_cases, = glob_wildcards('tests/test_{case}.cc') +TEST_LIBS = '-lgtest_main -lgtest' +MAINLESS_OBJ_FILES = OBJ_FILES.copy() +MAINLESS_OBJ_FILES.remove('build/src/main.o') -rule test: +rule cleantest: + shell: 'rm -rf build/tests tests/test_all' + +rule test: # build only individual tests input: expand('tests/test_{case}', case=_test_cases) +rule testall: # build a unified test suite + input: + testobjs=expand(joinpath(OBJ_DIR, 'tests/test_{case}.o'), case=_test_cases), + objs=MAINLESS_OBJ_FILES, + libs=[lib.target for lib in THIRD_PARTY_LIBS] + output: 'tests/test_all' + shell: '{CXX} {CXXFLAGS} -o {output} {input.testobjs} -Wl,--whole-archive {input.objs} -Wl,--no-whole-archive {TEST_LIBS} {LIBS}' + for case in _test_cases: includes = [f for f in compilelib.get_includes(fmt('tests/test_{case}.cc'), 'include')] requires = [joinpath(OBJ_DIR, f) for f in compilelib.get_requires(fmt('tests/test_{case}.cc'), 'src')] - rule: + rule: # for individual tests input: fmt('tests/test_{case}.cc'), includes, req=requires output: fmt('tests/test_{case}') - shell: '{CXX} {CXXFLAGS} -o {output} {input[0]} {input.req} {LIBS}' + shell: '{CXX} {CXXFLAGS} -o {output} {input[0]} {input.req} {TEST_LIBS} {LIBS}' + rule: # for unified test suite + input: fmt('tests/test_{case}.cc'), includes + output: joinpath(OBJ_DIR, fmt('tests/test_{case}.o')) + shell: '{CXX} {CXXFLAGS} -o {output} -c {input[0]}' for srcfile in SOURCE_FILES: # We generate build rules dynamically depending on the actual header diff --git a/tests/test_core_bitmap.cc b/tests/test_core_bitmap.cc index bed8557..eaa3369 100644 --- a/tests/test_core_bitmap.cc +++ b/tests/test_core_bitmap.cc @@ -6,8 +6,4 @@ using namespace nba; -int main() { - return 0; -} - // vim: ts=8 sts=4 sw=4 et diff --git a/tests/test_core_shiftedint.cc b/tests/test_core_shiftedint.cc index 0bf749c..2b2dc8e 100644 --- a/tests/test_core_shiftedint.cc +++ b/tests/test_core_shiftedint.cc @@ -1,24 +1,19 @@ #include #include #include +#include using namespace nba; -int main() { - printf("TEST: core.shiftedint\n"); - { - test_assert(sizeof(ShiftedInt) == sizeof(uint16_t), - "The size of ShfitedInt must be same to the given template."); - } - { - auto x = ShiftedInt(123); - test_assert((uint32_t) x == 120, "Expected precision loss due to shift."); - } - { - auto x = ShiftedInt(120); - test_assert((uint32_t) x == 120, "Expected exactly same value."); - } - return 0; +TEST(CoreShiftedIntTest, StorageSize) { + EXPECT_EQ(sizeof(ShiftedInt), sizeof(uint16_t)); +} + +TEST(CoreShiftedIntTest, Assignment) { + auto x = ShiftedInt(123); + EXPECT_EQ((uint32_t) x, 120) << "Precision loss due to shift should occur."; + auto y = ShiftedInt(120); + EXPECT_EQ((uint32_t) y, 120) << "Should be exactly same."; } // vim: ts=8 sts=4 sw=4 et