[20/23] test: dynamic string evaluations.

Message ID 1401861266-6240-21-git-send-email-keven.boell@intel.com
State New, archived
Headers

Commit Message

Keven Boell June 4, 2014, 5:54 a.m. UTC
  Tests various dynamic string evaluations. Dynamic strings
will be handled internally the same way as dynamic arrays.

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

testsuite/gdb.fortran/:

	* vla-strings.f90: New file.
	* vla-strings.exp: New file.

Change-Id: Ib2f3dded2fbc5f0a9684050c5cfa22a450e18358

Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/testsuite/gdb.fortran/vla-strings.exp |  104 +++++++++++++++++++++++++++++
 gdb/testsuite/gdb.fortran/vla-strings.f90 |   38 +++++++++++
 2 files changed, 142 insertions(+)
 create mode 100644 gdb/testsuite/gdb.fortran/vla-strings.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-strings.f90
  

Comments

Jan Kratochvil June 16, 2014, 6:41 p.m. UTC | #1
On Wed, 04 Jun 2014 07:54:23 +0200, Keven Boell wrote:
> --- /dev/null
> +++ b/gdb/testsuite/gdb.fortran/vla-strings.f90
> @@ -0,0 +1,38 @@
> +! Copyright 2014 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 2 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 this program; if not, write to the Free Software
> +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
> +
> +program vla_strings
> +  character(len=:), target, allocatable   :: var_char
> +  character(len=:), pointer               :: var_char_p
> +  logical                                 :: l
> +
> +  allocate(character(len=10) :: var_char)
> +  l = allocated(var_char)                 ! var_char-allocated-1
> +  var_char = 'foo'
> +  deallocate(var_char)                    ! var_char-filled-1
> +  l = allocated(var_char)                 ! var_char-deallocated
> +  allocate(character(len=42) :: var_char)
> +  l = allocated(var_char)
> +  var_char = 'foobar'
> +  var_char = ''                           ! var_char-filled-2
> +  allocate(character(len=21) :: var_char) ! var_char-empty

On Fedora Rawhide x86_64 (gcc-4.9.0-8.fc21.x86_64) I get:
$ ./gdb.fortran/vla-strings
At line 31 of file ./gdb.fortran/vla-strings.f90
Fortran runtime error: Attempting to allocate already allocated variable 'var_char'

This also causes:
Running ./gdb.fortran/vla-strings.exp ...
FAIL: gdb.fortran/vla-strings.exp: continue to breakpoint: var_char-allocated-3 (the program exited)
FAIL: gdb.fortran/vla-strings.exp: print var_char after allocated third time
FAIL: gdb.fortran/vla-strings.exp: whatis var_char after allocated third time
FAIL: gdb.fortran/vla-strings.exp: ptype var_char after allocated third time
FAIL: gdb.fortran/vla-strings.exp: continue to breakpoint: var_char_p-associated (the program is no longer running)
FAIL: gdb.fortran/vla-strings.exp: print var_char_p after associated
FAIL: gdb.fortran/vla-strings.exp: print *var_char_ after associated
FAIL: gdb.fortran/vla-strings.exp: whatis var_char_p after associated
FAIL: gdb.fortran/vla-strings.exp: ptype var_char_p after associated


> +  l = allocated(var_char)                 ! var_char-allocated-3
> +  var_char = 'johndoe'
> +  var_char_p => var_char
> +  l = associated(var_char_p)              ! var_char_p-associated
> +  var_char_p => null()
> +  l = associated(var_char_p)              ! var_char_p-not-associated
> +end program vla_strings
> -- 
> 1.7.9.5


Thanks,
Jan
  
Keven Boell June 17, 2014, 1:48 p.m. UTC | #2
> On Wed, 04 Jun 2014 07:54:23 +0200, Keven Boell wrote:
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.fortran/vla-strings.f90
>> @@ -0,0 +1,38 @@
>> +! Copyright 2014 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 2 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 this program; if not, write to the Free Software
>> +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
>> +
>> +program vla_strings
>> +  character(len=:), target, allocatable   :: var_char
>> +  character(len=:), pointer               :: var_char_p
>> +  logical                                 :: l
>> +
>> +  allocate(character(len=10) :: var_char)
>> +  l = allocated(var_char)                 ! var_char-allocated-1
>> +  var_char = 'foo'
>> +  deallocate(var_char)                    ! var_char-filled-1
>> +  l = allocated(var_char)                 ! var_char-deallocated
>> +  allocate(character(len=42) :: var_char)
>> +  l = allocated(var_char)
>> +  var_char = 'foobar'
>> +  var_char = ''                           ! var_char-filled-2
>> +  allocate(character(len=21) :: var_char) ! var_char-empty
> 
> On Fedora Rawhide x86_64 (gcc-4.9.0-8.fc21.x86_64) I get:
> $ ./gdb.fortran/vla-strings
> At line 31 of file ./gdb.fortran/vla-strings.f90
> Fortran runtime error: Attempting to allocate already allocated variable 'var_char'
> 
> This also causes:
> Running ./gdb.fortran/vla-strings.exp ...
> FAIL: gdb.fortran/vla-strings.exp: continue to breakpoint: var_char-allocated-3 (the program exited)
> FAIL: gdb.fortran/vla-strings.exp: print var_char after allocated third time
> FAIL: gdb.fortran/vla-strings.exp: whatis var_char after allocated third time
> FAIL: gdb.fortran/vla-strings.exp: ptype var_char after allocated third time
> FAIL: gdb.fortran/vla-strings.exp: continue to breakpoint: var_char_p-associated (the program is no longer running)
> FAIL: gdb.fortran/vla-strings.exp: print var_char_p after associated
> FAIL: gdb.fortran/vla-strings.exp: print *var_char_ after associated
> FAIL: gdb.fortran/vla-strings.exp: whatis var_char_p after associated
> FAIL: gdb.fortran/vla-strings.exp: ptype var_char_p after associated

Thanks for trying out the tests on your system. The test source was
incorrect. I tried to allocate a string, which wasn't deallocated before.
GFORTRAN 4.8.2, which I have on my system, doesn't complain about this mistake,
whereas GFORTRAN 4.9.0 does.
I fixed it and it resolves all of the FAIL's reported above.

> 
> 
>> +  l = allocated(var_char)                 ! var_char-allocated-3
>> +  var_char = 'johndoe'
>> +  var_char_p => var_char
>> +  l = associated(var_char_p)              ! var_char_p-associated
>> +  var_char_p => null()
>> +  l = associated(var_char_p)              ! var_char_p-not-associated
>> +end program vla_strings
>> -- 
>> 1.7.9.5
> 
> 
> Thanks,
> Jan
>
  

Patch

diff --git a/gdb/testsuite/gdb.fortran/vla-strings.exp b/gdb/testsuite/gdb.fortran/vla-strings.exp
new file mode 100644
index 0000000..7fc1734
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-strings.exp
@@ -0,0 +1,104 @@ 
+# Copyright 2014 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile ".f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+# check that all fortran standard datatypes will be
+# handled correctly when using as VLA's
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+gdb_breakpoint [gdb_get_line_number "var_char-allocated-1"]
+gdb_continue_to_breakpoint "var_char-allocated-1"
+gdb_test "print var_char" \
+  " = \\(PTR TO -> \\( character\\*10 \\)\\) ${hex}" \
+  "print var_char after allocated first time"
+gdb_test "print *var_char" \
+  " = '\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000'" \
+  "print *var_char after allocated first time"
+gdb_test "whatis var_char" "type = PTR TO -> \\( character\\*10 \\)" \
+  "whatis var_char first time"
+gdb_test "ptype var_char" "type = PTR TO -> \\( character\\*10 \\)" \
+  "ptype var_char first time"
+gdb_test "next" "\\d+.*var_char = 'foo'.*" \
+  "next to allocation status of var_char"
+gdb_test "print l" " = .TRUE." "print allocation status first time"
+
+gdb_breakpoint [gdb_get_line_number "var_char-filled-1"]
+gdb_continue_to_breakpoint "var_char-filled-1"
+gdb_test "print var_char" \
+  " = \\(PTR TO -> \\( character\\*3 \\)\\) ${hex}" \
+  "print var_char after filled first time"
+gdb_test "print *var_char" " = 'foo'" \
+  "print *var_char after filled first time"
+gdb_test "whatis var_char" "type = PTR TO -> \\( character\\*3 \\)" \
+  "whatis var_char after filled first time"
+gdb_test "ptype var_char" "type = PTR TO -> \\( character\\*3 \\)" \
+  "ptype var_char after filled first time"
+gdb_test "print var_char(1)" " = 102 'f'" "print var_char(1)"
+gdb_test "print var_char(3)" " = 111 'o'" "print var_char(3)"
+
+gdb_breakpoint [gdb_get_line_number "var_char-filled-2"]
+gdb_continue_to_breakpoint "var_char-filled-2"
+gdb_test "print var_char" \
+  " = \\(PTR TO -> \\( character\\*6 \\)\\) ${hex}" \
+  "print var_char after allocated second time"
+gdb_test "print *var_char" " = 'foobar'" \
+  "print *var_char after allocated second time"
+gdb_test "whatis var_char" "type = PTR TO -> \\( character\\*6 \\)" \
+  "whatis var_char second time"
+gdb_test "ptype var_char" "type = PTR TO -> \\( character\\*6 \\)" \
+  "ptype var_char second time"
+
+gdb_breakpoint [gdb_get_line_number "var_char-empty"]
+gdb_continue_to_breakpoint "var_char-empty"
+gdb_test "print var_char" \
+  " = \\(PTR TO -> \\( character\\*0 \\)\\) ${hex}" \
+  "print var_char after set empty"
+gdb_test "print *var_char" " = \"\"" "print *var_char after set empty"
+gdb_test "whatis var_char" "type = PTR TO -> \\( character\\*0 \\)" \
+  "whatis var_char after set empty"
+gdb_test "ptype var_char" "type = PTR TO -> \\( character\\*0 \\)" \
+  "ptype var_char after set empty"
+
+gdb_breakpoint [gdb_get_line_number "var_char-allocated-3"]
+gdb_continue_to_breakpoint "var_char-allocated-3"
+gdb_test "print var_char" \
+  " = \\(PTR TO -> \\( character\\*21 \\)\\) ${hex}" \
+  "print var_char after allocated third time"
+gdb_test "whatis var_char" "type = PTR TO -> \\( character\\*21 \\)" \
+  "whatis var_char after allocated third time"
+gdb_test "ptype var_char" "type = PTR TO -> \\( character\\*21 \\)" \
+  "ptype var_char after allocated third time"
+
+gdb_breakpoint [gdb_get_line_number "var_char_p-associated"]
+gdb_continue_to_breakpoint "var_char_p-associated"
+gdb_test "print var_char_p" \
+  " = \\(PTR TO -> \\( character\\*7 \\)\\) ${hex}" \
+  "print var_char_p after associated"
+gdb_test "print *var_char_p" " = 'johndoe'" \
+  "print *var_char_ after associated"
+gdb_test "whatis var_char_p" "type = PTR TO -> \\( character\\*7 \\)" \
+  "whatis var_char_p after associated"
+gdb_test "ptype var_char_p" "type = PTR TO -> \\( character\\*7 \\)" \
+  "ptype var_char_p after associated"
diff --git a/gdb/testsuite/gdb.fortran/vla-strings.f90 b/gdb/testsuite/gdb.fortran/vla-strings.f90
new file mode 100644
index 0000000..6679043
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-strings.f90
@@ -0,0 +1,38 @@ 
+! Copyright 2014 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 2 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 this program; if not, write to the Free Software
+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+program vla_strings
+  character(len=:), target, allocatable   :: var_char
+  character(len=:), pointer               :: var_char_p
+  logical                                 :: l
+
+  allocate(character(len=10) :: var_char)
+  l = allocated(var_char)                 ! var_char-allocated-1
+  var_char = 'foo'
+  deallocate(var_char)                    ! var_char-filled-1
+  l = allocated(var_char)                 ! var_char-deallocated
+  allocate(character(len=42) :: var_char)
+  l = allocated(var_char)
+  var_char = 'foobar'
+  var_char = ''                           ! var_char-filled-2
+  allocate(character(len=21) :: var_char) ! var_char-empty
+  l = allocated(var_char)                 ! var_char-allocated-3
+  var_char = 'johndoe'
+  var_char_p => var_char
+  l = associated(var_char_p)              ! var_char_p-associated
+  var_char_p => null()
+  l = associated(var_char_p)              ! var_char_p-not-associated
+end program vla_strings