Patchwork Environment variables forwarding

login
register
mail settings
Submitter max
Date March 24, 2014, 9:46 a.m.
Message ID <532FFEE1.2000606@partner.samsung.com>
Download mbox | patch
Permalink /patch/333040/
State New
Headers show

Comments

max - March 24, 2014, 9:46 a.m.
Adding Dejagnu list this time.

On 03/24/2014 12:28 PM, Maxim Ostapenko wrote:
> Hi all,
>
> When porting Lsan on arm, I ran into problem with testing, because 
> almost all lsan tests require environment variables forwarding for 
> remote targets. Unfortunately, this feature isn't implemented yet 
> neither in Dejagnu nor in GCC. These two small patches seem to resolve 
> this issue.
>
> Tested on arm with asan.exp and ubsan.exp.
>
> I've cross-posted this message in Dejagnu too.
>
> Do these changes make sense? If not - what's the proper way to forward 
> env vars on remote targets?
>
> -Maxim

Patch

2014-03-24  Max Ostapenko  <m.ostapenko@partner.samsung.com>

	* lib/gcc-dg.exp: Add check if Dejagnu supports environment
	variables forwarding for remote targets.
	* lib/target-supports.exp
	(check_runtime_env_vars_forwarding_nocache): New function.
	(check_runtime_env_vars_forwarding): New function.

diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index f9d52bc..05eab99 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -80,6 +80,9 @@  set LTO_TORTURE_OPTIONS ""
 global gcc_force_conventional_output
 set gcc_force_conventional_output ""
 
+global target_env_vars_available
+set target_env_vars_available ""
+
 if [check_effective_target_lto] {
     # When having plugin test both slim and fat LTO and plugin/nonplugin
     # path.
@@ -258,11 +261,21 @@  if { [info procs ${tool}_load] != [list] \
 	set saved_target_env_var [list]
 	if { [info exists set_target_env_var] \
 	     && [llength $set_target_env_var] != 0 } {
-	    if { [is_remote target] } {
-		return [list "unsupported" ""]
-	    }
-	    set-target-env-var
-	}
+        if { [is_remote target] } {
+            if [check_runtime_env_vars_forwarding] {
+                foreach env_var $set_target_env_var {
+                    set var [lindex $env_var 0]
+                    set value [lindex $env_var 1]
+                    set program "$var=$value $program"
+                }
+            } else {
+                return [list "unsupported" ""]
+            }
+        } else {
+        set-target-env-var
+        }
+        }
+
 	set result [eval [list saved_${tool}_load $program] $args]
 	if { [info exists set_target_env_var] \
 	     && [llength $set_target_env_var] != 0 } {
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index bee8471..3a3224f 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -5731,3 +5731,57 @@  proc force_conventional_output_for { test } {
     }
 }
 
+# This procedure is the same the check_runtime_nocache one. The only
+# difference is that executable will run with TEST=1 environment
+# variable. If Dejagnu supports environment variables forwarding
+# for remote targets, it will return 1, otherwise it will return 0.
+
+proc check_runtime_env_vars_forwarding_nocache {} {
+    global tool
+    global target_env_vars_available
+    set basename env_forwarding_works
+    set contents {
+            #ifdef __cplusplus
+            extern "C"
+            #endif
+            char *getenv(const char *name);
+
+            #ifdef __cplusplus
+            extern "C"
+            #endif
+            int strcmp(const char *s1, const char *s2);
+
+            int main () { return strcmp(getenv("TEST"), "1"); }
+        }
+
+    set args ""
+
+    set result [eval [list check_compile $basename executable $contents] $args]
+    set lines [lindex $result 0]
+    set output [lindex $result 1]
+
+    set ok 0
+    if { [string match "" $lines] } {
+    # No error messages, everything is OK.
+    set result [remote_load target "TEST=1 ./$output" "" ""]
+    set status [lindex $result 0]
+    verbose "check_runtime_nocache $basename: status is <$status>" 2
+    if { $status == "pass" } {
+        set ok 1
+    }
+    }
+    remote_file build delete $output
+    return $ok
+}
+
+proc check_runtime_env_vars_forwarding {} {
+    global target_env_vars_available
+    if { $target_env_vars_available == "" } {
+        if [check_runtime_env_vars_forwarding_nocache] {
+            set target_env_vars_available 1
+        } else {
+            set target_env_vars_available 0
+        }
+  }
+  return $target_env_vars_available
+}