Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA/testsuite] Test printing complex numbers in C
@ 2002-10-04 20:21 Daniel Jacobowitz
  2002-12-03  8:24 ` Fernando Nasser
  2002-12-05  7:10 ` Fernando Nasser
  0 siblings, 2 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2002-10-04 20:21 UTC (permalink / raw)
  To: gdb-patches; +Cc: fnasser

Fernando,

I think this test submission got lost, so here it is again.  It's a test for
the printing of complex numbers in C, for those compilers which support it. 
The test is GCC specific right now.

[By the way, it fails on GCC 3.0/stabs because of a (probably) GCC bug in
debug information.  Still not fixed in 3.2.  It also fails in GCC
2.95/DWARF-2 because of a bug with __attribute__((packed)).  We can sort out
XFAILs later, I have some ideas on that front.]

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer


2002-03-20  Daniel Jacobowitz  <drow@mvista.com>

	* gdb.base/complex.c: New file.
	* gdb.base/complex.exp: New file.

--- /dev/null	Wed Dec 31 19:00:00 1969
+++ gdb/testsuite/gdb.base/complex.c	Wed Mar 20 19:51:21 2002
@@ -0,0 +1,49 @@
+/* Test taken from GCC.  Verify that we can print a structure containing
+   a complex number.  */
+
+typedef __complex__ float cf;
+struct x { char c; cf f; } __attribute__ ((__packed__));
+struct unpacked_x { char c; cf f; };
+extern void f4 (struct unpacked_x*);
+extern void f3 (void);
+extern void f2 (struct x*);
+extern void f1 (void);
+int
+main (void)
+{
+  f1 ();
+  f3 ();
+  exit (0);
+}
+
+void
+f1 (void)
+{
+  struct x s;
+  s.f = 1;
+  s.c = 42;
+  f2 (&s);
+}
+
+void
+f2 (struct x *y)
+{
+  if (y->f != 1 || y->c != 42)
+    abort ();
+}
+
+void
+f3 (void)
+{
+  struct unpacked_x s;
+  s.f = 1;
+  s.c = 42;
+  f4 (&s);
+}
+
+void
+f4 (struct unpacked_x *y)
+{
+  if (y->f != 1 || y->c != 42)
+    abort ();
+}
--- /dev/null	Wed Dec 31 19:00:00 1969
+++ gdb/testsuite/gdb.base/complex.exp	Wed Mar 20 19:50:45 2002
@@ -0,0 +1,56 @@
+# Copyright 2002 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.  
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+if $tracelevel then {
+	strace $tracelevel
+}
+
+set bug_id 0
+
+set testfile complex
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+set options debug
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $options] != "" } {
+  # No support for __complex__, presumably.
+  unsupported "print complex packed value in C"
+  unsupported "print complex value in C"
+  return 0
+}
+
+# Start with a fresh gdb.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load $binfile
+
+if [runto f2] then {
+  gdb_test "p *y" "\\\$\[0-9\]* = \{c = 42 '\\*', f = 1 \\+ 0 \\* I\}" \
+	"print complex packed value in C"
+}
+
+if [runto f4] then {
+  gdb_test "p *y" "\\\$\[0-9\]* = \{c = 42 '\\*', f = 1 \\+ 0 \\* I\}" \
+	"print complex value in C"
+
+}
+
+return 0


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [RFA/testsuite] Test printing complex numbers in C
@ 2002-12-03  8:54 Michael Elizabeth Chastain
  2002-12-04 15:19 ` Fernando Nasser
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Elizabeth Chastain @ 2002-12-03  8:54 UTC (permalink / raw)
  To: drow, fnasser; +Cc: gdb-patches

		  stabs           DWARF-2
  GCC 2.95        pass            fail
  GCC 3.x         fail            pass

Do gcc 2.95.3/dwarf-2 and gcc 3.x/stabs+ have identical output,
or different output?

If they are different output, you can do:

  send_gdb "blah"
  gdb_expect {
    -re "good output" {
      pass ...
    }
    -re "flaky gcc 2.95.3/dwarf-2 output" {
      setup_xfail_format "dwarf-2"
      fail ...
    }
    -re "flaky gcc 3.x/stabs+ output" {
      setup_xfail_format "stabs+"
      fail ...
    }
    -re ".*" {
      fail ...
    }
  }

You can also dynamically poke at the executable to see what gcc compiled
it.  See "probe_demangler" in gdb.c++/cplusfuncs.exp for one way to do it.

Michael C


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [RFA/testsuite] Test printing complex numbers in C
@ 2002-12-04 20:29 Michael Elizabeth Chastain
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Elizabeth Chastain @ 2002-12-04 20:29 UTC (permalink / raw)
  To: drow, fnasser; +Cc: gdb-patches

Fernando Nasser writes:
> I wonder if we wouldn't do something with regards to compiler (GCC)
> versions as well.

I think we should bite the bullet and add something to lib/gdb.exp
to figure out the compiler version.

In fact, I see that we already do!  The variable "gcc_compiled" is set
to __GNUC__ if that is defined, or 0 if nothing is defined.  "info cpp"
says that __GNUC__ equals the major version of the compiler: 2 for gcc
2.x and 3 for gcc 3.x.  This is a documented feature so we can rely on
it being the major version number for all gcc's forever.

So "gcc_compiled" is more than a boolean, it actually has the values:

  0  not gnu c
  2  gcc v2
  3  gcc v3

I haven't actually tested this because I'm kinda tired and my test bed
is cranking on 5.2.91 and I don't want to get close to its playpen
and I don't want to start a different test bed.

As far as using it goes, I agree with Fernando, it's usually a good idea,
because it increases the specificity of the test suite.  Also it makes
the test suite a lot easier to maintain because it's clear which results
are expected from which compilers, so that people can read it easier,
and obsolete compilers can be de-supported more easily.

Michael C


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

end of thread, other threads:[~2002-12-05 15:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-04 20:21 [RFA/testsuite] Test printing complex numbers in C Daniel Jacobowitz
2002-12-03  8:24 ` Fernando Nasser
2002-12-03  8:33   ` Daniel Jacobowitz
2002-12-04 15:23     ` Fernando Nasser
2002-12-05  7:10 ` Fernando Nasser
2002-12-03  8:54 Michael Elizabeth Chastain
2002-12-04 15:19 ` Fernando Nasser
2002-12-04 20:29 Michael Elizabeth Chastain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox