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

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