From 263108e10f6dd413b3adbc3c3ed5bac906e71c9f Mon Sep 17 00:00:00 2001
From: Janis Johnson <janis187@us.ibm.com>
Date: Thu, 13 Jul 2006 22:58:07 +0000
Subject: [PATCH] sourcebuild.texi (Test Directives): Document dg-shouldfail.

gcc:

	* doc/sourcebuild.texi (Test Directives): Document dg-shouldfail.

gcc/testsuite:

	* lib/gcc-dg.exp (tool_load): Wrapper to support shouldfail tests.
	(dg-test): Support shouldfail tests.
	* lib/target-supports-dg.exp (dg-shouldfail): New.
	* gcc.test-framework/test-framework.awk: Handle shouldfail tests.
	* gcc.test-framework/dg-do-run-sf-exp-F.c: New test.
	* gcc.test-framework/dg-do-run-sf-exp-P.c: New test.
	* gcc.test-framework/dg-do-run-sft-exp-F.c: New test.
	* gcc.test-framework/dg-do-run-sft-exp-P.c: New test.
	* gcc.test-framework/dg-dox-run-sf-exp-XF.c: New test.
	* gcc.test-framework/dg-dox-run-sf-exp-XP.c: New test.

From-SVN: r115424
---
 gcc/ChangeLog                                 |  4 +++
 gcc/doc/sourcebuild.texi                      |  4 +++
 gcc/testsuite/ChangeLog                       | 13 ++++++++
 .../gcc.test-framework/dg-do-run-sf-exp-F.c   |  8 +++++
 .../gcc.test-framework/dg-do-run-sf-exp-P.c   | 10 ++++++
 .../gcc.test-framework/dg-do-run-sft-exp-F.c  | 10 ++++++
 .../gcc.test-framework/dg-do-run-sft-exp-P.c  | 10 ++++++
 .../gcc.test-framework/dg-dox-run-sf-exp-XF.c |  8 +++++
 .../gcc.test-framework/dg-dox-run-sf-exp-XP.c | 10 ++++++
 .../gcc.test-framework/test-framework.awk     |  4 ++-
 gcc/testsuite/lib/gcc-dg.exp                  | 25 +++++++++++++++
 gcc/testsuite/lib/target-supports-dg.exp      | 31 +++++++++++++++++++
 12 files changed, 136 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.test-framework/dg-do-run-sf-exp-F.c
 create mode 100644 gcc/testsuite/gcc.test-framework/dg-do-run-sf-exp-P.c
 create mode 100644 gcc/testsuite/gcc.test-framework/dg-do-run-sft-exp-F.c
 create mode 100644 gcc/testsuite/gcc.test-framework/dg-do-run-sft-exp-P.c
 create mode 100644 gcc/testsuite/gcc.test-framework/dg-dox-run-sf-exp-XF.c
 create mode 100644 gcc/testsuite/gcc.test-framework/dg-dox-run-sf-exp-XP.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 72167faf510a..6dca0bf66773 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,7 @@
+2006-07-13  Janis Johnson  <janis187@us.ibm.com>
+
+	* doc/sourcebuild.texi (Test Directives): Document dg-shouldfail.
+
 2006-07-13  Jan Hubicka  <jh@suse.cz>
 
 	* cgraphunit.c (cgraph_varpool_analyze_pending_decls): Call
diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 2bfa582f0c81..d7f18c5c1546 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -1004,6 +1004,10 @@ Skip the test if the test target, including current multilib flags,
 is not covered by the effective-target keyword.
 This directive must appear after any @code{dg-do} directive in the test.
 
+@item  @{ dg-shouldfail @var{comment} @{ @var{selector} @} @{ @var{include-opts} @} @{ @var{exclude-opts} @} @}
+Expect the test executable to return a nonzero exit status if the
+conditions (which are the same as for @code{dg-skip-if}) are met.
+
 @item @{ dg-error @var{regexp} [@var{comment} [@{ target/xfail @var{selector} @} [@var{line}] @}]] @}
 This DejaGnu directive appears on a source line that is expected to get
 an error message, or else specifies the source line associated with the
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b133204f32cd..8b711994d3d2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,16 @@
+2006-07-13  Janis Johnson  <janis187@us.ibm.com>
+
+	* lib/gcc-dg.exp (tool_load): Wrapper to support shouldfail tests.
+	(dg-test): Support shouldfail tests.
+	* lib/target-supports-dg.exp (dg-shouldfail): New.
+	* gcc.test-framework/test-framework.awk: Handle shouldfail tests.
+	* gcc.test-framework/dg-do-run-sf-exp-F.c: New test.
+	* gcc.test-framework/dg-do-run-sf-exp-P.c: New test.
+	* gcc.test-framework/dg-do-run-sft-exp-F.c: New test.
+	* gcc.test-framework/dg-do-run-sft-exp-P.c: New test.
+	* gcc.test-framework/dg-dox-run-sf-exp-XF.c: New test.
+	* gcc.test-framework/dg-dox-run-sf-exp-XP.c: New test.
+
 2006-07-13  Jan Hubicka  <jh@suse.cz>
 
 	* gcc.target/i386/memcpy-1.c: New.
diff --git a/gcc/testsuite/gcc.test-framework/dg-do-run-sf-exp-F.c b/gcc/testsuite/gcc.test-framework/dg-do-run-sf-exp-F.c
new file mode 100644
index 000000000000..076c14c52609
--- /dev/null
+++ b/gcc/testsuite/gcc.test-framework/dg-do-run-sf-exp-F.c
@@ -0,0 +1,8 @@
+/* { dg-do run } */
+/* { dg-shouldfail "required comment" } */
+
+int
+main ()
+{
+    return 0;  /* We expect nonzero, so this fails.  */
+}
diff --git a/gcc/testsuite/gcc.test-framework/dg-do-run-sf-exp-P.c b/gcc/testsuite/gcc.test-framework/dg-do-run-sf-exp-P.c
new file mode 100644
index 000000000000..6e9dd849c59b
--- /dev/null
+++ b/gcc/testsuite/gcc.test-framework/dg-do-run-sf-exp-P.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-shouldfail "required comment" } */
+
+extern void abort (void);
+
+int
+main ()
+{
+    abort ();  /* We expect nonzero, so this passes.  */
+}
diff --git a/gcc/testsuite/gcc.test-framework/dg-do-run-sft-exp-F.c b/gcc/testsuite/gcc.test-framework/dg-do-run-sft-exp-F.c
new file mode 100644
index 000000000000..8695bd66a2bb
--- /dev/null
+++ b/gcc/testsuite/gcc.test-framework/dg-do-run-sft-exp-F.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-shouldfail "comment" { unknown-*-* } { "*" } { "" } } */
+
+extern void abort (void);
+
+int
+main ()
+{
+    abort ();  /* Directive is ignored so we expect zero; this fails.  */
+}
diff --git a/gcc/testsuite/gcc.test-framework/dg-do-run-sft-exp-P.c b/gcc/testsuite/gcc.test-framework/dg-do-run-sft-exp-P.c
new file mode 100644
index 000000000000..0695df9142b6
--- /dev/null
+++ b/gcc/testsuite/gcc.test-framework/dg-do-run-sft-exp-P.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-shouldfail "comment" { *-*-* } { "*" } { "" } } */
+
+extern void abort (void);
+
+int
+main ()
+{
+    abort ();  /* We expect nonzero exit, so this passes.  */
+}
diff --git a/gcc/testsuite/gcc.test-framework/dg-dox-run-sf-exp-XF.c b/gcc/testsuite/gcc.test-framework/dg-dox-run-sf-exp-XF.c
new file mode 100644
index 000000000000..e5eae7775c4a
--- /dev/null
+++ b/gcc/testsuite/gcc.test-framework/dg-dox-run-sf-exp-XF.c
@@ -0,0 +1,8 @@
+/* { dg-do run { xfail *-*-* } } */
+/* { dg-shouldfail "required comment" } */
+
+int
+main ()
+{
+    return 0;  /* We want nonzero but expect to fail; XFAIL.  */
+}
diff --git a/gcc/testsuite/gcc.test-framework/dg-dox-run-sf-exp-XP.c b/gcc/testsuite/gcc.test-framework/dg-dox-run-sf-exp-XP.c
new file mode 100644
index 000000000000..59b5f8be21ff
--- /dev/null
+++ b/gcc/testsuite/gcc.test-framework/dg-dox-run-sf-exp-XP.c
@@ -0,0 +1,10 @@
+/* { dg-do run { xfail *-*-* } } */
+/* { dg-shouldfail "required comment" } */
+
+extern void abort (void);
+
+int
+main ()
+{
+    abort ();  /* We want nonzero, but expect to fail; XPASS.  */
+}
diff --git a/gcc/testsuite/gcc.test-framework/test-framework.awk b/gcc/testsuite/gcc.test-framework/test-framework.awk
index 30ff13d6e2de..4c1436fe74d4 100644
--- a/gcc/testsuite/gcc.test-framework/test-framework.awk
+++ b/gcc/testsuite/gcc.test-framework/test-framework.awk
@@ -3,7 +3,7 @@
 # of passing tests.
 #
 #
-# Copyright (c) 2004, 2005 Free Software Foundation, Inc.
+# Copyright (c) 2004, 2005, 2006 Free Software Foundation, Inc.
 #
 # This file is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -45,6 +45,8 @@ BEGIN			{ skip = 1; passes = 0; fails = 0; }
 /^PASS.*sa.*-1.c.*(test for excess errors)/ { ignore(); next }
 # The other dox tests pass the compile step; ignore that message.
 /^PASS.*dox.*(test for excess errors)/ { ignore(); next }
+# The sf tests pass the compile step; ignore that message.
+/^PASS.*sf.*(test for excess errors)/ { ignore(); next }
 # Ignore lines that begin with comma.
 /^,/			{ ignore(); next }
 # For tests of dg-output, ignore successful compilation.
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index d790396ab94e..869f944b4a50 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -186,6 +186,28 @@ proc gcc-dg-prune { system text } {
     return $text
 }
 
+# Replace ${tool}_load with a wrapper to provide for an expected nonzero
+# exit status.  Multiple languages include this file so this handles them
+# all, not just gcc.
+if { [info procs ${tool}_load] != [list] \
+      && [info procs saved_${tool}_load] == [list] } {
+    rename ${tool}_load saved_${tool}_load
+
+    proc ${tool}_load { program args } {
+	global tool
+	global shouldfail
+	set result [saved_${tool}_load $program $args]
+	if { $shouldfail != 0 } {
+	    switch [lindex $result 0] {
+		"pass" { set status "fail" }
+		"fail" { set status "pass" }
+	    }
+	    set result [list $status [lindex $result 1]]
+	}
+	return $result
+    }
+}
+
 # Utility routines.
 
 #
@@ -436,12 +458,14 @@ if { [info procs saved-dg-test] == [list] } {
 	global additional_prunes
 	global errorInfo
 	global compiler_conditional_xfail_data
+	global shouldfail
 
 	if { [ catch { eval saved-dg-test $args } errmsg ] } {
 	    set saved_info $errorInfo
 	    set additional_files ""
 	    set additional_sources ""
 	    set additional_prunes ""
+	    set shouldfail 0
 	    if [info exists compiler_conditional_xfail_data] {
 		unset compiler_conditional_xfail_data
 	    }
@@ -450,6 +474,7 @@ if { [info procs saved-dg-test] == [list] } {
 	set additional_files ""
 	set additional_sources ""
 	set additional_prunes ""
+	set shouldfail 0
 	if [info exists compiler_conditional_xfail_data] {
 	    unset compiler_conditional_xfail_data
 	}
diff --git a/gcc/testsuite/lib/target-supports-dg.exp b/gcc/testsuite/lib/target-supports-dg.exp
index e8eac300e694..929f8bcf2415 100644
--- a/gcc/testsuite/lib/target-supports-dg.exp
+++ b/gcc/testsuite/lib/target-supports-dg.exp
@@ -265,6 +265,37 @@ proc dg-xfail-if { args } {
     }
 }
 
+# Record whether the program is expected to return a nonzero status.
+
+set shouldfail 0
+
+proc dg-shouldfail { args } {
+    # Don't bother if we're already skipping the test.
+    upvar dg-do-what dg-do-what
+    if { [lindex ${dg-do-what} 1] == "N" } {
+      return
+    }
+
+    global shouldfail
+
+    set args [lreplace $args 0 0]
+    if { [llength $args] > 1 } {
+	set selector [list target [lindex $args 1]]
+	if { [dg-process-target $selector] == "S" } {
+	    # The target matches, now check the flags.  These variables
+	    # are defined in DejaGnu's dg-test, needed by check-flags.
+	    upvar dg-extra-tool-flags dg-extra-tool-flags
+	    upvar tool_flags tool_flags
+
+	    if [check-flags $args] {
+		set shouldfail 1
+	    }
+	}
+    } else {
+	set shouldfail 1
+    }
+}
+
 # Intercept the call to the DejaGnu version of dg-process-target to
 # support use of an effective-target keyword in place of a list of
 # target triplets to xfail or skip a test.
-- 
GitLab