[3/3] Tests for Python -P commandline support

Message ID 20190721235427.21893-4-kevinb@redhat.com
State New
Headers show
Series
  • Add -P command line switch for executing Python scripts
Related show

Commit Message

Kevin Buettner July 21, 2019, 11:54 p.m.
gdb/testsuite/ChangeLog:

	* gdb.python/py-script.c: New file.
	* gdb.python/py-script.exp: New file.
	* gdb.python/py-script.py: New file.
---
 gdb/testsuite/gdb.python/py-script.c   | 27 ++++++++++++++
 gdb/testsuite/gdb.python/py-script.exp | 51 ++++++++++++++++++++++++++
 gdb/testsuite/gdb.python/py-script.py  | 25 +++++++++++++
 3 files changed, 103 insertions(+)
 create mode 100644 gdb/testsuite/gdb.python/py-script.c
 create mode 100644 gdb/testsuite/gdb.python/py-script.exp
 create mode 100644 gdb/testsuite/gdb.python/py-script.py

-- 
2.21.0

Patch

diff --git a/gdb/testsuite/gdb.python/py-script.c b/gdb/testsuite/gdb.python/py-script.c
new file mode 100644
index 0000000000..bff3a5edf5
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-script.c
@@ -0,0 +1,27 @@ 
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2019 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/>.  */
+
+/* This program is intended to be started outside of gdb, and then
+   attached to by gdb.  It loops for a while, but not forever.  */
+
+#include <unistd.h>
+
+int
+main ()
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.python/py-script.exp b/gdb/testsuite/gdb.python/py-script.exp
new file mode 100644
index 0000000000..fc5b87cb34
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-script.exp
@@ -0,0 +1,51 @@ 
+# Copyright (C) 2019 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/>.
+
+# This file is part of the GDB testsuite.  It tests the loading
+# and execution of scripts specified on the GDB command line.
+
+load_lib gdb-python.exp
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
+    return -1
+}
+
+set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
+save_vars { GDBFLAGS } {
+    append GDBFLAGS " -P $pyfile"
+    clean_restart ${binfile}
+}
+
+if ![runto_main] then {
+    perror "couldn't run to breakpoint"
+    continue
+}
+
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+gdb_test "python print(gdb.script_var1)" "script var 1"
+gdb_test "python print(gdb.script_var2)" "script var 2"
+
+save_vars { GDBFLAGS } {
+    append GDBFLAGS " -P $pyfile first_arg second_arg third_arg"
+    clean_restart ${binfile}
+}
+
+gdb_test "python print(gdb.script_args\[0\])" "first_arg"
+gdb_test "python print(gdb.script_args\[1\])" "second_arg"
+gdb_test "python print(gdb.script_args\[2\])" "third_arg"
diff --git a/gdb/testsuite/gdb.python/py-script.py b/gdb/testsuite/gdb.python/py-script.py
new file mode 100644
index 0000000000..4bbd5ba593
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-script.py
@@ -0,0 +1,25 @@ 
+# Copyright (C) 2019 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/>.
+
+# This file is part of the GDB testsuite.  It tests the loading
+# and execution of a Python script specified on the GDB command line.
+
+import gdb
+import sys
+
+gdb.script_var1 = "script var 1"
+gdb.script_var2 = "script var 2"
+
+gdb.script_args = list(sys.argv)