Patchwork Environment variables forwarding

login
register
mail settings
Submitter Yury Gribov
Date March 25, 2014, 2:31 p.m.
Message ID <5331933B.7060308@samsung.com>
Download mbox | patch
Permalink /patch/333488/
State New
Headers show

Comments

Yury Gribov - March 25, 2014, 2:31 p.m.
Cc-ing Jakub cause he's the author of original set-target-env-var 
support in GCC testsuite.

On 03/24/2014 01:46 PM, Maxim Ostapenko wrote:
> 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

-Y
Mike Stump - March 26, 2014, 5:42 p.m.
On Mar 25, 2014, at 7:31 AM, Yury Gribov <y.gribov@samsung.com> wrote:
> On 03/24/2014 01:46 PM, Maxim Ostapenko wrote:
>> 
>> On 03/24/2014 12:28 PM, Maxim Ostapenko wrote:
>>> 
>>> 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.

So, I’m interested in what Jakub might say…  but, seems reasonable to enhance it so that this is possible.

Unless others have some friendly suggestions…  Ok for stage1.

>>> Do these changes make sense? If not - what's the proper way to forward
>>> env vars on remote targets?

I have a remote target that is done via the binutils sim style simulator.  For it, I can just set environment variables directly.   I’ve wired up getenv to look at the environment of the simulator.  I suspect the way you wired things, it would just work for me, for example.
Jakub Jelinek - March 26, 2014, 6:14 p.m.
On Wed, Mar 26, 2014 at 10:42:12AM -0700, Mike Stump wrote:
> On Mar 25, 2014, at 7:31 AM, Yury Gribov <y.gribov@samsung.com> wrote:
> > On 03/24/2014 01:46 PM, Maxim Ostapenko wrote:
> >> 
> >> On 03/24/2014 12:28 PM, Maxim Ostapenko wrote:
> >>> 
> >>> 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.
> 
> So, I’m interested in what Jakub might say…  but, seems reasonable to enhance it so that this is possible.

I'd personaly think it is not worth bothering, such features could be just
tested on native testing.  But if somebody is willing to maintain it for
cross-testing and review that, I don't object.

	Jakub
Yury Gribov - March 27, 2014, 5:56 a.m.
> But if somebody is willing to maintain it for
 > cross-testing

Yup, we'll do this.

Now what bothers me is zero feedback from Dejagnu folks...

-Y
Ben Elliston - March 27, 2014, 5:58 a.m.
On Thu, Mar 27, 2014 at 09:56:22AM +0400, Yury Gribov wrote:

> Now what bothers me is zero feedback from Dejagnu folks...

Come on, it's only been a couple of days. :-)

Ben

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
+}