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

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