This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/3] Test case: gdb.base/itset.exp and gdb.multi/itset.exp


These tests are about ITSET.  They cover most of ITSET syntax and error
checking.

These tests are run with native gdb and gdbserver/
native-extended-gdbserver.exp respectively.  No fails.

gdb/testsuite:

	* gdb.base/itset.c: New.
	* gdb.base/itset.exp: New.
	* gdb.multi/itset.c: New.
	* gdb.multi/itset.exp: New.
---
 gdb/testsuite/gdb.base/itset.c    |   63 +++++++
 gdb/testsuite/gdb.base/itset.exp  |  325 +++++++++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.multi/itset.c   |   57 +++++++
 gdb/testsuite/gdb.multi/itset.exp |   93 +++++++++++
 4 files changed, 538 insertions(+), 0 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/itset.c
 create mode 100644 gdb/testsuite/gdb.base/itset.exp
 create mode 100644 gdb/testsuite/gdb.multi/itset.c
 create mode 100644 gdb/testsuite/gdb.multi/itset.exp

diff --git a/gdb/testsuite/gdb.base/itset.c b/gdb/testsuite/gdb.base/itset.c
new file mode 100644
index 0000000..2e4ba9e
--- /dev/null
+++ b/gdb/testsuite/gdb.base/itset.c
@@ -0,0 +1,63 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+static void
+marker1 (void)
+{}
+
+static void
+end (void)
+{}
+
+#ifdef THREAD
+#include <pthread.h>
+#include <unistd.h>
+
+static void *
+thread_function (void *arg)
+{
+  int *flag = (int *) arg;
+
+  sleep (10);
+}
+#endif
+
+int
+main (int argc, char *argv[], char *envp[])
+{
+#ifdef THREAD
+  pthread_t threads[2];
+  int i;
+
+  for (i = 0; i < 2; i++)
+    pthread_create (&threads[i], NULL, thread_function, (void *) (&i));
+
+  /* Sleep for a while to make sure child threads are in sleep.  */
+  sleep (3);
+#endif
+
+  marker1 ();
+
+#ifdef THREADS
+  for (i = 0; i < 2; i++)
+    pthread_join (threads[i], NULL);
+#endif
+
+  end ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/itset.exp b/gdb/testsuite/gdb.base/itset.exp
new file mode 100644
index 0000000..3546a79
--- /dev/null
+++ b/gdb/testsuite/gdb.base/itset.exp
@@ -0,0 +1,325 @@
+# Copyright 2012 Free Software Foundation, Inc.
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+set testfile "itset"
+set srcfile ${testfile}.c
+set expfile $testfile.exp
+set binfile $objdir/$subdir/$testfile
+set executable $testfile
+
+if  { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list nowarnings debug]] != "" } { 
+     untested itset.exp
+     return -1
+}
+
+# Test the behaviour of ITSET without any running process.
+
+proc test_itset_without_running_process { } \
+{ with_test_prefix "wo run" \
+{
+    global srcdir
+    global subdir
+    global binfile
+
+    gdb_exit
+    gdb_start
+    gdb_reinitialize_dir $srcdir/$subdir
+    gdb_load ${binfile}
+
+    # Test `maint info itsets'
+    gdb_test_sequence "maint info itsets" "maint info itsets 1" {
+	"\[\r\n\]Num\[ \]+Name\[ \]+What"
+	"\[\r\n\]\-1\[ \]+all\[ \]+all"
+	"\[\r\n\]\-2\[ \]+empty\[ \]+"
+	"\[\r\n\]\-3\[ \]+running\[ \]+running"
+	"\[\r\n\]\-4\[ \]+stopped\[ \]+stopped"
+	"\[\r\n\]\-5\[ \]+curinf\[ \]+curinf"
+    }
+
+    # Test `info itsets'
+    with_test_prefix "info itsets" {
+	gdb_test "info itsets" "No named itsets\." "no itsets no arg"
+	gdb_test "info itsets 1" "No named itset found with number 1\." \
+	    "no itsets with number"
+    }
+
+    # Test defset and undefset
+    gdb_test_no_output "defset itset-c1 c1"
+    gdb_test_no_output "defset itset-c2 c2"
+
+    with_test_prefix "viewset" {
+	if [ gdb_test_sequence "viewset" "no arg" {
+	    "\[\n\r\]all contains:"
+	    "\[\n\r\]  inferiors: 1"
+	    "\[\n\r\]empty contains:"
+	    "\[\n\r\]running contains:"
+	    "\[\n\r\]stopped contains:"
+	    "\[\n\r\]curinf contains:"
+	    "\[\n\r\]  inferiors: 1"
+	    "\[\n\r\]itset-c1 contains:"
+	    "\[\n\r\]itset-c2 contains:"
+	} ] {
+	    fail "no arg"
+	}
+
+	gdb_test "viewset c1" "c1 contains:" "arg c1"
+	gdb_test_sequence "viewset i1" "arg i1" {
+	    "\[\n\r\]i1 contains:"
+	    "\[\n\r\]  inferiors: 1"
+	}
+    }
+
+    gdb_test "whichsets itset-c1" ".*"
+
+    with_test_prefix "info itsets" {
+	gdb_test_sequence "info itsets" "itset-c1" {
+	    "\[\n\r\]1\[ \]+itset-c1\[ \]+c1"
+	    "\[\n\r\]2\[ \]+itset-c2\[ \]+c2"
+	}
+    }
+
+    with_test_prefix "maint info itsets" {
+	if [ gdb_test_sequence "maint info itsets" "2" {
+	    "\[\n\r\]\Num\[ \]+Name\[ \]+What"
+	    "\[\n\r\]\-1\[ \]+all\[ \]+all"
+	    "\[\n\r\]\-2\[ \]+empty\[ \]+"
+	    "\[\n\r\]\-3\[ \]+running\[ \]+running"
+	    "\[\n\r\]\-4\[ \]+stopped\[ \]+stopped"
+	    "\[\n\r\]\-5\[ \]+curinf\[ \]+curinf"
+	    "\[\n\r\]1\[ \]+itset-c1\[ \]+c1"
+	    "\[\n\r\]2\[ \]+itset-c2\[ \]+c2"
+	} ] {
+	    fail "2"
+	}
+    }
+
+    # Test undefset
+    gdb_test_no_output "undefset itset-c1"
+    gdb_test_no_output "undefset -all"
+}}
+
+# Test various error messages from ITSET related commands.
+
+proc test_itset_check_error { } \
+{ with_test_prefix "error message" \
+{
+    global srcdir
+    global subdir
+    global binfile
+
+    gdb_exit
+    gdb_start
+    gdb_reinitialize_dir $srcdir/$subdir
+    gdb_load ${binfile}
+
+    with_test_prefix "defset" {
+	gdb_test "defset" "Argument required \\(no args\\)\." \
+	    "without args"
+
+	gdb_test_no_output "defset itset-c1 c1"
+	gdb_test "defset itset-c1 c2" "itset itset-c1 already exists" \
+	    "already exists"
+
+	# Test "static itset is empty".
+	gdb_test "defset itset2 !i8" "warning: static itset is empty" \
+	    "empty static itset"
+
+	gdb_test_no_output "undefset -all"
+    }
+
+    with_test_prefix "undefset" {
+	gdb_test "undefset" "Argument required \\(no args\\)\." \
+	    "without args"
+	gdb_test "undefset itset-c1" "itset itset-c1 does not exist" \
+	    "does not exist"
+
+	gdb_test_no_output "defset itset-c1 c1"
+	gdb_test_no_output "undefset -all"
+    }
+
+    gdb_test "info itsets foo" "No named itset found with number foo\."
+}}
+
+proc test_itset_check_syntax { } \
+{ with_test_prefix "syntax" \
+{
+    global srcdir
+    global subdir
+    global binfile
+
+    gdb_exit
+    gdb_start
+    gdb_reinitialize_dir $srcdir/$subdir
+    gdb_load ${binfile}
+
+    gdb_test "defset itset-c1 c2-a" "Expected digit in I/T set, at `a'"
+
+    gdb_test "defset itset1 c1,other" "Unknown named I/T set: `other\'"
+
+    # Test parse_parens_set.
+    gdb_test "defset itset1 c1.(t1,other" "Unknown named I/T set: `other\'" \
+	"parens set: parse one"
+    gdb_test "defset itset1 c1.(t1,t2w" "Invalid I/T syntax at `w\'" \
+	"parens set: missing )"
+
+    # Test exec ITSET.
+    with_test_prefix "exec" {
+	gdb_test "defset itset-exec2 exec./gdb" \
+	    "\'\\(\' expected in I/T set after `exec\'" "missing ("
+	gdb_test "defset itset-exec2 exec\(./gdb" \
+	    "No closing \'\\)\' in I/T set for `exec\'" "missing )"
+	gdb_test "defset itset-exec2 exec\(\)" \
+	    "Empty argument to `exec\' in I/T set" "empty argument"
+    }
+}}
+
+test_itset_without_running_process
+
+test_itset_check_error
+
+test_itset_check_syntax
+
+# Test the behaviour of ITSET in single-thread.
+
+proc test_itset_with_running_single_thread { } \
+{ with_test_prefix "w run st" \
+{
+    global executable
+    global binfile
+
+    # Start with a fresh gdb.
+    clean_restart ${executable}
+    if ![runto_main] {
+	fail "Can't run to main"
+	return -1
+    }
+
+    gdb_test_no_output "defset itset-t1 t1"
+    gdb_test_no_output "defset itset-t2 t2"
+    gdb_test_no_output "defset itset-t1-t2 t1-2"
+
+    gdb_test "whichsets t1" \
+	"i1\.t1 \\(Thread .*\\) is in: all, stopped, curinf, itset-t1, itset-t1-t2"
+    # whichsets for current itset.
+    gdb_test "whichsets" \
+	"i1\.t1 \\(Thread .*\\) is in: all, stopped, curinf, itset-t1, itset-t1-t2"
+
+    gdb_test_no_output "defset itset-exec1 exec\(${binfile}\)" "defset exec"
+    gdb_test "whichsets i1" \
+	"i1\.t1 \\(Thread .*\\) is in: all, stopped, curinf, itset-t1, itset-t1-t2, itset-exec1" \
+	"wichsets exec"
+
+    # Test viewset
+    set test "viewset t1"
+    if [ gdb_test_sequence "viewset t1" $test {
+	"\[\n\r\]t1 contains:"
+	"\[\n\r\]  inferiors: 1"
+	"\[\n\r\]  threads: 1"
+	"\[\n\r\]  cores: \[0-9\]+"
+    } ] {
+	fail $test
+    }
+}}
+
+test_itset_with_running_single_thread
+
+set testfile "itset-mt"
+set binfile $objdir/$subdir/$testfile
+set executable $testfile
+lappend compile_flags "additional_flags=-DTHREAD"
+
+# Compile a multi-threaded version of test case.
+if  { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
+	   executable [list nowarnings debug $compile_flags]] != "" } {
+     untested itset.exp
+     return -1
+}
+
+# Test the behaviour of static itset in mulit-thread.
+
+proc test_static_itset_with_multi_thread { } \
+{ with_test_prefix "static w run mt" \
+{
+    global executable
+    global srcfile
+
+    # Start with a fresh gdb.
+    clean_restart ${executable}
+    if ![runto_main] {
+	fail "Can't run to main"
+	return -1
+    }
+
+    # So far, there is only one thread t1.
+    gdb_test_no_output "defset s1 !i1.t1-2,i2.t3-4"
+    gdb_test "whichsets t1" \
+	"i1\.t1 \\(Thread .*\\) is in: all, stopped, curinf, s1" \
+	"1 thread: s1 contains t1"
+
+    gdb_test "break marker1" "Breakpoint \[0-9\] at .*${srcfile}.*"
+    gdb_test "continue" ".*Breakpoint \[0-9\], marker1.*" \
+	"continue to marker1"
+
+    # Update GDB's knowledge on existing threads.
+    gdb_test "info threads" ".*"
+
+   # Now, there are three threads.
+    gdb_test "whichsets t1" \
+	"i1\.t1 \\(Thread .*\\) is in: all, stopped, curinf, s1" \
+	"3 threads: s1 contains t1"
+    gdb_test "whichsets t2" \
+	"i1\.t2 \\(Thread .*\\) is in: all, stopped, curinf" \
+	"3 threads: s1 doesn't contain t2"
+    gdb_test "whichsets t3" \
+	"i1\.t3 \\(Thread .*\\) is in: all, stopped, curinf" \
+	"3 threads: s1 doesn't contain t3"
+
+    gdb_test_no_output "defset s2 !i1.t1-2,i2.t3-4"
+    gdb_test "whichsets t3" \
+	"i1\.t3 \\(Thread .*\\) is in: all, stopped, curinf" \
+	"3 threads: s2 doesn't contain t3"
+
+    gdb_test_sequence "whichsets" "whichsets no arg" {
+	"i1\.t3 \\(Thread .*\\) is in: all, stopped, curinf\[\n\r\]"
+	"i1\.t2 \\(Thread .*\\) is in: all, stopped, curinf, s2\[\n\r\]"
+	"i1\.t1 \\(Thread .*\\) is in: all, stopped, curinf, s1, s2\[\n\r\]"
+    }
+
+    # Assume that three threads are running on one of core from core 0 to
+    # core 1000.
+    gdb_test_no_output "defset s3 !t1,c0-1000"
+    gdb_test "whichsets t1" \
+	"i1\.t1 \\(Thread .*\\) is in: all, stopped, curinf, s1, s2, s3" \
+	"3 threads: s3 contains t1"
+    gdb_test "whichsets t2" \
+	"i1\.t2 \\(Thread .*\\) is in: all, stopped, curinf, s2, s3" \
+	"3 threads: s3 contains t2"
+    gdb_test "whichsets t3" \
+	"i1\.t3 \\(Thread .*\\) is in: all, stopped, curinf, s3" \
+	"3 threads: s3 contains t3"
+
+    # All three threads are stopped.
+    gdb_test_no_output "defset s4 !t1,stopped"
+    gdb_test "whichsets t1" \
+	"i1\.t1 \\(Thread .*\\) is in: all, stopped, curinf, s1, s2, s3, s4" \
+	"3 threads: s4 contains t1"
+    gdb_test "whichsets t2" \
+	"i1\.t2 \\(Thread .*\\) is in: all, stopped, curinf, s2, s3, s4" \
+	"3 threads: s4 contains t2"
+    gdb_test "whichsets t3" \
+	"i1\.t3 \\(Thread .*\\) is in: all, stopped, curinf, s3, s4" \
+	"3 threads: s4 contains t3"
+}}
+
+test_static_itset_with_multi_thread
diff --git a/gdb/testsuite/gdb.multi/itset.c b/gdb/testsuite/gdb.multi/itset.c
new file mode 100644
index 0000000..4ad59f5
--- /dev/null
+++ b/gdb/testsuite/gdb.multi/itset.c
@@ -0,0 +1,57 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+static void
+marker1 (void)
+{}
+
+static void
+end (void)
+{}
+
+#include <pthread.h>
+#include <unistd.h>
+
+static void *
+thread_function (void *arg)
+{
+  int *flag = (int *) arg;
+
+  sleep (10);
+}
+
+int
+main (int argc, char *argv[], char *envp[])
+{
+  pthread_t threads[2];
+  int i;
+
+  for (i = 0; i < 2; i++)
+    pthread_create (&threads[i], NULL, thread_function, (void *) (&i));
+
+  /* Sleep for a while to make sure child threads are in sleep.  */
+  sleep (3);
+
+  marker1 ();
+
+  for (i = 0; i < 2; i++)
+    pthread_join (threads[i], NULL);
+
+  end ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.multi/itset.exp b/gdb/testsuite/gdb.multi/itset.exp
new file mode 100644
index 0000000..667a32e
--- /dev/null
+++ b/gdb/testsuite/gdb.multi/itset.exp
@@ -0,0 +1,93 @@
+# Copyright 2012 Free Software Foundation, Inc.
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if { [is_remote target] || ![isnative] } then {
+    continue
+}
+
+# Until "catch exec" is implemented on other targets...
+#
+if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
+    continue
+}
+
+set testfile "itset"
+set srcfile ${testfile}.c
+set expfile $testfile.exp
+set binfile $objdir/$subdir/$testfile
+set executable $testfile
+
+if  { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
+	   executable [list nowarnings debug]] != "" } {
+     untested itset.exp
+     return -1
+}
+
+# Test the behaviour of static itset in multi-inferior and mulit-thread.
+
+proc test_static_itset { } \
+{ with_test_prefix "static w run" \
+{
+    global executable
+    global binfile
+    global srcfile
+
+    # Start with a fresh gdb.
+    clean_restart ${executable}
+    if ![runto_main] {
+	fail "Can't run to main 1"
+	return -1
+    }
+
+    gdb_test "add-inferior -exec ${binfile}" \
+	"Added inferior 2.*" \
+	"add inferior 2 with -exec ${binfile}"
+
+    gdb_test "inferior 2"
+    if ![runto_main] {
+	fail "Can't run to main 2"
+	return -1
+    }
+
+    # So far, there are two inferiors i1 and i2.  Each of them has only
+    # one thread.
+    gdb_test_no_output "defset s1 !i1.t1,i2.t2-10"
+    gdb_test "whichsets t1" "i1\.t1 \\(Thread .*\\) is in: all, stopped, s1" \
+	"1 thread: s1 contains i1.t1"
+    gdb_test "whichsets t2" "i2\.t2 \\(Thread .*\\) is in: all, stopped, curinf, s1" \
+	"1 thread: s1 contains i2.t2"
+
+    # This breakpoint is set to both inferior 1 and inferior 2.
+    gdb_test "break marker1" \
+	"Breakpoint \[0-9\] at .* marker1.*"
+
+    gdb_test "inferior 1"
+    gdb_test "continue" ".*Breakpoint \[0-9\], marker1.*" \
+	"continue to marker1"
+
+    # Now, there are three threads in inferior 1, t1, t3, t4, and still
+    # only one thread t2 in inferior 2.
+    # Update GDB's knowledge on existing threads.
+    gdb_test "info threads" ".*"
+    gdb_test "whichsets t2" "i2\.t2 \\(Thread .*\\) is in: all, stopped, s1" \
+	"1 thread: s1 contains i1.t2"
+    gdb_test "whichsets t3" \
+	"i1\.t3 \\(Thread .*\\) is in: all, stopped, curinf" \
+	"1 thread: s1 contains i1.t3"
+    gdb_test "whichsets t4" \
+	"i1\.t4 \\(Thread .*\\) is in: all, stopped, curinf" \
+	"1 thread: s1 contains i1.t4"
+}}
+
+test_static_itset
-- 
1.7.0.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]