From: Andi Kleen <a...@linux.intel.com>

Extend the existing bprob and tree-prof tests to also run with autofdo.
The test runtimes are really a bit too short for autofdo, but it's
a reasonable sanity check.

This only works natively for now.

dejagnu doesn't seem to support a wrapper for unix tests, so I had
to open code running these tests.  That should be ok due to the
native run restrictions.

gcc/testsuite/:
2016-03-27  Andi Kleen  <a...@linux.intel.com>

        * g++.dg/bprob/bprob.exp: Support autofdo.
        * g++.dg/tree-prof/tree-prof.exp: dito.
        * gcc.dg/tree-prof/tree-prof.exp: dito.
        * gcc.misc-tests/bprob.exp: dito.
        * gfortran.dg/prof/prof.exp: dito.
        * lib/profopt.exp: dito.
        * lib/target-supports.exp: Check for autofdo.
---
 gcc/testsuite/g++.dg/bprob/bprob.exp         | 19 +++++++++
 gcc/testsuite/g++.dg/tree-prof/tree-prof.exp | 19 +++++++++
 gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp | 19 +++++++++
 gcc/testsuite/gcc.misc-tests/bprob.exp       | 23 +++++++++++
 gcc/testsuite/gfortran.dg/prof/prof.exp      | 18 +++++++++
 gcc/testsuite/lib/profopt.exp                | 58 ++++++++++++++++++++++++++--
 gcc/testsuite/lib/target-supports.exp        | 23 +++++++++++
 7 files changed, 176 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/g++.dg/bprob/bprob.exp 
b/gcc/testsuite/g++.dg/bprob/bprob.exp
index d555507..92a1e94 100644
--- a/gcc/testsuite/g++.dg/bprob/bprob.exp
+++ b/gcc/testsuite/g++.dg/bprob/bprob.exp
@@ -53,6 +53,7 @@ if $tracelevel then {
 
 set profile_options "-fprofile-arcs"
 set feedback_options "-fbranch-probabilities"
+set profile_wrapper ""
 
 # Main loop.
 foreach profile_option $profile_options feedback_option $feedback_options {
@@ -65,4 +66,22 @@ foreach profile_option $profile_options feedback_option 
$feedback_options {
     }
 }
 
+set profile_wrapper [profopt-perf-wrapper]
+set profile_options "-g"
+set feedback_options "-fauto-profile"
+set run_autofdo 1
+
+foreach profile_option $profile_options feedback_option $feedback_options {
+    foreach src [lsort [glob -nocomplain $srcdir/$subdir/bprob-*.c]] {
+        if ![runtest_file_p $runtests $src] then {
+            continue
+        }
+       set base [file tail $srco
+        profopt-execute $src
+    }
+}
+
+set run_autofdo ""
+set profile_wrapper ""
+
 set PROFOPT_OPTIONS $bprob_save_profopt_options
diff --git a/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp 
b/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp
index 7a4b5cb..7220217 100644
--- a/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp
+++ b/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp
@@ -44,6 +44,7 @@ set PROFOPT_OPTIONS [list {}]
 # profile data.
 set profile_option "-fprofile-generate -D_PROFILE_GENERATE"
 set feedback_option "-fprofile-use -D_PROFILE_USE"
+set profile_wrapper ""
 
 foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.C]] {
     # If we're only testing specific files and this isn't one of them, skip it.
@@ -53,4 +54,22 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.C]] {
     profopt-execute $src
 }
 
+set profile_wrapper [profopt-perf-wrapper]
+set profile_options "-g"
+set feedback_options "-fauto-profile"
+set run_autofdo 1
+
+foreach profile_option $profile_options feedback_option $feedback_options {
+    foreach src [lsort [glob -nocomplain $srcdir/$subdir/bprob-*.c]] {
+        if ![runtest_file_p $runtests $src] then {
+            continue
+        }
+       set base [file tail $srco
+        profopt-execute $src
+    }
+}
+
+set run_autofdo ""
+set profile_wrapper ""
+
 set PROFOPT_OPTIONS $treeprof_save_profopt_options
diff --git a/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp 
b/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
index 650ad8d..7fff52c 100644
--- a/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
+++ b/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
@@ -44,6 +44,7 @@ set PROFOPT_OPTIONS [list {}]
 # profile data.
 set profile_option "-fprofile-generate -D_PROFILE_GENERATE"
 set feedback_option "-fprofile-use -D_PROFILE_USE"
+set profile_wrapper ""
 
 foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
     # If we're only testing specific files and this isn't one of them, skip it.
@@ -53,4 +54,22 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
     profopt-execute $src
 }
 
+set profile_wrapper [profopt-perf-wrapper]
+set profile_options "-g"
+set feedback_options "-fauto-profile"
+set run_autofdo 1
+
+foreach profile_option $profile_options feedback_option $feedback_options {
+    foreach src [lsort [glob -nocomplain $srcdir/$subdir/bprob-*.c]] {
+        if ![runtest_file_p $runtests $src] then {
+            continue
+        }
+       set base [file tail $srco
+        profopt-execute $src
+    }
+}
+
+set run_autofdo ""
+set profile_wrapper ""
+
 set PROFOPT_OPTIONS $treeprof_save_profopt_options
diff --git a/gcc/testsuite/gcc.misc-tests/bprob.exp 
b/gcc/testsuite/gcc.misc-tests/bprob.exp
index 52dcb1f..cc12f1f 100644
--- a/gcc/testsuite/gcc.misc-tests/bprob.exp
+++ b/gcc/testsuite/gcc.misc-tests/bprob.exp
@@ -41,6 +41,7 @@ load_lib profopt.exp
 set bprob_save_profopt_options $PROFOPT_OPTIONS
 set PROFOPT_OPTIONS [list { -O2 } { -O3  }]
 
+set profile_wrapper ""
 set profile_options "-fprofile-arcs"
 set feedback_options "-fbranch-probabilities"
 
@@ -54,4 +55,26 @@ foreach profile_option $profile_options feedback_option 
$feedback_options {
     }
 }
 
+if { ! [check_profiling_available "-fauto-profile"] } {
+    set PROFOPT_OPTIONS $bprob_save_profopt_options
+    return
+}
+
+set ext autogcov
+set profile_wrapper [profopt-perf-wrapper]
+set profile_options "-g"
+set feedback_options "-fauto-profile"
+set run_autofdo 1
+
+foreach profile_option $profile_options feedback_option $feedback_options {
+    foreach src [lsort [glob -nocomplain $srcdir/$subdir/bprob-*.c]] {
+        if ![runtest_file_p $runtests $src] then {
+            continue
+        }
+        profopt-execute $src
+    }
+}
+
+set run_autofdo ""
+set profile_wrapper ""
 set PROFOPT_OPTIONS $bprob_save_profopt_options
diff --git a/gcc/testsuite/gfortran.dg/prof/prof.exp 
b/gcc/testsuite/gfortran.dg/prof/prof.exp
index 0bad01d..24c3472 100644
--- a/gcc/testsuite/gfortran.dg/prof/prof.exp
+++ b/gcc/testsuite/gfortran.dg/prof/prof.exp
@@ -53,4 +53,22 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.f*]] {
     profopt-execute $src
 }
 
+set profile_wrapper [profopt-perf-wrapper]
+set profile_options "-g"
+set feedback_options "-fauto-profile"
+set run_autofdo 1
+
+foreach profile_option $profile_options feedback_option $feedback_options {
+    foreach src [lsort [glob -nocomplain $srcdir/$subdir/bprob-*.c]] {
+        if ![runtest_file_p $runtests $src] then {
+            continue
+        }
+       set base [file tail $srco
+        profopt-execute $src
+    }
+}
+
+set run_autofdo ""
+set profile_wrapper ""
+
 set PROFOPT_OPTIONS $treeprof_save_profopt_options
diff --git a/gcc/testsuite/lib/profopt.exp b/gcc/testsuite/lib/profopt.exp
index 0aea6c4..3502b3e 100644
--- a/gcc/testsuite/lib/profopt.exp
+++ b/gcc/testsuite/lib/profopt.exp
@@ -36,7 +36,7 @@ load_lib gcc-dg.exp
 global PROFOPT_OPTIONS perf_delta
 
 # The including .exp file must define these.
-global tool profile_option feedback_option prof_ext
+global tool profile_option feedback_option prof_ext profile_wrapper
 if ![info exists tool] {
     error "Tools is not specified."
 }
@@ -238,6 +238,7 @@ proc profopt-execute { src } {
     global srcdir tmpdir
     global PROFOPT_OPTIONS
     global tool profile_option feedback_option prof_ext perf_ext perf_delta
+    global profile_wrapper run_autofdo ld_library_path
     global generate_final_code use_final_code
     global verbose
     global testname_with_flags
@@ -248,6 +249,12 @@ proc profopt-execute { src } {
     if ![info exists feedback_option] {
         error "No feedback option specified for second compile."
     }
+    if ![info exists profile_wrapper] {
+       set profile_wrapper ""
+    }
+    if ![info exists run_autofdo] {
+       set run_autofdo ""
+    }
 
     # Use the default option list or one defined for a set of tests.
     if ![info exists PROFOPT_OPTIONS] {
@@ -313,6 +320,7 @@ proc profopt-execute { src } {
        # valid, by running it after dg-additional-files-options.
        foreach ext $prof_ext {
            profopt-target-cleanup $tmpdir $base $ext
+           profopt-target-cleanup $tmpdir perf data
        }
 
        # Tree profiling requires TLS runtime support, which may need
@@ -335,12 +343,51 @@ proc profopt-execute { src } {
        }
 
        # Run the profiled test.
+       if { $run_autofdo == 1 } {
+           # unix_load does not support wrappers in $PATH, so implement
+           # it manually here
+           if { ![info exists ld_library_path]} {
+               set ld_library_path ""
+           }
+           set orig_ld_library_path "[getenv LD_LIBRARY_PATH]"
+           setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path"
+           verbose "Running $profile_wrapper $execname1"
+           set id [remote_spawn "" "$profile_wrapper $execname1" "readonly"]
+           setenv LD_LIBRARY_PATH $orig_ld_library_path
+           if { $id < 0 } {
+               warning "Failed to run profiler"
+               set status "fail"
+           } else {
+               set result [remote_wait "" 300]
+               set status [lindex $result 0]
+               verbose "perf result $result"
+               if { $status == 0 } {
+                   set status "pass"
+               } else {
+                   set status "fail"
+               }
+           }
+       } else {
+           set result [${tool}_load $execname1 "" ""]
+           set status [lindex $result 0]
+       }
 
-       set result [${tool}_load $execname1 "" ""]
-       set status [lindex $result 0]
        set missing_file 0
        # Make sure the profile data was generated, and fail if not.
        if { $status == "pass" } {
+           # convert profile
+           if { $run_autofdo == 1 } {
+               set cmd "create_gcov --binary $execname1 --profile=perf.data 
-gcov_version=1 --gcov=$tmpdir/$base.$ext"
+               verbose "Running $cmd"
+               set id [remote_spawn "" $cmd]
+               if { $id < 0 } {
+                   set status "fail"
+                   fail "$testcase: Cannot run $cmd"
+               }
+               set status [remote_wait "" 300]
+               set status "pass"
+           }
+
            foreach ext $prof_ext {
                remote_upload target $tmpdir/$base.$ext
                set files [glob -nocomplain $base.$ext]
@@ -375,6 +422,10 @@ proc profopt-execute { src } {
        set options "$extra_options"
        lappend options "additional_flags=$option $extra_flags $feedback_option"
        set optstr "$option $feedback_option"
+       if { [string first "-fauto-profile" $options] >= 0} {
+           set options [regsub -- "-fauto-profile" $options 
"-fauto-profile=$tmpdir/$base.$ext"]
+       }
+
        set comp_output [${tool}_target_compile "$src" "$execname2" 
"executable" $options]
 
        # Prune warnings we know are unwanted.
@@ -400,6 +451,7 @@ proc profopt-execute { src } {
        foreach ext $prof_ext {
            profopt-target-cleanup $tmpdir $base $ext
        }
+       # XXX remove perf.data
 
        if { $status != "pass" } {
            continue
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index 777bff8..07d0fee 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -508,6 +508,11 @@ proc check_effective_target_keeps_null_pointer_checks { } {
     return 0
 }
 
+proc profopt-perf-wrapper { } {
+    global srcdir
+    return "$srcdir/../gcc-auto-profile -o perf.data "
+}
+
 # Return true if profiling is supported on the target.
 
 proc check_profiling_available { test_what } {
@@ -525,6 +530,24 @@ proc check_profiling_available { test_what } {
        }
     }
 
+    if { $test_what == "-fauto-profile" &&
+        ! ([istarget x86_64-*-linux*] || [istarget i?86-*-linux*]) } {
+       # not cross compiling?
+       if { ![isnative] } {
+           return 0
+       }
+       set event [profopt-perf-wrapper]
+       if {$event == "" } {
+           return 0
+       }
+       set status [remote_exec host "gcc-auto-profile" "true -v /dev/null"]
+       if { [lindex $status 0] != 0 } {
+           return 0
+       }
+       warning "autofdo not supported"
+       # Should check if create_gcov exists
+    }
+
     # Support for -p on solaris2 relies on mcrt1.o which comes with the
     # vendor compiler.  We cannot reliably predict the directory where the
     # vendor compiler (and thus mcrt1.o) is installed so we can't
-- 
2.7.3

Reply via email to