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

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