# 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
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
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
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])
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.
+++ /dev/null
-#!/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}
-
int main(int ac, char** av)
{
- return CommandLineTestRunner::RunAllTests(ac, av);
+ MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
+ return CommandLineTestRunner::RunAllTests(ac, av);
}