From: Heinonen Arvo Date: Thu, 23 Jan 2020 15:35:45 +0000 (+0200) Subject: Enable redismodule UT in CI pipeline X-Git-Tag: 0.4.0~5 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=23808aa82b74e248e265e70db4a831124ae88460;p=ric-plt%2Fdbaas.git Enable redismodule UT in CI pipeline Add new build stage to 'Dockerfile.redis' that runs unit tests with valgrind in ubuntu-based container. Also run unit tests without valgrind in the actual build stage. Valgrind is not run at this stage because alpine-linux uses musl implementation of libc which causes valgrind to emit false positives. Unit tests and valgrind memory checks are now enabled by default. They can be disabled with the configure options: '--disable-unit-test' and '--disable-unit-test-memcheck' respectively. Disabled cpputest's builtin memory checks in UT even if they are available. Updated redismodule/README.md on compiling redismodule. Removed some Nokia-specific scripts. Signed-off-by: Arvo Heinonen Change-Id: Id7c37f6a99888d1a9229ca41dd7cbc325b6d495f --- diff --git a/docker/Dockerfile.redis b/docker/Dockerfile.redis index 98d4c26..4b29ff2 100644 --- a/docker/Dockerfile.redis +++ b/docker/Dockerfile.redis @@ -18,13 +18,54 @@ # platform project (RICP). # -FROM nexus3.o-ran-sc.org:10004/bldr-alpine3:6-a3.9-nng as build-env + +# Alpine-linux based containers use musl implementation of libc which causes +# valgrind to emit false positives. Therefore we run UT with valgrind in +# a separate build stage that uses ubuntu container with GNU libc installed. +# +# NOTE: The valgrind false positive problem could also potentially be solved +# with valgrind suppression files but that kind of approach may be fragile. +FROM ubuntu:19.10 as cpputest-build + +RUN apt update && \ + apt install -y \ + automake \ + autoconf \ + cmake \ + curl \ + g++ \ + gcc \ + libtool \ + make \ + pkg-config \ + valgrind + +# Cpputest built-in memory checks generate false positives in valgrind. +# This is solved by compiling cpputest with memory checking disabled. +WORKDIR /cpputest +RUN curl -L https://github.com/cpputest/cpputest/releases/download/v3.8/cpputest-3.8.tar.gz | \ + tar --strip-components=1 -xzf - +WORKDIR /cpputest/builddir +RUN cmake -DMEMORY_LEAK_DETECTION=OFF .. && \ + make install COPY ./redismodule /redismodule WORKDIR /redismodule RUN ./autogen.sh && \ ./configure && \ - make install -j + make test + + +FROM nexus3.o-ran-sc.org:10004/bldr-alpine3:6-a3.9-nng as build-env + +RUN apk add cpputest +COPY ./redismodule /redismodule +WORKDIR /redismodule +RUN ./autogen.sh && \ + ./configure --disable-unit-test-memcheck && \ + make test && \ + make install + FROM redis:5.0.5-alpine3.9 diff --git a/redismodule/Makefile.am b/redismodule/Makefile.am index 2c41e18..a798ed1 100755 --- a/redismodule/Makefile.am +++ b/redismodule/Makefile.am @@ -109,15 +109,26 @@ redismodule_ut2_LDFLAGS = -Wl,-rpath=${libdir} ${UT_COVERAGE_LDFLAGS} redismodule_ut2_LDADD = -L${libdir} $(LIBCPPUTEST_LIBS) -lgcov -test: redismodule_ut redismodule_ut2 - ./run-tests.sh +if UNIT_TEST_MEMCHECK_ENABLED +test: ut_memcheck_test +else +test: ut_test +endif + +ut_test: redismodule_ut redismodule_ut2 + ./redismodule_ut + ./redismodule_ut2 + +ut_memcheck_test: redismodule_ut redismodule_ut2 + valgrind --error-exitcode=1 --leak-check=full ./redismodule_ut + valgrind --error-exitcode=1 --leak-check=full ./redismodule_ut2 TESTS = run-tests.sh else test: - echo 'enable ut with configure flag: --enable-unit-test' + echo 'enable ut with configure flag: --enable-unit-test and valgrind memcheck with: --enable-unit-test-memcheck' exit 1 endif #UNIT_TEST_ENABLED diff --git a/redismodule/README.md b/redismodule/README.md index 306edd8..7bccee0 100755 --- a/redismodule/README.md +++ b/redismodule/README.md @@ -3,24 +3,29 @@ This subdirectory provides implementation for the commands which are implemented as a [Redis modules](https://redis.io/topics/modules-intro). -# Compiling and UT (Unit Tests) +# Compiling and Unit Tests -To compile and install run standard automake commands -in the redismodule directory: +To compile, run unit tests and install use the commands: ``` ./autogen.sh ./configure make +make test make install ``` -To run unit tests `cpputest` and `valgrind` -need to be installed as additional dependencies. -To enable and run unit tests use the commands: +By default unit tests and valgrind memory checking are enabled. +This requires `cpputest` and `valgrind` as additional dependencies. +Unit test memory checking can be disabled with the `configure` option +`--disable-unit-test-memcheck` and the unit tests can be completely disabled +with the `configure` option `--disable-unit-test`. +For example to compile and install with unit tests completely disabled +one would run the commands: ``` ./autogen.sh -./configure --enable-unit-test -make test +./configure --disable-unit-test +make +make install ``` # Commands diff --git a/redismodule/configure.ac b/redismodule/configure.ac index a688bef..48289c3 100755 --- a/redismodule/configure.ac +++ b/redismodule/configure.ac @@ -2,7 +2,6 @@ AC_INIT([redismodule], [0.0.0], [], [], [https://gerrit.oran-osc.org/r/#/admin/p AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIRS([m4]) AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_FILES([run-tests.sh], [chmod +x run-tests.sh]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects tar-pax]) @@ -17,14 +16,33 @@ AC_PROG_INSTALL AC_PROG_MAKE_SET AC_ARG_ENABLE([unit-test], -[ --enable-unit-test Check for UT dependencies], -[ PKG_CHECK_MODULES([LIBCPPUTEST],[cpputest]) - AC_CHECK_PROG(VALGRIND_CHECK, valgrind, yes) - AS_IF([test x"$VALGRIND_CHECK" != x"yes"], [AC_MSG_ERROR([Install valgrind to run UT.])]) - UNIT_TEST_ENABLED=true -], -[ UNIT_TEST_ENABLED=false ]) -AM_CONDITIONAL([UNIT_TEST_ENABLED], [$UNIT_TEST_ENABLED]) + [--disable-unit-test], [Disable unit tests] +) + +AS_IF([test x"$enable_unit_test" != x"no"], + [ + PKG_CHECK_MODULES([LIBCPPUTEST],[cpputest]) + AM_CONDITIONAL([UNIT_TEST_ENABLED], [true]) + ], + [ + AM_CONDITIONAL([UNIT_TEST_ENABLED], [false]) + ] +) + +AC_ARG_ENABLE([unit-test-memcheck], + [AS_HELP_STRING([--disable-unit-test-memcheck], [Do not run unit tests with valgrind])] +) + +AS_IF([test x"$enable_unit_test_memcheck" != x"no"], + [ + AC_CHECK_PROG(VALGRIND_CHECK, valgrind, yes) + AM_CONDITIONAL([UNIT_TEST_MEMCHECK_ENABLED], [true]) + ], + [ + AM_CONDITIONAL([UNIT_TEST_MEMCHECK_ENABLED], [false]) + ] +) + # Checks for header files. diff --git a/redismodule/run-tests.sh.in b/redismodule/run-tests.sh.in deleted file mode 100755 index 4de7716..0000000 --- a/redismodule/run-tests.sh.in +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -valgrind --leak-check=full ./redismodule_ut -valgrind --leak-check=full ./redismodule_ut2 -if [ $? != 0 ] -then - exit -1 -fi -subsystem=redismodule -prbname=libredismodule -UT_DIR=${VOBTAG}/$subsystem -gcda_files=$(find $UT_DIR -name '*.gcda') -if [ -z "$gcda_files" ] -then - UT_DIR=${VOBTAG}/$subsystem/buildme.ut - gcda_files=$(find $UT_DIR -name '*.gcda') - if [ -z "$gcda_files" ] - then - echo "no gcda files, so cannot generate UT coverage" - exit 0 - fi -fi -echo "gcda file is found" -lcov_src_patterns='*/redismodule/src/*' -lcov_objs_root=${VOBTAG}/$subsystem -lcov_remove_patterns='*/tst/*' -${VOBTAG}/flexiserver/build/ut_lcov.sh ${lcov_objs_root} ${lcov_src_patterns} ${lcov_remove_patterns} - diff --git a/redismodule/tst/src/main.cpp b/redismodule/tst/src/main.cpp index eb09754..e217468 100755 --- a/redismodule/tst/src/main.cpp +++ b/redismodule/tst/src/main.cpp @@ -27,5 +27,6 @@ extern "C" { int main(int ac, char** av) { - return CommandLineTestRunner::RunAllTests(ac, av); + MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); + return CommandLineTestRunner::RunAllTests(ac, av); }