Blame SOURCES/0099-tests-create-the-asan-wrapper-automatically-if-syste.patch

a3e2b5
From 34a38e3632fc504b55847fb9658788ccf5d42dad Mon Sep 17 00:00:00 2001
a3e2b5
From: Evgeny Vereshchagin <evvers@ya.ru>
a3e2b5
Date: Thu, 5 Jul 2018 04:09:30 +0000
a3e2b5
Subject: [PATCH] tests: create the asan wrapper automatically if systemd has
a3e2b5
 been built with ASAN
a3e2b5
a3e2b5
(cherry picked from commit ec9181d2ce4c0ad8b1c70b16a2b02a2667b1cc05)
a3e2b5
---
a3e2b5
 test/test-functions | 24 ++++++++++++++++++++++++
a3e2b5
 1 file changed, 24 insertions(+)
a3e2b5
a3e2b5
diff --git a/test/test-functions b/test/test-functions
a3e2b5
index e69420aeca..4417301be9 100644
a3e2b5
--- a/test/test-functions
a3e2b5
+++ b/test/test-functions
a3e2b5
@@ -28,6 +28,27 @@ STATEDIR="${BUILD_DIR:-.}/test/$(basename $(dirname $(realpath $0)))"
a3e2b5
 STATEFILE="$STATEDIR/.testdir"
a3e2b5
 TESTLOG="$STATEDIR/test.log"
a3e2b5
 
a3e2b5
+is_built_with_asan() {
a3e2b5
+    if ! type -P objdump >/dev/null; then
a3e2b5
+        ddebug "Failed to find objdump. Assuming systemd hasn't been built with ASAN."
a3e2b5
+        return 1
a3e2b5
+    fi
a3e2b5
+
a3e2b5
+    # Borrowed from https://github.com/google/oss-fuzz/blob/cd9acd02f9d3f6e80011cc1e9549be526ce5f270/infra/base-images/base-runner/bad_build_check#L182
a3e2b5
+    local _asan_calls=$(objdump -dC $BUILD_DIR/systemd | egrep "callq\s+[0-9a-f]+\s+<__asan" -c)
a3e2b5
+    if (( $_asan_calls < 1000 )); then
a3e2b5
+        return 1
a3e2b5
+    else
a3e2b5
+        return 0
a3e2b5
+    fi
a3e2b5
+}
a3e2b5
+
a3e2b5
+IS_BUILT_WITH_ASAN=$(is_built_with_asan && echo yes || echo no)
a3e2b5
+
a3e2b5
+if [[ "$IS_BUILT_WITH_ASAN" = "yes" ]]; then
a3e2b5
+    STRIP_BINARIES=no
a3e2b5
+fi
a3e2b5
+
a3e2b5
 function find_qemu_bin() {
a3e2b5
     # SUSE and Red Hat call the binary qemu-kvm. Debian and Gentoo call it kvm.
a3e2b5
     # Either way, only use this version if we aren't running in KVM, because
a3e2b5
@@ -217,6 +238,9 @@ setup_basic_environment() {
a3e2b5
     strip_binaries
a3e2b5
     install_depmod_files
a3e2b5
     generate_module_dependencies
a3e2b5
+    if [[ "$IS_BUILT_WITH_ASAN" = "yes" ]]; then
a3e2b5
+         create_asan_wrapper
a3e2b5
+    fi
a3e2b5
 }
a3e2b5
 
a3e2b5
 setup_selinux() {