From: Jim Meyering Date: Thu, 16 Aug 2007 17:18:29 +0000 (+0200) Subject: Consolidate od tests. X-Git-Tag: v6.9.89~195 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d2e5e366a1d813e5ce2d03e250eb1ebe44473b63;p=platform%2Fupstream%2Fcoreutils.git Consolidate od tests. * tests/misc/od: Perform od-zero-len's test here. Include boilerplate code, so tests run in a subdirectory. * tests/misc/od-zero-len: Remove this file. --- diff --git a/ChangeLog b/ChangeLog index f9ebff1..3f8128c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2007-08-16 Jim Meyering + Consolidate od tests. + * tests/misc/od: Perform od-zero-len's test here. + Include boilerplate code, so tests run in a subdirectory. + * tests/misc/od-zero-len: Remove this file. + * tests/ls/time-1: Include sample-test boilerplate code. Remove the then-unnecessary, hard-coded envvar "unset" commands. diff --git a/tests/misc/od b/tests/misc/od index aba8474..e5d0c59 100755 --- a/tests/misc/od +++ b/tests/misc/od @@ -20,6 +20,20 @@ : ${PERL=perl} : ${srcdir=.} +pwd=`pwd` +t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ +trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 +trap '(exit $?); exit $?' 1 2 13 15 + +framework_failure=0 +mkdir -p $tmp || framework_failure=1 +cd $tmp || framework_failure=1 + +if test $framework_failure = 1; then + echo "$0: failure in testing framework" 1>&2 + (exit 1); exit 1 +fi + PROG=`echo $0|sed 's,.*/,,'`; export PROG $PERL -e 1 > /dev/null 2>&1 || { @@ -28,7 +42,7 @@ $PERL -e 1 > /dev/null 2>&1 || { exit 77 } -exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF +exec $PERL -w -I$pwd/.. -MCoreutils -- - <<\EOF require 5.003; use strict; @@ -37,6 +51,23 @@ use strict; # Turn off localisation of executable's ouput. @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; +# Use a file in /proc whose size is not likely to +# change between the wc and od invocations. +my $proc_file = '/proc/version'; +-f $proc_file + or $proc_file = '/dev/null'; + +# Count the bytes in $proc_file, _by reading_. +my $len = 0; +open FH, '<', $proc_file + or die "$program_name: can't open `$proc_file' for reading: $!\n"; +while (defined (my $line = )) + { + $len += length $line; + } +close FH; +my $proc_file_byte_count = $len; + my @Tests = ( # Skip the exact length of the input file. @@ -49,6 +80,11 @@ my @Tests = # Skip the sum of the lengths of the first three inputs, printing the 4th. ['j-bug4', '-c -j 3 -An', {IN=>{g=>'a'}}, {IN=>{h=>'b'}}, {IN=>{i=>'c'}}, {IN=>{j=>'d'}}, {OUT=>" d\n"}], + + # Ensure that od -j doesn't fseek across a nonempty file in /proc, + # even if the kernel reports that the file has stat.st_size = 0. + ['j-proc', "-An -c -j $proc_file_byte_count $proc_file", + {IN=>{f2=>'e'}}, {OUT=>" e\n"}], ); my $save_temps = $ENV{DEBUG}; diff --git a/tests/misc/od-zero-len b/tests/misc/od-zero-len deleted file mode 100755 index 42008ce..0000000 --- a/tests/misc/od-zero-len +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh -# ensure that od -j doesn't improperly fseek across a nonempty file in /proc - -# Copyright (C) 2007 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 . - -if test "$VERBOSE" = yes; then - set -x - od --version -fi - -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -printf e > f2 || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi - -# Use a file in /proc whose size is not likely to -# change between the wc and od invocations. -f=/proc/version -test -r $f || f=empty - -fail=0 - -n=`wc -c < $f` || fail=1 -od -An -c -j $n $f f2 > out || fail=1 -echo ' e' > exp || fail=1 - -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null - -(exit $fail); exit $fail