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

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