summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Khalikov <d.khalikov@partner.samsung.com>2018-01-24 18:51:31 +0300
committerDenis Khalikov <d.khalikov@partner.samsung.com>2018-01-24 18:51:31 +0300
commite02ff9cb23040ec72423720afd06bae4d8aabbe8 (patch)
treed3d183c582f927018f0f3a2881ac30971cd13308
parent20e2f2a4dbc161cbfe3362f49c2f0e4b49c7ab76 (diff)
downloadlinaro-gcc-sandbox/denis13/esan.tar.gz
linaro-gcc-sandbox/denis13/esan.tar.bz2
linaro-gcc-sandbox/denis13/esan.zip
[ESan] Add testsandbox/denis13/esan
Change-Id: Ia77ded09d2e6de62635d5c1c16fdb6ade70401c4
-rw-r--r--gcc/testsuite/g++.dg/esan/esan.exp34
-rw-r--r--gcc/testsuite/g++.dg/esan/workingset-simple.C29
-rw-r--r--gcc/testsuite/lib/esan-dg.exp156
3 files changed, 219 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/esan/esan.exp b/gcc/testsuite/g++.dg/esan/esan.exp
new file mode 100644
index 00000000000..9052347ce8e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/esan/esan.exp
@@ -0,0 +1,34 @@
+# Copyright (C) 2012-2016 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/>.
+
+# Load support procs.
+load_lib g++-dg.exp
+load_lib esan-dg.exp
+
+# Initialize `dg'.
+dg-init
+esan_init
+
+# Main loop.
+if [check_effective_target_fsanitize_esan] {
+ gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C]] "" ""
+}
+
+# All done.
+esan_finish
+dg-finish
diff --git a/gcc/testsuite/g++.dg/esan/workingset-simple.C b/gcc/testsuite/g++.dg/esan/workingset-simple.C
new file mode 100644
index 00000000000..f38134ed46d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/esan/workingset-simple.C
@@ -0,0 +1,29 @@
+// { dg-do run { target { x86_64-*-linux* } } }
+// { dg-options "-fsanitize=efficiency-working-set" }
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <assert.h>
+
+const int size = 0x1 << 25; // 520k cache lines
+const int line_size = 64;
+
+int main(int argc, char **argv) {
+ char *bufA = (char *)malloc(sizeof(char) * line_size);
+ char bufB[64];
+ char *bufC = (char *)mmap(0, size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ bufA[0] = 0;
+ // This additional access to the same line should not increase the line
+ // count: but it's difficult to make a non-flaky test that measures the
+ // lines down to the ones digit so right now we're not really testing that.
+ // If we add a heap-only mode we may be able to be more precise.
+ bufA[1] = 0;
+ bufB[33] = 1;
+ for (int i = 0; i < size; i += line_size)
+ bufC[i] = 0;
+ free(bufA);
+ munmap(bufC, 0x4000);
+ return 0;
+}
diff --git a/gcc/testsuite/lib/esan-dg.exp b/gcc/testsuite/lib/esan-dg.exp
new file mode 100644
index 00000000000..e3b933d5335
--- /dev/null
+++ b/gcc/testsuite/lib/esan-dg.exp
@@ -0,0 +1,156 @@
+# Copyright (C) 2013-2016 Free Software Foundation, Inc.
+
+# 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; either version 3 of the License, or
+# (at your option) any later version.
+#
+# 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 GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# Return 1 if compilation with -fsanitize=efficiency-working-set is error-free for trivial
+# code, 0 otherwise. Also set what to do by default here, depending on the
+# result of a runtime test.
+
+proc check_effective_target_fsanitize_esan {} {
+ global individual_timeout
+ global dg-do-what-default
+
+ if ![check_no_compiler_messages fsanitize_esan executable {
+ int main (void) { return 0; }
+ }] {
+ return 0
+ }
+
+ # Lower timeout value in case test does not terminate properly.
+ set individual_timeout 20
+ if [check_runtime_nocache esan_works {
+ int main () { return 0; }
+ }] {
+ set dg-do-what-default run
+ } else {
+ set dg-do-what-default link
+ }
+ unset individual_timeout
+
+ return 1
+}
+
+#
+# esan_link_flags -- compute library path and flags to find libesan.
+# (originally from g++.exp)
+#
+
+proc esan_link_flags { paths } {
+ global srcdir
+ global ld_library_path
+ global shlib_ext
+ global esan_saved_library_path
+
+ set gccpath ${paths}
+ set flags ""
+
+ set shlib_ext [get_shlib_extension]
+ set esan_saved_library_path $ld_library_path
+
+ if { $gccpath != "" } {
+ if { [file exists "${gccpath}/libsanitizer/esan/.libs/libesan.a"]
+ || [file exists "${gccpath}/libsanitizer/esan/.libs/libesan.${shlib_ext}"] } {
+ append flags " -B${gccpath}/libsanitizer/esan/ "
+ append flags " -L${gccpath}/libsanitizer/esan/.libs "
+ append ld_library_path ":${gccpath}/libsanitizer/esan/.libs"
+ }
+ } else {
+ global tool_root_dir
+
+ set libesan [lookfor_file ${tool_root_dir} libesan]
+ if { $libesan != "" } {
+ append flags "-L${libesan} "
+ append ld_library_path ":${libesan}"
+ }
+ }
+
+ set_ld_library_path_env_vars
+
+ return "$flags"
+}
+
+#
+# esan_init -- called at the start of each subdir of tests
+#
+
+proc esan_init { args } {
+ global TEST_ALWAYS_FLAGS
+ global ALWAYS_CXXFLAGS
+ global TOOL_OPTIONS
+ global esan_saved_TEST_ALWAYS_FLAGS
+ global esan_saved_ALWAYS_CXXFLAGS
+ global dg-do-what-default
+ global esan_saved_dg-do-what-default
+
+ set link_flags ""
+ if ![is_remote host] {
+ if [info exists TOOL_OPTIONS] {
+ set link_flags "[esan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
+ } else {
+ set link_flags "[esan_link_flags [get_multilibs]]"
+ }
+ }
+
+ if [info exists dg-do-what-default] {
+ set esan_saved_dg-do-what-default ${dg-do-what-default}
+ }
+ if [info exists TEST_ALWAYS_FLAGS] {
+ set esan_saved_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS
+ }
+ if [info exists ALWAYS_CXXFLAGS] {
+ set esan_saved_ALWAYS_CXXFLAGS $ALWAYS_CXXFLAGS
+ set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS]
+ set ALWAYS_CXXFLAGS [concat "{additional_flags=-fsanitize=efficiency-working-set -g}" $ALWAYS_CXXFLAGS]
+ } else {
+ if [info exists TEST_ALWAYS_FLAGS] {
+ set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=efficiency-working-set -g $TEST_ALWAYS_FLAGS"
+ } else {
+ set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=efficiency-working-set -g"
+ }
+ }
+}
+
+#
+# esan_finish -- called at the end of each subdir of tests
+#
+
+proc esan_finish { args } {
+ global TEST_ALWAYS_FLAGS
+ global esan_saved_TEST_ALWAYS_FLAGS
+ global esan_saved_ALWAYS_CXXFLAGS
+ global dg-do-what-default
+ global esan_saved_dg-do-what-default
+ global esan_saved_library_path
+ global ld_library_path
+
+ if [info exists esan_saved_ALWAYS_CXXFLAGS ] {
+ set ALWAYS_CXXFLAGS $esan_saved_ALWAYS_CXXFLAGS
+ } else {
+ if [info exists esan_saved_TEST_ALWAYS_FLAGS] {
+ set TEST_ALWAYS_FLAGS $esan_saved_TEST_ALWAYS_FLAGS
+ } else {
+ unset TEST_ALWAYS_FLAGS
+ }
+ }
+
+ if [info exists esan_saved_dg-do-what-default] {
+ set dg-do-what-default ${esan_saved_dg-do-what-default}
+ } else {
+ unset dg-do-what-default
+ }
+ set ld_library_path $esan_saved_library_path
+ set_ld_library_path_env_vars
+ clear_effective_target_cache
+}