Skip to content

Commit 0e61033

Browse files
committed
ci: run the tests under ASan/UBsan on GHActions
Signed-off-by: Evgeny Vereshchagin <[email protected]>
1 parent 7e30a10 commit 0e61033

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

.github/workflows/run_tests.yml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
python-ruby-version: {python: 3.9, ruby: 2.7, other: linker-bfd}
3030
- compiler: clang
3131
python-ruby-version: {python: 3.9, ruby: 2.7, other: linker-gold}
32+
include:
33+
- compiler: gcc
34+
python-ruby-version: {python: 3.9, ruby: 2.7, other: sanitizers}
3235

3336
steps:
3437
- uses: actions/checkout@v2
@@ -88,6 +91,11 @@ jobs:
8891
elif [ "${{ matrix.python-ruby-version.other }}" = "test-debug" ] ; then
8992
# Test hat debug build works fine
9093
EXPLICIT_MAKE_VARS="DEBUG=1"
94+
elif [ "${{ matrix.python-ruby-version.other }}" = "sanitizers" ] ; then
95+
sanitizers='-fsanitize=address,undefined'
96+
EXPLICIT_MAKE_VARS="CFLAGS='-g -I$DESTDIR/usr/include $sanitizers' LDFLAGS='-L$DESTDIR/usr/lib $sanitizers' LDLIBS= CPPFLAGS= OPT_SUBDIRS="
97+
echo "ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1" >> $GITHUB_ENV
98+
echo "UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1" >> $GITHUB_ENV
9199
else
92100
EXPLICIT_MAKE_VARS=
93101
fi
@@ -139,18 +147,18 @@ jobs:
139147
- name: Run tests
140148
run: |
141149
echo "::group::make install"
142-
make -j$(nproc) install $EXPLICIT_MAKE_VARS -k
150+
eval make -j$(nproc) install $EXPLICIT_MAKE_VARS -k
143151
echo "::endgroup::"
144152
echo "::group::make install-pywrap"
145-
make -j$(nproc) install-pywrap $EXPLICIT_MAKE_VARS -k
153+
eval make -j$(nproc) install-pywrap $EXPLICIT_MAKE_VARS -k
146154
echo "::endgroup::"
147155
echo "::group::make install-rubywrap"
148-
make -j$(nproc) install-rubywrap $EXPLICIT_MAKE_VARS -k
156+
eval make -j$(nproc) install-rubywrap $EXPLICIT_MAKE_VARS -k
149157
echo "::endgroup::"
150158
151159
# Now that everything is installed, run "make all" to build everything which may have not been built
152160
echo "::group::make all"
153-
make -j$(nproc) all $EXPLICIT_MAKE_VARS -k
161+
eval make -j$(nproc) all $EXPLICIT_MAKE_VARS -k
154162
echo "::endgroup::"
155163
156164
# Set up environment variables for the tests and show variables (to help debugging issues)
@@ -164,26 +172,28 @@ jobs:
164172
165173
# Run tests
166174
echo "::group::make test"
167-
make test $EXPLICIT_MAKE_VARS
175+
eval make test $EXPLICIT_MAKE_VARS
168176
echo "::endgroup::"
169177
170-
# Test Python and Ruby wrappers
171-
echo "::group::Test Python and Ruby wrappers"
172-
$PYTHON -c 'import selinux;import selinux.audit2why;import semanage;print(selinux.is_selinux_enabled())'
173-
$RUBY -e 'require "selinux";require "semanage";puts Selinux::is_selinux_enabled()'
174-
echo "::endgroup::"
175-
176-
# Run Python linter, but not on the downloaded refpolicy
177-
echo "::group::scripts/run-flake8"
178-
./scripts/run-flake8
179-
echo "::endgroup::"
178+
if [ "${{ matrix.python-ruby-version.other }}" != "sanitizers" ] ; then
179+
# Test Python and Ruby wrappers
180+
echo "::group::Test Python and Ruby wrappers"
181+
$PYTHON -c 'import selinux;import selinux.audit2why;import semanage;print(selinux.is_selinux_enabled())'
182+
$RUBY -e 'require "selinux";require "semanage";puts Selinux::is_selinux_enabled()'
183+
echo "::endgroup::"
184+
185+
# Run Python linter, but not on the downloaded refpolicy
186+
echo "::group::scripts/run-flake8"
187+
./scripts/run-flake8
188+
echo "::endgroup::"
189+
fi
180190
181191
echo "::group::Test .gitignore and make clean distclean"
182192
# Remove every installed files
183193
rm -rf "$DESTDIR"
184194
# Test that "git status" looks clean, or print a clear error message
185195
git status --short | sed -n 's/^??/error: missing .gitignore entry for/p' | (! grep '^')
186196
# Clean up everything and show which file needs to be added to "make clean"
187-
make clean distclean $EXPLICIT_MAKE_VARS
197+
eval make clean distclean $EXPLICIT_MAKE_VARS
188198
git ls-files --ignored --others --exclude-standard | sed 's/^/error: "make clean distclean" did not remove /' | (! grep '^')
189199
echo "::endgroup::"

libsepol/tests/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
ENV ?= env
12
M4 ?= m4
23
MKDIR ?= mkdir
34
EXE ?= libsepol-tests
@@ -44,10 +45,15 @@ clean:
4445
rm -f $(objs) $(EXE)
4546
rm -f $(policies)
4647
rm -f policies/test-downgrade/policy.hi policies/test-downgrade/policy.lo
47-
4848

49+
# mkdir is run in a clean environment created by env -i to avoid failing under ASan with:
50+
#
51+
# ASan runtime does not come first in initial library list;
52+
# you should either link runtime to your application or manually preload it with LD_PRELOAD
53+
#
54+
# when the source code is built with ASan
4955
test: $(EXE) $(policies)
50-
$(MKDIR) -p policies/test-downgrade
56+
$(ENV) -i $(MKDIR) -p policies/test-downgrade
5157
../../checkpolicy/checkpolicy -M policies/test-cond/refpolicy-base.conf -o policies/test-downgrade/policy.hi
5258
./$(EXE)
5359

0 commit comments

Comments
 (0)