From: Deepthi Hemraj <deepthi.hem...@windriver.com>

[YOCTO #15338]
Enabled ptest integration in gcc-sanitizers.inc to facilitate the proper 
testing and execution of address sanitizer (ASan)

Defined the do_check task to execute ASan tests with proper environment setup 
and updated do_install_ptest_base to copy ASan test executables to the ptest 
directory. Included the run-ptest script to automate test execution.

The run-ptest script iterates through executable files copied from the host, 
runs each on the target, and logs the outcomes as either 'PASS' or 'XFAIL'. 
XFAIL is because these tests are expected to fail on the host system as per 
dejagnu as { dg-shouldfail "asan" }

Signed-off-by: Deepthi Hemraj <deepthi.hem...@windriver.com>
---
 .../distro/include/ptest-packagelists.inc     |  1 +
 meta/recipes-devtools/gcc/gcc-14.2.inc        |  2 +
 meta/recipes-devtools/gcc/gcc-sanitizers.inc  | 43 ++++++++++++++++
 meta/recipes-devtools/gcc/gcc/asan-exp.patch  | 51 +++++++++++++++++++
 meta/recipes-devtools/gcc/gcc/run-ptest       | 28 ++++++++++
 5 files changed, 125 insertions(+)
 create mode 100644 meta/recipes-devtools/gcc/gcc/asan-exp.patch
 create mode 100755 meta/recipes-devtools/gcc/gcc/run-ptest

diff --git a/meta/conf/distro/include/ptest-packagelists.inc 
b/meta/conf/distro/include/ptest-packagelists.inc
index 7b8418654a..13b15b8647 100644
--- a/meta/conf/distro/include/ptest-packagelists.inc
+++ b/meta/conf/distro/include/ptest-packagelists.inc
@@ -85,6 +85,7 @@ PTESTS_FAST = "\
     wayland \
     xz \
     zlib \
+    gcc-sanitizers \
 "
 PTESTS_FAST:append:libc-glibc = " glibc-y2038-tests"
 PTESTS_PROBLEMS:remove:libc-glibc = "glibc-y2038-tests"
diff --git a/meta/recipes-devtools/gcc/gcc-14.2.inc 
b/meta/recipes-devtools/gcc/gcc-14.2.inc
index f05484cfc0..72cd93f4bd 100644
--- a/meta/recipes-devtools/gcc/gcc-14.2.inc
+++ b/meta/recipes-devtools/gcc/gcc-14.2.inc
@@ -68,6 +68,8 @@ SRC_URI = "${BASEURI} \
            file://0023-Fix-install-path-of-linux64.h.patch \
            file://0024-Avoid-hardcoded-build-paths-into-ppc-libgcc.patch \
            file://0025-gcc-testsuite-tweaks-for-mips-OE.patch \
+          file://asan-exp.patch \
+          file://run-ptest \
 "
 
 S = "${TMPDIR}/work-shared/gcc-${PV}-${PR}/${SOURCEDIR}"
diff --git a/meta/recipes-devtools/gcc/gcc-sanitizers.inc 
b/meta/recipes-devtools/gcc/gcc-sanitizers.inc
index 524ebd4ba4..bb617cc9de 100644
--- a/meta/recipes-devtools/gcc/gcc-sanitizers.inc
+++ b/meta/recipes-devtools/gcc/gcc-sanitizers.inc
@@ -119,3 +119,46 @@ FILES:libtsan-dev += "\
 FILES:libtsan-staticdev += "${libdir}/libtsan.a"
 
 FILES:${PN} = "${libdir}/*.spec 
${libdir}/${TARGET_SYS}/${BINV}/include/sanitizer/*.h"
+
+require gcc-testsuite.inc
+inherit ptest
+
+# test only asan.exp related testcases
+MAKE_CHECK_RUNTESTFLAGS ??= "${MAKE_CHECK_BOARDARGS} asan-ptest.exp"
+
+# specific host and target dependencies required for test suite running
+do_check[depends] += "dejagnu-native:do_populate_sysroot 
expect-native:do_populate_sysroot"
+do_check[depends] += "virtual/libc:do_populate_sysroot"
+# only depend on qemu if targeting linux user execution
+do_check[depends] += "${@'qemu-native:do_populate_sysroot' if "user" in 
d.getVar('TOOLCHAIN_TEST_TARGET') else ''}"
+do_check[prefuncs] += "extend_recipe_sysroot"
+do_check[prefuncs] += "check_prepare"
+do_check[dirs] = "${WORKDIR}/dejagnu ${B}"
+do_check() {
+    export DEJAGNU="${WORKDIR}/dejagnu/site.exp"
+    oe_runmake -i check-gcc RUNTESTFLAGS="${MAKE_CHECK_RUNTESTFLAGS}"
+}
+addtask check after do_compile before do_install_ptest_base
+
+do_install_ptest_base() {
+
+
+    ls ${B}/gcc/testsuite/gcc/*.exe > exe_files
+    tmp_file=$(cat exe_files)
+
+    echo "${tmp_file}"
+
+    install -d ${D}${PTEST_PATH}/tests/sanitizers-ptest/
+
+    for f in ${tmp_file}
+    do
+        cp -rf ${f} ${D}${PTEST_PATH}/tests/sanitizers-ptest/
+    done
+
+    install -d ${D}${PTEST_PATH}
+    cp ${S}/../sources-unpack/run-ptest ${D}${PTEST_PATH}/
+}
+
+INSANE_SKIP:${PN}-ptest += "ldflags buildpaths"
+INSANE_SKIP:${PN}-dbg += "buildpaths"
+FILES_${PN} += "${PTEST_PATH}/"
diff --git a/meta/recipes-devtools/gcc/gcc/asan-exp.patch 
b/meta/recipes-devtools/gcc/gcc/asan-exp.patch
new file mode 100644
index 0000000000..6ad8db56ef
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc/asan-exp.patch
@@ -0,0 +1,51 @@
+Upstream-Status: Pending [gcc specific]
+---
+diff --git a/gcc/testsuite/gcc.dg/asan/asan-ptest.exp 
b/gcc/testsuite/gcc.dg/asan/asan-ptest.exp
+new file mode 100644
+index 000000000..4f05d90d0
+--- /dev/null
++++ b/gcc/testsuite/gcc.dg/asan/asan-ptest.exp
+@@ -0,0 +1,43 @@
++# Copyright (C) 2012-2024 Free Software Foundation, Inc.
++#
++# This file is part of GCC.
++#
++# GCC 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; either version 3, or (at your option)
++# any later version.
++#
++# GCC 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 GCC; see the file COPYING3.  If not see
++# <http://www.gnu.org/licenses/>.
++
++# GCC testsuite that uses the `dg.exp' driver.
++
++# Load support procs.
++load_lib gcc-dg.exp
++load_lib asan-dg.exp
++
++# Initialize `dg'.
++dg-init
++# libasan uses libstdc++ so make sure we provide paths for it.
++asan_init 1
++
++# Main loop.
++if [check_effective_target_fsanitize_address] {
++    foreach testcase [lsort [glob -nocomplain $srcdir/$subdir/*.c ]] {
++        dg-test -keep-output $testcase  "" "" 
++    }
++    
++    foreach testcase [lsort [glob -nocomplain $srcdir/c-c++-common/asan/*.c 
]] {
++        dg-test -keep-output $testcase  "" "" 
++    }
++}
++
++# All done.
++asan_finish
++dg-finish
diff --git a/meta/recipes-devtools/gcc/gcc/run-ptest 
b/meta/recipes-devtools/gcc/gcc/run-ptest
new file mode 100755
index 0000000000..b8dcd16e95
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc/run-ptest
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+# This script is used to run sanitizers test suites
+
+ptestdir=$(dirname "$(readlink -f "$0")")
+export SRC_PATH=$ptestdir
+
+cd $ptestdir/
+files=$(ls tests/sanitizers-ptest/*.exe)
+total_testcases=$(ls tests/sanitizers-ptest/*.exe | wc -l)
+passed=0
+failed=0
+
+for f in $files; do
+    $f >/dev/null 2>&1
+    retcode=$?
+    if [ $retcode -eq 0 ]; then
+        echo "PASS" : $f
+        ((passed++))
+    else
+        echo "XFAIL" : $f
+        ((failed++))
+    fi
+done
+
+echo "Total Testcases: $total_testcases"
+echo "Passed: $passed"
+echo "Xfailed: $failed"
-- 
2.43.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#204060): 
https://lists.openembedded.org/g/openembedded-core/message/204060
Mute This Topic: https://lists.openembedded.org/mt/108223362/21656
Group Owner: openembedded-core+ow...@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to