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

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