Skip to content

Commit

Permalink
Build tests with asan and ubsan together to reduce CI time.
Browse files Browse the repository at this point in the history
Also fix typo in comments

Also fix memory leak in utilities/ovn-dbctl.c

Also add "-g" to CFLAGS to forbid autotools from adding "-g -O2" (temporary solution)

Signed-off-by: Igor Zhukov <ivzhukov@sbercloud.ru>
Acked-by: Dumitru Ceara <dceara@redhat.com>
Submitted-at: #139
Acked-by: Ales Musil <amusil@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>
(cherry picked from commit 5ea3c71)
Signed-off-by: Dumitru Ceara <dceara@redhat.com>
  • Loading branch information
fsb4000 authored and dceara committed Oct 21, 2022
1 parent d146678 commit 521c671
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 29 deletions.
16 changes: 5 additions & 11 deletions .ci/linux-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,14 @@ function configure_ovn()
save_OPTS="${OPTS} $*"
OPTS="${EXTRA_OPTS} ${save_OPTS}"

# If AddressSanitizer or UdefinedBehaviorSanitizer is requested, enable it,
# If AddressSanitizer and UndefinedBehaviorSanitizer are requested, enable them,
# but only for OVN, not for OVS. However, disable some optimizations for
# OVS, to make sanitizer reports user friendly.
if [ "$ASAN" ]; then
CFLAGS="-O1 -fno-omit-frame-pointer -fno-common"
CFLAGS_ASAN="-fsanitize=address"
OVN_CFLAGS="${OVN_CFLAGS} ${CFLAGS_ASAN}"
fi

if [ "$UBSAN" ]; then
if [ "$SANITIZERS" ]; then
# Use the default options configured in tests/atlocal.in, in UBSAN_OPTIONS.
CFLAGS="-O1 -fno-omit-frame-pointer -fno-common"
CFLAGS_UBSAN="-fsanitize=undefined"
OVN_CFLAGS="${OVN_CFLAGS} ${CFLAGS_UBSAN}"
CFLAGS="-O1 -fno-omit-frame-pointer -fno-common -g"
CFLAGS_SANITIZERS="-fsanitize=address,undefined"
OVN_CFLAGS="${OVN_CFLAGS} ${CFLAGS_SANITIZERS}"
fi

if [ "$CC" = "clang" ]; then
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
M32: ${{ matrix.m32 }}
OPTS: ${{ matrix.opts }}
TESTSUITE: ${{ matrix.testsuite }}
ASAN: ${{ matrix.asan }}
UBSAN: ${{ matrix.ubsan }}
SANITIZERS: ${{ matrix.sanitizers }}
CFLAGS: ${{ matrix.cflags }}

name: linux ${{ join(matrix.*, ' ') }}
runs-on: ubuntu-20.04
Expand All @@ -41,10 +41,8 @@ jobs:
testsuite: system-test
- compiler: clang
testsuite: test
asan: asan
- compiler: clang
testsuite: test
ubsan: ubsan
sanitizers: sanitizers
cflags: -g

- compiler: gcc
testsuite: test
Expand Down
4 changes: 2 additions & 2 deletions tests/atlocal.in
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ export OVS_CTL_TIMEOUT

# Add some default flags to make the tests run better under Address
# Sanitizer, if it was used for the build.
ASAN_OPTIONS=detect_leaks=1:abort_on_error=true:log_path=asan:$ASAN_OPTIONS
ASAN_OPTIONS=detect_leaks=1:abort_on_error=true:log_path=sanitizers:$ASAN_OPTIONS
export ASAN_OPTIONS

# Add some default flags for UndefinedBehaviorSanitizer, if it was used
# for the build.
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=true:log_path=ubsan:$UBSAN_OPTIONS
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=true:log_path=sanitizers:$UBSAN_OPTIONS
export UBSAN_OPTIONS

# Check whether we should run ddlog tests.
Expand Down
3 changes: 1 addition & 2 deletions tests/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ export ovs_srcdir
check-local:
set $(SHELL) '$(TESTSUITE)' -C tests AUTOTEST_PATH=$(AUTOTEST_PATH); \
"$$@" $(TESTSUITEFLAGS) || \
(test -z "$$(find $(TESTSUITE_DIR) -name 'asan.*')" && \
test -z "$$(find $(TESTSUITE_DIR) -name 'ubsan.*')" && \
(test -z "$$(find $(TESTSUITE_DIR) -name 'sanitizers.*')" && \
test X'$(RECHECK)' = Xyes && "$$@" --recheck)

# Python Coverage support.
Expand Down
11 changes: 3 additions & 8 deletions tests/ovs-macros.at
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,9 @@ m4_divert_pop([PREPARE_TESTS])

OVS_START_SHELL_HELPERS
ovs_cleanup() {
if test "$(echo asan.*)" != 'asan.*'; then
echo "Address Sanitizer reported errors in:" asan.*
cat asan.*
AT_FAIL_IF([:])
fi
if test "$(echo ubsan.*)" != 'ubsan.*'; then
echo "Undefined Behavior Sanitizer reported errors in:" ubsan.*
cat ubsan.*
if test "$(echo sanitizers.*)" != 'sanitizers.*'; then
echo "Undefined Behavior Sanitizer or Address Sanitizer reported errors in:" sanitizers.*
cat sanitizers.*
AT_FAIL_IF([:])
fi
}
Expand Down
4 changes: 4 additions & 0 deletions utilities/ovn-dbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ ovn_dbctl_main(int argc, char *argv[],
}
free(commands);
if (error) {
for (int i = 0; i < argc; i++) {
free(argv_[i]);
}
free(argv_);
ctl_fatal("%s", error);
}
}
Expand Down

0 comments on commit 521c671

Please sign in to comment.