public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Doug Evans <xdje42@gmail.com>
To: Tim Wiederhake <tim.wiederhake@intel.com>
Cc: gdb-patches@sourceware.org,  markus.t.metzger@intel.com,
	 palves@redhat.com
Subject: Re: [PATCH v5 8/9] python: Add tests for record Python bindings
Date: Mon, 13 Feb 2017 03:51:00 -0000	[thread overview]
Message-ID: <m3poimrboa.fsf@sspiff.org> (raw)
In-Reply-To: <1485527996-32506-9-git-send-email-tim.wiederhake@intel.com> (Tim	Wiederhake's message of "Fri, 27 Jan 2017 15:39:55 +0100")

Tim Wiederhake <tim.wiederhake@intel.com> writes:
> 2017-01-27  Tim Wiederhake  <tim.wiederhake@intel.com>
>
> gdb/testsuite/ChangeLog:
>
>         * gdb.python/py-record-btrace.c, gdb.python/py-record-btrace.exp,
> 	gdb.python/py-record-full.c, gdb.python/py-record-full.exp: New file.

Hi. Just one question.
Does py-record-full.exp need something like a "skip_btrace_tests" check?
[What if it's run on a target that doesn't have recording.]

>
> ---
>  gdb/testsuite/gdb.python/py-record-btrace.c   |  46 ++++++++
>  gdb/testsuite/gdb.python/py-record-btrace.exp | 146 ++++++++++++++++++++++++++
>  gdb/testsuite/gdb.python/py-record-full.c     |  46 ++++++++
>  gdb/testsuite/gdb.python/py-record-full.exp   |  51 +++++++++
>  4 files changed, 289 insertions(+)
>  create mode 100644 gdb/testsuite/gdb.python/py-record-btrace.c
>  create mode 100644 gdb/testsuite/gdb.python/py-record-btrace.exp
>  create mode 100644 gdb/testsuite/gdb.python/py-record-full.c
>  create mode 100644 gdb/testsuite/gdb.python/py-record-full.exp
>
> diff --git a/gdb/testsuite/gdb.python/py-record-btrace.c b/gdb/testsuite/gdb.python/py-record-btrace.c
> new file mode 100644
> index 0000000..78ba56b
> --- /dev/null
> +++ b/gdb/testsuite/gdb.python/py-record-btrace.c
> @@ -0,0 +1,46 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2016-2017 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/>.  */
> +
> +int
> +function (int arg)
> +{
> +  return arg + 1;
> +}
> +
> +void
> +inner (void)
> +{
> +}
> +
> +void
> +outer (void)
> +{
> +  inner ();
> +}
> +
> +int
> +main (void)
> +{
> +  int i, j;
> +
> +  for (i = 0, j = 0; i < 100; ++i)
> +    j = function (j);
> +
> +  outer ();
> +
> +  return j;
> +}
> diff --git a/gdb/testsuite/gdb.python/py-record-btrace.exp b/gdb/testsuite/gdb.python/py-record-btrace.exp
> new file mode 100644
> index 0000000..65a3e7d
> --- /dev/null
> +++ b/gdb/testsuite/gdb.python/py-record-btrace.exp
> @@ -0,0 +1,146 @@
> +# This testcase is part of GDB, the GNU debugger.
> +#
> +# Copyright 2016-2017 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/>.
> +
> +# Skip this test if btrace is disabled.
> +
> +if { [skip_btrace_tests] } {
> +    untested "skipping btrace tests"
> +    return -1
> +}
> +
> +load_lib gdb-python.exp
> +
> +standard_testfile
> +
> +if [prepare_for_testing "failed to prepare" $testfile $srcfile] { return -1 }
> +
> +# Skip this test if python is disabled.
> +
> +if { [skip_python_tests] } {
> +    untested "skipping python tests"
> +    return -1
> +}
> +
> +if ![runto_main ] then {
> +    fail "can't run to main"
> +    return -1
> +}
> +
> +with_test_prefix "no or double record" {
> +    gdb_test "python print(gdb.current_recording())" "None"
> +
> +    gdb_test_no_output "python gdb.start_recording(\"btrace\")"
> +    gdb_test "python gdb.start_recording(\"btrace\")" ".*gdb\.error: The process is already being recorded\..*"
> +
> +    gdb_test_no_output "python gdb.stop_recording()" "first"
> +    gdb_test "python gdb.stop_recording()" ".*gdb\.error: No record target is currently active\..*" "second"
> +}
> +
> +with_test_prefix "preopened record btrace" {
> +    gdb_test_no_output "record btrace"
> +    gdb_test "python print(gdb.current_recording().method)" "btrace"
> +    gdb_test "python print(gdb.current_recording().format)" "pt|bts"
> +    gdb_test_no_output "python gdb.stop_recording()"
> +}
> +
> +with_test_prefix "prepare record" {
> +    gdb_test_no_output "python r = gdb.start_recording(\"btrace\")"
> +    gdb_test "python print(len(r.ptid))" "3"
> +    gdb_test "python print(r.method)" "btrace"
> +    gdb_test "python print(r.format)" "pt|bts"
> +    gdb_test "stepi 100" ".*"
> +    gdb_test_no_output "python insn = r.instruction_history"
> +    gdb_test_no_output "python call = r.function_call_history"
> +    gdb_test_no_output "python i = insn\[0\]"
> +    gdb_test_no_output "python c = call\[0\]"
> +}
> +
> +with_test_prefix "replay begin" {
> +    gdb_test "python print(r.replay_position)" "None"
> +    gdb_test "python r.goto(r.begin)"
> +    gdb_test "python print(r.replay_position.number)" "1"
> +}
> +
> +with_test_prefix "replay end" {
> +    gdb_test "python r.goto(r.end)"
> +    gdb_test "python print(r.replay_position)" "None"
> +}
> +
> +with_test_prefix "instruction " {
> +    gdb_test "python print(i.number)" "1"
> +    gdb_test "python print(i.error)" "None"
> +    gdb_test "python print(i.sal)" "symbol and line for .*"
> +    gdb_test "python print(i.pc)" "$decimal"
> +    gdb_test "python print(i.data)" "<memory at $hex>"
> +    gdb_test "python print(i.decoded)" ".*"
> +    gdb_test "python print(i.size)" "$decimal"
> +    gdb_test "python print(i.is_speculative)" "False"
> +}
> +
> +with_test_prefix "function call" {
> +    gdb_test "python print(c.number)" "1"
> +    gdb_test "python print(c.symbol)" "main"
> +    gdb_test "python print(c.level)" "$decimal"
> +    gdb_test "python print(len(c.instructions))" "$decimal"
> +    gdb_test "python print(c.up)" "None"
> +    gdb_test "python print(c.prev_sibling)" "None"
> +    gdb_test "python print(c == c.next_sibling.prev_sibling)" "True"
> +}
> +
> +with_test_prefix "list" {
> +    gdb_test "python print(len(insn))" "100"
> +    gdb_test "python print(len(insn\[23:65\]))" "42"
> +    gdb_test "python print(insn\[17:\]\[2\].number)" "20"
> +    gdb_test "python print(i in insn)" "True"
> +    gdb_test "python print(i in call)" "False"
> +    gdb_test "python print(c in insn)" "False"
> +    gdb_test "python print(c in call)" "True"
> +    gdb_test "python print(insn.index(i))" "0"
> +    gdb_test "python print(insn.count(i))" "1"
> +}
> +
> +with_test_prefix "sublist" {
> +    gdb_test_no_output "python s1 = insn\[3:72:5\]"
> +    gdb_test_no_output "python s2 = s1\[2:13:3\]"
> +    gdb_test_no_output "python s3 = s1\[13:2:-3\]"
> +    gdb_test_no_output "python s4 = insn\[::-1\]"
> +
> +    gdb_test "python print(\[i.number for i in s1\])" "\\\[4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69\\\]"
> +    gdb_test "python print(\[i.number for i in s2\])" "\\\[14, 29, 44, 59\\\]"
> +    gdb_test "python print(\[i.number for i in s3\])" "\\\[69, 54, 39, 24\\\]"
> +
> +    gdb_test "python print(len(s1))" "14"
> +    gdb_test "python print(len(s2))" "4"
> +    gdb_test "python print(len(s3))" "4"
> +    gdb_test "python print(len(s4))" "100"
> +
> +    gdb_test "python print(s4\[5\].number)" "95"
> +    gdb_test "python print(s4\[-5\].number)" "5"
> +    gdb_test "python print(s4\[100\].number)" ".*IndexError.*"
> +    gdb_test "python print(s4\[-101\].number)" ".*IndexError.*"
> +}
> +
> +with_test_prefix "level" {
> +    gdb_test_no_output "python gdb.stop_recording()"
> +    gdb_test "break inner" "Breakpoint.*"
> +    gdb_test "continue" "Continuing\..*"
> +    gdb_test_no_output "record btrace"
> +    gdb_test "step" "outer ().*" "step one"
> +    gdb_test "step" "main ().*" "step two"
> +    gdb_test "python print(gdb.current_recording().function_call_history\[0\].level)" "1"
> +    gdb_test "python print(gdb.current_recording().function_call_history\[1\].level)" "0"
> +}
> diff --git a/gdb/testsuite/gdb.python/py-record-full.c b/gdb/testsuite/gdb.python/py-record-full.c
> new file mode 100644
> index 0000000..78ba56b
> --- /dev/null
> +++ b/gdb/testsuite/gdb.python/py-record-full.c
> @@ -0,0 +1,46 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2016-2017 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/>.  */
> +
> +int
> +function (int arg)
> +{
> +  return arg + 1;
> +}
> +
> +void
> +inner (void)
> +{
> +}
> +
> +void
> +outer (void)
> +{
> +  inner ();
> +}
> +
> +int
> +main (void)
> +{
> +  int i, j;
> +
> +  for (i = 0, j = 0; i < 100; ++i)
> +    j = function (j);
> +
> +  outer ();
> +
> +  return j;
> +}
> diff --git a/gdb/testsuite/gdb.python/py-record-full.exp b/gdb/testsuite/gdb.python/py-record-full.exp
> new file mode 100644
> index 0000000..de18b87
> --- /dev/null
> +++ b/gdb/testsuite/gdb.python/py-record-full.exp
> @@ -0,0 +1,51 @@
> +# This testcase is part of GDB, the GNU debugger.
> +#
> +# Copyright 2016-2017 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/>.
> +
> +load_lib gdb-python.exp
> +
> +standard_testfile
> +
> +if [prepare_for_testing "failed to prepare" $testfile $srcfile] { return -1 }
> +
> +# Skip this test if python is disabled.
> +
> +if { [skip_python_tests] } {
> +    untested "skipping python tests"
> +    return -1
> +}
> +
> +if ![runto_main ] then {
> +    fail "can't run to main"
> +    return -1
> +}
> +
> +with_test_prefix "no or double record" {
> +    gdb_test "python print(gdb.current_recording())" "None"
> +
> +    gdb_test_no_output "python gdb.start_recording(\"full\")"
> +    gdb_test "python gdb.start_recording(\"full\")" ".*gdb\.error: The process is already being recorded\..*"
> +
> +    gdb_test_no_output "python gdb.stop_recording()" "first"
> +    gdb_test "python gdb.stop_recording()" ".*gdb\.error: No record target is currently active\..*" "second"
> +}
> +
> +with_test_prefix "preopened record full" {
> +    gdb_test_no_output "record full"
> +    gdb_test "python print(gdb.current_recording().method)" "full"
> +    gdb_test "python print(gdb.current_recording().format)" "full"
> +    gdb_test_no_output "python gdb.stop_recording()"
> +}

  reply	other threads:[~2017-02-13  3:51 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-27 14:40 [PATCH v5 0/9] Python bindings for btrace recordings Tim Wiederhake
2017-01-27 14:40 ` [PATCH v5 6/9] python: Create Python bindings for record history Tim Wiederhake
2017-02-13  3:58   ` Doug Evans
2017-01-27 14:40 ` [PATCH v5 4/9] Add record_start and record_stop functions Tim Wiederhake
2017-02-13  3:58   ` Doug Evans
2017-01-27 14:40 ` [PATCH v5 5/9] Add method to query current recording method to target_ops Tim Wiederhake
2017-02-13  3:58   ` Doug Evans
2017-01-27 14:40 ` [PATCH v5 9/9] Add documentation for new record Python bindings Tim Wiederhake
2017-01-27 14:40 ` [PATCH v5 8/9] python: Add tests for " Tim Wiederhake
2017-02-13  3:51   ` Doug Evans [this message]
2017-02-13 12:39     ` Wiederhake, Tim
2017-01-27 14:40 ` [PATCH v5 3/9] btrace: Use binary search to find instruction Tim Wiederhake
2017-02-13  3:58   ` Doug Evans
2017-01-27 14:41 ` [PATCH v5 1/9] btrace: Count gaps as one instruction explicitly Tim Wiederhake
2017-02-13  3:57   ` Doug Evans
2017-01-27 14:41 ` [PATCH v5 2/9] btrace: Export btrace_decode_error function Tim Wiederhake
2017-02-13  3:57   ` Doug Evans
2017-01-27 14:41 ` [PATCH v5 7/9] python: Implement btrace Python bindings for record history Tim Wiederhake
2017-02-13  3:46   ` Doug Evans
2017-02-13 12:38     ` Wiederhake, Tim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3poimrboa.fsf@sspiff.org \
    --to=xdje42@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=markus.t.metzger@intel.com \
    --cc=palves@redhat.com \
    --cc=tim.wiederhake@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).