Blame SOURCES/gdb-6.6-bz237572-ppc-atomic-sequence-test.patch

861f93
2007-06-25  Jan Kratochvil  <jan.kratochvil@redhat.com>
861f93
861f93
	* gdb.threads/atomic-seq-threaded.c,
861f93
	gdb.threads/atomic-seq-threaded.exp: New files.
861f93
861f93
Index: gdb-6.8.50.20081128/gdb/testsuite/gdb.threads/atomic-seq-threaded.c
861f93
===================================================================
861f93
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
861f93
+++ gdb-6.8.50.20081128/gdb/testsuite/gdb.threads/atomic-seq-threaded.c	2008-12-08 22:27:01.000000000 +0100
861f93
@@ -0,0 +1,171 @@
861f93
+/* This testcase is part of GDB, the GNU debugger.
861f93
+
861f93
+   Copyright 2007 Free Software Foundation, Inc.
861f93
+
861f93
+   This program is free software; you can redistribute it and/or modify
861f93
+   it under the terms of the GNU General Public License as published by
861f93
+   the Free Software Foundation; either version 2 of the License, or
861f93
+   (at your option) any later version.
861f93
+
861f93
+   This program is distributed in the hope that it will be useful,
861f93
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
861f93
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
861f93
+   GNU General Public License for more details.
861f93
+ 
861f93
+   You should have received a copy of the GNU General Public License
861f93
+   along with this program; if not, write to the Free Software
861f93
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
861f93
+   MA 02110-1301, USA.  */
861f93
+
861f93
+/* Test stepping over RISC atomic sequences.
861f93
+   This variant testcases the code for stepping another thread while skipping
861f93
+   over the atomic sequence in the former thread
861f93
+   (STEPPING_PAST_SINGLESTEP_BREAKPOINT).
861f93
+   Code comes from gcc/testsuite/gcc.dg/sync-2.c  */
861f93
+
861f93
+/* { dg-options "-march=i486" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
861f93
+/* { dg-options "-mcpu=v9" { target sparc*-*-* } } */
861f93
+
861f93
+/* Test functionality of the intrinsics for 'short' and 'char'.  */
861f93
+
861f93
+#include <stdlib.h>
861f93
+#include <string.h>
861f93
+#include <pthread.h>
861f93
+#include <assert.h>
861f93
+#include <unistd.h>
861f93
+
861f93
+#define LOOPS 2
861f93
+
861f93
+static int unused;
861f93
+
861f93
+static char AI[18];
861f93
+static char init_qi[18] = { 3,5,7,9,0,0,0,0,-1,0,0,0,0,0,-1,0,0,0 };
861f93
+static char test_qi[18] = { 3,5,7,9,1,4,22,-12,7,8,9,7,1,-12,7,8,9,7 };
861f93
+
861f93
+static void
861f93
+do_qi (void)
861f93
+{
861f93
+  if (__sync_fetch_and_add(AI+4, 1) != 0)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_add(AI+5, 4) != 0)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_add(AI+6, 22) != 0)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_sub(AI+7, 12) != 0)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_and(AI+8, 7) != (char)-1)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_or(AI+9, 8) != 0)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_xor(AI+10, 9) != 0)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_nand(AI+11, 7) != 0)
861f93
+    abort ();
861f93
+
861f93
+  if (__sync_add_and_fetch(AI+12, 1) != 1)
861f93
+    abort ();
861f93
+  if (__sync_sub_and_fetch(AI+13, 12) != (char)-12)
861f93
+    abort ();
861f93
+  if (__sync_and_and_fetch(AI+14, 7) != 7)
861f93
+    abort ();
861f93
+  if (__sync_or_and_fetch(AI+15, 8) != 8)
861f93
+    abort ();
861f93
+  if (__sync_xor_and_fetch(AI+16, 9) != 9)
861f93
+    abort ();
861f93
+  if (__sync_nand_and_fetch(AI+17, 7) != 7)
861f93
+    abort ();
861f93
+}
861f93
+
861f93
+static short AL[18];
861f93
+static short init_hi[18] = { 3,5,7,9,0,0,0,0,-1,0,0,0,0,0,-1,0,0,0 };
861f93
+static short test_hi[18] = { 3,5,7,9,1,4,22,-12,7,8,9,7,1,-12,7,8,9,7 };
861f93
+
861f93
+static void
861f93
+do_hi (void)
861f93
+{
861f93
+  if (__sync_fetch_and_add(AL+4, 1) != 0)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_add(AL+5, 4) != 0)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_add(AL+6, 22) != 0)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_sub(AL+7, 12) != 0)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_and(AL+8, 7) != -1)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_or(AL+9, 8) != 0)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_xor(AL+10, 9) != 0)
861f93
+    abort ();
861f93
+  if (__sync_fetch_and_nand(AL+11, 7) != 0)
861f93
+    abort ();
861f93
+
861f93
+  if (__sync_add_and_fetch(AL+12, 1) != 1)
861f93
+    abort ();
861f93
+  if (__sync_sub_and_fetch(AL+13, 12) != -12)
861f93
+    abort ();
861f93
+  if (__sync_and_and_fetch(AL+14, 7) != 7)
861f93
+    abort ();
861f93
+  if (__sync_or_and_fetch(AL+15, 8) != 8)
861f93
+    abort ();
861f93
+  if (__sync_xor_and_fetch(AL+16, 9) != 9)
861f93
+    abort ();
861f93
+  if (__sync_nand_and_fetch(AL+17, 7) != 7)
861f93
+    abort ();
861f93
+}
861f93
+
861f93
+static void *
861f93
+start1 (void *arg)
861f93
+{
861f93
+  unsigned loop;
861f93
+  sleep(1);
861f93
+
861f93
+  for (loop = 0; loop < LOOPS; loop++)
861f93
+    {
861f93
+      memcpy(AI, init_qi, sizeof(init_qi));
861f93
+
861f93
+      do_qi ();
861f93
+
861f93
+      if (memcmp (AI, test_qi, sizeof(test_qi)))
861f93
+	abort ();
861f93
+    }
861f93
+
861f93
+  return arg;						/* _delete1_ */
861f93
+}
861f93
+
861f93
+static void *
861f93
+start2 (void *arg)
861f93
+{
861f93
+  unsigned loop;
861f93
+
861f93
+  for (loop = 0; loop < LOOPS; loop++)
861f93
+    {
861f93
+      memcpy(AL, init_hi, sizeof(init_hi));
861f93
+
861f93
+      do_hi ();
861f93
+
861f93
+      if (memcmp (AL, test_hi, sizeof(test_hi)))
861f93
+	abort ();
861f93
+    }
861f93
+
861f93
+  return arg;						/* _delete2_ */
861f93
+}
861f93
+
861f93
+int
861f93
+main (int argc, char **argv)
861f93
+{
861f93
+  pthread_t thread;
861f93
+  int i;
861f93
+
861f93
+  i = pthread_create (&thread, NULL, start1, NULL);	/* _create_ */
861f93
+  assert (i == 0);					/* _create_after_ */
861f93
+
861f93
+  sleep (1);
861f93
+
861f93
+  start2 (NULL);
861f93
+
861f93
+  i = pthread_join (thread, NULL);			/* _delete_ */
861f93
+  assert (i == 0);
861f93
+
861f93
+  return 0;						/* _exit_ */
861f93
+}
861f93
Index: gdb-6.8.50.20081128/gdb/testsuite/gdb.threads/atomic-seq-threaded.exp
861f93
===================================================================
861f93
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
861f93
+++ gdb-6.8.50.20081128/gdb/testsuite/gdb.threads/atomic-seq-threaded.exp	2008-12-08 22:31:01.000000000 +0100
861f93
@@ -0,0 +1,84 @@
861f93
+# atomic-seq-threaded.exp -- Test case for stepping over RISC atomic code seqs.
861f93
+# This variant testcases the code for stepping another thread while skipping
861f93
+# over the atomic sequence in the former thread
861f93
+# (STEPPING_PAST_SINGLESTEP_BREAKPOINT).
861f93
+# Copyright (C) 2007 Free Software Foundation, Inc.
861f93
+
861f93
+# This program is free software; you can redistribute it and/or modify
861f93
+# it under the terms of the GNU General Public License as published by
861f93
+# the Free Software Foundation; either version 2 of the License, or
861f93
+# (at your option) any later version.
861f93
+# 
861f93
+# This program is distributed in the hope that it will be useful,
861f93
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
861f93
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
861f93
+# GNU General Public License for more details.
861f93
+# 
861f93
+# You should have received a copy of the GNU General Public License
861f93
+# along with this program; if not, write to the Free Software
861f93
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
861f93
+
861f93
+# Please email any bugs, comments, and/or additions to this file to:
861f93
+# bug-gdb@prep.ai.mit.edu
861f93
+
861f93
+set testfile atomic-seq-threaded
861f93
+set srcfile ${testfile}.c
861f93
+set binfile ${objdir}/${subdir}/${testfile}
861f93
+
861f93
+foreach opts {{} {compiler=gcc4} {FAIL}} {
861f93
+    if {$opts eq "FAIL"} {
861f93
+	return -1
861f93
+    }
861f93
+    if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $opts]] eq "" } {
861f93
+	break
861f93
+    }
861f93
+}
861f93
+
861f93
+gdb_exit
861f93
+gdb_start
861f93
+gdb_reinitialize_dir $srcdir/$subdir
861f93
+
861f93
+gdb_load ${binfile}
861f93
+if ![runto_main] then {
861f93
+   fail "Can't run to main"
861f93
+   return 0
861f93
+}
861f93
+
861f93
+# pthread_create () will not pass even on x86_64 with software watchpoint.
861f93
+# Pass after pthread_create () without any watchpoint active.
861f93
+set line [gdb_get_line_number "_create_after_"]
861f93
+gdb_test "tbreak $line" \
861f93
+	 "reakpoint (\[0-9\]+) at .*$srcfile, line $line\..*" \
861f93
+	 "set breakpoint after pthread_create ()"
861f93
+gdb_test "c" \
861f93
+	 ".*/\\* _create_after_ \\*/.*" \
861f93
+	 "run till after pthread_create ()"
861f93
+
861f93
+# Without a watchpoint being software no single-stepping would be used.
861f93
+set test "Start (software) watchpoint"
861f93
+gdb_test_multiple "watch unused" $test {
861f93
+    -re "Watchpoint \[0-9\]+: unused.*$gdb_prompt $" {
861f93
+	pass $test
861f93
+    }
861f93
+    -re "Hardware watchpoint \[0-9\]+: unused.*$gdb_prompt $" {
861f93
+	# We do not test the goal but still the whole testcase should pass.
861f93
+	unsupported $test
861f93
+    }
861f93
+}
861f93
+
861f93
+# More thorough testing of the scheduling logic.
861f93
+gdb_test "set scheduler-locking step" ""
861f93
+
861f93
+# Critical code path is stepped through at this point.
861f93
+set line [gdb_get_line_number "_exit_"]
861f93
+gdb_test "tbreak $line" \
861f93
+	 "reakpoint \[0-9\]+ at .*$srcfile, line $line\..*" \
861f93
+	 "set breakpoint at _exit_"
861f93
+gdb_test "c" \
861f93
+	 ".*/\\* _exit_ \\*/.*" \
861f93
+	 "run till _exit_"
861f93
+
861f93
+# Just a nonproblematic program exit.
861f93
+gdb_test "c" \
861f93
+	 ".*Program exited normally\\..*" \
861f93
+	 "run till program exit"