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