public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/testsuite: update expected results in gdb.python/py-startup-opt.exp
@ 2021-04-29  9:23 Andrew Burgess
  2021-04-29  9:54 ` Tom de Vries
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2021-04-29  9:23 UTC (permalink / raw)
  To: gdb-patches

The test gdb.python/py-startup-opt.exp checks the behaviour of GDB's:

  set python dont-write-bytecode on

This flag (when on) stops Python creating .pyc files.  The test first
checks that .pyc files will be created, then turns this option on and
checks .pyc files will not be created.

However, if the user has PYTHONDONTWRITEBYTECODE set in their
environment then this will prevent Python from creating .pyc files, as
such the first test, that .pyc files are being created, currently
fails.

We could unset PYTHONDONTWRITEBYTECODE, however, until Python 3.8
there is no way to control where Python writes the .pyc files.  As the
GDB developer clearly doesn't want .pyc files created in their
file-system it feels wrong to silently unset this environment
variable.

My proposal then, is that we just spot when this environment variable
is set and adjust the expected results.  My hope is that across all
GDB developers some will be running with PYTHONDONTWRITEBYTECODE
unset, so this feature will be fully tested at least some of the time.

gdb/testsuite/ChangeLog:

	PR testsuite/27788:
	* gdb.python/py-startup-opt.exp (test_python_settings): Change the
	expected results when environment variable PYTHONDONTWRITEBYTECODE
	is set.
---
 gdb/testsuite/ChangeLog                     |  7 +++++++
 gdb/testsuite/gdb.python/py-startup-opt.exp | 18 +++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.python/py-startup-opt.exp b/gdb/testsuite/gdb.python/py-startup-opt.exp
index 842add30807..3a3c8e46327 100644
--- a/gdb/testsuite/gdb.python/py-startup-opt.exp
+++ b/gdb/testsuite/gdb.python/py-startup-opt.exp
@@ -62,13 +62,29 @@ proc test_python_settings { exp_state } {
     gdb_test_no_output "python import sys"
 
     foreach_with_prefix attr {ignore_environment dont_write_bytecode} {
+
+	# If the user has PYTHONDONTWRITEBYTECODE set in their environment
+	# then this will override the expected results for this test.  We
+	# could unset this environment variable, but until Python 3.8 there
+	# was no way to control where .pyc files are placed, and it feels
+	# bad to cause .pyc files to be created within the users filesystem
+	# when they clearly don't want them.  And so, we just adjust the
+	# expected results.  Hopefully, between all GDB developers some will
+	# test GDB with this environment variable unset.
+	if { $attr == "dont_write_bytecode" \
+		 && [info exists ::env(PYTHONDONTWRITEBYTECODE)] } {
+	    set answer "on"
+	} else {
+	    set answer $exp_state
+	}
+
 	gdb_test_multiline "testname" \
 	    "python" "" \
 	    "if hasattr(sys, 'flags') and getattr(sys.flags, '${attr}', False):" "" \
 	    "  print (\"${attr} is on\")" "" \
 	    "else:" "" \
 	    "  print (\"${attr} is off\")" "" \
-	    "end" "${attr} is ${exp_state}"
+	    "end" "${attr} is ${answer}"
     }
 
     gdb_exit
-- 
2.25.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb/testsuite: update expected results in gdb.python/py-startup-opt.exp
  2021-04-29  9:23 [PATCH] gdb/testsuite: update expected results in gdb.python/py-startup-opt.exp Andrew Burgess
@ 2021-04-29  9:54 ` Tom de Vries
  2021-05-03 11:23   ` Andrew Burgess
  0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2021-04-29  9:54 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1355 bytes --]

On 4/29/21 11:23 AM, Andrew Burgess wrote:
> The test gdb.python/py-startup-opt.exp checks the behaviour of GDB's:
> 
>   set python dont-write-bytecode on
> 
> This flag (when on) stops Python creating .pyc files.  The test first
> checks that .pyc files will be created, then turns this option on and
> checks .pyc files will not be created.
> 
> However, if the user has PYTHONDONTWRITEBYTECODE set in their
> environment then this will prevent Python from creating .pyc files, as
> such the first test, that .pyc files are being created, currently
> fails.
> 
> We could unset PYTHONDONTWRITEBYTECODE, however, until Python 3.8
> there is no way to control where Python writes the .pyc files.  As the
> GDB developer clearly doesn't want .pyc files created in their
> file-system it feels wrong to silently unset this environment
> variable.
> 
> My proposal then, is that we just spot when this environment variable
> is set and adjust the expected results.  My hope is that across all
> GDB developers some will be running with PYTHONDONTWRITEBYTECODE
> unset, so this feature will be fully tested at least some of the time.
> 

LGTM.

FWIW, just one observation: If ignore_environment is on, then testing
the value of the environment variable should be unnecessary.

Something like updated patch below tries to make that explicit.

Thanks,
- Tom



[-- Attachment #2: tmp.patch --]
[-- Type: text/x-patch, Size: 1565 bytes --]

diff --git a/gdb/testsuite/gdb.python/py-startup-opt.exp b/gdb/testsuite/gdb.python/py-startup-opt.exp
index 842add30807..1d035e0e18b 100644
--- a/gdb/testsuite/gdb.python/py-startup-opt.exp
+++ b/gdb/testsuite/gdb.python/py-startup-opt.exp
@@ -62,13 +62,30 @@ proc test_python_settings { exp_state } {
     gdb_test_no_output "python import sys"
 
     foreach_with_prefix attr {ignore_environment dont_write_bytecode} {
+
+	set answer $exp_state
+	# If the user has PYTHONDONTWRITEBYTECODE set in their environment
+	# then this will override the expected results for this test.  We
+	# could unset this environment variable, but until Python 3.8 there
+	# was no way to control where .pyc files are placed, and it feels
+	# bad to cause .pyc files to be created within the users filesystem
+	# when they clearly don't want them.  And so, we just adjust the
+	# expected results.  Hopefully, between all GDB developers some will
+	# test GDB with this environment variable unset.
+	if { $exp_state == "on" } {
+	    # Environment is ignored, so no override needed.
+	} elseif { $attr == "dont_write_bytecode" \
+		 && [info exists ::env(PYTHONDONTWRITEBYTECODE)] } {
+	    set answer "on"
+	}
+
 	gdb_test_multiline "testname" \
 	    "python" "" \
 	    "if hasattr(sys, 'flags') and getattr(sys.flags, '${attr}', False):" "" \
 	    "  print (\"${attr} is on\")" "" \
 	    "else:" "" \
 	    "  print (\"${attr} is off\")" "" \
-	    "end" "${attr} is ${exp_state}"
+	    "end" "${attr} is ${answer}"
     }
 
     gdb_exit

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb/testsuite: update expected results in gdb.python/py-startup-opt.exp
  2021-04-29  9:54 ` Tom de Vries
@ 2021-05-03 11:23   ` Andrew Burgess
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Burgess @ 2021-05-03 11:23 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches

* Tom de Vries <tdevries@suse.de> [2021-04-29 11:54:25 +0200]:

> On 4/29/21 11:23 AM, Andrew Burgess wrote:
> > The test gdb.python/py-startup-opt.exp checks the behaviour of GDB's:
> > 
> >   set python dont-write-bytecode on
> > 
> > This flag (when on) stops Python creating .pyc files.  The test first
> > checks that .pyc files will be created, then turns this option on and
> > checks .pyc files will not be created.
> > 
> > However, if the user has PYTHONDONTWRITEBYTECODE set in their
> > environment then this will prevent Python from creating .pyc files, as
> > such the first test, that .pyc files are being created, currently
> > fails.
> > 
> > We could unset PYTHONDONTWRITEBYTECODE, however, until Python 3.8
> > there is no way to control where Python writes the .pyc files.  As the
> > GDB developer clearly doesn't want .pyc files created in their
> > file-system it feels wrong to silently unset this environment
> > variable.
> > 
> > My proposal then, is that we just spot when this environment variable
> > is set and adjust the expected results.  My hope is that across all
> > GDB developers some will be running with PYTHONDONTWRITEBYTECODE
> > unset, so this feature will be fully tested at least some of the time.
> > 
> 
> LGTM.
> 
> FWIW, just one observation: If ignore_environment is on, then testing
> the value of the environment variable should be unnecessary.
> 
> Something like updated patch below tries to make that explicit.

Thanks for the suggestion.  I incorporated the extra condition into a
single `if` statement, and rewrote the comment.  Below is what I
pushed.

Thanks,
Andrew

--

commit d389a1a7692d247b6153fc6a98ebc43d7070fc2e
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Thu Apr 29 10:11:35 2021 +0100

    gdb/testsuite: update expected results in gdb.python/py-startup-opt.exp
    
    The test gdb.python/py-startup-opt.exp checks the behaviour of GDB's:
    
      set python dont-write-bytecode on
    
    This flag (when on) stops Python creating .pyc files.  The test first
    checks that .pyc files will be created, then turns this option on and
    checks .pyc files will not be created.
    
    However, if the user has PYTHONDONTWRITEBYTECODE set in their
    environment then this will prevent Python from creating .pyc files, as
    such the first test, that .pyc files are being created, currently
    fails.
    
    We could unset PYTHONDONTWRITEBYTECODE, however, until Python 3.8
    there is no way to control where Python writes the .pyc files.  As the
    GDB developer clearly doesn't want .pyc files created in their
    file-system it feels wrong to silently unset this environment
    variable.
    
    My proposal then, is that we just spot when this environment variable
    is set and adjust the expected results.  My hope is that across all
    GDB developers some will be running with PYTHONDONTWRITEBYTECODE
    unset, so this feature will be fully tested at least some of the time.
    
    gdb/testsuite/ChangeLog:
    
            PR testsuite/27788
            * gdb.python/py-startup-opt.exp (test_python_settings): Change the
            expected results when environment variable PYTHONDONTWRITEBYTECODE
            is set.

diff --git a/gdb/testsuite/gdb.python/py-startup-opt.exp b/gdb/testsuite/gdb.python/py-startup-opt.exp
index 842add30807..f0a735b3f44 100644
--- a/gdb/testsuite/gdb.python/py-startup-opt.exp
+++ b/gdb/testsuite/gdb.python/py-startup-opt.exp
@@ -62,13 +62,41 @@ proc test_python_settings { exp_state } {
     gdb_test_no_output "python import sys"
 
     foreach_with_prefix attr {ignore_environment dont_write_bytecode} {
+
+	# If we are checking 'dont_write_bytecode', and we are
+	# expecting this attribute to be 'off', then, if the user has
+	# PYTHONDONTWRITEBYTECODE set in their environment, the result
+	# will be 'on' instead of 'off', so override the expected
+	# result here.
+	#
+	# The reason for this is, 'set python dont-write-bytecode' by
+	# default is set to 'auto', which means, so long as 'set
+	# python ignore-environment' is 'off', GDB will check for the
+	# above environment variable.
+	#
+	# We could unset the environment variable, but until Python
+	# 3.8 there was no way to control where .pyc files are placed,
+	# and it feels bad to cause .pyc files to be created within
+	# the users filesystem when they clearly don't want them.
+	#
+	# And so, we adjust the expected results.  Hopefully, between
+	# all GDB developers some will test GDB with this environment
+	# variable unset.
+	if { $attr == "dont_write_bytecode" \
+		 && $exp_state == "off"
+		 && [info exists ::env(PYTHONDONTWRITEBYTECODE)] } {
+	    set answer "on"
+	} else {
+	    set answer $exp_state
+	}
+
 	gdb_test_multiline "testname" \
 	    "python" "" \
 	    "if hasattr(sys, 'flags') and getattr(sys.flags, '${attr}', False):" "" \
 	    "  print (\"${attr} is on\")" "" \
 	    "else:" "" \
 	    "  print (\"${attr} is off\")" "" \
-	    "end" "${attr} is ${exp_state}"
+	    "end" "${attr} is ${answer}"
     }
 
     gdb_exit

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-03 11:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-29  9:23 [PATCH] gdb/testsuite: update expected results in gdb.python/py-startup-opt.exp Andrew Burgess
2021-04-29  9:54 ` Tom de Vries
2021-05-03 11:23   ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).