Skip to content

Commit

Permalink
refs #27: Add unified test suite
Browse files Browse the repository at this point in the history
 * `snakemake testall` combines all test cases in a single binary,
   tests/test_all.
   You may use gtest's filter options to run only specific test cases.

 * `snakemake test` builds individual executables for each test suite.
   This is for isolated, faster-iteration test cases.

 * `snakemake cleantest` removes test-related binaries.
   (It does NOT remove other framework/element binaries, though.
   You should use `snakemake clean` to remove them.)
  • Loading branch information
achimnol committed Jan 20, 2016
1 parent 1bda622 commit 762ff5f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
30 changes: 24 additions & 6 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand All @@ -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}'

Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions tests/test_core_bitmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@

using namespace nba;

int main() {
return 0;
}

// vim: ts=8 sts=4 sw=4 et
25 changes: 10 additions & 15 deletions tests/test_core_shiftedint.cc
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
#include <nba/core/assert.hh>
#include <nba/core/shiftedint.hh>
#include <cstdio>
#include <gtest/gtest.h>

using namespace nba;

int main() {
printf("TEST: core.shiftedint\n");
{
test_assert(sizeof(ShiftedInt<uint16_t, 0>) == sizeof(uint16_t),
"The size of ShfitedInt must be same to the given template.");
}
{
auto x = ShiftedInt<uint16_t, 2>(123);
test_assert((uint32_t) x == 120, "Expected precision loss due to shift.");
}
{
auto x = ShiftedInt<uint16_t, 2>(120);
test_assert((uint32_t) x == 120, "Expected exactly same value.");
}
return 0;
TEST(CoreShiftedIntTest, StorageSize) {
EXPECT_EQ(sizeof(ShiftedInt<uint16_t, 0>), sizeof(uint16_t));
}

TEST(CoreShiftedIntTest, Assignment) {
auto x = ShiftedInt<uint16_t, 2>(123);
EXPECT_EQ((uint32_t) x, 120) << "Precision loss due to shift should occur.";
auto y = ShiftedInt<uint16_t, 2>(120);
EXPECT_EQ((uint32_t) y, 120) << "Should be exactly same.";
}

// vim: ts=8 sts=4 sw=4 et

0 comments on commit 762ff5f

Please sign in to comment.