Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For discussion: Introduce sanitizer options and run with sanitizer on Linux/MacOS #78

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
name: build
# GitHub action to compile atf on ubuntu-24.04 (amd64) and macos-latest (aarch64)
# * set-up prerequisites
# * configure && make && make check && make install
# * upload installed binaries as well as kyua reports as build artefact
#
# We run in a matrix with os/sanitize flags.

on:
pull_request:
branches:
- main
push:
workflow_dispatch:

permissions:
contents: read

jobs:
build:
name: build ${{ join(matrix.sanitize, '+') }} ${{ matrix.build-os }} ${{ matrix.compiler }}
runs-on: "${{ matrix.build-os }}"
strategy:
fail-fast: false
matrix:
build-os:
- ubuntu-24.04
- macos-latest
sanitize:
- ""
- [ "asan", "lsan" ]
- ubsan
include:
- build-os: macos-latest
compiler: clang-19
pkgs:
- llvm@19
- autoconf
- automake
- libtool
# - pkgconf pre-installed on GH
llvm-bindir: /opt/homebrew/opt/llvm@19/bin
- build-os: ubuntu-24.04
compiler: clang-18
pkgs:
- clang-18
- automake
- libtool
- kyua
- pkgconf
llvm-bindir: /usr/lib/llvm-18/bin
steps:
- name: install packages (macOS)
if: runner.os == 'macOS'
run: |
# on MacOS we build with
# * latest clang@19 from brew (system provided clang lacks sanitizers)
# * ld from system
#

brew update --quiet || true
brew install ${{ join(matrix.pkgs, ' ') }}

# kyua was kicked out of brew due to lack of activity
# we patch away the disabled line and install the last built binary version
# note that it cannot be rebuilt as compiler defaults have changed
curl https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/k/kyua.rb | sed 's/[[:space:]]*disable!.*$//' > kyua.rb
brew install --formula ./kyua.rb

- name: install packages (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update --quiet || true
sudo apt-get -yq --no-install-suggests --no-install-recommends install ${{ join(matrix.pkgs, ' ') }}
- uses: actions/checkout@v4
with:
path: src.atf
- name: setup environment
run: |
echo "CC=${{ matrix.llvm-bindir }}/clang" >> "${GITHUB_ENV}"
echo "CXX=${{ matrix.llvm-bindir }}/clang++" >> "${GITHUB_ENV}"
echo "CPP=${{ matrix.llvm-bindir }}/clang-cpp" >> "${GITHUB_ENV}"
echo "AR=${{ matrix.llvm-bindir }}/llvm-ar" >> "${GITHUB_ENV}"
echo "OBJDUMP=${{ matrix.llvm-bindir }}/llvm-objdump" >> "${GITHUB_ENV}"
echo "STRIP=${{ matrix.llvm-bindir }}/llvm-strip" >> "${GITHUB_ENV}"
echo "RANLIB=${{ matrix.llvm-bindir }}/llvm-ranlib" >> "${GITHUB_ENV}"
echo "NM=${{ matrix.llvm-bindir }}/llvm-nm" >> "${GITHUB_ENV}"
echo "SRC_ATF=${GITHUB_WORKSPACE}/src.atf" >> "${GITHUB_ENV}"
echo "BUILD_ATF=${GITHUB_WORKSPACE}/build.atf" >> "${GITHUB_ENV}"
echo "INST_ATF=${GITHUB_WORKSPACE}/inst.atf" >> "${GITHUB_ENV}"
echo "NPROC=`getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null || echo 1`" >> "${GITHUB_ENV}"

- name: build atf
run: |
CFG_OPTS="--disable-dependency-tracking"
CFG_OPTS="${CFG_OPTS} --prefix=${INST_ATF}"
for i in ${{ join(matrix.sanitize, ' ') }}; do
CFG_OPTS="${CFG_OPTS} --enable-${i}"
done
echo Building atf with ${{ matrix.sanitize }} .. ${CFG_OPTS}
echo uname -a: $(uname -a)
echo uname -m: $(uname -m)
echo uname -p: $(uname -p)
kyua about | head -1
echo NPROC="${NPROC}"
echo CC="${CC}"
echo CPP="${CPP}"
echo PKG_CONFIG_PATH="${PKG_CONFIG_PATH}"
echo SRC_ATF="${SRC_ATF}"
echo BUILD_ATF="${BUILD_ATF}"
echo INST_ATF="${INST_ATF}"

cd "${SRC_ATF}"
autoreconf -isv -I/usr/local/share/aclocal

mkdir -p "${BUILD_ATF}"
cd "${BUILD_ATF}"
${SRC_ATF}/configure ${CFG_OPTS}
make -j${NPROC} | tee make-all.log

- name: install&check atf
run: |
set +e
echo Installing and Checking atf
cd "${BUILD_ATF}"
make install installcheck-kyua
check_exit=$?

cd "${INST_ATF}/tests/atf"
if [ $check_exit -eq 0 ]; then
echo "# ✅ All mandatory checks passed" >> $GITHUB_STEP_SUMMARY
# kyua report
else
echo "# ❌ Some checks failed" >> $GITHUB_STEP_SUMMARY
echo "::error file=.github/workflows/build.yaml,line=173,endLine=173,title=Checks failed!::make check failed"
# kyua report --verbose
fi

# example run with tweaks
# running one test directly without overriding exitcode and not logging to stderr
ASAN_OPTIONS=exitcode=0:log_path=$PWD/testlog kyua debug atf-c++/atf_c++_test:include
cat testlog.*

kyua report --results-filter=xfail,broken,failed | sed 's/===>/##/' >> $GITHUB_STEP_SUMMARY
if [ $check_exit -ne 0 ]; then
kyua report --verbose --results-filter=xfail,broken,failed | sed 's/===>/##/' >> $GITHUB_STEP_SUMMARY
fi

kyua report-html --output ${BUILD_ATF}/html # produces html subdirectory
# also include plain text
kyua report --verbose --results-filter=xfail,broken,failed > ${BUILD_ATF}/html/test-reportfailed.txt
# also include plain JUnit
kyua report-junit --output ${BUILD_ATF}/html/test-reportfailed.xml
# also include the kyua log
cp -a ~/.kyua/logs ${BUILD_ATF}/html/

exit $check_exit

- name: tar install archive
run: |
test -d ${INST_ATF} && tar cvf atf-${{ matrix.build-os }}-${{ matrix.compiler }}.tar -C ${INST_ATF} .
if: ${{ success() && '' == join(matrix.sanitize, '') }} # only install successful non-debug builds

- name: tar test reports
run: |
tar cvf atf-${{ matrix.build-os }}-${{ matrix.compiler }}-report${{ join(matrix.sanitize, '_') }}.tar -C "${BUILD_ATF}/html" .
if: ${{ always() }}

- name: archive build artefacts
uses: actions/upload-artifact@v4
with:
name: atf-test${{ join(matrix.sanitize, '_') }}-${{ matrix.build-os }}-${{ matrix.compiler }}
path: atf*.tar
compression-level: 0
retention-days: 10
overwrite: true
if: ${{ always() }}
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ EXTRA_DIST += $(doc_DATA) INSTALL README
#

TESTS_ENVIRONMENT = PATH=$(prefix)/bin:$${PATH} \
PKG_CONFIG_PATH=$(prefix)/lib/pkgconfig
PKG_CONFIG_PATH=$(prefix)/lib/pkgconfig \
ASAN_OPTIONS=detect_leaks=1 \
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1

# Allow the caller to override the configuration file to passed to our
# test runs below.
Expand Down
2 changes: 2 additions & 0 deletions atf-c++/Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ atf-c++/atf-c++.pc: $(srcdir)/atf-c++/atf-c++.pc.in Makefile
-e 's#__CXX__#$(ATF_BUILD_CXX)#g' \
-e 's#__INCLUDEDIR__#$(includedir)#g' \
-e 's#__LIBDIR__#$(libdir)#g' \
-e 's#__PC_CXXFLAGS__#$(pc_cxxflags)#g' \
-e 's#__PC_LDFLAGS__#$(pc_ldflags)#g' \
<$(srcdir)/atf-c++/atf-c++.pc.in >atf-c++/atf-c++.pc.tmp; \
mv atf-c++/atf-c++.pc.tmp atf-c++/atf-c++.pc

Expand Down
4 changes: 2 additions & 2 deletions atf-c++/atf-c++.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ libdir=__LIBDIR__
Name: atf-c++
Description: Automated Testing Framework (C++ binding)
Version: __ATF_VERSION__
Cflags: -I${includedir}
Libs: -L${libdir} -latf-c++ -latf-c
Cflags: -I${includedir} __PC_CXXFLAGS__
Libs: -L${libdir} -latf-c++ -latf-c __PC_LDFLAGS__
2 changes: 2 additions & 0 deletions atf-c/Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ atf-c/atf-c.pc: $(srcdir)/atf-c/atf-c.pc.in Makefile
-e 's#__CC__#$(ATF_BUILD_CC)#g' \
-e 's#__INCLUDEDIR__#$(includedir)#g' \
-e 's#__LIBDIR__#$(libdir)#g' \
-e 's#__PC_CFLAGS__#$(pc_cflags)#g' \
-e 's#__PC_LDFLAGS__#$(pc_ldflags)#g' \
<$(srcdir)/atf-c/atf-c.pc.in >atf-c/atf-c.pc.tmp; \
mv atf-c/atf-c.pc.tmp atf-c/atf-c.pc

Expand Down
4 changes: 2 additions & 2 deletions atf-c/atf-c.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ libdir=__LIBDIR__
Name: atf-c
Description: Automated Testing Framework (C binding)
Version: __ATF_VERSION__
Cflags: -I${includedir}
Libs: -L${libdir} -latf-c
Cflags: -I${includedir} __PC_CFLAGS__
Libs: -L${libdir} -latf-c __PC_LDFLAGS__
54 changes: 54 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,60 @@ AM_INIT_AUTOMAKE([1.9 check-news foreign subdir-objects -Wall])
AM_PROG_AR
LT_INIT

pc_cflags=
pc_cxxflags=
pc_ldflags=

AC_ARG_ENABLE([asan],
AS_HELP_STRING([--enable-asan], [Turn on AddressSanitizer]),,
[enable_asan=no])

if test ${enable_asan} = yes; then
AC_MSG_NOTICE([building with AddressSanitizer; developer mode autoenabled])
enable_developer=yes
CFLAGS="${CFLAGS} -fsanitize=address"
pc_cflags="${pc_cflags} -fsanitize=address"
CXXFLAGS="${CXXFLAGS} -fsanitize=address"
pc_cxxflags="${pc_cxxflags} -fsanitize=address"
LDFLAGS="${LDFLAGS} -fsanitize=address"
pc_ldflags="${pc_ldflags} -fsanitize=address"
fi

AC_ARG_ENABLE([lsan],
AS_HELP_STRING([--enable-lsan], [Turn on LeakSanitizer]),,
[enable_lsan=no])

if test ${enable_lsan} = yes; then
AC_MSG_NOTICE([building with LeakSanitizer; developer mode autoenabled])
enable_developer=yes
CFLAGS="${CFLAGS} -fsanitize=leak"
pc_cflags="${pc_cflags} -fsanitize=leak"
CXXFLAGS="${CXXFLAGS} -fsanitize=leak"
pc_cxxflags="${pc_cxxflags} -fsanitize=leak"
LDFLAGS="${LDFLAGS} -fsanitize=leak"
pc_ldflags="${pc_ldflags} -fsanitize=leak"
fi

AC_ARG_ENABLE([ubsan],
AS_HELP_STRING([--enable-ubsan], [Turn on UndefinedBehaviourSanitizer]),,
[enable_ubsan=no])

if test ${enable_ubsan} = yes; then
AC_MSG_NOTICE([building with UndefinedBehaviourSanitizer; developer mode autoenabled])
enable_developer=yes
CFLAGS="${CFLAGS} -fsanitize=undefined"
pc_cflags="${pc_cflags} -fsanitize=undefined"
CXXFLAGS="${CXXFLAGS} -fsanitize=undefined"
pc_cxxflags="${pc_cxxflags} -fsanitize=undefined"
LDFLAGS="${LDFLAGS} -fsanitize=undefined"
pc_ldflags="${pc_ldflags} -fsanitize=undefined"
fi

AC_SUBST([pc_cflags])
AC_SUBST([pc_cxxflags])
AC_SUBST([pc_ldflags])


dnl -----------------------------------------------------------------------
dnl Check for the C and C++ compilers and required features.
dnl -----------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion m4/developer-mode.m4
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ AC_DEFUN([KYUA_DEVELOPER_MODE], [
# Mac OS X. This is due to the way _IOR is defined.
#

try_c_cxx_flags="-D_FORTIFY_SOURCE=2 \
# try_c_cxx_flags="-D_FORTIFY_SOURCE=2 \
try_c_cxx_flags=" \
-Wall \
-Wcast-qual \
-Wextra \
Expand Down