From 6ef48206d277ca7c2fd50db755a6cfe8a61a71e9 Mon Sep 17 00:00:00 2001 From: Simon Halvorsen Date: Thu, 27 Aug 2026 15:59:55 +0200 Subject: [PATCH 1/2] Added container to compile/unittest with ASAN Ticket: CFE-3419 Changelog: None Signed-off-by: Simon Halvorsen (cherry picked from commit 6975b91212dabe88f6a92bfdeb9f17b8c995e114) --- configure.ac | 3 ++- tests/Makefile.am | 2 +- tests/asan-check/Containerfile | 6 ++++++ tests/asan-check/Makefile.am | 25 +++++++++++++++++++++++++ tests/asan-check/run.sh | 17 +++++++++++++++++ tests/asan-check/run_checks.sh | 27 +++++++++++++++++++++++++++ 6 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 tests/asan-check/Containerfile create mode 100644 tests/asan-check/Makefile.am create mode 100755 tests/asan-check/run.sh create mode 100755 tests/asan-check/run_checks.sh diff --git a/configure.ac b/configure.ac index 7f291474c64..a21f6960fc1 100644 --- a/configure.ac +++ b/configure.ac @@ -2019,7 +2019,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 From 8aa23050c77b943026d6ecf05e89364abb12ef60 Mon Sep 17 00:00:00 2001 From: Simon Halvorsen Date: Fri, 28 Aug 2026 13:34:40 +0200 Subject: [PATCH 2/2] Updated asan-check to work in Jenkins Ticket: None Changelog: None Signed-off-by: Simon Halvorsen (cherry picked from commit 2f0af421f0cc443518d45e96bdbeee9804ada3c4) --- tests/asan-check/run_checks.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/asan-check/run_checks.sh b/tests/asan-check/run_checks.sh index 69fda5f60a4..8dae9cf930e 100755 --- a/tests/asan-check/run_checks.sh +++ b/tests/asan-check/run_checks.sh @@ -6,22 +6,25 @@ 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 + if [ "$use_procs" -lt 1 ]; then use_procs=1 fi local asan_flags="-fsanitize=address" - ./autogen.sh --enable-debug && + # Assume we are in core directory + if [ -f ./configure ] ; then + ./configure -C --enable-debug + else + ./autogen.sh -C --enable-debug + fi 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; + exit 1; fi -exit $failure