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

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