From patchwork Wed Oct 6 01:43:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 66886 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 5747AB70A5 for ; Wed, 6 Oct 2010 12:43:18 +1100 (EST) Received: (qmail 15345 invoked by alias); 6 Oct 2010 01:43:16 -0000 Received: (qmail 15327 invoked by uid 22791); 6 Oct 2010 01:43:14 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, TW_SV, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from ra.se.axis.com (HELO ra.se.axis.com) (195.60.68.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 Oct 2010 01:43:09 +0000 Received: from localhost (localhost [127.0.0.1]) by ra.se.axis.com (Postfix) with ESMTP id 07D4511ECA; Wed, 6 Oct 2010 03:43:06 +0200 (CEST) Received: from ra.se.axis.com ([127.0.0.1]) by localhost (ra.se.axis.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id XslYcv4PYCgZ; Wed, 6 Oct 2010 03:43:04 +0200 (CEST) Received: from miranda.se.axis.com (miranda.se.axis.com [10.0.2.171]) by ra.se.axis.com (Postfix) with ESMTPS id 51B9C11EC9; Wed, 6 Oct 2010 03:43:04 +0200 (CEST) Received: from ignucius.se.axis.com (ignucius.se.axis.com [10.88.21.50]) by miranda.se.axis.com (8.13.4/8.13.4/Debian-3sarge3) with ESMTP id o961h5Rk001331; Wed, 6 Oct 2010 03:43:05 +0200 Received: from ignucius.se.axis.com (localhost [127.0.0.1]) by ignucius.se.axis.com (8.12.8p1/8.12.8/Debian-2woody1) with ESMTP id o961h3F6032151; Wed, 6 Oct 2010 03:43:03 +0200 Received: (from hp@localhost) by ignucius.se.axis.com (8.12.8p1/8.12.8/Debian-2woody1) id o961h3bi032147; Wed, 6 Oct 2010 03:43:03 +0200 Date: Wed, 6 Oct 2010 03:43:03 +0200 Message-Id: <201010060143.o961h3bi032147@ignucius.se.axis.com> From: Hans-Peter Nilsson To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [RFA:] Stricter libstdc++ testsuite gate for working target file I/O 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 First but incidentally, we never did any useful target file I/O in the the check_v3_target_fileio gate, we just tried to open "." and seek to 0 (a nop at best; could also be construed as invalid). The test-suite does actual file I/O gated by that '// { dg-require-fileio "" }' line: reading, writing, seeking, so I think the gate function should try that, using the same machinery as the actual tests. Several tests require a working lseek primitive. I think it's easy enough to get seeking with a negative offset wrong in a simulator(*) that it's worth testing for that. Also, the generic framework for the lseek syscall in the GNU simulators at src/sim has a bug causing an invalid seek, like backwards from position 0, to return 0 instead of properly yielding an error. (I have patches for those simulator bugs, upcoming on gdb-patches@, and I'll delay committing this patch until those patches are applied.) ((*) where the API to the host uses "long" for syscall parameters like src/sim struct cb_syscall, and the target is ILP32 like cris-*-*, and if you handle your targets addresses as zero-extended (as most targets except MIPS and SH/SH64, IIUC) so you handle syscall parameters generally using unsigned 32-bit numbers and you don't special-case the lseek position parameter to properly get it sign-extended rather than zero-extended when on a LP64 host...) Here's a patch fixing the check_v3_target_fileio gate function. I can't think of a system that this fixup would *incorrectly* flag as not working. It catches both the mentioned simulator bugs (thus avoiding spurious failures leading to bogus bug reports wasting maintainer time :) but passes for a fixed (cris-elf) simulator and natively on a x86_64-unknown-linux-gnu (manually testing the code). Also, as a sanity check, ran a complete regtest for cris-elf (fixed simulator) at r164529 with no regressions. While working on this I noticed that several tests miss the // { dg-require-fileio "" } line, which I'll add as obvious, later. The bugs at this PR didn't stop there (with this one in the test-suite, two simulator bugs and actually also one in libstdc++ proper ironically found by the buggy simulator; a patch has already been posted to add a properly "working" testcase IIUC). I also ran into which manifested as "svn diff -c164529" not showing 27_io/basic_filebuf/sync/wchar_t/1.cc as a deleted file, as it dies for 27_io/basic_filebuf/sync/char/1.cc. So be warned: don't ultimately trust applying patches from svn diff -rOLD:NEW as a way of patching up your tree; beware of deleted directories. At least with subversion lower than 1.7.0 (to wit, 1.6.9). Ok to commit? Would it be ok to backport to open branches? PR libstdc++/45841 * testsuite/lib/libstdc++.exp (check_v3_target_fileio): Rewrite to use an actual testsuite file and machinery, not ".". Specifically check that incorrectly seeking backwards from 0 yields an error, and that reading, seeking backwards and reading again works. brgds, H-P --- libstdc++-v3/testsuite/lib/libstdc++.exp.orig Wed Sep 15 23:27:44 2010 +++ libstdc++-v3/testsuite/lib/libstdc++.exp Wed Oct 6 00:01:46 2010 @@ -631,6 +631,7 @@ proc check_v3_target_fileio { } { global et_fileio_saved global et_fileio_target_name global tool + global srcdir if { ![info exists et_fileio_target_name] } { set et_fileio_target_name "" @@ -656,6 +657,8 @@ proc check_v3_target_fileio { } { # the file functions set src fileio[pid].cc set exe fileio[pid].x + set testfile "cin_unget-1.txt" + v3-copy-files "$srcdir/data/$testfile" set f [open $src "w"] puts $f "#include " @@ -663,20 +666,26 @@ proc check_v3_target_fileio { } { puts $f "#include " puts $f "#include " puts $f "#include " + puts $f "#include " puts $f "using namespace std;" puts $f "int main ()" puts $f "{" - puts $f " int fd = open (\".\", O_RDONLY);" + puts $f " int fd = open (\"$testfile\", O_RDONLY);" puts $f " int ret = 0;" + puts $f " char buf\[10\];" puts $f " if (fd == -1)" - puts $f " {" - puts $f " int err = errno;" - puts $f " if (err == EIO || err == ENOSYS)" - puts $f " ret = 1;" - puts $f " }" + puts $f " ret = 1;" puts $f " else" puts $f " {" - puts $f " if (lseek (fd, 0, SEEK_CUR) == -1)" + puts $f " if (lseek (fd, -1, SEEK_CUR) != -1 || errno != EINVAL)" + puts $f " ret = 1;" + puts $f " errno = 0;" + puts $f " if (lseek (fd, 0, SEEK_CUR) != 0" + puts $f " || read (fd, buf, 4) != 4" + puts $f " || memcmp (buf, \"1234\", 4) != 0" + puts $f " || lseek (fd, -2, SEEK_CUR) != 2" + puts $f " || read (fd, buf, 2) != 2" + puts $f " || memcmp (buf, \"34\", 2) != 0)" puts $f " ret = 1;" puts $f " close (fd);" puts $f " }"