diff --git a/configure.ac b/configure.ac index 767fad0049a..1663bbdb94a 100644 --- a/configure.ac +++ b/configure.ac @@ -2034,7 +2034,8 @@ AC_CONFIG_FILES([Makefile tests/unit/Makefile tests/load/Makefile tests/static-check/Makefile - tests/valgrind-check/Makefile]) + tests/valgrind-check/Makefile + tests/asan-check/Makefile]) # Run autoconf/configure in libutils, generating necessary makefiles: AC_CONFIG_SUBDIRS([libntech]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 340cbf403d8..0f80e566120 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,4 +21,4 @@ # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. # -SUBDIRS = unit load acceptance static-check valgrind-check +SUBDIRS = unit load acceptance static-check valgrind-check asan-check diff --git a/tests/asan-check/Containerfile b/tests/asan-check/Containerfile new file mode 100644 index 00000000000..4b3c6e92074 --- /dev/null +++ b/tests/asan-check/Containerfile @@ -0,0 +1,6 @@ +FROM ubuntu:24.04 AS build +RUN DEBIAN_FRONTEND=noninteractive apt-get update -y --fix-missing && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y libssl-dev libxml2-dev libpam0g-dev liblmdb-dev libacl1-dev libpcre2-dev librsync-dev git flex bison byacc automake make autoconf libtool +COPY . core +WORKDIR core +CMD bash tests/asan-check/run_checks.sh diff --git a/tests/asan-check/Makefile.am b/tests/asan-check/Makefile.am new file mode 100644 index 00000000000..9f99b624c9b --- /dev/null +++ b/tests/asan-check/Makefile.am @@ -0,0 +1,25 @@ +# +# Copyright 2026 Northern.tech AS +# +# This file is part of CFEngine 3 - written and maintained by Northern.tech AS. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA +# +# To the extent this program is licensed as part of the Enterprise +# versions of CFEngine, the applicable Commercial Open Source License +# (COSL) may apply to this file if you as a licensee so wish it. See +# included file COSL.txt. +# + +DISTFILES = run_checks.sh run.sh Makefile.in Makefile.am Containerfile diff --git a/tests/asan-check/run.sh b/tests/asan-check/run.sh new file mode 100755 index 00000000000..80d00046e0b --- /dev/null +++ b/tests/asan-check/run.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e +trap "echo FAILURE" ERR + +set -x + +cd "$(dirname "$0")"/../../ + +if which podman ; then + CLI="sudo podman --cgroup-manager=cgroupfs" +else + CLI="docker" +fi + +$CLI build --tag ubuntu:mycfecontainer -f ./tests/asan-check/Containerfile . +$CLI run --rm ubuntu:mycfecontainer diff --git a/tests/asan-check/run_checks.sh b/tests/asan-check/run_checks.sh new file mode 100755 index 00000000000..69fda5f60a4 --- /dev/null +++ b/tests/asan-check/run_checks.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -x + +function check_with_asan() { + local n_procs use_procs + n_procs="$(getconf _NPROCESSORS_ONLN)" + use_procs=$((n_procs/2)) + if [ "$use_procs" -lt "1" ]; then + use_procs=1 + fi + + local asan_flags="-fsanitize=address" + + ./autogen.sh --enable-debug && + make -j"${use_procs}" CFLAGS="-Werror -Wall -Wextra -Wno-sign-compare ${asan_flags}" LDFLAGS="${asan_flags}" && + make -C tests/unit CFLAGS="${asan_flags}" LDFLAGS="${asan_flags}" check +} + +cd "$(dirname "$0")"/../../ + +failure=0 +if ! check_with_asan; then + echo "FAIL: ASAN compile/unit check failed"; + failure=1; +fi +exit $failure