From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22066 invoked by alias); 21 Nov 2016 15:49:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 21951 invoked by uid 89); 21 Nov 2016 15:49:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=ipc, corp, Corp, stepi X-HELO: mga14.intel.com Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 21 Nov 2016 15:48:58 +0000 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP; 21 Nov 2016 07:48:56 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga005.jf.intel.com with ESMTP; 21 Nov 2016 07:48:55 -0800 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id uALFmsfW026288; Mon, 21 Nov 2016 15:48:54 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id uALFmsH4024819; Mon, 21 Nov 2016 16:48:54 +0100 Received: (from twiederh@localhost) by ulvlx001.iul.intel.com with œ id uALFmsPB024816; Mon, 21 Nov 2016 16:48:54 +0100 From: Tim Wiederhake To: gdb-patches@sourceware.org Cc: palves@redhat.com, markus.t.metzger@intel.com Subject: [PATCH v3 7/8] python: Add tests for record Python bindings Date: Mon, 21 Nov 2016 15:49:00 -0000 Message-Id: <1479743318-24523-8-git-send-email-tim.wiederhake@intel.com> In-Reply-To: <1479743318-24523-1-git-send-email-tim.wiederhake@intel.com> References: <1479743318-24523-1-git-send-email-tim.wiederhake@intel.com> X-IsSubscribed: yes X-SW-Source: 2016-11/txt/msg00609.txt.bz2 2016-11-21 Tim Wiederhake gdb/testsuite/ChangeLog: * gdb.python/py-record-btrace.c: New file. * gdb.python/py-record-btrace.exp: New file. --- gdb/testsuite/gdb.python/py-record-btrace.c | 48 ++++++++ gdb/testsuite/gdb.python/py-record-btrace.exp | 160 ++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 gdb/testsuite/gdb.python/py-record-btrace.c create mode 100644 gdb/testsuite/gdb.python/py-record-btrace.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..e12c132 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-record-btrace.c @@ -0,0 +1,48 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2016 Free Software Foundation, Inc. + + Contributed by Intel Corp. + + 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 . */ + +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..8f8beeb --- /dev/null +++ b/gdb/testsuite/gdb.python/py-record-btrace.exp @@ -0,0 +1,160 @@ +# This testcase is part of GDB, the GNU debugger. +# +# Copyright 2016 Free Software Foundation, Inc. +# +# Contributed by Intel Corp. +# +# 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 . + +# Skip this test if btrace is disabled. + +if { [skip_btrace_tests] } { return -1 } + +load_lib gdb-python.exp + +standard_testfile + +if [prepare_for_testing $testfile.exp $testfile $srcfile] { return -1 } + +# Skip this test if python is disabled. + +if { [skip_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()" + 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()" +} + +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 "open record full" { + gdb_test_no_output "python r = gdb.start_recording(\"full\")" + gdb_test "python print(r.method)" "full" + gdb_test "python print(r.format)" "full" + gdb_test_no_output "python gdb.stop_recording()" +} + +with_test_prefix "open record btrace" { + gdb_test_no_output "python r = gdb.start_recording(\"btrace\")" + gdb_test "python print(r.method)" "btrace" + gdb_test "python print(r.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 "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.symbol)" "symbol and line for .*" + gdb_test "python print(i.pc)" "$decimal" + gdb_test "python print(i.data)" "" + 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" +} -- 2.7.4