From patchwork Wed Jan 26 21:32:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 80553 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 3C4BCB7109 for ; Thu, 27 Jan 2011 08:32:29 +1100 (EST) Received: (qmail 991 invoked by alias); 26 Jan 2011 21:32:27 -0000 Received: (qmail 971 invoked by uid 22791); 26 Jan 2011 21:32:25 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_CX, TW_DC, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 26 Jan 2011 21:32:19 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0QLWHSm002448 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 26 Jan 2011 16:32:17 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p0QLWHfR024555; Wed, 26 Jan 2011 16:32:17 -0500 Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p0QLWGUD003290; Wed, 26 Jan 2011 16:32:16 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id C196A3783AD; Wed, 26 Jan 2011 14:32:15 -0700 (MST) From: Tom Tromey To: libstdc Subject: RFC: add a testsuite for libstdc++ pretty-printers CC: gcc-patches@gcc.gnu.org Date: Wed, 26 Jan 2011 14:32:15 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch adds a minimal test suite for the libstdc++ pretty-printers. I based it on Alexandre's gcc-gdb-test.exp code from the gcc test suite. However, I needed somewhat different functionality, so I modified it in a few ways. Adding a new test is very simple: modify simple.cc and add a dg-final marker to pretty-print the relevant objects. Let me know what you think. Tom 2011-01-26 Tom Tromey * testsuite/libstdc++-pp/simple.cc: New file. * testsuite/lib/gdb-test.exp: New file. * testsuite/libstdc++-pp/pp.exp: New file. Index: testsuite/libstdc++-pp/pp.exp =================================================================== --- testsuite/libstdc++-pp/pp.exp (revision 0) +++ testsuite/libstdc++-pp/pp.exp (revision 0) @@ -0,0 +1,46 @@ +# Copyright (C) 2011 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; see the file COPYING3. If not see +# . + +load_lib gdb-test.exp + +dg-init +v3-build_support + +global GDB +if ![info exists ::env(GUALITY_GDB_NAME)] { + if [info exists GDB] { + set guality_gdb_name "$GDB" + } else { + set guality_gdb_name "[transform gdb]" + } + setenv GUALITY_GDB_NAME "$guality_gdb_name" +} + +# This can be used to keep the .exe around. dg-test has an option for +# this but there is no way to pass it through dg-runtest. +global dg-interpreter-batch-mode +set dg-interpreter-batch-mode 1 + +global DEFAULT_CXXFLAGS +global PCH_CXXFLAGS +dg-runtest [lsort [glob $srcdir/$subdir/*.cc]] \ + "" "$DEFAULT_CXXFLAGS $PCH_CXXFLAGS" + +if [info exists guality_gdb_name] { + unsetenv GUALITY_GDB_NAME +} + +dg-finish Index: testsuite/libstdc++-pp/simple.cc =================================================================== --- testsuite/libstdc++-pp/simple.cc (revision 0) +++ testsuite/libstdc++-pp/simple.cc (revision 0) @@ -0,0 +1,87 @@ +// { dg-do run } +// { dg-options "-g" } + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This library 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 library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include +#include +#include + +template +void +placeholder(const T &s) +{ + std::cout << s; +} + +template +void +placeholder(const std::pair &s) +{ + std::cout << s.first; +} + +template +void +use(const T &container) +{ + for (typename T::const_iterator i = container.begin(); + i != container.end(); + ++i) + placeholder(*i); +} + +int +main() +{ + std::string str = "zardoz"; +// { dg-final { note-test str "\"zardoz\"" } } + + std::bitset<10> bs; + bs[0] = 1; + bs[5] = 1; + bs[7] = 1; +// { dg-final { note-test bs {std::bitset = {[0] = 1, [5] = 1, [7] = 1}} } } + + std::deque deq; + deq.push_back("one"); + deq.push_back("two"); +// { dg-final { note-test deq {std::deque with 2 elements = {"one", "two"}} } } + + std::list lst; + lst.push_back("one"); + lst.push_back("two"); +// { dg-final { note-test lst {std::list = {[0] = "one", [1] = "two"}} } } + + std::map mp; + mp["zardoz"] = 23; +// { dg-final { note-test mp {std::map with 1 elements = {["zardoz"] = 23}} } } + + placeholder(str); // Mark SPOT + std::cout << bs; + use(deq); + use(lst); + use(mp); + + return 0; +} + +// { dg-final { gdb-test SPOT } } Index: testsuite/lib/gdb-test.exp =================================================================== --- testsuite/lib/gdb-test.exp (revision 0) +++ testsuite/lib/gdb-test.exp (revision 0) @@ -0,0 +1,162 @@ +# Copyright (C) 2009, 2011 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 GCC; see the file COPYING3. If not see +# . + +global gdb_tests +set gdb_tests {} + +# Scan a file for markers and fill in the gdb_marker array for that +# file. Any error in this script is simply thrown; errors here are +# programming errors in the test suite itself and should not be +# caught. +proc scan_gdb_markers {filename} { + global gdb_markers + + if {[info exists gdb_markers($filename,-)]} { + return + } + + set fd [open $filename] + set lineno 1 + while {! [eof $fd]} { + set line [gets $fd] + if {[regexp -- "Mark (\[a-zA-Z0-9\]+)" $line ignore marker]} { + set gdb_markers($filename,$marker) $lineno + } + incr lineno + } + close $fd + + set gdb_markers($filename,-) {} +} + +# Find a marker in a source file, and return the marker's line number. +proc get_line_number {filename marker} { + global gdb_markers + + scan_gdb_markers $filename + return $gdb_markers($filename,$marker) +} + +# Make note of a gdb test. A test consists of a variable name and an +# expected result. +proc note-test {var result} { + global gdb_tests + + lappend gdb_tests $var $result +} + +# Utility for testing variable values using gdb, invoked via dg-final. +# Tests all tests indicated by note-test. +# +# Argument 0 is the marker on which to put a breakpoint +# Argument 2 handles expected failures and the like +proc gdb-test { marker {selector {}} } { + if { ![isnative] || [is_remote target] } { return } + + if {[string length $selector] > 0} { + switch [dg-process-target $selector] { + "S" { } + "N" { return } + "F" { setup_xfail "*-*-*" } + "P" { } + } + } + + # This assumes that we are three frames down from dg-test, and that + # it still stores the filename of the testcase in a local variable "name". + # A cleaner solution would require a new DejaGnu release. + upvar 2 name testcase + upvar 2 prog prog + + set line [get_line_number $prog $marker] + + set gdb_name $::env(GUALITY_GDB_NAME) + set testname "$testcase" + set output_file "[file rootname [file tail $prog]].exe" + set cmd_file "[file rootname [file tail $prog]].gdb" + + global srcdir + set pycode [file join $srcdir .. python libstdcxx v6 printers.py] + + global gdb_tests + + set fd [open $cmd_file "w"] + puts $fd "source $pycode" + puts $fd "python register_libstdcxx_printers(None)" + puts $fd "break $line" + puts $fd "run" + + set count 0 + foreach {var result} $gdb_tests { + puts $fd "print $var" + incr count + set gdb_var($count) $var + set gdb_expected($count) $result + } + set gdb_tests {} + + puts $fd "quit" + close $fd + + send_log "Spawning: $gdb_name -nx -nw -quiet -batch -x $cmd_file ./$output_file\n" + set res [remote_spawn target "$gdb_name -nx -nw -quiet -batch -x $cmd_file ./$output_file"] + if { $res < 0 || $res == "" } { + unsupported "$testname" + return + } + + remote_expect target [timeout_value] { + -re {^\$([0-9]+) = ([^\n\r]*)[\n\r]+} { + set num $expect_out(1,string) + set first $expect_out(2,string) + if { ![string compare $first $gdb_expected($num)] } { + pass "$testname print $gdb_var($num)" + } else { + fail "$testname print $gdb_var($num)" + verbose " got =>$first<=" + verbose "expected =>$gdb_expected($num)<=" + } + + if {$num == $count} { + remote_close target + return + } else { + exp_continue + } + } + + -re {Python scripting is not supported in this copy of GDB.[\n\r]+} { + unsupported "$testname" + remote_close target + return + } + + -re {^[^$][^\n\r]*[\n\r]+} { + verbose "skipping: $expect_out(buffer)" + exp_continue + } + + timeout { + unsupported "$testname" + remote_close target + return + } + } + + remote_close target + unsupported "$testname" + return +}