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

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