diff options
Diffstat (limited to 'tests/misc')
202 files changed, 19152 insertions, 0 deletions
diff --git a/tests/misc/arch.sh b/tests/misc/arch.sh new file mode 100755 index 0000000..c50b324 --- /dev/null +++ b/tests/misc/arch.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Ensure that arch output is equal to uname -m + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ arch + +arch > out || fail=1 +uname -m > exp || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/b2sum.sh b/tests/misc/b2sum.sh new file mode 100755 index 0000000..3089702 --- /dev/null +++ b/tests/misc/b2sum.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# 'b2sum' tests + +# Copyright (C) 2016-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cksum + +for prog in 'b2sum' 'cksum -a blake2b'; do +# Also check b2sum if built +[ "$prog" = 'b2sum' ] && { $prog --version || continue; } + +# Ensure we can --check the --tag format we produce +rm -f check.b2sum || framework_failure_ +[ "$prog" = 'b2sum' ] && tag_opt='--tag' || tag_opt='' +for i in 'a' ' b' '*c' '44' ' '; do + echo "$i" > "$i" + for l in 0 128; do + $prog -l $l $tag_opt "$i" >> check.b2sum + done +done +# Note -l is inferred from the tags in the mixed format file +$prog --strict -c check.b2sum || fail=1 +# Also ensure the openssl tagged variant works +sed 's/ //; s/ =/=/' < check.b2sum > openssl.b2sum || framework_failure_ +$prog --strict -c openssl.b2sum || fail=1 + +rm -f check.vals || framework_failure_ +# Ensure we can check non tagged format +[ "$prog" != 'b2sum' ] && tag_opt='--untagged' || tag_opt='' +[ "$prog" == 'b2sum' ] && text_opt='--text' || text_opt='' +for l in 0 128; do + $prog $tag_opt $text_opt -l $l /dev/null | tee -a check.vals > check.b2sum + $prog -l $l --strict -c check.b2sum || fail=1 + $prog --strict -c check.b2sum || fail=1 +done + +# Ensure the checksum values are correct. The reference +# check.vals was created with the upstream SSE reference implementation. +[ "$prog" != 'b2sum' ] && tag_opt='--untagged' || tag_opt='' +$prog $tag_opt --length=128 check.vals > out.tmp || fail=1 +tr '*' ' ' < out.tmp > out || framework_failure_ # Remove binary tag on cygwin +printf '%s\n' '796485dd32fe9b754ea5fd6c721271d9 check.vals' > exp +compare exp out || fail=1 + +# This would segfault from coreutils-8.26 to coreutils-8.28 +printf '%s\n' 'BLAKE2' 'BLAKE2b' 'BLAKE2-' 'BLAKE2(' 'BLAKE2 (' > crash.check \ + || framework_failure_ +returns_ 1 $prog -c crash.check || fail=1 + +done + +Exit $fail diff --git a/tests/misc/base64.pl b/tests/misc/base64.pl new file mode 100755 index 0000000..955ce32 --- /dev/null +++ b/tests/misc/base64.pl @@ -0,0 +1,214 @@ +#!/usr/bin/perl +# Exercise base{32,64}. + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# Return the encoding of a string of N 'a's. +sub enc64($) +{ + my ($n) = @_; + my %remainder = ( 0 => '', 1 => 'YQ==', 2 => 'YWE=' ); + return 'YWFh' x ($n / 3) . $remainder{$n % 3}; +} + +sub enc32($) +{ + my ($n) = @_; + my %remainder = ( 0 => '', 1 => 'ME======', 2 => 'MFQQ====', + 3 => 'MFQWC===', 4 => 'MFQWCYI='); + return 'MFQWCYLB' x ($n / 5) . $remainder{$n % 5}; +} + +# Function reference to appropriate encoder +my $enc; + +# An encoded string of length 4KB, using 3K "a"s. +my $a3k; +my @a3k_nl; + +# Return a copy of S, with newlines inserted every WIDTH bytes. +# Ensure that the result (if not the empty string) is newline-terminated. +sub wrap($$) +{ + my ($s, $width) = @_; + $s =~ s/(.{$width})/$1\n/g; + substr ($s, -1, 1) ne "\n" + and $s .= "\n"; + return $s; +} + +my @Tests; + +sub gen_tests($) +{ + my ($prog) = @_; + my $try_help = "Try '$prog --help' for more information.\n"; + @Tests= + ( + ['empty', {IN=>''}, {OUT=>""}], + ['inout1', {IN=>'a'x1}, {OUT=>&$enc(1)."\n"}], + ['inout2', {IN=>'a'x2}, {OUT=>&$enc(2)."\n"}], + ['inout3', {IN=>'a'x3}, {OUT=>&$enc(3)."\n"}], + ['inout4', {IN=>'a'x4}, {OUT=>&$enc(4)."\n"}], + ['inout5', {IN=>'a'x5}, {OUT=>&$enc(5)."\n"}], + ['wrap', '--wrap 0', {IN=>'a'}, {OUT=>&$enc(1)}], + ['wrap-zero', '--wrap 08', {IN=>'a'}, {OUT=>&$enc(1)."\n"}], + ['wrap5-39', '--wrap=5', {IN=>'a' x 39}, {OUT=>wrap &$enc(39),5}], + ['wrap5-40', '--wrap=5', {IN=>'a' x 40}, {OUT=>wrap &$enc(40),5}], + ['wrap5-41', '--wrap=5', {IN=>'a' x 41}, {OUT=>wrap &$enc(41),5}], + ['wrap5-42', '--wrap=5', {IN=>'a' x 42}, {OUT=>wrap &$enc(42),5}], + ['wrap5-43', '--wrap=5', {IN=>'a' x 43}, {OUT=>wrap &$enc(43),5}], + ['wrap5-44', '--wrap=5', {IN=>'a' x 44}, {OUT=>wrap &$enc(44),5}], + ['wrap5-45', '--wrap=5', {IN=>'a' x 45}, {OUT=>wrap &$enc(45),5}], + ['wrap5-46', '--wrap=5', {IN=>'a' x 46}, {OUT=>wrap &$enc(46),5}], + + ['wrap-bad-1', '-w0x0', {IN=>''}, {OUT=>""}, + {ERR_SUBST => 's/base..:/base..:/'}, + {ERR => "base..: invalid wrap size: '0x0'\n"}, {EXIT => 1}], + ['wrap-bad-2', '-w1k', {IN=>''}, {OUT=>""}, + {ERR_SUBST => 's/base..:/base..:/'}, + {ERR => "base..: invalid wrap size: '1k'\n"}, {EXIT => 1}], + ['wrap-bad-3', '-w-1', {IN=>''}, {OUT=>""}, + {ERR_SUBST => 's/base..:/base..:/'}, + {ERR => "base..: invalid wrap size: '-1'\n"}, {EXIT => 1}], + + ['buf-1', '--decode', {IN=>&$enc(1)}, {OUT=>'a' x 1}], + ['buf-2', '--decode', {IN=>&$enc(2)}, {OUT=>'a' x 2}], + ['buf-3', '--decode', {IN=>&$enc(3)}, {OUT=>'a' x 3}], + ['buf-4', '--decode', {IN=>&$enc(4)}, {OUT=>'a' x 4}], + # 4KB worth of input. + ['buf-4k0', '--decode', {IN=>&$enc(3072+0)}, {OUT=>'a' x (3072+0)}], + ['buf-4k1', '--decode', {IN=>&$enc(3072+1)}, {OUT=>'a' x (3072+1)}], + ['buf-4k2', '--decode', {IN=>&$enc(3072+2)}, {OUT=>'a' x (3072+2)}], + ['buf-4k3', '--decode', {IN=>&$enc(3072+3)}, {OUT=>'a' x (3072+3)}], + ['buf-4km1','--decode', {IN=>&$enc(3072-1)}, {OUT=>'a' x (3072-1)}], + ['buf-4km2','--decode', {IN=>&$enc(3072-2)}, {OUT=>'a' x (3072-2)}], + ['buf-4km3','--decode', {IN=>&$enc(3072-3)}, {OUT=>'a' x (3072-3)}], + ['buf-4km4','--decode', {IN=>&$enc(3072-4)}, {OUT=>'a' x (3072-4)}], + + # Exercise the case in which the final base-64 byte is + # in a buffer all by itself. + ['b4k-1', '--decode', {IN=>$a3k_nl[1]}, {OUT=>'a' x (3072+0)}], + ['b4k-2', '--decode', {IN=>$a3k_nl[2]}, {OUT=>'a' x (3072+0)}], + ['b4k-3', '--decode', {IN=>$a3k_nl[3]}, {OUT=>'a' x (3072+0)}], + + ['ext-op1', 'a b', {IN=>''}, {EXIT=>1}, + {ERR => "$prog: extra operand 'b'\n" . $try_help}], + # Again, with more option arguments + ['ext-op2', '-di --wrap=40 a b', {IN=>''}, {EXIT=>1}, + {ERR => "$prog: extra operand 'b'\n" . $try_help}], + ); + + if ($prog eq "base64") + { + push @Tests, ( + ['baddecode', '--decode', {IN=>'a'}, {OUT=>""}, + {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}], + ['baddecode2', '--decode', {IN=>'ab'}, {OUT=>"i"}, + {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}], + ['baddecode3', '--decode', {IN=>'Zzz'}, {OUT=>"g<"}, + {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}], + ['baddecode4', '--decode', {IN=>'Zz='}, {OUT=>"g"}, + {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}], + ['baddecode5', '--decode', {IN=>'Z==='}, {OUT=>""}, + {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}] + ); + } + + # For each non-failing test, create a --decode test using the + # expected output as input. Also, add tests inserting newlines. + my @new; + foreach my $t (@Tests) + { + my $exit_val; + my $in; + my @out; + + # If the test has a single option of "--decode", then skip it. + !ref $t->[1] && $t->[1] eq '--decode' + and next; + + foreach my $e (@$t) + { + ref $e && ref $e eq 'HASH' + or next; + defined $e->{EXIT} + and $exit_val = $e->{EXIT}; + defined $e->{IN} + and $in = $e->{IN}; + if (defined $e->{OUT}) + { + my $t = $e->{OUT}; + push @out, $t; + my $len = length $t; + foreach my $i (0..$len) + { + my $u = $t; + substr ($u, $i, 0) = "\n"; + push @out, $u; + 10 <= $i + and last; + } + } + } + $exit_val + and next; + + my $i = 0; + foreach my $o (@out) + { + push @new, ["d$i-$t->[0]", '--decode', {IN => $o}, {OUT => $in}]; + ++$i; + } + } + push @Tests, @new; +} + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = 0; +foreach my $prog (qw(base32 base64)) + { + $enc = $prog eq "base32" ? \&enc32 : \&enc64; + + # Construct an encoded string of length 4KB, using 3K "a"s. + $a3k = &$enc(3072); + @a3k_nl = (); + # A few copies, each with different number of newlines at the start. + for my $k (0..3) + { + (my $t = $a3k) =~ s/^/"\n"x $k/e; + push @a3k_nl, $t; + } + + gen_tests($prog); + + $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); + if ($fail != 0) + { + last; + } + } + +exit $fail; diff --git a/tests/misc/basename.pl b/tests/misc/basename.pl new file mode 100755 index 0000000..4be4949 --- /dev/null +++ b/tests/misc/basename.pl @@ -0,0 +1,92 @@ +#!/usr/bin/perl +# Test basename. +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +use strict; +use File::stat; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $stat_single = stat('/'); +my $stat_double = stat('//'); +my $double_slash = ($stat_single->dev == $stat_double->dev + && $stat_single->ino == $stat_double->ino) ? '/' : '//'; + +my $prog = 'basename'; + +my @Tests = + ( + ['fail-1', {ERR => "$prog: missing operand\n" + . "Try '$prog --help' for more information.\n"}, {EXIT => '1'}], + ['fail-2', qw(a b c), {ERR => "$prog: extra operand 'c'\n" + . "Try '$prog --help' for more information.\n"}, {EXIT => '1'}], + + ['a', qw(d/f), {OUT => 'f'}], + ['b', qw(/d/f), {OUT => 'f'}], + ['c', qw(d/f/), {OUT => 'f'}], + ['d', qw(d/f//), {OUT => 'f'}], + ['e', qw(f), {OUT => 'f'}], + ['f', qw(/), {OUT => '/'}], + ['g', qw(//), {OUT => "$double_slash"}], + ['h', qw(///), {OUT => '/'}], + ['i', qw(///a///), {OUT => 'a'}], + ['j', qw(''), {OUT => ''}], + ['k', qw(aa a), {OUT => 'a'}], + ['l', qw(-a a b), {OUT => "a\nb"}], + ['m', qw(-s a aa ba ab), {OUT => "a\nb\nab"}], + ['n', qw(a-a -a), {OUT => 'a'}], + ['1', qw(f.s .s), {OUT => 'f'}], + ['2', qw(fs s), {OUT => 'f'}], + ['3', qw(fs fs), {OUT => 'fs'}], + ['4', qw(fs/ s), {OUT => 'f'}], + ['5', qw(dir/file.suf .suf), {OUT => 'file'}], + ['6', qw(// /), {OUT => "$double_slash"}], + ['7', qw(// //), {OUT => "$double_slash"}], + ['8', qw(fs x), {OUT => 'fs'}], + ['9', qw(fs ''), {OUT => 'fs'}], + ['10', qw(fs/ s/), {OUT => 'fs'}], + + # Exercise -z option. + ['z0', qw(-z a), {OUT => "a\0"}], + ['z1', qw(--zero a), {OUT => "a\0"}], + ['z2', qw(-za a b), {OUT => "a\0b\0"}], + ['z3', qw(-z ba a), {OUT => "b\0"}], + ['z4', qw(-z -s a ba), {OUT => "b\0"}], + ); + +# Append a newline to end of each expected 'OUT' string. +# Skip -z tests, i.e., those whose 'OUT' string has a trailing '\0'. +my $t; +foreach $t (@Tests) + { + my $arg1 = $t->[1]; + my $e; + foreach $e (@$t) + { + $e->{OUT} = "$e->{OUT}\n" + if ref $e eq 'HASH' and exists $e->{OUT} + and not $e->{OUT} =~ /\0$/; + } + } + +my $save_temps = $ENV{SAVE_TEMPS}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/basenc.pl b/tests/misc/basenc.pl new file mode 100755 index 0000000..d324d18 --- /dev/null +++ b/tests/misc/basenc.pl @@ -0,0 +1,292 @@ +#!/usr/bin/perl +# Exercise basenc. + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +# This test exercises the various encoding (other than base64/32). +# It also does not test the general options (e.g. --wrap), as that code is +# shared and tested in base64. + +use strict; + +(my $program_name = $0) =~ s|.*/||; +my $prog = 'basenc'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + + +my $base64_in = "\x54\x0f\xdc\xf0\x0f\xaf\x4a"; +my $base64_out = "VA/c8A+vSg=="; +my $base64url_out = $base64_out; +$base64url_out =~ y|+/|-_|; +my $base64url_out_nl = $base64url_out; +$base64url_out_nl =~ s/(..)/\1\n/g; # add newline every two characters + + +# Bug 49741: +# The input is 'abc' in base64, in an 8K buffer (larger than 1024*5, +# the buffer size which caused the bug). +my $base64_bug49741_in = "YWJj" x 2000 ; +my $base64_bug49741_out = "abc" x 2000 ; + + +my $base32_in = "\xfd\xd8\x07\xd1\xa5"; +my $base32_out = "7XMAPUNF"; +my $x = $base32_out; +$x =~ y|ABCDEFGHIJKLMNOPQRSTUVWXYZ234567|0123456789ABCDEFGHIJKLMNOPQRSTUV|; +my $base32hex_out = $x; + +# base32 with padding and newline +my $base32_in2 = "\xFF\x00"; +my $base32_out2 = "74AA===="; +$x = $base32_out2; +$x =~ y|ABCDEFGHIJKLMNOPQRSTUVWXYZ234567|0123456789ABCDEFGHIJKLMNOPQRSTUV|; +my $base32hex_out2 = $x; +my $base32hex_out2_nl = $x; +$base32hex_out2_nl =~ s/(...)/\1\n/g; # Add newline every 3 characters + +my $base16_in = "\xfd\xd8\x07\xd1\xa5"; +my $base16_out = "FDD807D1A5"; + +my $z85_in = "\x86\x4F\xD2\x6F\xB5\x59\xF7\x5B"; +my $z85_out = 'HelloWorld'; + +my $base2lsbf_ab = "1000011001000110"; +my $base2lsbf_ab_nl = $base2lsbf_ab; +$base2lsbf_ab_nl =~ s/(...)/\1\n/g; # Add newline every 3 characters +my $base2msbf_ab = "0110000101100010"; +my $base2msbf_ab_nl = $base2msbf_ab; +$base2msbf_ab_nl =~ s/(...)/\1\n/g; # Add newline every 3 characters + +my $try_help = "Try '$prog --help' for more information.\n"; + +my @Tests = +( + # These are mainly for higher coverage + ['help', '--help', {IN=>''}, {OUT=>""}, {OUT_SUBST=>'s/.*//sm'}], + + # Typical message is " unrecognized option '--foobar'", but on + # Open/NetBSD it is " unknown option -- foobar". + ['error', '--foobar', {IN=>''}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: foobar\n" . $try_help }, + {ERR_SUBST=>"s/(unrecognized|unknown) option [-' ]*foobar[' ]*/foobar/"}], + + ['noenc', '', {IN=>''}, {EXIT=>1}, + {ERR=>"$prog: missing encoding type\n" . $try_help }], + + ['extra', '--base64 A B', {IN=>''}, {EXIT=>1}, + {ERR=>"$prog: extra operand 'B'\n" . $try_help}], + + + ['empty1', '--base64', {IN=>''}, {OUT=>""}], + ['empty2', '--base64url', {IN=>''}, {OUT=>""}], + ['empty3', '--base32', {IN=>''}, {OUT=>""}], + ['empty4', '--base32hex', {IN=>''}, {OUT=>""}], + ['empty5', '--base16', {IN=>''}, {OUT=>""}], + ['empty6', '--base2msbf', {IN=>''}, {OUT=>""}], + ['empty7', '--base2lsbf', {IN=>''}, {OUT=>""}], + ['empty8', '--z85', {IN=>''}, {OUT=>""}], + + + + + ['b64_1', '--base64', {IN=>$base64_in}, {OUT=>$base64_out}], + ['b64_2', '--base64 -d', {IN=>$base64_out}, {OUT=>$base64_in}], + ['b64_3', '--base64 -d -i', {IN=>'&'.$base64_out},{OUT=>$base64_in}], + + ['b64u_1', '--base64url', {IN=>$base64_in}, {OUT=>$base64url_out}], + ['b64u_2', '--base64url -d', {IN=>$base64url_out}, {OUT=>$base64_in}], + ['b64u_3', '--base64url -di', {IN=>'&'.$base64url_out} , {OUT=>$base64_in}], + ['b64u_4', '--base64url -di', {IN=>'/'.$base64url_out.'+'},{OUT=>$base64_in}], + ['b64u_5', '--base64url -d', {IN=>$base64url_out_nl}, {OUT=>$base64_in}], + ['b64u_6', '--base64url -di', {IN=>$base64url_out_nl}, {OUT=>$base64_in}], + # ensure base64url fails to decode base64 input with "+" and "/" + ['b64u_7', '--base64url -d', {IN=>$base64_out}, + {EXIT=>1}, {ERR=>"$prog: invalid input\n"}], + + ['b64_bug49741', '--base64 -d', {IN=>$base64_bug49741_in}, + {OUT=>$base64_bug49741_out}], + + + + ['b32_1', '--base32', {IN=>$base32_in}, {OUT=>$base32_out}], + ['b32_2', '--base32 -d', {IN=>$base32_out}, {OUT=>$base32_in}], + ['b32_3', '--base32 -d -i', {IN=>'&'.$base32_out},{OUT=>$base32_in}], + ['b32_4', '--base32', {IN=>$base32_in2}, {OUT=>$base32_out2}], + ['b32_5', '--base32 -d', {IN=>$base32_out2}, {OUT=>$base32_in2}], + ['b32_6', '--base32 -d -i', {IN=>$base32_out2}, {OUT=>$base32_in2}], + + + + ['b32h_1', '--base32hex', {IN=>$base32_in}, {OUT=>$base32hex_out}], + ['b32h_2', '--base32hex -d', {IN=>$base32hex_out}, {OUT=>$base32_in}], + ['b32h_3', '--base32hex -d -i', {IN=>'/'.$base32hex_out}, {OUT=>$base32_in}], + ['b32h_4', '--base32hex -d -i', {IN=>'W'.$base32hex_out}, {OUT=>$base32_in}], + ['b32h_5', '--base32hex -d', {IN=>$base32hex_out.'W'}, , {OUT=>$base32_in}, + {EXIT=>1}, {ERR=>"$prog: invalid input\n"}], + ['b32h_6', '--base32hex -d', {IN=>$base32hex_out.'/'}, {OUT=>$base32_in}, + {EXIT=>1}, {ERR=>"$prog: invalid input\n"}], + ['b32h_7', '--base32hex', {IN=>$base32_in2}, {OUT=>$base32hex_out2}], + ['b32h_8', '--base32hex -d', {IN=>$base32hex_out2}, {OUT=>$base32_in2}], + ['b32h_9', '--base32hex -di', {IN=>$base32hex_out2}, {OUT=>$base32_in2}], + ['b32h_10', '--base32hex -d', {IN=>$base32hex_out2_nl}, {OUT=>$base32_in2}], + ['b32h_11', '--base32hex -di', {IN=>$base32hex_out2_nl}, {OUT=>$base32_in2}], + + + + ['b16_1', '--base16', {IN=>$base16_in}, {OUT=>$base16_out}], + ['b16_2', '--base16 -d', {IN=>$base16_out}, {OUT=>$base16_in}], + ['b16_3', '--base16 -d -i', {IN=>'&'. $base16_out}, {OUT=>$base16_in}], + ['b16_4', '--base16 -d -i', {IN=>$base16_out.'G'}, {OUT=>$base16_in}], + ['b16_5', '--base16 -d', {IN=>'.'}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b16_6', '--base16 -d', {IN=>'='}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b16_7', '--base16 -d', {IN=>'G'}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b16_8', '--base16 -d', {IN=>"AB\nCD"}, {OUT=>"\xAB\xCD"}], + + + + ['b2m_1', '--base2m', {IN=>"\xC1"}, {OUT=>"11000001"}], + ['b2m_2', '--base2m -d', {IN=>'11000001'}, {OUT=>"\xC1"}], + ['b2m_3', '--base2m -d', {IN=>"110\n00001"}, {OUT=>"\xC1"}], + ['b2m_4', '--base2m -di', {IN=>"110x00001"}, {OUT=>"\xC1"}], + ['b2m_5', '--base2m -d', {IN=>"110x00001"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b2m_6', '--base2m -d', {IN=>"11000001x"}, {OUT=>"\xC1"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b2m_7', '--base2m -d', {IN=>"1"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b2m_8', '--base2m -d', {IN=>"1000100"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b2m_9', '--base2m -d', {IN=>"100010000000000"}, {OUT=>"\x88"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b2m_10','--base2m', {IN=>"ab"}, {OUT=>$base2msbf_ab}], + ['b2m_11','--base2m -d', {IN=>$base2msbf_ab}, {OUT=>"ab"}], + ['b2m_12','--base2m -d', {IN=>$base2msbf_ab_nl}, {OUT=>"ab"}], + + + ['b2l_1', '--base2l', {IN=>"\x83"}, {OUT=>"11000001"}], + ['b2l_2', '--base2l -d', {IN=>'11000001'}, {OUT=>"\x83"}], + ['b2l_3', '--base2l -d', {IN=>"110\n00001"}, {OUT=>"\x83"}], + ['b2l_4', '--base2l -di', {IN=>"110x00001"}, {OUT=>"\x83"}], + ['b2l_5', '--base2l -d', {IN=>"110x00001"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b2l_6', '--base2l -d', {IN=>"11000001x"}, {OUT=>"\x83"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b2l_7', '--base2l -d', {IN=>"1"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b2l_8', '--base2l -d', {IN=>"1000100"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b2l_9', '--base2l -d', {IN=>"100010000000000"}, {OUT=>"\x11"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['b2l_10','--base2l', {IN=>"ab"}, {OUT=>$base2lsbf_ab}], + ['b2l_11','--base2l -d', {IN=>$base2lsbf_ab}, {OUT=>"ab"}], + ['b2l_12','--base2l -d', {IN=>$base2lsbf_ab_nl}, {OUT=>"ab"}], + + + + + + ['z85_1', '--z85', {IN=>$z85_in}, {OUT=>$z85_out}], + ['z85_2', '--z85 -d', {IN=>$z85_out}, {OUT=>$z85_in}], + ['z85_3', '--z85 -d -i', {IN=>'~'. $z85_out}, {OUT=>$z85_in}], + ['z85_4', '--z85 -d -i', {IN=>' '. $z85_out}, {OUT=>$z85_in}], + ['z85_5', '--z85 -d', {IN=>'%j$qP'}, {OUT=>"\xFF\xDD\xBB\x99"}], + ['z85_6', '--z85 -d -i', {IN=>'%j~$qP'}, {OUT=>"\xFF\xDD\xBB\x99"}], + + # z85 encoding require input to be multiple of 5 octets + ['z85_7', '--z85 -d', {IN=>'hello'}, {OUT=>"5jXu"}], + ['z85_8', '--z85 -d', {IN=>'helloX'}, {OUT=>"5jXu"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['z85_9', '--z85 -d', {IN=>"he\nl\nlo"}, {OUT=>"5jXu"}], + + # Invalid input characters (space ~ ") + ['z85_10', '--z85 -d', {IN=>' j$qP'}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['z85_11', '--z85 -d', {IN=>'%j$q~'}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['z85_12', '--z85 -d', {IN=>'%j$"P'}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + + # Invalid length (binary input must be a multiple of 4 octets, + # z85-encoded input must be a multiple of 5 octets) + ['z85_20', '--z85', {IN=>'A'}, {EXIT=>1}, + {ERR=>"$prog: invalid input (length must be multiple of 4 characters)\n"}], + ['z85_21', '--z85', {IN=>'AB'}, {EXIT=>1}, + {ERR=>"$prog: invalid input (length must be multiple of 4 characters)\n"}], + ['z85_22', '--z85', {IN=>'ABC'}, {EXIT=>1}, + {ERR=>"$prog: invalid input (length must be multiple of 4 characters)\n"}], + ['z85_23', '--z85', {IN=>'ABCD'}, {OUT=>'k%^}b'}], + ['z85_24', '--z85', {IN=>'ABCDE'}, {EXIT=>1}, + {ERR=>"$prog: invalid input (length must be multiple of 4 characters)\n"}], + + ['z85_30', '--z85 -d', {IN=>'A'}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['z85_31', '--z85 -d', {IN=>'AB'}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['z85_32', '--z85 -d', {IN=>'ABC'}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['z85_33', '--z85 -d', {IN=>'ABCD'}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['z85_34', '--z85 -d', {IN=>'ABCDE'}, {OUT=>"\x71\x61\x9e\xb6"}], + ['z85_35', '--z85 -d', {IN=>'ABCDEF'},{OUT=>"\x71\x61\x9e\xb6"}, + {EXIT=>1}, {ERR=>"$prog: invalid input\n"}], + + # largest possible value + ['z85_40', '--z85', {IN=>"\xFF\xFF\xFF\xFF"},{OUT=>"%nSc0"}], + ['z85_41', '--z85 -d', {IN=>"%nSc0"}, {OUT=>"\xFF\xFF\xFF\xFF"}], + # Invalid encoded data - will decode to more than 0xFFFFFFFF + ['z85_42', '--z85 -d', {IN=>"%nSc1"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['z85_43', '--z85 -d', {IN=>"%nSd0"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['z85_44', '--z85 -d', {IN=>"%nTc0"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['z85_45', '--z85 -d', {IN=>"%oSc0"}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['z85_46', '--z85 -d', {IN=>'$nSc0'}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], + ['z85_47', '--z85 -d', {IN=>'#0000'}, {EXIT=>1}, + {ERR=>"$prog: invalid input\n"}], +); + +# Prepend the command line argument and append a newline to end +# of each expected 'OUT' string. +my $t; + +Test: +foreach $t (@Tests) + { + foreach my $e (@$t) + { + ref $e && ref $e eq 'HASH' && defined $e->{OUT_SUBST} + and next Test; + } + + push @$t, {OUT_SUBST=>'s/\n$//s'}; + } + + + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); + +exit $fail; diff --git a/tests/misc/cat-E.sh b/tests/misc/cat-E.sh new file mode 100755 index 0000000..46d52bc --- /dev/null +++ b/tests/misc/cat-E.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# Copyright (C) 2021-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cat + +# \r followed by \n is displayed as ^M$ +# Up to and including 8.32 the $ would have displayed at the start of the line +# overwriting the first character +printf 'a\rb\r\nc\n\r\nd\r' > 'in' || framework_failure_ +printf 'a\rb^M$\nc$\n^M$\nd\r' > 'exp' || framework_failure_ +cat -E 'in' > out || fail=1 +compare exp out || fail=1 + +# Ensure \r\n spanning files (or buffers) is handled +printf '1\r' > in2 || framework_failure_ +printf '\n2\r\n' > in2b || framework_failure_ +printf '1^M$\n2^M$\n' > 'exp' || framework_failure_ +cat -E 'in2' 'in2b' > out || fail=1 +compare exp out || fail=1 + +# Ensure \r at end of buffer is handled +printf '1\r' > in2 || framework_failure_ +printf '2\r\n' > in2b || framework_failure_ +printf '1\r2^M$\n' > 'exp' || framework_failure_ +cat -E 'in2' 'in2b' > out || fail=1 +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/cat-buf.sh b/tests/misc/cat-buf.sh new file mode 100755 index 0000000..e075d22 --- /dev/null +++ b/tests/misc/cat-buf.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# Ensure that cat outputs processed data immediately. + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cat + +# Use a fifo rather than a pipe in the tests below +# so that the producer (cat) will wait until the +# consumer (dd) opens the fifo therefore increasing +# the chance that dd will read the data from each +# write separately. +mkfifo_or_skip_ fifo + +# Terminate any background cp process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +echo 1 > exp + +cat_buf_1() +{ + local delay="$1" + + > out || framework_failure_ + dd count=1 if=fifo > out & pid=$! + (echo 1; sleep $delay; echo 2) | cat -v > fifo + wait $pid + compare exp out +} + +retry_delay_ cat_buf_1 .1 6 || fail=1 + +Exit $fail diff --git a/tests/misc/cat-proc.sh b/tests/misc/cat-proc.sh new file mode 100755 index 0000000..44dbe9a --- /dev/null +++ b/tests/misc/cat-proc.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Ensure that cat -E produces same output as cat, modulo '$'s, +# even when applied to a file in /proc. + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cat + + +f=/proc/cpuinfo +test -f $f \ + || skip_ "no $f" + + +# Yes, parts of /proc/cpuinfo might change between cat runs. +# If that happens, consider choosing a file that's less likely to change, +# or just filter out the changing lines. The sed filter should help +# to avoid any spurious numeric differences. +cat -E $f | sed 's/[0-9][0-9]*/D/g' | tr -d '$' > out || fail=1 +cat $f | sed 's/[0-9][0-9]*/D/g' | tr -d '$' > exp || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/cat-self.sh b/tests/misc/cat-self.sh new file mode 100755 index 0000000..cd3b9cb --- /dev/null +++ b/tests/misc/cat-self.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# Check that cat operates correctly when the input is the same as the output. + +# Copyright 2014-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cat + +echo x >out || framework_failure_ +echo x >out1 || framework_failure_ +returns_ 1 cat out >>out || fail=1 +compare out out1 || fail=1 + +# This example is taken from the POSIX spec for 'cat'. +echo x >doc || framework_failure_ +echo y >doc.end || framework_failure_ +cat doc doc.end >doc || fail=1 +compare doc doc.end || fail=1 + +Exit $fail diff --git a/tests/misc/chcon-fail.sh b/tests/misc/chcon-fail.sh new file mode 100755 index 0000000..ddec41c --- /dev/null +++ b/tests/misc/chcon-fail.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Ensure that chcon fails when it should. +# These tests don't use any actual SE Linux syscalls. + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chcon + + +# neither context nor file +returns_ 1 chcon 2> /dev/null || fail=1 + +# No file +returns_ 1 chcon CON 2> /dev/null || fail=1 + +# No file +touch f +returns_ 1 chcon --reference=f 2> /dev/null || fail=1 + +# No file +returns_ 1 chcon -u anyone 2> /dev/null || fail=1 + +Exit $fail diff --git a/tests/misc/chcon.sh b/tests/misc/chcon.sh new file mode 100755 index 0000000..19ccb29 --- /dev/null +++ b/tests/misc/chcon.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# exercise chcon + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chcon +require_root_ +require_selinux_ +skip_if_mcstransd_is_running_ +mls_enabled_ || skip_ 'MLS is disabled' + +mkdir -p d/sub/s2 || framework_failure_ +touch f g d/sub/1 d/sub/2 || framework_failure_ + + +# Set to a specified context. +# Use root:object_r:tmp_t:s0. It is special in that +# it works even when mcstransd isn't running. +u1=root +r1=object_r +t1=tmp_t +range=s0 +ctx=$u1:$r1:$t1:$range +chcon $ctx f || skip_ "Failed to set context: $ctx" +stat --printf='f|%C\n' f > out || fail=1 + +# Use --reference. +chcon --ref=f g || fail=1 +stat --printf='g|%C\n' g >> out || fail=1 + +# Change the individual parts of the context, one by one. +u2=user_u +r2=object_r +t2=unlabeled_t +for i in --user=$u2 --role=$r2 --type=$t2 --range=$range; do + chcon $i f || fail=1 + stat --printf="f|$i|"'%C\n' f >> out || fail=1 +done + +# Same, but change back using the short-named options. +for i in -u$u1 -r$r1 -t$t1; do + chcon $i f || fail=1 + stat --printf="f|$i|"'%C\n' f >> out || fail=1 +done + +cat <<EOF > exp || framework_failure_ +f|$ctx +g|$ctx +f|--user=$u2|$u2:$r1:$t1:$range +f|--role=$r2|$u2:$r2:$t1:$range +f|--type=$t2|$u2:$r2:$t2:$range +f|--range=$range|$u2:$r2:$t2:$range +f|-uroot|root:object_r:$t2:$range +f|-robject_r|root:object_r:$t2:$range +f|-ttmp_t|root:object_r:tmp_t:$range +EOF + +compare exp out || fail=1 + +chcon --verbose -u$u1 f > out || fail=1 +echo "changing security context of 'f'" > exp || framework_failure_ +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/chroot-credentials.sh b/tests/misc/chroot-credentials.sh new file mode 100755 index 0000000..fd7cc9f --- /dev/null +++ b/tests/misc/chroot-credentials.sh @@ -0,0 +1,123 @@ +#!/bin/sh +# Verify that the credentials are changed correctly. + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chroot + +require_root_ + +EXIT_CANCELED=125 + +grep '^#define HAVE_SETGROUPS 1' "$CONFIG_HEADER" >/dev/null \ + && HAVE_SETGROUPS=1 + +root=$(id -nu 0) || skip_ "Couldn't look up root username" + +# verify numeric IDs looked up similarly to names +NON_ROOT_UID=$(id -u $NON_ROOT_USERNAME) +NON_ROOT_GROUP=$NON_ROOT_GID # Used where we want name lookups to occur + +# "uid:" is supported (unlike chown etc.) since we treat it like "uid" +chroot --userspec=$NON_ROOT_UID: / true || fail=1 + +# verify that invalid groups are diagnosed +for g in ' ' ',' '0trail'; do + returns_ $EXIT_CANCELED chroot --groups="$g" / id -G >invalid || fail=1 + compare /dev/null invalid || fail=1 +done + +# Verify that root credentials are kept. +test $(chroot / whoami) = "$root" || fail=1 +test "$(groups)" = "$(chroot / groups)" || fail=1 + +# Verify that credentials are changed correctly. +whoami_after_chroot=$( + chroot --userspec=$NON_ROOT_USERNAME:$NON_ROOT_GROUP / whoami +) +test "$whoami_after_chroot" != "$root" || fail=1 + +# Verify that when specifying only a group we don't change the +# list of supplemental groups +test "$(chroot --userspec=:$NON_ROOT_GROUP / id -G)" = \ + "$NON_ROOT_GID $(id -G)" || fail=1 + +if ! test "$HAVE_SETGROUPS"; then + Exit $fail +fi + +# Change all whitespaces to newlines, then sort the input. +# Use for tests with more groups in 'id' output. +num_sort() { tr -s ' ' '\n' | sort -n; } + +# Verify that there are no additional groups. +id_G_after_chroot=$( + chroot --userspec=$NON_ROOT_USERNAME:$NON_ROOT_GROUP \ + --groups=$NON_ROOT_GROUP / id -G +) +test "$id_G_after_chroot" = $NON_ROOT_GID || fail=1 + +# Verify that when specifying only the user name we get all their groups +test "$(chroot --userspec=$NON_ROOT_USERNAME / id -G | num_sort)" = \ + "$(id -G $NON_ROOT_USERNAME | num_sort)" || fail=1 + +# Ditto with trailing : on the user name. +test "$(chroot --userspec=$NON_ROOT_USERNAME: / id -G | num_sort)" = \ + "$(id -G $NON_ROOT_USERNAME | num_sort)" || fail=1 + +# Verify that when specifying only the user and clearing supplemental groups +# that we only get the primary group +test "$(chroot --userspec=$NON_ROOT_USERNAME --groups='' / id -G)" = \ + $NON_ROOT_GID || fail=1 + +# Verify that when specifying only the UID we get all their groups +test "$(chroot --userspec=$NON_ROOT_UID / id -G | num_sort)" = \ + "$(id -G $NON_ROOT_USERNAME | num_sort)" || fail=1 + +# Verify that when specifying only the user and clearing supplemental groups +# that we only get the primary group. Note this variant with prepended '+' +# results in no lookups in the name database which could be useful depending +# on your chroot setup. +test "$(chroot --userspec=+$NON_ROOT_UID:+$NON_ROOT_GID --groups='' / id -G)" =\ + $NON_ROOT_GID || fail=1 + +# Verify that when specifying only a group we get the current user ID +test "$(chroot --userspec=:$NON_ROOT_GROUP / id -u)" = "$(id -u)" \ + || fail=1 + +# verify that arbitrary numeric IDs are supported +test "$(chroot --userspec=1234:+5678 --groups=' +8765,4321' / id -G)" \ + || fail=1 + +# demonstrate that extraneous commas are supported +test "$(chroot --userspec=1234:+5678 --groups=',8765,,4321,' / id -G)" \ + || fail=1 + +# demonstrate that --groups is not cumulative +test "$(chroot --groups='invalid ignored' --groups='' / id -G)" \ + || fail=1 + +if ! id -u +12342; then + # Ensure supplemental groups cleared from some arbitrary unknown ID + test "$(chroot --userspec=+12342:+5678 / id -G)" = '5678' || fail=1 + + # Ensure we fail when we don't know what groups to set for an unknown ID + returns_ $EXIT_CANCELED chroot --userspec=+12342 / true || fail=1 +fi + +Exit $fail diff --git a/tests/misc/chroot-fail.sh b/tests/misc/chroot-fail.sh new file mode 100755 index 0000000..77df64f --- /dev/null +++ b/tests/misc/chroot-fail.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# Verify that internal failure in chroot gives exact status. + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chroot pwd + +# These tests verify exact status of internal failure; since none of +# them actually run a command, we don't need root privileges +returns_ 125 chroot || fail=1 # missing argument +returns_ 125 chroot --- / true || fail=1 # unknown option + +# chroot("/") succeeds for non-root users on some systems, but not all. +if chroot / true ; then + can_chroot_root=1 + returns_ 2 chroot / sh -c 'exit 2' || fail=1 # exit status propagation + returns_ 126 chroot / . || fail=1# invalid command + returns_ 127 chroot / no_such || fail=1 # no such command +else + test $? = 125 || fail=1 + can_chroot_root=0 +fi + +# Ensure that --skip-chdir fails with a non-"/" argument. +cat <<\EOF > exp || framework_failure_ +chroot: option --skip-chdir only permitted if NEWROOT is old '/' +Try 'chroot --help' for more information. +EOF +chroot --skip-chdir . env pwd >out 2>err && fail=1 +compare /dev/null out || fail=1 +compare exp err || fail=1 + +# Ensure we chdir("/") appropriately when NEWROOT is old "/". +if test $can_chroot_root = 1; then + ln -s / isroot || framework_failure_ + for dir in '/' '/.' '/../' isroot; do + # Verify that chroot(1) succeeds and performs chdir("/") + # (chroot(1) of coreutils-8.23 failed to run the latter). + curdir=$(chroot "$dir" env pwd) || fail=1 + test "$curdir" = '/' || fail=1 + + # Test the "--skip-chdir" option. + curdir=$(chroot --skip-chdir "$dir" env pwd) || fail=1 + test "$curdir" = '/' && fail=1 + done +fi + +Exit $fail diff --git a/tests/misc/cksum-a.sh b/tests/misc/cksum-a.sh new file mode 100755 index 0000000..34b6d4d --- /dev/null +++ b/tests/misc/cksum-a.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# Validate cksum --algorithm operation + +# Copyright (C) 2021-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cksum + +cat > input_options <<\EOF || framework_failure_ +bsd sum -r +sysv sum -s +crc cksum +md5 md5sum -t +sha1 sha1sum -t +sha224 sha224sum -t +sha256 sha256sum -t +sha384 sha384sum -t +sha512 sha512sum -t +blake2b b2sum -t +EOF + +while read algo prog; do + $prog /dev/null >> out || continue + cksum --untagged --algorithm=$algo /dev/null > out-c || fail=1 + + case "$algo" in + bsd) ;; + sysv) ;; + crc) ;; + *) cksum --check --algorithm=$algo out-c || fail=1 ;; + esac + + cat out-c >> out-a || framework_failure_ +done < input_options +compare out out-a || fail=1 + +# Ensure --check not allowed with older (non tagged) algorithms +returns_ 1 cksum -a bsd --check </dev/null || fail=1 + +# Ensure abbreviations not supported for algorithm selection +returns_ 1 cksum -a sha22 </dev/null || fail=1 + +Exit $fail diff --git a/tests/misc/cksum-c.sh b/tests/misc/cksum-c.sh new file mode 100755 index 0000000..c342ea8 --- /dev/null +++ b/tests/misc/cksum-c.sh @@ -0,0 +1,59 @@ +#!/bin/sh +# Validate cksum --check dynamic operation + +# Copyright (C) 2021-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cksum shuf + +shuf -i 1-10 > input || framework_failure_ + +for args in '-a sha384' '-a blake2b' '-a blake2b -l 384' '-a sm3'; do + cksum $args 'input' >> CHECKSUMS || fail=1 +done +cksum --strict --check CHECKSUMS || fail=1 + +# Ensure leading whitespace and \ ignored +sed 's/^/ \\/' CHECKSUMS | cksum --strict -c || fail=1 + +# Check common signed checksums format works in non strict mode +cat >> signed_CHECKSUMS <<\EOF +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA384 + +# ignored comment +EOF +cat CHECKSUMS >> signed_CHECKSUMS +cat >> signed_input <<\EOF +-----BEGIN PGP SIGNATURE----- + +# Note base64 doesn't have ambiguous delimiters in its charset +SHA384+BCAAdFiEEjFummQvbJuGfKhqAEWGuaUVxmjkFAmCDId0ACgkQEWGuaUVx +BLAKE2b/00001EuON62pTEnqrJ5lav61QxRByiuDp/6VODrRL2JWM6Stxu1Myws= +=AWU7 +-----END PGP SIGNATURE----- +EOF +cksum --check signed_CHECKSUMS || fail=1 + +# Can check individual digests in a mixed file +cksum --check -a sm3 CHECKSUMS || fail=1 + +# Checks against older (non hex) checksum formats not supported +returns_ 1 cksum -a crc -c CHECKSUMS || fail=1 +cksum -a crc 'input' > CHECKSUMS.crc || fail=1 +returns_ 1 cksum -c CHECKSUMS.crc || fail=1 + +Exit $fail diff --git a/tests/misc/cksum.sh b/tests/misc/cksum.sh new file mode 100755 index 0000000..da7e4d5 --- /dev/null +++ b/tests/misc/cksum.sh @@ -0,0 +1,74 @@ +#!/bin/sh +# Validate cksum operation + +# Copyright (C) 2020-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cksum printf + +returns_ 1 cksum missing || fail=1 + +{ + for offset in $(seq -1 6); do + env printf $(env printf '\\%03o' $(seq 0 $offset)); + env printf $(env printf '\\%03o' $(seq 0 255)); + done +} > in || framework_failure_ + +cksum in > out || fail=1 +printf '%s\n' '4097727897 2077 in' > exp || framework_failure_ +compare exp out || fail=1 + +# Make sure crc is correct for files larger than 128 bytes (4 fold pclmul) +{ + env printf $(env printf '\\%03o' $(seq 0 130)); +} > in || framework_failure_ + +cksum in > out || fail=1 +printf '%s\n' '3800919234 131 in' > exp || framework_failure_ +compare exp out || fail=1 + +# Make sure crc is correct for files larger than 32 bytes +# but <128 bytes (1 fold pclmul) +{ + env printf $(env printf '\\%03o' $(seq 0 64)); +} > in || framework_failure_ + +cksum in > out || fail=1 +printf '%s\n' '796287823 65 in' > exp || framework_failure_ +compare exp out || fail=1 + +# Make sure crc is still handled correctly when next 65k buffer is read +# (>32 bytes more than 65k) +{ + seq 1 12780 +} > in || framework_failure_ + +cksum in > out || fail=1 +printf '%s\n' '3720986905 65574 in' > exp || framework_failure_ +compare exp out || fail=1 + +# Make sure crc is still handled correctly when next 65k buffer is read +# (>=128 bytes more than 65k) +{ + seq 1 12795 +} > in || framework_failure_ + +cksum in > out || fail=1 +printf '%s\n' '4278270357 65664 in' > exp || framework_failure_ +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/close-stdout.sh b/tests/misc/close-stdout.sh new file mode 100755 index 0000000..38b4038 --- /dev/null +++ b/tests/misc/close-stdout.sh @@ -0,0 +1,65 @@ +#!/bin/sh +# Ensure that several programs work fine, even with stdout initially closed. +# This is effectively a test of closeout.c's close_stdout function. + +# Copyright (C) 2004-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ rm + +p=$abs_top_builddir + + +# Ensure these exit successfully, even though stdout is closed, +# because they generate no output. +touch a +cp a b >&- || fail=1 +test -f b || fail=1 +chmod o-w . >&- || fail=1 +ln a c >&- || fail=1 +rm c >&- || fail=1 +mkdir d >&- || fail=1 +mv d e >&- || fail=1 +rmdir e >&- || fail=1 +touch e >&- || fail=1 +sleep 0 >&- || fail=1 +"$p/src/true" >&- || fail=1 +"$p/src/printf" '' >&- || fail=1 + +# If >&- works, ensure these fail, because stdout is closed and they +# *do* generate output. >&- apparently does not work in HP-UX 11.23. +# This test is ineffective unless /dev/stdout also works. +if "$p/src/test" -w /dev/stdout >/dev/null && + "$p/src/test" ! -w /dev/stdout >&-; then + returns_ 1 "$p/src/printf" 'foo' >&- 2>/dev/null || fail=1 + returns_ 1 cp --verbose a b >&- 2>/dev/null || fail=1 + rm -Rf tmpfile-?????? || fail=1 + returns_ 1 mktemp tmpfile-XXXXXX >&- 2>/dev/null || fail=1 + returns_ 1 mktemp tmpfile-XXXXXX -q >&- 2>/dev/null || fail=1 + case $(echo tmpfile-??????) in 'tmpfile-??????') ;; *) fail=1 ;; esac +fi + +# Likewise for /dev/full, if /dev/full works. +if test -w /dev/full && test -c /dev/full; then + returns_ 1 "$p/src/printf" 'foo' >/dev/full 2>/dev/null || fail=1 + returns_ 1 cp --verbose a b >/dev/full 2>/dev/null || fail=1 + rm -Rf tmpdir-?????? || fail=1 + returns_ 1 mktemp -d tmpdir-XXXXXX >/dev/full 2>/dev/null || fail=1 + returns_ 1 mktemp -d -q tmpdir-XXXXXX >/dev/full 2>/dev/null || fail=1 + case $(echo tmpfile-??????) in 'tmpfile-??????') ;; *) fail=1 ;; esac +fi + +Exit $fail diff --git a/tests/misc/comm.pl b/tests/misc/comm.pl new file mode 100755 index 0000000..73e8c37 --- /dev/null +++ b/tests/misc/comm.pl @@ -0,0 +1,183 @@ +#!/usr/bin/perl +# -*- perl -*- +# Test comm + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +require 5.003; +use strict; + +(my $program_name = $0) =~ s|.*/||; + +my $prog = 'comm'; + +# Turn off localization of executable's ouput. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @inputs = ({IN=>{a=>"1\n3\n3\n3"}}, {IN=>{b=>"2\n2\n3\n3\n3"}}); +my @zinputs = ({IN=>{za=>"1\0003\0003\0003"}}, + {IN=>{zb=>"2\0002\0003\0003\0003"}}); + +my @Tests = + ( + # basic operation + ['basic', @inputs, {OUT=>"1\n\t2\n\t2\n\t\t3\n\t\t3\n\t\t3\n"} ], + ['zbasic', '-z', @zinputs, {OUT=>"1\0\t2\0\t2\0\t\t3\0\t\t3\0\t\t3\0"} ], + + # suppress lines unique to file 1 + ['opt-1', '-1', @inputs, {OUT=>"2\n2\n\t3\n\t3\n\t3\n"} ], + ['zopt-1', '-z', '-1', @zinputs, {OUT=>"2\0002\000\t3\000\t3\000\t3\000"} ], + + # suppress lines unique to file 2 + ['opt-2', '-2', @inputs, {OUT=>"1\n\t3\n\t3\n\t3\n"} ], + ['zopt-2', '-z', '-2', @zinputs, {OUT=>"1\000\t3\000\t3\000\t3\000"} ], + + # suppress lines that appear in both files + ['opt-3', '-3', @inputs, {OUT=>"1\n\t2\n\t2\n"} ], + ['zopt-3', '-z', '-3', @zinputs, {OUT=>"1\000\t2\000\t2\000"} ], + + # suppress lines unique to file 1 and lines unique to file 2 + ['opt-12', '-1', '-2', @inputs, {OUT=>"3\n3\n3\n"} ], + ['zopt-12', '-12z', @zinputs, {OUT=>"3\0003\0003\000"} ], + + # suppress lines unique to file 1 and those that appear in both files + ['opt-13', '-1', '-3', @inputs, {OUT=>"2\n2\n"} ], + ['zopt-13', '-13z', @zinputs, {OUT=>"2\0002\000"} ], + + # suppress lines unique to file 2 and those that appear in both files + ['opt-23', '-2', '-3', @inputs, {OUT=>"1\n"} ], + ['zopt-23', '-23z', @zinputs, {OUT=>"1\000"} ], + + # suppress all output + ['opt-123', '-1', '-2', '-3', @inputs, {OUT=>""} ], + + # show summary: 1 only in file1, 2 only in file2, 3 in both files + ['total-all', '--total', @inputs, {OUT=>"1\n\t2\n\t2\n\t\t3\n\t\t3\n\t\t3\n" + . "1\t2\t3\ttotal\n"} ], + + # show summary only, suppressing regular output + ['total-123', '--total', '-123', @inputs, {OUT=>"1\t2\t3\ttotal\n"} ], + + # invalid missing command line argument (1) + ['missing-arg1', $inputs[0], {EXIT=>1}, + {ERR => "$prog: missing operand after 'a'\n" + . "Try '$prog --help' for more information.\n"}], + + # invalid missing command line argument (both) + ['missing-arg2', {EXIT=>1}, + {ERR => "$prog: missing operand\n" + . "Try '$prog --help' for more information.\n"}], + + # invalid extra command line argument + ['extra-arg', @inputs, 'no-such', {EXIT=>1}, + {ERR => "$prog: extra operand 'no-such'\n" + . "Try '$prog --help' for more information.\n"}], + + # out-of-order input + ['ooo', {IN=>{a=>"1\n3"}}, {IN=>{b=>"3\n2"}}, {EXIT=>1}, + {OUT => "1\n\t\t3\n\t2\n"}, + {ERR => "$prog: file 2 is not in sorted order\n" + . "$prog: input is not in sorted order\n"}], + + # out-of-order input, fatal + ['ooo2', '--check-order', {IN=>{a=>"1\n3"}}, {IN=>{b=>"3\n2"}}, {EXIT=>1}, + {OUT => "1\n\t\t3\n"}, + {ERR => "$prog: file 2 is not in sorted order\n"}], + + # out-of-order input, ignored + ['ooo3', '--nocheck-order', {IN=>{a=>"1\n3"}}, {IN=>{b=>"3\n2"}}, + {OUT => "1\n\t\t3\n\t2\n"}], + + # both inputs out-of-order + ['ooo4', {IN=>{a=>"3\n1\n0"}}, {IN=>{b=>"3\n2\n0"}}, {EXIT=>1}, + {OUT => "\t\t3\n1\n0\n\t2\n\t0\n"}, + {ERR => "$prog: file 1 is not in sorted order\n". + "$prog: file 2 is not in sorted order\n" + . "$prog: input is not in sorted order\n"}], + + # both inputs out-of-order on last pair + ['ooo5', {IN=>{a=>"3\n1"}}, {IN=>{b=>"3\n2"}}, {EXIT=>1}, + {OUT => "\t\t3\n1\n\t2\n"}, + {ERR => "$prog: file 1 is not in sorted order\n". + "$prog: file 2 is not in sorted order\n" + . "$prog: input is not in sorted order\n"}], + + # first input out-of-order extended + ['ooo5b', {IN=>{a=>"0\n3\n1"}}, {IN=>{b=>"2\n3"}}, {EXIT=>1}, + {OUT => "0\n\t2\n\t\t3\n1\n"}, + {ERR => "$prog: file 1 is not in sorted order\n" + . "$prog: input is not in sorted order\n"}], + + # second input out-of-order extended + ['ooo5c', {IN=>{a=>"0\n3"}}, {IN=>{b=>"2\n3\n1"}}, {EXIT=>1}, + {OUT => "0\n\t2\n\t\t3\n\t1\n"}, + {ERR => "$prog: file 2 is not in sorted order\n" + . "$prog: input is not in sorted order\n"}], + + # both inputs out-of-order, but fully pairable + ['ooo6', {IN=>{a=>"2\n1\n0"}}, {IN=>{b=>"2\n1\n0"}}, {EXIT=>0}, + {OUT => "\t\t2\n\t\t1\n\t\t0\n"}], + + # both inputs out-of-order, fully pairable, but forced to fail + ['ooo7', '--check-order', {IN=>{a=>"2\n1\n0"}}, {IN=>{b=>"2\n1\n0"}}, + {EXIT=>1}, + {OUT => "\t\t2\n"}, + {ERR => "$prog: file 1 is not in sorted order\n"}], + + # out-of-order, line 2 is a prefix of line 1 + # until coreutils-7.2, this test would fail -- no disorder detected + ['ooo-prefix', '--check-order', {IN=>{a=>"Xa\nX\n"}}, {IN=>{b=>""}}, + {EXIT=>1}, + {OUT => "Xa\n"}, + {ERR => "$prog: file 1 is not in sorted order\n"}], + + # alternate delimiter: ',' + ['delim-comma', '--output-delimiter=,', @inputs, + {OUT=>"1\n,2\n,2\n,,3\n,,3\n,,3\n"} ], + + # two-character alternate delimiter: '++' + ['delim-2char', '--output-delimiter=++', @inputs, + {OUT=>"1\n++2\n++2\n++++3\n++++3\n++++3\n"} ], + + # NUL delimiter + ['delim-empty', '--output-delimiter=', @inputs, + {OUT=>"1\n\0002\n\0002\n\000\0003\n\000\0003\n\000\0003\n"} ], + ['zdelim-empty', '-z', '-z --output-delimiter=', @zinputs, + {OUT=>"1\000\0002\000\0002\000\000\0003\000\000\0003\000\000\0003\000"} ], + + # invalid dual delimiter + ['delim-dual', '--output-delimiter=,', '--output-delimiter=+', @inputs, + {EXIT=>1}, {ERR => "$prog: multiple output delimiters specified\n"}], + + # valid dual delimiter specification + ['delim-dual2', '--output-delimiter=,', '--output-delimiter=,', @inputs, + {OUT=>"1\n,2\n,2\n,,3\n,,3\n,,3\n"} ], + + # show summary, zero-terminated + ['totalz-all', '--total', '-z', @zinputs, + {OUT=>"1\000\t2\000\t2\000\t\t3\000\t\t3\000\t\t3\000" + . "1\t2\t3\ttotal\000"} ], + + # show summary only (-123), zero-terminated and with ',' as delimiter + ['totalz-123', '--total', '-z123', '--output-delimiter=,', @zinputs, + {OUT=>"1,2,3,total\000"} ], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/coreutils.sh b/tests/misc/coreutils.sh new file mode 100755 index 0000000..8bdd6b1 --- /dev/null +++ b/tests/misc/coreutils.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# Verify behavior of separate coreutils multicall binary + +# Copyright (C) 2014-2022 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 <https://www.gnu.org/licenses/>. + + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ coreutils + +test -s "$abs_top_builddir/src/coreutils.h" \ + || skip_ "multicall binary is disabled" + +# Yes outputs all its params so is good to verify argv manipulations +echo 'y' > exp +coreutils --coreutils-prog=yes | head -n10 | uniq > out +compare exp out || fail=1 + +# Ensure if incorrect program passed, we diagnose +echo "coreutils: unknown program 'blah'" > exp +coreutils --coreutils-prog='blah' --help 2>err && fail=1 +compare exp err || fail=1 + +Exit $fail diff --git a/tests/misc/csplit-1000.sh b/tests/misc/csplit-1000.sh new file mode 100755 index 0000000..36c32b0 --- /dev/null +++ b/tests/misc/csplit-1000.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# cause a 1-byte heap buffer overrun + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ csplit + +# Before coreutils-8.7, this would overrun the 6-byte filename_space buffer. +# It's hard to detect that without using valgrind, so here, we simply +# run the demonstrator. +seq 1000 | csplit - '/./' '{*}' || fail=1 +test -f xx1000 || fail=1 +test -f xx1001 && fail=1 + +Exit $fail diff --git a/tests/misc/csplit-heap.sh b/tests/misc/csplit-heap.sh new file mode 100755 index 0000000..326374f --- /dev/null +++ b/tests/misc/csplit-heap.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# ensure that csplit uses a bounded amount of memory + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ csplit + +# Determine basic amount of memory needed. +{ echo y; echo n; } > f || framework_failure_ +vm=$(get_min_ulimit_v_ csplit -z f %n%1) \ + || skip_ "this shell lacks ulimit support" + +( + ulimit -v $(($vm + 1000)) \ + && { yes | head -n2500000; echo n; } | csplit -z - %n%1 +) || fail=1 + +Exit $fail diff --git a/tests/misc/csplit-io-err.sh b/tests/misc/csplit-io-err.sh new file mode 100755 index 0000000..9ad00bb --- /dev/null +++ b/tests/misc/csplit-io-err.sh @@ -0,0 +1,92 @@ +#!/bin/sh +# Ensure we handle i/o errors correctly in csplit + +# Copyright (C) 2015-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ csplit +require_gcc_shared_ + +if ! test -w /dev/full || ! test -c /dev/full; then + skip_ '/dev/full is required' +fi + +# Ensure error messages are in English +LC_ALL=C +export LC_ALL + +# Replace fwrite and ferror, always returning an error +cat > k.c <<'EOF' || framework_failure_ +#include <stdio.h> +#include <errno.h> + +#undef fwrite +#undef fwrite_unlocked + +size_t +fwrite (const void *ptr, size_t size, size_t nitems, FILE *stream) +{ + if (stream == stderr) + { + /* Perform the normal operation of fwrite. */ + const char *p = ptr; + size_t count = size * nitems; + size_t i; + for (i = 0; i < count; i++) + if (putc ((unsigned char) *p++, stream) == EOF) + break; + return i / size; + } + else + { + fclose (fopen ("preloaded","w")); /* marker for preloaded interception */ + errno = ENOSPC; + return 0; + } +} + +size_t +fwrite_unlocked (const void *ptr, size_t size, size_t nitems, FILE *stream) +{ + return fwrite (ptr, size, nitems, stream); +} +EOF + +# Get the wording of the OS-dependent ENOSPC message +returns_ 1 seq 1 >/dev/full 2>msgt || framework_failure_ +sed 's/seq: write error: //' msgt > msg || framework_failure_ + +# Create the expected error message +{ printf "%s" "csplit: write error for 'xx01': " ; cat msg ; } > exp \ + || framework_failure_ + +# compile/link the interception shared library: +gcc_shared_ k.c k.so \ + || skip_ 'failed to build forced-fwrite-failure shared library' + +# Split the input, and force fwrite() failure - +# the 'csplit' command should fail with exit code 1 +# (checked with 'returns_ 1 ... || fail=1') +seq 10 | +(export LD_PRELOAD=$LD_PRELOAD:./k.so + returns_ 1 csplit - 1 4 2>out) || fail=1 + +test -e preloaded || skip_ 'LD_PRELOAD interception failed' + +# Ensure we got the expected error message +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/csplit-suppress-matched.pl b/tests/misc/csplit-suppress-matched.pl new file mode 100755 index 0000000..58a88ec --- /dev/null +++ b/tests/misc/csplit-suppress-matched.pl @@ -0,0 +1,218 @@ +#!/usr/bin/perl + +# Copyright (C) 2013-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $limits = getlimits (); + +my $prog = 'csplit'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# Input from 'seq 6' +my $IN_SEQ_6 =<<EOF; +1 +2 +3 +4 +5 +6 +EOF + +# Input from a possible run of 'uniq --group' +# (groups separated by empty lines) +my $IN_UNIQ =<<EOF; +a +a +YY + +XX +b +b +YY + +XX +c +YY + +XX +d +d +d +EOF + +# Standard Coreutils::run_tests() structure, except the addition of +# "OUTPUTS" array, containing the expected content of the output files. +# See code below for conversion into PRE/CMP/POST checks. +my @csplit_tests = +( + # without --suppress-matched, + # the newline (matched line) appears in the output files + ["re-base", "-q - '/^\$/' '{*}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => [ "a\na\nYY\n", "\nXX\nb\nb\nYY\n","\nXX\nc\nYY\n", + "\nXX\nd\nd\nd\n" ] }], + + # the newline (matched line) does not appear in the output files + ["re-1", " --suppress-matched -q - '/^\$/' '{*}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => ["a\na\nYY\n", "XX\nb\nb\nYY\n", "XX\nc\nYY\n", + "XX\nd\nd\nd\n"]}], + + # the 'XX' (matched line + offset 1) does not appear in the output files. + # the newline appears in the files (before each split, at the end of the file) + ["re-2", "--suppress-matched -q - '/^\$/1' '{*}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => ["a\na\nYY\n\n","b\nb\nYY\n\n","c\nYY\n\n","d\nd\nd\n"]}], + + # the 'YY' (matched line + offset of -1) does not appear in the output files + # the newline appears in the files (as the first line of the new split) + ["re-3", " --suppress-matched -q - '/^\$/-1' '{*}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => ["a\na\n", "\nXX\nb\nb\n", "\nXX\nc\n", "\nXX\nd\nd\nd\n"]}], + + # the last matched line for a non infinite match repetition is suppressed. + # Up to and including coreutils 8.32, the last match was output. + ["re-4", " --suppress-matched -q - '/^\$/' '{2}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => ["a\na\nYY\n", "XX\nb\nb\nYY\n", "XX\nc\nYY\n", + "XX\nd\nd\nd\n"]}], + + # Test two consecutive matched lines + # without suppress-matched, the second file should contain a single newline. + ["re-4.1", "-q - '/^\$/' '{*}'", {IN_PIPE => "a\n\n\nb\n"}, + {OUTPUTS => [ "a\n", "\n", "\nb\n" ]}], + # suppress-matched will cause the second file to be empty. + ["re-4.2", "--suppress-match -q - '/^\$/' '{*}'", {IN_PIPE => "a\n\n\nb\n"}, + {OUTPUTS => [ "a\n", "", "b\n" ]}], + # suppress-matched + elide-empty should output just two files. + ["re-4.3", "--suppress-match -zq - '/^\$/' '{*}'", {IN_PIPE => "a\n\n\nb\n"}, + {OUTPUTS => [ "a\n", "b\n" ]}], + + + # Test a matched-line as the last line + # default: last file with newline should be created. + ["re-5.1", "-q - '/^\$/' '{*}'", {IN_PIPE => "a\n\nb\n\n"}, + {OUTPUTS => [ "a\n", "\nb\n", "\n" ]}], + # suppress-matched - last empty files should be created. + ["re-5.2", "--suppress-match -q - '/^\$/' '{*}'", {IN_PIPE => "a\n\nb\n\n"}, + {OUTPUTS => [ "a\n", "b\n", "" ]}], + # suppress-matched + elide-empty: just two files should be created. + ["re-5.3", "--suppress-match -zq - '/^\$/' '{*}'", {IN_PIPE => "a\n\nb\n\n"}, + {OUTPUTS => [ "a\n", "b\n" ]}], + + # without suppress-matched, + # the matched lines (2/4/6) appears in the output files + ["int-base", '-q - 2 4 6', {IN_PIPE => $IN_SEQ_6}, + {OUTPUTS => [ "1\n", "2\n3\n", "4\n5\n", "6\n" ]}], + # suppress matched - the matching lines (2/4/6) should not appear. + ["int-1", '--suppress-matched -q - 2 4 6', {IN_PIPE => $IN_SEQ_6}, + {OUTPUTS => [ "1\n", "3\n", "5\n", "" ]}], + # suppress matched + elide-empty + ["int-2", '--suppress-matched -zq - 2 4 6', {IN_PIPE => $IN_SEQ_6}, + {OUTPUTS => [ "1\n", "3\n", "5\n" ]}], +); + + + +=pod +The following loop translate the above @Tests to a Cureutils::run_tests() +compatible structure. It converts "OUTPUTS" key into "CMP" + "POST" keys: +1. Each element in the OUTPUTS key is expected to be an output file + from csplit (named xx00, xx01, xx02...) + create a "CMP" key for each one, with the output and the filename. +2. Add a "POST" key, ensuring no extra files have been created. + (e.g. if there are 4 expected outputs, xx00 to xx03, + ensure xx04 doesn't exist). +3. Add a "PRE" key, deleting all existing 'xx*' files. + +Example: + +Before conversion: + my @csplit_tests = + ( + ["1", '-z -q - 2 4 6', + {IN_PIPE => "1\n2\n3\n4\n5\n6\n"}, + {OUTPUTS => [ "1\n", "2\n3\n", "4\n5\n", "6\n" ], + ] + ) + +After conversion: + + my @csplit_tests = + ( + ["1", '-z -q - 2 4 6', + {IN_PIPE => "1\n2\n3\n4\n5\n6\n"}, + {PRE => sub { unlink glob './xx??' ; }}, + {CMP => ["1\n", {'xx00'=> undef}]}, + {CMP => ["2\n3\n", {'xx01'=> undef}]}, + {CMP => ["4\n5\n", {'xx02'=> undef}]}, + {CMP => ["6\n", {'xx03'=> undef}]}, + {POST => sub { die "extra file" if -e 'xx04'}}, + ], + ); +=cut +my @Tests; +foreach my $t (@csplit_tests) + { + my ($test_name, $cmdline, @others) = @$t; + my $new_ent = [$test_name, $cmdline]; + + my $out_file_num = 0 ; + + foreach my $e (@others) + { + die "Internal error: expecting a hash (e.g. IN_PIPE/OUTPUTS/ERR)" . + "in test '$test_name', got $e" + unless ref $e && (ref $e eq 'HASH'); + + my ($key, $value) = each %$e; + if ($key eq 'OUTPUTS') + { + # Convert each expected OUTPUT to a 'CMP' key. + foreach my $output (@$value) + { + my $filename = sprintf("xx%02d",$out_file_num++); + my $cmp = {CMP => [ $output, { $filename => undef}]}; + push @$new_ent, $cmp; + } + + # Add a 'POST' check + # Ensure no extra files have been created. + my $filename = sprintf("xx%02d",$out_file_num++); + my $post = { POST => sub { die "Test failed: an extraneous file " . + "'$filename' has been created\n" + if -e $filename; } } ; + push @$new_ent, $post; + + # before running each test, cleanup the 'xx00' files + # from previous runs. + my $pre = { PRE => sub { unlink glob "./xx??"; } }; + push @$new_ent, $pre; + } + else + { + # pass other entities as-is (e.g. OUT, ERR, OUT_SUBST, EXIT) + # run_tests() will know how to handle them. + push @$new_ent, $e; + } + } + + push @Tests, $new_ent; + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/csplit.sh b/tests/misc/csplit.sh new file mode 100755 index 0000000..ab15e50 --- /dev/null +++ b/tests/misc/csplit.sh @@ -0,0 +1,103 @@ +#!/bin/sh +# various csplit tests + +# Copyright (C) 2001-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ csplit + + +# csplit could get a failed assertion to 2.0.17 +(echo a; echo; echo) > in +csplit in '/^$/' 2 > out || fail=1 +cat <<EOF > exp +2 +0 +2 +EOF +compare exp out || fail=1 +rm -f in out exp + +# Ensure that xx02 contains just two newlines. +# This would fail due to reading from freed buffer with coreutils-5.0.91. +printf '\n\n' > exp +cp xx02 out || fail=1 +compare exp out || fail=1 +rm -f in out exp + +# csplit would infloop +(echo; echo a) > in +csplit in '/a/-1' '{*}' > out || fail=1 +cat <<EOF > exp +0 +3 +EOF +compare exp out || fail=1 +rm -f in out exp + +# 'echo |csplit - 1 1' used to abort. +echo > in +csplit in 1 1 > out 2> err || fail=1 +cat <<EOF > exp +0 +0 +1 +EOF +compare exp out || fail=1 +cat <<\EOF > experr +csplit: warning: line number '1' is the same as preceding line number +EOF +compare experr err || fail=1 +rm -f in out exp err experr + +# 'echo | csplit -b '%0#6.3x' - 1' incorrectly warned about the format +# up through coreutils 8.6. +echo > in +csplit -b '%0#6.3x' in 1 > out 2> err || fail=1 +cat <<EOF > exp +0 +1 +EOF +compare exp out || fail=1 +touch experr +compare experr err || fail=1 +compare 'xx 000' experr || fail=1 +compare 'xx 0x001' in || fail=1 +rm -f in out exp err experr xx* + +# make sure 'csplit FILE 0' fails. +echo > in +csplit in 0 > out 2> err && fail=1 +csplit in 2 1 > out 2>> err && fail=1 +csplit in 3 3 > out 2>> err && fail=1 +cat <<\EOF > experr +csplit: 0: line number must be greater than zero +csplit: line number '1' is smaller than preceding line number, 2 +csplit: warning: line number '3' is the same as preceding line number +csplit: '3': line number out of range +EOF +compare experr err || fail=1 + +# Ensure that lines longer than the initial buffer length don't cause +# trouble (e.g. reading from freed memory, resulting in corrupt output). +# This test failed at least in coreutils-5.2.1 and 5.3.0, and was fixed +# in 5.3.1. +rm -f in out exp err experr xx?? +printf 'x%8199s\nx\n%8199s\nx\n' x x > in +csplit in '/x\{1\}/' '{*}' > /dev/null || fail=1 +cat xx?? | compare - in || fail=1 + +Exit $fail diff --git a/tests/misc/cut-huge-range.sh b/tests/misc/cut-huge-range.sh new file mode 100755 index 0000000..a235d6e --- /dev/null +++ b/tests/misc/cut-huge-range.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# Ensure that cut does not allocate mem for large ranges + +# Copyright (C) 2012-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cut +getlimits_ + +vm=$(get_min_ulimit_v_ returns_ 0 cut -b1 /dev/null) \ + || skip_ "this shell lacks ulimit support" + +# Ensure we can cut up to our sentinel value. +# Don't use expr to subtract one, +# since UINTMAX_MAX may exceed its maximum value. +CUT_MAX=$(expr $UINTMAX_MAX - 1) || framework_failure_ + +# From coreutils-8.10 through 8.20, this would make cut try to allocate +# a 256MiB bit vector. +(ulimit -v $vm && cut -b$CUT_MAX- /dev/null > err 2>&1) || fail=1 + +# Up to and including coreutils-8.21, cut would allocate possibly needed +# memory upfront. Subsequently extra memory is no longer needed. +(ulimit -v $vm && cut -b1-$CUT_MAX /dev/null >> err 2>&1) || fail=1 + +# Explicitly disallow values above CUT_MAX +(ulimit -v $vm && returns_ 1 cut -b$UINTMAX_MAX /dev/null 2>/dev/null) || + fail=1 +(ulimit -v $vm && returns_ 1 cut -b$UINTMAX_OFLOW /dev/null 2>/dev/null) || + fail=1 + +compare /dev/null err || fail=1 + +Exit $fail diff --git a/tests/misc/cut.pl b/tests/misc/cut.pl new file mode 100755 index 0000000..c93d738 --- /dev/null +++ b/tests/misc/cut.pl @@ -0,0 +1,255 @@ +#!/usr/bin/perl +# Test "cut". + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $ME = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $mb_locale = $ENV{LOCALE_FR_UTF8}; +! defined $mb_locale || $mb_locale eq 'none' + and $mb_locale = 'C'; + +my $prog = 'cut'; +my $try = "Try '$prog --help' for more information.\n"; +my $from_field1 = "$prog: fields are numbered from 1\n$try"; +my $from_pos1 = "$prog: byte/character positions are numbered from 1\n$try"; +my $inval_fld = "$prog: invalid field range\n$try"; +my $inval_pos = "$prog: invalid byte or character range\n$try"; +my $no_endpoint = "$prog: invalid range with no endpoint: -\n$try"; +my $nofield = "$prog: an input delimiter may be specified only when " . + "operating on fields\n$try"; + +my @Tests = + ( + # Provoke a double-free in cut from coreutils-6.7. + ['dbl-free', '-f2-', {IN=>{f=>'x'}}, {IN=>{g=>'y'}}, {OUT=>"x\ny\n"}], + + # This failed (as it should) even before coreutils-6.9.90, + # but cut from 6.9.90 produces a more useful diagnostic. + ['zero-1', '-b0', {ERR=>$from_pos1}, {EXIT => 1} ], + + # Up to coreutils-6.9, specifying a range of 0-2 was not an error. + # It was treated just like "-2". + ['zero-2', '-f0-2', {ERR=>$from_field1}, {EXIT => 1} ], + + # Up to coreutils-8.20, specifying a range of 0- was not an error. + ['zero-3b', '-b0-', {ERR=>$from_pos1}, {EXIT => 1} ], + ['zero-3c', '-c0-', {ERR=>$from_pos1}, {EXIT => 1} ], + ['zero-3f', '-f0-', {ERR=>$from_field1}, {EXIT => 1} ], + + ['1', '-d:', '-f1,3-', {IN=>"a:b:c\n"}, {OUT=>"a:c\n"}], + ['2', '-d:', '-f1,3-', {IN=>"a:b:c\n"}, {OUT=>"a:c\n"}], + ['3', qw(-d: -f2-), {IN=>"a:b:c\n"}, {OUT=>"b:c\n"}], + ['4', qw(-d: -f4), {IN=>"a:b:c\n"}, {OUT=>"\n"}], + ['5', qw(-d: -f4), {IN=>""}, {OUT=>""}], + ['6', '-c4', {IN=>"123\n"}, {OUT=>"\n"}], + ['7', '-c4', {IN=>"123"}, {OUT=>"\n"}], + ['8', '-c4', {IN=>"123\n1"}, {OUT=>"\n\n"}], + ['9', '-c4', {IN=>""}, {OUT=>""}], + ['a', qw(-s -d:), '-f3-', {IN=>"a:b:c\n"}, {OUT=>"c\n"}], + ['b', qw(-s -d:), '-f2,3', {IN=>"a:b:c\n"}, {OUT=>"b:c\n"}], + ['c', qw(-s -d:), '-f1,3', {IN=>"a:b:c\n"}, {OUT=>"a:c\n"}], + # Trailing colon should not be output + ['d', qw(-s -d:), '-f1,3', {IN=>"a:b:c:\n"}, {OUT=>"a:c\n"}], + ['e', qw(-s -d:), '-f3-', {IN=>"a:b:c:\n"}, {OUT=>"c:\n"}], + ['f', qw(-s -d:), '-f3-4', {IN=>"a:b:c:\n"}, {OUT=>"c:\n"}], + ['g', qw(-s -d:), '-f3,4', {IN=>"a:b:c:\n"}, {OUT=>"c:\n"}], + # Make sure -s suppresses non-delimited lines + ['h', qw(-s -d:), '-f2,3', {IN=>"abc\n"}, {OUT=>""}], + # + ['i', qw(-d: -f1-3), {IN=>":::\n"}, {OUT=>"::\n"}], + ['j', qw(-d: -f1-4), {IN=>":::\n"}, {OUT=>":::\n"}], + ['k', qw(-d: -f2-3), {IN=>":::\n"}, {OUT=>":\n"}], + ['l', qw(-d: -f2-4), {IN=>":::\n"}, {OUT=>"::\n"}], + ['m', qw(-s -d: -f1-3), {IN=>":::\n"}, {OUT=>"::\n"}], + ['n', qw(-s -d: -f1-4), {IN=>":::\n"}, {OUT=>":::\n"}], + ['o', qw(-s -d: -f2-3), {IN=>":::\n"}, {OUT=>":\n"}], + ['p', qw(-s -d: -f2-4), {IN=>":::\n"}, {OUT=>"::\n"}], + ['q', qw(-s -d: -f2-4), {IN=>":::\n:\n"}, {OUT=>"::\n\n"}], + ['r', qw(-s -d: -f2-4), {IN=>":::\n:1\n"}, {OUT=>"::\n1\n"}], + ['s', qw(-s -d: -f1-4), {IN=>":::\n:a\n"}, {OUT=>":::\n:a\n"}], + ['t', qw(-s -d: -f3-), {IN=>":::\n:1\n"}, {OUT=>":\n\n"}], + # Make sure it handles empty input properly, with and without -s. + ['u', qw(-s -f3-), {IN=>""}, {OUT=>""}], + ['v', '-f3-', {IN=>""}, {OUT=>""}], + # Make sure it handles empty input properly. + ['w', qw(-b 1), {IN=>""}, {OUT=>""}], + ['x', qw(-s -d: -f2-4), {IN=>":\n"}, {OUT=>"\n"}], + # Errors + # -s may be used only with -f + ['y', qw(-s -b4), {IN=>":\n"}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: suppressing non-delimited lines makes sense\n" + . "\tonly when operating on fields\n$try"}], + # You must specify bytes or fields (or chars) + ['z', '', {IN=>":\n"}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: you must specify a list of bytes, characters, or fields\n$try"} + ], + # Empty field list + ['empty-fl', qw(-f ''), {IN=>":\n"}, {OUT=>""}, {EXIT=>1}, + {ERR=>$from_field1}], + # Missing field list + ['missing-fl', qw(-f --), {IN=>":\n"}, {OUT=>""}, {EXIT=>1}, + {ERR=>$inval_fld}], + # Empty byte list + ['empty-bl', qw(-b ''), {IN=>":\n"}, {OUT=>""}, {EXIT=>1}, {ERR=>$from_pos1}], + # Missing byte list + ['missing-bl', qw(-b --), {IN=>":\n"}, {OUT=>""}, {EXIT=>1}, + {ERR=>$inval_pos}], + + # This test fails with cut from textutils-1.22. + ['empty-f1', '-f1', {IN=>""}, {OUT=>""}], + + ['empty-f2', '-f2', {IN=>""}, {OUT=>""}], + + ['o-delim', qw(-d: --out=_), '-f2,3', {IN=>"a:b:c\n"}, {OUT=>"b_c\n"}], + ['nul-idelim', qw(-d '' --out=_), '-f2,3', {IN=>"a\0b\0c\n"}, {OUT=>"b_c\n"}], + ['nul-odelim', qw(-d: --out=), '-f2,3', {IN=>"a:b:c\n"}, {OUT=>"b\0c\n"}], + ['multichar-od', qw(-d: --out=_._), '-f2,3', {IN=>"a:b:c\n"}, + {OUT=>"b_._c\n"}], + + # Ensure delim is not allowed without a field + # Prior to 8.21, a NUL delim was allowed without a field + ['delim-no-field1', qw(-d ''), '-b1', {EXIT=>1}, {ERR=>$nofield}], + ['delim-no-field2', qw(-d:), '-b1', {EXIT=>1}, {ERR=>$nofield}], + + # Prior to 1.22i, you couldn't use a delimiter that would sign-extend. + ['8bit-delim', '-d', "\255", '--out=_', '-f2,3', {IN=>"a\255b\255c\n"}, + {OUT=>"b_c\n"}], + + # newline processing for fields + ['newline-1', '-f1-', {IN=>"a\nb"}, {OUT=>"a\nb\n"}], + ['newline-2', '-f1-', {IN=>""}, {OUT=>""}], + ['newline-3', '-d:', '-f1', {IN=>"a:1\nb:2\n"}, {OUT=>"a\nb\n"}], + ['newline-4', '-d:', '-f1', {IN=>"a:1\nb:2"}, {OUT=>"a\nb\n"}], + ['newline-5', '-d:', '-f2', {IN=>"a:1\nb:2\n"}, {OUT=>"1\n2\n"}], + ['newline-6', '-d:', '-f2', {IN=>"a:1\nb:2"}, {OUT=>"1\n2\n"}], + ['newline-7', '-s', '-d:', '-f1', {IN=>"a:1\nb:2"}, {OUT=>"a\nb\n"}], + ['newline-8', '-s', '-d:', '-f1', {IN=>"a:1\nb:2\n"}, {OUT=>"a\nb\n"}], + ['newline-9', '-s', '-d:', '-f1', {IN=>"a1\nb2"}, {OUT=>""}], + ['newline-10', '-s', '-d:', '-f1,2', {IN=>"a:1\nb:2"}, {OUT=>"a:1\nb:2\n"}], + ['newline-11', '-s', '-d:', '-f1,2', {IN=>"a:1\nb:2\n"}, {OUT=>"a:1\nb:2\n"}], + ['newline-12', '-s', '-d:', '-f1', {IN=>"a:1\nb:"}, {OUT=>"a\nb\n"}], + ['newline-13', '-d:', '-f1-', {IN=>"a1:\n:"}, {OUT=>"a1:\n:\n"}], + # newline processing for fields when -d == '\n' + ['newline-14', "-d'\n'", '-f1', {IN=>"a:1\nb:"}, {OUT=>"a:1\n"}], + ['newline-15', '-s', "-d'\n'", '-f1', {IN=>"a:1\nb:"}, {OUT=>"a:1\n"}], + ['newline-16', '-s', "-d'\n'", '-f2', {IN=>"\nb"}, {OUT=>"b\n"}], + ['newline-17', '-s', "-d'\n'", '-f1', {IN=>"\nb"}, {OUT=>"\n"}], + ['newline-18', "-d'\n'", '-f2', {IN=>"\nb"}, {OUT=>"b\n"}], + ['newline-19', "-d'\n'", '-f1', {IN=>"\nb"}, {OUT=>"\n"}], + ['newline-20', '-s', "-d'\n'", '-f1-', {IN=>"\n"}, {OUT=>"\n"}], + ['newline-21', '-s', "-d'\n'", '-f1-', {IN=>"\nb"}, {OUT=>"\nb\n"}], + ['newline-22', "-d'\n'", '-f1-', {IN=>"\nb"}, {OUT=>"\nb\n"}], + ['newline-23', "-d'\n'", '-f1-', '--ou=:', {IN=>"a\nb\n"}, {OUT=>"a:b\n"}], + ['newline-24', "-d'\n'", '-f1,2', '--ou=:', {IN=>"a\nb\n"}, {OUT=>"a:b\n"}], + + # --zero-terminated + ['zerot-1', "-z", '-c1', {IN=>"ab\0cd\0"}, {OUT=>"a\0c\0"}], + ['zerot-2', "-z", '-c1', {IN=>"ab\0cd"}, {OUT=>"a\0c\0"}], + ['zerot-3', '-z -f1-', {IN=>""}, {OUT=>""}], + ['zerot-4', '-z -d:', '-f1', {IN=>"a:1\0b:2"}, {OUT=>"a\0b\0"}], + ['zerot-5', '-z -d:', '-f1-', {IN=>"a1:\0:"}, {OUT=>"a1:\0:\0"}], + ['zerot-6', "-z -d ''", '-f1,2', '--ou=:', {IN=>"a\0b\0"}, {OUT=>"a:b\0"}], + + # New functionality: + ['out-delim1', '-c1-3,5-', '--output-d=:', {IN=>"abcdefg\n"}, + {OUT=>"abc:efg\n"}], + # A totally overlapped field shouldn't change anything: + ['out-delim2', '-c1-3,2,5-', '--output-d=:', {IN=>"abcdefg\n"}, + {OUT=>"abc:efg\n"}], + # Partial overlap: index '2' is not at the start of a range. + ['out-delim3', '-c1-3,2-4,6', '--output-d=:', {IN=>"abcdefg\n"}, + {OUT=>"abcd:f\n"}], + ['out-delim3a', '-c1-3,2-4,6-', '--output-d=:', {IN=>"abcdefg\n"}, + {OUT=>"abcd:fg\n"}], + # Ensure that the following two commands produce the same output. + # Before an off-by-1 fix, the output from the former would not contain a ':'. + ['out-delim4', '-c4-,2-3', '--output-d=:', + {IN=>"abcdefg\n"}, {OUT=>"bc:defg\n"}], + ['out-delim5', '-c2-3,4-', '--output-d=:', + {IN=>"abcdefg\n"}, {OUT=>"bc:defg\n"}], + # This test would fail for cut from coreutils-5.0.1 and earlier. + ['out-delim6', '-c2,1-3', '--output-d=:', {IN=>"abc\n"}, {OUT=>"abc\n"}], + # + ['od-abut', '-b1-2,3-4', '--output-d=:', {IN=>"abcd\n"}, {OUT=>"ab:cd\n"}], + ['od-overlap', '-b1-2,2', '--output-d=:', {IN=>"abc\n"}, {OUT=>"ab\n"}], + ['od-overlap2', '-b1-2,2-', '--output-d=:', {IN=>"abc\n"}, {OUT=>"abc\n"}], + ['od-overlap3', '-b1-3,2-', '--output-d=:', {IN=>"abcd\n"}, {OUT=>"abcd\n"}], + ['od-overlap4', '-b1-3,2-3', '--output-d=:', {IN=>"abcd\n"}, {OUT=>"abc\n"}], + ['od-overlap5', '-b1-3,1-4', '--output-d=:', + {IN=>"abcde\n"}, {OUT=>"abcd\n"}], + + # None of the following invalid ranges provoked an error up to coreutils-6.9. + ['inval1', qw(-f 2-0), {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR=>"$prog: invalid decreasing range\n$try"}], + ['inval2', qw(-f -), {IN=>''}, {OUT=>''}, {EXIT=>1}, {ERR=>$no_endpoint}], + ['inval3', '-f', '4,-', {IN=>''}, {OUT=>''}, {EXIT=>1}, {ERR=>$no_endpoint}], + ['inval4', '-f', '1-2,-', {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR=>$no_endpoint}], + ['inval5', '-f', '1-,-', {IN=>''}, {OUT=>''}, {EXIT=>1}, {ERR=>$no_endpoint}], + ['inval6', '-f', '-1,-', {IN=>''}, {OUT=>''}, {EXIT=>1}, {ERR=>$no_endpoint}], + # This would evoke a segfault from 5.3.0..8.10 + ['big-unbounded-b', '--output-d=:', '-b1234567890-', {IN=>''}, {OUT=>''}], + ['big-unbounded-b2a', '--output-d=:', '-b1,9-', {IN=>'123456789'}, + {OUT=>"1:9\n"}], + ['big-unbounded-b2b', '--output-d=:', '-b1,1234567890-', {IN=>''}, {OUT=>''}], + ['big-unbounded-c', '--output-d=:', '-c1234567890-', {IN=>''}, {OUT=>''}], + ['big-unbounded-f', '--output-d=:', '-f1234567890-', {IN=>''}, {OUT=>''}], + + ['overlapping-unbounded-1', '-b3-,2-', {IN=>"1234\n"}, {OUT=>"234\n"}], + ['overlapping-unbounded-2', '-b2-,3-', {IN=>"1234\n"}, {OUT=>"234\n"}], + + # When printing output delimiters, and with one or more ranges subsumed + # by a to-EOL range, cut 8.20 and earlier would print extraneous delimiters. + ['EOL-subsumed-1', '--output-d=: -b2-,3,4-4,5', + {IN=>"123456\n"}, {OUT=>"23456\n"}], + ['EOL-subsumed-2', '--output-d=: -b3,4-4,5,2-', + {IN=>"123456\n"}, {OUT=>"23456\n"}], + ['EOL-subsumed-3', '--complement -b3,4-4,5,2-', + {IN=>"123456\n"}, {OUT=>"1\n"}], + ['EOL-subsumed-4', '--output-d=: -b1-2,2-3,3-', + {IN=>"1234\n"}, {OUT=>"1234\n"}], + ); + +if ($mb_locale ne 'C') + { + # Duplicate each test vector, appending "-mb" to the test name and + # inserting {ENV => "LC_ALL=$mb_locale"} in the copy, so that we + # provide coverage for the distro-added multi-byte code paths. + my @new; + foreach my $t (@Tests) + { + my @new_t = @$t; + my $test_name = shift @new_t; + + push @new, ["$test_name-mb", @new_t, {ENV => "LC_ALL=$mb_locale"}]; + } + push @Tests, @new; + } + + +@Tests = triple_test \@Tests; + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/date-debug.sh b/tests/misc/date-debug.sh new file mode 100755 index 0000000..0b52176 --- /dev/null +++ b/tests/misc/date-debug.sh @@ -0,0 +1,301 @@ +#!/bin/sh +# Test 'date --debug' option. + +# Copyright (C) 2016-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ date + +export LC_ALL=C + +## Ensure timezones are supported. +## (NOTE: America/Belize timezone does not change on DST) +test "$(TZ=America/Belize date +%z)" = '-0600' \ + || skip_ 'Timezones database not found' + +date --debug >/dev/null 2>d_t_fmt.err || fail=1 +d_t_fmt=$(sed -n "s/.*'\(.*\)'$/\1/p" < d_t_fmt.err) || framework_failure_ +test -n "$d_t_fmt" || fail=1 + +## +## Test 1: complex date string +## +in1='TZ="Asia/Tokyo" Sun, 90-12-11 + 3 days - 90 minutes' + +cat<<EOF>exp1 +date: parsed day part: Sun (day ordinal=0 number=0) +date: parsed date part: (Y-M-D) 0090-12-11 +date: parsed relative part: +3 day(s) +date: parsed relative part: +3 day(s) -90 minutes +date: input timezone: TZ="Asia/Tokyo" in date string +date: warning: adjusting year value 90 to 1990 +date: warning: using midnight as starting time: 00:00:00 +date: warning: day (Sun) ignored when explicit dates are given +date: starting date/time: '(Y-M-D) 1990-12-11 00:00:00' +date: warning: when adding relative days, it is recommended to specify noon +date: after date adjustment (+0 years, +0 months, +3 days), +date: new date/time = '(Y-M-D) 1990-12-14 00:00:00' +date: '(Y-M-D) 1990-12-14 00:00:00' = 661100400 epoch-seconds +date: after time adjustment (+0 hours, -90 minutes, +0 seconds, +0 ns), +date: new time = 661095000 epoch-seconds +date: timezone: TZ="Asia/Tokyo" environment value +date: final: 661095000.000000000 (epoch-seconds) +date: final: (Y-M-D) 1990-12-13 13:30:00 (UTC) +date: final: (Y-M-D) 1990-12-13 22:30:00 (UTC+09) +date: output format: '%a %b %e %T %z %Y' +Thu Dec 13 07:30:00 -0600 1990 +EOF + +TZ=America/Belize date --debug -d "$in1" +'%a %b %e %T %z %Y' >out1 2>&1 || + fail=1 + +compare exp1 out1 || fail=1 + +## +## Test 2: Invalid date from Coreutils' FAQ +## (with explicit timezone added) +in2='TZ="America/Edmonton" 2006-04-02 02:30:00' +cat<<EOF>exp2 +date: parsed date part: (Y-M-D) 2006-04-02 +date: parsed time part: 02:30:00 +date: input timezone: TZ="America/Edmonton" in date string +date: using specified time as starting value: '02:30:00' +date: error: invalid date/time value: +date: user provided time: '(Y-M-D) 2006-04-02 02:30:00' +date: normalized time: '(Y-M-D) 2006-04-02 XX:XX:XX' +date: -- +date: possible reasons: +date: non-existing due to daylight-saving time; +date: numeric values overflow; +date: missing timezone +date: invalid date 'TZ="America/Edmonton" 2006-04-02 02:30:00' +EOF + +# date should return 1 (error) for invalid date +returns_ 1 date --debug -d "$in2" >out2-t 2>&1 || fail=1 + +# The output line of "normalized time" can differ between systems +# (e.g. glibc vs musl) and should not be checked. +# See: https://lists.gnu.org/archive/html/coreutils/2019-05/msg00039.html +sed '/normalized time:/s/ [0-9][0-9]:[0-9][0-9]:[0-9][0-9]/ XX:XX:XX/' \ + out2-t > out2 || framework_failure_ + +compare exp2 out2 || fail=1 + +## +## Test 3: timespec (input always UTC, output is TZ-dependent) +## +in3='@1' +cat<<EOF>exp3 +date: parsed number of seconds part: number of seconds: 1 +date: input timezone: '@timespec' - always UTC +date: timezone: TZ="America/Lima" environment value +date: final: 1.000000000 (epoch-seconds) +date: final: (Y-M-D) 1970-01-01 00:00:01 (UTC) +date: final: (Y-M-D) 1969-12-31 19:00:01 (UTC-05) +date: output format: '%a %b %e %T %z %Y' +Wed Dec 31 19:00:01 -0500 1969 +EOF + +TZ=America/Lima date --debug -d "$in3" +'%a %b %e %T %z %Y' >out3 2>&1 || fail=1 +compare exp3 out3 || fail=1 + +## +## Parsing a lone number. +## Fixed in gnulib v0.1-1099-gf2d4b5c +## https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=f2d4b5caa +cat<<EOF>exp4 +date: parsed number part: (Y-M-D) 2013-01-01 +date: input timezone: TZ="UTC0" environment value or -u +date: warning: using midnight as starting time: 00:00:00 +date: starting date/time: '(Y-M-D) 2013-01-01 00:00:00' +date: '(Y-M-D) 2013-01-01 00:00:00' = 1356998400 epoch-seconds +date: timezone: Universal Time +date: final: 1356998400.000000000 (epoch-seconds) +date: final: (Y-M-D) 2013-01-01 00:00:00 (UTC) +date: final: (Y-M-D) 2013-01-01 00:00:00 (UTC+00) +date: output format: '$d_t_fmt' +Tue Jan 1 00:00:00 UTC 2013 +EOF + +date -u --debug -d '20130101' >out4 2>&1 || fail=1 +compare exp4 out4 || fail=1 + + +## +## Parsing a relative number after a timezone string +## Fixed in gnulib v0.1-1100-g5c438e8 +## https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=5c438e8ce7d +cat<<EOF>exp5 +date: parsed date part: (Y-M-D) 2013-10-30 +date: parsed time part: 00:00:00 +date: parsed relative part: -8 day(s) +date: parsed zone part: UTC+00 +date: input timezone: parsed date/time string (+00) +date: using specified time as starting value: '00:00:00' +date: starting date/time: '(Y-M-D) 2013-10-30 00:00:00 TZ=+00' +date: warning: when adding relative days, it is recommended to specify noon +date: after date adjustment (+0 years, +0 months, -8 days), +date: new date/time = '(Y-M-D) 2013-10-22 00:00:00 TZ=+00' +date: '(Y-M-D) 2013-10-22 00:00:00 TZ=+00' = 1382400000 epoch-seconds +date: timezone: Universal Time +date: final: 1382400000.000000000 (epoch-seconds) +date: final: (Y-M-D) 2013-10-22 00:00:00 (UTC) +date: final: (Y-M-D) 2013-10-22 00:00:00 (UTC+00) +date: output format: '%F' +2013-10-22 +EOF + +in5='2013-10-30 00:00:00 UTC -8 days' +date -u --debug +%F -d "$in5" >out5 2>&1 || fail=1 +compare exp5 out5 || fail=1 + +## +## Explicitly warn about unexpected day/month shifts. +## added in gnulib v0.1-1101-gf14eff1 +## https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=f14eff1b3cde2b +TOOLONG='it is recommended to specify the 15th of the months' +cat<<EOF>exp6 +date: parsed date part: (Y-M-D) 2016-10-31 +date: parsed relative part: -1 month(s) +date: input timezone: TZ="UTC0" environment value or -u +date: warning: using midnight as starting time: 00:00:00 +date: starting date/time: '(Y-M-D) 2016-10-31 00:00:00' +date: warning: when adding relative months/years, $TOOLONG +date: after date adjustment (+0 years, -1 months, +0 days), +date: new date/time = '(Y-M-D) 2016-10-01 00:00:00' +date: warning: month/year adjustment resulted in shifted dates: +date: adjusted Y M D: 2016 09 31 +date: normalized Y M D: 2016 10 01 +date: '(Y-M-D) 2016-10-01 00:00:00' = 1475280000 epoch-seconds +date: timezone: Universal Time +date: final: 1475280000.000000000 (epoch-seconds) +date: final: (Y-M-D) 2016-10-01 00:00:00 (UTC) +date: final: (Y-M-D) 2016-10-01 00:00:00 (UTC+00) +date: output format: '$d_t_fmt' +Sat Oct 1 00:00:00 UTC 2016 +EOF + +date -u --debug -d '2016-10-31 - 1 month' >out6 2>&1 || fail=1 +compare exp6 out6 || fail=1 + + +## +## Explicitly warn about crossing DST boundaries. +## added in gnulib v0.1-1102-g30a55dd +## https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=30a55dd72dad2 +TOOLONG2='it is recommended to specify the 15th of the months' +cat<<EOF>exp7 +date: parsed date part: (Y-M-D) 2016-06-01 +date: parsed local_zone part: isdst=1 +date: parsed relative part: +6 month(s) +date: input timezone: TZ="America/New_York" environment value, dst +date: warning: using midnight as starting time: 00:00:00 +date: starting date/time: '(Y-M-D) 2016-06-01 00:00:00' +date: warning: when adding relative months/years, $TOOLONG2 +date: after date adjustment (+0 years, +6 months, +0 days), +date: new date/time = '(Y-M-D) 2016-11-30 23:00:00' +date: warning: daylight saving time changed after date adjustment +date: warning: month/year adjustment resulted in shifted dates: +date: adjusted Y M D: 2016 12 01 +date: normalized Y M D: 2016 11 30 +date: '(Y-M-D) 2016-11-30 23:00:00' = 1480564800 epoch-seconds +date: timezone: TZ="America/New_York" environment value +date: final: 1480564800.000000000 (epoch-seconds) +date: final: (Y-M-D) 2016-12-01 04:00:00 (UTC) +date: final: (Y-M-D) 2016-11-30 23:00:00 (UTC-05) +date: output format: '%F' +2016-11-30 +EOF + +in7='2016-06-01 EDT + 6 months' +TZ=America/New_York date --debug -d "$in7" +%F >out7 2>&1 || fail=1 +compare exp7 out7 || fail=1 + + +## fix local timezone debug messages. +## fixed in git v0.1-1103-gc56e7fb +## https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=c56e7fbb032 + +cat<<EOF>exp8_1 +date: parsed date part: (Y-M-D) 2011-12-11 +date: parsed local_zone part: isdst=0 +date: input timezone: TZ="Europe/Helsinki" environment value +date: warning: using midnight as starting time: 00:00:00 +date: starting date/time: '(Y-M-D) 2011-12-11 00:00:00' +date: '(Y-M-D) 2011-12-11 00:00:00' = 1323554400 epoch-seconds +date: timezone: TZ="Europe/Helsinki" environment value +date: final: 1323554400.000000000 (epoch-seconds) +date: final: (Y-M-D) 2011-12-10 22:00:00 (UTC) +date: final: (Y-M-D) 2011-12-11 00:00:00 (UTC+02) +date: output format: '$d_t_fmt' +Sun Dec 11 00:00:00 EET 2011 +EOF + +TZ=Europe/Helsinki date --debug -d '2011-12-11 EET' >out8_1 2>&1 || fail=1 +compare exp8_1 out8_1 || fail=1 + +cat<<EOF>exp8_2 +date: parsed date part: (Y-M-D) 2011-06-11 +date: parsed local_zone part: isdst=1 +date: input timezone: TZ="Europe/Helsinki" environment value, dst +date: warning: using midnight as starting time: 00:00:00 +date: starting date/time: '(Y-M-D) 2011-06-11 00:00:00' +date: '(Y-M-D) 2011-06-11 00:00:00' = 1307739600 epoch-seconds +date: timezone: TZ="Europe/Helsinki" environment value +date: final: 1307739600.000000000 (epoch-seconds) +date: final: (Y-M-D) 2011-06-10 21:00:00 (UTC) +date: final: (Y-M-D) 2011-06-11 00:00:00 (UTC+03) +date: output format: '$d_t_fmt' +Sat Jun 11 00:00:00 EEST 2011 +EOF + +TZ=Europe/Helsinki date --debug -d '2011-06-11 EEST' >out8_2 2>&1 || fail=1 +compare exp8_2 out8_2 || fail=1 + + + +## fix debug message on lone year number (The "2011" part). +## fixed in gnulib v0.1-1104-g15b8f30 +## https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=15b8f3046a25 +## +## NOTE: +## When the date 'Apr 11' is parsed, the year part will be the +## current year. The expected output thus depends on the year +## the test is being run. We'll use sed to change it to XXXX. +cat<<EOF>exp9 +date: parsed date part: (Y-M-D) XXXX-04-11 +date: parsed time part: 22:59:00 +date: parsed number part: year: 2011 +date: input timezone: TZ="UTC0" environment value or -u +date: using specified time as starting value: '22:59:00' +date: starting date/time: '(Y-M-D) 2011-04-11 22:59:00' +date: '(Y-M-D) 2011-04-11 22:59:00' = 1302562740 epoch-seconds +date: timezone: Universal Time +date: final: 1302562740.000000000 (epoch-seconds) +date: final: (Y-M-D) 2011-04-11 22:59:00 (UTC) +date: final: (Y-M-D) 2011-04-11 22:59:00 (UTC+00) +date: output format: '$d_t_fmt' +Mon Apr 11 22:59:00 UTC 2011 +EOF + +date -u --debug -d 'Apr 11 22:59:00 2011' >out9_t 2>&1 || fail=1 +sed '1s/(Y-M-D) [0-9][0-9][0-9][0-9]-/(Y-M-D) XXXX-/' out9_t > out9 \ + || framework_failure_ +compare exp9 out9 || fail=1 + + +Exit $fail diff --git a/tests/misc/date-next-dow.pl b/tests/misc/date-next-dow.pl new file mode 100755 index 0000000..8761c71 --- /dev/null +++ b/tests/misc/date-next-dow.pl @@ -0,0 +1,78 @@ +#!/usr/bin/perl +# Test "date". + +# Copyright (C) 2005-2022 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 <https://www.gnu.org/licenses/>. + +use strict; +use POSIX qw(strftime); + +(my $ME = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# Export TZ=UTC0 so that zone-dependent strings match. +$ENV{TZ} = 'UTC0'; + +my $now = time; +my @d = localtime ($now); +my @d_week = localtime ($now + 7 * 24 * 3600); +my $wday = $d[6]; +my $wday_str = qw(sun mon tue wed thu fri sat)[$wday]; + +my @Tests = + ( + # test-name, [option, option, ...] {OUT=>"expected-output"} + # + + # Running "date -d mon +%a" on a Monday must print Mon. + ['dow', "-d $wday_str +%a", {OUT => ucfirst $wday_str}], + # It had better be the same date, too. + ['dow2', "-d $wday_str +%Y-%m-%d", {OUT => strftime("%Y-%m-%d", @d)}], + + ['next-dow', "-d 'next $wday_str' +%Y-%m-%d", + {OUT => strftime("%Y-%m-%d", @d_week)}], + ); + +# Append "\n" to each OUT=> RHS if the expected exit value is either +# zero or not specified (defaults to zero). +foreach my $t (@Tests) + { + my $exit_val; + foreach my $e (@$t) + { + ref $e && ref $e eq 'HASH' && defined $e->{EXIT} + and $exit_val = $e->{EXIT}; + } + foreach my $e (@$t) + { + ref $e && ref $e eq 'HASH' && defined $e->{OUT} && ! $exit_val + and $e->{OUT} .= "\n"; + } + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'date'; +my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose); + +# Skip the test if the starting and stopping day numbers differ. +my @d_post = localtime (time); +$d_post[7] == $d[7] + or CuSkip::skip "$ME: test straddled a day boundary; skipped"; + +exit $fail; diff --git a/tests/misc/date-sec.sh b/tests/misc/date-sec.sh new file mode 100755 index 0000000..fdd5105 --- /dev/null +++ b/tests/misc/date-sec.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# Ensure that a command like +# date --date="21:04 +0100" +%S' always prints '00'. +# Before coreutils-5.2.1, it would print the seconds from the current time. + +# Copyright (C) 2004-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ date + + + +# It would be easier simply to sleep for two seconds between two runs +# of $(date --date="21:04 +0100" +%S) and ensure that both outputs +# are '00', but I prefer not to sleep unconditionally. 'make check' +# takes long enough as it is. + +n=0 +# See if the current number of seconds is '00' or just before. +s=$(date +%S) +case "$s" in + 58) n=3;; + 59) n=2;; + 00) n=1;; +esac + +# If necessary, wait for the system clock to pass the minute mark. +test $n = 0 || sleep $n + +s=$(date --date="21:04 +0100" +%S) +case "$s" in + 00) ;; + *) fail=1;; +esac + +Exit $fail diff --git a/tests/misc/date-tz.sh b/tests/misc/date-tz.sh new file mode 100755 index 0000000..ac17f7e --- /dev/null +++ b/tests/misc/date-tz.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Verify TZ processing. + +# Copyright (C) 2017-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ date + +# coreutils-8.27 would overwrite the heap with large TZ values +tz_long=$(printf '%2000s' | tr ' ' a) +date -d "TZ=\"${tz_long}0\" 2017" || fail=1 + +Exit $fail diff --git a/tests/misc/date.pl b/tests/misc/date.pl new file mode 100755 index 0000000..f40a377 --- /dev/null +++ b/tests/misc/date.pl @@ -0,0 +1,381 @@ +#!/usr/bin/perl +# Test "date". + +# Copyright (C) 2005-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $ME = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# Export TZ=UTC0 so that zone-dependent strings match. +$ENV{TZ} = 'UTC0'; + +my $t0 = '08:17:48'; +my $d0 = '1997-01-19'; +my $d1 = "$d0 $t0 +0"; +my $dT = "${d0}T$t0+0"; # ISO 8601 with "T" separator + +my $ts = '08:17:49'; # next second +my $tm = '08:18:48'; # next minute +my $th = '09:17:48'; # next hour + +my $dd = '1997-01-20'; # next day +my $dw = '1997-01-26'; # next week +my $dm = '1997-02-19'; # next month +my $dy = '1998-01-19'; # next month + +my $fmt = "'+%Y-%m-%d %T'"; + +my @Tests = + ( + # test-name, [option, option, ...] {OUT=>"expected-output"} + # + ['1', "-d '$d1' +'%% %a %A %b %B'", {OUT=>"% Sun Sunday Jan January"}], + + # [Actually, skip it on *all* systems. -- this Perl code is run at + # distribution-build-time, not at configure/test time. ] + + # Skip the test of %c on SunOS4 systems. Such systems would fail this + # test because their underlying strftime doesn't handle the %c format + # properly. GNU strftime must rely on the underlying host library + # function to get locale-dependent behavior, as strftime is the only + # portable interface to that behavior. + # ['2', "-d '$d1' +'%c'", {OUT=>"Sun Jan 19 $t0 1997"}], + + ['3', "-d '$d1' +'%d_%D_%e_%h_%H'", {OUT=>"19_01/19/97_19_Jan_08"}], + ['3T',"-d '$dT' +'%d_%D_%e_%h_%H'", {OUT=>"19_01/19/97_19_Jan_08"}], + + ['4', "-d '$d1' +'%I_%j_%k_%l_%m'", {OUT=>"08_019_ 8_ 8_01"}], + ['5', "-d '$d1' +'%M_%n_%p_%r'", {OUT=>"17_\n_AM_$t0 AM"}], + ['6', "-d '$d1' +'%s_%S_%t_%T'", {OUT=>"853661868_48_\t_$t0"}], + ['7', "-d '$d1' +'%U_%V_%w_%W'", {OUT=>"03_03_0_02"}], + ['8', "-d '$d1' +'%x_%X_%y_%Y'", {OUT=>"01/19/97_${t0}_97_1997"}], + ['9', "-d '$d1' +'%z'", {OUT=>"+0000"}], + + ['leap-1', "--date '02/29/1996 1 year' +%Y-%m-%d", {OUT=>"1997-03-01"}], + + ['U95-1', "--date '1995-1-1' +%U", {OUT=>"01"}], + ['U95-2', "--date '1995-1-7' +%U", {OUT=>"01"}], + ['U95-3', "--date '1995-1-8' +%U", {OUT=>"02"}], + + ['U92-1', "--date '1992-1-1' +%U", {OUT=>"00"}], + ['U92-2', "--date '1992-1-4' +%U", {OUT=>"00"}], + ['U92-3', "--date '1992-1-5' +%U", {OUT=>"01"}], + + ['V92-1', "--date '1992-1-1' +%V", {OUT=>"01"}], + ['V92-2', "--date '1992-1-5' +%V", {OUT=>"01"}], + ['V92-3', "--date '1992-1-6' +%V", {OUT=>"02"}], + + ['W92-1', "--date '1992-1-1' +%W", {OUT=>"00"}], + ['W92-2', "--date '1992-1-5' +%W", {OUT=>"00"}], + ['W92-3', "--date '1992-1-6' +%W", {OUT=>"01"}], + + ['q-1', "--date '2016-1-1' +%q", {OUT=>"1"}], + ['q-2', "--date '2016-4-1' +%q", {OUT=>"2"}], + ['q-3', "--date '2016-7-1' +%q", {OUT=>"3"}], + ['q-4', "--date '2016-10-1' +%q", {OUT=>"4"}], + + ['millen-1', "--date '1998-1-1 3 years' +%Y", {OUT=>"2001"}], + + ['rel-0', "-d '$d1 now' '+%Y-%m-%d %T'", {OUT=>"$d0 $t0"}], + + ['rel-1a', "-d '$d1 yesterday' $fmt", {OUT=>"1997-01-18 $t0"}], + ['rel-1b', "-d '$d1 tomorrow' $fmt", {OUT=>"1997-01-20 $t0"}], + + ['rel-2a', "-d '$d1 6 years ago' $fmt", {OUT=>"1991-01-19 $t0"}], + ['rel-2b', "-d '$d1 7 months ago' $fmt", {OUT=>"1996-06-19 $t0"}], + ['rel-2c', "-d '$d1 8 weeks ago' $fmt", {OUT=>"1996-11-24 $t0"}], + ['rel-2d', "-d '$d1 1 day ago' $fmt", {OUT=>"1997-01-18 $t0"}], + ['rel-2e', "-d '$d1 2 hours ago' $fmt", {OUT=>"$d0 06:17:48"}], + ['rel-2f', "-d '$d1 3 minutes ago' $fmt", {OUT=>"$d0 08:14:48"}], + ['rel-2g', "-d '$d1 4 seconds ago' $fmt", {OUT=>"$d0 08:17:44"}], + + ['rel-3a', "-d '$d1 4 seconds ago' $fmt", {OUT=>"$d0 08:17:44"}], + + # This has always worked, ... + ['rel-1day', "-d '20050101 1 day' +%F", {OUT=>"2005-01-02"}], + # ...but up to coreutils-6.9, this was rejected due to the "+". + ['rel-plus1', "-d '20050101 +1 day' +%F", {OUT=>"2005-01-02"}], + + ['next-s', "-d '$d1 next second' '+%Y-%m-%d %T'", {OUT=>"$d0 $ts"}], + ['next-m', "-d '$d1 next minute' '+%Y-%m-%d %T'", {OUT=>"$d0 $tm"}], + ['next-h', "-d '$d1 next hour' '+%Y-%m-%d %T'", {OUT=>"$d0 $th"}], + ['next-d', "-d '$d1 next day' '+%Y-%m-%d %T'", {OUT=>"$dd $t0"}], + ['next-w', "-d '$d1 next week' '+%Y-%m-%d %T'", {OUT=>"$dw $t0"}], + ['next-mo', "-d '$d1 next month' '+%Y-%m-%d %T'", {OUT=>"$dm $t0"}], + ['next-y', "-d '$d1 next year' '+%Y-%m-%d %T'", {OUT=>"$dy $t0"}], + + ['utc-0', "-u -d '08/01/97 6:00' '+%D,%H:%M'", {OUT=>"08/01/97,06:00"}, + {ENV => 'TZ=UTC+4'}], + + ['utc-0a', "-u -d '08/01/97 6:00 UTC +4 hours' '+%D,%H:%M'", + {OUT=>"08/01/97,10:00"}], + # Make sure --file=FILE works with -u. + ['utc-1', "-u --file=f '+%Y-%m-%d %T'", + {AUX=>{f=>"$d0 $t0\n$d0 $t0"}}, + {OUT=>"$d0 $t0\n$d0 $t0"}, + {ENV => 'TZ=UTC+1'}], + + ['utc-1a', "-u --file=f '+%Y-%m-%d %T'", + {AUX=>{f=>"$d0 $t0 UTC +1 hour\n$d0 $t0 UTC +1 hour"}}, + {OUT=>"$d0 $th\n$d0 $th"}], + + # From the examples in the documentation. + ['date2sec-0', "-d '1970-01-01 00:00:01' +%s", {OUT=>"7201"}, + {ENV => 'TZ=UTC+2'}], + + # Same as above, but don't rely on TZ in environment. + ['date2sec-0a', "-d '1970-01-01 00:00:01 UTC +2 hours' +%s", + {OUT=>"7201"}], + + ['date2sec-1', "-d 2000-01-01 +%s", {OUT=>"946684800"}], + ['sec2date-0', "-d '1970-01-01 UTC 946684800 sec' +'%Y-%m-%d %T %z'", + {OUT=>"2000-01-01 00:00:00 +0000"}], + + ['this-m', "-d '$d0 $t0 this minute' $fmt", {OUT=>"$d0 $t0"}], + ['this-h', "-d '$d0 $t0 this hour' $fmt", {OUT=>"$d0 $t0"}], + ['this-w', "-d '$d0 $t0 this week' $fmt", {OUT=>"$d0 $t0"}], + ['this-mo', "-d '$d0 $t0 this month' $fmt", {OUT=>"$d0 $t0"}], + ['this-y', "-d '$d0 $t0 this year' $fmt", {OUT=>"$d0 $t0"}], + + ['risks-1', "-d 'Nov 10 1996' $fmt", {OUT=>"1996-11-10 00:00:00"}], + + # This one would pass if TZ (with any, or even no, value) were in + # the environment. + ['regress-1', "-u -d '1996-11-10 0:00:00 +0' $fmt", + {OUT=>"1996-11-10 00:00:00"}, + {ENV =>'LANG=C'}], + + + ['datevtime-1', "-d 000909 $fmt", {OUT=>"2000-09-09 00:00:00"}], + + # test for RFC-822 conformance + ['rfc822-1', "-R -d '$d1'", {OUT=>"Sun, 19 Jan 1997 08:17:48 +0000"}, + # Solaris 5.9's /bin/sh emits this diagnostic to stderr + # if you don't have support for the named locale. + {ERR_SUBST => q!s/^couldn't set locale correctly\n//!}, + {ENV => 'LC_ALL=de_DE TZ=UTC0'}], + + # Relative seconds, with time. fixed in 2.0j + ['relative-1', "--utc -d '1970-01-01 00:00:00 UTC +961062237 sec' $fmt", + {OUT=>"2000-06-15 09:43:57"}], + + # Relative seconds, no time. + ['relative-2', "--utc -d '1970-01-01 UTC +961062237 sec' $fmt", + {OUT=>"2000-06-15 09:43:57"}, + {ENV => 'TZ=UTC+1'}], + + # Relative days, no time, across time zones. + ['relative-3', "-I -d '2006-04-23 21 days ago'", {OUT=>"2006-04-02"}, + {ENV=>'TZ=PST8PDT,M4.1.0,M10.5.0'}], + + # This would infloop (or appear to) prior to coreutils-4.5.5, + # due to a bug in strftime.c. + ['wide-fmt', "-d '1999-06-01'", '+%3004Y', {OUT=>'0' x 3000 . "1999"}], + + # Ensure that we can parse MONTHNAME-DAY-YEAR. + ['moname-d-y', '--iso -d May-23-2003', {OUT=>"2003-05-23"}], + ['moname-d-y-r', '--rfc-3339=date -d May-23-2003', {OUT=>"2003-05-23"}], + + ['epoch', '--iso=sec -d @31536000', + {OUT=>"1971-01-01T00:00:00+00:00"}], + ['epoch-r', '--rfc-3339=sec -d @31536000', + {OUT=>"1971-01-01 00:00:00+00:00"}], + + ['ns-10', '--iso=ns', '-d "1969-12-31 13:00:00.00000001-1100"', + {OUT=>"1970-01-01T00:00:00,000000010+00:00"}], + ['ns-10-r', '--rfc-3339=ns', '-d "1969-12-31 13:00:00.00000001-1100"', + {OUT=>"1970-01-01 00:00:00.000000010+00:00"}], + + ['ns-max32', '--iso=ns', '-d "2038-01-19 03:14:07.999999999"', + {OUT=>"2038-01-19T03:14:07,999999999+00:00"}], + ['ns-max32-r', '--rfc-3339=ns', '-d "2038-01-19 03:14:07.999999999"', + {OUT=>"2038-01-19 03:14:07.999999999+00:00"}], + + ['tz-1', '+%:::z', {OUT=>"-12:34:56"}, {ENV=>'TZ=XXX12:34:56'}], + + ['tz-2', '+%:::z', {OUT=>"+12:34:56"}, {ENV=>'TZ=XXX-12:34:56'}], + + ['tz-3', '+%::z', {OUT=>"+01:02:03"}, {ENV=>'TZ=XXX-1:02:03'}], + + ['tz-4', '+%:::z', {OUT=>"+12"}, {ENV=>'TZ=XXX-12'}], + + ['tz-5', '+%:z', {OUT=>"-00:01"}, {ENV=>'TZ=XXX0:01'}], + + # Accept %:z with a field width before the ':'. + ['tz-5w','+%8:z', {OUT=>"-0000:01"}, {ENV=>'TZ=XXX0:01'}], + # Don't recognize %:z with a field width between the ':' and the 'z'. + ['tz-5wf', '+%:8z', {OUT=>"%:8z"}, {ENV=>'TZ=XXX0:01'}], + + # Test alphabetic timezone abbrv + ['tz-6', '+%Z', {OUT=>"UTC"}], + ['tz-7', '+%Z', {OUT=>"JST"}, {ENV=>'TZ=JST-9'}], + + ['ns-relative', + '--iso=ns', + "-d'1970-01-01 00:00:00.1234567 UTC +961062237.987654321 sec'", + {OUT=>"2000-06-15T09:43:58,111111021+00:00"}], + ['ns-relativer', '--rfc-3339=ns', + "-d'1970-01-01 00:00:00.1234567 UTC +961062237.987654321 sec'", + {OUT=>"2000-06-15 09:43:58.111111021+00:00"}], + + # Since coreutils/lib/getdate.y revision 1.96 (post-coreutils-5.3.0), + # a command like the following would mistakenly exit nonzero with an + # 'invalid date ...' diagnostic, but when run in a time zone for + # which daylight savings time is in effect for the starting date. + # Unfortunately (for ease of testing), if you set TZ at all, this + # failure is not triggered, hence the removal of TZ from the environment. + ['cross-dst', "-d'2005-03-27 +1 day'", '+%Y', {OUT=>"2005"}, + {ENV_DEL => 'TZ'}, + ], + + ['empty-fmt', '+', {OUT=>""}], + + ['neg-secs', '-d @-22 +%05s', {OUT=>"-0022"}], + ['neg-secs2', '-d @-22 +%_5s', {OUT=>" -22"}], + + # FIXME: Ensure date doesn't print uninitialized data + # for an out-of-range date. This test is currently + # disabled as various systems have different limits + # for localtime(), and we can't use perl for example + # to determine those limits as it doesn't always call + # down to the system localtime() as it has configure + # time checks and settings itself for these limits. + #['uninit-64', "-d \@72057594037927935", + # {OUT=>''}, + # # Use ERR_SUBST to get around fact that the diagnostic + # # you get on a system with 32-bit time_t is not the same as + # # the one you get for a system where it's 64 bits wide: + # # - date: time 72057594037927935 is out of range + # # + date: invalid date '@72057594037927935' + # {ERR_SUBST => 's/.*//'}, + # {ERR => "\n"}, + # {EXIT => 1}, + #], + + ['fill-1', '-d 1999-12-08 +%_3d', {OUT=>' 8'}], + ['fill-2', '-d 1999-12-08 +%03d', {OUT=>'008'}], + + # Test the combination of the to-upper-case modifier (^) and a conversion + # specifier that expands to a string containing lower case characters. + ['subfmt-up1', '-d "1999-12-08 7:30" "+%^c"', + # Solaris 5.9 prints 'WED DEC 08 07:30:00 1999', while + # most others print 'WED DEC 8 07:30:00 1999'. + {OUT_SUBST => 's/ [ 0]8.*//'}, + {OUT=>'WED DEC'}], + + ['invalid-high-bit-set', "-d '\xb0'", + {ERR => "date: invalid date '\\260'\n"}, + {EXIT => 1}, + ], + + # From coreutils-5.3.0 to 8.22 inclusive + # this would either infinite loop or crash + ['invalid-TZ-crash', "-d 'TZ=\"\"\"'", + {ERR => "date: invalid date 'TZ=\"\"\"'\n"}, + {EXIT => 1}, + ], + + # https://bugs.debian.org/851934#10 + ['cross-TZ-mishandled', "-d 'TZ=\"EST5\" 1970-01-01 00:00'", + {ENV => 'TZ=PST8'}, + {OUT => 'Wed Dec 31 21:00:00 PST 1969'}, + ], + + # https://bugs.gnu.org/34608 + ['date-century-plus', '-d @0 +.%+4C.', {OUT => '.+019.'}], + + # https://bugs.gnu.org/50115 + ['date-epoch-minus-1', '-u -d "1970-12-31T23:59:59+00:00 - 1 year"', + {OUT => 'Wed Dec 31 23:59:59 UTC 1969'}], + + # Military time zones, new behavior (since 8.32) + # https://lists.gnu.org/r/bug-gnulib/2019-08/msg00005.html + ['mtz1', '-u -d "09:00B" +%T', {OUT => '07:00:00'}], + ['mtz2', '-u -d "09:00L" +%T', {OUT => '22:00:00'}], + ['mtz3', '-u -d "09:00N" +%T', {OUT => '10:00:00'}], + ['mtz4', '-u -d "09:00T" +%T', {OUT => '16:00:00'}], + ['mtz5', '-u -d "09:00X" +%T', {OUT => '20:00:00'}], + ['mtz6', '-u -d "09:00Z" +%T', {OUT => '09:00:00'}], + + # test with %%-N + ['pct-pct', '+%%-N', {OUT => '%-N'}], + ); + +# Repeat the cross-dst test, using Jan 1, 2005 and every interval from 1..364. +foreach my $i (1..364) + { + push @Tests, ["cross-dst$i", + "-d'2005-01-01 +$i day'", '+%Y', {OUT=>"2005"}, + {ENV_DEL => 'TZ'}, + ]; + } + +# Append "\n" to each OUT=> RHS if the expected exit value is either +# zero or not specified (defaults to zero). +foreach my $t (@Tests) + { + my $exit_val; + foreach my $e (@$t) + { + ref $e && ref $e eq 'HASH' && defined $e->{EXIT} + and $exit_val = $e->{EXIT}; + } + foreach my $e (@$t) + { + ref $e && ref $e eq 'HASH' && defined $e->{OUT} && ! $exit_val + and $e->{OUT} .= "\n"; + } + } + +# Repeat all tests with --debug option, ensure it does not cause any regression +my @debug_tests; +foreach my $t (@Tests) + { + # Skip tests with EXIT!=0 or ERR_SUBST part + # (as '--debug' requires its own ERR_SUBST). + my $exit_val; + my $have_err_subst; + foreach my $e (@$t) + { + next unless ref $e && ref $e eq 'HASH'; + $exit_val = $e->{EXIT} if defined $e->{EXIT}; + $have_err_subst = 1 if defined $e->{ERR_SUBST}; + } + next if $exit_val || $have_err_subst; + + # Duplicate the test, add '--debug' argument + my @newt = @$t; + $newt[0] = 'dbg_' . $newt[0]; + $newt[1] = '--debug ' . $newt[1]; + + # Discard all debug printouts before comparing output + push @newt, {ERR_SUBST => q!s/^date: .*\n//m!}; + + push @debug_tests, \@newt; + } +push @Tests, @debug_tests; + + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'date'; +my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/dircolors.pl b/tests/misc/dircolors.pl new file mode 100755 index 0000000..6bb8b74 --- /dev/null +++ b/tests/misc/dircolors.pl @@ -0,0 +1,76 @@ +#!/usr/bin/perl +# Simple dircolors tests. + +# Copyright (C) 1998-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + ['a', '-b', {IN => {k => "exec\n"}}, + {ERR => "dircolors: k:1: invalid line; missing second token\n"}, + {EXIT => 1}], + ['quote', '-b', {IN => "exec 'echo Hello;:'\n"}, + {OUT => "LS_COLORS='ex='\\''echo Hello;\\:'\\'':';\n" + . "export LS_COLORS\n"}], + ['other-wr', '-b', {IN => "owt 40;33\n"}, + {OUT => "LS_COLORS='tw=40;33:';\nexport LS_COLORS\n"}], + ['term-1', '-b', {IN => "TERM none\nowt 40;33\n"}, + {OUT => "LS_COLORS='tw=40;33:';\nexport LS_COLORS\n"}], + ['term-2', '-b', {IN => "TERM non*\nowt 40;33\n"}, + {OUT => "LS_COLORS='tw=40;33:';\nexport LS_COLORS\n"}], + ['term-3', '-b', {IN => "TERM nomatch\nowt 40;33\n"}, + {OUT => "LS_COLORS='';\nexport LS_COLORS\n"}], + ['term-4', '-b', {IN => "TERM N*match\nowt 40;33\n"}, + {OUT => "LS_COLORS='';\nexport LS_COLORS\n"}], + + ['colorterm-1', '-b', {ENV => 'COLORTERM=any'}, + {IN => "COLORTERM ?*\nowt 40;33\n"}, + {OUT => "LS_COLORS='tw=40;33:';\nexport LS_COLORS\n"}], + + ['colorterm-2', '-b', {ENV => 'COLORTERM='}, + {IN => "COLORTERM ?*\nowt 40;33\n"}, + {OUT => "LS_COLORS='';\nexport LS_COLORS\n"}], + + ['print-clash1', '-p', '--print-ls', + {ERR => "dircolors: options --print-database and --print-ls-colors " . + "are mutually exclusive\n" . + "Try 'dircolors --help' for more information.\n"}, + {EXIT => 1}], + ['print-clash2', '-b', '--print-database', + {ERR => "dircolors: the options to output non shell syntax,\n" . + "and to select a shell syntax are mutually exclusive\n" . + "Try 'dircolors --help' for more information.\n"}, + {EXIT => 1}], + + ['print-ls-colors', '--print-ls-colors', {IN => "OWT 40;33\n"}, + {OUT => "\x1B[40;33mtw\t40;33\x1B[0m\n"}], + + # CAREFUL: always specify the -b option, unless explicitly testing + # for csh syntax output, or --print-ls-color output. + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'dircolors'; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/dirname.pl b/tests/misc/dirname.pl new file mode 100755 index 0000000..d1a78c1 --- /dev/null +++ b/tests/misc/dirname.pl @@ -0,0 +1,72 @@ +#!/usr/bin/perl +# Test "dirname". + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +use strict; +use File::stat; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $stat_single = stat('/'); +my $stat_double = stat('//'); +my $double_slash = ($stat_single->dev == $stat_double->dev + && $stat_single->ino == $stat_double->ino) ? '/' : '//'; + +my $prog = 'dirname'; + +my @Tests = + ( + ['fail-1', {ERR => "$prog: missing operand\n" + . "Try '$prog --help' for more information.\n"}, {EXIT => '1'}], + + ['a', qw(d/f), {OUT => 'd'}], + ['b', qw(/d/f), {OUT => '/d'}], + ['c', qw(d/f/), {OUT => 'd'}], + ['d', qw(d/f//), {OUT => 'd'}], + ['e', qw(f), {OUT => '.'}], + ['f', qw(/), {OUT => '/'}], + ['g', qw(//), {OUT => "$double_slash"}], + ['h', qw(///), {OUT => '/'}], + ['i', qw(//a//), {OUT => "$double_slash"}], + ['j', qw(///a///), {OUT => '/'}], + ['k', qw(///a///b), {OUT => '///a'}], + ['l', qw(///a//b/), {OUT => '///a'}], + ['m', qw(''), {OUT => '.'}], + ['n', qw(a/b c/d), {OUT => "a\nc"}], + ); + +# Append a newline to end of each expected 'OUT' string. +my $t; +foreach $t (@Tests) + { + my $arg1 = $t->[1]; + my $e; + foreach $e (@$t) + { + $e->{OUT} = "$e->{OUT}\n" + if ref $e eq 'HASH' and exists $e->{OUT}; + } + } + +my $save_temps = $ENV{SAVE_TEMPS}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/echo.sh b/tests/misc/echo.sh new file mode 100755 index 0000000..2294035 --- /dev/null +++ b/tests/misc/echo.sh @@ -0,0 +1,99 @@ +#!/bin/sh +# basic tests for echo + +# Copyright (C) 2018-2022 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 <https://www.gnu.org/licenses/>. + +prog='env echo' + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ echo + + +# Verify the methods of specifying "Escape": +# Note 4 octal digits are allowed (unlike printf which uses up to 3) +printf '%s\n' . . . . . | tr . '\033' > exp +$prog -n -e '\x1b\n\e\n\33\n\033\n\0033\n' > out || fail=1 +compare exp out || fail=1 + +# Incomplete hex escapes are output as is (unlike printf) +printf '\\x\n' > exp +$prog -n -e '\x\n' > out || fail=1 +compare exp out || fail=1 + +# Always output -- (unlike printf) +$prog -- 'foo' > out || fail=1 +$prog -n -e -- 'foo\n' >> out || fail=1 +cat <<\EOF > exp +-- foo +-- foo +EOF +compare exp out || fail=1 + +# Ensure \c stops processing +$prog -e 'foo\n\cbar' > out || fail=1 +printf 'foo\n' > exp +compare exp out || fail=1 + +# With POSIXLY_CORRECT: +# only -n as the first (separate) option enables option processing +# -E is ignored +# escapes are processed by default +POSIXLY_CORRECT=1 $prog -n -E 'foo\n' > out || fail=1 +POSIXLY_CORRECT=1 $prog -nE 'foo' >> out || fail=1 +POSIXLY_CORRECT=1 $prog -E -n 'foo' >> out || fail=1 +POSIXLY_CORRECT=1 $prog --version >> out || fail=1 +cat <<\EOF > exp +foo +-nE foo +-E -n foo +--version +EOF +compare exp out || fail=1 + +# Further test coverage. +# Output a literal '-' (on a line itself). +$prog - > out || fail=1 +# Output a literal backslash '\', no newline. +$prog -n -e '\\' >> out || fail=1 +# Output an empty line (merely to have a newline after the previous test). +$prog >> out || fail=1 +# Test other characters escaped by a backslash: +# \a hex 07 alert, bell +# \b hex 08 backspace +# \e hex 1b escape +# \f hex 0c form feed +# \n hex 0a new line +# \r hex 0d carriage return +# \t hex 09 horizontal tab +# \v hex 0b vertical tab +# Convert output, yet checking the exit status of $prog. +{ $prog -n -e '\a\b\e\f\n\r\t\v' || touch fail; } | od -tx1 >> out || fail=1 +test '!' -f fail || fail=1 +# Output hex values which contain hexadecimal characters to test hextobin(). +# Hex values 4a through 4f are ASCII "JKLMNO". +$prog -n -e '\x4a\x4b\x4c\x4d\x4e\x4f\x4A\x4B\x4C\x4D\x4E\x4F' >> out || fail=1 +# Output another newline. +$prog >> out || fail=1 +cat <<\EOF > exp +- +\ +0000000 07 08 1b 0c 0a 0d 09 0b +0000010 +JKLMNOJKLMNO +EOF +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/env-S-script.sh b/tests/misc/env-S-script.sh new file mode 100755 index 0000000..0fd43d3 --- /dev/null +++ b/tests/misc/env-S-script.sh @@ -0,0 +1,147 @@ +#!/bin/sh +# Test env -S in a #! line of a script. + +# Copyright (C) 2018-2022 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 <https://www.gnu.org/licenses/>. + + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ env +print_ver_ printf + +require_perl_ + +# a shortcut to avoid long lines +dir="$abs_top_builddir/src" + +cat <<EOF > shebang || framework_failure_ +#!$SHELL +EOF +cat <<\EOF >> shebang || framework_failure_ +# Execute a script as per 3 argument shebang +# but without length limits (127 on Linux for example). +script="$1"; shift +shebang=$(sed -n 's/^#!//p;q' < "$script") +interp=$(printf '%s' "$shebang" | cut -d' ' -f1) +rest=$(printf '%s' "$shebang" | cut -s -d' ' -f2-) +test "$rest" && exec "$interp" "$rest" "$script" "$@" +exec "$interp" "$script" "$@" +EOF +chmod a+x shebang || framework_failure_ + +# A simple shebang program to call our new "env" +printf "#!$dir/env sh\necho hello\n" > env_test || framework_failure_ +chmod a+x env_test || framework_failure_ + +# Verify we can run the shebang which is not the case if +# there are spaces in $abs_top_builddir. +./shebang ./env_test || skip_ "Error running env_test script" + +# env should execute 'printf' with 7 parameters: +# 'x%sx\n', 'A', 'B' from the "-S" argument, +# the name of the executed script, and its 3 parameters (C,D,'E F'). +# Ignoring the absolute paths, the script is: +# #!env -S printf x%sx\n A B +printf "#!$dir/env -S $dir/printf "'x%%sx\\n A B\n' > env1 || framework_failure_ +chmod a+x env1 || framework_failure_ +cat<<\EOF>exp1 || framework_failure_ +xAx +xBx +x./env1x +xCx +xDx +xE Fx +EOF +./shebang ./env1 C D "E F" > out1 || fail=1 +compare exp1 out1 || fail=1 + + +# similar to the above test but with quotes, the first parameter should be +# 'A B' and not two paramaters 'A','B'. +# Ignoring the absolute paths, the script is: +# #!env -S printf x%sx\n "A B" +printf "#!$dir/env -S $dir/printf "'x%%sx\\n "A B"\n' > env2 || + framework_failure_ +chmod a+x env2 || framework_failure_ +cat<<\EOF>exp2 || framework_failure_ +xA Bx +x./env2x +EOF +./shebang ./env2 > out2 || fail=1 +compare exp2 out2 || fail=1 + + +# backslash-underscore instead of spaces. +# Ignoring the absolute paths, the script is: +# #!env -Sprintf\_x%sx\n\_Y +printf "#!$dir/env -S$dir/printf"'\\_x%%sx\\n\\_Y\n' > env3 || + framework_failure_ +chmod a+x env3 || framework_failure_ +cat<<\EOF>exp3 || framework_failure_ +xYx +x./env3x +xWx +EOF +./shebang ./env3 W > out3 || fail=1 +compare exp3 out3 || fail=1 + + + +# Test comments - The "#C D" should be ignored. +# Ignoring the absolute paths, the script is: +# #!env -Sprintf x%sx\n A#B #C D +printf "#!$dir/env -S$dir/printf"' x%%sx\\n A#B #C D\n' > env4 \ + || framework_failure_ +chmod a+x env4 || framework_failure_ +cat<<\EOF>exp4 || framework_failure_ +xA#Bx +x./env4x +xZx +EOF +./shebang ./env4 Z > out4 || fail=1 +compare exp4 out4 || fail=1 + + +# Test with a simple Perl usage. +# (assume Perl is in $PATH, as it is required for the test suite). +# Ignoring the absolute paths, the script is: +# #!env -S perl -w -T +# print "hello\n"; +{ printf "#!$dir/env -S $PERL -w -T\n" ; + printf 'print "hello\\n";\n' ; } > env5 || framework_failure_ +chmod a+x env5 || framework_failure_ +cat<<\EOF>exp5 || framework_failure_ +hello +EOF +./shebang ./env5 > out5 || fail=1 +compare exp5 out5 || fail=1 + + +# Test with a more complex Perl usage. +# Ignoring the absolute paths, the script is: +# #!env -S perl -mFile::Basename=basename -e "print basename(\$ARGV[0]);" +# The backslash before the '$' is required to prevent env(1) from treating +# $ARGV as an (invalid syntax) envvar, and pass it as-is to Perl. +{ printf "#!$dir/env -S " ; + printf "$PERL -mFile::Basename=basename -e " ; + printf '"print basename(\\$ARGV[0]);"\n' ; } > env6 || framework_failure_ +chmod a+x env6 || framework_failure_ +# Note: the perl script does not output a newline. +printf "env6" > exp6 || framework_failure_ +./shebang ./env6 > out6 || fail=1 +compare exp6 out6 || fail=1 + + +Exit $fail diff --git a/tests/misc/env-S.pl b/tests/misc/env-S.pl new file mode 100755 index 0000000..b11836d --- /dev/null +++ b/tests/misc/env-S.pl @@ -0,0 +1,289 @@ +#!/usr/bin/perl +# Test 'env -S' feature + +# Copyright (C) 2018-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; +my $prog = 'env'; + +my $env = "$ENV{abs_top_builddir}/src/env"; +# Ensure no whitespace or other problematic chars in path +$env =~ m!^([-+\@\w./]+)$! + or CuSkip::skip "unusual absolute builddir name; skipping this test\n"; +$env = $1; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# This envvar is somehow set at least on macOS 11.6, and would +# otherwise cause failure of q*, t* and more tests below. Ignore it. +my $cf = '__CF_USER_TEXT_ENCODING'; +exists $ENV{$cf} and $env .= " -u$cf"; +# Likewise for these Cygwin env vars +my $cf = 'SYSTEMROOT'; +exists $ENV{$cf} and $env .= " -u$cf"; +my $cf = 'WINDIR'; +exists $ENV{$cf} and $env .= " -u$cf"; + +my @Tests = + ( + # Test combination of -S and regular arguments + ['1', q[-ufoo A=B FOO=AR sh -c 'echo $A$FOO'], {OUT=>"BAR"}], + ['2', q[-ufoo -S'A=B FOO=AR sh -c "echo \\$A\\$FOO"'], {OUT=>"BAR"}], + ['3', q[-ufoo -S'A=B FOO=AR' sh -c 'echo $A$FOO'], {OUT=>"BAR"}], + ['4', q[-ufoo -S'A=B' FOO=AR sh -c 'echo $A$FOO'], {OUT=>"BAR"}], + ['5', q[-S'-ufoo A=B FOO=AR sh -c "echo \\$A\\$FOO"'], {OUT=>"BAR"}], + + # Test quoting inside -S + ['q1', q[-S'-i A="B C" ]."$env'", {OUT=>"A=B C"}], + ['q2', q[-S"-i A='B C' ]."$env\"", {OUT=>"A=B C"}], + ['q3', q[-S"-i A=\"B C\" ]."$env\"", {OUT=>"A=B C"}], + # Test backslash-quoting inside quoting inside -S + ['q4', q[-S'-i A="B \" C" ]."$env'", {OUT=>'A=B " C'}], + ['q5', q[-S"-i A='B \\' C' ]."$env\"", {OUT=>"A=B ' C"}], + # Single-quotes in double-quotes and vice-versa + ['q6', q[-S'-i A="B'"'"'C" ]."$env'", {OUT=>"A=B'C"}], + ['q7', q[-S"-i A='B\\"C' ]."$env\"", {OUT=>'A=B"C'}], + + # Test tab and space (note: tab here is expanded by perl + # and sent to the shell as ASCII 0x9 inside single-quotes). + ['t1', qq[-S'-i\tA="B \tC" $env'], {OUT=>"A=B \tC"}], + # Here '\\t' is not interpolated by perl/shell, passed as two characters + # (backslash, 't') to env, resulting in one argument ("A<tab>B"). + ['t2', qq[-S'printf x%sx\\n A\\tB'], {OUT=>"xA\tBx"}], + # Here '\t' is interpolated by perl, passed as literal tab (ASCII 0x9) + # to env, resulting in two arguments ("A" <whitespace> "B"). + ['t3', qq[-S'printf x%sx\\n A\tB'], {OUT=>"xAx\nxBx"}], + ['t4', qq[-S'printf x%sx\\n A \t B'], {OUT=>"xAx\nxBx"}], + # Ensure \v\f\r\n treated like other whitespace. + # From 8.30 - 8.32 these would introduce arguments to printf, + # and also crash ASAN builds with out of bounds access. + ['t5', qq[-S'printf x%sx\\n A \t B \013\f\r\n'], {OUT=>"xAx\nxBx"}], + + + # Test empty strings + ['m1', qq[-i -S"" A=B $env], {OUT=>"A=B"}], + ['m2', qq[-i -S" \t" A=B $env], {OUT=>"A=B"}], + + # Test escape sequences. + # note: in the following, there is no interpolation by perl due + # to q[], and no interpolation by the shell due to single-quotes. + # env will receive the backslash character followed by t/f/r/n/v. + # Also: Perl does not recognize "\v", so use "\013" for vertical tab. + ['e1', q[-i -S'A="B\tC" ]."$env'", {OUT=>"A=B\tC"}], + ['e2', q[-i -S'A="B\fC" ]."$env'", {OUT=>"A=B\fC"}], + ['e3', q[-i -S'A="B\rC" ]."$env'", {OUT=>"A=B\rC"}], + ['e4', q[-i -S'A="B\nC" ]."$env'", {OUT=>"A=B\nC"}], + ['e5', q[-i -S'A="B\vC" ]."$env'", {OUT=>"A=B\013C"}], + ['e6', q[-i -S'A="B\$C" ]."$env'", {OUT=>'A=B$C'}], + ['e7', q[-i -S'A=B\$C ]."$env'", {OUT=>'A=B$C'}], + ['e8', q[-i -S'A="B\#C" ]."$env'", {OUT=>'A=B#C'}], + ['e9', q[-i -S'A="B\\\\C" ]."$env'", {OUT=>'A=B\\C'}], + ['e10',q[-i -S"A='B\\\\\\\\C' ]."$env\"", {OUT=>'A=B\\C'}], + + # Escape in single-quoted string - passed as-is + # (the multiple pairs of backslashes are to survive two interpolations: + # by perl and then by the shell due to double-quotes). + ['e11',q[-i -S"A='B\\\\tC' ]."$env\"", {OUT=>'A=B\tC'}], + ['e12',q[-i -S"A='B\\\\#C' ]."$env\"", {OUT=>'A=B\#C'}], + ['e13',q[-i -S"A='B\\\\\\$C' ]."$env\"", {OUT=>'A=B\$C'}], + ['e14',q[-i -S"A='B\\\\\\"C' ]."$env\"", {OUT=>'A=B\"C'}], + + # Special escape sequences: + # \_ in duoble-quotes is a space - result is just one envvar 'A' + ['e20', q[-i -S'A="B\_C=D" ]."$env'", {OUT=>'A=B C=D'}], + # \_ outside double-quotes is arg separator, the command to + # execute should be 'env env' + ['e21', q[-i -S'A=B]."\\_$env\\_$env'", {OUT=>"A=B"}], + + # Test -C inside -S + ['c1', q["-S-C/ pwd"], {OUT=>"/"}], + ['c2', q["-S -C / pwd"], {OUT=>"/"}], + ['c3', q["-S --ch'dir='/ pwd"], {OUT=>"/"}], + + # Test -u inside and outside -S + # u1,u2 - establish a baseline, without -S + ['u1', q[ sh -c 'echo =$FOO='], {ENV=>"FOO=BAR"}, {OUT=>"=BAR="}], + ['u2', q[-uFOO sh -c 'echo =$FOO='], {ENV=>"FOO=BAR"}, {OUT=>"=="}], + # u3,u4: ${FOO} expanded by env itself before executing sh. + # \\$FOO expanded by sh. + # ${FOO} should have value of the original environment + # and \\$FOO should be unset, regardlss where -uFOO is used. + # 'u3' behavior differs from FreeBSD's but deemed preferable, in + # https://lists.gnu.org/r/coreutils/2018-04/msg00014.html + ['u3', q[-uFOO -S'sh -c "echo x${FOO}x =\\$FOO="'], + {ENV=>"FOO=BAR"}, {OUT=>"xBARx =="}], + ['u4', q[-S'-uFOO sh -c "echo x${FOO}x =\\$FOO="'], + {ENV=>"FOO=BAR"}, {OUT=>"xBARx =="}], + + # Test ENVVAR expansion + ['v1', q[-i -S'A=${FOO} ]."$env'", {ENV=>"FOO=BAR"}, {OUT=>"A=BAR"}], + ['v2', q[-i -S'A=x${FOO}x ]."$env'", {ENV=>"FOO=BAR"}, {OUT=>"A=xBARx"}], + ['v3', q[-i -S'A=x${FOO}x ]."$env'", {ENV=>"FOO="}, {OUT=>"A=xx"}], + ['v4', q[-i -S'A=x${FOO}x ]."$env'", {OUT=>"A=xx"}], + ['v5', q[-i -S'A="x${FOO}x" ]."$env'", {ENV=>"FOO=BAR"}, {OUT=>"A=xBARx"}], + ['v6', q[-i -S'${FOO}=A ]."$env'", {ENV=>"FOO=BAR"}, {OUT=>"BAR=A"}], + # No expansion inside single-quotes + ['v7', q[-i -S"A='x\${FOO}x' ]."$env\"", {OUT=>'A=x${FOO}x'}], + ['v8', q[-i -S'A="${_FOO}" ]."$env'", {ENV=>"_FOO=BAR"}, {OUT=>"A=BAR"}], + ['v9', q[-i -S'A="${F_OO}" ]."$env'", {ENV=>"F_OO=BAR"}, {OUT=>"A=BAR"}], + ['v10', q[-i -S'A="${FOO1}" ]."$env'", {ENV=>"FOO1=BAR"}, {OUT=>"A=BAR"}], + + # Test end-of-string '#" and '\c' + ['d1', q[-i -S'A=B #C=D' ]."$env", {OUT=>"A=B"}], + ['d2', q[-i -S'#A=B C=D' ]."$env", {OUT=>""}], + ['d3', q[-i -S'A=B#' ]."$env", {OUT=>"A=B#"}], + ['d4', q[-i -S'A=B #' ]."$env", {OUT=>"A=B"}], + + ['d5', q[-i -S'A=B\cC=D' ]."$env", {OUT=>"A=B"}], + ['d6', q[-i -S'\cA=B C=D' ]."$env", {OUT=>""}], + ['d7', q[-i -S'A=B\c' ]."$env", {OUT=>"A=B"}], + ['d8', q[-i -S'A=B \c' ]."$env", {OUT=>"A=B"}], + + ['d10', q[-S'echo FOO #BAR'], {OUT=>"FOO"}], + ['d11', q[-S'echo FOO \\#BAR'], {OUT=>"FOO #BAR"}], + ['d12', q[-S'echo FOO#BAR'], {OUT=>"FOO#BAR"}], + + # Test underscore as space/separator in double/single/no quotes + ['s1', q[-S'printf x%sx\\n "A\\_B"'], {OUT=>"xA Bx"}], + ['s2', q[-S"printf x%sx\\n 'A\\_B'"], {OUT=>"xA\\_Bx"}], + ['s3', q[-S"printf x%sx\\n A\\_B"], {OUT=>"xAx\nxBx"}], + ['s4', q[-S"printf x%sx\\n A B"], {OUT=>"xAx\nxBx"}], + ['s5', q[-S"printf x%sx\\n A B"], {OUT=>"xAx\nxBx"}], + # test underscore/spaces variations - + # ensure they don't generate empty arguments. + ['s6', q[-S"\\_printf x%sx\\n FOO"], {OUT=>"xFOOx"}], + ['s7', q[-S"printf x%sx\\n FOO\\_"], {OUT=>"xFOOx"}], + ['s8', q[-S"\\_printf x%sx\\n FOO\\_"], {OUT=>"xFOOx"}], + ['s9', q[-S"\\_\\_printf x%sx\\n FOO\\_\\_"], {OUT=>"xFOOx"}], + ['s10', q[-S" printf x%sx\\n FOO"], {OUT=>"xFOOx"}], + ['s11', q[-S"printf x%sx\\n FOO "], {OUT=>"xFOOx"}], + ['s12', q[-S" printf x%sx\\n FOO "], {OUT=>"xFOOx"}], + ['s13', q[-S" printf x%sx\\n FOO "], {OUT=>"xFOOx"}], + ['s14', q[-S'printf\\_x%sx\\n\\_FOO'], {OUT=>"xFOOx"}], + ['s15', q[-S"printf x%sx\\n \\_ FOO"], {OUT=>"xFOOx"}], + ['s16', q[-S"printf x%sx\\n\\_ \\_FOO"], {OUT=>"xFOOx"}], + ['s17', q[-S"\\_ \\_ printf x%sx\\n FOO \\_ \\_"], {OUT=>"xFOOx"}], + + # Check for empty quotes + ['eq1', q[-S'printf x%sx\\n A "" B'], {OUT=>"xAx\nxx\nxBx"}], + ['eq2', q[-S'printf x%sx\\n A"" B'], {OUT=>"xAx\nxBx"}], + ['eq3', q[-S'printf x%sx\\n A""B'], {OUT=>"xABx"}], + ['eq4', q[-S'printf x%sx\\n A ""B'], {OUT=>"xAx\nxBx"}], + ['eq5', q[-S'printf x%sx\\n ""'], {OUT=>"xx"}], + ['eq6', q[-S'printf x%sx\\n "" '], {OUT=>"xx"}], + ['eq10', q[-S"printf x%sx\\n A '' B"], {OUT=>"xAx\nxx\nxBx"}], + ['eq11', q[-S"printf x%sx\\n A'' B"], {OUT=>"xAx\nxBx"}], + ['eq12', q[-S"printf x%sx\\n A''B"], {OUT=>"xABx"}], + ['eq13', q[-S"printf x%sx\\n A ''B"], {OUT=>"xAx\nxBx"}], + ['eq14', q[-S'printf x%sx\\n ""'], {OUT=>"xx"}], + ['eq15', q[-S'printf x%sx\\n "" '], {OUT=>"xx"}], + + # extreme example - such as could be found on a #! line. + ['p10', q[-S"\\_ \\_perl\_-w\_-T\_-e\_'print \"hello\n\";'\\_ \\_"], + {OUT=>"hello"}], + + # Test Error Conditions + ['err1', q[-S'"\\c"'], {EXIT=>125}, + {ERR=>"$prog: '\\c' must not appear in double-quoted -S string\n"}], + ['err2', q[-S'A=B\\'], {EXIT=>125}, + {ERR=>"$prog: invalid backslash at end of string in -S\n"}], + ['err3', q[-S'"A=B\\"'], {EXIT=>125}, + {ERR=>"$prog: no terminating quote in -S string\n"}], + ['err4', q[-S"'A=B\\\\'"], {EXIT=>125}, + {ERR=>"$prog: no terminating quote in -S string\n"}], + ['err5', q[-S'A=B\\q'], {EXIT=>125}, + {ERR=>"$prog: invalid sequence '\\q' in -S\n"}], + ['err6', q[-S'A=$B'], {EXIT=>125}, + {ERR=>"$prog: only \${VARNAME} expansion is supported, error at: \$B\n"}], + ['err7', q[-S'A=${B'], {EXIT=>125}, + {ERR=>"$prog: only \${VARNAME} expansion is supported, " . + "error at: \${B\n"}], + ['err8', q[-S'A=${B%B}'], {EXIT=>125}, + {ERR=>"$prog: only \${VARNAME} expansion is supported, " . + "error at: \${B%B}\n"}], + ['err9', q[-S'A=${9B}'], {EXIT=>125}, + {ERR=>"$prog: only \${VARNAME} expansion is supported, " . + "error at: \${9B}\n"}], + + # Test incorrect shebang usage (extraneous whitespace). + ['err_sp2', q['-v -S cat -n'], {EXIT=>125}, + {ERR=>"env: invalid option -- ' '\n" . + "env: use -[v]S to pass options in shebang lines\n" . + "Try 'env --help' for more information.\n"}], + ['err_sp3', q['-v -S cat -n'], {EXIT=>125}, # embedded tab after -v + {ERR=>"env: invalid option -- '\t'\n" . + "env: use -[v]S to pass options in shebang lines\n" . + "Try 'env --help' for more information.\n"}], + + # Also diagnose incorrect shebang usage when failing to exec. + # This typically happens with: + # + # $ cat xxx + # #!env -v -S cat -n + # + # $ ./xxx + # + # in which case: + # argv[0] = env + # argv[1] = '-v -S cat -n' + # argv[2] = './xxx' + ['err_sp5', q['cat -n' ./xxx], {EXIT=>127}, + {ERR=>"env: 'cat -n': No such file or directory\n" . + "env: use -[v]S to pass options in shebang lines\n"}], + + ['err_sp6', q['cat -n' ./xxx arg], {EXIT=>127}, + {ERR=>"env: 'cat -n': No such file or directory\n" . + "env: use -[v]S to pass options in shebang lines\n"}], + ); + +# Append a newline to end of each expected 'OUT' string. +my $t; +foreach $t (@Tests) + { + my $arg1 = $t->[1]; + my $e; + foreach $e (@$t) + { + $e->{OUT} .= "\n" + if ref $e eq 'HASH' and exists $e->{OUT} and length($e->{OUT})>0; + } + } + +# Repeat above tests with "--debug" option (but discard STDERR). +my @new; +foreach my $t (@Tests) +{ + #skip tests that are expected to fail + next if $t->[0] =~ /^err/; + + my @new_t = @$t; + my $test_name = shift @new_t; + my $args = shift @new_t; + push @new, ["$test_name-debug", + "--debug " . $args, + @new_t, + {ERR_SUBST => 's/.*//ms'}]; +} +push @Tests, @new; + +my $save_temps = $ENV{SAVE_TEMPS}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/env-null.sh b/tests/misc/env-null.sh new file mode 100755 index 0000000..0340830 --- /dev/null +++ b/tests/misc/env-null.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# Verify behavior of env -0 and printenv -0. + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ env printenv + +# POSIX is clear that environ may, but need not be, sorted. +# Environment variable values may contain newlines, which cannot be +# observed by merely inspecting output from env. +# Cygwin requires a minimal environment to launch new processes: execve +# adds missing variables SYSTEMROOT and WINDIR, which show up in a +# subsequent env. Cygwin also requires /bin to always be part of PATH, +# and attempts to unset or reduce PATH may cause execve to fail. +# +# For these reasons, it is better to compare two outputs from distinct +# programs that should be the same, rather than building an exp file. +env -i PATH="$PATH" env -0 > out1 || fail=1 +env -i PATH="$PATH" printenv -0 > out2 || fail=1 +compare out1 out2 || fail=1 +env -i PATH="$PATH" env --null > out2 || fail=1 +compare out1 out2 || fail=1 +env -i PATH="$PATH" printenv --null > out2 || fail=1 +compare out1 out2 || fail=1 + +# env -0 does not work if a command is specified. +returns_ 125 env -0 echo hi > out || fail=1 +compare /dev/null out || fail=1 + +# Test env -0 on a one-variable environment. +printf 'a=b\nc=\0' > exp || framework_failure_ +env -i -0 "$(printf 'a=b\nc=')" > out || fail=1 +compare exp out || fail=1 + +# Test printenv -0 on particular values. +printf 'b\nc=\0' > exp || framework_failure_ +env "$(printf 'a=b\nc=')" printenv -0 a > out || fail=1 +compare exp out || fail=1 +returns_ 1 env -u a printenv -0 a > out || fail=1 +compare /dev/null out || fail=1 +returns_ 1 env -u b "$(printf 'a=b\nc=')" printenv -0 b a > out || fail=1 +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/env-signal-handler.sh b/tests/misc/env-signal-handler.sh new file mode 100755 index 0000000..ff4ffa1 --- /dev/null +++ b/tests/misc/env-signal-handler.sh @@ -0,0 +1,126 @@ +#!/bin/sh +# Test env --default-signal=PIPE feature. + +# Copyright (C) 2019-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ env seq test timeout printf +trap_sigpipe_or_skip_ + +# /bin/sh has an intermittent failure in ignoring SIGPIPE on OpenIndiana 11 +# so we require bash as discussed at: +# https://lists.gnu.org/archive/html/coreutils/2020-03/msg00004.html +require_bash_as_SHELL_ + +# Paraphrasing http://bugs.gnu.org/34488#8: +# POSIX requires that sh started with an inherited ignored SIGPIPE must +# silently ignore all attempts from within the shell to restore SIGPIPE +# handling to child processes of the shell: +# +# $ (trap '' PIPE; bash -c 'trap - PIPE; seq inf | head -n1') +# 1 +# seq: write error: Broken pipe +# +# With 'env --default-signal=PIPE', the signal handler can be reset to its +# default. + +# Baseline Test - default signal handler +# -------------------------------------- +# Ensure this results in a "broken pipe" error (the first 'trap' +# sets SIGPIPE to ignore, and the second 'trap' becomes a no-op instead +# of resetting SIGPIPE to its default). Upon a SIGPIPE 'seq' will not be +# terminated, instead its write(2) call will return an error. +(trap '' PIPE; $SHELL -c 'trap - PIPE; seq 999999 2>err1t | head -n1 > out1') + +# The exact broken pipe message depends on the operating system, just ensure +# there was a 'write error' message in stderr: +sed 's/^\(seq: write error:\) .*/\1/' err1t > err1 || framework_failure_ + +printf "1\n" > exp-out || framework_failure_ +printf "seq: write error:\n" > exp-err1 || framework_failure_ + +compare exp-out out1 || framework_failure_ +compare exp-err1 err1 || framework_failure_ + + +# env test - default signal handler +# --------------------------------- +# With env resetting the signal handler to its defaults, there should be no +# error message (because the default SIGPIPE action is to terminate the +# 'seq' program): +(trap '' PIPE; + env --default-signal=PIPE \ + $SHELL -c 'trap - PIPE; seq 999999 2>err2 | head -n1 > out2') + +compare exp-out out2 || fail=1 +compare /dev/null err2 || fail=1 + +# env test - default signal handler (3) +# ------------------------------------- +# Repeat the previous test, using --default-signal with no signal names, +# i.e., all signals. +(trap '' PIPE; + env --default-signal \ + $SHELL -c 'trap - PIPE; seq 999999 2>err4 | head -n1 > out4') + +compare exp-out out4 || fail=1 +compare /dev/null err4 || fail=1 + +# env test - block signal handler +env --block-signal true || fail=1 + +env_ignore_delay_() +{ + local delay="$1" + + # The first 'env' is just to ensure timeout is not a shell built-in. + env timeout --verbose --kill-after=.1 --signal=INT $delay \ + env $env_opt sleep 10 > /dev/null 2>outt + # check only the first two lines from stderr, which are printed by timeout. + # (operating systems might add more messages, like "killed"). + sed -n '1,2p' outt > out || framework_failure_ + compare exp out +} + +# Baseline test - ignore signal handler +# ------------------------------------- +# Terminate 'sleep' with SIGINT +# (SIGINT's default action is to terminate a program). +cat <<\EOF >exp || framework_failure_ +timeout: sending signal INT to command 'env' +EOF +env_opt='' retry_delay_ env_ignore_delay_ .1 6 || fail=1 + +# env test - ignore signal handler +# -------------------------------- +# Use env to ignore SIGINT - "sleep" should continue running +# after timeout sends SIGINT, and be killed using SIGKILL. +cat <<\EOF >exp || framework_failure_ +timeout: sending signal INT to command 'env' +timeout: sending signal KILL to command 'env' +EOF +env_opt='--ignore-signal=INT' retry_delay_ env_ignore_delay_ .1 6 || fail=1 +env_opt='--ignore-signal' retry_delay_ env_ignore_delay_ .1 6 || fail=1 + +# env test --list-signal-handling +env --default-signal --ignore-signal=INT --list-signal-handling true \ + 2> err8t || fail=1 +sed 's/(.*)/()/' err8t > err8 || framework_failure_ +env printf 'INT (): IGNORE\n' > exp-err8 || framework_failure_ +compare exp-err8 err8 || fail=1 + + +Exit $fail diff --git a/tests/misc/env.sh b/tests/misc/env.sh new file mode 100755 index 0000000..5a63f34 --- /dev/null +++ b/tests/misc/env.sh @@ -0,0 +1,166 @@ +#!/bin/sh +# Verify behavior of env. + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ env pwd nice + +# A simple shebang program to call "echo" from symlinks like "./-u" or "./--". +echo "#!$abs_top_builddir/src/echo simple_echo" > simple_echo \ + || framework_failure_ +chmod a+x simple_echo || framework_failure_ + +# Verify we can run the shebang which is not the case if +# there are spaces in $abs_top_builddir. +./simple_echo || skip_ "Error running simple_echo script" + +# Verify clearing the environment +a=1 +export a +env - > out || fail=1 +compare /dev/null out || fail=1 +env -i > out || fail=1 +compare /dev/null out || fail=1 +env -u a -i -u a -- > out || fail=1 +compare /dev/null out || fail=1 +env -i -- a=b > out || fail=1 +echo a=b > exp || framework_failure_ +compare exp out || fail=1 + +# These tests verify exact status of internal failure. +returns_ 125 env --- || fail=1 # unknown option +returns_ 125 env -u || fail=1 # missing option argument +returns_ 2 env sh -c 'exit 2' || fail=1 # exit status propagation +returns_ 126 nice . && { returns_ 126 env . || fail=1; } # invalid command +returns_ 127 env no_such || fail=1 # no such command + +# POSIX is clear that environ may, but need not be, sorted. +# Environment variable values may contain newlines, which cannot be +# observed by merely inspecting output from env. +# Cygwin requires a minimal environment to launch new processes: execve +# adds missing variables SYSTEMROOT and WINDIR, which show up in a +# subsequent env. Cygwin also requires /bin to always be part of PATH, +# and attempts to unset or reduce PATH may cause execve to fail. +# +# For these reasons, it is more portable to grep that our desired changes +# took place, rather than comparing output of env over an entire environment. +if env | grep '^ENV_TEST' >/dev/null ; then + skip_ "environment has potential interference from ENV_TEST*" +fi + +ENV_TEST1=a +export ENV_TEST1 +>out || framework_failure_ +env ENV_TEST2= > all || fail=1 +grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure_ +env -u ENV_TEST1 ENV_TEST3=c > all || fail=1 +grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure_ +env ENV_TEST1=b > all || fail=1 +grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure_ +env ENV_TEST2= env > all || fail=1 +grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure_ +env -u ENV_TEST1 ENV_TEST3=c env > all || fail=1 +grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure_ +env ENV_TEST1=b env > all || fail=1 +grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure_ +cat <<EOF >exp || framework_failure_ +ENV_TEST1=a +ENV_TEST2= +ENV_TEST3=c +ENV_TEST1=b +ENV_TEST1=a +ENV_TEST2= +ENV_TEST3=c +ENV_TEST1=b +EOF +compare exp out || fail=1 + +# PATH modifications affect exec. +mkdir unlikely_name || framework_failure_ +cat <<EOF > unlikely_name/also_unlikely || framework_failure_ +#!/bin/sh +echo pass +EOF +chmod +x unlikely_name/also_unlikely || framework_failure_ +returns_ 127 env also_unlikely || fail=1 +test x$(PATH=$PATH:unlikely_name env also_unlikely) = xpass || fail=1 +test x$(env PATH="$PATH":unlikely_name also_unlikely) = xpass || fail=1 + +# Explicitly put . on the PATH for the rest of this test. +PATH=$PATH: +export PATH + +# Use -- to end options (but not variable assignments). +# On some systems, execve("-i") invokes a shebang script ./-i on PATH as +# '/bin/sh -i', rather than '/bin/sh -- -i', which doesn't do what we want. +# Avoid the issue by using a shebang to 'echo' passing a second parameter +# before the '-i'. See the definition of simple_echo before. +# Test -u, rather than -i, to minimize PATH problems. +ln -s "simple_echo" ./-u || framework_failure_ +case $(env -u echo echo good) in + good) ;; + *) fail=1 ;; +esac +case $(env -u echo -- echo good) in + good) ;; + *) fail=1 ;; +esac +case $(env -- -u pass) in + *pass) ;; + *) fail=1 ;; +esac + +# After options have ended, the first argument not containing = is a program. +returns_ 127 env a=b -- true || fail=1 +ln -s "simple_echo" ./-- || framework_failure_ +case $(env a=b -- true || echo fail) in + *true) ;; + *) fail=1 ;; +esac + +# No way to directly invoke program name containing =. +cat <<EOF >./c=d || framework_failure_ +#!/bin/sh +echo pass +EOF +chmod +x c=d || framework_failure_ +test "x$(env c=d echo fail)" = xfail || fail=1 +test "x$(env -- c=d echo fail)" = xfail || fail=1 +test "x$(env ./c=d echo fail)" = xfail || fail=1 +test "x$(env sh -c 'exec "$@"' sh c=d echo fail)" = xpass || fail=1 +test "x$(sh -c '\c=d echo fail')" = xpass && #dash 0.5.4 fails so check first + { test "x$(env sh -c '\c=d echo fail')" = xpass || fail=1; } + +# catch unsetenv failure, broken through coreutils 8.0 +returns_ 125 env -u a=b true || fail=1 +returns_ 125 env -u '' true || fail=1 + +# Verify changing directory. +mkdir empty || framework_failure_ +returns_ 125 env --chdir=empty/nonexistent true || fail=1 +returns_ 125 env -C empty 2>out || fail=1 +printf '%s\n' \ + 'env: must specify command with --chdir (-C)' \ + "Try 'env --help' for more information." > exp || + framework_failure_ +compare exp out || fail=1 +exp=$(cd empty && env pwd) || framework_failure_ +got=$(env --chdir=empty pwd) || fail=1 +test "$exp" = "$got" || fail=1 + +Exit $fail diff --git a/tests/misc/expand.pl b/tests/misc/expand.pl new file mode 100755 index 0000000..7a77e6f --- /dev/null +++ b/tests/misc/expand.pl @@ -0,0 +1,191 @@ +#!/usr/bin/perl +# Exercise expand. + +# Copyright (C) 2004-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $limits = getlimits (); +my $UINTMAX_OFLOW = $limits->{UINTMAX_OFLOW}; + +(my $program_name = $0) =~ s|.*/||; +my $prog = 'expand'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + ['t1', '--tabs=3', {IN=>"a\tb"}, {OUT=>"a b"}], + ['t2', '--tabs=3,6,9', {IN=>"a\tb\tc\td\te"}, {OUT=>"a b c d e"}], + ['t3', '--tabs="3 6 9"', {IN=>"a\tb\tc\td\te"}, {OUT=>"a b c d e"}], + # Leading space/commas are silently ignored; Mixing space/commas is allowed. + # (a side-effect of allowing direct "-3,9" parameter). + ['t4', '--tabs=", 3,6 9"', {IN=>"a\tb\tc\td\te"}, {OUT=>"a b c d e"}], + # tab stops parameter without values + ['t5', '--tabs=""', {IN=>"a\tb\tc"}, {OUT=>"a b c"}], + ['t6', '--tabs=","', {IN=>"a\tb\tc"}, {OUT=>"a b c"}], + ['t7', '--tabs=" "', {IN=>"a\tb\tc"}, {OUT=>"a b c"}], + ['t8', '--tabs="/"', {IN=>"a\tb\tc"}, {OUT=>"a b c"}], + + # Input field wider than the specified tab list + ['if', '--tabs=6,9', {IN=>"a\tbbbbbbbbbbbbb\tc"}, + {OUT=>"a bbbbbbbbbbbbb c"}], + + ['i1', '--tabs=3 -i', {IN=>"\ta\tb"}, {OUT=>" a\tb"}], + ['i2', '--tabs=3 -i', {IN=>" \ta\tb"}, {OUT=>" a\tb"}], + + # Undocumented feature: + # treat "expand -7" as "expand --tabs 7" , + # and "expand -90" as "expand --tabs 90", + ['u1', '-3', {IN=>"a\tb\tc"}, {OUT=>"a b c"}], + ['u2', '-4 -9', {IN=>"a\tb\tc"}, {OUT=>"a b c"}], + ['u3', '-11', {IN=>"a\tb\tc"}, {OUT=>"a b c"}], + # Test all digits (for full code coverage) + ['u4', '-2 -6', {IN=>"a\tb\tc"}, {OUT=>"a b c"}], + ['u5', '-7', {IN=>"a\tb"}, {OUT=>"a b"}], + ['u6', '-8', {IN=>"a\tb"}, {OUT=>"a b"}], + # This syntax is handled internally as "-3, -9" + ['u7', '-3,9', {IN=>"a\tb\tc"}, {OUT=>"a b c"}], + + # Multiple non-empty files + ['f1', '--tabs=4', + {IN=>{"in1" => "a\tb\n"}}, {IN=>{"in2" => "c\td\n"}}, + {OUT=>"a b\nc d\n"}], + # Multiple files, first file is empty + ['f2', '--tabs=4', + {IN=>{"in1" => ""}}, {IN=>{"in2" => "c\td\n"}}, + {OUT=>"c d\n"}], + # Multiple files, second file is empty + ['f3', '--tabs=4', + {IN=>{"in1" => "a\tb\n"}}, {IN=>{"in2" => ""}}, + {OUT=>"a b\n"}], + + + # Test '\b' (back-space) - subtract one column. + # + # Note: + # In a terminal window, 'expand' will appear to erase the 'a' characters + # due to overwriting them with spaces: + # + # $ printf 'aaa\b\b\bc\td\n' + # caa d + # $ printf 'aaa\b\b\bc\td\n' | expand + # c d + # + # However the characters are all printed: + # + # $ printf 'aaa\b\b\bc\td\n' | expand | od -An -ta + # a a a bs bs bs c sp sp sp sp sp sp sp d nl + # + # If users ever report a problem with these tests and just + # copy&paste from the terminal, their report will be confusing + # (the 'a' will not appear). + # + # To see an example, enable the 'b-confusing' test, and examine the + # reported log: + # + # expand.pl: test b-confusing: stdout mismatch + # *** b-confusing.2 Fri Jun 24 15:43:21 2016 + # --- b-confusing.O Fri Jun 24 15:43:21 2016 + # *************** + # *** 1 **** + # ! c d + # --- 1 ---- + # ! c d + # + # ['b-confusing','', {IN=>"aaa\b\b\bc\td\n"}, {OUT=>"c d\n"}], + + ['b1','', {IN=>"aaa\b\b\bc\td\n"}, {OUT=>"aaa\b\b\bc d\n"}], + + # \b as first character, when column is zero + ['b2','', {IN=>"\bc\td"}, {OUT=>"\bc d"}], + + # Testing tab list adjusted due to backspaces + # ('b3' is the baseline without backspaces). + ['b3','--tabs 2,4,6,10', + {IN=>"1\t2\t3\t4\t5\n" . + "a\tb\tc\td\te\n"}, + {OUT=>"1 2 3 4 5\n" . + "a b c d e\n"}], + + # On screen this will appear the same as 'b3' + ['b4','--tabs 2,4,6,10', + {IN=>"1\t2\t3\t4\t5\n" . + "a\tbHELLO\b\b\b\b\b\tc\td\te\n"}, + {OUT=>"1 2 3 4 5\n" . + "a bHELLO\b\b\b\b\b c d e\n"}], + + # On screen on 'bHE' will appear (LLO overwritten by spaces), + # 'c' should align with 4, 'd' with 5: + # 1 2 3 4 5 + # a bHE c d e + ['b5','--tabs 2,4,6,10', + {IN=>"1\t2\t3\t4\t5\n" . + "a\tbHELLO\b\b\b\tc\td\te\n"}, + {OUT=>"1 2 3 4 5\n" . + "a bHELLO\b\b\b c d e\n"}], + + # Test the trailing '/' feature which specifies the + # tab size to use after the last specified stop + ['trail1', '--tabs=1,/5', {IN=>"\ta\tb\tc"}, {OUT=>" a b c"}], + ['trail2', '--tabs=2,/5', {IN=>"\ta\tb\tc"}, {OUT=>" a b c"}], + ['trail3', '--tabs=1,2,/5', {IN=>"\ta\tb\tc"}, {OUT=>" a b c"}], + ['trail4', '--tabs=/5', {IN=>"\ta\tb"}, {OUT=>" a b"}], + ['trail5', '--tabs=//5', {IN=>"\ta\tb"}, {OUT=>" a b"}], + ['trail5a','--tabs=+/5', {IN=>"\ta\tb"}, {OUT=>" a b"}], + ['trail6', '--tabs=/,/5', {IN=>"\ta\tb"}, {OUT=>" a b"}], + ['trail7', '--tabs=,/5', {IN=>"\ta\tb"}, {OUT=>" a b"}], + ['trail8', '--tabs=1 -t/5', {IN=>"\ta\tb\tc"}, {OUT=>" a b c"}], + ['trail9', '--tab=1,2 -t/5',{IN=>"\ta\tb\tc"}, {OUT=>" a b c"}], + + # Test incremental trailing '+' feature which specifies that + # tab stops should continue every increment + ['incre0', '--tab=1,+5', {IN=>"+\t\ta\tb"}, {OUT=>"+ a b"}], + ['incre1', '--tabs=1,+5', {IN=>"\ta\tb\tc"}, {OUT=>" a b c"}], + ['incre2', '--tabs=2,+5', {IN=>"\ta\tb\tc"}, {OUT=>" a b c"}], + ['incre3', '--tabs=1,2,+5', {IN=>"\ta\tb\tc"}, {OUT=>" a b c"}], + ['incre4', '--tabs=+5', {IN=>"\ta\tb"}, {OUT=>" a b"}], + ['incre5', '--tabs=++5', {IN=>"\ta\tb"}, {OUT=>" a b"}], + ['incre5a','--tabs=/+5', {IN=>"\ta\tb"}, {OUT=>" a b"}], + ['incre6', '--tabs=+,+5', {IN=>"\ta\tb"}, {OUT=>" a b"}], + ['incre7', '--tabs=,+5', {IN=>"\ta\tb"}, {OUT=>" a b"}], + ['incre8', '--tabs=1 -t+5', {IN=>"\ta\tb\tc"}, {OUT=>" a b c"}], + ['incre9', '--tab=1,2 -t+5',{IN=>"\ta\tb\tc"}, {OUT=>" a b c"}], + + + # Test errors + ['e1', '--tabs="a"', {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR => "$prog: tab size contains invalid character(s): 'a'\n"}], + ['e2', "-t $UINTMAX_OFLOW", {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR => "$prog: tab stop is too large '$UINTMAX_OFLOW'\n"}], + ['e3', '--tabs=0', {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR => "$prog: tab size cannot be 0\n"}], + ['e4', '--tabs=3,3', {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR => "$prog: tab sizes must be ascending\n"}], + ['e5', '--tabs=/3,6,8', {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR => "$prog: '/' specifier only allowed with the last value\n"}], + ['e6', '-t/3 -t/6', {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR => "$prog: '/' specifier only allowed with the last value\n"}], + ['e7', '--tabs=3/', {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR => "$prog: '/' specifier not at start of number: '/'\n"}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/expr-multibyte.pl b/tests/misc/expr-multibyte.pl new file mode 100755 index 0000000..635b0de --- /dev/null +++ b/tests/misc/expr-multibyte.pl @@ -0,0 +1,226 @@ +#!/usr/bin/perl +# Exercise expr with multibyte input + +# Copyright (C) 2017-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $ME = $0) =~ s|.*/||; + +my $limits = getlimits (); +my $UINTMAX_OFLOW = $limits->{UINTMAX_OFLOW}; + +(my $program_name = $0) =~ s|.*/||; +my $prog = 'expr'; + +my $locale = $ENV{LOCALE_FR_UTF8}; +! defined $locale || $locale eq 'none' + and CuSkip::skip "$ME: this test requires FR-UTF8 locale\n"; + + +=pod +ἔκφρασις (ekphrasis) - "expression" in Ancient Greek. +=cut +my $expression = "\x{1F14}\x{3BA}\x{3C6}\x{3C1}\x{3B1}\x{3C3}\x{3B9}\x{3C2}"; + + +## NOTE about tests locales: +## Tests starting with 'mb' will have {ENV=>"LC_ALL=$locale"} +## added to them automatically - results are multibyte-aware. +## Tests starting with 'sb' have the same input but will be +## run under C locale and will be treated as single-bytes. +## This enables interleaving C/UTF8 tests +## (for easier comparison of expected results). + +my @Tests = + ( + ### length expressions ### + + # sanity check + ['mb-l1', 'length abcdef', {OUT=>"6"}], + ['st-l1', 'length abcdef', {OUT=>"6"}], + + # A single multibyte character in the beginning of the string + # \xCE\xB1 is UTF-8 for "U+03B1 GREEK SMALL LETTER ALPHA" + ['mb-l2', "length \xCE\xB1bcdef", {OUT=>"6"}], + ['st-l2', "length \xCE\xB1bcdef", {OUT=>"7"}], + + # A single multibyte character in the middle of the string + # \xCE\xB4 is UTF-8 for "U+03B4 GREEK SMALL LETTER DELTA" + ['mb-l3', "length abc\xCE\xB4ef", {OUT=>"6"}], + ['st-l3', "length abc\xCE\xB4ef", {OUT=>"7"}], + + # A single multibyte character in the end of the string + ['mb-l4', "length fedcb\xCE\xB1", {OUT=>"6"}], + ['st-l4', "length fedcb\xCE\xB1", {OUT=>"7"}], + + # A invalid multibyte sequence + ['mb-l5', "length \xB1aaa", {OUT=>"4"}], + ['st-l5', "length \xB1aaa", {OUT=>"4"}], + + # An incomplete multibyte sequence at the end of the string + ['mb-l6', "length aaa\xCE", {OUT=>"4"}], + ['st-l6', "length aaa\xCE", {OUT=>"4"}], + + # An incomplete multibyte sequence at the end of the string + ['mb-l7', "length $expression", {OUT=>"8"}], + ['st-l7', "length $expression", {OUT=>"17"}], + + + + ### index expressions ### + + # sanity check + ['mb-i1', 'index abcdef fb', {OUT=>"2"}], + ['st-i1', 'index abcdef fb', {OUT=>"2"}], + + # Search for a single-octet + ['mb-i2', "index \xCE\xB1bc\xCE\xB4ef b", {OUT=>"2"}], + ['st-i2', "index \xCE\xB1bc\xCE\xB4ef b", {OUT=>"3"}], + ['mb-i3', "index \xCE\xB1bc\xCE\xB4ef f", {OUT=>"6"}], + ['st-i3', "index \xCE\xB1bc\xCE\xB4ef f", {OUT=>"8"}], + + # Search for multibyte character. + # In the C locale, the search string is treated as two octets. + # the first of them (\xCE) matches the first octet of the input string. + ['mb-i4', "index \xCE\xB1bc\xCE\xB4ef \xCE\xB4", {OUT=>"4"}], + ['st-i4', "index \xCE\xB1bc\xCE\xB4ef \xCE\xB4", {OUT=>"1"}], + + # Invalid multibyte sequence in the input string, treated as a single octet. + ['mb-i5', "index \xCEbc\xCE\xB4ef \xCE\xB4", {OUT=>"4"}], + ['st-i5', "index \xCEbc\xCE\xB4ef \xCE\xB4", {OUT=>"1"}], + + # Invalid multibyte sequence in the search string, treated as a single octet. + # In multibyte locale, there should be no match, expr returns and prints + # zero, and terminates with exit-code 1 (as per POSIX). + ['mb-i6', "index \xCE\xB1bc\xCE\xB4ef \xB4", {OUT=>"0"}, {EXIT=>1}], + ['st-i6', "index \xCE\xB1bc\xCE\xB4ef \xB4", {OUT=>"6"}], + + # Edge-case: invalid multibyte sequence BOTH in the input string + # and in the search string: expr should find a match. + ['mb-i7', "index \xCE\xB1bc\xB4ef \xB4", {OUT=>"4"}], + + + ### substr expressions ### + + # sanity check + ['mb-s1', 'substr abcdef 2 3', {OUT=>"bcd"}], + ['st-s1', 'substr abcdef 2 3', {OUT=>"bcd"}], + + ['mb-s2', "substr \xCE\xB1bc\xCE\xB4ef 1 1", {OUT=>"\xCE\xB1"}], + ['st-s2', "substr \xCE\xB1bc\xCE\xB4ef 1 1", {OUT=>"\xCE"}], + + ['mb-s3', "substr \xCE\xB1bc\xCE\xB4ef 3 2", {OUT=>"c\xCE\xB4"}], + ['st-s3', "substr \xCE\xB1bc\xCE\xB4ef 3 2", {OUT=>"bc"}], + + ['mb-s4', "substr \xCE\xB1bc\xCE\xB4ef 4 1", {OUT=>"\xCE\xB4"}], + ['st-s4', "substr \xCE\xB1bc\xCE\xB4ef 4 1", {OUT=>"c"}], + + ['mb-s5', "substr \xCE\xB1bc\xCE\xB4ef 4 2", {OUT=>"\xCE\xB4e"}], + ['st-s5', "substr \xCE\xB1bc\xCE\xB4ef 4 2", {OUT=>"c\xCE"}], + + ['mb-s6', "substr \xCE\xB1bc\xCE\xB4ef 6 1", {OUT=>"f"}], + ['st-s6', "substr \xCE\xB1bc\xCE\xB4ef 6 1", {OUT=>"\xB4"}], + + ['mb-s7', "substr \xCE\xB1bc\xCE\xB4ef 7 1", {OUT=>""}, {EXIT=>1}], + ['st-s7', "substr \xCE\xB1bc\xCE\xB4ef 7 1", {OUT=>"e"}], + + # Invalid multibyte sequences + ['mb-s8', "substr \xCE\xB1bc\xB4ef 3 3", {OUT=>"c\xB4e"}], + ['st-s8', "substr \xCE\xB1bc\xB4ef 3 3", {OUT=>"bc\xB4"}], + + + ### match expressions ### + + # sanity check + ['mb-m1', 'match abcdef ab', {OUT=>"2"}], + ['st-m1', 'match abcdef ab', {OUT=>"2"}], + ['mb-m2', 'match abcdef "\(ab\)"', {OUT=>"ab"}], + ['st-m2', 'match abcdef "\(ab\)"', {OUT=>"ab"}], + + # The regex engine should match the '.' to the first multibyte character. + ['mb-m3', "match \xCE\xB1bc\xCE\xB4ef .bc", {OUT=>"3"}], + ['st-m3', "match \xCE\xB1bc\xCE\xB4ef .bc", {OUT=>"0"}, {EXIT=>1}], + + # The opposite of the previous test: two dots should only match + # the two octets in single-byte locale. + ['mb-m4', "match \xCE\xB1bc\xCE\xB4ef ..bc", {OUT=>"0"}, {EXIT=>1}], + ['st-m4', "match \xCE\xB1bc\xCE\xB4ef ..bc", {OUT=>"4"}], + + # Match with grouping - a single dot should return the two octets + ['mb-m5', "match \xCE\xB1bc\xCE\xB4ef '\\(.b\\)c'", {OUT=>"\xCE\xB1b"}], + ['st-m5', "match \xCE\xB1bc\xCE\xB4ef '\\(.b\\)c'", {OUT=>""}, {EXIT=>1}], + + # Invalid multibyte sequences - regex should not match in multibyte locale + # (POSIX requirement) + ['mb-m6', "match \xCEbc\xCE\xB4ef '\\(.\\)'", {OUT=>""}, {EXIT=>1}], + ['st-m6', "match \xCEbc\xCE\xB4ef '\\(.\\)'", {OUT=>"\xCE"}], + + + # Character classes: in the multibyte case, the regex engine understands + # there is a single multibyte characeter in the brackets. + # In the single byte case, the regex engine sees two octets in the character + # class ('\xCE' and '\xB1') - and it matches the first one. + ['mb-m7', "match \xCE\xB1bc\xCE\xB4e '\\([\xCE\xB1]\\)'", {OUT=>"\xCE\xB1"}], + ['st-m7', "match \xCE\xB1bc\xCE\xB4e '\\([\xCE\xB1]\\)'", {OUT=>"\xCE"}], + + ); + + +# Append a newline to end of each expected 'OUT' string. +my $t; +foreach $t (@Tests) + { + my $arg1 = $t->[1]; + my $e; + foreach $e (@$t) + { + $e->{OUT} .= "\n" + if ref $e eq 'HASH' and exists $e->{OUT}; + } + } + + +# Force multibyte locale in all tests. +# +# NOTE about the ERR_SUBST: +# The error tests above (e1/e2/e3/e4) expect error messages in C locale +# having single-quote character (ASCII 0x27). +# In UTF-8 locale, the error messages will use: +# 'LEFT SINGLE QUOTATION MARK' (U+2018) (UTF8: 0xE2 0x80 0x98) +# 'RIGHT SINGLE QUOTATION MARK' (U+2019) (UTF8: 0xE2 0x80 0x99) +# So we replace them with ascii single-quote and the results will +# match the expected error string. +if ($locale ne 'C') + { + my @new; + foreach my $t (@Tests) + { + my ($tname) = @$t; + if ($tname =~ /^mb/) + { + push @$t, ({ENV => "LC_ALL=$locale"}, + {ERR_SUBST => "s/\xe2\x80[\x98\x99]/'/g"}); + } + } + } + + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/expr.pl b/tests/misc/expr.pl new file mode 100755 index 0000000..5be0404 --- /dev/null +++ b/tests/misc/expr.pl @@ -0,0 +1,238 @@ +#!/usr/bin/perl +# Basic tests for "expr". + +# Copyright (C) 2001-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; +my $prog = 'expr'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $mb_locale = $ENV{LOCALE_FR_UTF8}; +! defined $mb_locale || $mb_locale eq 'none' + and $mb_locale = 'C'; + +my $big = '98782897298723498732987928734'; +my $big_p1 = '98782897298723498732987928735'; +my $big_sum = '197565794597446997465975857469'; +my $big_prod = '9758060798730154302876482828124348356960410232492450771490'; + +my @Tests = + ( + ['a', '5 + 6', {OUT => '11'}], + ['b', '5 - 6', {OUT => '-1'}], + ['c', '5 \* 6', {OUT => '30'}], + ['d', '100 / 6', {OUT => '16'}], + ['e', '100 % 6', {OUT => '4'}], + ['f', '3 + -2', {OUT => '1'}], + ['g', '-2 + -2', {OUT => '-4'}], + + # Verify option processing. + # Added when option processing broke in the 7.0 beta release + ['opt1', '-- -11 + 12', {OUT => '1'}], + ['opt2', '-11 + 12', {OUT => '1'}], + ['opt3', '-- -1 + 2', {OUT => '1'}], + ['opt4', '-1 + 2', {OUT => '1'}], + # This evoked a syntax error diagnostic before 2.0.12. + ['opt5', '-- 2 + 2', {OUT => '4'}], + + ['paren1', '\( 100 % 6 \)', {OUT => '4'}], + ['paren2', '\( 100 % 6 \) - 8', {OUT => '-4'}], + ['paren3', '9 / \( 100 % 6 \) - 8', {OUT => '-6'}], + ['paren4', '9 / \( \( 100 % 6 \) - 8 \)', {OUT => '-2'}], + ['paren5', '9 + \( 100 % 6 \)', {OUT => '13'}], + + # Before 2.0.12, this would output '1'. + ['0bang', '00 \< 0!', {OUT => '0'}, {EXIT => 1}], + + # In 5.1.3 and earlier, these would exit with status 0. + ['00', '00', {OUT => '00'}, {EXIT => 1}], + ['minus0', '-0', {OUT => '-0'}, {EXIT => 1}], + + # In 5.1.3 and earlier, these would report errors. + ['andand', '0 \& 1 / 0', {OUT => '0'}, {EXIT => 1}], + ['oror', '1 \| 1 / 0', {OUT => '1'}, {EXIT => 0}], + + # In 5.1.3 and earlier, this would output the empty string. + ['orempty', '"" \| ""', {OUT => '0'}, {EXIT => 1}], + + + # This erroneously succeeded and output '3' before 2.0.12. + ['fail-a', '3 + -', {ERR => "$prog: non-integer argument\n"}, + {EXIT => 2}], + + # This erroneously succeeded before 5.3.1. + ['bigcmp', '-- -2417851639229258349412352 \< 2417851639229258349412352', + {OUT => '1'}, {EXIT => 0}], + + # In 5.94 and earlier, anchors incorrectly matched newlines. + ['anchor', "'a\nb' : 'a\$'", {OUT => '0'}, {EXIT => 1}], + + # In 8.32, \( ... \) that did not match caused memory errors. + ['emptysub', '"a" : "\\(b\\)*"', {OUT => ''}, {EXIT => 1}], + + # These tests are taken from grep/tests/bre.tests. + ['bre1', '"abc" : "a\\(b\\)c"', {OUT => 'b'}], + ['bre2', '"a(" : "a("', {OUT => '2'}], + ['bre3', '_ : "a\\("', + {ERR => "$prog: Unmatched ( or \\(\n"}, {EXIT => 2}], + ['bre4', '_ : "a\\(b"', + {ERR => "$prog: Unmatched ( or \\(\n"}, {EXIT => 2}], + ['bre5', '"a(b" : "a(b"', {OUT => '3'}], + ['bre6', '"a)" : "a)"', {OUT => '2'}], + ['bre7', '_ : "a\\)"', + {ERR => "$prog: Unmatched ) or \\)\n"}, {EXIT => 2}], + ['bre8', '_ : "\\)"', + {ERR => "$prog: Unmatched ) or \\)\n"}, {EXIT => 2}], + ['bre9', '"ab" : "a\\(\\)b"', {OUT => ''}, {EXIT => 1}], + ['bre10', '"a^b" : "a^b"', {OUT => '3'}], + ['bre11', '"a\$b" : "a\$b"', {OUT => '3'}], + ['bre12', '"" : "\\($\\)\\(^\\)"', {OUT => ''}, {EXIT => 1}], + ['bre13', '"b" : "a*\\(^b\$\\)c*"', {OUT => 'b'}], + ['bre14', '"X|" : "X\\(|\\)" : "(" "X|" : "X\\(|\\)" ")"', {OUT => '1'}], + ['bre15', '"X*" : "X\\(*\\)" : "(" "X*" : "X\\(*\\)" ")"', {OUT => '1'}], + ['bre16', '"abc" : "\\(\\)"', {OUT => ''}, {EXIT => 1}], + ['bre17', '"{1}a" : "\\(\\{1\\}a\\)"', {OUT => '{1}a'}], + ['bre18', '"X*" : "X\\(*\\)" : "^*"', {OUT => '1'}], + ['bre19', '"{1}" : "^\\{1\\}"', {OUT => '3'}], + ['bre20', '"{" : "{"', {OUT => '1'}], + ['bre21', '"abbcbd" : "a\\(b*\\)c\\1d"', {OUT => ''}, {EXIT => 1}], + ['bre22', '"abbcbbbd" : "a\\(b*\\)c\\1d"', {OUT => ''}, {EXIT => 1}], + ['bre23', '"abc" : "\\(.\\)\\1"', {OUT => ''}, {EXIT => 1}], + ['bre24', '"abbccd" : "a\\(\\([bc]\\)\\2\\)*d"', {OUT => 'cc'}], + ['bre25', '"abbcbd" : "a\\(\\([bc]\\)\\2\\)*d"', + {OUT => ''}, {EXIT => 1}], + ['bre26', '"abbbd" : "a\\(\\(b\\)*\\2\\)*d"', {OUT => 'bbb'}], + ['bre27', '"aabcd" : "\\(a\\)\\1bcd"', {OUT => 'a'}], + ['bre28', '"aabcd" : "\\(a\\)\\1bc*d"', {OUT => 'a'}], + ['bre29', '"aabd" : "\\(a\\)\\1bc*d"', {OUT => 'a'}], + ['bre30', '"aabcccd" : "\\(a\\)\\1bc*d"', {OUT => 'a'}], + ['bre31', '"aabcccd" : "\\(a\\)\\1bc*[ce]d"', {OUT => 'a'}], + ['bre32', '"aabcccd" : "\\(a\\)\\1b\\(c\\)*cd\$"', {OUT => 'a'}], + ['bre33', '"a*b" : "a\\(*\\)b"', {OUT => '*'}], + ['bre34', '"ab" : "a\\(**\\)b"', {OUT => ''}, {EXIT => 1}], + ['bre35', '"ab" : "a\\(***\\)b"', {OUT => ''}, {EXIT => 1}], + ['bre36', '"*a" : "*a"', {OUT => '2'}], + ['bre37', '"a" : "**a"', {OUT => '1'}], + ['bre38', '"a" : "***a"', {OUT => '1'}], + ['bre39', '"ab" : "a\\{1\\}b"', {OUT => '2'}], + ['bre40', '"ab" : "a\\{1,\\}b"', {OUT => '2'}], + ['bre41', '"aab" : "a\\{1,2\\}b"', {OUT => '3'}], + ['bre42', '_ : "a\\{1"', + {ERR => "$prog: Unmatched \\{\n"}, {EXIT => 2}], + ['bre43', '_ : "a\\{1a"', + {ERR => "$prog: Unmatched \\{\n"}, {EXIT => 2}], + ['bre44', '_ : "a\\{1a\\}"', + {ERR => "$prog: Invalid content of \\{\\}\n"}, {EXIT => 2}], + ['bre45', '"a" : "a\\{,2\\}"', {OUT => '1'}], + ['bre46', '"a" : "a\\{,\\}"', {OUT => '1'}], + ['bre47', '_ : "a\\{1,x\\}"', + {ERR => "$prog: Invalid content of \\{\\}\n"}, {EXIT => 2}], + ['bre48', '_ : "a\\{1,x"', + {ERR => "$prog: Unmatched \\{\n"}, {EXIT => 2}], + ['bre49', '_ : "a\\{32768\\}"', + {ERR => "$prog: Invalid content of \\{\\}\n"}, {EXIT => 2}, + # Map AIX-6's different diagnostic to the one we expect: + {ERR_SUBST => + 's,Regular expression too big,Invalid content of \\\\{\\\\},'}, + ], + ['bre50', '_ : "a\\{1,0\\}"', + {ERR => "$prog: Invalid content of \\{\\}\n"}, {EXIT => 2}], + ['bre51', '"acabc" : ".*ab\\{0,0\\}c"', {OUT => '2'}], + ['bre52', '"abcac" : "ab\\{0,1\\}c"', {OUT => '3'}], + ['bre53', '"abbcac" : "ab\\{0,3\\}c"', {OUT => '4'}], + ['bre54', '"abcac" : ".*ab\\{1,1\\}c"', {OUT => '3'}], + ['bre55', '"abcac" : ".*ab\\{1,3\\}c"', {OUT => '3'}], + ['bre56', '"abbcabc" : ".*ab\{2,2\}c"', {OUT => '4'}], + ['bre57', '"abbcabc" : ".*ab\{2,4\}c"', {OUT => '4'}], + ['bre58', '"aa" : "a\\{1\\}\\{1\\}"', {OUT => '1'}], + ['bre59', '"aa" : "a*\\{1\\}"', {OUT => '2'}], + ['bre60', '"aa" : "a\\{1\\}*"', {OUT => '2'}], + ['bre61', '"acd" : "a\\(b\\)?c\\1d"', {OUT => ''}, {EXIT => 1}], + ['bre62', '-- "-5" : "-\\{0,1\\}[0-9]*\$"', {OUT => '2'}], + + ['fail-c', {ERR => "$prog: missing operand\n" + . "Try '$prog --help' for more information.\n"}, + {EXIT => 2}], + + ['bignum-add', "$big + 1", {OUT => $big_p1}], + ['bignum-add2', "$big + $big_p1", {OUT => $big_sum}], + ['bignum-sub', "$big_p1 - 1", {OUT => $big}], + ['bignum-sub2', "$big_sum - $big", {OUT => $big_p1}], + ['bignum-mul', "$big_p1 '*' $big", {OUT => $big_prod}], + ['bignum-div', "$big_prod / $big", {OUT => $big_p1}], + + + # Test syntax error messages + ['se0', '9 9', + {ERR => "$prog: syntax error: unexpected argument '9'\n"}, {EXIT => 2}], + ['se1', "2 a", {EXIT=>2}, + {ERR=>"$prog: syntax error: unexpected argument 'a'\n"}], + ['se2', "2 '+'", {EXIT=>2}, + {ERR=>"$prog: syntax error: missing argument after '+'\n"}], + ['se3', "2 :", {EXIT=>2}, + {ERR=>"$prog: syntax error: missing argument after ':'\n"}], + ['se4', "length", {EXIT=>2}, + {ERR=>"$prog: syntax error: missing argument after 'length'\n"}], + ['se5', "'(' 2 ", {EXIT=>2}, + {ERR=>"$prog: syntax error: expecting ')' after '2'\n"}], + ['se6', "'(' 2 a", {EXIT=>2}, + {ERR=>"$prog: syntax error: expecting ')' instead of 'a'\n"}], + ); + +# Append a newline to end of each expected 'OUT' string. +my $t; +foreach $t (@Tests) + { + my $arg1 = $t->[1]; + my $e; + foreach $e (@$t) + { + $e->{OUT} .= "\n" + if ref $e eq 'HASH' and exists $e->{OUT}; + } + } + +# Try multibyte locale in most tests. +# +if ($mb_locale ne 'C') + { + # Duplicate each test vector, appending "-mb" to the test name and + # inserting {ENV => "LC_ALL=$mb_locale"} in the copy, so that we + # provide coverage for the distro-added multi-byte code paths. + my @new; + foreach my $t (@Tests) + { + # Don't add the quote varying tests to the multi-byte set + $t->[0] =~ /^se/ + and next; + + my @new_t = @$t; + my $test_name = shift @new_t; + + push @new, ["$test_name-mb", @new_t, {ENV => "LC_ALL=$mb_locale"}]; + } + push @Tests, @new; + } + +my $save_temps = $ENV{SAVE_TEMPS}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/factor-parallel.sh b/tests/misc/factor-parallel.sh new file mode 100755 index 0000000..153f6cf --- /dev/null +++ b/tests/misc/factor-parallel.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Test for complete lines on output + +# Copyright (C) 2015-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ factor + + +odd() { LC_ALL=C sed '/[24680]$/d'; } +primes() { LC_ALL=C sed 's/.*: //; / /d'; } + +# Before v8.24 the number reported here would vary +# Note -u not supplied to split, increased batching of quickly processed items. +# As processing cost increases it becomes advantageous to use -u to keep +# the factor processes supplied with data. +nprimes=$(seq 1e6 | odd | split -nr/4 --filter='factor' | primes | wc -l) + +test "$nprimes" = '78498' || fail=1 + +Exit $fail diff --git a/tests/misc/factor.pl b/tests/misc/factor.pl new file mode 100755 index 0000000..a12768b --- /dev/null +++ b/tests/misc/factor.pl @@ -0,0 +1,122 @@ +#!/usr/bin/perl +# Basic tests for "factor". + +# Copyright (C) 1998-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; +my $prog = 'factor'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + ['1', '9', {OUT => '3 3'}], + ['1a', '7', {OUT => '7'}], + ['1b', ' +7', {OUT => '7'}], + ['2', '4294967291', {OUT => '4294967291'}], + ['3', '4294967292', {OUT => '2 2 3 3 7 11 31 151 331'}], + ['4', '4294967293', {OUT => '9241 464773'}], + + ['a', '4294966201', {OUT => '12197 352133'}], + ['b', '4294966339', {OUT => '13187 325697'}], + ['c', '4294966631', {OUT => '13729 312839'}], + ['d', '4294966457', {OUT => '14891 288427'}], + ['e', '4294966759', {OUT => '21649 198391'}], + ['f', '4294966573', {OUT => '23071 186163'}], + ['g', '4294967101', {OUT => '23603 181967'}], + ['h', '4294966519', {OUT => '34583 124193'}], + ['i', '4294966561', {OUT => '36067 119083'}], + ['j', '4294966901', {OUT => '37747 113783'}], + ['k', '4294966691', {OUT => '39241 109451'}], + ['l', '4294966969', {OUT => '44201 97169'}], + ['m', '4294967099', {OUT => '44483 96553'}], + ['n', '4294966271', {OUT => '44617 96263'}], + ['o', '4294966789', {OUT => '50411 85199'}], + ['p', '4294966189', {OUT => '53197 80737'}], + ['q', '4294967213', {OUT => '57139 75167'}], + ['s', '4294967071', {OUT => '65521 65551'}], + ['t', '4294966194', {OUT => '2 3 3 3 3 3 3 3 53 97 191'}], + ['u', '4294966272', {OUT => '2 2 2 2 2 2 2 2 2 2 3 23 89 683'}], + ['v', '4294966400', {OUT => '2 2 2 2 2 2 2 5 5 1342177'}], + ['w', '4294966464', {OUT => '2 2 2 2 2 2 3 3 3 2485513'}], + ['x', '4294966896', {OUT => '2 2 2 2 3 3 3 11 607 1489'}], + ['y', '4294966998', {OUT => '2 3 7 3917 26107'}], + ['z', '-1', + # Map newer glibc diagnostic to expected. + # Also map OpenBSD 5.1's "unknown option" to expected "invalid option". + {ERR_SUBST => q!s/'1'/1/;s/unknown/invalid/!}, + {ERR => "$prog: invalid option -- 1\n" + . "Try '$prog --help' for more information.\n"}, + {EXIT => 1}], + ['cont', 'a 4', + {OUT => "4: 2 2\n"}, + {ERR => "$prog: 'a' is not a valid positive integer\n"}, + {EXIT => 1}], + ['bug-2012-a', '465658903', {OUT => '15259 30517'}], + ['bug-2012-b', '2242724851', {OUT => '33487 66973'}], + ['bug-2012-c', '6635692801', {OUT => '57601 115201'}], + ['bug-2012-d', '17709149503', {OUT => '94099 188197'}], + ['bug-2012-e', '17754345703', {OUT => '94219 188437'}], + # Infinite loop bugs in v8.20 to 8.26 inclusive + ['bug-2016-a', '158909489063877810457', + {OUT => '3401347 3861211 12099721'}], + ['bug-2016-b', '222087527029934481871', + {OUT => '15601 26449 111427 4830277'}], + ['bug-2016-c', '12847291069740315094892340035', + {OUT => '5 4073 18899 522591721 63874247821'}], + ['bug-gmp-2_sup_128', '340282366920938463463374607431768211456', + {OUT => '2 'x127 . '2'}], + ['bug-gmp-2_sup_256', + '115792089237316195423570985008687907853' + . '269984665640564039457584007913129639936', + {OUT => '2 'x255 . '2'}], + ['bug-gmp-plus_2_sup_128_plus_1', + '+170141183460469231731687303715884105729', + {OUT => '3 56713727820156410577229101238628035243'}], + ); + + +# Prepend the command line argument and append a newline to end +# of each expected 'OUT' string. +my $t; + +Test: +foreach $t (@Tests) + { + (my $arg1 = $t->[1]) =~ s| *\+?||; + + # Don't fiddle with expected OUT string if there's a nonzero exit status. + foreach my $e (@$t) + { + ref $e eq 'HASH' && exists $e->{EXIT} && $e->{EXIT} + and next Test; + } + + foreach my $e (@$t) + { + ref $e eq 'HASH' && exists $e->{OUT} + and $e->{OUT} = "$arg1: $e->{OUT}\n" + } + } + +my $save_temps = $ENV{SAVE_TEMPS}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/false-status.sh b/tests/misc/false-status.sh new file mode 100755 index 0000000..5f4ab7e --- /dev/null +++ b/tests/misc/false-status.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# ensure that false exits nonzero even with --help or --version +# and ensure that true exits nonzero when it can't write --help or --version + +# Copyright (C) 2003-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ false true + +returns_ 1 env false --version > /dev/null || fail=1 +returns_ 1 env false --help > /dev/null || fail=1 + +if test -w /dev/full && test -c /dev/full; then + returns_ 1 env true --version > /dev/full || fail=1 + returns_ 1 env true --help > /dev/full || fail=1 +fi + +Exit $fail diff --git a/tests/misc/fold.pl b/tests/misc/fold.pl new file mode 100755 index 0000000..2834f92 --- /dev/null +++ b/tests/misc/fold.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl +# Exercise fold. + +# Copyright (C) 2003-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + ['s1', '-w2 -s', {IN=>"a\t"}, {OUT=>"a\n\t"}], + ['s2', '-w4 -s', {IN=>"abcdef d\n"}, {OUT=>"abcd\nef d\n"}], + ['s3', '-w4 -s', {IN=>"a cd fgh\n"}, {OUT=>"a \ncd \nfgh\n"}], + ['s4', '-w4 -s', {IN=>"abc ef\n"}, {OUT=>"abc \nef\n"}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'fold'; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/groups-dash.sh b/tests/misc/groups-dash.sh new file mode 100755 index 0000000..d4d2dcd --- /dev/null +++ b/tests/misc/groups-dash.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# ensure groups handles -- sanely + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ groups + +# An invalid user name +user=:invalid + +printf '%s\n' "groups: ':invalid': no such user" > exp || framework_failure_ + +# Coreutils 6.9 and earlier failed to display information on first argument +# if later argument was --. +returns_ 1 groups $user -- > out 2>&1 || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/groups-process-all.sh b/tests/misc/groups-process-all.sh new file mode 100755 index 0000000..77be78f --- /dev/null +++ b/tests/misc/groups-process-all.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Ensure groups processes all arguments before exiting. +# With coreutils-2.27 and prior, it would exit upon first failure. + +# Copyright (C) 2017-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ groups + +returns_ 1 groups :1 :2 :3 2> err || fail=1 +test $(wc -l < err) = 3 || fail=1 + +Exit $fail diff --git a/tests/misc/groups-version.sh b/tests/misc/groups-version.sh new file mode 100755 index 0000000..14ba4bd --- /dev/null +++ b/tests/misc/groups-version.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# ensure groups --version output is similar to id --version + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ groups + +groups --version | sed 's/^groups/id/; /^$/q' > out || fail=1 +id --version | sed '/^$/q' > exp || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/head-c.sh b/tests/misc/head-c.sh new file mode 100755 index 0000000..7655ff3 --- /dev/null +++ b/tests/misc/head-c.sh @@ -0,0 +1,59 @@ +#!/bin/sh +# exercise head -c + +# Copyright (C) 2001-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ head +getlimits_ + +vm=$(get_min_ulimit_v_ head -c1 /dev/null) \ + || skip_ "this shell lacks ulimit support" + +# exercise the fix of 2001-08-18, based on test case from Ian Bruce +echo abc > in || framework_failure_ +(head -c1; head -c1) < in > out || fail=1 +case "$(cat out)" in + ab) ;; + *) fail=1 ;; +esac + +# Test for a bug in coreutils 5.0.1 through 8.22. +printf 'abc\ndef\n' > in1 || framework_failure_ +(dd bs=1 skip=1 count=0 status=none && head -c-4) < in1 > out1 || fail=1 +case "$(cat out1)" in + bc) ;; + *) fail=1 ;; +esac + +# Only allocate memory as needed. +# Coreutils <= 8.21 would allocate memory up front +# based on the value passed to -c +(ulimit -v $(($vm+8000)) && head --bytes=-$SSIZE_MAX < /dev/null) || fail=1 + +# Make sure it works on funny files in /proc and /sys. + +for file in /proc/version /sys/kernel/profiling; do + if test -r $file; then + cp -f $file copy && + head -c -1 copy > exp1 || framework_failure_ + + head -c -1 $file > out1 || fail=1 + compare exp1 out1 || fail=1 + fi +done + +Exit $fail diff --git a/tests/misc/head-elide-tail.pl b/tests/misc/head-elide-tail.pl new file mode 100755 index 0000000..16f5f04 --- /dev/null +++ b/tests/misc/head-elide-tail.pl @@ -0,0 +1,110 @@ +#!/usr/bin/perl +# Exercise head's --bytes=-N option. + +# Copyright (C) 2003-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +$ENV{PROG} = 'head'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# This should match the definition in head.c. +my $READ_BUFSIZE = 8192; + +my @Tests = + ( + # Elide the exact size of the file. + ['elide-b1', "--bytes=-2", {IN=>"a\n"}, {OUT=>''}], + # Elide more than the size of the file. + ['elide-b2', "--bytes=-2", {IN=>"a"}, {OUT=>''}], + # Leave just one byte. + ['elide-b3', "--bytes=-2", {IN=>"abc"}, {OUT=>'a'}], + # Make it so the elided bytes straddle the end of the first + # $READ_BUFSIZE block. + ['elide-b4', "--bytes=-2", + {IN=> 'a' x ($READ_BUFSIZE-3) . "\nbcd"}, + {OUT=>'a' x ($READ_BUFSIZE-3) . "\nb"}], + # Make it so the elided bytes straddle the end of the 2nd + # $READ_BUFSIZE block. + ['elide-b5', "--bytes=-2", + {IN=> 'a' x (2 * $READ_BUFSIZE - 2) . 'bcd'}, + {OUT=>'a' x (2 * $READ_BUFSIZE - 2) . 'b'}], + + ['elide-l0', "--lines=-1", {IN=>''}, {OUT=>''}], + ['elide-l1', "--lines=-1", {IN=>"a\n"}, {OUT=>''}], + ['elide-l2', "--lines=-1", {IN=>"a"}, {OUT=>''}], + ['elide-l3', "--lines=-1", {IN=>"a\nb"}, {OUT=>"a\n"}], + ['elide-l4', "--lines=-1", {IN=>"a\nb\n"}, {OUT=>"a\n"}], + ['elide-l5', "--lines=-0", {IN=>"a\nb\n"}, {OUT=>"a\nb\n"}], + ['elide-l6', "--lines=-0", {IN=>"a\nb"}, {OUT=>"a\nb"}], + ); + +if ($ENV{RUN_EXPENSIVE_TESTS}) + { + # Brute force: use all combinations of file sizes [0..20] and + # number of bytes to elide [0..20]. For better coverage, recompile + # head with -DHEAD_TAIL_PIPE_READ_BUFSIZE=4 and + # -DHEAD_TAIL_PIPE_BYTECOUNT_THRESHOLD=8 + my $s = "abcdefghijklmnopqrst"; + for my $file_size (0..20) + { + for my $n_elide (0..20) + { + my $input = substr $s, 0, $file_size; + my $out_len = $n_elide < $file_size ? $file_size - $n_elide : 0; + my $output = substr $input, 0, $out_len; + my $t = ["elideb$file_size-$n_elide", "--bytes=-$n_elide", + {IN=>$input}, {OUT=>$output}]; + push @Tests, $t; + my @u = @$t; + # Insert the ---presume-input-pipe option. + $u[0] .= 'p'; + $u[1] .= ' ---presume-input-pipe'; + push @Tests, \@u; + } + } + + $s =~ s/(.)/$1\n/g; + $s .= 'u'; # test without trailing '\n' + for my $file_size (0..21) + { + for my $n_elide (0..21) + { + my $input = substr $s, 0, 2 * $file_size; + my $out_len = $n_elide < $file_size ? $file_size - $n_elide : 0; + my $output = substr $input, 0, 2 * $out_len; + my $t = ["elidel$file_size-$n_elide", "--lines=-$n_elide", + {IN=>$input}, {OUT=>$output}]; + push @Tests, $t; + my @u = @$t; + # Insert the ---presume-input-pipe option. + $u[0] .= 'p'; + $u[1] .= ' ---presume-input-pipe'; + push @Tests, \@u; + } + } + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n"; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/head-pos.sh b/tests/misc/head-pos.sh new file mode 100755 index 0000000..3715e90 --- /dev/null +++ b/tests/misc/head-pos.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# When reading a specified number of lines, ensure that the output +# file pointer is positioned just after those lines. + +# Copyright (C) 2002-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ head + +(echo a; echo b) > in || framework_failure_ +echo b > exp || framework_failure_ + +for i in -1 1; do + (head -n $i >/dev/null; cat) < in > out || fail=1 + compare exp out || fail=1 +done + +# Exercise the (start_pos < pos) block in elide_tail_lines_seekable. +# So far, this is the only test to do that. +# Do that by creating a file larger than BUFSIZ (I've seen 128K) and +# elide a suffix of it (by line count) that is also larger than BUFSIZ. +# 50000 lines times 6 bytes per line gives us enough leeway even on a +# system with a BUFSIZ of 256K. +n_lines=50000 +seq 70000 > in2 || framework_failure_ +echo $n_lines > exp-n || framework_failure_ + +(head -n-$n_lines>/dev/null; wc -l) < in2 > n +compare exp-n n || fail=1 + +Exit $fail diff --git a/tests/misc/head-write-error.sh b/tests/misc/head-write-error.sh new file mode 100755 index 0000000..6362261 --- /dev/null +++ b/tests/misc/head-write-error.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# Ensure we diagnose and not continue writing to +# the output if we get a write error. + +# Copyright (C) 2014-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ head + +if ! test -w /dev/full || ! test -c /dev/full; then + skip_ '/dev/full is required' +fi + +# We can't use /dev/zero as that's bypassed in the --lines case +# due to lseek() indicating it has a size of zero. +yes | head -c10M > bigseek || framework_failure_ + +# This is the single output diagnostic expected, +# (without the possibly varying :strerror(ENOSPC) suffix). +printf '%s\n' "head: error writing 'standard output'" > exp + +# Memory is bounded in these cases +for item in lines bytes; do + for N in 0 1; do + # pipe case + yes | returns_ 1 timeout 10s head --$item=-$N > /dev/full 2> errt || fail=1 + sed 's/\(head:.*\):.*/\1/' errt > err + compare exp err || fail=1 + + # seekable case + returns_ 1 timeout 10s head --$item=-$N bigseek > /dev/full 2> errt \ + || fail=1 + sed 's/\(head:.*\):.*/\1/' errt > err + compare exp err || fail=1 + done +done + +Exit $fail diff --git a/tests/misc/head.pl b/tests/misc/head.pl new file mode 100755 index 0000000..5c767cd --- /dev/null +++ b/tests/misc/head.pl @@ -0,0 +1,87 @@ +#!/usr/bin/perl +# test head + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $prog = 'head'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $in = join ('', map { "$_\n" } 0..600); +my $in_1024 = substr $in, 0, 1024; + +# FIXME: set this properly +my $x32_bit_long = 0; + +my @Tests = +( + ['idem-0', {IN=>''}, {OUT=>''}], + ['idem-1', {IN=>'a'}, {OUT=>'a'}], + ['idem-2', {IN=>"\n"}, {OUT=>"\n"}], + ['idem-3', {IN=>"a\n"}, {OUT=>"a\n"}], + + ['basic-10', + {IN=>"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n"}, + {OUT=>"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n"}], + + ['basic-09', + {IN=>"1\n2\n3\n4\n5\n6\n7\n8\n9\n"}, + {OUT=>"1\n2\n3\n4\n5\n6\n7\n8\n9\n"}], + + ['basic-11', + {IN=>"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\nb\n"}, + {OUT=>"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n"}], + + ['obs-0', '-1', {IN=>"1\n2\n"}, {OUT=>"1\n"}], + ['obs-1', '-1c', {IN=>''}, {OUT=>''}], + ['obs-2', '-1c', {IN=>'12'}, {OUT=>'1'}], + ['obs-3', '-14c', {IN=>'1234567890abcdefg'}, {OUT=>'1234567890abcd'}], + ['obs-4', '-2b', {IN=>$in}, {OUT=>$in_1024}], + ['obs-5', '-1k', {IN=>$in}, {OUT=>$in_1024}], + + # This test fails for textutils-1.22, because head let 4096m overflow to 0 + # and did not fail. Now head fails with a diagnostic. + # Disable this test because it fails on systems with 64-bit uintmax_t. + # ['fail-0', qw(-n 4096m), {IN=>"a\n"}, {EXIT=>1}], + + # In spite of its name, this test passes -- just to contrast with the above. + ['fail-1', qw(-n 2048m), {IN=>"a\n"}, {OUT=>"a\n"}], + + # Make sure we don't break like AIX 4.3.1 on files with \0 in them. + ['null-1', {IN=>"a\0a\n"}, {OUT=>"a\0a\n"}], + + # Make sure counts are interpreted as decimal. + # Before 2.0f, these would have been interpreted as octal + ['no-oct-1', '-08', {IN=>"\n"x12}, {OUT=>"\n"x8}], + ['no-oct-2', '-010', {IN=>"\n"x12}, {OUT=>"\n"x10}], + ['no-oct-3', '-n 08', {IN=>"\n"x12}, {OUT=>"\n"x8}], + ['no-oct-4', '-c 08', {IN=>"\n"x12}, {OUT=>"\n"x8}], + + # --zero-terminated + ['zero-1', '-z -n 1', {IN=>"x\0y"}, {OUT=>"x\0"}], + ['zero-2', '-z -n 2', {IN=>"x\0y"}, {OUT=>"x\0y"}], +); + +@Tests = triple_test \@Tests; + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/help-version-getopt.sh b/tests/misc/help-version-getopt.sh new file mode 100755 index 0000000..2e01b41 --- /dev/null +++ b/tests/misc/help-version-getopt.sh @@ -0,0 +1,74 @@ +#!/bin/sh +# Ensure --version and --help options are processed before +# any other options by some programs. + +# Copyright (C) 2019-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ yes + +programs="cksum dd hostid hostname link logname nohup +sleep tsort unlink uptime users whoami yes" + +# All these variations should show the help/version screen +# regardless of their position on the command line arguments. +for prog in $programs; do + # skip if the program is not built (e.g., hostname) + case " $built_programs " in + *" $prog "*) ;; + *) continue;; + esac + + for opt in --help --version; do + rm -f exp out1 out2 out3 || framework_failure_ + + # Get the reference output + env $prog $opt >exp || fail=1 + + # Test: some other argument AFTER --help/--version. + env $prog $opt AFTER > out1 || fail=1 + compare exp out1 || fail=1 + + # nohup is an exception: stops processing after first non-option parameter. + # E.g., "nohup df --help" should run "df --help", not "df --help". + if [ "$prog" = nohup ]; then + rm -f exp || framework_failure_ + df $opt > exp || framework_failure_ + BEFORE=df + else + BEFORE=BEFORE + fi + + # Test: some other argument BEFORE --help/--version. + env $prog $BEFORE $opt > out2 || fail=1 + compare exp out2 || fail=1 + + # Test: some other arguments BEFORE and AFTER --help/--version. + env $prog $BEFORE $opt AFTER > out3 || fail=1 + compare exp out3 || fail=1 + done +done + +# After end-of-options marker (--), the options should not be parsed. +# Test with 'yes', and assume the common code will work the +# same for the other programs. +cat >exp <<\EOF || framework_failure_ +--help +EOF +env yes -- --help | head -n1 > out +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/help-version.sh b/tests/misc/help-version.sh new file mode 100755 index 0000000..ffabd6d --- /dev/null +++ b/tests/misc/help-version.sh @@ -0,0 +1,272 @@ +#!/bin/sh +# Make sure all of these programs work properly +# when invoked with --help or --version. + +# Copyright (C) 2000-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src + +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +expected_failure_status_chroot=125 +expected_failure_status_env=125 +expected_failure_status_nice=125 +expected_failure_status_nohup=125 +expected_failure_status_stdbuf=125 +expected_failure_status_timeout=125 +expected_failure_status_printenv=2 +expected_failure_status_tty=3 +expected_failure_status_sort=2 +expected_failure_status_expr=3 +expected_failure_status_lbracket=2 +expected_failure_status_dir=2 +expected_failure_status_ls=2 +expected_failure_status_vdir=2 + +expected_failure_status_cmp=2 +expected_failure_status_zcmp=2 +expected_failure_status_sdiff=2 +expected_failure_status_diff3=2 +expected_failure_status_diff=2 +expected_failure_status_zdiff=2 +expected_failure_status_zgrep=2 +expected_failure_status_zegrep=2 +expected_failure_status_zfgrep=2 + +expected_failure_status_grep=2 +expected_failure_status_egrep=2 +expected_failure_status_fgrep=2 + +test "$built_programs" \ + || fail_ "built_programs not specified!?!" + +test "$VERSION" \ + || fail_ "set envvar VERSION; it is required for a PATH sanity-check" + +# Extract version from --version output of the first program +for i in $built_programs; do + v=$(env $i --version | sed -n '1s/.* //p;q') + break +done + +# Ensure that it matches $VERSION. +test "x$v" = "x$VERSION" \ + || fail_ "--version-\$VERSION mismatch" + +for i in $built_programs; do + + # Skip 'test'; it doesn't accept --help or --version. + test $i = test && continue + + # false fails even when invoked with --help or --version. + # true and false are tested with these options separately. + test $i = false || test $i = true && continue + + # The just-built install executable is always named 'ginstall'. + test $i = install && i=ginstall + + # Make sure they exit successfully, under normal conditions. + env $i --help >/dev/null || fail=1 + env $i --version >/dev/null || fail=1 + + # Make sure they fail upon 'file system full' error. + if test -w /dev/full && test -c /dev/full && + ! printf x >/dev/full 2>/dev/null; then + test $i = [ && prog=lbracket || prog=$(echo $i|sed "s/$EXEEXT$//") + eval "expected=\$expected_failure_status_$prog" + test x$expected = x && expected=1 + + returns_ $expected env $i --help >/dev/full 2>/dev/null && + returns_ $expected env $i --version >/dev/full 2>/dev/null || + { + fail=1 + env $i --help >/dev/full 2>/dev/null + status=$? + echo "*** $i: bad exit status '$status' (expected $expected)," 1>&2 + echo " with --help or --version output redirected to /dev/full" 1>&2 + } + fi +done + +bigZ_in=bigZ-in.Z +zin=zin.gz +zin2=zin2.gz + +tmp=tmp-$$ +tmp_in=in-$$ +tmp_in2=in2-$$ +tmp_dir=dir-$$ +tmp_out=out-$$ +mkdir $tmp || fail=1 +cd $tmp || fail=1 + +comm_setup () { args="$tmp_in $tmp_in"; } +csplit_setup () { args="$tmp_in //"; } +cut_setup () { args='-f 1'; } +join_setup () { args="$tmp_in $tmp_in"; } +tr_setup () { args='a a'; } + +chmod_setup () { args="a+x $tmp_in"; } +# Punt on these. +chgrp_setup () { args=--version; } +chown_setup () { args=--version; } +mkfifo_setup () { args=--version; } +mknod_setup () { args=--version; } +# Punt on uptime, since it fails (e.g., failing to get boot time) +# on some systems, and we shouldn't let that stop 'make check'. +uptime_setup () { args=--version; } + +# Create a file in the current directory, not in $TMPDIR. +mktemp_setup () { args=mktemp.XXXX; } + +cmp_setup () { args="$tmp_in $tmp_in2"; } + +# Tell dd not to print the line with transfer rate and total. +# The transfer rate would vary between runs. +dd_setup () { args=status=noxfer; } + +zdiff_setup () { args="$zin $zin2"; } +zcmp_setup () { zdiff_setup; } +zcat_setup () { TERM=dumb; export TERM; args=$zin; } +gunzip_setup () { zcat_setup; } +zmore_setup () { zcat_setup; } +zless_setup () { zcat_setup; } +znew_setup () { args=$bigZ_in; } +zforce_setup () { zcat_setup; } +zgrep_setup () { args="z $zin"; } +zegrep_setup () { zgrep_setup; } +zfgrep_setup () { zgrep_setup; } +gzexe_setup () { args=$tmp_in; } + +# We know that $tmp_in contains a "0" +grep_setup () { args="0 $tmp_in"; } +egrep_setup () { args="0 $tmp_in"; } +fgrep_setup () { args="0 $tmp_in"; } + +diff_setup () { args="$tmp_in $tmp_in2"; } +sdiff_setup () { args="$tmp_in $tmp_in2"; } +diff3_setup () { args="$tmp_in $tmp_in2 $tmp_in2"; } +cp_setup () { args="$tmp_in $tmp_in2"; } +ln_setup () { args="$tmp_in ln-target"; } +ginstall_setup () { args="$tmp_in $tmp_in2"; } +mv_setup () { args="$tmp_in $tmp_in2"; } +mkdir_setup () { args=$tmp_dir/subdir; } +realpath_setup () { args=$tmp_in; } +rmdir_setup () { args=$tmp_dir; } +rm_setup () { args=$tmp_in; } +shred_setup () { args=$tmp_in; } +touch_setup () { args=$tmp_in2; } +truncate_setup () { args="--reference=$tmp_in $tmp_in2"; } + +mkid_setup () { printf 'f(){}\ntypedef int t;\n' > f.c; args=. ; } +lid_setup () { args=; } +fid_setup () { args=f.c; } +fnid_setup () { args=; } +xtokid_setup () { args=; } +aid_setup () { args=f; } +eid_setup () { args=--version; } +gid_setup () { args=f; } +defid_setup () { args=t; } + +basename_setup () { args=$tmp_in; } +dirname_setup () { args=$tmp_in; } +expr_setup () { args=foo; } +basenc_setup () { args=--version; } + +# Punt, in case GNU 'id' hasn't been installed yet. +groups_setup () { args=--version; } + +pathchk_setup () { args=$tmp_in; } +yes_setup () { args=--version; } +logname_setup () { args=--version; } +nohup_setup () { args=--version; } +printf_setup () { args=foo; } +seq_setup () { args=10; } +sleep_setup () { args=0; } +stdbuf_setup () { args="-oL true"; } +timeout_setup () { args=--version; } + +# I'd rather not run sync, since it spins up disks that I've +# deliberately caused to spin down (but not unmounted). +sync_setup () { args=--version; } + +test_setup () { args=foo; } + +# This is necessary in the unusual event that there is +# no valid entry in /etc/mtab. +df_setup () { args=/; } + +# This is necessary in the unusual event that getpwuid (getuid ()) fails. +id_setup () { args=-u; } + +# Use env to avoid invoking built-in sleep of Solaris 11's /bin/sh. +kill_setup () { + external=env + $external sleep 10m & pid=$! + args=$pid +} + +link_setup () { args="$tmp_in link-target"; } +unlink_setup () { args=$tmp_in; } + +readlink_setup () { + ln -s . slink + args=slink; +} + +stat_setup () { args=$tmp_in; } +unlink_setup () { args=$tmp_in; } +lbracket_setup () { args=": ]"; } + +parted_setup () { args="-s $tmp_in mklabel gpt" + dd if=/dev/null of=$tmp_in seek=2000; } + +# Ensure that each program "works" (exits successfully) when doing +# something more than --help or --version. +for i in $built_programs; do + # Skip these. + case $i in chroot|stty|tty|false|chcon|runcon|coreutils) continue;; esac + + rm -rf $tmp_in $tmp_in2 $tmp_dir $tmp_out $bigZ_in $zin $zin2 + echo z |gzip > $zin + cp $zin $zin2 + cp $zin $bigZ_in + + # This is sort of kludgey: use numbers so this is valid input for factor, + # and two tokens so it's valid input for tsort. + echo 2147483647 0 > $tmp_in + # Make $tmp_in2 identical. Then, using $tmp_in and $tmp_in2 as arguments + # to the likes of cmp and diff makes them exit successfully. + cp $tmp_in $tmp_in2 + mkdir $tmp_dir + # echo ================== $i + test $i = [ && prog=lbracket || prog=$(echo $i|sed "s/$EXEEXT$//") + if type ${prog}_setup > /dev/null 2>&1; then + ${prog}_setup + else + args= + fi + if env $i $args < $tmp_in > $tmp_out; then + : # ok + else + echo FAIL: $i + fail=1 + fi + rm -rf $tmp_in $tmp_in2 $tmp_out $tmp_dir +done + +Exit $fail diff --git a/tests/misc/invalid-opt.pl b/tests/misc/invalid-opt.pl new file mode 100755 index 0000000..76fa046 --- /dev/null +++ b/tests/misc/invalid-opt.pl @@ -0,0 +1,102 @@ +#!/usr/bin/perl +# exercise the 'invalid option' handling code in each program + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +require 5.003; +use strict; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my %exit_status = + ( + ls => 2, + dir => 2, + vdir => 2, + test => 2, + chroot => 125, + echo => 0, + env => 125, + expr => 0, + nice => 125, + nohup => 125, + sort => 2, + stdbuf => 125, + test => 0, + timeout => 125, + true => 0, + tty => 2, + printf => 0, + printenv => 2, + ); + +my %expected_out = + ( + echo => "-/\n", + expr => "-/\n", + printf => "-/", + ); + +my %expected_err = + ( + false => '', + stty => '', + ); + +my $fail = 0; +my @built_programs = split ' ', $ENV{built_programs}; +foreach my $prog (@built_programs) + { + $prog eq '[' + and next; + + my $try = "Try '$prog --help' for more information.\n"; + my $x = $exit_status{$prog}; + defined $x + or $x = 1; + + my $out = $expected_out{$prog}; + defined $out + or $out = ''; + + my $err = $expected_err{$prog}; + defined $err + or $err = $x == 0 ? '' : "$prog: invalid option -- /\n$try"; + + # Accommodate different syntax in glibc's getopt + # diagnostics by filtering out single quotes. + # Also accommodate BSD getopt. + my $err_subst = "s,'/',/,; s,unknown,invalid,"; + + # Depending on how this script is run, stty emits different + # diagnostics. Don't bother checking them. + $prog eq 'stty' + and $err_subst = 's/(.|\n)*//ms'; + + my @Tests = (["$prog-invalid-opt", '-/', {OUT=>$out}, + {ERR_SUBST => $err_subst}, + {EXIT=>$x}, {ERR=>$err}]); + + my $save_temps = $ENV{DEBUG}; + my $verbose = $ENV{VERBOSE}; + + my $f = run_tests ($prog, \$prog, \@Tests, $save_temps, $verbose); + $f + and $fail = 1; + } + +exit $fail; diff --git a/tests/misc/join.pl b/tests/misc/join.pl new file mode 100755 index 0000000..06ad777 --- /dev/null +++ b/tests/misc/join.pl @@ -0,0 +1,342 @@ +#!/usr/bin/perl +# Test join. + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $limits = getlimits (); + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $prog = 'join'; + +my $delim = chr 0247; +sub t_subst ($) +{ + (my $s = $_[0]) =~ s/:/$delim/g; + return $s; +} + +my @tv = ( +# test name +# flags file-1 file-2 expected output expected return code +# +['1a', '-a1', ["a 1\n", "b\n"], "a 1\n", 0], +['1b', '-a2', ["a 1\n", "b\n"], "b\n", 0], # Got "\n" +['1c', '-a1 -a2', ["a 1\n", "b\n"], "a 1\nb\n", 0], # Got "a 1\n\n" +['1d', '-a1', ["a 1\nb\n", "b\n"], "a 1\nb\n", 0], +['1e', '-a2', ["a 1\nb\n", "b\n"], "b\n", 0], +['1f', '-a2', ["b\n", "a\nb\n"], "a\nb\n", 0], + +['2a', '-a1 -e .', ["a\nb\nc\n", "a x y\nb\nc\n"], "a x y\nb\nc\n", 0], +['2b', '-a1 -e . -o 2.1,2.2,2.3', ["a\nb\nc\n", "a x y\nb\nc\n"], + "a x y\nb . .\nc . .\n", 0], +['2c', '-a1 -e . -o 2.1,2.2,2.3', ["a\nb\nc\nd\n", "a x y\nb\nc\n"], + "a x y\nb . .\nc . .\n. . .\n", 0], + +['3a', '-t:', ["a:1\nb:1\n", "a:2:\nb:2:\n"], "a:1:2:\nb:1:2:\n", 0], + +# operate on whole line (as sort does by default) +['3b', '-t ""', ["a 1\nb 1\n", "a 1\nb 2\n"], "a 1\n", 0], +# use NUL as the field delimiter +['3c', '-t "\\0"', ["a\0a\n", "a\0b\n"], "a\0a\0b\n", 0], + +# Just like -a1 and -a2 when there are no pairable lines +['4a', '-v 1', ["a 1\n", "b\n"], "a 1\n", 0], +['4b', '-v 2', ["a 1\n", "b\n"], "b\n", 0], + +['4c', '-v 1', ["a 1\nb\n", "b\n"], "a 1\n", 0], +['4d', '-v 2', ["a 1\nb\n", "b\n"], "", 0], +['4e', '-v 2', ["b\n", "a 1\nb\n"], "a 1\n", 0], +['5a', '-a1 -e - -o 1.1,2.2', + ["a 1\nb 2\n", "a 11\nb\n"], "a 11\nb -\n", 0], +['5b', '-a1 -e - -o 1.1,2.2', + ["apr 15\naug 20\ndec 18\nfeb 05\n", "apr 06\naug 14\ndate\nfeb 15"], + "apr 06\naug 14\ndec -\nfeb 15\n", 0], +['5c', '-a1 -e - -o 1.1,2.2', + ["aug 20\ndec 18\n", "aug 14\ndate\nfeb 15"], + "aug 14\ndec -\n", 0], +['5d', '-a1 -e - -o 1.1,2.2', + ["dec 18\n", ""], "dec -\n", 0], +['5e', '-a2 -e - -o 1.1,2.2', + ["apr 15\naug 20\ndec 18\nfeb 05\n", "apr 06\naug 14\ndate\nfeb 15\n"], + "apr 06\naug 14\n- -\nfeb 15\n", 0], +['5f', '-a2 -e - -o 2.2,1.1', + ["apr 15\naug 20\ndec 18\nfeb 05\n", "apr 06\naug 14\ndate\nfeb 15\n"], + "06 apr\n14 aug\n- -\n15 feb\n", 0], +['5g', '-a1 -e - -o 2.2,1.1', + ["apr 15\naug 20\ndec 18\nfeb 05\n", "apr 06\naug 14\ndate\nfeb 15\n"], + "06 apr\n14 aug\n- dec\n15 feb\n", 0], + +['5h', '-a1 -e - -o 2.2,1.1', + ["apr 15\naug 20\ndec 18\nfeb 05\n", "apr 06\naug 14\ndate\n"], + "06 apr\n14 aug\n- dec\n- feb\n", 0], +['5i', '-a1 -e - -o 1.1,2.2', + ["apr 15\naug 20\ndec 18\nfeb 05\n", "apr 06\naug 14\ndate\n"], + "apr 06\naug 14\ndec -\nfeb -\n", 0], + +['5j', '-a2 -e - -o 2.2,1.1', + ["apr 15\naug 20\ndec 18\nfeb 05\n", "apr 06\naug 14\ndate\n"], + "06 apr\n14 aug\n- -\n", 0], +['5k', '-a2 -e - -o 2.2,1.1', + ["apr 15\naug 20\ndec 18\nfeb 05\n", "apr 06\naug 14\ndate\n"], + "06 apr\n14 aug\n- -\n", 0], + +['5l', '-a1 -e - -o 2.2,1.1', + ["apr 15\naug 20\ndec 18\n", "apr 06\naug 14\ndate\nfeb 15\n"], + "06 apr\n14 aug\n- dec\n", 0], +['5m', '-a2 -e - -o 2.2,1.1', + ["apr 15\naug 20\ndec 18\n", "apr 06\naug 14\ndate\nfeb 15\n"], + "06 apr\n14 aug\n- -\n15 -\n", 0], + +['6a', '-e -', + ["a 1\nb 2\nd 4\n", "a 21\nb 22\nc 23\nf 26\n"], + "a 1 21\nb 2 22\n", 0], +['6b', '-a1 -e -', + ["a 1\nb 2\nd 4\n", "a 21\nb 22\nc 23\nf 26\n"], + "a 1 21\nb 2 22\nd 4\n", 0], +['6c', '-a1 -e -', + ["a 21\nb 22\nc 23\nf 26\n", "a 1\nb 2\nd 4\n"], + "a 21 1\nb 22 2\nc 23\nf 26\n", 0], + +['7a', '-a1 -e . -o 2.7', + ["a\nb\nc\n", "a x y\nb\nc\n"], ".\n.\n.\n", 0], + +['8a', '-a1 -e . -o 0,1.2', + ["a\nb\nc\nd G\n", "a x y\nb\nc\ne\n"], + "a .\nb .\nc .\nd G\n", 0], +['8b', '-a1 -a2 -e . -o 0,1.2', + ["a\nb\nc\nd G\n", "a x y\nb\nc\ne\n"], + "a .\nb .\nc .\nd G\ne .\n", 0], + +# From David Dyck +['9a', '', [" a 1\n b 2\n", " a Y\n b Z\n"], "a 1 Y\nb 2 Z\n", 0], + +# -o 'auto' +['10a', '-a1 -a2 -e . -o auto', + ["a 1 2\nb 1\nd 1 2\n", "a 3 4\nb 3 4\nc 3 4\n"], + "a 1 2 3 4\nb 1 . 3 4\nc . . 3 4\nd 1 2 . .\n", 0], +['10b', '-a1 -a2 -j3 -e . -o auto', + ["a 1 2\nb 1\nd 1 2\n", "a 3 4\nb 3 4\nc 3 4\n"], + "2 a 1 . .\n. b 1 . .\n2 d 1 . .\n4 . . a 3\n4 . . b 3\n4 . . c 3\n"], +['10c', '-a1 -1 1 -2 4 -e. -o auto', + ["a 1 2\nb 1\nd 1 2\n", "a 3 4\nb 3 4\nc 3 4\n"], + "a 1 2 . . .\nb 1 . . . .\nd 1 2 . . .\n"], +['10d', '-a2 -1 1 -2 4 -e. -o auto', + ["a 1 2\nb 1\nd 1 2\n", "a 3 4\nb 3 4\nc 3 4\n"], + ". . . a 3 4\n. . . b 3 4\n. . . c 3 4\n"], +['10e', '-o auto', + ["a 1 2\nb 1 2 discard\n", "a 3 4\nb 3 4 discard\n"], + "a 1 2 3 4\nb 1 2 3 4\n"], +['10f', '-t, -o auto', + ["a,1,,2\nb,1,2\n", "a,3,4\nb,3,4\n"], + "a,1,,2,3,4\nb,1,2,,3,4\n"], + +# For -v2, print the match field correctly with the default output format, +# when that match field is different between file 1 and file 2. Fixed in 8.10 +['v2-order', '-v2 -2 2', ["", "2 1\n"], "1 2\n", 0], + +# From Tim Smithers: fixed in 1.22l +['trailing-sp', '-t: -1 1 -2 1', ["a:x \n", "a:y \n"], "a:x :y \n", 0], + +# From Paul Eggert: fixed in 1.22n +['sp-vs-blank', '', ["\f 1\n", "\f 2\n"], "\f 1 2\n", 0], + +# From Paul Eggert: fixed in 1.22n (this would fail on Solaris7, +# with LC_ALL set to en_US). +# Unfortunately, that Solaris7's en_US locale folds case (making +# the first input file sorted) is not portable, so this test would +# fail on e.g. Linux systems, because the input to join isn't sorted. +# ['lc-collate', '', ["a 1a\nB 1B\n", "B 2B\n"], "B 1B 2B\n", 0], + +# Based on a report from Antonio Rendas. Fixed in 2.0.9. +['8-bit-t', t_subst "-t:", + [t_subst "a:1\nb:1\n", t_subst "a:2:\nb:2:\n"], + t_subst "a:1:2:\nb:1:2:\n", 0], + +# fields > SIZE_MAX are silently interpreted as SIZE_MAX +['bigfield1', "-1 $limits->{UINTMAX_OFLOW} -2 2", + ["a\n", "b\n"], " a b\n", 0], +['bigfield2', "-1 $limits->{SIZE_OFLOW} -2 2", + ["a\n", "b\n"], " a b\n", 0], + +# FIXME: change this to ensure the diagnostic makes sense +['invalid-j', '-j x', ["", ""], "", 1, + "$prog: invalid field number: 'x'\n"], + +# With ordering check, inputs in order +['chkodr-1', '--check-order', + [" a 1\n b 2\n", " a Y\n b Z\n"], "a 1 Y\nb 2 Z\n", 0], + +# Without check, inputs in order +['chkodr-2', '--nocheck-order', + [" a 1\n b 2\n", " a Y\n b Z\n"], "a 1 Y\nb 2 Z\n", 0], + +# Without check, both inputs out of order (in fact, in reverse order) +# but all pairable. Support for this is a GNU extension. +['chkodr-3', '--nocheck-order', + [" b 1\n a 2\n", " b Y\n a Z\n"], "b 1 Y\na 2 Z\n", 0], + +# The extension should work without --nocheck-order, since that is the +# default. +['chkodr-4', '', + [" b 1\n a 2\n", " b Y\n a Z\n"], "b 1 Y\na 2 Z\n", 0], + +# With check, both inputs out of order (in fact, in reverse order) +['chkodr-5', '--check-order', + [" b 1\n a 2\n", " b Y\n a Z\n"], "", 1, + "$prog: chkodr-5.1:2: is not sorted: a 2\n"], + +# Similar, but with only file 2 not sorted. +['chkodr-5b', '--check-order', + [" a 2\n b 1\n", " b Y\n a Z\n"], "", 1, + "$prog: chkodr-5b.2:2: is not sorted: a Z\n"], + +# Similar, but with the offending line having length 0 (excluding newline). +['chkodr-5c', '--check-order', + [" a 2\n b 1\n", " b Y\n\n"], "", 1, + "$prog: chkodr-5c.2:2: is not sorted: \n"], + +# Similar, but elicit a warning for each input file (without --check-order). +['chkodr-5d', '', + ["a\nx\n\n", "b\ny\n\n"], "", 1, + "$prog: chkodr-5d.1:3: is not sorted: \n" . + "$prog: chkodr-5d.2:3: is not sorted: \n" . + "$prog: input is not in sorted order\n" + ], + +# Similar, but make it so each offending line has no newline. +['chkodr-5e', '', + ["a\nx\no", "b\ny\np"], "", 1, + "$prog: chkodr-5e.1:3: is not sorted: o\n" . + "$prog: chkodr-5e.2:3: is not sorted: p\n" . + "$prog: input is not in sorted order\n" + ], + +# Without order check, both inputs out of order and some lines +# unpairable. This is NOT supported by the GNU extension. All that +# we really care about for this test is that the return status is +# zero, since that is the only way to actually verify that the +# --nocheck-order option had any effect. We don't actually want to +# guarantee that join produces this output on stdout. +['chkodr-6', '--nocheck-order', + [" b 1\n a 2\n", " b Y\n c Z\n"], "b 1 Y\n", 0], + +# Before 6.10.143, this would mistakenly fail with the diagnostic: +# join: File 1 is not in sorted order +['chkodr-7', '-12', ["2 a\n1 b\n", "2 c\n1 d"], "", 0], + +# After 8.9, join doesn't report disorder by default +# when comparing against an empty input file. +['chkodr-8', '', ["2 a\n1 b\n", ""], "", 0], + +# Test '--header' feature +['header-1', '--header', + [ "ID Name\n1 A\n2 B\n", "ID Color\n1 red\n"], "ID Name Color\n1 A red\n", 0], + +# '--header' with '--check-order' : The header line is out-of-order but the +# actual data is in order. This join should succeed. +['header-2', '--header --check-order', + ["ID Name\n1 A\n2 B\n", "ID Color\n2 green\n"], + "ID Name Color\n2 B green\n", 0], + +# '--header' with '--check-order' : The header line is out-of-order AND the +# actual data out-of-order. This join should fail. +['header-3', '--header --check-order', + ["ID Name\n2 B\n1 A\n", "ID Color\n2 blue\n"], "ID Name Color\n", 1, + "$prog: header-3.1:3: is not sorted: 1 A\n"], + +# '--header' with specific output format '-o'. +# output header line should respect the requested format +['header-4', '--header -o "0,1.3,2.2"', + ["ID Group Name\n1 Foo A\n2 Bar B\n", "ID Color\n2 blue\n"], + "ID Name Color\n2 B blue\n", 0], + +# '--header' always outputs headers from the first file +# even if the headers from the second file don't match +['header-5', '--header', + [ "ID1 Name\n1 A\n2 B\n", "ID2 Color\n1 red\n"], + "ID1 Name Color\n1 A red\n", 0], + +# '--header' doesn't check order of a header +# even if there is no header in the second file +['header-6', '--header -a1', + [ "ID1 Name\n1 A\n", ""], + "ID1 Name\n1 A\n", 0], + +# Zero-terminated lines +['z1', '-z', + ["a\0c\0e\0", "a\0b\0c\0"], "a\0c\0", 0], + +# not zero-terminated, but related to the code change: +# the old readlinebuffer() auto-added '\n' to the last line. +# the new readlinebuffer_delim() does not. +# Ensure it doesn't matter. +['z2', '', + ["a\nc\ne\n", "a\nb\nc"], "a\nc\n", 0], +['z3', '', + ["a\nc\ne", "a\nb\nc"], "a\nc\n", 0], +# missing last NUL at the end of the last line (=end of file) +['z4', '-z', + ["a\0c\0e", "a\0b\0c"], "a\0c\0", 0], +# With -z, embedded newlines are treated as field separators. +# Note '\n' are converted to ' ' in this case. +['z5', '-z -a1 -a2', + ["a\n\n1\0c 3\0", "a 2\0b\n8\0c 9\0"], "a 1 2\0b 8\0c 3 9\0"], +# One can avoid field processing like: +['z6', '-z -t ""', + ["a\n1\n\0", "a\n1\n\0"], "a\n1\n\0"], + +); + +# Convert the above old-style test vectors to the newer +# format used by Coreutils.pm. + +my @Tests; +foreach my $t (@tv) + { + my ($test_name, $flags, $in, $exp, $ret, $err_msg) = @$t; + my $new_ent = [$test_name, $flags]; + if (!ref $in) + { + push @$new_ent, {IN=>$in}; + } + elsif (ref $in eq 'HASH') + { + # ignore + } + else + { + foreach my $e (@$in) + { + push @$new_ent, {IN=>$e}; + } + } + push @$new_ent, {OUT=>$exp}; + $ret + and push @$new_ent, {EXIT=>$ret}, {ERR=>$err_msg}; + push @Tests, $new_ent; + } + +@Tests = triple_test \@Tests; + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/kill.sh b/tests/misc/kill.sh new file mode 100755 index 0000000..1efd14c --- /dev/null +++ b/tests/misc/kill.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# Validate kill operation + +# Copyright (C) 2015-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ kill + +# params required +returns_ 1 env kill || fail=1 +returns_ 1 env kill -TERM || fail=1 + +# Invalid combinations +returns_ 1 env kill -l -l || fail=1 +returns_ 1 env kill -l -t || fail=1 +returns_ 1 env kill -l -s 1 || fail=1 +returns_ 1 env kill -t -s 1 || fail=1 + +# signal sending +returns_ 1 env kill -0 no_pid || fail=1 +env kill -0 $$ || fail=1 +env kill -s0 $$ || fail=1 +env kill -n0 $$ || fail=1 # bash compat +env kill -CONT $$ || fail=1 +env kill -Cont $$ || fail=1 +returns_ 1 env kill -cont $$ || fail=1 +env kill -0 -1 || fail=1 # to group + +# table listing +env kill -l || fail=1 +env kill -t || fail=1 +env kill -L || fail=1 # bash compat +env kill -t TERM HUP || fail=1 + +# Verify (multi) name to signal number and vice versa +SIGTERM=$(env kill -l HUP TERM | tail -n1) || fail=1 +test $(env kill -l "$SIGTERM") = TERM || fail=1 + +# Verify we only consider the lower "signal" bits, +# to support ksh which just adds 256 to the signal value +STD_TERM_STATUS=$(expr "$SIGTERM" + 128) +KSH_TERM_STATUS=$(expr "$SIGTERM" + 256) +test $(env kill -l $STD_TERM_STATUS $KSH_TERM_STATUS | uniq) = TERM || fail=1 + +# Verify invalid signal spec is diagnosed +returns_ 1 env kill -l -1 || fail=1 +returns_ 1 env kill -l -1 0 || fail=1 +returns_ 1 env kill -l INVALID TERM || fail=1 + +Exit $fail diff --git a/tests/misc/ls-misc.pl b/tests/misc/ls-misc.pl new file mode 100755 index 0000000..a2ac60b --- /dev/null +++ b/tests/misc/ls-misc.pl @@ -0,0 +1,376 @@ +#!/usr/bin/perl + +# Copyright (C) 1998-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $ME = $0) =~ s|.*/||; +my $prog = 'ls'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $saved_ls_colors; + +sub push_ls_colors($) +{ + $saved_ls_colors = $ENV{LS_COLORS} || ''; + $ENV{LS_COLORS} = $_[0]; +} + +sub restore_ls_colors() +{ + $ENV{LS_COLORS} = $saved_ls_colors; +} + +# If the string $S is a well-behaved file name, simply return it. +# If it contains white space, quotes, etc., quote it, and return the new string. +sub shell_quote($) +{ + my ($s) = @_; + if ($s =~ m![^\w+/.,-]!) + { + # Convert each single quote to '\'' + $s =~ s/\'/\'\\\'\'/g; + # Then single quote the string. + $s = "'$s'"; + } + return $s; +} + +# Set up files used by the setuid-etc tests; skip this entire test if +# that cannot be done. +sub setuid_setup() +{ + my $test = 'env test'; + system (qq(touch setuid && chmod u+s setuid && $test -u setuid && + touch setgid && chmod g+s setgid && $test -g setgid && + mkdir sticky && chmod +t sticky && $test -k sticky && + mkdir owt && chmod +t,o+w owt && $test -k owt && + mkdir owr && chmod o+w owr)) == 0 + or CuSkip::skip "$ME: cannot create setuid/setgid/sticky files," + . "so can't run this test\n"; +} + +sub mk_file(@) +{ + foreach my $f (@_) + { + open (F, '>', $f) && close F + or die "creating $f: $!\n"; + } +} + +sub mkdir_d {mkdir 'd',0755 or die "d: $!\n"} +sub rmdir_d {rmdir 'd' or die "d: $!\n"} +my $mkdir = {PRE => sub {mkdir_d}}; +my $rmdir = {POST => sub {rmdir_d}}; +my $mkdir_reg = {PRE => sub {mkdir_d; mk_file 'd/f' }}; +my $rmdir_reg = {POST => sub {unlink 'd/f' or die "d/f: $!\n"; + rmdir 'd' or die "d: $!\n"}}; + +my $mkdir2 = {PRE => sub {mkdir 'd',0755 or die "d: $!\n"; + mkdir 'd/e',0755 or die "d/e: $!\n" }}; +my $rmdir2 = {POST => sub {rmdir 'd/e' or die "d/e: $!\n"; + rmdir 'd' or die "d: $!\n" }}; + +my $target = {PRE => sub { + mkdir 'd',0755 or die "d: $!\n"; + symlink '.', 'd/X' or die "d/X: $!\n"; + push_ls_colors('ln=target') + }}; +my $target2 = {POST => sub {unlink 'd/X' or die "d/X: $!\n"; + rmdir 'd' or die "d: $!\n"; + restore_ls_colors + }}; +my $slink_d = {PRE => sub {symlink '/', 'd' or die "d: $!\n"; + push_ls_colors('ln=01;36:di=01;34:or=40;31;01') + }}; +my $unlink_d = {POST => sub {unlink 'd' or die "d: $!\n"; restore_ls_colors}}; + +my $mkdir_d_slink = {PRE => sub {mkdir 'd',0755 or die "d: $!\n"; + symlink '/', 'd/s' or die "d/s: $!\n" }}; +my $rmdir_d_slink = {POST => sub {unlink 'd/s' or die "d/s: $!\n"; + rmdir 'd' or die "d: $!\n" }}; + +sub make_j_d () +{ + mkdir 'j', 0700 or die "creating j: $!\n"; + mk_file 'j/d'; + chmod 0555, 'j/d' or die "making j/d executable: $!\n"; +} + +my @v_files = ( + '.A', '.Z', '.a', '.z', '.zz~', '.zz', '.zz.~1~', + '.0', '.9', '.zz.0', + '0', '9', + 'A', 'Z', 'a', 'z', 'zz~', 'zz', 'zz.~1~', + 'zz.0'); +my $exe_in_subdir = {PRE => sub { make_j_d (); push_ls_colors('ex=01;32') }}; +my $remove_j = {POST => sub {unlink 'j/d' or die "j/d: $!\n"; + rmdir 'j' or die "j: $!\n"; + restore_ls_colors }}; + +my $e = "\e[0m"; +my $q_bell = {IN => {"q\a" => ''}}; +my @Tests = + ( + # test-name options input expected-output + # + # quoting tests............................................ + ['q-', $q_bell, {OUT => "q\a\n"}, {EXIT => 0}], + ['q-N', '-N', $q_bell, {OUT => "q\a\n"}, {ERR => ''}], + ['q-q', '-q', $q_bell, {OUT => "q?\n"}], + ['q-Q', '-Q', $q_bell, {OUT => "\"q\\a\"\n"}], + + ['q-qs-lit', '--quoting=literal', $q_bell, {OUT => "q\a\n"}], + ['q-qs-sh', '--quoting=shell', $q_bell, {OUT => "q\a\n"}], + ['q-qs-sh-a', '--quoting=shell-always',$q_bell, {OUT => "'q\a'\n"}], + ['q-qs-sh-e', '--quoting=shell-escape',$q_bell, {OUT => "'q'\$'\\a'\n"}], + ['q-qs-c', '--quoting=c', $q_bell, {OUT => "\"q\\a\"\n"}], + ['q-qs-esc', '--quoting=escape', $q_bell, {OUT => "q\\a\n"}], + ['q-qs-loc', '--quoting=locale', $q_bell, {OUT => "'q\\a'\n"}], + ['q-qs-cloc', '--quoting=clocale', $q_bell, {OUT => "\"q\\a\"\n"}], + + ['q-qs-lit-q', '--quoting=literal -q', $q_bell, {OUT => "q?\n"}], + ['q-qs-sh-q', '--quoting=shell -q', $q_bell, {OUT => "q?\n"}], + ['q-qs-sh-a-q', '--quoting=shell-al -q', $q_bell, {OUT => "'q?'\n"}], + ['q-qs-sh-e-q', '--quoting=shell-escape -q', + $q_bell, {OUT => "'q'\$'\\a'\n"}], + ['q-qs-c-q', '--quoting=c -q', $q_bell, {OUT => "\"q\\a\"\n"}], + ['q-qs-esc-q', '--quoting=escape -q', $q_bell, {OUT => "q\\a\n"}], + ['q-qs-loc-q', '--quoting=locale -q', $q_bell, {OUT => "'q\\a'\n"}], + ['q-qs-cloc-q', '--quoting=clocale -q', $q_bell, {OUT => "\"q\\a\"\n"}], + + ['q-qs-c-1', '--quoting=c', + {IN => {"t\004" => ''}}, {OUT => "\"t\\004\"\n"}], + + ['emptydir', 'd', {OUT => ''}, $mkdir, $rmdir], + ['emptydir-x2', 'd d', {OUT => "d:\n\nd:\n"}, $mkdir, $rmdir], + ['emptydir-R', '-R d', {OUT => "d:\n"}, $mkdir, $rmdir], + + # test 'ls -R .' ............................................ + ['R-dot', '--ignore="[a-ce-zA-Z]*" -R .', {OUT => ".:\nd\n\n\./d:\n"}, + $mkdir, $rmdir], + + ['slink-dir-F', '-F d', {OUT => "d@\n"}, $slink_d, $unlink_d], + ['slink-dir-dF', '-dF d', {OUT => "d@\n"}, $slink_d, $unlink_d], + ['slinkdir-dFH', '-dFH d', {OUT => "d/\n"}, $slink_d, $unlink_d], + ['slinkdir-dFL', '-dFL d', {OUT => "d/\n"}, $slink_d, $unlink_d], + + # Test for a bug that was fixed in coreutils-4.5.4. + ['sl-F-color', '-F --color=always d', + {OUT => "$e\e[01;36md$e\@\n"}, + $slink_d, $unlink_d], + ['sl-dF-color', '-dF --color=always d', + {OUT => "$e\e[01;36md$e\@\n"}, + $slink_d, $unlink_d], + + # A listing with no output should have no color sequences at all. + ['no-c-empty', '--color=always d', {OUT => ""}, $mkdir, $rmdir], + # A listing with only regular files should have no color sequences at all. + ['no-c-reg', '--color=always d', {OUT => "f\n"}, $mkdir_reg, $rmdir_reg], + + # Test for a bug fixed after coreutils-6.9. + ['sl-target', '--color=always d', + {OUT => "$e\e[01;34mX$e\n"}, $target, $target2], + + # Test for another bug fixed after coreutils-6.9. + # This one bites only for a system/file system with d_type support. + ['sl-dangle', '--color=always d', + {OUT => "$e\e[40;31;01mX$e\n"}, + {PRE => sub { + mkdir 'd',0755 or die "d: $!\n"; + symlink 'non-existent', 'd/X' or die "d/X: $!\n"; + push_ls_colors('or=40;31;01') + }}, + {POST => sub {unlink 'd/X' or die "d/X: $!\n"; + rmdir 'd' or die "d: $!\n"; + restore_ls_colors; }}, + ], + + # Test for a bug fixed after coreutils-8.2. + ['sl-dangle2', '-o --time-style=+:TIME: --color=always l', + {OUT_SUBST => 's/.*:TIME: //'}, + {OUT => "l -> nowhere\n"}, + {PRE => sub {symlink 'nowhere', 'l' or die "l: $!\n"; + push_ls_colors('ln=target') + }}, + {POST => sub {unlink 'l' or die "l: $!\n"; + restore_ls_colors; }}, + ], + ['sl-dangle3', '-o --time-style=+:TIME: --color=always l', + {OUT_SUBST => 's/.*:TIME: //'}, + {OUT => "$e\e[40ml$e -> \e[34mnowhere$e\n"}, + {PRE => sub {symlink 'nowhere', 'l' or die "l: $!\n"; + push_ls_colors('ln=target:or=40:mi=34:') + }}, + {POST => sub {unlink 'l' or die "l: $!\n"; + restore_ls_colors; }}, + ], + ['sl-dangle4', '-o --time-style=+:TIME: --color=always l', + {OUT_SUBST => 's/.*:TIME: //'}, + {OUT => "$e\e[36ml$e -> \e[35mnowhere$e\n"}, + {PRE => sub {symlink 'nowhere', 'l' or die "l: $!\n"; + push_ls_colors('ln=34:mi=35:or=36:') + }}, + {POST => sub {unlink 'l' or die "l: $!\n"; + restore_ls_colors; }}, + ], + ['sl-dangle5', '-o --time-style=+:TIME: --color=always l', + {OUT_SUBST => 's/.*:TIME: //'}, + {OUT => "$e\e[34ml$e -> \e[35mnowhere$e\n"}, + {PRE => sub {symlink 'nowhere', 'l' or die "l: $!\n"; + push_ls_colors('ln=34:mi=35:') + }}, + {POST => sub {unlink 'l' or die "l: $!\n"; + restore_ls_colors; }}, + ], + + # Test for a bug fixed after coreutils-8.13 + # where 'argetm' was errenously printed for dangling links + # when ln=target was used in LS_COLORS + ['sl-dangle6', '-L --color=always d', + {OUT => "s\n"}, + {PRE => sub {mkdir 'd',0755 or die "d: $!\n"; + symlink 'dangle', 'd/s' or die "d/s: $!\n"; + push_ls_colors('ln=target') + }}, + {POST => sub {unlink 'd/s' or die "d/s: $!\n"; + rmdir 'd' or die "d: $!\n"; + restore_ls_colors; }}, + {ERR => "ls: cannot access 'd/s': No such file or directory\n"}, + {EXIT => 1} + ], + # Related to the above fix, is this case where + # the code simulates "linkok". In this case "linkmode" + # should always be zero, and hence not trigger any + # issues with type being set to C_LINK + ['sl-dangle7', '--color=always d', + {OUT => "$e\e[ms$e\n"}, + {PRE => sub {mkdir 'd',0755 or die "d: $!\n"; + symlink 'dangle', 'd/s' or die "d/s: $!\n"; + push_ls_colors('ln=target:or=:ex=:') + }}, + {POST => sub {unlink 'd/s' or die "d/s: $!\n"; + rmdir 'd' or die "d: $!\n"; + restore_ls_colors; }}, + ], + # Another case with simulated "linkok", that does + # actually use the value of 'ln' from $LS_COLORS. + # This path is not taken though when 'ln=target'. + ['sl-dangle8', '--color=always s', + {OUT => "$e\e[1;36ms$e\n"}, + {PRE => sub {symlink 'dangle', 's' or die "s: $!\n"; + push_ls_colors('ln=1;36:or=:') + }}, + {POST => sub {unlink 's' or die "s: $!\n"; + restore_ls_colors; }}, + ], + # The patch associated with sl-dangle[678] introduced a regression + # that was fixed after coreutils-8.19. This edge case triggers when + # listing a dir containing dangling symlinks, but with orphans uncolored. + # I.e., the same as the previous test, but listing the directory + # rather than the symlink directly. + ['sl-dangle9', '--color=always d', + {OUT => "$e\e[1;36ms$e\n"}, + {PRE => sub {mkdir 'd',0755 or die "d: $!\n"; + symlink 'dangle', 'd/s' or die "d/s: $!\n"; + push_ls_colors('ln=1;36:or=:') + }}, + {POST => sub {unlink 'd/s' or die "d/s: $!\n"; + rmdir 'd' or die "d: $!\n"; + restore_ls_colors; }}, + ], + + # Test for a bug that was introduced in coreutils-4.5.4; fixed in 4.5.5. + # To demonstrate it, the file in question (with executable bit set) + # must not be a command line argument. + ['color-exe1', '--color=always j', + {OUT => "$e\e[01;32md$e\n"}, + $exe_in_subdir, $remove_j], + + # From Stéphane Chazelas. + ['no-a-isdir-b', 'no-dir d', + {OUT => "d:\n"}, + {ERR => "ls: cannot access 'no-dir': No such file or directory\n"}, + $mkdir, $rmdir, {EXIT => 2}], + + ['recursive-2', '-R d', {OUT => "d:\ne\n\nd/e:\n"}, $mkdir2, $rmdir2], + + ['setuid-etc', '-1 -d --color=always owr owt setgid setuid sticky', + {OUT => + "$e\e[34;42mowr$e\n" + . "\e[30;42mowt$e\n" + . "\e[30;43msetgid$e\n" + . "\e[37;41msetuid$e\n" + . "\e[37;44msticky$e\n" + }, + + {PRE => sub { + push_ls_colors('ow=34;42:tw=30;42:sg=30;43:su=37;41:st=37;44'); }}, + {POST => sub { + unlink qw(setuid setgid); + foreach my $dir (qw(owr owt sticky)) {rmdir $dir} + restore_ls_colors; }}, + ], + + # For 5.97 and earlier, --file-type acted like --indicator-style=slash. + ['file-type', '--file-type d', {OUT => "s@\n"}, + $mkdir_d_slink, $rmdir_d_slink], + + # 7.1 had a regression in how -v -a ordered some files + ['version-sort', '-v -A ' . join (' ', @v_files), + {OUT => join ("\n", @v_files) . "\n"}, + {PRE => sub { mk_file @v_files }}, + {POST => sub { unlink @v_files }}, + ], + + # Test for the ls -1U bug fixed in coreutils-7.5. + # It is triggered only with -1U and with two or more arguments, + # at least one of which is a nonempty directory. + ['multi-arg-U1', '-U1 d no-such', + {OUT => "d:\nf\n"}, + {ERR_SUBST=>"s/ch':.*/ch':/"}, + {ERR => "$prog: cannot access 'no-such':\n"}, + $mkdir_reg, + $rmdir_reg, + {EXIT => 2}, + ], + ); + +umask 022; + +# Start with an unset LS_COLORS environment variable. +delete $ENV{LS_COLORS}; + +my $save_temps = $ENV{SAVE_TEMPS}; +my $verbose = $ENV{VERBOSE}; + +setuid_setup; +my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose); +$fail + and exit 1; + +# Be careful to use the just-build dircolors. +my $env = qx/dircolors -b/; +$env =~ s/^LS_COLORS=\'//; +$env =~ s/\';.*//sm; +$ENV{LS_COLORS} = $env; + +setuid_setup; +$fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/ls-time.sh b/tests/misc/ls-time.sh new file mode 100755 index 0000000..af41648 --- /dev/null +++ b/tests/misc/ls-time.sh @@ -0,0 +1,145 @@ +#!/bin/sh +# Test some of ls's sorting options. + +# Copyright (C) 1998-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ ls + +# Avoid any possible glitches due to daylight-saving changes near the +# timestamps used during the test. +TZ=UTC0 +export TZ + +t1='1998-01-15 21:00' +t2='1998-01-15 22:00' +t3='1998-01-15 23:00' + +u1='1998-01-14 11:00' +u2='1998-01-14 12:00' +u3='1998-01-14 13:00' + +touch -m -d "$t3" a || framework_failure_ +touch -m -d "$t2" b || framework_failure_ +touch -m -d "$t1" c || framework_failure_ + +touch -a -d "$u3" c || framework_failure_ +touch -a -d "$u2" b || framework_failure_ +# Make sure A has ctime at least 1 second more recent than C's. +sleep 2 +touch -a -d "$u1" a || framework_failure_ +# Updating the atime is usually enough to update the ctime, but on +# Solaris 10's tmpfs, ctime is not updated, so force an update here: +{ ln a a-ctime && rm a-ctime; } || framework_failure_ + + +# A has ctime more recent than C. +set $(ls -c a c) +test "$*" = 'a c' || fail=1 + +# Sleep so long in an attempt to avoid spurious failures +# due to NFS caching and/or clock skew. +sleep 2 + +# Create a link, updating c's ctime. +ln c d || framework_failure_ + +# Before we go any further, verify that touch's -m option works. +set -- $(ls --full -l a) +case "$*" in + *" $t3:00.000000000 +0000 a") ;; + *) + # This might be what's making HPUX 11 systems fail this test. + cat >&2 << EOF +A basic test of touch -m has just failed, so the subsequent +tests in this file will not be run. + +In the output below, the date of last modification for 'a' should +have been $t3. +EOF + ls --full -l a + skip_ "touch -m -d '$t3' didn't work" + ;; +esac + +# Ensure that touch's -a option works. +set -- $(ls --full -lu a) +case "$*" in + *" $u1:00.000000000 +0000 a") ;; + *) + # This might be what's making HPUX 11 systems fail this test. + cat >&2 << EOF +A fundamental touch -a test has just failed, so the subsequent +tests in this file will not be run. + +In the output below, the date of last access for 'a' should +have been $u1. +EOF + ls --full -lu a + Exit 77 + ;; +esac + +set $(ls -ut a b c) +test "$*" = 'c b a' && : || fail=1 +test $fail = 1 && ls -l --full-time --time=access a b c + +set $(ls -t a b c) +test "$*" = 'a b c' && : || fail=1 +test $fail = 1 && ls -l --full-time a b c + +# Now, C should have ctime more recent than A. +set $(ls -ct a c) +if test "$*" = 'c a'; then + : ok +else + # In spite of documentation, (e.g., stat(2)), neither link nor chmod + # update a file's st_ctime on SunOS4.1.4. + cat >&2 << \EOF +failed ls ctime test -- this failure is expected at least for SunOS4.1.4 +and for tmpfs file systems on Solaris 5.5.1. +It is also expected to fail on a btrfs file system until +https://bugzilla.redhat.com/591068 is addressed. + +In the output below, 'c' should have had a ctime more recent than +that of 'a', but does not. +EOF + #' + ls -ctl --full-time a c + fail=1 +fi + +# This check is ineffective if: +# en_US locale is not on the system. +# The system en_US message catalog has a specific TIME_FMT translation, +# which was inadvertently the case between coreutils 8.1 and 8.5 inclusive. + +if gettext --version >/dev/null 2>&1; then + + default_tf1='%b %e %Y' + en_tf1=$(LC_ALL=en_US gettext coreutils "$default_tf1") + + if test "$default_tf1" = "$en_tf1"; then + LC_ALL=en_US ls -l c >en_output + ls -l --time-style=long-iso c >liso_output + if compare en_output liso_output; then + fail=1 + echo "Long ISO TIME_FMT being used for en_US locale." >&2 + fi + fi +fi + +Exit $fail diff --git a/tests/misc/md5sum-bsd.sh b/tests/misc/md5sum-bsd.sh new file mode 100755 index 0000000..57188e8 --- /dev/null +++ b/tests/misc/md5sum-bsd.sh @@ -0,0 +1,95 @@ +#!/bin/sh +# 'md5sum' tests for generation and checking of +# BSD traditional and alternate formats (md5 [-r]) + +# Copyright (C) 2011-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ md5sum + +## BSD alternate format tests ## + +# Ensure we can --check BSD alternate format. +# Note we start this list with a name +# that's unambiguous in BSD format. +# I.e., one not starting with ' ' or '*' +for i in 'a' ' b' '*c' 'dd' ' '; do + echo "$i" > "$i" + md5sum --text "$i" >> check.md5sum || fail=1 +done +sed 's/ / /' check.md5sum > check.md5 + +# Note only a single format is supported per run +md5sum --strict -c check.md5sum || fail=1 +md5sum --strict -c check.md5 || fail=1 + +# Ensure we don't trigger BSD reversed format with GPG headers etc. +{ echo '____not_all_hex_so_no_match_____ blah'; + cat check.md5sum; } > check2.md5sum || framework_failure_ +md5sum -c check2.md5sum 2>check2.err || fail=1 +echo 'md5sum: WARNING: 1 line is improperly formatted' >check2.exp +compare check2.exp check2.err || fail=1 + +# If we skip the first entry in the BSD format checksums +# then it'll be detected as standard format and error. +# This unlikely caveat was thought better than mandating +# an option to avoid the ambiguity. +tail -n+2 check.md5 | returns_ 1 md5sum --strict -c || fail=1 + + +## BSD traditional format tests (--tag option) ## + +# Ensure --tag and --check are mutually exclusive +returns_ 1 md5sum --tag --check /dev/null || fail=1 + +# Ensure --tag and --text are mutually exclusive +# We don't support --text with BSD tradition format, +# as that would complicate the output format, +# while providing little benefit over --text processing +# available with the default md5sum output format. +returns_ 1 md5sum --tag --text /dev/null || fail=1 + +# Ensure we can --check BSD traditional format we produce +rm check.md5 +for i in 'a' ' b' '*c' 'dd' ' '; do + echo "$i" > "$i" + md5sum --tag "$i" >> check.md5 || fail=1 +done +md5sum --strict -c check.md5 || fail=1 + +# Ensure we can --check BSD traditional format we produce +# with the GNU extension of escaped newlines +nl=' +' +tab=' ' +rm check.md5 +for i in 'a\b' 'a\' "a${nl}b" "a${tab}b"; do + : > "$i" + md5sum --tag "$i" >> check.md5 || fail=1 +done +md5sum --strict -c check.md5 || fail=1 + +# Ensure BSD traditional format with GNU extension escapes +# is in the expected format +ex_file='test +\\file' +ex_output='\MD5 (test\n\\\\file) = d41d8cd98f00b204e9800998ecf8427e' +touch "$ex_file" +printf "%s\n" "$ex_output" > exp +md5sum --tag "$ex_file" > out || fail=1 +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/md5sum-newline.pl b/tests/misc/md5sum-newline.pl new file mode 100755 index 0000000..a89b3ca --- /dev/null +++ b/tests/misc/md5sum-newline.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl +# Newline tests for "md5sum". + +# Copyright (C) 1999-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $ME = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# See if we can create a file name that contains a newline. +# Use system, since Perl doesn't let you do this with "open". +system ('touch', "a\nb") == 0 + or CuSkip::skip "$ME: failed to create newline-containing file name\n"; + +my $degenerate = "d41d8cd98f00b204e9800998ecf8427e"; +my $t = '--text'; +my $z = '--zero'; + +my @Tests = + ( + ['newline', $t, {IN=> {"a\nb"=> ''}}, {OUT=>"\\$degenerate a\\nb\n"}], + ['zero', "$t $z", {IN=> {"a\nb"=> ''}}, {OUT=>"$degenerate a\nb\0"}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'md5sum'; +my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/md5sum-parallel.sh b/tests/misc/md5sum-parallel.sh new file mode 100755 index 0000000..f35a67a --- /dev/null +++ b/tests/misc/md5sum-parallel.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# Ensure that md5sum prints each checksum atomically +# so that concurrent md5sums don't intersperse their output + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ md5sum + +xargs -P2 </dev/null >/dev/null 2>&1 \ + || skip_ 'xargs -P is required' + +(mkdir tmp && cd tmp && seq 500 | xargs touch) + +# This will output at least 16KiB per process +# and start 3 processes, with 2 running concurrently, +# which triggers often on Fedora 11 at least. +(find tmp tmp tmp -type f | xargs -n500 -P2 md5sum 2>err) | +sed -n '/[0-9a-f]\{32\} /!p' | +grep . > /dev/null && fail=1 +compare /dev/null err || fail=1 + +Exit $fail diff --git a/tests/misc/md5sum.pl b/tests/misc/md5sum.pl new file mode 100755 index 0000000..f477319 --- /dev/null +++ b/tests/misc/md5sum.pl @@ -0,0 +1,184 @@ +#!/usr/bin/perl +# Basic tests for "md5sum". + +# Copyright (C) 1998-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $prog = 'md5sum'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $degenerate = "d41d8cd98f00b204e9800998ecf8427e"; + +my $try_help = "Try 'md5sum --help' for more information.\n"; + +my @Tests = + ( + ['1', {IN=> {f=> ''}}, {OUT=>"$degenerate f\n"}], + ['2', {IN=> {f=> 'a'}}, {OUT=>"0cc175b9c0f1b6a831c399e269772661 f\n"}], + ['3', {IN=> {f=> 'abc'}}, {OUT=>"900150983cd24fb0d6963f7d28e17f72 f\n"}], + ['4', {IN=> {f=> 'message digest'}}, + {OUT=>"f96b697d7cb7938d525a2f31aaf161d0 f\n"}], + ['5', {IN=> {f=> 'abcdefghijklmnopqrstuvwxyz'}}, + {OUT=>"c3fcd3d76192e4007dfb496cca67e13b f\n"}], + ['6', {IN=> {f=> join ('', 'A'..'Z', 'a'..'z', '0'..'9')}}, + {OUT=>"d174ab98d277d9f5a5611c2c9f419d9f f\n"}], + ['7', {IN=> {f=> '1234567890' x 8}}, + {OUT=>"57edf4a22be3c955ac49da2e2107b67a f\n"}], + ['backslash-1', {IN=> {".\nfoo"=> ''}}, + {OUT=>"\\$degenerate .\\nfoo\n"}], + ['backslash-2', {IN=> {".\\foo"=> ''}}, + {OUT=>"\\$degenerate .\\\\foo\n"}], + ['backslash-3', {IN=> {".\rfoo"=> ''}}, + {OUT=>"\\$degenerate .\\rfoo\n"}], + ['check-1', '--check', {AUX=> {f=> ''}}, + {IN=> {'f.md5' => "$degenerate f\n"}}, + {OUT=>"f: OK\n"}], + ['check-windows', '--check', {AUX=> {f=> ''}}, + {IN=> {'f.md5' => "$degenerate f\r\n"}}, + {OUT=>"f: OK\n"}], + + # Same as above, but with an added empty line, to test --strict. + ['ck-strict-1', '--check --strict', {AUX=> {f=> ''}}, + {IN=> {'f.md5' => "$degenerate f\n\n"}}, + {OUT=>"f: OK\n"}], + + # As above, but with the invalid line first, to ensure that following + # lines are processed in spite of the preceding invalid input line. + ['ck-strict-2', '--check --strict', {AUX=> {f=> ''}}, + {IN=> {'in.md5' => "ERR\n$degenerate f\n"}}, + {OUT=>"f: OK\n"}, + {ERR=>"md5sum: " + . "WARNING: 1 line is improperly formatted\n"}, + {EXIT=> 1}], + ['check-2', '--check', '--status', {IN=>{'f.md5' => "$degenerate f\n"}}, + {AUX=> {f=> 'foo'}}, {EXIT=> 1}], + ['check-quiet1', '--check', '--quiet', {AUX=> {f=> ''}}, + {IN=> {'f.md5' => "$degenerate f\n"}}, + {OUT=>""}], + ['check-quiet2', '--check', '--quiet', + {IN=>{'f.md5' => "$degenerate f\n"}}, + {AUX=> {f=> 'foo'}}, {OUT=>"f: FAILED\n"}, + {ERR=>"md5sum: WARNING: 1 computed" + . " checksum did NOT match\n"}, + {EXIT=> 1}], + # Exercise new-after-8.6, easier-to-translate diagnostics. + ['check-multifail', '--check', + {IN=>{'f.md5' => + "$degenerate f\n" + . "$degenerate f\n" + . "invalid\n" }}, + {AUX=> {f=> 'foo'}}, + {OUT=>"f: FAILED\nf: FAILED\n"}, + {ERR=>"md5sum: WARNING: 1 line is improperly formatted\n" + . "md5sum: WARNING: 2 computed checksums did NOT match\n"}, + {EXIT=> 1}], + # Similar to the above, but use --warn to evoke one more diagnostic. + ['check-multifail-warn', '--check', '--warn', + {IN=>{'f.md5' => + "$degenerate f\n" + . "$degenerate f\n" + . "invalid\n" }}, + {AUX=> {f=> 'foo'}}, + {OUT=>"f: FAILED\nf: FAILED\n"}, + {ERR=>"md5sum: f.md5: 3: " + . "improperly formatted MD5 checksum line\n" + . "md5sum: WARNING: 1 line is improperly formatted\n" + . "md5sum: WARNING: 2 computed checksums did NOT match\n"}, + {EXIT=> 1}], + # The sha1sum and md5sum drivers share a lot of code. + # Ensure that md5sum does *not* share the part that makes + # sha1sum accept BSD format. + ['check-bsd', '--check', {IN=> {'f.sha1' => "SHA1 (f) = $degenerate\n"}}, + {AUX=> {f=> ''}}, + {ERR=>"md5sum: f.sha1: no properly formatted " + . "checksum lines found\n"}, + {EXIT=> 1}], + ['check-bsd2', '--check', {IN=> {'f.md5' => "MD5 (f) = $degenerate\n"}}, + {AUX=> {f=> ''}}, {OUT=>"f: OK\n"}], + ['check-bsd3', '--check', '--status', + {IN=> {'f.md5' => "MD5 (f) = $degenerate\n"}}, + {AUX=> {f=> 'bar'}}, {EXIT=> 1}], + ['check-openssl', '--check', {IN=> {'f.sha1' => "SHA1(f)= $degenerate\n"}}, + {AUX=> {f=> ''}}, + {ERR=>"md5sum: f.sha1: no properly formatted " + . "checksum lines found\n"}, + {EXIT=> 1}], + ['check-openssl2', '--check', {IN=> {'f.md5' => "MD5(f)= $degenerate\n"}}, + {AUX=> {f=> ''}}, {OUT=>"f: OK\n"}], + ['check-openssl3', '--check', '--status', + {IN=> {'f.md5' => "MD5(f)= $degenerate\n"}}, + {AUX=> {f=> 'bar'}}, {EXIT=> 1}], + ['check-ignore-missing-1', '--check', '--ignore-missing', + {AUX=> {f=> ''}}, + {IN=> {'f.md5' => "$degenerate f\n". + "$degenerate f.missing\n"}}, + {OUT=>"f: OK\n"}], + ['check-ignore-missing-2', '--check', '--ignore-missing', + {AUX=> {f=> ''}}, + {IN=> {'f.md5' => "$degenerate f\n". + "$degenerate f.missing\n"}}, + {OUT=>"f: OK\n"}], + ['check-ignore-missing-3', '--check', '--quiet', '--ignore-missing', + {AUX=> {f=> ''}}, + {IN=> {'f.md5' => "$degenerate missing/f\n". + "$degenerate f\n"}}, + {OUT=>""}], + ['check-ignore-missing-4', '--ignore-missing', + {IN=> {f=> ''}}, + {ERR=>"md5sum: the --ignore-missing option is ". + "meaningful only when verifying checksums\n". + $try_help}, + {EXIT=> 1}], + ['check-ignore-missing-5', '--check', '--ignore-missing', + {AUX=> {f=> ''}}, + {IN=> {'f.md5' => "$degenerate missing\n"}}, + {ERR=> + "md5sum: f.md5: no file was verified\n"}, + {EXIT=> 1}], + # coreutils-8.25 with --ignore-missing treated checksums starting with 00 + # as if the file was not present + ['check-ignore-missing-6', '--check', '--ignore-missing', + {AUX=> {f=> '9t'}}, + {IN=> {'f.md5' => + "006999e6df389641adf1fa3a74801d9d f\n"}}, + {OUT=>"f: OK\n"}], + ['bsd-segv', '--check', {IN=> {'z' => "MD5 ("}}, {EXIT=> 1}, + {ERR=> "$prog: z: no properly formatted checksum lines found\n"}], + + # Ensure that when there's a NUL byte among the checksum hex digits + # we detect the invalid formatting and don't even open the file. + # Up to coreutils-6.10, this would report: + # h: FAILED + # md5sum: WARNING: 1 of 1 computed checksum did NOT match + ['nul-in-cksum', '--check', {IN=> {'h'=>("\0"x32)." h\n"}}, {EXIT=> 1}, + {ERR=> "$prog: h: no properly formatted checksum lines found\n"}], + ); + +# Insert the '--text' argument for each test. +my $t; +foreach $t (@Tests) + { + splice @$t, 1, 0, '--text' unless @$t[1] =~ /--check/; + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/mknod.sh b/tests/misc/mknod.sh new file mode 100755 index 0000000..250bb90 --- /dev/null +++ b/tests/misc/mknod.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# Ensure that mknod, mkfifo, mkdir -m MODE work with a restrictive umask + +# Copyright (C) 2004-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ mknod + +# Ensure fifos are supported +mkfifo_or_skip_ fifo + +umask 777 + +mknod -m 734 f1 p || fail=1 +mode=$(ls -dgo f1|cut -b-10) +test $mode = prwx-wxr-- || fail=1 + +mkfifo -m 734 f2 || fail=1 +mode=$(ls -dgo f2|cut -b-10) +test $mode = prwx-wxr-- || fail=1 + +mkdir -m 734 f3 || fail=1 +mode=$(ls -dgo f3|cut -b-10) +test $mode = drwx-wxr-- || test $mode = drwx-wsr-- || fail=1 + +Exit $fail diff --git a/tests/misc/mktemp.pl b/tests/misc/mktemp.pl new file mode 100755 index 0000000..a0f0dea --- /dev/null +++ b/tests/misc/mktemp.pl @@ -0,0 +1,200 @@ +#!/usr/bin/perl +# Test "mktemp". + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $ME = $0) =~ s|.*/||; + +sub check_tmp($$) +{ + my ($file, $file_or_dir) = @_; + + my (undef, undef, $mode, undef) = stat $file + or die "$ME: failed to stat $file: $!\n"; + my $required_mode; + if ($file_or_dir eq 'D') { + -d $file or die "$ME: $file isn't a directory\n"; + -x $file or die "$ME: $file isn't owner-searchable\n"; + $required_mode = 0700; + } elsif ($file_or_dir eq 'F') { + -f $file or die "$ME: $file isn't a regular file\n"; + $required_mode = 0600; + } + -r $file or die "$ME: $file isn't owner-readable\n"; + -w $file or die "$ME: $file isn't owner-writable\n"; + ($mode & 0777) == $required_mode + or die "$ME: $file doesn't have required permissions\n"; + + $file_or_dir eq 'D' + and do { rmdir $file or die "$ME: failed to rmdir $file: $!\n" }; + $file_or_dir eq 'F' + and do { unlink $file or die "$ME: failed to unlink $file: $!\n" }; +} + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; +my $prog = 'mktemp'; +my $bad_dir = 'no/such/dir'; + +my @Tests = + ( + # test-name, [option, option, ...] {OUT=>"expected-output"} + # + ['too-many', '-q a b', + {ERR=>"$prog: too many templates\n" + . "Try '$prog --help' for more information.\n"}, {EXIT => 1} ], + + ['too-few-x', '-q foo.XX', {EXIT => 1}, + {ERR=>"$prog: too few X's in template 'foo.XX'\n"}], + + ['1f', 'bar.XXXX', {OUT => "bar.ZZZZ\n"}, + {OUT_SUBST => 's,\.....$,.ZZZZ,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }} + ], + + ['2f', '-- -XXXX', {OUT => "-ZZZZ\n"}, + {OUT_SUBST => 's,-....$,-ZZZZ,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }} + ], + + # Create a temporary directory. + ['1d', '-d f.XXXX', {OUT => "f.ZZZZ\n"}, + {OUT_SUBST => 's,\.....$,.ZZZZ,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'D'; }} + ], + + # Use a template consisting solely of X's + ['1d-allX', '-d XXXX', {OUT => "ZZZZ\n"}, + {PRE => sub {mkdir 'XXXX',0755 or die "XXXX: $!\n"}}, + {OUT_SUBST => 's,^....$,ZZZZ,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'D'; rmdir 'XXXX' or die "rmdir XXXX: $!\n"; }} + ], + + # Test -u + ['uf', '-u f.XXXX', {OUT => "f.ZZZZ\n"}, + {OUT_SUBST => 's,\.....$,.ZZZZ,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + -e $f and die "dry-run created file"; }}], + ['ud', '-d --dry-run d.XXXX', {OUT => "d.ZZZZ\n"}, + {OUT_SUBST => 's,\.....$,.ZZZZ,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + -e $f and die "dry-run created directory"; }}], + + # Test bad templates + ['invalid-tl', '-t a/bXXXX', + {ERR=>"$prog: invalid template, 'a/bXXXX', " + . "contains directory separator\n"}, {EXIT => 1} ], + + ['invalid-t2', '--tmpdir=a /bXXXX', + {ERR=>"$prog: invalid template, '/bXXXX'; " + . "with --tmpdir, it may not be absolute\n"}, {EXIT => 1} ], + + # Suffix after X. + ['suffix1f', 'aXXXXb', {OUT=>"aZZZZb\n"}, + {OUT_SUBST=>'s,a....b,aZZZZb,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }}], + ['suffix1d', '-d aXXXXb', {OUT=>"aZZZZb\n"}, + {OUT_SUBST=>'s,a....b,aZZZZb,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'D'; }}], + ['suffix1u', '-u aXXXXb', {OUT=>"aZZZZb\n"}, + {OUT_SUBST=>'s,a....b,aZZZZb,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + -e $f and die "dry-run created file"; }}], + + ['suffix2f', 'aXXXXaaXXXXa', {OUT=>"aXXXXaaZZZZa\n"}, + {OUT_SUBST=>'s,a....a$,aZZZZa,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }}], + ['suffix2d', '-d --suffix= aXXXXaaXXXX', {OUT=>"aXXXXaaZZZZ\n"}, + {OUT_SUBST=>'s,a....$,aZZZZ,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'D'; }}], + + ['suffix3f', '--suffix=b aXXXX', {OUT=>"aZZZZb\n"}, + {OUT_SUBST=>'s,a....b,aZZZZb,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }}], + + ['suffix4f', '--suffix=X aXXXX', {OUT=>"aZZZZX\n"}, + {OUT_SUBST=>'s,^a....,aZZZZ,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }}], + + ['suffix5f', '--suffix /b aXXXX', {EXIT=>1}, + {ERR=>"$prog: invalid suffix '/b', contains directory separator\n"}], + + ['suffix6f', 'aXXXX/b', {EXIT=>1}, + {ERR=>"$prog: invalid suffix '/b', contains directory separator\n"}], + + ['suffix7f', '--suffix= aXXXXb', {EXIT=>1}, + {ERR=>"$prog: with --suffix, template 'aXXXXb' must end in X\n"}], + ['suffix7d', '-d --suffix=aXXXXb ""', {EXIT=>1}, + {ERR=>"$prog: with --suffix, template '' must end in X\n"}], + + ['suffix8f', 'aXXXX --suffix=b', {OUT=>"aZZZZb\n"}, + {OUT_SUBST=>'s,^a....,aZZZZ,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }}], + + ['suffix9f', 'aXXXX --suffix=b', {EXIT=>1}, + {ENV=>"POSIXLY_CORRECT=1"}, + {ERR=>"$prog: too many templates\n" + . "Try '$prog --help' for more information.\n"}], + + ['suffix10f', 'aXXb', {EXIT => 1}, + {ERR=>"$prog: too few X's in template 'aXXb'\n"}], + ['suffix10d', '-d --suffix=X aXX', {EXIT => 1}, + {ERR=>"$prog: too few X's in template 'aXXX'\n"}], + + ['suffix11f', '--suffix=.txt', {OUT=>"./tmp.ZZZZZZZZZZ.txt\n"}, + {ENV=>"TMPDIR=."}, + {OUT_SUBST=>'s,\..{10}\.,.ZZZZZZZZZZ.,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }}], + + + # Test template with subdirectory + ['tmp-w-slash', '--tmpdir=. a/bXXXX', + {PRE => sub {mkdir 'a',0755 or die "a: $!\n"}}, + {OUT_SUBST => 's,b....$,bZZZZ,'}, + {OUT => "./a/bZZZZ\n"}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; unlink $f; rmdir 'a' or die "rmdir a: $!\n" }} + ], + + ['pipe-bad-tmpdir', + {ENV => "TMPDIR=$bad_dir"}, + {ERR_SUBST => "s,($bad_dir/)[^']+': .*,\$1...,"}, + {ERR => "$prog: failed to create file via template '$bad_dir/...\n"}, + {EXIT => 1}], + ['pipe-bad-tmpdir-u', '-u', {OUT => "$bad_dir/tmp.ZZZZZZZZZZ\n"}, + {ENV => "TMPDIR=$bad_dir"}, + {OUT_SUBST => 's,\..{10}$,.ZZZZZZZZZZ,'}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/nice-fail.sh b/tests/misc/nice-fail.sh new file mode 100755 index 0000000..5fdd9c3 --- /dev/null +++ b/tests/misc/nice-fail.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# Verify that internal failure in nice gives exact status. + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ nice env + + +# These tests verify exact status of internal failure. +returns_ 125 nice -n 1 || fail=1 # missing command +returns_ 125 nice --- || fail=1 # unknown option +returns_ 125 nice -n 1a || fail=1 # invalid adjustment +returns_ 2 nice sh -c 'exit 2' || fail=1 # exit status propagation +returns_ 126 env . && { returns_ 126 nice . || fail=1; } # invalid command +returns_ 127 nice no_such || fail=1 # no such command + +Exit $fail diff --git a/tests/misc/nice.sh b/tests/misc/nice.sh new file mode 100755 index 0000000..d2b5cea --- /dev/null +++ b/tests/misc/nice.sh @@ -0,0 +1,93 @@ +#!/bin/sh +# Test "nice". + +# Copyright (C) 2002-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ nice + +tests=' +0 empty 10 +1 -1 1 +2 -12 12 +3 -1:-2 2 +4 -n:1 1 +5 -n:1:-2 2 +6 -n:1:-+12 12 +7 -2:-n:1 1 +8 -2:-n:12 12 +9 -+1 1 +10 -+12 12 +11 -+1:-+12 12 +12 -n:+1 1 +13 --1:-2 2 +14 --1:-2:-13 13 +15 --1:-n:2 2 +16 --1:-n:2:-3 3 +17 --1:-n:2:-13 13 +18 -n:-1:-12 12 +19 --1:-12 12 +NA LAST NA +' +set $tests + +# Require that this test be run at 'nice' level 0. +niceness=$(nice) +if test "$niceness" = 0; then + : ok +else + skip_ "this test must be run at nice level 0" +fi + +while :; do + test_name=$1 + args=$2 + expected_result=$3 + test $args = empty && args='' + test x$args = xLAST && break + args=$(echo x$args|tr : ' '|sed 's/^x//') + if test "$VERBOSE" = yes; then + #echo "testing \$(nice $args nice\) = $expected_result ..." + echo "test $test_name... " | tr -d '\n' + fi + test x$(nice $args nice 2> /dev/null) = x$expected_result \ + && ok=ok || ok=FAIL fail=1 + test "$VERBOSE" = yes && echo $ok + shift; shift; shift +done + +# Test negative niceness - command must be run whether or not change happens. +if test x$(nice -n -1 nice 2> /dev/null) = x0 ; then + # unprivileged user - warn about failure to change + nice -n -1 true 2> err || fail=1 + compare /dev/null err && fail=1 + mv err exp || framework_failure_ + nice --1 true 2> err || fail=1 + compare exp err || fail=1 + # Failure to write advisory message is fatal. Buggy through coreutils 8.0. + if test -w /dev/full && test -c /dev/full; then + returns_ 125 nice -n -1 nice > out 2> /dev/full || fail=1 + compare /dev/null out || fail=1 + fi +else + # superuser - change succeeds + nice -n -1 nice 2> err || fail=1 + compare /dev/null err || fail=1 + test x$(nice -n -1 nice) = x-1 || fail=1 + test x$(nice --1 nice) = x-1 || fail=1 +fi + +Exit $fail diff --git a/tests/misc/nl.sh b/tests/misc/nl.sh new file mode 100755 index 0000000..8a47c9e --- /dev/null +++ b/tests/misc/nl.sh @@ -0,0 +1,113 @@ +#!/bin/sh +# exercise nl functionality + +# Copyright (C) 2002-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ nl +getlimits_ + +echo a | nl > out || fail=1 +echo b | nl -s%n >> out || fail=1 +echo c | nl -n ln >> out || fail=1 +echo d | nl -n rn >> out || fail=1 +echo e | nl -n rz >> out || fail=1 +echo === >> out +printf 'a\n\n' | nl > t || fail=1; cat -A t >> out +cat <<\EOF > exp + 1 a + 1%nb +1 c + 1 d +000001 e +=== + 1^Ia$ + $ +EOF +compare exp out || fail=1 + +# Ensure numbering reset at each delimiter. +# coreutils <= v8.25 only reset at a page header. +printf '%s\n' '\:\:\:' a '\:\:' b '\:' c > in.txt || framework_failure_ +nl -ha -fa in.txt > out.tmp || fail=1 +nl -p -ha -fa in.txt >> out.tmp || fail=1 +sed '/^$/d' < out.tmp > out || framework_failure_ +cat <<\EOF > exp + 1 a + 1 b + 1 c + 1 a + 2 b + 3 c +EOF +compare exp out || fail=1 + +# Ensure we only indicate overflow when needing to output overflowed numbers +returns_ 1 nl -v$INTMAX_OFLOW /dev/null || fail=1 +printf '%s\n' a \\:\\: b > in.txt || framework_failure_ +nl -v$INTMAX_MAX in.txt > out || fail=1 +cat <<EOF > exp +$INTMAX_MAX a + +$INTMAX_MAX b +EOF +compare exp out || fail=1 +returns_ 1 nl -p -v$INTMAX_MAX in.txt > out || fail=1 + +# Test negative iteration +returns_ 1 nl -i$INTMAX_UFLOW /dev/null || fail=1 +printf '%s\n' a b > in.txt || framework_failure_ +nl -v$INTMAX_MAX -i$INTMAX_MIN in.txt > out || fail=1 +cat <<EOF > exp +$INTMAX_MAX a + -1 b +EOF +compare exp out || fail=1 +printf '%s\n' a b c > in.txt || framework_failure_ +returns_ 1 nl -v$INTMAX_MAX -i$INTMAX_MIN in.txt > out || fail=1 + +# Test GNU extension to --section-delimiter, of disabling section matching +printf '%s\n' a '\:\:' c > in.txt || framework_failure_ +nl -d '' in.txt > out || fail=1 +cat <<\EOF > exp + 1 a + 2 \:\: + 3 c +EOF +compare exp out || fail=1 + +# Test GNU extension to --section-delimiter, of supporting strings longer than 2 +printf '%s\n' a foofoo c > in.txt || framework_failure_ +nl -d 'foo' in.txt > out || fail=1 +cat <<EOF > exp + 1 a + + 1 c +EOF +compare exp out || fail=1 + +# Ensure single char delimiters assume a following ':' character (as per POSIX) +# coreutils <= v8.32 didn't match single char delimiters at all +printf '%s\n' a x:x: c > in.txt || framework_failure_ +nl -d 'x' in.txt > out || fail=1 +cat <<EOF > exp + 1 a + + 1 c +EOF +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/nohup.sh b/tests/misc/nohup.sh new file mode 100755 index 0000000..3825d12 --- /dev/null +++ b/tests/misc/nohup.sh @@ -0,0 +1,125 @@ +#!/bin/sh +# test nohup + +# Copyright (C) 2003-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ nohup + + +nohup sh -c 'echo stdout; echo stderr 1>&2' 2>err || fail=1 + +# Be careful. The results of the above nohup command +# change depending on whether stdin and stdout are redirected. +if test -t 1; then + test "$(cat nohup.out)" = stdout || fail=1 + if test -t 0; then + echo 'nohup: ignoring input and appending output to 'nohup.out'\' + else + echo 'nohup: appending output to 'nohup.out'\' + fi >exp || framework_failure_ +else + # Here it should not even exist. + test -f nohup.out && fail=1 + if test -t 0; then + echo 'nohup: ignoring input' >exp + else + rm -f exp + fi || framework_failure_ +fi +echo 'stderr' >> exp || framework_failure_ + +compare exp err || fail=1 +rm -f nohup.out err exp +# ---------------------- + +# Be careful. The results of the following nohup command +# change depending on whether stderr is redirected. +nohup sh -c 'echo stdout; echo stderr 1>&2' >out || fail=1 +if test -t 2; then + test "$(cat out|tr '\n' -)" = stdout-stderr- || fail=1 +else + test "$(cat out|tr '\n' -)" = stdout- || fail=1 +fi +# It must *not* exist. +test -f nohup.out && fail=1 +rm -f nohup.out err +# ---------------------- + +# Bug present through coreutils 8.0: failure to print advisory message +# to stderr must be fatal. Requires stdout to be terminal. +if test -w /dev/full && test -c /dev/full; then +( + # POSIX shells immediately exit the subshell on exec error. + # So check we can write to /dev/tty before the exec, which + # isn't possible if we've no controlling tty for example. + test -c /dev/tty && >/dev/tty || exit 0 + + exec >/dev/tty + test -t 1 || exit 0 + returns_ 125 nohup echo hi 2> /dev/full || fail=1 + test -f nohup.out || fail=1 + compare /dev/null nohup.out || fail=1 + rm -f nohup.out + exit $fail +) || fail=1 +fi + +nohup no-such-command 2> err +errno=$? +if test -t 1; then + test $errno = 127 || fail=1 + # It must exist. + test -f nohup.out || fail=1 + # It must be empty. + compare /dev/null nohup.out || fail=1 +fi + +cat <<\EOF > exp || framework_failure_ +nohup: appending output to 'nohup.out' +nohup: cannot run command 'no-such-command': No such file or directory +EOF +# Disable these comparisons. Too much variation in 2nd line. +# compare exp err || fail=1 +rm -f nohup.out err exp +# ---------------------- + +touch k; chmod 0 k +nohup ./k 2> err +errno=$? +test $errno = 126 || fail=1 +if test -t 1; then + # It must exist. + test -f nohup.out || fail=1 + # It must be empty. + compare /dev/null nohup.out || fail=1 +fi + +cat <<\EOF > exp || framework_failure_ +nohup: appending output to 'nohup.out' +nohup: cannot run command './k': Permission denied +EOF +# Disable these comparisons. Too much variation in 2nd line. +# compare exp err || fail=1 + +# Make sure it fails with exit status of 125 when given too few arguments, +# except that POSIX requires 127 in this case. +returns_ 125 nohup >/dev/null 2>&1 || fail=1 +export POSIXLY_CORRECT=1 +returns_ 127 nohup >/dev/null 2>&1 || fail=1 +unset POSIXLY_CORRECT + +Exit $fail diff --git a/tests/misc/nproc-avail.sh b/tests/misc/nproc-avail.sh new file mode 100755 index 0000000..14b7d6e --- /dev/null +++ b/tests/misc/nproc-avail.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Ensure that "nproc" is less than or equal to "nproc --all". + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ nproc + +all=$(nproc --all) +available=$(OMP_NUM_THREADS= nproc) + +test $available -le $all || fail=1 + +Exit $fail diff --git a/tests/misc/nproc-override.sh b/tests/misc/nproc-override.sh new file mode 100755 index 0000000..a0767db --- /dev/null +++ b/tests/misc/nproc-override.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# Test the various OpenMP override options + +# Copyright (C) 2017-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ nproc + +unset OMP_NUM_THREADS +unset OMP_THREADS_LIMIT + +avail=$(nproc) || fail=1 +test $(($avail > 0)) || fail=1 + +#OMP_THREAD_LIMIT OMP_NUM_THREADS NPROC +echo "\ + - - $avail + 1 - 1 + 1 0 1 + - 0 $avail + - 2,2,1 2 + - 2,ignored 2 + - 2bad $avail + - -2 $avail + 1 2,2,1 1 + 0 2,2,1 2 + 1bad 2,2,1 2 + 1bad $(($avail+1)),2,1 $(($avail+1)) + 1 $(($avail+1)) 1 + $(($avail+2)) $(($avail+1)) $(($avail+1)) + $(($avail+1)) $(($avail+2)) $(($avail+1)) + - $(($avail+1)) $(($avail+1))" | + +while read OMP_THREAD_LIMIT OMP_NUM_THREADS NPROC; do + test $OMP_THREAD_LIMIT = '-' && unset OMP_THREAD_LIMIT + test $OMP_NUM_THREADS = '-' && unset OMP_NUM_THREADS + export OMP_THREAD_LIMIT + export OMP_NUM_THREADS + test $(nproc) = $NPROC || + echo "[$OMP_THREAD_LIMIT] [$OMP_NUM_THREADS]" >> failed +done + +test -e failed && fail=1 + +Exit $fail diff --git a/tests/misc/nproc-positive.sh b/tests/misc/nproc-positive.sh new file mode 100755 index 0000000..25db685 --- /dev/null +++ b/tests/misc/nproc-positive.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# Ensure that nproc prints a number > 0 + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ nproc + +for mode in --all ''; do + procs=$(nproc $mode) + test "$procs" -gt 0 || fail=1 +done + +for i in -1000 0 1 1000; do + procs=$(OMP_NUM_THREADS=$i nproc) + test "$procs" -gt 0 || fail=1 +done + +for i in 0 ' 1' 1000; do + procs=$(nproc --ignore="$i") + test "$procs" -gt 0 || fail=1 +done + +for i in -1 N; do + returns_ 1 nproc --ignore=$i || fail=1 +done + +procs=$(OMP_NUM_THREADS=42 nproc --ignore=40) +test "$procs" -eq 2 || fail=1 + +Exit $fail diff --git a/tests/misc/numfmt.pl b/tests/misc/numfmt.pl new file mode 100755 index 0000000..7ec04b1 --- /dev/null +++ b/tests/misc/numfmt.pl @@ -0,0 +1,1119 @@ +#!/usr/bin/perl +# Basic tests for "numfmt". + +# Copyright (C) 2012-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; +my $prog = 'numfmt'; + +my $limits = getlimits (); + +# TODO: add localization tests with "grouping" +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $locale = $ENV{LOCALE_FR_UTF8}; +! defined $locale || $locale eq 'none' + and $locale = 'C'; + +my $try = "Try '$prog --help' for more information.\n"; + +my @Tests = + ( + ['1', '1234', {OUT => "1234"}], + ['2', '--from=si 1K', {OUT => "1000"}], + ['3', '--from=iec 1K', {OUT => "1024"}], + ['4', '--from=auto 1K', {OUT => "1000"}], + ['5', '--from=auto 1Ki', {OUT => "1024"}], + ['5.1', '--from=iec-i 1Ki', {OUT => "1024"}], + + ['6', {IN_PIPE => "1234\n"}, {OUT => "1234"}], + ['7', '--from=si', {IN_PIPE => "2K\n"}, {OUT => "2000"}], + ['7a', '--invalid=fail', {IN_PIPE => "no_NL"}, {OUT => "no_NL"}, + {ERR => "$prog: invalid number: 'no_NL'\n"}, + {EXIT => '2'}], + + ['8', '--to=si 2000', {OUT => "2.0K"}], + ['9', '--to=si 2001', {OUT => "2.1K"}], + ['10', '--to=si 1999', {OUT => "2.0K"}], + ['11', '--to=si --round=down 2001', {OUT => "2.0K"}], + ['12', '--to=si --round=down 1999', {OUT => "1.9K"}], + ['13', '--to=si --round=up 1901', {OUT => "2.0K"}], + ['14', '--to=si --round=down 1901', {OUT => "1.9K"}], + ['15', '--to=si --round=nearest 1901', {OUT => "1.9K"}], + ['16', '--to=si --round=nearest 1945', {OUT => "1.9K"}], + ['17', '--to=si --round=nearest 1955', {OUT => "2.0K"}], + + ['18', '--to=iec 2048', {OUT => "2.0K"}], + ['19', '--to=iec 2049', {OUT => "2.1K"}], + ['20', '--to=iec 2047', {OUT => "2.0K"}], + ['21', '--to=iec --round=down 2049', {OUT => "2.0K"}], + ['22', '--to=iec --round=down 2047', {OUT => "1.9K"}], + ['23', '--to=iec --round=up 2040', {OUT => "2.0K"}], + ['24', '--to=iec --round=down 2040', {OUT => "1.9K"}], + ['25', '--to=iec --round=nearest 1996', {OUT => "1.9K"}], + ['26', '--to=iec --round=nearest 1997', {OUT => "2.0K"}], + ['27', '--to=iec-i 2048', {OUT => "2.0Ki"}], + + ['neg-1', '-- -1234', {OUT => "-1234"}], + ['neg-2', '--padding=5 -- -1234', {OUT => "-1234"}], + ['neg-3', '--padding=6 -- -1234', {OUT => " -1234"}], + ['neg-4', '--to=iec -- 9100 -9100', {OUT => "8.9K\n-8.9K"}], + ['neg-5', '-- -0.1', {OUT => "-0.1"}], + ['neg-6', '-- -0', {OUT => "0"}], + ['neg-7', '-- -0.-1', + {ERR => "$prog: invalid number: '-0.-1'\n"}, + {EXIT => '2'}], + + ['float-1', '1.1', {OUT => "1.1"}], + ['float-2', '1.22', {OUT => "1.22"}], + ['float-3', '1.22.', + {ERR => "$prog: invalid suffix in input: '1.22.'\n"}, + {EXIT => '2'}], + + ['unit-1', '--from-unit=512 4', {OUT => "2048"}], + ['unit-2', '--to-unit=512 2048', {OUT => "4"}], + ['unit-3', '--from-unit=512 --from=si 4M', {OUT => "2048000000"}], + ['unit-4', '--from-unit=512 --from=iec --to=iec 4M', {OUT => "2.0G"}], + ['unit-5', '--from-unit=AA --from=iec --to=iec 4M', + {ERR => "$prog: invalid unit size: 'AA'\n"}, + {EXIT => '1'}], + ['unit-6', '--from-unit=54W --from=iec --to=iec 4M', + {ERR => "$prog: invalid unit size: '54W'\n"}, + {EXIT => '1'}], + ['unit-7', '--from-unit=K 30', {OUT=>"30000"}], + ['unit-7.1', '--from-unit=Ki 30', {OUT=>"30720"}], + ['unit-7.2', '--from-unit=i 0', + {ERR => "$prog: invalid unit size: 'i'\n"}, + {EXIT => '1'}], + ['unit-7.3', '--from-unit=1i 0', + {ERR => "$prog: invalid unit size: '1i'\n"}, + {EXIT => '1'}], + ['unit-8', '--from-unit='.$limits->{UINTMAX_OFLOW}.' --to=iec 30', + {ERR => "$prog: invalid unit size: '$limits->{UINTMAX_OFLOW}'\n"}, + {EXIT => '1'}], + ['unit-9', '--from-unit=0 1', + {ERR => "$prog: invalid unit size: '0'\n"}, + {EXIT => '1'}], + ['unit-10', '--to-unit=0 1', + {ERR => "$prog: invalid unit size: '0'\n"}, + {EXIT => '1'}], + + # Test Suffix logic + ['suf-1', '4000', {OUT=>'4000'}], + ['suf-2', '4Q', + {ERR => "$prog: invalid suffix in input: '4Q'\n"}, + {EXIT => '2'}], + ['suf-2.1', '4M', + {ERR => "$prog: rejecting suffix " . + "in input: '4M' (consider using --from)\n"}, + {EXIT => '2'}], + ['suf-3', '--from=si 4M', {OUT=>'4000000'}], + ['suf-4', '--from=si 4Q', + {ERR => "$prog: invalid suffix in input: '4Q'\n"}, + {EXIT => '2'}], + ['suf-5', '--from=si 4MQ', + {ERR => "$prog: invalid suffix in input '4MQ': 'Q'\n"}, + {EXIT => '2'}], + + ['suf-6', '--from=iec 4M', {OUT=>'4194304'}], + ['suf-7', '--from=auto 4M', {OUT=>'4000000'}], + ['suf-8', '--from=auto 4Mi', {OUT=>'4194304'}], + ['suf-9', '--from=auto 4MiQ', + {ERR => "$prog: invalid suffix in input '4MiQ': 'Q'\n"}, + {EXIT => '2'}], + ['suf-10', '--from=auto 4QiQ', + {ERR => "$prog: invalid suffix in input: '4QiQ'\n"}, + {EXIT => '2'}], + + # characters after a white space are OK - printed as-is + ['suf-11', '"4 M"', {OUT=>'4 M'}], + + # Custom suffix + ['suf-12', '--suffix=Foo 70Foo', {OUT=>'70Foo'}], + ['suf-13', '--suffix=Foo 70', {OUT=>'70Foo'}], + ['suf-14', '--suffix=Foo --from=si 70K', {OUT=>'70000Foo'}], + ['suf-15', '--suffix=Foo --from=si 70KFoo', {OUT=>'70000Foo'}], + ['suf-16', '--suffix=Foo --to=si 7000Foo', {OUT=>'7.0KFoo'}], + ['suf-17', '--suffix=Foo --to=si 7000Bar', + {ERR => "$prog: invalid suffix in input: '7000Bar'\n"}, + {EXIT => '2'}], + ['suf-18', '--suffix=Foo --to=si 7000FooF', + {ERR => "$prog: invalid suffix in input: '7000FooF'\n"}, + {EXIT => '2'}], + # space(s) between number and suffix. Note only field 1 is used + # by default so specify the NUL delimiter to consider the whole "line". + ['suf-19', "-d '' --from=si '4.0 K'", {OUT => "4000"}], + + ## GROUPING + + # "C" locale - no grouping (locale-specific tests, below) + ['grp-1', '--from=si --grouping 7M', {OUT=>'7000000'}], + ['grp-2', '--from=si --to=si --grouping 7M', + {ERR => "$prog: grouping cannot be combined with --to\n"}, + {EXIT => '1'}], + + + ## Padding + ['pad-1', '--padding=10 5', {OUT=>' 5'}], + ['pad-2', '--padding=-10 5', {OUT=>'5 '}], + ['pad-3', '--padding=A 5', + {ERR => "$prog: invalid padding value 'A'\n"}, + {EXIT => '1'}], + ['pad-3.1', '--padding=0 5', + {ERR => "$prog: invalid padding value '0'\n"}, + {EXIT => '1'}], + ['pad-3.2', "--padding=$limits->{LONG_MIN} 0", + {ERR => "$prog: invalid padding value '$limits->{LONG_MIN}'\n"}, + {EXIT => '1'}], + ['pad-4', '--padding=10 --to=si 50000', {OUT=>' 50K'}], + ['pad-5', '--padding=-10 --to=si 50000', {OUT=>'50K '}], + + # padding too narrow + ['pad-6', '--padding=2 --to=si 1000', {OUT=>'1.0K'}], + + + # Padding + suffix + ['pad-7', '--padding=10 --suffix=foo --to=si 50000', + {OUT=>' 50Kfoo'}], + ['pad-8', '--padding=-10 --suffix=foo --to=si 50000', + {OUT=>'50Kfoo '}], + + + # Delimiters + ['delim-1', '--delimiter=: --from=auto 40M:', {OUT=>'40000000:'}], + ['delim-2', '--delimiter="" --from=auto "40 M"',{OUT=>'40000000'}], + ['delim-3', '--delimiter=" " --from=auto "40M Foo"',{OUT=>'40000000 Foo'}], + ['delim-4', '--delimiter=: --from=auto 40M:60M', {OUT=>'40000000:60M'}], + ['delim-5', '-d: --field=2 --from=auto :40M:60M', {OUT=>':40000000:60M'}], + ['delim-6', '-d: --field 3 --from=auto 40M:60M', {OUT=>"40M:60M"}], + ['delim-err-1', '-d,, --to=si 1', {EXIT=>1}, + {ERR => "$prog: the delimiter must be a single character\n"}], + + #Fields + ['field-1', '--field A', + {ERR => "$prog: invalid field value 'A'\n$try"}, + {EXIT => '1'}], + ['field-2', '--field 2 --from=auto "Hello 40M World 90G"', + {OUT=>'Hello 40000000 World 90G'}], + ['field-3', '--field 3 --from=auto "Hello 40M World 90G"', + {OUT=>"Hello 40M "}, + {ERR=>"$prog: invalid number: 'World'\n"}, + {EXIT => 2},], + # Last field - no text after number + ['field-4', '--field 4 --from=auto "Hello 40M World 90G"', + {OUT=>"Hello 40M World 90000000000"}], + # Last field - a delimiter after the number + ['field-5', '--field 4 --from=auto "Hello 40M World 90G "', + {OUT=>"Hello 40M World 90000000000 "}], + + # Mix Fields + Delimiters + ['field-6', '--delimiter=: --field 2 --from=auto "Hello:40M:World:90G"', + {OUT=>"Hello:40000000:World:90G"}], + + # not enough fields + ['field-8', '--field 3 --to=si "Hello World"', {OUT=>"Hello World"}], + + # Multiple fields + ['field-range-1', '--field 2,4 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1000 2.0K 3000 4.0K 5000"}], + + ['field-range-2', '--field 2-4 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1000 2.0K 3.0K 4.0K 5000"}], + + ['field-range-3', '--field 1,2,3-5 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4.0K 5.0K"}], + + ['field-range-4', '--field 1-5 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4.0K 5.0K"}], + + ['field-range-5', '--field 1-3,5 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4000 5.0K"}], + + ['field-range-6', '--field 3- --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1000 2000 3.0K 4.0K 5.0K"}], + + ['field-range-7', '--field -3 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4000 5000"}], + + ['field-range-8', '--field 1-2,4-5 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3000 4.0K 5.0K"}], + ['field-range-9', '--field 4-5,1-2 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3000 4.0K 5.0K"}], + + ['field-range-10','--field 1-3,2-4 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4.0K 5000"}], + ['field-range-11','--field 2-4,1-3 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4.0K 5000"}], + + ['field-range-12','--field 1-1,3-3 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2000 3.0K 4000 5000"}], + + ['field-range-13', '--field 1,-2 --to=si "1000 2000 3000"', + {OUT=>"1.0K 2.0K 3000"}], + + ['field-range-14', '--field -2,4- --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3000 4.0K 5.0K"}], + ['field-range-15', '--field -2,-4 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4.0K 5000"}], + ['field-range-16', '--field 2-,4- --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1000 2.0K 3.0K 4.0K 5.0K"}], + ['field-range-17', '--field 4-,2- --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1000 2.0K 3.0K 4.0K 5.0K"}], + + # white space are valid field separators + # (undocumented? but works in cut as well). + ['field-range-18', '--field "1,2 4" --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3000 4.0K 5000"}], + + # Unlike 'cut', a lone '-' means 'all fields', even as part of a list + # of fields. + ['field-range-19','--field 3,- --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4.0K 5.0K"}], + + ['all-fields-1', '--field=- --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4.0K 5.0K"}], + + ['field-range-err-1', '--field -foo --to=si 10', + {EXIT=>1}, {ERR=>"$prog: invalid field value 'foo'\n$try"}], + ['field-range-err-2', '--field --3 --to=si 10', + {EXIT=>1}, {ERR=>"$prog: invalid field range\n$try"}], + ['field-range-err-3', '--field 0 --to=si 10', + {EXIT=>1}, {ERR=>"$prog: fields are numbered from 1\n$try"}], + ['field-range-err-4', '--field 3-2 --to=si 10', + {EXIT=>1}, {ERR=>"$prog: invalid decreasing range\n$try"}], + ['field-range-err-6', '--field - --field 1- --to=si 10', + {EXIT=>1}, {ERR=>"$prog: multiple field specifications\n"}], + ['field-range-err-7', '--field -1 --field 1- --to=si 10', + {EXIT=>1}, {ERR=>"$prog: multiple field specifications\n"}], + ['field-range-err-8', '--field -1 --field 1,2,3 --to=si 10', + {EXIT=>1}, {ERR=>"$prog: multiple field specifications\n"}], + ['field-range-err-9', '--field 1- --field 1,2,3 --to=si 10', + {EXIT=>1}, {ERR=>"$prog: multiple field specifications\n"}], + ['field-range-err-10','--field 1,2,3 --field 1- --to=si 10', + {EXIT=>1}, {ERR=>"$prog: multiple field specifications\n"}], + ['field-range-err-11','--field 1-2-3 --to=si 10', + {EXIT=>1}, {ERR=>"$prog: invalid field range\n$try"}], + ['field-range-err-12','--field 0-1 --to=si 10', + {EXIT=>1}, {ERR=>"$prog: fields are numbered from 1\n$try"}], + ['field-range-err-13','--field '.$limits->{UINTMAX_MAX}.',22 --to=si 10', + {EXIT=>1}, {ERR=>"$prog: field number " . + "'".$limits->{UINTMAX_MAX}."' is too large\n$try"}], + + # Auto-consume white-space, setup auto-padding + ['whitespace-1', '--to=si --field 2 "A 500 B"', {OUT=>"A 500 B"}], + ['whitespace-2', '--to=si --field 2 "A 5000 B"', {OUT=>"A 5.0K B"}], + ['whitespace-3', '--to=si " 500"', {OUT=>" 500"}], + ['whitespace-4', '--to=si " 6500"', {OUT=>" 6.5K"}], + # NOTE: auto-padding is not enabled if the value is on the first + # field and there's no white-space before it. + ['whitespace-5', '--to=si "6000000"', {OUT=>"6.0M"}], + # but if there is whitespace, assume auto-padding is desired. + ['whitespace-6', '--to=si " 6000000"', {OUT=>" 6.0M"}], + + # auto-padding - lines have same padding-width + # (padding_buffer will be alloc'd just once) + ['whitespace-7', '--to=si --field 2', + {IN_PIPE=>"rootfs 100000\n" . + "udevxx 2000000\n"}, + {OUT =>"rootfs 100K\n" . + "udevxx 2.0M"}], + # auto-padding - second line requires a + # larger padding (padding-buffer needs to be realloc'd) + ['whitespace-8', '--to=si --field 2', + {IN_PIPE=>"rootfs 100000\n" . + "udev 20000000\n"}, + {OUT =>"rootfs 100K\n" . + "udev 20M"}], + + + # Corner-cases: + # weird mix of identical suffix,delimiters + # The priority is: + # 1. delimiters (and fields) are parsed (in process_line() + # 2. optional custom suffix is removed (in process_suffixed_number()) + # 3. Remaining suffixes must be valid SI/IEC (in human_xstrtol()) + + # custom suffix comes BEFORE SI/IEC suffix, + # so these are 40 of "M", not 40,000,000. + ['mix-1', '--suffix=M --from=si 40M', {OUT=>"40M"}], + + # These are forty-million Ms . + ['mix-2', '--suffix=M --from=si 40MM', {OUT=>"40000000M"}], + + ['mix-3', '--suffix=M --from=auto 40MM', {OUT=>"40000000M"}], + ['mix-4', '--suffix=M --from=auto 40MiM', {OUT=>"41943040M"}], + ['mix-5', '--suffix=M --to=si --from=si 4MM', {OUT=>"4.0MM"}], + + # This might be confusing to the user, but it's legit: + # The M in the output is the custom suffix, not Mega. + ['mix-6', '--suffix=M 40', {OUT=>"40M"}], + ['mix-7', '--suffix=M 4000000', {OUT=>"4000000M"}], + ['mix-8', '--suffix=M --to=si 4000000', {OUT=>"4.0MM"}], + + # The output 'M' is the custom suffix. + ['mix-10', '--delimiter=M --suffix=M 40', {OUT=>"40M"}], + + # The INPUT 'M' is a delimiter (delimiters are top priority) + # The output contains one M for custom suffix, and one 'M' delimiter. + ['mix-11', '--delimiter=M --suffix=M 40M', {OUT=>"40MM"}], + + # Same as above, the "M" is NOT treated as a mega SI prefix, + ['mix-12', '--delimiter=M --from=si --suffix=M 40M', {OUT=>"40MM"}], + + # The 'M' is treated as a delimiter, and so the input value is '4000' + ['mix-13', '--delimiter=M --to=si --from=auto 4000M5000M9000', + {OUT=>"4.0KM5000M9000"}], + # 'M' is the delimiter, so the second input field is '5000' + ['mix-14', '--delimiter=M --field 2 --from=auto --to=si 4000M5000M9000', + {OUT=>"4000M5.0KM9000"}], + + + + ## Header testing + + # header - silently ignored with command line parameters + ['header-1', '--header --to=iec 4096', {OUT=>"4.0K"}], + + # header warning with --debug + ['header-2', '--debug --header --to=iec 4096', {OUT=>"4.0K"}, + {ERR=>"$prog: --header ignored with command-line input\n"}], + + ['header-3', '--header=A', + {ERR=>"$prog: invalid header value 'A'\n"}, + {EXIT => 1},], + ['header-4', '--header=0', + {ERR=>"$prog: invalid header value '0'\n"}, + {EXIT => 1},], + ['header-5', '--header=-6', + {ERR=>"$prog: invalid header value '-6'\n"}, + {EXIT => 1},], + ['header-6', '--debug --header --to=iec', + {IN_PIPE=>"size\n5000\n90000\n"}, + {OUT=>"size\n4.9K\n88K"}], + ['header-7', '--debug --header=3 --to=iec', + {IN_PIPE=>"hello\nworld\nsize\n5000\n90000\n"}, + {OUT=>"hello\nworld\nsize\n4.9K\n88K"}], + # header, but no actual content + ['header-8', '--header=2 --to=iec', + {IN_PIPE=>"hello\nworld\n"}, + {OUT=>"hello\nworld"}], + # not enough header lines + ['header-9', '--header=3 --to=iec', + {IN_PIPE=>"hello\nworld\n"}, + {OUT=>"hello\nworld"}], + + + ## human_strtod testing + + # NO_DIGITS_FOUND + ['strtod-1', '--from=si "foo"', + {ERR=>"$prog: invalid number: 'foo'\n"}, + {EXIT=> 2}], + ['strtod-2', '--from=si ""', + {ERR=>"$prog: invalid number: ''\n"}, + {EXIT=> 2}], + + # FRACTION_NO_DIGITS_FOUND + ['strtod-5', '--from=si 12.', + {ERR=>"$prog: invalid number: '12.'\n"}, + {EXIT=>2}], + ['strtod-6', '--from=si 12.K', + {ERR=>"$prog: invalid number: '12.K'\n"}, + {EXIT=>2}], + + # whitespace is not allowed after decimal-point + ['strtod-6.1', '--from=si --delimiter=, "12. 2"', + {ERR=>"$prog: invalid number: '12. 2'\n"}, + {EXIT=>2}], + + # INVALID_SUFFIX + ['strtod-9', '--from=si 12.2Q', + {ERR=>"$prog: invalid suffix in input: '12.2Q'\n"}, + {EXIT=>2}], + + # VALID_BUT_FORBIDDEN_SUFFIX + ['strtod-10', '12M', + {ERR => "$prog: rejecting suffix " . + "in input: '12M' (consider using --from)\n"}, + {EXIT=>2}], + + # MISSING_I_SUFFIX + ['strtod-11', '--from=iec-i 12M', + {ERR => "$prog: missing 'i' suffix in input: " . + "'12M' (e.g Ki/Mi/Gi)\n"}, + {EXIT=>2}], + + # + # Test double_to_human() + # + + # 1K and smaller + ['dbl-to-human-1','--to=si 800', {OUT=>"800"}], + ['dbl-to-human-2','--to=si 0', {OUT=>"0"}], + ['dbl-to-human-2.1','--to=si 999', {OUT=>"999"}], + ['dbl-to-human-2.2','--to=si 1000', {OUT=>"1.0K"}], + #NOTE: the following are consistent with "ls -lh" output + ['dbl-to-human-2.3','--to=iec 999', {OUT=>"999"}], + ['dbl-to-human-2.4','--to=iec 1023', {OUT=>"1023"}], + ['dbl-to-human-2.5','--to=iec 1024', {OUT=>"1.0K"}], + ['dbl-to-human-2.6','--to=iec 1025', {OUT=>"1.1K"}], + ['dbl-to-human-2.7','--to=iec 0', {OUT=>"0"}], + # no "i" suffix if output has no suffix + ['dbl-to-human-2.8','--to=iec-i 0', {OUT=>"0"}], + + # values resulting in "N.Nx" output + ['dbl-to-human-3','--to=si 8000', {OUT=>"8.0K"}], + ['dbl-to-human-3.1','--to=si 8001', {OUT=>"8.1K"}], + ['dbl-to-human-4','--to=si --round=down 8001', {OUT=>"8.0K"}], + + ['dbl-to-human-5','--to=si --round=down 3500', {OUT=>"3.5K"}], + ['dbl-to-human-6','--to=si --round=nearest 3500', {OUT=>"3.5K"}], + ['dbl-to-human-7','--to=si --round=up 3500', {OUT=>"3.5K"}], + + ['dbl-to-human-8','--to=si --round=down 3501', {OUT=>"3.5K"}], + ['dbl-to-human-9','--to=si --round=nearest 3501', {OUT=>"3.5K"}], + ['dbl-to-human-10','--to=si --round=up 3501', {OUT=>"3.6K"}], + + ['dbl-to-human-11','--to=si --round=nearest 3550', {OUT=>"3.6K"}], + ['dbl-to-human-12','--to=si --from=si 999.89K', {OUT=>"1.0M"}], + ['dbl-to-human-13','--to=si --from=si 9.9K', {OUT=>"9.9K"}], + ['dbl-to-human-14','--to=si 9900', {OUT=>"9.9K"}], + ['dbl-to-human-15','--to=iec --from=si 3.3K', {OUT=>"3.3K"}], + ['dbl-to-human-16','--to=iec --round=down --from=si 3.3K', {OUT=>"3.2K"}], + + # values resulting in 'NNx' output + ['dbl-to-human-17','--to=si 9999', {OUT=>"10K"}], + ['dbl-to-human-18','--to=si --round=down 35000', {OUT=>"35K"}], + ['dbl-to-human-19','--to=iec 35000', {OUT=>"35K"}], + ['dbl-to-human-20','--to=iec --round=down 35000', {OUT=>"34K"}], + ['dbl-to-human-21','--to=iec 35000000', {OUT=>"34M"}], + ['dbl-to-human-22','--to=iec --round=down 35000000', {OUT=>"33M"}], + ['dbl-to-human-23','--to=si 35000001', {OUT=>"36M"}], + ['dbl-to-human-24','--to=si --from=si 9.99M', {OUT=>"10M"}], + ['dbl-to-human-25','--to=si --from=iec 9.99M', {OUT=>"11M"}], + ['dbl-to-human-25.1','--to=iec 99999', {OUT=>"98K"}], + + # values resulting in 'NNNx' output + ['dbl-to-human-26','--to=si 999000000000', {OUT=>"999G"}], + ['dbl-to-human-27','--to=iec 999000000000', {OUT=>"931G"}], + ['dbl-to-human-28','--to=si 123600000000000', {OUT=>"124T"}], + ['dbl-to-human-29','--to=si 998123', {OUT=>"999K"}], + ['dbl-to-human-30','--to=si --round=nearest 998123', {OUT=>"998K"}], + ['dbl-to-human-31','--to=si 99999', {OUT=>"100K"}], + ['dbl-to-human-32','--to=iec 102399', {OUT=>"100K"}], + ['dbl-to-human-33','--to=iec-i 102399', {OUT=>"100Ki"}], + + + # Default --round=from-zero + ['round-1','--to-unit=1024 -- 6000 -6000', + {OUT=>"6\n-6"}], + ['round-2','--to-unit=1024 -- 6000.0 -6000.0', + {OUT=>"5.9\n-5.9"}], + ['round-3','--to-unit=1024 -- 6000.00 -6000.00', + {OUT=>"5.86\n-5.86"}], + ['round-4','--to-unit=1024 -- 6000.000 -6000.000', + {OUT=>"5.860\n-5.860"}], + ['round-5','--to-unit=1024 -- 6000.0000 -6000.0000', + {OUT=>"5.8594\n-5.8594"}], + # --round=up + ['round-1-up','--round=up --to-unit=1024 -- 6000 -6000', + {OUT=>"6\n-5"}], + ['round-2-up','--round=up --to-unit=1024 -- 6000.0 -6000.0', + {OUT=>"5.9\n-5.8"}], + ['round-3-up','--round=up --to-unit=1024 -- 6000.00 -6000.00', + {OUT=>"5.86\n-5.85"}], + ['round-4-up','--round=up --to-unit=1024 -- 6000.000 -6000.000', + {OUT=>"5.860\n-5.859"}], + ['round-5-up','--round=up --to-unit=1024 -- 6000.0000 -6000.0000', + {OUT=>"5.8594\n-5.8593"}], + # --round=down + ['round-1-down','--round=down --to-unit=1024 -- 6000 -6000', + {OUT=>"5\n-6"}], + ['round-2-down','--round=down --to-unit=1024 -- 6000.0 -6000.0', + {OUT=>"5.8\n-5.9"}], + ['round-3-down','--round=down --to-unit=1024 -- 6000.00 -6000.00', + {OUT=>"5.85\n-5.86"}], + ['round-4-down','--round=down --to-unit=1024 -- 6000.000 -6000.000', + {OUT=>"5.859\n-5.860"}], + ['round-5-down','--round=down --to-unit=1024 -- 6000.0000 -6000.0000', + {OUT=>"5.8593\n-5.8594"}], + # --round=towards-zero + ['round-1-to-zero','--ro=towards-zero --to-u=1024 -- 6000 -6000', + {OUT=>"5\n-5"}], + ['round-2-to-zero','--ro=towards-zero --to-u=1024 -- 6000.0 -6000.0', + {OUT=>"5.8\n-5.8"}], + ['round-3-to-zero','--ro=towards-zero --to-u=1024 -- 6000.00 -6000.00', + {OUT=>"5.85\n-5.85"}], + ['round-4-to-zero','--ro=towards-zero --to-u=1024 -- 6000.000 -6000.000', + {OUT=>"5.859\n-5.859"}], + ['round-5-to-zero','--ro=towards-zero --to-u=1024 -- 6000.0000 -6000.0000', + {OUT=>"5.8593\n-5.8593"}], + # --round=nearest + ['round-1-near','--ro=nearest --to-u=1024 -- 6000 -6000', + {OUT=>"6\n-6"}], + ['round-2-near','--ro=nearest --to-u=1024 -- 6000.0 -6000.0', + {OUT=>"5.9\n-5.9"}], + ['round-3-near','--ro=nearest --to-u=1024 -- 6000.00 -6000.00', + {OUT=>"5.86\n-5.86"}], + ['round-4-near','--ro=nearest --to-u=1024 -- 6000.000 -6000.000', + {OUT=>"5.859\n-5.859"}], + ['round-5-near','--ro=nearest --to-u=1024 -- 6000.0000 -6000.0000', + {OUT=>"5.8594\n-5.8594"}], + + + # Leading zeros weren't handled appropriately before 8.24 + ['leading-1','0000000000000000000000000001', {OUT=>"1"}], + ['leading-2','.1', {OUT=>"0.1"}], + ['leading-3','bad.1', + {ERR => "$prog: invalid number: 'bad.1'\n"}, + {EXIT => 2}], + ['leading-4','..1', + {ERR => "$prog: invalid suffix in input: '..1'\n"}, + {EXIT => 2}], + ['leading-5','1.', + {ERR => "$prog: invalid number: '1.'\n"}, + {EXIT => 2}], + + # precision override + ['precision-1','--format=%.4f 9991239123 --to=si', {OUT=>"9.9913G"}], + ['precision-2','--format=%.1f 9991239123 --to=si', {OUT=>"10.0G"}], + ['precision-3','--format=%.1f 1', {OUT=>"1.0"}], + ['precision-4','--format=%.1f 1.12', {OUT=>"1.2"}], + ['precision-5','--format=%.1f 9991239123 --to-unit=G', {OUT=>"10.0"}], + ['precision-6','--format="% .1f" 9991239123 --to-unit=G', {OUT=>"10.0"}], + ['precision-7','--format=%.-1f 1.1', + {ERR => "$prog: invalid precision in format '%.-1f'\n"}, + {EXIT => 1}], + ['precision-8','--format=%.+1f 1.1', + {ERR => "$prog: invalid precision in format '%.+1f'\n"}, + {EXIT => 1}], + ['precision-9','--format="%. 1f" 1.1', + {ERR => "$prog: invalid precision in format '%. 1f'\n"}, + {EXIT => 1}], + + # debug warnings + ['debug-1', '--debug 4096', {OUT=>"4096"}, + {ERR=>"$prog: no conversion option specified\n"}], + # '--padding' is a valid conversion option - no warning should be printed + ['debug-1.1', '--debug --padding 10 4096', {OUT=>" 4096"}], + ['debug-2', '--debug --grouping --from=si 4.0K', {OUT=>"4000"}, + {ERR=>"$prog: grouping has no effect in this locale\n"}], + + # dev-debug messages - the actual messages don't matter + # just ensure the program works, and for code coverage testing. + ['devdebug-1', '---debug --from=si 4.9K', {OUT=>"4900"}, + {ERR=>""}, + {ERR_SUBST=>"s/.*//msg"}], + ['devdebug-2', '---debug 4900', {OUT=>"4900"}, + {ERR=>""}, + {ERR_SUBST=>"s/.*//msg"}], + ['devdebug-3', '---debug --from=auto 4Mi', {OUT=>"4194304"}, + {ERR=>""}, + {ERR_SUBST=>"s/.*//msg"}], + ['devdebug-4', '---debug --to=si 4000000', {OUT=>"4.0M"}, + {ERR=>""}, + {ERR_SUBST=>"s/.*//msg"}], + ['devdebug-5', '---debug --to=si --padding=5 4000000', {OUT=>" 4.0M"}, + {ERR=>""}, + {ERR_SUBST=>"s/.*//msg"}], + ['devdebug-6', '---debug --suffix=Foo 1234Foo', {OUT=>"1234Foo"}, + {ERR=>""}, + {ERR_SUBST=>"s/.*//msg"}], + ['devdebug-7', '---debug --suffix=Foo 1234', {OUT=>"1234Foo"}, + {ERR=>""}, + {ERR_SUBST=>"s/.*//msg"}], + ['devdebug-9', '---debug --grouping 10000', {OUT=>"10000"}, + {ERR=>""}, + {ERR_SUBST=>"s/.*//msg"}], + ['devdebug-10', '---debug --format %f 10000', {OUT=>"10000"}, + {ERR=>""}, + {ERR_SUBST=>"s/.*//msg"}], + ['devdebug-11', '---debug --format "%\'-10f" 10000',{OUT=>"10000 "}, + {ERR=>""}, + {ERR_SUBST=>"s/.*//msg"}], + + # Invalid parameters + ['help-1', '--foobar', + {ERR=>"$prog: unrecognized option\n$try"}, + {ERR_SUBST=>"s/option.*/option/; s/unknown/unrecognized/"}, + {EXIT=>1}], + + ## Format string - check error detection + ['fmt-err-1', '--format ""', + {ERR=>"$prog: format '' has no % directive\n"}, + {EXIT=>1}], + ['fmt-err-2', '--format "hello"', + {ERR=>"$prog: format 'hello' has no % directive\n"}, + {EXIT=>1}], + ['fmt-err-3', '--format "hello%"', + {ERR=>"$prog: format 'hello%' ends in %\n"}, + {EXIT=>1}], + ['fmt-err-4', '--format "%d"', + {ERR=>"$prog: invalid format '%d', " . + "directive must be %[0]['][-][N][.][N]f\n"}, + {EXIT=>1}], + ['fmt-err-5', '--format "% -43 f"', + {ERR=>"$prog: invalid format '% -43 f', " . + "directive must be %[0]['][-][N][.][N]f\n"}, + {EXIT=>1}], + ['fmt-err-6', '--format "%f %f"', + {ERR=>"$prog: format '%f %f' has too many % directives\n"}, + {EXIT=>1}], + ['fmt-err-7', '--format "%'.$limits->{LONG_OFLOW}.'f"', + {ERR=>"$prog: invalid format '%$limits->{LONG_OFLOW}f'". + " (width overflow)\n"}, + {EXIT=>1}], + ['fmt-err-9', '--format "%f" --grouping', + {ERR=>"$prog: --grouping cannot be combined with --format\n"}, + {EXIT=>1}], + ['fmt-err-10', '--format "%\'f" --to=si', + {ERR=>"$prog: grouping cannot be combined with --to\n"}, + {EXIT=>1}], + ['fmt-err-11', '--debug --format "%\'f" 5000', {OUT=>"5000"}, + {ERR=>"$prog: grouping has no effect in this locale\n"}], + + ## Format string - check some corner cases + ['fmt-1', '--format "%% %f" 5000', {OUT=>"%%5000"}], + ['fmt-2', '--format "%f %%" 5000', {OUT=>"5000 %%"}], + + ['fmt-3', '--format "--%f--" 5000000', {OUT=>"--5000000--"}], + ['fmt-4', '--format "--%f--" --to=si 5000000', {OUT=>"--5.0M--"}], + + ['fmt-5', '--format "--%10f--" --to=si 5000000',{OUT=>"-- 5.0M--"}], + ['fmt-6', '--format "--%-10f--" --to=si 5000000',{OUT=>"--5.0M --"}], + ['fmt-7', '--format "--%10f--" 5000000',{OUT=>"-- 5000000--"}], + ['fmt-8', '--format "--%-10f--" 5000000',{OUT=>"--5000000 --"}], + + # too-short width + ['fmt-9', '--format "--%5f--" 5000000',{OUT=>"--5000000--"}], + + # Format + Suffix + ['fmt-10', '--format "--%10f--" --suffix Foo 50', {OUT=>"-- 50Foo--"}], + ['fmt-11', '--format "--%-10f--" --suffix Foo 50',{OUT=>"--50Foo --"}], + + # Grouping in C locale - no grouping effect + ['fmt-12', '--format "%\'f" 50000',{OUT=>"50000"}], + ['fmt-13', '--format "%\'10f" 50000', {OUT=>" 50000"}], + ['fmt-14', '--format "%\'-10f" 50000',{OUT=>"50000 "}], + + # Very large format strings + ['fmt-15', '--format "--%100000f--" --to=si 4200', + {OUT=>"--" . " " x 99996 . "4.2K--" }], + + # --format padding overrides --padding + ['fmt-16', '--format="%6f" --padding=66 1234',{OUT=>" 1234"}], + + # zero padding + ['fmt-17', '--format="%06f" 1234',{OUT=>"001234"}], + # also support spaces (which are ignored as spacing is handled separately) + ['fmt-18', '--format="%0 6f" 1234',{OUT=>"001234"}], + # handle generic padding in combination + ['fmt-22', '--format="%06f" --padding=7 1234',{OUT=>" 001234"}], + ['fmt-23', '--format="%06f" --padding=-7 1234',{OUT=>"001234 "}], + + + ## Check all errors again, this time with --invalid=fail + ## Input will be printed without conversion, + ## and exit code will be 2 + ['ign-err-1', '--invalid=fail 4Q', + {ERR => "$prog: invalid suffix in input: '4Q'\n"}, + {OUT => "4Q\n"}, + {EXIT => 2}], + ['ign-err-2', '--invalid=fail 4M', + {ERR => "$prog: rejecting suffix " . + "in input: '4M' (consider using --from)\n"}, + {OUT => "4M\n"}, + {EXIT => 2}], + ['ign-err-3', '--invalid=fail --from=si 4MQ', + {ERR => "$prog: invalid suffix in input '4MQ': 'Q'\n"}, + {OUT => "4MQ\n"}, + {EXIT => 2}], + ['ign-err-4', '--invalid=fail --suffix=Foo --to=si 7000FooF', + {ERR => "$prog: invalid suffix in input: '7000FooF'\n"}, + {OUT => "7000FooF\n"}, + {EXIT => 2}], + ['ign-err-5','--invalid=fail --field 3 --from=auto "Hello 40M World 90G"', + {ERR => "$prog: invalid number: 'World'\n"}, + {OUT => "Hello 40M World 90G\n"}, + {EXIT => 2}], + ['ign-err-7', '--invalid=fail --from=si "foo"', + {ERR => "$prog: invalid number: 'foo'\n"}, + {OUT => "foo\n"}, + {EXIT=> 2}], + ['ign-err-8', '--invalid=fail 12M', + {ERR => "$prog: rejecting suffix " . + "in input: '12M' (consider using --from)\n"}, + {OUT => "12M\n"}, + {EXIT => 2}], + ['ign-err-9', '--invalid=fail --from=iec-i 12M', + {ERR => "$prog: missing 'i' suffix in input: " . + "'12M' (e.g Ki/Mi/Gi)\n"}, + {OUT => "12M\n"}, + {EXIT=>2}], + + ## Ignore Errors with multiple conversions + ['ign-err-m1', '--invalid=ignore --to=si 1000 2000 bad 3000', + {OUT => "1.0K\n2.0K\nbad\n3.0K"}, + {EXIT => 0}], + ['ign-err-m1.1', '--invalid=ignore --to=si', + {IN_PIPE => "1000\n2000\nbad\n3000\n"}, + {OUT => "1.0K\n2.0K\nbad\n3.0K"}, + {EXIT => 0}], + ['ign-err-m1.3', '--invalid=fail --debug --to=si 1000 2000 3000', + {OUT => "1.0K\n2.0K\n3.0K"}, + {EXIT => 0}], + ['ign-err-m2', '--invalid=fail --to=si 1000 Foo 3000', + {OUT => "1.0K\nFoo\n3.0K\n"}, + {ERR => "$prog: invalid number: 'Foo'\n"}, + {EXIT => 2}], + ['ign-err-m2.1', '--invalid=warn --to=si', + {IN_PIPE => "1000\nFoo\n3000\n"}, + {OUT => "1.0K\nFoo\n3.0K"}, + {ERR => "$prog: invalid number: 'Foo'\n"}, + {EXIT => 0}], + + # --debug will trigger a final warning at EOF + ['ign-err-m2.2', '--invalid=fail --debug --to=si 1000 Foo 3000', + {OUT => "1.0K\nFoo\n3.0K\n"}, + {ERR => "$prog: invalid number: 'Foo'\n" . + "$prog: failed to convert some of the input numbers\n"}, + {EXIT => 2}], + + ['ign-err-m3', '--invalid=fail --field 2 --from=si --to=iec', + {IN_PIPE => "A 1K x\nB 2M y\nC 3G z\n"}, + {OUT => "A 1000 x\nB 2.0M y\nC 2.8G z"}, + {EXIT => 0}], + # invalid input on one of the fields + ['ign-err-m3.1', '--invalid=fail --field 2 --from=si --to=iec', + {IN_PIPE => "A 1K x\nB Foo y\nC 3G z\n"}, + {OUT => "A 1000 x\nB Foo y\nC 2.8G z\n"}, + {ERR => "$prog: invalid number: 'Foo'\n"}, + {EXIT => 2}], + ); + +# test null-terminated lines +my @NullDelim_Tests = + ( + # Input from STDIN + ['z1', '-z --to=iec', + {IN_PIPE => "1025\x002048\x00"}, {OUT=>"1.1K\x002.0K\x00"}], + + # Input from the commandline - terminated by NULL vs NL + ['z3', ' --to=iec 1024', {OUT=>"1.0K\n"}], + ['z2', '-z --to=iec 1024', {OUT=>"1.0K\x00"}], + + # Input from STDIN, with fields + ['z4', '-z --field=3 --to=si', + {IN_PIPE => "A B 1001 C\x00" . + "D E 2002 F\x00"}, + {OUT => "A B 1.1K C\x00" . + "D E 2.1K F\x00"}], + + # Input from STDIN, with fields and embedded NL + ['z5', '-z --field=3 --to=si', + {IN_PIPE => "A\nB 1001 C\x00" . + "D E\n2002 F\x00"}, + {OUT => "A B 1.1K C\x00" . + "D E 2.1K F\x00"}], + ); + +my @Limit_Tests = + ( + # Large Values + ['large-1','1000000000000000', {OUT=>"1000000000000000"}], + # 18 digits is OK + ['large-2','1000000000000000000', {OUT=>"1000000000000000000"}], + # 19 digits is too much (without output scaling) + ['large-3','10000000000000000000', + {ERR => "$prog: value too large to be printed: '1e+19' " . + "(consider using --to)\n"}, + {EXIT=>2}], + ['large-4','1000000000000000000.0', + {ERR => "$prog: value/precision too large to be printed: " . + "'1e+18/1' (consider using --to)\n"}, + {EXIT=>2}], + + + # Test input: + # Up to 27 digits is OK. + ['large-3.1', '--to=si 1', {OUT=> "1"}], + ['large-3.2', '--to=si 10', {OUT=> "10"}], + ['large-3.3', '--to=si 100', {OUT=> "100"}], + ['large-3.4', '--to=si 1000', {OUT=>"1.0K"}], + ['large-3.5', '--to=si 10000', {OUT=> "10K"}], + ['large-3.6', '--to=si 100000', {OUT=>"100K"}], + ['large-3.7', '--to=si 1000000', {OUT=>"1.0M"}], + ['large-3.8', '--to=si 10000000', {OUT=> "10M"}], + ['large-3.9', '--to=si 100000000', {OUT=>"100M"}], + ['large-3.10','--to=si 1000000000', {OUT=>"1.0G"}], + ['large-3.11','--to=si 10000000000', {OUT=> "10G"}], + ['large-3.12','--to=si 100000000000', {OUT=>"100G"}], + ['large-3.13','--to=si 1000000000000', {OUT=>"1.0T"}], + ['large-3.14','--to=si 10000000000000', {OUT=> "10T"}], + ['large-3.15','--to=si 100000000000000', {OUT=>"100T"}], + ['large-3.16','--to=si 1000000000000000', {OUT=>"1.0P"}], + ['large-3.17','--to=si 10000000000000000', {OUT=> "10P"}], + ['large-3.18','--to=si 100000000000000000', {OUT=>"100P"}], + ['large-3.19','--to=si 1000000000000000000', {OUT=>"1.0E"}], + ['large-3.20','--to=si 10000000000000000000', {OUT=> "10E"}], + ['large-3.21','--to=si 210000000000000000000', {OUT=>"210E"}], + ['large-3.22','--to=si 3210000000000000000000', {OUT=>"3.3Z"}], + ['large-3.23','--to=si 43210000000000000000000', {OUT=> "44Z"}], + ['large-3.24','--to=si 543210000000000000000000', {OUT=>"544Z"}], + ['large-3.25','--to=si 6543210000000000000000000', {OUT=>"6.6Y"}], + ['large-3.26','--to=si 76543210000000000000000000', {OUT=> "77Y"}], + ['large-3.27','--to=si 876543210000000000000000000', {OUT=>"877Y"}], + + # More than 27 digits is not OK + ['large-3.28','--to=si 9876543210000000000000000000', + {ERR => "$prog: value too large to be converted: " . + "'9876543210000000000000000000'\n"}, + {EXIT => 2}], + + # Test Output + ['large-4.1', '--from=si 9.7M', {OUT=>"9700000"}], + ['large-4.2', '--from=si 10M', {OUT =>"10000000"}], + ['large-4.3', '--from=si 200M', {OUT =>"200000000"}], + ['large-4.4', '--from=si 3G', {OUT =>"3000000000"}], + ['large-4.5', '--from=si 40G', {OUT =>"40000000000"}], + ['large-4.6', '--from=si 500G', {OUT =>"500000000000"}], + ['large-4.7', '--from=si 6T', {OUT =>"6000000000000"}], + ['large-4.8', '--from=si 70T', {OUT =>"70000000000000"}], + ['large-4.9', '--from=si 800T', {OUT =>"800000000000000"}], + ['large-4.10','--from=si 9P', {OUT =>"9000000000000000"}], + ['large-4.11','--from=si 10P', {OUT =>"10000000000000000"}], + ['large-4.12','--from=si 200P', {OUT =>"200000000000000000"}], + ['large-4.13','--from=si 3E', {OUT =>"3000000000000000000"}], + + # More than 18 digits of output without scaling - no good. + ['large-4.14','--from=si 40E', + {ERR => "$prog: value too large to be printed: '4e+19' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.15','--from=si 500E', + {ERR => "$prog: value too large to be printed: '5e+20' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.16','--from=si 6Z', + {ERR => "$prog: value too large to be printed: '6e+21' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.17','--from=si 70Z', + {ERR => "$prog: value too large to be printed: '7e+22' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.18','--from=si 800Z', + {ERR => "$prog: value too large to be printed: '8e+23' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.19','--from=si 9Y', + {ERR => "$prog: value too large to be printed: '9e+24' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.20','--from=si 10Y', + {ERR => "$prog: value too large to be printed: '1e+25' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.21','--from=si 200Y', + {ERR => "$prog: value too large to be printed: '2e+26' " . + "(consider using --to)\n"}, + {EXIT => 2}], + + ['large-5.1','--to=si 1000000000000000000', {OUT=>"1.0E"}], + ['large-5','--from=si --to=si 2E', {OUT=>"2.0E"}], + ['large-6','--from=si --to=si 3.4Z', {OUT=>"3.4Z"}], + ['large-7','--from=si --to=si 80Y', {OUT=>"80Y"}], + ['large-8','--from=si --to=si 9000Z', {OUT=>"9.0Y"}], + + ['large-10','--from=si --to=si 999Y', {OUT=>"999Y"}], + ['large-11','--from=si --to=iec 999Y', {OUT=>"827Y"}], + ['large-12','--from=si --round=down --to=iec 999Y', {OUT=>"826Y"}], + + # units can also affect the output + ['large-13','--from=si --from-unit=1000000 9P', + {ERR => "$prog: value too large to be printed: '9e+21' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-13.1','--from=si --from-unit=1000000 --to=si 9P', {OUT=>"9.0Z"}], + + # Numbers>999Y are never acceptable, regardless of scaling + ['large-14','--from=si --to=si 999Y', {OUT=>"999Y"}], + ['large-14.1','--from=si --to=si 1000Y', + {ERR => "$prog: value too large to be printed: '1e+27' " . + "(cannot handle values > 999Y)\n"}, + {EXIT => 2}], + ['large-14.2','--from=si --to=si --from-unit=10000 1Y', + {ERR => "$prog: value too large to be printed: '1e+28' " . + "(cannot handle values > 999Y)\n"}, + {EXIT => 2}], + + # intmax_t overflow when rounding caused this to fail before 8.24 + ['large-15',$limits->{INTMAX_OFLOW}, {OUT=>$limits->{INTMAX_OFLOW}}], + ['large-16','9.300000000000000000', {OUT=>'9.300000000000000000'}], + + # INTEGRAL_OVERFLOW + ['strtod-3', '--from=si "1234567890123456789012345678901234567890'. + '1234567890123456789012345678901234567890"', + {ERR=>"$prog: value too large to be converted: '" . + "1234567890123456789012345678901234567890" . + "1234567890123456789012345678901234567890'\n", + }, + {EXIT=> 2}], + + # FRACTION_OVERFLOW + ['strtod-7', '--from=si "12.1234567890123456789012345678901234567890'. + '1234567890123456789012345678901234567890"', + {ERR=>"$prog: value too large to be converted: '" . + "12.1234567890123456789012345678901234567890" . + "1234567890123456789012345678901234567890'\n", + }, + {EXIT=> 2}], + + ['debug-4', '--to=si --debug 12345678901234567890', + {OUT=>"13E"}, + {ERR=>"$prog: large input value '12345678901234567890':" . + " possible precision loss\n"}], + ['debug-5', '--to=si --from=si --debug 1.12345678901234567890Y', + {OUT=>"1.2Y"}, + {ERR=>"$prog: large input value '1.12345678901234567890Y':" . + " possible precision loss\n"}], + + ['ign-err-10','--invalid=fail 10000000000000000000', + {ERR => "$prog: value too large to be printed: '1e+19' " . + "(consider using --to)\n"}, + {OUT => "10000000000000000000\n"}, + {EXIT=>2}], + ['ign-err-11','--invalid=fail --to=si 9876543210000000000000000000', + {ERR => "$prog: value too large to be converted: " . + "'9876543210000000000000000000'\n"}, + {OUT => "9876543210000000000000000000\n"}, + {EXIT => 2}], + ); +# Restrict these tests to systems with LDBL_DIG == 18 +(system "$prog ---debug 1 2>&1|grep 'MAX_UNSCALED_DIGITS: 18' > /dev/null") == 0 + and push @Tests, @Limit_Tests; + +my @Locale_Tests = + ( + # Locale that supports grouping, but without '--grouping' parameter + ['lcl-grp-1', '--from=si 7M', {OUT=>"7000000"}, + {ENV=>"LC_ALL=$locale"}], + + # Locale with grouping + ['lcl-grp-2', '--from=si --grouping 7M', {OUT=>"7 000 000"}, + {ENV=>"LC_ALL=$locale"}], + + # Locale with grouping and debug - no debug warning message + ['lcl-grp-3', '--from=si --debug --grouping 7M', {OUT=>"7 000 000"}, + {ENV=>"LC_ALL=$locale"}], + + # Input with locale'd decimal-point + ['lcl-stdtod-1', '--from=si 12,2K', {OUT=>"12200"}, + {ENV=>"LC_ALL=$locale"}], + + ['lcl-dbl-to-human-1', '--to=si 1100', {OUT=>"1,1K"}, + {ENV=>"LC_ALL=$locale"}], + + # Format + Grouping + ['lcl-fmt-1', '--format "%\'f" 50000',{OUT=>"50 000"}, + {ENV=>"LC_ALL=$locale"}], + ['lcl-fmt-2', '--format "--%\'10f--" 50000', {OUT=>"-- 50 000--"}, + {ENV=>"LC_ALL=$locale"}], + ['lcl-fmt-3', '--format "--%\'-10f--" 50000',{OUT=>"--50 000 --"}, + {ENV=>"LC_ALL=$locale"}], + ['lcl-fmt-4', '--format "--%-10f--" --to=si 5000000', + {OUT=>"--5,0M --"}, + {ENV=>"LC_ALL=$locale"}], + # handle zero/grouping in combination + ['lcl-fmt-5', '--format="%\'06f" 1234',{OUT=>"01 234"}, + {ENV=>"LC_ALL=$locale"}], + ['lcl-fmt-6', '--format="%0\'6f" 1234',{OUT=>"01 234"}, + {ENV=>"LC_ALL=$locale"}], + ['lcl-fmt-7', '--format="%0\'\'6f" 1234',{OUT=>"01 234"}, + {ENV=>"LC_ALL=$locale"}], + + ); +if ($locale ne 'C') + { + # Reset locale to 'C' if LOCALE_FR_UTF8 doesn't output as expected + # as determined by the separate printf program. + open(LOC_NUM, "env LC_ALL=$locale printf \"%'d\" 1234|") + or die "Can't fork command: $!"; + my $loc_num = <LOC_NUM>; + close(LOC_NUM) || die "Failed to read grouped number from printf"; + if ($loc_num ne '1 234') + { + warn "skipping locale grouping tests as 1234 groups like $loc_num\n"; + $locale = 'C'; + } + } +push @Tests, @Locale_Tests if $locale ne 'C'; + +## Check all valid/invalid suffixes +foreach my $suf ( 'A' .. 'Z', 'a' .. 'z' ) { + if ( $suf =~ /^[KMGTPEZY]$/ ) + { + push @Tests, ["auto-suf-si-$suf","--from=si --to=si 1$suf", + {OUT=>"1.0$suf"}]; + push @Tests, ["auto-suf-iec-$suf","--from=iec --to=iec 1$suf", + {OUT=>"1.0$suf"}]; + push @Tests, ["auto-suf-auto-$suf","--from=auto --to=iec 1${suf}i", + {OUT=>"1.0$suf"}]; + push @Tests, ["auto-suf-iec-to-ieci-$suf","--from=iec --to=iec-i 1${suf}", + {OUT=>"1.0${suf}i"}]; + push @Tests, ["auto-suf-ieci-to-iec-$suf", + "--from=iec-i --to=iec 1${suf}i",{OUT=>"1.0${suf}"}]; + } + else + { + push @Tests, ["auto-suf-si-$suf","--from=si --to=si 1$suf", + {ERR=>"$prog: invalid suffix in input: '1${suf}'\n"}, + {EXIT=>2}]; + } +} + +# Prepend the command line argument and append a newline to end +# of each expected 'OUT' string. +my $t; + +Test: +foreach $t (@Tests) + { + # Don't fiddle with expected OUT string if there's a nonzero exit status. + foreach my $e (@$t) + { + ref $e eq 'HASH' && exists $e->{EXIT} && $e->{EXIT} + and next Test; + } + + foreach my $e (@$t) + { + ref $e eq 'HASH' && exists $e->{OUT} + and $e->{OUT} .= "\n" + } + } + +# Add test for null-terminated lines (after adjusting the OUT string, above). +push @Tests, @NullDelim_Tests; + +my $save_temps = $ENV{SAVE_TEMPS}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/od-N.sh b/tests/misc/od-N.sh new file mode 100755 index 0000000..1ea36c3 --- /dev/null +++ b/tests/misc/od-N.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# Verify that 'od -N N' reads no more than N bytes of input. + +# Copyright (C) 2001-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ od + +echo abcdefg > in || framework_failure_ + + +(od -An -N3 -c; od -An -N3 -c) < in > out +cat <<EOF > exp || framework_failure_ + a b c + d e f +EOF +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/od-endian.sh b/tests/misc/od-endian.sh new file mode 100755 index 0000000..10f1dfb --- /dev/null +++ b/tests/misc/od-endian.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# verify that od --endian works properly + +# Copyright (C) 2014-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ od + +in='0123456789abcdef' + +NL=' +' + +# rev(1) is not generally available, so here's a simplistic +# implementation sufficient for our purposes. +rev() { + while read line; do + printf '%s' "$line" | sed "s/./&\\$NL/g" | tac | paste -s -d '' + done +} + +in_swapped() { printf '%s' "$in" | sed "s/.\{$1\}/&\\$NL/g" | rev |tr -d '\n'; } + +for e in little big; do + test $e = little && eo=big || eo=little + for s in 1 2 4 8 16; do + for t in x f; do + od -t $t$s --endian=$e /dev/null > /dev/null 2>&1 || continue + printf '%s' "$in" | od -An -t $t$s --endian=$e > out1 + in_swapped "$s" | od -An -t $t$s --endian=$eo > out2 + compare out1 out2 || fail=1 + done + done +done + +Exit $fail diff --git a/tests/misc/od-float.sh b/tests/misc/od-float.sh new file mode 100755 index 0000000..91a9030 --- /dev/null +++ b/tests/misc/od-float.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# Test od on floating-point values. + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ od + +export LC_ALL=C + +# Test for a bug in coreutils up through 8.7: od was losing +# information when asked to parse floating-point values. The numeric +# tests are valid only on Intel-like hosts, but that should be good +# enough to detect regressions, as they are designed to succeed on +# non-Intel-like hosts. Also, test for another bug in coreutils 8.7 +# on x86: sometimes there was no space between the columns. + +set x $(echo aaaabaaa | tr ab '\376\377' | od -t fF) || + fail=1 +case "$*" in +*0-*) fail=1;; +esac +case $3,$4 in +-1.694740e+38,-1.694740e+38) fail=1;; +esac + +set x $(echo aaaaaaaabaaaaaaa | tr ab '\376\377' | od -t fD) || + fail=1 +case "$*" in +*0-*) fail=1;; +esac +case $3,$4 in +-5.314010372517808e+303,-5.314010372517808e+303) fail=1;; +esac + +set x $(echo aaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa | tr ab '\376\377' | od -t fL) || + fail=1 +case "$*" in +*0-*) fail=1;; +esac +case $3,$4 in +-1.023442870282055988e+4855,-1.023442870282055988e+4855) fail=1;; +esac + +# Ensure od doesn't crash as it did on glibc <= 2.5: +# https://sourceware.org/bugzilla/show_bug.cgi?id=4586 +set x $(printf 00000000ff000000 | tr 0f '\000\377' | od -t fL) || fail=1 +# With coreutils <= 8.7 we used to print "nan" for the above invalid value. +# However since v8.7-22-ga71c22f we deferred to the system printf routines +# through the use of the ftoastr module. So the following check would only +# be valid on x86_64 if we again handle the conversion internally or +# if this glibc bug is resolved: +# https://sourceware.org/bugzilla/show_bug.cgi?id=17661 +#case "$*" in +#*nan*) ;; +#*) fail=1;; +#esac + +Exit $fail diff --git a/tests/misc/od-j.sh b/tests/misc/od-j.sh new file mode 100755 index 0000000..a632f3b --- /dev/null +++ b/tests/misc/od-j.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# Verify that 'od -j N' skips N bytes of input. + +# Copyright 2014-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ od + +for file in ${srcdir=.}/tests/init.sh /proc/version /sys/kernel/profiling; do + test -r $file || continue + + cp -f $file copy && + bytes=$(wc -c < copy) || framework_failure_ + + od -An $file > exp || fail=1 + od -An -j $bytes $file $file > out || fail=1 + compare exp out || fail=1 + + od -An -j 4096 copy copy > exp1 2> experr1; expstatus=$? + od -An -j 4096 $file $file > out1 2> err1; status=$? + test $status -eq $expstatus || fail=1 + compare exp1 out1 || fail=1 + compare experr1 err1 || fail=1 +done + +Exit $fail diff --git a/tests/misc/od-multiple-t.sh b/tests/misc/od-multiple-t.sh new file mode 100755 index 0000000..2bfc6b3 --- /dev/null +++ b/tests/misc/od-multiple-t.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# verify that multiple -t specifiers to od align well +# This would fail before coreutils-6.13. + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ od + +# Choose 48 bytes for the input, as that is lcm for 1, 2, 4, 8, 12, 16; +# we don't anticipate any other native object size on modern hardware. +seq 19 > in || framework_failure_ +test $(wc -c < in) -eq 48 || framework_failure_ + + +list='a c dC dS dI dL oC oS oI oL uC uS uI uL xC xS xI xL fF fD fL' +for format1 in $list; do + for format2 in $list; do + od -An -t${format1}z -t${format2}z in > out-raw || fail=1 + linewidth=$(head -n1 out-raw | wc -c) + linecount=$(wc -l < out-raw) + echo $format1 $format2 $(wc -c < out-raw) >> out + echo $format1 $format2 $(expr $linewidth '*' $linecount) >> exp + done +done + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/od-x8.sh b/tests/misc/od-x8.sh new file mode 100755 index 0000000..4fcbee7 --- /dev/null +++ b/tests/misc/od-x8.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# verify that od -t x8 works properly +# This would fail before coreutils-4.5.2. + +# Copyright (C) 2002-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ od + +od -t x8 /dev/null >/dev/null || + skip_ "od lacks support for 8-byte quantities" + +echo abcdefgh |tr -d '\n' > in || framework_failure_ + + +od -An -t x8 in > out-raw || fail=1 +sed 's/^ //;s/\(..\)/\1 /g;s/ $//' out-raw \ + | tr ' ' '\n' \ + | sort -n \ + > out + +od -An -t x1 in \ + | sed 's/^ //' \ + | tr ' ' '\n' \ + | sort -n \ + > exp + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/od.pl b/tests/misc/od.pl new file mode 100755 index 0000000..0ef1dc7 --- /dev/null +++ b/tests/misc/od.pl @@ -0,0 +1,74 @@ +#!/usr/bin/perl +# Exercise od + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@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 = <FH>)) + { + $len += length $line; + } +close FH; +my $proc_file_byte_count = $len; + +my @Tests = + ( + # Skip the exact length of the input file. + # Up to coreutils-6.9, this would ignore the "-j 1". + ['j-bug1', '-c -j 1 -An', {IN=>{g=>'a'}}, {OUT=>''}], + ['j-bug2', '-c -j 2 -An', {IN=>{g=>'a'}}, {IN=>{h=>'b'}}, {OUT=>''}], + # Skip the sum of the lengths of the first three inputs. + ['j-bug3', '-c -j 3 -An', {IN=>{g=>'a'}}, {IN=>{h=>'b'}}, + {IN=>{i=>'c'}}, {OUT=>''}], + # 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"}], + + # Ensure that a large width does not cause trouble. + # From coreutils-7.0 through coreutils-8.21, these would print + # approximately 128KiB of padding. + ['wide-a', '-a -w65537 -An', {IN=>{g=>'x'}}, {OUT=>" x\n"}], + ['wide-c', '-c -w65537 -An', {IN=>{g=>'x'}}, {OUT=>" x\n"}], + ['wide-x', '-tx1 -w65537 -An', {IN=>{g=>'B'}}, {OUT=>" 42\n"}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'od'; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/paste.pl b/tests/misc/paste.pl new file mode 100755 index 0000000..9e65cbc --- /dev/null +++ b/tests/misc/paste.pl @@ -0,0 +1,74 @@ +#!/usr/bin/perl +# Test paste. + +# Copyright (C) 2003-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $prog = 'paste'; +my $msg = "$prog: delimiter list ends with an unescaped backslash: "; + +my @Tests = + ( + # Ensure that paste properly handles files lacking a final newline. + ['no-nl-1', {IN=>"a"}, {IN=>"b"}, {OUT=>"a\tb\n"}], + ['no-nl-2', {IN=>"a\n"}, {IN=>"b"}, {OUT=>"a\tb\n"}], + ['no-nl-3', {IN=>"a"}, {IN=>"b\n"}, {OUT=>"a\tb\n"}], + ['no-nl-4', {IN=>"a\n"}, {IN=>"b\n"}, {OUT=>"a\tb\n"}], + + ['zno-nl-1', '-z', {IN=>"a"}, {IN=>"b"}, {OUT=>"a\tb\0"}], + ['zno-nl-2', '-z', {IN=>"a\0"}, {IN=>"b"}, {OUT=>"a\tb\0"}], + ['zno-nl-3', '-z', {IN=>"a"}, {IN=>"b\0"}, {OUT=>"a\tb\0"}], + ['zno-nl-4', '-z', {IN=>"a\0"}, {IN=>"b\0"}, {OUT=>"a\tb\0"}], + + # Same as above, but with a two lines in each input file and + # the addition of the -d option to make SPACE be the output delimiter. + ['no-nla1', '-d" "', {IN=>"1\na"}, {IN=>"2\nb"}, {OUT=>"1 2\na b\n"}], + ['no-nla2', '-d" "', {IN=>"1\na\n"}, {IN=>"2\nb"}, {OUT=>"1 2\na b\n"}], + ['no-nla3', '-d" "', {IN=>"1\na"}, {IN=>"2\nb\n"}, {OUT=>"1 2\na b\n"}], + ['no-nla4', '-d" "', {IN=>"1\na\n"}, {IN=>"2\nb\n"}, {OUT=>"1 2\na b\n"}], + + ['zno-nla1', '-zd" "', {IN=>"1\0a"}, {IN=>"2\0b"}, {OUT=>"1 2\0a b\0"}], + ['zno-nla2', '-zd" "', {IN=>"1\0a\0"}, {IN=>"2\0b"}, {OUT=>"1 2\0a b\0"}], + ['zno-nla3', '-zd" "', {IN=>"1\0a"}, {IN=>"2\0b\0"}, {OUT=>"1 2\0a b\0"}], + ['zno-nla4', '-zd" "', {IN=>"1\0a\0"}, {IN=>"2\0b\0"}, {OUT=>"1 2\0a b\0"}], + + # Specifying a delimiter with a trailing backslash would overrun a + # malloc'd buffer. + ['delim-bs1', q!-d'\'!, {IN=>{'a'x50=>''}}, {EXIT => 1}, + # We print a single backslash into the expected output + {ERR => $msg . q!\\! . "\n"} ], + + # Prior to coreutils-5.1.2, this sort of abuse would make paste + # scribble on command-line arguments. With paste from coreutils-5.1.0, + # this example would mangle the first file name argument, if it contains + # accepted backslash-escapes: + # $ paste -d\\ '123\b\b\b.....@' 2>&1 |cat -A + # paste: 23^H^H^H.....@...@: No such file or directory$ + ['delim-bs2', q!-d'\'!, {IN=>{'123\b\b\b.....@'=>''}}, {EXIT => 1}, + {ERR => $msg . q!\\! . "\n"} ], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/pathchk1.sh b/tests/misc/pathchk1.sh new file mode 100755 index 0000000..93403b6 --- /dev/null +++ b/tests/misc/pathchk1.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# pathchk tests + +# Copyright (C) 2002-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ pathchk +skip_if_root_ + +touch file || framework_failure_ + + +# This should exit nonzero. Before 2.0.13, it gave a diagnostic, +# but exited successfully. +returns_ 1 pathchk file/x > /dev/null 2>&1 || fail=1 + +# This should exit nonzero. Through 5.3.0 it exited with status zero. +returns_ 1 pathchk -p '' > /dev/null 2>&1 || fail=1 + +# This tests the new -P option. +returns_ 1 pathchk -P '' > /dev/null 2>&1 || fail=1 +returns_ 1 pathchk -P -- - > /dev/null 2>&1 || fail=1 +returns_ 1 pathchk -p -P x/- > /dev/null 2>&1 || fail=1 + +Exit $fail diff --git a/tests/misc/printenv.sh b/tests/misc/printenv.sh new file mode 100755 index 0000000..6cee5e7 --- /dev/null +++ b/tests/misc/printenv.sh @@ -0,0 +1,83 @@ +#!/bin/sh +# Verify behavior of printenv. + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ printenv + +# Without arguments, printenv behaves like env. Some shells provide +# printenv as a builtin, so we must invoke it via "env". +# But beware of $_, set by many shells to the last command run. +# Also, filter out LD_PRELOAD, which is set when running under valgrind. +# Note the apparently redundant "env env": this is to ensure to get +# env's output the same way as that of printenv and works around a bug +# on aarch64 at least where libc's execvp reverses the order of the +# output. +env -- env | grep -Ev '^(_|LD_PRELOAD)=' > exp || framework_failure_ +env -- printenv | grep -Ev '^(_|LD_PRELOAD)=' > out || fail=1 +compare exp out || fail=1 + +# POSIX is clear that environ may, but need not be, sorted. +# Environment variable values may contain newlines, which cannot be +# observed by merely inspecting output from printenv. +if env -- printenv | grep '^ENV_TEST' >/dev/null ; then + skip_ "environment has potential interference from ENV_TEST*" +fi + +# Printing a single variable's value. +returns_ 1 env -- printenv ENV_TEST > out || fail=1 +compare /dev/null out || fail=1 +echo a > exp || framework_failure_ +ENV_TEST=a env -- printenv ENV_TEST > out || fail=1 +compare exp out || fail=1 + +# Printing multiple variables. Order follows command line. +ENV_TEST1=a ENV_TEST2=b env -- printenv ENV_TEST2 ENV_TEST1 ENV_TEST2 > out \ + || fail=1 +ENV_TEST1=a ENV_TEST2=b env -- printenv ENV_TEST1 ENV_TEST2 >> out || fail=1 +cat <<EOF > exp || framework_failure_ +b +a +b +a +b +EOF +compare exp out || fail=1 + +# Exit status reflects missing variable, but remaining arguments processed. +export ENV_TEST1=a +returns_ 1 env -- printenv ENV_TEST2 ENV_TEST1 > out || fail=1 +returns_ 1 env -- printenv ENV_TEST1 ENV_TEST2 >> out || fail=1 +unset ENV_TEST1 +cat <<EOF > exp || framework_failure_ +a +a +EOF +compare exp out || fail=1 + +# Non-standard environment variable name. Shells won't create it, but +# env can, and printenv must be able to deal with it. +echo b > exp || framework_failure_ +env -- -a=b printenv -- -a > out || fail=1 +compare exp out || fail=1 + +# Silently reject invalid env-var names. +# Bug present through coreutils 8.0. +returns_ 1 env a=b=c printenv a=b > out || fail=1 +compare /dev/null out || fail=1 + +Exit $fail diff --git a/tests/misc/printf-cov.pl b/tests/misc/printf-cov.pl new file mode 100755 index 0000000..ab6bd15 --- /dev/null +++ b/tests/misc/printf-cov.pl @@ -0,0 +1,101 @@ +#!/usr/bin/perl +# improve printf.c test coverage + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $prog = 'printf'; +my $try = "Try '$prog --help' for more information.\n"; +my $pow_2_31 = 2**31; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = +( + ['no-args', {EXIT=>1}, {ERR=>"$prog: missing operand\n$try"}], + ['no-arg2', '--', {EXIT=>1}, {ERR=>"$prog: missing operand\n$try"}], + ['escape-1', q('\a\b\f\n\r\t\v\z\c'), {OUT=>"\a\b\f\n\r\t\x0b\\z"}], + ['hex-ucX', '%X 999', {OUT=>"3E7"}], + ['hex-ucXw', '%4X 999', {OUT=>" 3E7"}], + ['hex-ucXp', '%.4X 999', {OUT=>"03E7"}], + ['hex-ucXwp', '%5.4X 999', {OUT=>" 03E7"}], + ['hex-vw', '%*X 4 42', {OUT=>" 2A"}], + ['hex-vp', '%.*X 4 42', {OUT=>"002A"}], + ['hex-vwvp', '%*.*X 3 2 15', {OUT=>" 0F"}], + ['b', q('nl\ntab\tx'), {OUT=>"nl\ntab\tx"}], + ['c1', '%c 123', {OUT=>"1"}], + ['cw', '%\*c 3 123', {OUT=>" 1"}], + ['d-ucXwp', '%5.4d 999', {OUT=>" 0999"}], + ['d-vw', '%*d 4 42', {OUT=>" 42"}], + ['d-vp', '%.*d 4 42', {OUT=>"0042"}], + ['d-vwvp', '%*.*d 3 2 15', {OUT=>" 15"}], + ['d-neg-prec', '%.*d -3 15', {OUT=>"15"}], + ['d-big-prec', "%.*d $pow_2_31 15", # INT_MAX + {EXIT=>1}, {ERR=>"$prog: invalid precision: '$pow_2_31'\n"}], + ['d-big-fwidth', "%*d $pow_2_31 15", # INT_MAX + {EXIT=>1}, {ERR=>"$prog: invalid field width: '$pow_2_31'\n"}], + ['F', '%F 1', {OUT=>"1.000000"}], + ['LF', '%LF 1', {OUT=>"1.000000"}], + ['E', '%E 2', {OUT=>"2.000000E+00"}], + ['LE', '%LE 2', {OUT=>"2.000000E+00"}], + ['s', '%s x', {OUT=>"x"}], + ['sw', '%\*s 2 x', {OUT=>" x"}], + ['sp', '%.\*s 2 abcd', {OUT=>"ab"}], + ['swp', '%\*.\*s 2 2 abcd', {OUT=>"ab"}], + ['sw-no-args', '%\*s'], + ['sw-no-args2', '%.\*s'], + ['G-ucXwp', '%5.4G 3', {OUT=>" 3"}], + ['G-vw', '%*G 4 42', {OUT=>" 42"}], + ['G-vp', '%.*G 4 42', {OUT=>"42"}], + ['G-vwvp', '%*.*G 5 3 15', {OUT=>" 15"}], + ['esc', q('\xaa\0377'), {OUT=>"\xaa\0377"}], + ['esc-bad-hex', q('\x'), {EXIT=>1}, + {ERR=>"$prog: missing hexadecimal number in escape\n"}], + # ['u4', q('\u09ac'), {OUT=>"\xe0a6ac"}], + ['u-invalid', q('\u0000'), {EXIT=>1}, + {ERR=>"$prog: invalid universal character name \\u0000\n"}], + ['u-missing', q('\u'), {EXIT=>1}, + {ERR=>"$prog: missing hexadecimal number in escape\n"}], + ['d-invalid', '%d no-num', {OUT=>'0'}, {EXIT=>1}, + # Depending on the strtol implementation we expect one of these: + # no-num: Invalid argument (FreeBSD6) + # no-num: expected a numeric value (glibc, Solaris 10) + {ERR_SUBST => 's/Invalid argument$/expected a numeric value/'}, + {ERR=>"$prog: 'no-num': expected a numeric value\n"}], + ['d-bad-suffix', '%d 9z', {OUT=>'9'}, {EXIT=>1}, + {ERR=>"$prog: '9z': value not completely converted\n"}], + ['d-out-of-range', '%d '.('9'x30), {EXIT=>1}, + {OUT=>"inaccurate"}, {OUT_SUBST => 's/\d+/inaccurate/'}, + {ERR=>"$prog: 9...9\n"}, {ERR_SUBST => "s/'9+.*/9...9/"}], + ['excess', 'B 1', {OUT=>'B'}, + {ERR=>"$prog: warning: ignoring excess arguments, starting with '1'\n"}], + ['percent', '%%', {OUT=>'%'}], + ['d-sp', q('% d' 33), {OUT=>' 33'}], + ['d-plus', q('%+d' 33), {OUT=>'+33'}], + ['d-minus', q('%-d' 33), {OUT=> '33'}], + ['d-zero', q('%02d' 1), {OUT=> '01'}], + ['d-quote', q("%'d" 3333), {OUT=> '3333'}, {OUT_SUBST => 'tr/3//c'}], + ['d-hash', q("%#d" 3333), {EXIT=>1}, + {ERR=>"$prog: %#d: invalid conversion specification\n"}], +); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, \$prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/printf-hex.sh b/tests/misc/printf-hex.sh new file mode 100755 index 0000000..6e76ad1 --- /dev/null +++ b/tests/misc/printf-hex.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# make sure that only two hex. digits are consumed in a \xHHH sequence + +# Copyright (C) 2002-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ printf + +env printf '\x7e3\n' > out || fail=1 +cat <<\EOF > exp +~3 +EOF + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/printf-mb.sh b/tests/misc/printf-mb.sh new file mode 100755 index 0000000..f2f32c8 --- /dev/null +++ b/tests/misc/printf-mb.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# tests for printing multi-byte values of characters + +# Copyright (C) 2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ printf + +prog='env printf' + +unset LC_ALL +f=$LOCALE_FR_UTF8 +: ${LOCALE_FR_UTF8=none} +if test "$LOCALE_FR_UTF8" != "none"; then + ( + #valid multi-byte + LC_ALL=$f $prog '%04x\n' '"á' >>out 2>>err + #invalid multi-byte + LC_ALL=$f $prog '%04x\n' "'$($prog '\xe1')" >>out 2>>err + #uni-byte + LC_ALL=C $prog '%04x\n' "'$($prog '\xe1')" >>out 2>>err + #valid multi-byte, with trailing + LC_ALL=$f $prog '%04x\n' '"á=' >>out 2>>err + #invalid multi-byte, with trailing + LC_ALL=$f $prog '%04x\n' "'$($prog '\xe1')=" >>out 2>>err + ) + cat <<\EOF > exp || framework_failure_ +00e1 +00e1 +00e1 +00e1 +00e1 +EOF + compare exp out || fail=1 + + # Disparate LC_CTYPE and LC_MESSAGES problematic on macos, + # so just look for character in warning message, + # and normalize to LC_MESSAGES=C + C_WARNING='printf: '\ +'warning: =: character(s) following character constant have been ignored' + + sed "s/printf:.*=.*/$C_WARNING/" < err > c_err || framework_failure_ + + cat <<EOF > exp_err +$C_WARNING +$C_WARNING +EOF + compare exp_err c_err || fail=1 +fi + +Exit $fail diff --git a/tests/misc/printf-quote.sh b/tests/misc/printf-quote.sh new file mode 100755 index 0000000..f396001 --- /dev/null +++ b/tests/misc/printf-quote.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# tests for printf %q + +# Copyright (C) 2015-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ printf + +prog='env printf' + +# Equivalent output to ls --quoting=shell-escape +$prog '%q\n' '' "'" a 'a b' '~a' 'a~' "$($prog %b 'a\r')" > out +cat <<\EOF > exp || framework_failure_ +'' +"'" +a +'a b' +'~a' +a~ +'a'$'\r' +EOF +compare exp out || fail=1 + +unset LC_ALL +f=$LOCALE_FR_UTF8 +: ${LOCALE_FR_UTF8=none} +if test "$LOCALE_FR_UTF8" != "none"; then + ( + #printable multi-byte + LC_ALL=$f $prog '%q\n' 'áḃç' > out + #non-printable multi-byte + LC_ALL=$f $prog '%q\n' "$($prog '\xc2\x81')" >> out + #printable multi-byte in C locale + LC_ALL=C $prog '%q\n' 'áḃç' >> out + ) + cat <<\EOF > exp || framework_failure_ +áḃç +''$'\302\201' +''$'\303\241\341\270\203\303\247' +EOF + compare exp out || fail=1 +fi + +Exit $fail diff --git a/tests/misc/printf-surprise.sh b/tests/misc/printf-surprise.sh new file mode 100755 index 0000000..480f6b9 --- /dev/null +++ b/tests/misc/printf-surprise.sh @@ -0,0 +1,98 @@ +#!/bin/sh +# Detect printf(3) failure even when it doesn't set stream error indicator + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +prog=printf + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ printf + +vm=$(get_min_ulimit_v_ env $prog %20f 0) \ + || skip_ "this shell lacks ulimit support" + +# Up to coreutils-6.9, "printf %.Nf 0" would encounter an ENOMEM internal +# error from glibc's printf(3) function whenever N was large relative to +# the size of available memory. As of Oct 2007, that internal stream- +# related failure was not reflected (for any libc I know of) in the usual +# stream error indicator that is tested by ferror. The result was that +# while the printf command obviously failed (generated no output), +# it mistakenly exited successfully (exit status of 0). + +# Testing it is tricky, because there is so much variance +# in quality for this corner of printf(3) implementations. +# Most implementations do attempt to allocate N bytes of storage. +# Using the maximum value for N (2^31-1) causes glibc-2.7 to try to +# allocate almost 2^64 bytes, while freeBSD 6.1's implementation +# correctly outputs almost 2GB worth of 0's, which takes too long. +# We want to test implementations that allocate N bytes, but without +# triggering the above extremes. + +# Some other versions of glibc-2.7 have a snprintf function that segfaults +# when an internal (technically unnecessary!) memory allocation fails. + +# The compromise is to limit virtual memory to something reasonable, +# and to make an N-byte-allocating-printf require more than that, thus +# triggering the printf(3) misbehavior -- which, btw, is required by ISO C99. + +mkfifo_or_skip_ fifo +trap_sigpipe_or_skip_ + +# Disable MALLOC_PERTURB_, to avoid triggering this bug +# https://bugs.debian.org/481543#77 +export MALLOC_PERTURB_=0 + +# Terminate any background process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +head -c 10 fifo > out & pid=$! + +# Trigger large mem allocation failure +( trap '' PIPE && ulimit -v $vm && env $prog %20000000f 0 2>err-msg > fifo ) +exit=$? + +# Map this longer, and rarer, diagnostic to the common one. +# printf: cannot perform formatted output: Cannot allocate memory" +sed 's/cannot perform .*/write error/' err-msg > k && mv k err-msg +err_msg=$(tr '\n' : < err-msg) + +# By some bug, on Solaris 11 (5.11 snv_86), err_msg ends up +# containing '1> fifo:printf: write error:'. Recognize that, too. + +case $err_msg in + "$prog: write error:"*) diagnostic=y ;; + "1> fifo:$prog: write error:") diagnostic=y ;; + '') diagnostic=n ;; + *) diagnostic=unexpected ;; +esac +n_out=$(wc -c < out) + +case $n_out:$diagnostic:$exit in + 10:n:0) ;; # ok, succeeds w/no diagnostic: FreeBSD 6.1 + 10:y:1) ;; # ok, fails with EPIPE diagnostic: musl libc + 0:y:1) ;; # ok, glibc-2.8 and newer, when printf(3) fails with ENOMEM + + # With MALLOC_PERTURB_=0, this no longer happens. + # *:139) # segfault; known bug at least in debian unstable's libc6 2.7-11 + # echo 1>&2 "$0: bug in snprintf causes low-mem use of printf to segfault" + # fail=77;; + + # 10:y) ;; # Fail: doesn't happen: nobody succeeds with a diagnostic + # 0:n) ;; # Fail pre-patch: no output, no diag + *) fail=1;; +esac + +Exit $fail diff --git a/tests/misc/printf.sh b/tests/misc/printf.sh new file mode 100755 index 0000000..797fed6 --- /dev/null +++ b/tests/misc/printf.sh @@ -0,0 +1,128 @@ +#!/bin/sh +# basic tests for printf + +# Copyright (C) 2002-2022 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 <https://www.gnu.org/licenses/>. + +prog='env printf' + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ printf + +getlimits_ + + +# Verify the 3 methods of specifying "Escape": +printf '%s\n' . . . | tr . '\033' > exp +$prog '\x1b\n\33\n\e\n' > out || fail=1 +compare exp out || fail=1 + +# This would fail (by printing the '--') for printf in sh-utils +# and in coreutils 4.5.1. +$prog -- 'foo\n' > out || fail=1 +cat <<\EOF > exp +foo +EOF + +compare exp out || fail=1 + +rm -f out exp +# Until coreutils-4.5.10, this would elicit a segfault. +$prog '1 %*sy\n' -3 x > out || fail=1 + +# Until coreutils 5.2.2, this would succeed. +if POSIXLY_CORRECT=1 $prog '2 \x' >/dev/null 2>&1; then + fail=1 +else + echo '2 failed, as expected' >> out +fi + +# Until coreutils-4.5.12, these would fail. +$prog '3 \x40\n' >> out || fail=1 +POSIXLY_CORRECT=1 \ +$prog '4 \x40\n' >> out || fail=1 +$prog '5 % +d\n' 234 >> out || fail=1 + +# This should print "6 !\n", but don't rely on '!' being the +# one-byte representation of octal 041. With printf prior to +# coreutils-5.0.1, it would print six bytes: "6 \41\n". +$prog '6 \41\n' | tr '\41' '!' >> out + +# Note that as of coreutils-5.0.1, printf with a format of '\0002y' +# prints a NUL byte followed by the digit '2' and a 'y'. +$prog '7 \2y \02y \002y \0002y\n' |tr '\0\2' '*=' >> out + +$prog '8 %b %b %b %b\n' '\1y' '\01y' '\001y' '\0001y'|tr '\1' = >> out + +$prog '9 %*dx\n' -2 0 >>out || fail=1 + +$prog '10 %.*dx\n' $INT_UFLOW 0 >>out || fail=1 +returns_ 1 $prog '%.*dx\n' $INT_OFLOW 0 >>out 2> /dev/null || fail=1 + +$prog '11 %*c\n' 2 x >>out || fail=1 + +returns_ 1 $prog '%#d\n' 0 >>out 2> /dev/null || fail=1 + +returns_ 1 $prog '%0s\n' 0 >>out 2> /dev/null || fail=1 + +returns_ 1 $prog '%.9c\n' 0 >>out 2> /dev/null || fail=1 + +returns_ 1 $prog '%'\''s\n' 0 >>out 2> /dev/null || fail=1 + +cat <<\EOF > exp +1 x y +2 failed, as expected +3 @ +4 @ +5 +234 +6 ! +7 =y =y =y *2y +8 =y =y =y =y +9 0 x +10 0x +11 x +EOF + +compare exp out || fail=1 + +# Verify handling of single quote chars (\' or \") + +$prog '%d\n' '"a' >out 2>err # valid +$prog '%d\n' '"a"' >>out 2>>err # invalid +$prog '%d\n' '"' >>out 2>>err # invalid +$prog '%d\n' 'a' >>out 2>>err # invalid + +cat <<EOF > exp +97 +97 +0 +0 +EOF + +# POSIX says strtoimax *may* set errno to EINVAL in the latter +# two cases. So far, that happens at least on MacOS X 10.5. +# Map that output to the more common expected output. +sed 's/: Invalid.*/: expected a numeric value/' err > k && mv k err + +cat <<EOF > exp_err +printf: warning: ": character(s) following character constant have been ignored +printf: '"': expected a numeric value +printf: 'a': expected a numeric value +EOF + +compare exp out || fail=1 +compare exp_err err || fail=1 + +Exit $fail diff --git a/tests/misc/ptx-overrun.sh b/tests/misc/ptx-overrun.sh new file mode 100755 index 0000000..a616bb1 --- /dev/null +++ b/tests/misc/ptx-overrun.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ ptx + +# Trigger a heap-clobbering bug in ptx from coreutils-6.10 and earlier. +# Using a long file name makes an abort more likely. +# Even with no file name, valgrind detects the buffer overrun. +f=01234567890123456789012345678901234567890123456789 +touch $f empty || framework_failure_ + +# Specifying a regular expression ending in a lone backslash +# would cause ptx to write beyond the end of a malloc'd buffer. +ptx -F '\' $f < /dev/null > out || fail=1 +ptx -S 'foo\' $f < /dev/null >> out || fail=1 +ptx -W 'bar\\\' $f < /dev/null >> out || fail=1 +compare out empty || fail=1 + + +# Trigger an invalid heap reference noticed by gcc -fsanitize=address +# from coreutils-8.22 and earlier. As well as an invalid memory reference, +# the issue can be seen in the output, with non deterministice whitespace +# trimming when multiple files are specified. +printf '%s\n' 'This is a ptx whitespace Trimming test' > ws.in +ptx ws.in ws.in | sort | uniq -u > out +compare /dev/null out || fail=1 + + +# Trigger an invalid heap reference noticed by gcc -fsanitize=address +# from coreutils-8.25 and earlier. +echo a > a +ptx -w1 -A "$PWD/a" >/dev/null || fail=1 + +Exit $fail diff --git a/tests/misc/ptx.pl b/tests/misc/ptx.pl new file mode 100755 index 0000000..2feec87 --- /dev/null +++ b/tests/misc/ptx.pl @@ -0,0 +1,57 @@ +#!/usr/bin/perl + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $prog = 'ptx'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = +( +["1tok", '-w10', {IN=>"bar\n"}, {OUT=>" bar\n"}], +["2tok", '-w10', {IN=>"foo bar\n"}, {OUT=>" / bar\n foo/\n"}], + +# with coreutils-6.12 and earlier, this would infloop with -wN, N < 10 +["narrow", '-w2', {IN=>"qux\n"}, {OUT=>" qux\n"}], +["narrow-g", '-g1 -w2', {IN=>"ta\n"}, {OUT=>" ta\n"}], + +# with coreutils-6.12 and earlier, this would act like "ptx F1 F1" +["2files", '-g1 -w1', {IN=>{F1=>"a"}}, {IN=>{F2=>"b"}}, {OUT=>" a\n b\n"}], + +# with coreutils-8.22 and earlier, the --format long option would +# fall through into the --help case. +["format-r", '--format=roff', {IN=>"foo\n"}, + {OUT=>".xx \"\" \"\" \"foo\" \"\"\n"}], +["format-t", '--format=tex', {IN=>"foo\n"}, + {OUT=>"\\xx {}{}{foo}{}{}\n"}], + +# with coreutils-8.28 and earlier, the -S option would infloop with +# matches of zero-length. +["S-infloop", '-S \^', {IN=>"a\n"}, {EXIT=>1}, + {ERR_SUBST=>'s/^.*reg.*ex.*length zero.*$/regexlzero/'}, + {ERR=>"regexlzero\n"}], +); + +@Tests = triple_test \@Tests; + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/pwd-long.sh b/tests/misc/pwd-long.sh new file mode 100755 index 0000000..34a3b54 --- /dev/null +++ b/tests/misc/pwd-long.sh @@ -0,0 +1,123 @@ +#!/bin/sh +# -*- perl -*- +# Ensure that pwd works even when run from a very deep directory. + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ pwd + +require_readable_root_ +require_perl_ + +ARGV_0=$0 +export ARGV_0 + +# Don't use CuTmpdir here, since File::Temp's use of rmtree can't +# remove the deep tree we create. +$PERL -Tw -I"$abs_srcdir/tests" -MCuSkip -- - <<\EOF + +# Show that pwd works even when the length of the resulting +# directory name is longer than PATH_MAX. +use strict; + +(my $ME = $ENV{ARGV_0}) =~ s|.*/||; + +sub normalize_to_cwd_relative ($$$) +{ + my ($dir, $dev, $ino) = @_; + my $slash = -1; + my $next_slash; + while (1) + { + $slash = index $dir, '/', $slash + 1; + $slash <= -1 + and die "$ME: $dir does not contain old CWD\n"; + my $dir_prefix = $slash ? substr ($dir, 0, $slash) : '/'; + my ($d, $i) = (stat $dir_prefix)[0, 1]; + defined $d && defined $i + or die "$ME: $dir_prefix: stat failed: $!\n"; + $d eq $dev && $i eq $ino + and return substr $dir, $slash + 1; + } +} + +# Set up a safe, well-known environment +$ENV{IFS} = ''; + +# Taint checking requires a sanitized $PATH. This script performs no $PATH +# search, so on most Unix-based systems, it is fine simply to clear $ENV{PATH}. +# However, on Cygwin, it's used to find cygwin1.dll, so set it. +$ENV{PATH} = '/bin:/usr/bin'; + +# Save CWD's device and inode numbers. +my ($dev, $ino) = (stat '.')[0, 1]; + +# Construct the expected "."-relative part of pwd's output. +my $z = 'z' x 31; +my $n = 256; +my $expected = "/$z" x $n; +# Remove the leading "/". +substr ($expected, 0, 1) = ''; + +my $i = 0; +do + { + mkdir $z, 0700 + or CuSkip::skip "$ME: skipping this test; cannot create long " + . "directory name at depth $i: $!\n"; + chdir $z + } +until (++$i == $n); + +my $abs_top_builddir = $ENV{abs_top_builddir}; +$abs_top_builddir + or die "$ME: envvar abs_top_builddir not defined\n"; +my $build_src_dir = "$abs_top_builddir/src"; +$build_src_dir =~ m!^([-+.:/\w]+)$! + or CuSkip::skip "$ME: skipping this test; odd build source directory name:\n" + . "$build_src_dir\n"; +$build_src_dir = $1; + +my $pwd_binary = "$build_src_dir/pwd"; + +-x $pwd_binary + or die "$ME: $pwd_binary is not an executable file\n"; +chomp (my $actual = qx!$pwd_binary!); + +# Convert the absolute name from pwd into a $CWD-relative name. +# This is necessary in order to avoid a spurious failure when run +# from a directory in a bind-mounted partition. What happens is +# pwd reads a ".." that contains two or more entries with identical +# dev,ino that match the ones we're looking for, and it chooses a +# name that does not correspond to the one already recorded in $CWD. +$actual = normalize_to_cwd_relative $actual, $dev, $ino; + +if ($expected ne $actual) + { + my $e_len = length $expected; + my $a_len = length $actual; + warn "expected len: $e_len\n"; + warn "actual len: $a_len\n"; + warn "expected: $expected\n"; + warn "actual: $actual\n"; + exit 1; + } +EOF + +fail=$? + +Exit $fail diff --git a/tests/misc/pwd-option.sh b/tests/misc/pwd-option.sh new file mode 100755 index 0000000..fdcf675 --- /dev/null +++ b/tests/misc/pwd-option.sh @@ -0,0 +1,62 @@ +#!/bin/sh +# Ensure that pwd options work. + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ pwd + +mkdir -p a/b || framework_failure_ +ln -s a/b c || framework_failure_ +base=$(env -- pwd -P) + +# Remove any logical paths from $PWD. +cd "$base" || framework_failure_ +test "x$PWD" = "x$base" || framework_failure_ + +# Enter a logical directory. +cd c || framework_failure_ +test "x$PWD" = "x$base/c" || skip_ "cd does not properly update \$PWD" + +env -- pwd -L > out || fail=1 +printf %s\\n "$base/c" > exp || fail=1 + +env -- pwd --logical -P >> out || fail=1 +printf %s\\n "$base/a/b" >> exp || fail=1 + +env -- pwd --physical >> out || fail=1 +printf %s\\n "$base/a/b" >> exp || fail=1 + +# By default, we use -P unless POSIXLY_CORRECT. +env -- pwd >> out || fail=1 +printf %s\\n "$base/a/b" >> exp || fail=1 + +env -- POSIXLY_CORRECT=1 pwd >> out || fail=1 +printf %s\\n "$base/c" >> exp || fail=1 + +# Make sure we reject bogus values, and silently fall back to -P. +env -- PWD="$PWD/." pwd -L >> out || fail=1 +printf %s\\n "$base/a/b" >> exp || fail=1 + +env -- PWD=bogus pwd -L >> out || fail=1 +printf %s\\n "$base/a/b" >> exp || fail=1 + +env -- PWD="$base/a/../c" pwd -L >> out || fail=1 +printf %s\\n "$base/a/b" >> exp || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/readlink-fp-loop.sh b/tests/misc/readlink-fp-loop.sh new file mode 100755 index 0000000..a8e8430 --- /dev/null +++ b/tests/misc/readlink-fp-loop.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# readlink from 6.9 would fail with a false-positive symlink loop error + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ readlink pwd +cwd=$(env pwd -P) + +# To trigger this bug, we have to construct a name/situation during +# the resolution of which the code dereferences the same symlink (S) +# two different times with no actual loop. In addition, arrange +# so that the second and fourth calls to readlink operate on S. + +ln -s s p || framework_failure_ +ln -s d s || framework_failure_ +mkdir d || framework_failure_ +echo 2 > d/2 || framework_failure_ +ln -s ../s/2 d/1 || framework_failure_ + +# With coreutils-6.9, this would fail with ELOOP. +readlink -v -e p/1 > out || fail=1 +# readlink -e d/2 > exp || fail=1 +echo "$cwd/d/2" > exp || framework_failure_ +compare exp out || fail=1 + +# Construct a real loop and make sure readlink still detects it. +ln -sf ../s/1 d/2 || framework_failure_ +readlink -v -e p/1 2> out && fail=1 +readlink_msg=$(cat out) +case $readlink_msg in + "readlink: p/1: "*) ;; + *) fail=1;; +esac +symlink_loop_msg=${readlink_msg#"readlink: p/1: "} + +# Exercise the hash table code. +ln -nsf ../s/3 d/2 || framework_failure_ +ln -nsf ../p/4 d/3 || framework_failure_ +ln -nsf ../p/5 d/4 || framework_failure_ +ln -nsf ../p/6 d/5 || framework_failure_ +ln -nsf ../p/7 d/6 || framework_failure_ +ln -nsf ../p/8 d/7 || framework_failure_ +echo x > d/8 || framework_failure_ +readlink -v -e p/1 > out || fail=1 +echo "$cwd/d/8" > exp || framework_failure_ +compare exp out || fail=1 + +# A trivial loop +ln -s loop loop +readlink -v -e loop 2> out && fail=1 +echo "readlink: loop: $symlink_loop_msg" > exp || framework_failure_ +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/readlink-root.sh b/tests/misc/readlink-root.sh new file mode 100755 index 0000000..1e79125 --- /dev/null +++ b/tests/misc/readlink-root.sh @@ -0,0 +1,92 @@ +#!/bin/sh +# tests for canonicalize-existing mode (readlink -e) on /. + +# Copyright (C) 2012-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ readlink + +stat_single=$(stat -c %d:%i /) || framework_failure_ +stat_double=$(stat -c %d:%i //) || framework_failure_ +double_slash=// +if test x"$stat_single" = x"$stat_double"; then + double_slash=/ +fi + +test -d /dev || framework_failure_ + +ln -s / one || framework_failure_ +ln -s // two || framework_failure_ +ln -s /// three || framework_failure_ +ln -s /./..// one-dots || framework_failure_ +ln -s //./..// two-dots || framework_failure_ +ln -s ///./..// three-dots || framework_failure_ +ln -s /dev one-dev || framework_failure_ +ln -s //dev two-dev || framework_failure_ +ln -s ///dev three-dev || framework_failure_ + +cat >exp <<EOF || framework_failure_ +/ +$double_slash +/ +/ +$double_slash +/ +/ +$double_slash +/ +/ +$double_slash +/ +/dev +${double_slash}dev +/dev +/dev +${double_slash}dev +/dev +/dev +${double_slash}dev +/dev +EOF + +{ + readlink -e / || fail=1 + readlink -e // || fail=1 + readlink -e /// || fail=1 + readlink -e /.//.. || fail=1 + readlink -e //.//.. || fail=1 + readlink -e ///.//.. || fail=1 + readlink -e one || fail=1 + readlink -e two || fail=1 + readlink -e three || fail=1 + readlink -e one-dots || fail=1 + readlink -e two-dots || fail=1 + readlink -e three-dots || fail=1 + readlink -e one-dev || fail=1 + # We know /dev exists, but cannot assume //dev exists + readlink -f two-dev || fail=1 + readlink -e three-dev || fail=1 + readlink -e one/dev || fail=1 + readlink -f two/dev || fail=1 + readlink -e three/dev || fail=1 + readlink -e one-dots/dev || fail=1 + readlink -f two-dots/dev || fail=1 + readlink -e three-dots/dev || fail=1 +} > out + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/realpath.sh b/tests/misc/realpath.sh new file mode 100755 index 0000000..a27a46b --- /dev/null +++ b/tests/misc/realpath.sh @@ -0,0 +1,111 @@ +#!/bin/sh +# Validate realpath operation + +# Copyright (C) 2011-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ realpath + +stat_single=$(stat -c %d:%i /) || framework_failure_ +stat_double=$(stat -c %d:%i //) || framework_failure_ +double_slash=// +if test x"$stat_single" = x"$stat_double"; then + double_slash=/ +fi +nl=' +' + +test -d /dev || framework_failure_ + +# Setup dir, file, symlink structure + +mkdir -p dir1/dir2 || framework_failure_ +ln -s dir1/dir2 ldir2 || framework_failure_ +touch dir1/f dir1/dir2/f || framework_failure_ +ln -s / one || framework_failure_ +ln -s // two || framework_failure_ +ln -s /// three || framework_failure_ + +# Basic operation +realpath -Pqz . >/dev/null || fail=1 +# Operand is required +returns_ 1 realpath >/dev/null || fail=1 +returns_ 1 realpath --relative-base . --relative-to . || fail=1 +returns_ 1 realpath --relative-base . || fail=1 + +# -e --relative-* require directories +returns_ 1 realpath -e --relative-to=dir1/f --relative-base=. . || fail=1 +realpath -e --relative-to=dir1/ --relative-base=. . || fail=1 + +# Note NUL params are unconditionally rejected by canonicalize_filename_mode +returns_ 1 realpath -m '' || fail=1 +returns_ 1 realpath --relative-base= --relative-to=. . || fail=1 + +# symlink resolution +this=$(realpath .) +test "$(realpath ldir2/..)" = "$this/dir1" || fail=1 +test "$(realpath -L ldir2/..)" = "$this" || fail=1 +test "$(realpath -s ldir2)" = "$this/ldir2" || fail=1 + +# relative string handling +test $(realpath -m --relative-to=prefix prefixed/1) = '../prefixed/1' || fail=1 +test $(realpath -m --relative-to=prefixed prefix/1) = '../prefix/1' || fail=1 +test $(realpath -m --relative-to=prefixed prefixed/1) = '1' || fail=1 + +# Ensure no redundant trailing '/' present, as was the case in v8.15 +test $(realpath -sm --relative-to=/usr /) = '..' || fail=1 +# Ensure no redundant leading '../' present, as was the case in v8.15 +test $(realpath -sm --relative-to=/ /usr) = 'usr' || fail=1 + +# Ensure --relative-base works +out=$(realpath -sm --relative-base=/usr --relative-to=/usr /tmp /usr) || fail=1 +test "$out" = "/tmp$nl." || fail=1 +out=$(realpath -sm --relative-base=/ --relative-to=/ / /usr) || fail=1 +test "$out" = ".${nl}usr" || fail=1 +# --relative-to defaults to the value of --relative-base +out=$(realpath -sm --relative-base=/usr /tmp /usr) || fail=1 +test "$out" = "/tmp$nl." || fail=1 +out=$(realpath -sm --relative-base=/ / /usr) || fail=1 +test "$out" = ".${nl}usr" || fail=1 +# For now, --relative-base must be a prefix of --relative-to, or all output +# will be absolute (compare to MacOS 'relpath -d dir start end'). +out=$(realpath -sm --relative-base=/usr/local --relative-to=/usr \ + /usr /usr/local) || fail=1 +test "$out" = "/usr${nl}/usr/local" || fail=1 + +# Ensure // is handled correctly. +test "$(realpath / // ///)" = "/$nl$double_slash$nl/" || fail=1 +test "$(realpath one two three)" = "/$nl$double_slash$nl/" || fail=1 +out=$(realpath -sm --relative-to=/ / // /dev //dev) || fail=1 +if test $double_slash = //; then + test "$out" = ".$nl//${nl}dev$nl//dev" || fail=1 +else + test "$out" = ".$nl.${nl}dev${nl}dev" || fail=1 +fi +out=$(realpath -sm --relative-to=// / // /dev //dev) || fail=1 +if test $double_slash = //; then + test "$out" = "/$nl.$nl/dev${nl}dev" || fail=1 +else + test "$out" = ".$nl.${nl}dev${nl}dev" || fail=1 +fi +out=$(realpath --relative-base=/ --relative-to=// / //) || fail=1 +if test $double_slash = //; then + test "$out" = "/$nl//" || fail=1 +else + test "$out" = ".$nl." || fail=1 +fi + +Exit $fail diff --git a/tests/misc/runcon-no-reorder.sh b/tests/misc/runcon-no-reorder.sh new file mode 100755 index 0000000..cc5ff1b --- /dev/null +++ b/tests/misc/runcon-no-reorder.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# Ensure that runcon does not reorder its arguments. + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ runcon + +diag='runcon: runcon may be used only on a SELinux kernel' +echo "$diag" > exp || framework_failure_ + + +# This test works even on systems without SELinux. +# On such a system it fails with the above diagnostic, which is fine. +# Before the no-reorder change, it would have failed with a diagnostic +# about -j being an invalid option. +runcon $(id -Z) true -j 2> out && > exp + +# When run on a system with no /selinux/context (i.e., in a chroot), +# it fails with this: "runcon: invalid context: \ +# root:system_r:unconfined_t:s0-s0:c0.c1023: No such file or directory" +# That diagnostic is ok, too, so map it to the more common one. +case $(cat out) in + 'runcon: invalid context: '*) echo "$diag" > out;; +esac + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/selinux.sh b/tests/misc/selinux.sh new file mode 100755 index 0000000..fe85467 --- /dev/null +++ b/tests/misc/selinux.sh @@ -0,0 +1,65 @@ +#!/bin/sh +# Test SELinux-related options. + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chcon cp ls mv stat + +require_root_ +require_selinux_ +skip_if_mcstransd_is_running_ + +# Create a regular file, dir, fifo. +touch f || framework_failure_ +mkdir d s1 s2 || framework_failure_ +mkfifo_or_skip_ p + + +# special context that works both with and without mcstransd +ctx='root:object_r:tmp_t' +mls_enabled_ && ctx="$ctx:s0" + +chcon $ctx f d p || skip_ "Failed to set context: $ctx" + +# inspect that context with both ls -Z and stat. +for i in d f p; do + c=$(ls -dogZ $i|cut -d' ' -f3); test x$c = x$ctx || fail=1 + c=$(stat --printf %C $i); test x$c = x$ctx || fail=1 +done + +# ensure that ls -l output includes the ".". +c=$(ls -l f|cut -c11); test "$c" = . || fail=1 + +# Copy with an invalid context and ensure it fails +# Note this may succeed when root and selinux is in permissive mode +if test "$(getenforce)" = Enforcing; then + returns_ 1 cp --context='invalid-selinux-context' f f.cp || fail=1 +fi + +# Copy each to a new directory and ensure that context is preserved. +cp -r --preserve=all d f p s1 || fail=1 +for i in d f p; do + c=$(stat --printf %C s1/$i); test x$c = x$ctx || fail=1 +done + +# Now, move each to a new directory and ensure that context is preserved. +mv d f p s2 || fail=1 +for i in d f p; do + c=$(stat --printf %C s2/$i); test x$c = x$ctx || fail=1 +done + +Exit $fail diff --git a/tests/misc/seq-epipe.sh b/tests/misc/seq-epipe.sh new file mode 100755 index 0000000..9e382b2 --- /dev/null +++ b/tests/misc/seq-epipe.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# Test for proper detection of EPIPE with ignored SIGPIPE + +# Copyright (C) 2016-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ seq +trap_sigpipe_or_skip_ + +# /bin/sh has an intermittent failure in ignoring SIGPIPE on OpenIndiana 11 +# so we require bash as discussed at: +# https://lists.gnu.org/archive/html/coreutils/2020-03/msg00004.html +require_bash_as_SHELL_ + +# upon EPIPE with signals ignored, 'seq' should exit with an error. +timeout 10 $SHELL -c \ + 'trap "" PIPE && { seq inf 2>err; echo $? >code; } | head -n1' >out + +# Exit-code must be 1, indicating 'write error' +echo 1 > exp || framework_failure_ +compare exp out || fail=1 +compare exp code || fail=1 + +grep '^seq: write error: ' err \ + || { warn_ "seq emitted incorrect error on EPIPE"; \ + cat err;\ + fail=1; } + +Exit $fail diff --git a/tests/misc/seq-extra-number.sh b/tests/misc/seq-extra-number.sh new file mode 100755 index 0000000..ded774d --- /dev/null +++ b/tests/misc/seq-extra-number.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# Test the "print_extra_number" logic seq.c:print_numbers() + +# Copyright (C) 2019-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ seq + +## +## Test 1: the documented reason for the logic +## +cat<<'EOF'>exp1 || framework_failure_ +0.000000 +0.000001 +0.000002 +0.000003 +EOF + +seq 0 0.000001 0.000003 > out1 || fail=1 +compare exp1 out1 || fail=1 + + +## +## Test 2: before 8.32, this resulted in TWO lines +## (print_extra_number was erroneously set to true) +## The '=' is there instead of a space to ease visual inspection. +cat<<'EOF'>exp2 || framework_failure_ +1e+06= +EOF + +seq -f "%g=" 1000000 1000000 > out2 || fail=1 +compare exp2 out2 || fail=1 + +Exit $fail diff --git a/tests/misc/seq-io-errors.sh b/tests/misc/seq-io-errors.sh new file mode 100755 index 0000000..41886b7 --- /dev/null +++ b/tests/misc/seq-io-errors.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# Test for proper detection of I/O errors in seq + +# Copyright (C) 2016-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ seq + +if ! test -w /dev/full || ! test -c /dev/full; then + skip_ '/dev/full is required' +fi + +# Run 'seq' with a timeout, preventing infinite-loop run. +# expected returned codes: +# 1 - seq detected an I/O error and exited with an error. +# 124 - timed-out (seq likely infloop) +# other - unexpected error +timed_seq_fail() { timeout 10 seq "$@" >/dev/full 2>/dev/null; } + + +# Test infinite sequence, using fast-path method (seq_fast). +returns_ 1 timed_seq_fail 1 inf || fail=1 + +# Test infinite sequence, using slow-path method (print_numbers). +returns_ 1 timed_seq_fail 1.1 .1 inf || fail=1 + +# Test non-infinite sequence, using slow-path method (print_numbers). +# (despite being non-infinite, the entire sequence should take long time to +# print. Thus, either an I/O error is detected immediately, or seq will +# timeout). +returns_ 1 timed_seq_fail 1 0.0001 99999999 || fail=1 + +Exit $fail diff --git a/tests/misc/seq-locale.sh b/tests/misc/seq-locale.sh new file mode 100755 index 0000000..f0efd2c --- /dev/null +++ b/tests/misc/seq-locale.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# Test for output with appropriate precision + +# Copyright (C) 2019-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ seq + +# With coreutils-8.30 and earlier, the last decimal point would be ',' +# when setlocale(LC_ALL, "") failed, but setlocale(LC_NUMERIC, "") succeeded. +LC_ALL= LANG=invalid LC_NUMERIC=$LOCALE_FR_UTF8 seq 0.1 0.2 0.7 > out || fail=1 +uniq -w2 out > out-merge || framework_failure_ +test "$(wc -l < out-merge)" = 1 || { fail=1; cat out; } + +Exit $fail diff --git a/tests/misc/seq-long-double.sh b/tests/misc/seq-long-double.sh new file mode 100755 index 0000000..cfc39f8 --- /dev/null +++ b/tests/misc/seq-long-double.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# Test for this fix: 461231f022bdb3ee392622d31dc475034adceeb2. +# Ensure that seq prints exactly two numbers for a 2-number integral +# range at the limit of floating point precision. + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ seq +getlimits_ + +# Run this test only with glibc and sizeof (long double) > sizeof (double). +# Otherwise, there are known failures. +cat <<\EOF > long.c +#include <features.h> +#if defined __GNU_LIBRARY__ && __GLIBC__ >= 2 +int foo[sizeof (long double) - sizeof (double) - 1]; +#else +"run this test only with glibc" +#endif +EOF +$CC -c long.c \ + || skip_ \ + 'this test runs only on systems with glibc and long double != double' + +a=$INTMAX_MAX +b=$INTMAX_OFLOW + +seq $a $b > out || fail=1 +printf "$a\n$b\n" > exp || fail=1 +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/seq-precision.sh b/tests/misc/seq-precision.sh new file mode 100755 index 0000000..d489d76 --- /dev/null +++ b/tests/misc/seq-precision.sh @@ -0,0 +1,85 @@ +#!/bin/sh +# Test for output with appropriate precision + +# Copyright (C) 2015-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ seq +getlimits_ + +# Integer only. Before v8.24 these would switch output format + +seq 999999 inf | head -n2 > out || fail=1 +printf "%s\n" 999999 1000000 > exp || framework_failure_ +compare exp out || fail=1 + +# Exercise buffer handling in non floating point output +for i in $(seq 100); do + n1="$(printf '%*s' $i '' | tr ' ' 9)" + n2="1$(echo $n1 | tr 9 0)" + + seq $n1 $n2 > out || fail=1 + printf "%s\n" "$n1" "$n2" > exp || framework_failure_ + compare exp out || fail=1 +done + +seq 0xF423F 0xF4240 > out || fail=1 +printf "%s\n" 999999 1000000 > exp || framework_failure_ +compare exp out || fail=1 + +# Ensure consistent precision for inf +seq 1 .1 inf | head -n2 > out || fail=1 +printf "%s\n" 1.0 1.1 > exp || framework_failure_ +compare exp out || fail=1 + +# Ensure standard output methods with inf start +seq inf inf | head -n2 | uniq > out || fail=1 +test "$(wc -l < out)" = 1 || fail=1 + +# Ensure auto precision for hex float +seq 1 0x1p-1 2 > out || fail=1 +printf "%s\n" 1 1.5 2 > exp || framework_failure_ +compare exp out || fail=1 + +# Ensure consistent precision for hex +seq 1 .1 0x2 | head -n2 > out || fail=1 +printf "%s\n" 1.0 1.1 > exp || framework_failure_ +compare exp out || fail=1 + +# Ensure consistent handling of precision/width for exponents + +seq 1.1e1 12 > out || fail=1 +printf "%s\n" 11 12 > exp || framework_failure_ +compare exp out || fail=1 + +seq 11 1.2e1 > out || fail=1 +printf "%s\n" 11 12 > exp || framework_failure_ +compare exp out || fail=1 + +seq -w 1.1e4 | head -n1 > out || fail=1 +printf "%s\n" 00001 > exp || framework_failure_ +compare exp out || fail=1 + +seq -w 1.10000e5 1.10000e5 > out || fail=1 +printf "%s\n" 110000 > exp || framework_failure_ +compare exp out || fail=1 + +# Ensure no undefined behavior which failed with <= 8.32 +# This test would fail with: -fsanitize=undefined +seq 1e$LONG_MIN 2> err || fail=1 +compare /dev/null err || fail=1 + +Exit $fail diff --git a/tests/misc/seq.pl b/tests/misc/seq.pl new file mode 100755 index 0000000..7220055 --- /dev/null +++ b/tests/misc/seq.pl @@ -0,0 +1,202 @@ +#!/usr/bin/perl +# Test "seq". + +# Copyright (C) 1999-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $prog = 'seq'; +my $try_help = "Try '$prog --help' for more information.\n"; +my $err_inc_zero = "seq: invalid Zero increment value: '0'\n".$try_help; +my $err_nan_arg = "seq: invalid 'not-a-number' argument: 'nan'\n".$try_help; + +my $locale = $ENV{LOCALE_FR_UTF8}; +! defined $locale || $locale eq 'none' + and $locale = 'C'; + +my $p = '9' x 81; +(my $q = $p) =~ s/9/0/g; +$q = "1$q"; +(my $r = $q) =~ s/0$/1/; + +my @Tests = + ( + ['onearg-1', qw(10), {OUT => [(1..10)]}], + ['onearg-2', qw(-1)], + ['empty-rev', qw(1 -1 3)], + ['neg-1', qw(-10 10 10), {OUT => [qw(-10 0 10)]}], + # ['neg-2', qw(-.1 .1 .11), {OUT => [qw(-0.1 0.0 0.1)]}], + ['neg-3', qw(1 -1 0), {OUT => [qw(1 0)]}], + ['neg-4', qw(1 -1 -1), {OUT => [qw(1 0 -1)]}], + + ['float-1', qw(0.8 0.1 0.9), {OUT => [qw(0.8 0.9)]}], + ['float-2', qw(0.1 0.99 1.99), {OUT => [qw(0.10 1.09)]}], + ['float-3', qw(10.8 0.1 10.95), {OUT => [qw(10.8 10.9)]}], + ['float-4', qw(0.1 -0.1 -0.2), {OUT => [qw(0.1 0.0 -0.1 -0.2)]}, + {OUT_SUBST => 's,^-0\.0$,0.0,'}, + ], + ['float-5', qw(0.8 1e-1 0.9), {OUT => [qw(0.8 0.9)]}], + # Don't append lots of zeros to that 0.9000...; for example, changing the + # number to 0.90000000000000000000 tickles a bug in Solaris 8 strtold + # that would cause the test to fail. + ['float-6', qw(0.8 0.1 0.9000000000000), {OUT => [qw(0.8 0.9)]}], + + ['wid-1', qw(.8 1e-2 .81), {OUT => [qw(0.80 0.81)]}], + ['wid-2', qw(.89999 1e-7 .8999901), {OUT => [qw(0.8999900 0.8999901)]}], + + ['eq-wid-1', qw(-w 1 -1 -1), {OUT => [qw(01 00 -1)]}], + # Prior to 2.0g, this test would fail on e.g., HPUX systems + # because it'd end up using %3.1f as the format instead of %4.1f. + ['eq-wid-2', qw(-w -.1 .1 .11),{OUT => [qw(-0.1 00.0 00.1)]}], + ['eq-wid-3', qw(-w 1 3.0), {OUT => [qw(1 2 3)]}], + ['eq-wid-4', qw(-w .8 1e-2 .81), {OUT => [qw(0.80 0.81)]}], + ['eq-wid-5', qw(-w 1 .5 2), {OUT => [qw(1.0 1.5 2.0)]}], + ['eq-wid-6', qw(-w +1 2), {OUT => [qw(1 2)]}], + ['eq-wid-7', qw(-w " .1" " .1"), {OUT => [qw(0.1)]}], + ['eq-wid-8', qw(-w 9 0.5 10), {OUT => [qw(09.0 09.5 10.0)]}], + # Prior to 8.21, these tests involving numbers in scentific notation + # would fail with misalignment or wrong widths. + ['eq-wid-9', qw(-w -1e-3 1), {OUT => [qw(-0.001 00.999)]}], + ['eq-wid-10',qw(-w -1e-003 1), {OUT => [qw(-0.001 00.999)]}], + ['eq-wid-11',qw(-w -1.e-3 1), {OUT => [qw(-0.001 00.999)]}], + ['eq-wid-12',qw(-w -1.0e-4 1), {OUT => [qw(-0.00010 00.99990)]}], + ['eq-wid-13',qw(-w 999 1e3), {OUT => [qw(0999 1000)]}], + # Prior to 8.21, if the start value hadn't a precision, while step did, + # then misalignment would occur if the sequence narrowed. + ['eq-wid-14',qw(-w -1 1.0 0), {OUT => [qw(-1.0 00.0)]}], + ['eq-wid-15',qw(-w 10 -.1 9.9), {OUT => [qw(10.0 09.9)]}], + + # Prior to coreutils-4.5.11, some of these were not accepted. + ['fmt-1', qw(-f %2.1f 1.5 .5 2),{OUT => [qw(1.5 2.0)]}], + ['fmt-2', qw(-f %0.1f 1.5 .5 2),{OUT => [qw(1.5 2.0)]}], + ['fmt-3', qw(-f %.1f 1.5 .5 2),{OUT => [qw(1.5 2.0)]}], + + ['fmt-4', qw(-f %3.0f 1 2), {OUT => [' 1', ' 2']}], + ['fmt-5', qw(-f %-3.0f 1 2), {OUT => ['1 ', '2 ']}], + ['fmt-6', qw(-f %+3.0f 1 2), {OUT => [' +1', ' +2']}], + ['fmt-7', qw(-f %0+3.0f 1 2), {OUT => [qw(+01 +02)]}], + ['fmt-8', qw(-f %0+.0f 1 2), {OUT => [qw(+1 +2)]}], + ['fmt-9', '-f "% -3.0f"', qw(-1 0), {OUT => ['-1 ', ' 0 ']}], + ['fmt-a', '-f "% -.0f"',qw(-1 0), {OUT => ['-1', ' 0']}], + ['fmt-b', qw(-f %%%g%% 1), {OUT => ['%1%']}], + + # In coreutils-[6.0..6.9], this would mistakenly succeed and print "%Lg". + ['fmt-c', qw(-f %%g 1), {EXIT => 1}, + {ERR => "seq: format '%%g' has no % directive\n"}], + + # In coreutils-6.9..6.10, this would fail with an erroneous diagnostic: + # "seq: memory exhausted". In coreutils-6.0..6.8, it would mistakenly + # succeed and print a blank line. + ['fmt-eos1', qw(-f % 1), {EXIT => 1}, + {ERR => "seq: format '%' ends in %\n"}], + ['fmt-eos2', qw(-f %g% 1), {EXIT => 1}, + {ERR => "seq: format '%g%' has too many % directives\n"}], + + ['fmt-d', qw(-f "" 1), {EXIT => 1}, + {ERR => "seq: format '' has no % directive\n"}], + ['fmt-e', qw(-f %g%g 1), {EXIT => 1}, + {ERR => "seq: format '%g%g' has too many % directives\n"}], + + # With coreutils-6.12 and earlier, with a UTF8 numeric locale that uses + # something other than "." as the decimal point, this use of seq would + # fail to print the "2,0" endpoint. + ['locale-dec-pt', qw(-0.1 0.1 2), + {OUT => [qw(-0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 + 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0)]}, + + {ENV => "LC_ALL=$locale"}, + {OUT_SUBST => 's/,/./g'}, + ], + + # With coreutils-8.19 and prior, this would infloop. + ['long-1', "$p $r", {OUT => [$p, $q, $r]}], + + # Exercise the code that trims leading zeros. + ['long-leading-zeros1', qw(000 2), {OUT => [qw(0 1 2)]}], + ['long-leading-zeros2', qw(000 02), {OUT => [qw(0 1 2)]}], + ['long-leading-zeros3', qw(00 02), {OUT => [qw(0 1 2)]}], + ['long-leading-zeros4', qw(0 02), {OUT => [qw(0 1 2)]}], + + # Exercise the -s option, which was broken in 8.20 + ['sep-1', qw(-s, 1 3), {OUT => [qw(1,2,3)]}], + ['sep-2', qw(-s, 1 1), {OUT => [qw(1)]}], + ['sep-3', qw(-s,, 1 3), {OUT => [qw(1,,2,,3)]}], + + # Exercise fast path avoidance logic. + # In 8.20 a step value != 1, with positive integer start and end was broken + ['not-fast-1', qw(1 3 1), {OUT => [qw(1)]}], + ['not-fast-2', qw(1 1 4.2), {OUT => [qw(1 2 3 4)]}], + ['not-fast-3', qw(1 1 0)], + # In 8.20..8.22 a start or end of -0 was broken + ['not-fast-4', qw(-0 10), {OUT => [qw(-0 1 2 3 4 5 6 7 8 9 10)]}], + ['not-fast-5', qw(1 -0)], + + # Ensure the correct parameters are passed to the fast path + ['fast-1', qw(4), {OUT => [qw(1 2 3 4)]}], + ['fast-2', qw(1 4), {OUT => [qw(1 2 3 4)]}], + ['fast-3', qw(1 1 4), {OUT => [qw(1 2 3 4)]}], + ['fast-4', qw(1 2 4), {OUT => [qw(1 3)]}], + ['fast-5', qw(1 4 4), {OUT => [qw(1)]}], + ['fast-6', qw(1 1e0 4), {OUT => [qw(1 2 3 4)]}], + + # Ensure an INCREMENT of Zero is rejected. + ['inc-zero-1', qw(1 0 10), {EXIT => 1}, {ERR => $err_inc_zero}], + ['inc-zero-2', qw(0 -0 0), {EXIT => 1}, {ERR => $err_inc_zero}, + {ERR_SUBST => 's/-0/0/'}], + ['inc-zero-3', qw(1 0.0 10), {EXIT => 1},{ERR => $err_inc_zero}, + {ERR_SUBST => 's/0.0/0/'}], + ['inc-zero-4', qw(1 -0.0e-10 10), {EXIT => 1},{ERR => $err_inc_zero}, + {ERR_SUBST => 's/-0\.0e-10/0/'}], + + # Ensure NaN arguments rejected. + ['nan-first-1', qw(nan), {EXIT => 1}, {ERR => $err_nan_arg}], + ['nan-first-2', qw(NaN 2), {EXIT => 1}, {ERR => $err_nan_arg}, + {ERR_SUBST => 's/NaN/nan/'}], + ['nan-first-3', qw(nan 1 2), {EXIT => 1}, {ERR => $err_nan_arg}], + ['nan-first-4', qw(-- -nan), {EXIT => 1}, {ERR => $err_nan_arg}, + {ERR_SUBST => 's/-nan/nan/'}], + ['nan-inc-1', qw(1 nan 2), {EXIT => 1}, {ERR => $err_nan_arg}], + ['nan-inc-2', qw(1 -NaN 2), {EXIT => 1}, {ERR => $err_nan_arg}, + {ERR_SUBST => 's/-NaN/nan/'}], + ['nan-last-1', qw(1 1 nan), {EXIT => 1}, {ERR => $err_nan_arg}], + ['nan-last-2', qw(1 NaN), {EXIT => 1}, {ERR => $err_nan_arg}, + {ERR_SUBST => 's/NaN/nan/'}], + ['nan-last-3', qw(0 -1 -NaN), {EXIT => 1}, {ERR => $err_nan_arg}, + {ERR_SUBST => 's/-NaN/nan/'}], + ); + +# Append a newline to each entry in the OUT array. +my $t; +foreach $t (@Tests) + { + my $e; + foreach $e (@$t) + { + $e->{OUT} = join ("\n", @{$e->{OUT}}) . "\n" + if ref $e eq 'HASH' and exists $e->{OUT}; + } + } + +my $save_temps = $ENV{SAVE_TEMPS}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/sha1sum-vec.pl b/tests/misc/sha1sum-vec.pl new file mode 100755 index 0000000..9d2e2b0 --- /dev/null +++ b/tests/misc/sha1sum-vec.pl @@ -0,0 +1,534 @@ +#!/usr/bin/perl +# Sample vectors for "sha1sum". + +# Copyright (C) 2000-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# The data from which these tests were derived came from here: +# https://web.archive.org/web/20060505234703/http://csrc.nist.gov/cryptval/shs/sha1-vectors.zip + +my @Tests = + ( + ['1', {IN=> {f=> '0 1 ^'}}, + {OUT=>'DA39A3EE5E6B4B0D3255BFEF95601890AFD80709'}], + ['2', {IN=> {f=> '5 0 2 1 2 1 2 ^'}}, + {OUT=>'3CDF2936DA2FC556BFA533AB1EB59CE710AC80E5'}], + ['3', {IN=> {f=> '5 0 1 3 4 4 4 ^'}}, + {OUT=>'19C1E2048FA7393CFBF2D310AD8209EC11D996E5'}], + ['4', {IN=> {f=> '7 0 4 3 4 4 1 4 4 ^'}}, + {OUT=>'CA775D8C80FAA6F87FA62BECA6CA6089D63B56E5'}], + ['5', {IN=> {f=> '10 0 4 1 5 3 4 4 3 1 3 4 ^'}}, + {OUT=>'71AC973D0E4B50AE9E5043FF4D615381120A25A0'}], + ['6', {IN=> {f=> '10 0 3 1 6 5 5 1 3 6 6 4 ^'}}, + {OUT=>'A6B5B9F854CFB76701C3BDDBF374B3094EA49CBA'}], + ['7', {IN=> {f=> '13 1 3 2 5 3 3 3 4 6 6 1 4 6 2 ^'}}, + {OUT=>'D87A0EE74E4B9AD72E6847C87BDEEB3D07844380'}], + ['8', {IN=> {f=> '16 1 3 5 5 1 2 1 3 3 6 3 5 2 3 5 7 2 ^'}}, + {OUT=>'1976B8DD509FE66BF09C9A8D33534D4EF4F63BFD'}], + ['9', {IN=> {f=> '15 1 8 1 5 3 2 7 4 5 6 7 3 3 1 6 3 ^'}}, + {OUT=>'5A78F439B6DB845BB8A558E4CEB106CD7B7FF783'}], + ['10', {IN=> {f=> '15 1 4 6 8 2 1 4 2 5 1 6 8 8 6 4 7 ^'}}, + {OUT=>'F871BCE62436C1E280357416695EE2EF9B83695C'}], + ['11', {IN=> {f=> '18 1 1 2 7 3 8 6 7 5 4 3 4 3 5 3 3 2 6 8 ^'}}, + {OUT=>'62B243D1B780E1D31CF1BA2DE3F01C72AEEA0E47'}], + ['12', {IN=> {f=> '16 0 9 8 1 8 1 7 6 7 7 1 2 6 9 5 4 7 ^'}}, + {OUT=>'1698994A273404848E56E7FDA4457B5900DE1342'}], + ['13', {IN=> {f=> '18 0 7 1 7 3 9 4 7 7 5 2 8 1 7 8 2 7 2 9 ^'}}, + {OUT=>'056F4CDC02791DA7ED1EB2303314F7667518DEEF'}], + ['14', {IN=> {f=> '19 1 2 3 1 8 8 6 9 10 3 10 8 9 2 4 1 5 1 5 9 ^'}}, + {OUT=>'9FE2DA967BD8441EEA1C32DF68DDAA9DC1FC8E4B'}], + ['15', {IN=> {f=> '19 1 8 5 4 8 1 3 9 5 7 7 2 7 2 7 8 7 4 8 10 ^'}}, + {OUT=>'73A31777B4ACE9384EFA8BBEAD45C51A71ABA6DD'}], + ['16', {IN=> {f=> '20 1 1 9 7 4 1 4 5 1 10 8 6 4 4 9 9 9 8 2 9 10 ^'}}, + {OUT=>'3F9D7C4E2384EDDABFF5DD8A31E23DE3D03F42AC'}], + ['17', {IN=> {f=> '19 1 11 6 7 7 2 6 2 6 10 6 9 10 5 11 1 6 8 11 4 ^'}}, + {OUT=>'4814908F72B93FFD011135BEE347DE9A08DA838F'}], + ['18', {IN=> {f=> '22 0 10 5 10 3 7 8 9 9 1 1 1 10 2 1 5 10 2 9 9 9 7 8 ^'}}, + {OUT=>'0978374B67A412A3102C5AA0B10E1A6596FC68EB'}], + ['19', {IN=> {f=> '21 0 1 10 1 6 9 4 2 5 2 11 8 12 12 9 8 1 3 10 7 11 12 ^'}}, + {OUT=>'44AD6CB618BD935460D46D3F921D87B99AB91C1E'}], + ['20', {IN=> {f=> '24 1 3 9 5 12 3 4 2 9 12 11 6 6 1 1 9 5 9 1 4 9 4 10 8 9 ^'}}, + {OUT=>'02DC989AF265B09CF8485640842128DCF95E9F39'}], + ['21', {IN=> {f=> '25 1 3 2 3 11 1 12 5 6 2 7 8 4 8 8 9 9 8 4 9 1 4 8 10 9 9 ^'}}, + {OUT=>'67507B8D497B35D6E99FC01976D73F54AECA75CF'}], + ['22', {IN=> {f=> '23 0 11 10 7 10 10 6 10 9 4 5 10 5 8 4 1 10 12 4 6 1 8 11 6 ^'}}, + {OUT=>'1EAE0373C1317CB60C36A42A867B716039D441F5'}], + ['23', {IN=> {f=> '22 0 12 8 10 4 3 8 5 5 7 11 13 11 12 11 4 12 3 6 5 11 10 5 ^'}}, + {OUT=>'9C3834589E5BFFAC9F50950E0199B3EC2620BEC8'}], + ['24', {IN=> {f=> '26 1 10 9 6 9 7 2 10 4 4 5 5 2 12 13 5 3 1 10 1 4 7 8 13 13 12 9 ^'}}, + {OUT=>'209F7ABC7F3B878EE46CDF3A1FBB9C21C3474F32'}], + ['25', {IN=> {f=> '31 0 2 6 5 4 7 3 10 6 13 6 3 9 6 2 10 5 3 8 4 1 11 3 5 3 7 11 1 12 9 12 5 ^'}}, + {OUT=>'05FC054B00D97753A9B3E2DA8FBBA3EE808CEF22'}], + ['26', {IN=> {f=> '27 1 14 5 1 3 7 2 3 9 3 4 14 4 4 10 8 5 14 1 11 12 12 10 4 13 7 11 9 ^'}}, + {OUT=>'0C4980EA3A46C757DFBFC5BAA38AC6C8E72DDCE7'}], + ['27', {IN=> {f=> '30 1 4 9 5 5 8 9 5 10 4 2 4 7 9 9 6 3 5 1 8 3 2 13 3 14 9 8 9 10 14 10 ^'}}, + {OUT=>'96A460D2972D276928B69864445BEA353BDCFFD2'}], + ['28', {IN=> {f=> '27 0 12 9 5 8 7 2 14 12 3 8 14 6 6 4 7 5 7 10 7 11 10 1 9 6 7 12 14 ^'}}, + {OUT=>'F3EF04D8FA8C6FA9850F394A4554C080956FA64B'}], + ['29', {IN=> {f=> '24 0 12 9 9 2 11 13 12 11 11 6 14 13 10 5 6 8 10 4 3 11 11 14 5 14 ^'}}, + {OUT=>'F2A31D875D1D7B30874D416C4D2EA6BAF0FFBAFE'}], + ['30', {IN=> {f=> '24 0 15 4 5 3 8 12 15 8 14 15 9 12 12 3 10 13 6 11 10 4 13 14 8 8 ^'}}, + {OUT=>'F4942D3B9E9588DCFDC6312A84DF75D05F111C20'}], + ['31', {IN=> {f=> '28 1 1 8 1 5 11 4 9 12 4 13 15 5 9 11 7 14 11 1 11 7 8 8 11 1 13 15 12 13 ^'}}, + {OUT=>'310207DF35B014E4676D30806FA34424813734DD'}], + ['32', {IN=> {f=> '32 1 5 8 3 8 10 7 8 1 5 13 12 14 5 3 6 4 12 15 6 6 10 11 13 9 1 11 6 10 3 7 14 2 ^'}}, + {OUT=>'4DA1955B2FA7C7E74E3F47D7360CE530BBF57CA3'}], + ['33', {IN=> {f=> '31 0 10 3 5 1 14 11 11 16 1 2 2 11 6 13 15 12 6 5 16 2 14 2 10 12 2 5 5 6 10 13 15 ^'}}, + {OUT=>'74C4BC5B26FB4A08602D40CCEC6C6161B6C11478'}], + ['34', {IN=> {f=> '34 0 3 10 8 16 9 5 12 15 4 11 13 3 6 5 10 8 1 3 9 3 11 1 2 16 12 10 6 1 9 1 16 5 6 14 ^'}}, + {OUT=>'0B103CE297338DFC7395F7715EE47539B556DDB6'}], + ['35', {IN=> {f=> '30 1 1 12 4 4 2 15 13 15 11 15 5 11 9 7 15 16 6 16 12 3 2 10 16 5 5 7 1 7 11 16 ^'}}, + {OUT=>'EFC72D99E3D2311CE14190C0B726BDC68F4B0821'}], + ['36', {IN=> {f=> '34 0 7 9 11 2 5 5 5 4 13 13 14 4 7 12 6 4 8 2 9 9 13 13 3 3 6 7 16 7 6 15 5 8 15 14 ^'}}, + {OUT=>'660EDAC0A8F4CE33DA0D8DBAE597650E97687250'}], + ['37', {IN=> {f=> '36 1 4 6 16 15 11 14 14 4 7 10 3 4 10 3 6 7 14 4 6 6 5 2 7 8 16 2 12 16 10 14 3 2 3 7 14 3 ^'}}, + {OUT=>'FE0A55A988B3B93946A63EB36B23785A5E6EFC3E'}], + ['38', {IN=> {f=> '32 0 15 10 9 1 14 10 14 6 6 16 3 2 3 8 3 12 8 11 17 3 9 7 16 14 4 11 15 5 13 9 5 17 ^'}}, + {OUT=>'0CBDF2A5781C59F907513147A0DE3CC774B54BF3'}], + ['39', {IN=> {f=> '30 0 17 17 13 8 2 6 8 16 1 12 5 17 2 9 8 10 13 14 11 17 12 5 14 9 11 9 11 4 11 12 ^'}}, + {OUT=>'663E40FEE5A44BFCB1C99EA5935A6B5BC9F583B0'}], + ['40', {IN=> {f=> '30 1 16 6 10 5 8 3 17 16 14 1 15 15 15 6 13 2 11 6 13 11 13 4 6 7 11 11 12 16 13 16 ^'}}, + {OUT=>'00162134256952DD9AE6B51EFB159B35C3C138C7'}], + ['41', {IN=> {f=> '33 1 16 16 14 16 2 4 16 11 6 15 7 4 17 6 5 7 6 3 14 16 5 17 11 13 1 1 14 13 3 6 14 5 16 ^'}}, + {OUT=>'CEB88E4736E354416E2010FC1061B3B53B81664B'}], + ['42', {IN=> {f=> '39 1 2 16 13 7 8 6 2 15 1 9 12 4 4 11 13 7 2 11 9 18 4 5 4 8 2 14 9 9 1 8 13 11 15 8 5 9 10 16 7 ^'}}, + {OUT=>'A6A2C4B6BCC41DDC67278F3DF4D8D0B9DD7784EF'}], + ['43', {IN=> {f=> '34 0 2 7 1 1 17 13 6 11 10 8 5 12 15 6 15 10 12 4 18 1 2 8 11 12 16 10 12 18 11 16 12 11 17 6 ^'}}, + {OUT=>'C23D083CD8820B57800A869F5F261D45E02DC55D'}], + ['44', {IN=> {f=> '34 1 4 7 13 7 10 7 10 6 1 12 7 18 11 18 2 10 15 10 14 8 18 9 9 12 12 3 13 12 6 4 9 17 13 17 ^'}}, + {OUT=>'E8AC31927B78DDEC41A31CA7A44EB7177165E7AB'}], + ['45', {IN=> {f=> '40 0 5 7 3 2 1 17 14 4 16 6 13 1 13 6 6 10 1 3 18 3 11 7 9 5 7 11 17 1 9 16 5 15 10 17 3 8 15 17 8 12 ^'}}, + {OUT=>'E864EC5DBAB0F9FF6984AB6AD43A8C9B81CC9F9C'}], + ['46', {IN=> {f=> '40 0 11 3 15 17 11 1 1 4 3 14 18 4 2 18 8 15 6 4 6 3 15 11 16 10 17 17 9 6 3 2 6 16 4 9 12 6 8 1 11 17 ^'}}, + {OUT=>'CFED6269069417A84D6DE2347220F4B858BCD530'}], + ['47', {IN=> {f=> '37 1 2 19 12 8 16 14 2 9 16 2 6 6 7 9 10 9 11 9 14 11 15 5 16 9 2 17 2 8 15 8 4 3 14 14 16 16 12 ^'}}, + {OUT=>'D9217BFB46C96348722C3783D29D4B1A3FEDA38C'}], + ['48', {IN=> {f=> '37 1 11 10 16 12 11 7 14 14 14 6 10 10 1 6 13 19 5 6 4 7 12 12 10 5 10 15 15 8 5 13 17 13 5 6 14 1 19 ^'}}, + {OUT=>'DEC24E5554F79697218D317315FA986229CE3350'}], + ['49', {IN=> {f=> '38 1 2 6 5 17 9 11 18 18 8 6 13 15 3 3 15 5 13 18 3 2 5 5 14 7 13 4 17 7 2 17 3 18 15 7 15 16 18 11 ^'}}, + {OUT=>'83A099DF7071437BA5495A5B0BFBFEFE1C0EF7F3'}], + ['50', {IN=> {f=> '38 1 12 8 6 3 17 12 13 19 15 9 7 17 16 15 3 11 11 5 2 13 19 16 2 4 16 7 8 1 2 9 17 12 3 5 18 19 11 9 ^'}}, + {OUT=>'AA3198E30891A83E33CE3BFA0587D86A197D4F80'}], + ['51', {IN=> {f=> '39 1 14 16 14 8 9 16 5 1 6 3 17 18 16 9 1 15 9 10 9 19 1 3 3 20 11 13 17 1 19 8 3 4 3 7 1 14 19 19 19 ^'}}, + {OUT=>'9B6ACBEB4989CBEE7015C7D515A75672FFDE3442'}], + ['52', {IN=> {f=> '37 1 18 13 11 5 18 4 19 10 6 19 11 17 10 10 7 9 13 16 9 10 18 4 12 5 16 5 20 12 3 8 10 1 18 1 6 20 14 ^'}}, + {OUT=>'B021EB08A436B02658EAA7BA3C88D49F1219C035'}], + ['53', {IN=> {f=> '36 0 8 9 6 12 11 7 7 3 17 13 6 20 17 9 20 16 10 12 17 8 11 8 11 10 5 10 14 18 8 19 9 12 12 2 20 19 ^'}}, + {OUT=>'CAE36DAB8AEA29F62E0855D9CB3CD8E7D39094B1'}], + ['54', {IN=> {f=> '39 0 12 16 20 3 9 9 19 17 13 13 4 17 2 11 7 14 3 6 16 13 10 13 5 16 10 2 8 2 17 19 4 17 7 19 6 9 15 15 6 ^'}}, + {OUT=>'02DE8BA699F3C1B0CB5AD89A01F2346E630459D7'}], + ['55', {IN=> {f=> '43 0 7 2 18 5 7 18 5 2 15 7 11 10 9 3 2 14 19 3 11 8 18 15 5 3 5 12 15 16 10 17 7 19 16 2 1 16 6 3 19 12 5 18 16 ^'}}, + {OUT=>'88021458847DD39B4495368F7254941859FAD44B'}], + ['56', {IN=> {f=> '49 1 9 11 2 1 12 11 14 12 14 10 4 11 6 8 16 7 5 11 20 8 17 4 14 4 15 3 2 2 4 3 2 3 14 15 10 2 12 7 3 7 20 20 19 10 2 3 1 10 20 ^'}}, + {OUT=>'91A165295C666FE85C2ADBC5A10329DAF0CB81A0'}], + ['57', {IN=> {f=> '36 0 19 20 12 5 19 21 5 21 11 14 19 1 17 8 9 4 19 3 17 1 14 21 14 7 6 5 20 14 21 20 4 6 21 7 11 12 ^'}}, + {OUT=>'4B31312EAF8B506811151A9DBD162961F7548C4B'}], + ['58', {IN=> {f=> '41 0 12 9 11 6 16 18 18 10 11 20 6 12 11 5 7 21 19 18 6 15 21 10 4 14 9 19 10 3 3 5 13 1 8 12 3 13 9 7 10 17 14 ^'}}, + {OUT=>'3FE70971B20558F7E9BAC303ED2BC14BDE659A62'}], + ['59', {IN=> {f=> '45 0 10 6 8 3 17 18 3 21 19 6 17 15 4 9 15 9 15 14 4 7 14 8 10 13 4 11 10 7 6 21 1 14 5 11 7 7 2 13 13 3 9 13 8 14 20 ^'}}, + {OUT=>'93FB769D5BF49D6C563685954E2AECC024DC02D6'}], + ['60', {IN=> {f=> '39 1 3 7 18 4 9 9 5 15 13 17 10 15 16 20 8 19 9 10 9 1 19 14 21 2 18 13 10 4 18 16 4 21 15 10 18 19 3 12 18 ^'}}, + {OUT=>'BC8827C3E614D515E83DEA503989DEA4FDA6EA13'}], + ['61', {IN=> {f=> '41 0 14 4 13 11 1 11 1 10 2 12 4 21 10 21 18 9 2 16 7 20 6 7 12 19 20 1 13 12 10 8 21 15 7 19 13 6 8 19 20 18 19 ^'}}, + {OUT=>'E83868DBE4A389AB48E61CFC4ED894F32AE112AC'}], + ['62', {IN=> {f=> '37 0 11 18 1 17 14 15 20 16 20 8 2 17 10 4 21 5 19 19 14 22 21 18 13 14 1 3 12 11 11 4 22 13 5 18 7 21 21 ^'}}, + {OUT=>'55C95459CDE4B33791B4B2BCAAF840930AF3F3BD'}], + ['63', {IN=> {f=> '48 0 9 22 19 12 8 16 5 17 5 9 1 2 9 6 12 6 1 7 4 3 15 1 14 1 12 3 10 2 10 14 21 13 17 6 6 17 1 21 2 14 16 17 9 11 20 21 11 18 ^'}}, + {OUT=>'36BB0E2BA438A3E03214D9ED2B28A4D5C578FCAA'}], + ['64', {IN=> {f=> '50 1 12 8 20 13 2 9 20 9 14 10 1 16 2 22 6 4 16 14 15 1 12 4 14 9 21 3 3 9 8 21 15 14 8 4 14 4 2 3 8 12 8 6 1 2 18 20 15 3 19 10 ^'}}, + {OUT=>'3ACBF874199763EBA20F3789DFC59572ACA4CF33'}], + ['65', {IN=> {f=> '44 0 10 20 14 6 3 4 21 1 12 4 18 2 6 7 6 9 20 14 10 10 19 17 21 12 15 17 7 10 11 8 10 12 1 19 19 9 18 21 4 18 11 9 22 5 ^'}}, + {OUT=>'86BE037C4D509C9202020767D860DAB039CADACE'}], + ['66', {IN=> {f=> '47 0 15 8 15 3 5 6 2 19 12 17 4 20 8 11 20 2 18 4 16 20 12 9 9 6 16 21 16 3 16 18 3 19 5 16 2 4 2 12 11 15 11 14 17 2 10 18 8 ^'}}, + {OUT=>'51B57D7080A87394EEC3EB2E0B242E553F2827C9'}], + ['67', {IN=> {f=> '48 1 5 13 3 21 5 3 6 18 18 10 1 21 21 7 1 13 12 19 1 14 6 8 21 19 21 11 19 13 2 13 4 1 10 22 16 4 9 4 10 16 3 7 15 11 9 13 17 12 ^'}}, + {OUT=>'1EFBFA78866315CE6A71E457F3A750A38FACAB41'}], + ['68', {IN=> {f=> '45 0 14 7 6 2 20 3 6 19 19 10 2 22 12 17 12 1 20 7 7 15 20 6 18 8 3 14 23 18 15 4 7 5 23 15 7 14 10 10 19 17 2 4 15 17 21 ^'}}, + {OUT=>'57D6CB41AEEC20236F365B3A490C61D0CFA39611'}], + ['69', {IN=> {f=> '45 1 15 11 8 9 17 5 12 18 14 6 20 17 21 12 16 9 22 9 20 15 2 22 11 2 6 11 9 8 2 4 14 19 3 21 21 23 8 2 11 4 8 4 20 22 11 ^'}}, + {OUT=>'C532CB64B4BA826372BCCF2B4B5793D5B88BB715'}], + ['70', {IN=> {f=> '38 0 21 18 22 10 19 9 14 17 23 21 10 7 15 13 16 5 4 10 13 14 20 23 12 20 23 18 10 12 8 21 11 6 12 7 19 14 18 17 ^'}}, + {OUT=>'15833B5631032663E783686A209C6A2B47A1080E'}], + ['71', {IN=> {f=> '40 0 18 22 6 9 22 5 23 13 6 8 23 20 22 5 22 15 19 20 9 9 1 13 13 10 14 13 5 22 14 21 9 21 19 14 14 4 18 13 12 14 ^'}}, + {OUT=>'D04F2043C96E10CD83B574B1E1C217052CD4A6B2'}], + ['72', {IN=> {f=> '48 1 7 3 15 5 17 14 23 14 5 17 22 11 1 8 13 23 6 21 3 6 11 7 23 8 6 21 4 4 22 19 13 8 5 19 7 5 23 1 4 19 11 23 11 21 14 1 3 21 ^'}}, + {OUT=>'E8882627C64DB743F7DB8B4413DD033FC63BEB20'}], + ['73', {IN=> {f=> '43 0 22 14 11 7 18 16 17 24 12 12 3 13 19 16 22 4 16 4 6 23 8 18 11 2 3 20 22 9 21 8 23 1 23 20 7 16 13 23 4 13 3 7 22 ^'}}, + {OUT=>'CD2D32286B8867BC124A0AF2236FC74BE3622199'}], + ['74', {IN=> {f=> '47 1 23 6 13 19 2 3 7 2 9 9 15 6 13 4 22 6 19 20 1 9 7 14 1 15 3 23 24 22 18 12 12 17 19 10 8 11 22 12 10 2 20 15 18 17 18 7 19 ^'}}, + {OUT=>'019B70D745375091ED5C7B218445EC986D0F5A82'}], + ['75', {IN=> {f=> '47 1 12 21 6 12 4 7 18 17 3 2 14 24 14 1 23 1 11 15 10 6 18 20 7 1 8 1 16 6 20 23 23 21 10 10 12 24 10 11 23 2 12 23 9 3 24 24 10 ^'}}, + {OUT=>'E5FF5FEC1DADBAED02BF2DAD4026BE6A96B3F2AF'}], + ['76', {IN=> {f=> '52 0 14 10 18 15 14 5 16 11 22 2 15 24 8 22 1 4 24 9 10 15 3 9 5 4 17 15 9 12 19 19 1 3 10 6 8 3 17 8 18 24 19 3 4 15 4 9 2 24 5 20 13 13 ^'}}, + {OUT=>'6F4E23B3F2E2C068D13921FE4E5E053FFED4E146'}], + ['77', {IN=> {f=> '42 0 20 17 19 22 13 8 10 19 15 11 1 14 17 20 22 10 7 11 16 9 21 22 17 23 12 15 4 24 7 21 18 2 21 16 1 19 18 20 11 3 15 17 ^'}}, + {OUT=>'25E179602A575C915067566FBA6DA930E97F8678'}], + ['78', {IN=> {f=> '50 0 18 1 6 14 5 5 5 19 13 10 24 19 16 24 15 13 2 19 15 24 21 17 4 13 17 1 1 9 1 10 2 18 1 21 19 5 18 12 2 22 16 23 15 19 6 18 9 1 23 5 ^'}}, + {OUT=>'67DED0E68E235C8A523E051E86108EEB757EFBFD'}], + ['79', {IN=> {f=> '51 0 21 13 14 11 18 12 13 3 19 9 20 22 20 2 11 12 6 1 12 16 18 2 9 8 4 3 11 17 11 5 4 19 16 11 23 13 18 1 20 8 2 16 16 21 4 19 5 5 20 24 16 ^'}}, + {OUT=>'AF78536EA83C822796745556D62A3EE82C7BE098'}], + ['80', {IN=> {f=> '53 1 20 25 17 11 8 4 19 25 17 7 16 21 6 4 8 2 15 9 2 9 19 3 6 3 3 10 25 13 15 7 8 20 21 12 10 12 5 24 11 20 3 13 13 16 9 13 10 3 9 16 3 7 25 ^'}}, + {OUT=>'64D7AC52E47834BE72455F6C64325F9C358B610D'}], + ['81', {IN=> {f=> '49 1 9 9 14 2 13 17 25 2 18 5 19 23 9 25 9 10 23 12 12 7 13 8 15 7 1 6 21 2 8 7 6 16 14 14 12 15 13 24 10 15 11 10 8 14 15 21 25 21 25 ^'}}, + {OUT=>'9D4866BAA3639C13E541F250FFA3D8BC157A491F'}], + ['82', {IN=> {f=> '47 0 9 18 20 22 21 20 11 14 23 22 10 13 14 8 19 12 2 11 20 23 13 4 10 6 5 7 23 11 3 16 8 21 4 8 18 5 12 14 8 6 20 19 24 8 23 17 23 ^'}}, + {OUT=>'2E258811961D3EB876F30E7019241A01F9517BEC'}], + ['83', {IN=> {f=> '48 1 7 19 1 18 1 14 22 13 14 5 8 22 18 14 25 17 11 12 22 2 12 12 16 12 13 18 17 12 17 14 18 8 25 9 23 5 3 8 14 24 17 7 3 3 23 17 22 19 ^'}}, + {OUT=>'8E0EBC487146F83BC9077A1630E0FB3AB3C89E63'}], + ['84', {IN=> {f=> '51 1 19 17 16 22 24 14 16 20 23 20 9 19 16 7 12 16 5 8 9 7 10 21 24 10 11 19 1 21 14 14 19 3 22 8 12 20 1 18 5 6 5 12 14 1 1 11 9 22 3 24 4 ^'}}, + {OUT=>'CE8953741FFF3425D2311FBBF4AB481B669DEF70'}], + ['85', {IN=> {f=> '52 1 6 1 11 16 1 12 8 11 11 17 10 22 7 3 10 2 6 4 24 16 24 19 4 5 18 11 12 9 20 21 25 2 21 18 10 20 25 21 3 17 17 5 8 22 25 19 8 10 19 7 11 18 ^'}}, + {OUT=>'789D1D2DAB52086BD90C0E137E2515ED9C6B59B5'}], + ['86', {IN=> {f=> '44 0 26 14 21 25 25 4 9 13 5 8 9 21 8 12 26 24 9 24 15 1 23 22 16 14 8 22 15 19 24 20 7 8 15 24 12 4 4 23 21 13 19 15 21 12 ^'}}, + {OUT=>'B76CE7472700DD68D6328B7AA8437FB051D15745'}], + ['87', {IN=> {f=> '59 1 15 7 3 21 20 8 22 14 23 26 19 2 10 18 3 5 3 1 9 15 15 3 7 13 23 9 7 1 13 17 14 25 9 16 2 2 6 13 7 19 25 17 1 5 21 2 7 22 5 6 25 3 12 19 6 2 4 24 17 ^'}}, + {OUT=>'F218669B596C5FFB0B1C14BD03C467FC873230A0'}], + ['88', {IN=> {f=> '60 0 9 18 20 19 4 11 14 1 6 8 26 6 9 22 4 10 2 7 21 9 8 24 25 14 22 12 22 3 23 3 3 20 6 11 23 6 1 7 5 18 5 15 25 26 1 1 10 11 11 4 12 11 20 3 14 2 3 2 23 15 ^'}}, + {OUT=>'1FF3BDBE0D504CB0CDFAB17E6C37ABA6B3CFFDED'}], + ['89', {IN=> {f=> '49 0 12 17 24 11 8 6 24 16 15 22 21 14 6 12 20 19 5 5 12 11 6 23 2 16 23 7 24 6 21 2 17 17 5 25 11 25 20 25 24 18 6 12 19 25 7 6 5 2 25 ^'}}, + {OUT=>'2F3CBACBB14405A4652ED52793C1814FD8C4FCE0'}], + ['90', {IN=> {f=> '54 1 12 16 1 15 7 1 26 19 19 13 20 11 17 6 20 5 24 24 1 21 11 9 20 21 15 10 19 26 3 2 6 7 12 9 10 8 14 10 15 5 17 8 21 1 20 25 6 19 8 3 22 16 16 20 ^'}}, + {OUT=>'982C8AB6CE164F481915AF59AAED9FFF2A391752'}], + ['91', {IN=> {f=> '63 0 17 13 11 10 17 15 12 6 13 14 17 4 12 10 24 5 13 24 3 5 2 5 11 14 8 5 10 17 16 8 4 14 21 15 3 6 17 25 8 2 3 3 19 10 13 22 22 8 2 13 25 17 2 1 19 1 14 20 2 5 4 15 24 ^'}}, + {OUT=>'5CD92012D488A07ECE0E47901D0E083B6BD93E3F'}], + ['92', {IN=> {f=> '49 0 14 20 7 25 20 26 20 16 7 17 17 22 1 13 6 5 1 18 14 15 23 15 10 5 19 18 18 26 12 13 3 25 12 21 16 24 4 16 3 6 26 26 10 20 13 1 20 24 15 ^'}}, + {OUT=>'69603FEC02920851D4B3B8782E07B92BB2963009'}], + ['93', {IN=> {f=> '56 0 3 8 14 5 5 7 11 13 11 26 11 4 26 17 20 19 11 10 3 10 14 9 6 9 7 16 10 4 4 19 19 2 26 13 19 17 15 24 15 4 21 22 13 13 12 22 2 14 20 5 18 7 17 24 20 20 ^'}}, + {OUT=>'3E90F76437B1EA44CF98A08D83EA24CECF6E6191'}], + ['94', {IN=> {f=> '58 1 6 17 9 20 2 10 19 3 22 4 1 11 3 5 3 21 11 15 12 23 26 5 2 27 6 5 16 6 3 2 23 5 3 20 20 4 24 2 18 21 7 14 10 27 23 6 24 6 19 23 3 9 22 16 21 17 19 23 ^'}}, + {OUT=>'34C09F107C42D990EB4881D4BF2DDDCAB01563AE'}], + ['95', {IN=> {f=> '58 1 17 7 21 19 6 16 15 15 20 14 2 25 19 14 18 19 7 9 1 14 11 10 16 3 23 14 26 10 11 1 18 1 12 24 19 19 1 7 2 3 24 7 12 9 2 8 16 20 24 5 26 26 4 9 2 7 25 17 ^'}}, + {OUT=>'474BE0E5892EB2382109BFC5E3C8249A9283B03D'}], + ['96', {IN=> {f=> '54 1 8 12 18 14 26 7 17 18 4 20 1 16 14 21 26 4 6 8 24 11 25 15 24 16 23 4 10 23 21 24 15 10 9 26 7 14 24 21 6 20 5 17 16 17 1 3 12 1 4 13 3 9 21 26 ^'}}, + {OUT=>'A04B4F75051786682483252438F6A75BF4705EC6'}], + ['97', {IN=> {f=> '56 1 7 18 11 1 19 20 23 12 12 27 13 13 15 16 13 1 16 15 12 26 3 16 16 8 17 13 21 4 6 5 19 14 16 4 16 11 14 18 18 27 9 13 21 3 26 22 3 7 6 4 26 3 15 8 25 21 ^'}}, + {OUT=>'BE88A6716083EB50ED9416719D6A247661299383'}], + ['98', {IN=> {f=> '50 1 20 13 9 11 20 6 11 21 27 25 20 7 4 18 26 16 27 5 12 19 7 23 6 25 25 2 11 13 25 21 18 17 6 12 14 13 24 11 14 19 26 27 25 6 1 15 4 7 27 15 ^'}}, + {OUT=>'C67E38717FEE1A5F65EC6C7C7C42AFC00CD37F04'}], + ['99', {IN=> {f=> '51 0 15 16 26 27 23 14 12 28 22 15 8 19 2 20 13 1 24 2 25 1 6 19 19 8 11 24 24 21 13 27 5 11 28 17 7 25 6 23 24 14 25 12 5 13 26 2 5 8 10 16 17 ^'}}, + {OUT=>'959AC4082388E19E9BE5DE571C047EF10C174A8D'}], + ['100', {IN=> {f=> '58 1 5 26 18 19 21 3 12 11 13 4 14 22 22 14 16 13 3 22 16 23 5 19 6 13 10 26 17 27 26 4 3 25 6 14 2 3 5 7 23 11 22 8 25 2 9 25 18 17 8 2 14 4 19 1 5 27 13 24 ^'}}, + {OUT=>'BAA7AA7B7753FA0ABDC4A541842B5D238D949F0A'}], + ['101', {IN=> {f=> '53 0 2 27 28 2 17 23 10 27 18 26 7 22 16 3 27 1 26 21 28 10 3 6 2 2 10 17 13 16 6 17 21 23 13 20 22 5 6 11 12 12 8 23 13 17 9 23 20 3 28 27 12 17 22 ^'}}, + {OUT=>'351394DCEBC08155D100FCD488578E6AE71D0E9C'}], + ['102', {IN=> {f=> '59 0 28 19 5 21 4 27 8 1 19 14 20 6 7 9 1 6 22 3 19 26 14 8 6 7 19 15 23 1 17 16 6 26 14 5 22 25 4 7 10 16 21 10 18 19 24 16 23 8 3 17 28 18 10 2 5 3 21 21 15 ^'}}, + {OUT=>'AB8BE94C5AF60D9477EF1252D604E58E27B2A9EE'}], + ['103', {IN=> {f=> '58 0 6 24 1 4 24 18 10 22 1 21 12 5 4 4 20 25 24 26 8 25 11 2 7 27 22 19 4 18 27 10 28 4 12 24 8 16 12 11 16 17 25 8 12 16 1 9 9 10 5 24 23 18 5 14 18 8 4 28 ^'}}, + {OUT=>'3429EC74A695FDD3228F152564952308AFE0680A'}], + ['104', {IN=> {f=> '61 0 5 17 8 28 1 22 4 11 3 2 17 3 14 9 27 13 18 24 9 8 7 28 25 14 21 27 24 6 18 16 2 12 15 9 14 10 1 8 17 4 6 15 26 11 15 2 28 20 26 16 3 7 5 8 9 26 10 12 25 11 22 ^'}}, + {OUT=>'907FA46C029BC67EAA8E4F46E3C2A232F85BD122'}], + ['105', {IN=> {f=> '53 0 9 13 24 15 20 2 4 8 2 22 20 19 4 15 14 28 13 25 10 10 12 28 24 22 26 28 15 9 11 26 19 22 27 2 21 8 20 23 26 12 10 21 9 15 13 25 7 26 1 13 5 9 20 ^'}}, + {OUT=>'2644C87D1FBBBC0FC8D65F64BCA2492DA15BAAE4'}], + ['106', {IN=> {f=> '58 0 3 9 21 22 7 1 23 28 1 2 8 22 12 18 28 5 18 14 7 11 17 20 20 7 21 13 8 28 21 22 2 16 20 15 28 9 3 22 13 10 23 4 16 11 14 1 10 8 14 14 15 18 13 12 21 18 25 28 ^'}}, + {OUT=>'110A3EEB408756E2E81ABAF4C5DCD4D4C6AFCF6D'}], + ['107', {IN=> {f=> '60 1 29 20 2 29 22 8 16 20 4 12 9 6 12 16 16 7 9 20 29 11 9 4 1 15 25 16 29 10 22 7 2 8 5 18 14 23 24 4 6 26 3 11 6 12 1 7 14 24 14 6 10 21 16 23 29 25 6 14 17 24 ^'}}, + {OUT=>'CD4FDC35FAC7E1ADB5DE40F47F256EF74D584959'}], + ['108', {IN=> {f=> '64 0 12 10 5 10 15 25 8 15 3 7 13 25 16 14 1 29 22 26 15 27 9 1 8 8 28 6 13 5 13 3 15 5 23 8 23 2 5 5 4 17 13 14 7 17 12 27 3 18 5 7 5 26 18 15 22 28 16 13 7 2 23 19 25 15 ^'}}, + {OUT=>'8E6E273208AC256F9ECCF296F3F5A37BC8A0F9F7'}], + ['109', {IN=> {f=> '56 1 17 7 16 25 23 11 11 15 2 13 9 26 2 24 26 7 28 11 2 29 7 22 23 5 28 19 1 27 29 1 24 11 18 20 3 13 11 7 3 15 17 24 1 18 13 6 3 25 27 16 28 18 24 8 23 22 ^'}}, + {OUT=>'FE0606100BDBC268DB39B503E0FDFE3766185828'}], + ['110', {IN=> {f=> '51 1 29 28 6 28 14 12 28 27 22 4 14 25 1 3 9 7 11 14 15 16 10 19 12 19 11 20 13 28 4 27 28 7 27 12 4 28 21 17 22 20 17 15 15 23 22 13 12 21 22 21 29 ^'}}, + {OUT=>'6C63C3E58047BCDB35A17F74EEBA4E9B14420809'}], + ['111', {IN=> {f=> '64 1 12 14 12 18 27 8 7 4 9 14 16 15 8 11 21 20 10 10 21 23 20 2 11 23 1 11 1 5 3 23 16 15 27 14 5 16 3 22 2 3 24 3 19 29 4 4 10 8 20 14 15 1 26 12 27 25 4 28 22 11 19 19 24 9 ^'}}, + {OUT=>'BCC2BD305F0BCDA8CF2D478EF9FE080486CB265F'}], + ['112', {IN=> {f=> '60 1 20 8 9 5 25 19 17 19 15 7 24 24 21 3 20 16 8 3 17 28 18 29 9 23 9 10 29 4 12 24 15 5 8 22 17 29 12 3 8 29 15 21 21 4 7 20 7 10 7 26 10 16 24 6 7 12 8 12 15 17 ^'}}, + {OUT=>'CE5223FD3DD920A3B666481D5625B16457DCB5E8'}], + ['113', {IN=> {f=> '60 0 9 17 11 28 12 26 26 6 29 13 10 20 6 23 10 4 3 26 26 14 20 20 25 14 13 15 24 14 11 4 23 27 24 20 9 16 17 24 13 12 6 1 14 26 25 7 8 21 1 19 3 2 2 17 21 13 5 9 21 11 ^'}}, + {OUT=>'948886776E42E4F5FAE1B2D0C906AC3759E3F8B0'}], + ['114', {IN=> {f=> '54 0 25 1 27 24 6 23 16 5 1 20 29 22 25 9 25 10 3 28 28 25 19 18 16 24 14 15 5 28 12 28 26 29 2 15 15 9 5 18 19 22 12 15 4 6 15 24 16 9 4 26 25 18 27 12 ^'}}, + {OUT=>'4C12A51FCFE242F832E3D7329304B11B75161EFB'}], + ['115', {IN=> {f=> '61 1 20 4 26 12 3 22 1 22 30 3 28 10 9 24 14 29 6 30 3 10 20 14 6 3 19 21 21 28 16 18 11 30 11 20 30 1 9 8 11 5 19 10 24 4 22 4 2 26 5 15 20 8 3 13 30 18 8 1 25 28 19 ^'}}, + {OUT=>'C54BDD2050504D92F551D378AD5FC72C9ED03932'}], + ['116', {IN=> {f=> '56 1 20 15 21 18 18 12 16 13 24 9 21 2 28 6 1 23 9 18 27 27 4 9 13 10 8 14 16 15 12 11 14 21 14 10 11 25 17 17 30 21 13 27 26 26 22 14 13 17 21 19 9 9 20 23 13 28 ^'}}, + {OUT=>'8F53E8FA79EA09FD1B682AF5ED1515ECA965604C'}], + ['117', {IN=> {f=> '59 1 10 28 24 10 22 27 23 27 8 17 14 6 4 21 26 15 1 8 29 27 6 28 15 3 27 25 25 14 19 13 29 8 24 2 8 2 4 12 19 11 10 6 26 14 22 24 30 10 11 12 2 12 17 23 8 8 12 28 12 ^'}}, + {OUT=>'2D7E17F6294524CE78B33EAB72CDD08E5FF6E313'}], + ['118', {IN=> {f=> '56 0 14 28 2 17 4 8 3 26 9 23 21 30 30 20 4 13 28 29 9 3 17 7 19 30 28 1 2 20 9 12 24 15 30 20 27 3 23 11 6 29 25 23 26 17 20 10 22 15 23 6 25 5 4 30 2 29 ^'}}, + {OUT=>'64582B4B57F782C9302BFE7D07F74AA176627A3A'}], + ['119', {IN=> {f=> '63 1 23 15 27 14 26 1 1 7 19 12 7 6 20 18 14 4 15 17 28 7 11 7 8 9 22 17 12 5 23 18 25 18 6 12 26 30 12 30 14 3 1 18 10 20 27 21 8 6 24 26 20 11 24 7 2 4 18 15 14 30 16 19 14 ^'}}, + {OUT=>'6D88795B71D3E386BBD1EB830FB9F161BA98869F'}], + ['120', {IN=> {f=> '52 0 27 15 4 19 25 29 29 7 14 18 9 11 9 27 11 15 29 9 28 20 2 30 26 21 17 8 28 17 22 29 24 8 11 18 29 15 6 7 27 27 17 24 18 23 11 19 8 30 5 24 22 24 ^'}}, + {OUT=>'86AD34A6463F12CEE6DE9596ABA72F0DF1397FD1'}], + ['121', {IN=> {f=> '66 1 25 15 28 23 5 10 21 5 8 7 3 10 19 17 6 9 15 29 10 7 4 1 16 21 16 29 13 18 5 3 8 15 8 21 29 20 5 27 2 13 27 7 7 30 2 18 26 10 2 5 29 21 15 25 26 24 8 12 20 3 9 10 30 7 12 29 ^'}}, + {OUT=>'7EB46685A57C0D466152DC339C8122548C757ED1'}], + ['122', {IN=> {f=> '53 1 30 26 20 11 22 19 27 2 16 10 6 4 24 17 20 25 20 15 8 23 23 20 30 18 16 3 30 15 26 23 28 7 21 8 7 31 31 14 26 18 3 1 26 28 15 25 11 31 3 25 9 21 30 ^'}}, + {OUT=>'E7A98FB0692684054407CC221ABC60C199D6F52A'}], + ['123', {IN=> {f=> '67 0 2 6 14 4 9 5 28 8 17 22 1 4 8 7 10 14 19 10 14 8 27 9 24 26 4 30 11 8 19 5 21 7 2 27 20 16 20 20 22 14 13 16 26 14 10 3 25 22 25 23 21 10 15 15 29 8 13 4 2 13 22 20 7 4 20 31 23 ^'}}, + {OUT=>'34DF1306662206FD0A5FC2969A4BEEC4EB0197F7'}], + ['124', {IN=> {f=> '65 0 2 2 28 13 19 14 12 23 27 6 2 14 2 22 6 25 30 29 31 13 14 16 31 12 16 30 5 14 31 11 4 1 1 25 21 13 26 22 21 5 22 14 29 1 21 3 14 30 4 2 29 12 15 23 3 15 5 1 6 23 22 13 1 14 23 ^'}}, + {OUT=>'56CF7EBF08D10F0CB9FE7EE3B63A5C3A02BCB450'}], + ['125', {IN=> {f=> '59 1 25 5 15 6 13 3 22 11 23 31 24 6 5 20 4 14 3 29 8 29 19 7 29 23 25 28 19 11 15 27 21 14 1 19 20 26 12 7 12 1 18 13 29 28 23 29 14 23 7 1 9 29 24 5 30 18 5 25 30 ^'}}, + {OUT=>'3BAE5CB8226642088DA760A6F78B0CF8EDDEA9F1'}], + ['126', {IN=> {f=> '55 1 31 25 13 7 24 25 24 1 12 19 9 7 6 28 20 14 28 21 19 31 20 20 6 24 18 27 24 4 18 21 1 31 15 1 15 2 27 4 26 25 4 23 19 2 31 22 30 21 22 5 27 12 30 28 31 ^'}}, + {OUT=>'6475DF681E061FA506672C27CBABFA9AA6DDFF62'}], + ['127', {IN=> {f=> '62 0 27 15 18 14 25 15 17 7 28 11 28 29 30 1 17 12 10 2 18 20 21 2 11 12 5 4 12 25 14 5 5 24 22 18 31 15 22 29 11 3 21 31 21 27 3 28 7 10 25 2 15 30 9 30 7 22 15 9 3 20 24 14 ^'}}, + {OUT=>'79D81991FA4E4957C8062753439DBFD47BBB277D'}], + ['128', {IN=> {f=> '60 0 28 14 18 9 27 14 22 27 31 10 8 14 7 15 7 20 5 26 1 29 7 17 17 8 3 13 27 18 8 31 27 28 22 22 17 19 18 18 11 19 13 25 10 19 6 28 4 31 23 10 18 26 31 5 10 13 12 8 15 27 ^'}}, + {OUT=>'BAE224477B20302E881F5249F52EC6C34DA8ECEF'}], + ['129', {IN=> {f=> '60 1 24 22 4 29 22 31 28 20 4 16 21 3 1 15 5 15 6 30 3 29 29 7 27 20 2 20 31 22 26 9 29 16 4 26 32 17 20 14 28 17 19 6 24 11 26 28 5 18 15 8 16 20 21 4 9 12 4 8 17 29 ^'}}, + {OUT=>'EDE4DEB4293CFE4138C2C056B7C46FF821CC0ACC'}], + ['130', {IN=> {f=> '69 1 5 3 11 15 12 24 31 23 1 6 28 2 8 31 6 7 30 5 19 23 12 6 9 31 19 17 24 25 22 6 12 16 3 7 9 9 11 29 4 11 2 5 13 29 10 12 30 32 18 28 18 27 3 30 4 4 26 6 13 31 13 2 11 7 24 4 17 29 12 ^'}}, + {OUT=>'A771FA5C812BD0C9596D869EC99E4F4AC988B13F'}], + ['131', {IN=> {f=> '95 0 21 19 21 23 11 42 36 2 13 4 1 33 22 16 27 9 4 33 16 3 30 15 11 32 13 17 38 32 9 38 4 36 15 32 27 19 42 18 6 36 22 10 29 12 25 40 15 29 23 28 30 4 8 11 24 9 10 31 28 43 23 16 29 33 5 40 26 3 19 12 36 43 5 35 37 5 14 11 45 35 16 10 8 32 4 15 35 26 2 39 22 37 22 30 29 ^'}}, + {OUT=>'E99D566212BBBCEEE903946F6100C9C96039A8F4'}], + ['132', {IN=> {f=> '106 1 18 14 51 2 6 32 51 9 32 50 44 46 51 8 11 53 45 55 16 10 3 52 8 20 20 46 46 13 32 2 46 50 43 25 54 9 31 29 2 47 15 29 24 45 44 18 37 14 28 39 36 44 47 16 50 10 44 24 53 35 22 40 20 15 51 22 18 22 42 6 54 49 38 21 7 13 30 16 7 52 16 22 13 38 7 11 44 33 9 25 13 37 42 14 45 53 30 38 5 25 5 35 38 22 28 53 ^'}}, + {OUT=>'B48CE6B1D13903E3925AE0C88CB931388C013F9C'}], + ['133', {IN=> {f=> '127 0 58 35 43 28 5 28 63 8 12 25 9 47 53 29 62 7 37 2 3 48 5 12 55 56 28 35 12 63 6 58 27 27 48 44 35 14 17 22 56 10 8 1 16 15 42 63 14 51 57 19 41 7 8 56 47 34 52 22 48 60 43 9 1 52 4 21 49 61 18 50 23 13 46 62 23 45 62 9 56 18 23 31 8 30 27 36 13 38 4 58 53 47 24 18 41 58 19 12 18 52 42 29 44 45 26 63 34 32 41 64 15 26 55 19 2 49 6 30 53 13 54 12 53 37 12 37 43 ^'}}, + {OUT=>'E647D5BAF670D4BF3AFC0A6B72A2424B0C64F194'}], + ['134', {IN=> {f=> '148 0 60 4 51 47 58 38 17 63 33 23 28 43 12 69 70 33 17 12 50 18 18 36 45 2 67 4 45 20 4 33 38 29 45 8 22 58 39 71 38 32 53 35 19 53 31 29 51 35 4 63 18 33 26 47 70 9 64 62 63 30 15 1 35 28 16 40 20 14 50 33 19 38 30 27 55 10 16 46 47 7 55 12 53 26 56 33 29 55 25 17 48 43 21 43 18 24 63 27 68 46 38 33 35 10 18 11 27 5 9 58 35 70 36 36 39 47 2 10 66 47 5 18 21 44 71 51 57 3 22 7 56 55 28 25 14 40 16 24 48 37 66 50 24 45 18 39 53 55 ^'}}, + {OUT=>'65C1CD932A06B05CD0B43AFB3BC7891F6BCEF45C'}], + ['135', {IN=> {f=> '165 1 15 62 35 29 15 40 19 76 67 4 5 71 46 61 26 8 77 48 1 23 12 60 40 24 44 33 29 42 73 66 49 61 20 30 1 54 52 42 39 64 23 65 37 24 20 11 26 66 22 77 22 57 7 38 57 33 61 73 7 64 1 49 35 76 14 27 21 45 68 38 58 73 13 72 47 73 33 8 66 23 38 4 56 77 47 10 71 13 20 31 41 6 51 3 18 17 61 47 14 48 76 46 28 34 43 1 56 4 25 7 65 41 1 34 37 23 59 59 27 26 13 15 14 75 60 14 1 28 59 26 65 61 16 23 17 28 6 19 2 35 49 30 29 48 2 63 73 59 1 3 76 41 11 19 18 43 54 63 67 51 4 9 78 60 66 ^'}}, + {OUT=>'70FFAE353A5CD0F8A65A8B2746D0F16281B25EC7'}], + ['136', {IN=> {f=> '181 0 18 19 84 17 12 10 57 18 77 51 52 16 39 74 49 52 63 38 72 2 15 64 83 62 49 56 11 26 68 58 83 33 23 50 63 71 53 27 84 22 39 41 52 58 11 64 7 60 45 70 22 5 73 38 30 30 48 21 75 80 40 21 8 53 9 26 30 34 81 71 71 51 23 75 33 41 23 32 5 8 66 40 72 40 16 66 45 14 48 34 21 41 27 3 55 27 37 23 41 65 4 57 51 74 22 19 75 42 16 19 46 16 10 48 20 19 37 41 14 57 9 17 55 38 5 60 7 46 20 43 36 39 52 20 10 62 45 23 46 7 35 75 29 70 35 36 34 25 12 15 84 26 10 6 71 29 79 33 32 25 59 76 82 64 58 7 8 19 41 74 2 53 65 24 1 55 51 36 21 79 7 ^'}}, + {OUT=>'CC8221F2B829B8CF39646BF46888317C3EB378EA'}], + ['137', {IN=> {f=> '184 1 60 66 66 6 3 9 73 12 7 40 70 18 71 70 65 51 14 14 27 50 9 87 81 50 22 19 40 37 16 79 12 34 37 76 82 10 61 7 81 49 67 26 45 82 50 81 63 45 69 31 31 76 51 9 59 34 51 54 34 83 10 33 51 86 81 82 69 18 8 22 64 19 86 62 58 33 37 17 34 5 29 83 42 76 50 54 66 39 9 1 36 43 17 65 6 35 56 72 71 83 88 10 1 8 87 22 6 21 78 25 89 43 62 40 55 85 31 89 74 63 46 28 24 26 31 17 7 8 27 19 12 85 17 20 27 77 10 2 54 80 17 52 74 76 69 78 11 20 80 4 29 24 85 75 18 39 23 70 83 29 57 67 72 70 33 4 15 46 42 2 69 13 53 33 69 64 33 64 14 40 69 59 78 54 ^'}}, + {OUT=>'26ACCC2D6D51FF7BF3E5895588907765111BB69B'}], + ['138', {IN=> {f=> '193 1 68 43 95 53 38 58 55 28 20 16 67 48 17 86 32 44 68 67 28 16 14 79 25 15 72 67 50 80 18 30 10 75 1 60 45 87 78 28 95 49 63 70 59 26 6 51 73 60 65 18 26 8 87 5 58 31 25 57 40 46 78 57 34 78 61 36 66 57 38 80 22 32 68 71 30 74 37 81 66 77 66 55 2 51 24 93 61 40 68 45 61 12 63 24 89 59 52 72 43 20 20 69 36 40 88 46 9 62 55 77 84 20 18 6 77 15 52 39 75 3 26 4 85 17 62 29 11 92 46 58 29 59 28 42 80 71 96 2 49 85 37 63 4 61 14 2 53 87 25 86 6 75 76 93 41 39 93 92 42 56 41 63 26 28 18 77 11 50 78 79 1 12 12 91 29 13 58 5 56 92 66 59 4 39 47 95 5 5 62 33 13 80 27 ^'}}, + {OUT=>'01072915B8E868D9B28E759CF2BC1AEA4BB92165'}], + ['139', {IN=> {f=> '203 1 35 28 11 7 20 7 17 3 3 30 89 13 65 56 66 63 22 82 16 31 55 56 77 91 91 71 101 13 10 85 101 95 17 99 98 91 33 14 20 48 32 7 64 29 38 35 25 4 95 23 34 1 85 81 23 31 96 71 84 50 15 79 47 25 51 45 35 66 19 61 60 9 31 93 64 70 30 42 86 53 1 71 46 42 22 38 96 10 99 34 76 26 55 73 63 63 97 23 92 81 64 46 1 30 31 35 86 91 88 64 87 16 37 69 84 94 60 100 3 47 52 8 71 87 57 29 76 43 18 45 46 15 65 12 44 42 66 60 15 68 19 58 39 62 76 9 92 101 57 32 4 34 15 41 62 32 89 71 43 35 31 41 21 17 82 33 96 27 62 29 82 57 46 62 15 24 99 37 83 40 52 46 56 80 98 3 91 74 6 27 7 58 94 10 41 79 97 84 77 74 26 99 35 ^'}}, + {OUT=>'3016115711D74236ADF0C371E47992F87A428598'}], + ['140', {IN=> {f=> '212 1 26 101 17 91 45 97 80 59 102 30 68 4 85 9 4 39 16 18 85 70 11 87 62 72 78 38 3 41 53 82 82 35 18 13 94 64 52 39 77 59 26 9 65 46 64 98 32 29 86 79 16 63 54 76 56 98 16 98 78 22 72 33 103 104 52 84 12 65 15 85 101 97 84 31 51 26 100 100 38 80 13 2 78 7 24 44 84 103 27 7 28 16 33 99 25 103 54 14 42 62 87 92 27 22 42 5 52 100 84 73 72 63 24 48 56 52 23 5 17 76 31 1 95 58 43 60 50 62 30 23 35 79 20 35 3 72 32 45 51 87 41 84 27 79 77 70 102 15 54 15 100 8 52 69 105 3 30 84 42 93 66 89 69 74 24 33 42 97 4 38 99 106 13 93 6 106 74 100 54 45 21 59 56 37 9 50 32 75 79 31 77 9 61 1 8 68 6 60 81 7 100 99 14 61 48 25 73 26 70 72 94 34 ^'}}, + {OUT=>'BF30417999C1368F008C1F19FECA4D18A5E1C3C9'}], + ['141', {IN=> {f=> '233 0 11 98 110 88 35 110 35 64 49 88 93 28 85 6 78 65 90 52 24 97 51 39 51 59 23 1 3 49 33 11 78 27 35 55 64 5 102 4 70 25 56 58 38 66 11 31 96 66 104 59 41 86 58 29 79 41 40 72 51 12 92 34 52 44 69 104 21 97 89 96 48 21 4 61 40 28 67 34 23 85 44 22 62 52 33 84 23 30 73 74 4 79 12 81 47 80 53 47 89 40 19 80 62 34 61 29 41 95 43 1 70 63 55 53 18 19 13 48 10 19 89 49 4 52 53 56 76 10 8 104 77 15 28 38 75 109 3 85 90 8 40 8 93 90 43 39 14 60 17 36 78 56 105 80 35 75 36 58 82 50 100 98 45 74 13 66 95 72 71 95 34 14 98 72 33 38 37 52 6 14 107 59 3 29 61 67 98 92 5 93 17 98 36 87 41 75 71 57 88 17 25 91 84 3 58 20 92 69 51 50 36 31 14 25 18 30 18 1 41 104 30 82 59 87 70 34 96 28 47 62 81 103 48 ^'}}, + {OUT=>'62BA49087185F2742C26E1C1F4844112178BF673'}], + ['142', {IN=> {f=> '234 1 63 90 108 108 102 64 82 88 4 111 76 97 22 1 108 41 34 91 33 20 25 24 26 8 83 11 31 7 85 109 106 4 105 85 68 28 33 99 53 8 16 12 11 74 17 83 66 70 16 30 9 67 68 34 24 81 47 92 72 47 37 33 38 92 17 8 28 88 22 62 69 32 89 75 3 72 96 85 13 105 24 38 37 94 115 83 72 108 114 24 93 76 103 60 99 102 9 43 10 59 95 46 33 93 15 26 69 44 2 86 107 55 45 61 65 92 66 9 55 39 70 83 29 98 67 13 111 15 20 31 62 8 2 51 20 19 33 44 14 115 71 112 97 10 41 28 53 51 26 57 15 38 98 55 106 22 56 31 50 95 107 110 84 70 10 108 96 73 100 25 36 55 88 71 63 96 30 90 96 79 22 7 30 23 28 59 89 8 51 99 47 86 34 18 43 65 98 104 107 49 7 79 71 8 57 21 29 80 2 74 78 44 57 9 61 22 13 68 52 91 74 98 43 30 58 68 95 101 72 102 76 42 99 61 ^'}}, + {OUT=>'E1F6B9536F384DD3098285BBFD495A474140DC5A'}], + ['143', {IN=> {f=> '249 0 27 117 45 119 80 2 59 52 8 76 20 94 102 69 96 42 46 106 67 9 110 89 71 69 34 31 15 85 16 29 100 82 37 62 68 95 108 44 23 114 34 36 56 93 11 30 96 12 31 67 14 114 14 66 70 30 81 46 53 119 85 6 104 47 92 72 70 5 70 15 115 68 105 33 97 13 85 106 14 61 29 22 86 45 57 69 91 38 38 28 66 13 60 95 103 3 15 5 113 38 23 62 5 65 94 107 73 104 37 47 102 117 3 78 35 7 95 56 78 45 52 28 46 43 37 32 53 19 55 29 47 97 76 115 83 71 11 45 62 73 99 116 2 24 116 7 28 41 2 29 37 52 23 5 118 79 31 57 89 61 24 101 78 50 93 73 41 7 33 45 47 24 1 48 73 36 3 25 87 46 28 108 54 68 53 67 119 28 36 118 104 42 88 27 112 4 74 85 1 63 39 97 71 74 75 76 10 49 12 79 11 50 103 118 94 117 118 37 27 12 94 60 28 51 47 82 110 17 15 105 23 52 43 12 21 22 81 41 12 74 90 42 108 117 98 67 4 69 85 ^'}}, + {OUT=>'B522DAE1D67726EBA7C4136D4E2F6D6D645AC43E'}], + ['144', {IN=> {f=> '243 0 76 81 26 101 13 68 62 106 87 19 98 32 81 63 79 93 31 121 123 75 52 11 66 41 54 87 38 5 104 62 51 38 55 29 31 120 44 16 48 94 46 105 91 66 78 27 43 6 64 2 55 79 75 84 113 22 4 113 109 31 33 17 96 11 29 63 98 103 107 116 34 14 9 95 38 18 51 75 33 109 118 55 66 4 76 7 75 70 82 74 23 1 26 69 40 112 99 47 65 31 70 119 52 103 88 85 86 28 16 12 76 25 22 78 64 21 86 27 61 77 72 108 2 18 106 119 121 54 16 85 72 2 73 26 88 66 60 80 35 24 117 63 24 44 67 52 122 119 33 72 16 99 98 69 54 19 42 28 53 114 32 117 81 100 57 49 123 56 21 68 80 53 95 1 45 95 107 98 87 1 27 24 99 116 16 67 1 113 91 84 25 40 25 72 3 28 90 87 112 80 16 117 45 77 36 90 105 59 88 122 64 108 108 71 98 18 50 115 93 105 77 35 6 46 55 47 102 4 26 87 111 120 81 113 4 57 105 3 84 94 115 61 73 ^'}}, + {OUT=>'E9A021C3EB0B9F2C710554D4BF21B19F78E09478'}], + ['145', {IN=> {f=> '255 1 91 47 51 9 57 9 55 94 61 61 68 46 107 6 35 81 114 78 96 74 14 89 73 67 67 69 113 107 11 98 113 109 20 92 17 67 70 88 57 10 124 9 60 122 93 91 45 7 15 24 51 5 98 115 24 49 90 104 117 66 128 94 64 80 12 43 91 46 111 59 58 77 30 14 88 60 123 68 41 44 68 40 104 118 41 43 93 90 105 92 16 127 26 54 125 114 79 71 24 48 21 25 118 40 103 49 91 44 67 65 25 119 109 18 48 23 69 112 38 61 64 87 84 104 119 110 122 92 22 1 8 83 34 100 32 62 41 46 112 34 102 76 56 39 4 127 30 13 19 110 124 7 16 128 95 4 124 11 104 116 126 49 95 3 55 96 70 90 101 4 122 96 75 118 39 128 99 92 18 42 20 87 83 35 75 111 61 67 71 28 101 9 56 34 105 95 71 23 73 71 26 57 15 23 76 55 99 89 128 98 117 68 43 88 62 38 62 39 2 83 36 15 26 60 128 96 73 74 10 1 12 42 22 2 77 33 33 32 57 13 14 82 57 12 39 3 58 80 14 87 85 44 69 109 119 ^'}}, + {OUT=>'DF13573188F3BF705E697A3E1F580145F2183377'}], + ['146', {IN=> {f=> '283 0 102 55 53 41 60 88 25 67 58 76 44 22 68 118 108 40 95 96 81 90 85 28 77 18 11 37 72 93 60 110 124 119 95 131 91 37 109 126 8 73 69 72 80 17 83 5 76 20 32 15 10 1 103 18 22 116 98 9 51 104 102 44 33 15 12 24 31 89 1 6 28 101 8 64 72 106 30 5 52 89 111 39 108 64 85 17 57 124 22 105 78 115 3 40 108 66 108 77 128 103 44 35 38 13 95 10 111 63 98 117 61 51 126 69 96 70 70 59 39 13 97 33 112 2 77 7 123 70 83 29 66 67 49 79 19 104 115 14 60 2 55 40 71 33 28 114 51 91 17 46 45 128 57 87 62 25 115 38 50 55 90 74 8 51 102 79 43 94 36 122 94 12 41 36 25 104 91 24 7 99 80 30 126 32 63 122 107 114 27 28 79 41 12 35 51 115 122 70 22 79 65 2 88 27 17 59 15 23 44 57 5 65 6 26 78 80 125 93 84 100 45 22 129 68 36 111 74 118 11 50 42 120 47 21 8 86 112 26 67 60 99 45 93 47 8 38 59 52 56 124 20 82 18 117 24 18 46 106 19 117 26 41 47 45 130 7 15 1 4 5 100 10 85 50 44 11 48 92 119 108 42 118 125 ^'}}, + {OUT=>'188835CFE52ECFA0C4135C2825F245DC29973970'}], + ['147', {IN=> {f=> '272 0 8 61 99 70 96 20 87 123 134 82 22 2 110 118 33 86 5 7 5 94 56 15 60 96 54 13 22 55 99 4 25 105 17 37 69 10 38 117 117 30 70 13 9 109 115 62 94 52 66 117 100 135 7 75 23 5 81 110 31 118 29 1 62 11 41 88 109 119 102 37 3 30 123 47 31 56 134 29 124 116 118 99 21 56 77 91 23 37 135 81 44 51 67 95 51 133 30 57 67 116 122 48 100 7 132 97 106 69 93 4 95 125 102 103 119 81 57 133 96 37 118 50 117 113 81 127 17 45 103 32 121 129 60 43 65 127 30 36 132 110 52 53 35 71 12 76 22 72 130 112 99 76 26 21 73 63 63 97 23 58 115 132 114 1 132 31 35 18 23 54 30 53 118 37 35 84 94 60 100 3 47 18 110 105 87 57 63 76 43 52 45 46 49 65 12 10 42 66 60 117 34 19 92 5 28 76 9 126 101 125 32 38 34 15 7 62 32 21 3 43 69 31 109 123 51 116 135 130 129 130 63 14 57 80 62 15 126 31 105 83 108 120 80 124 46 98 105 91 6 6 27 7 58 128 78 7 79 63 84 77 74 128 65 61 95 121 17 24 123 117 51 122 ^'}}, + {OUT=>'41B615A34EE2CEC9D84A91B141CFAB115821950B'}], + ['148', {IN=> {f=> '284 0 44 71 43 20 126 58 53 47 98 18 19 119 93 29 70 39 94 112 44 115 135 98 82 10 67 29 102 113 68 80 19 75 1 91 114 87 80 7 40 37 86 120 16 104 136 117 82 138 32 65 114 119 137 121 8 12 46 126 26 119 73 130 60 76 113 100 14 133 26 116 34 120 80 95 84 53 15 24 44 51 4 10 23 77 24 99 66 37 54 63 42 136 21 34 76 5 17 128 101 1 59 40 113 112 32 97 31 93 105 79 91 18 39 1 103 132 51 68 124 111 13 97 43 128 69 84 85 72 15 12 26 87 16 16 92 101 13 77 4 118 89 103 56 42 16 60 44 39 126 46 18 83 93 41 105 3 82 106 115 91 6 4 54 115 15 120 109 113 48 41 9 95 20 62 67 105 111 25 132 7 116 46 138 44 83 61 124 131 35 107 6 109 81 114 67 41 137 77 56 74 73 34 12 14 69 52 11 98 47 54 83 81 6 1 15 88 35 139 80 83 49 89 27 47 130 92 133 87 51 112 76 49 109 49 57 93 73 22 117 50 64 58 97 139 36 131 111 133 58 33 8 88 55 38 90 46 30 118 57 29 82 74 41 117 38 46 94 92 5 105 15 117 70 103 68 60 120 48 21 110 85 40 81 66 ^'}}, + {OUT=>'AB3DD6221D2AFE6613B815DA1C389EEC74AA0337'}], + ['149', {IN=> {f=> '291 0 46 113 52 134 79 74 64 57 18 23 9 52 8 16 103 57 138 59 59 65 92 2 7 130 92 8 34 40 86 131 140 100 112 4 42 1 110 108 43 37 15 67 19 35 94 61 130 98 35 88 34 65 104 56 126 118 50 87 10 81 109 90 86 118 32 6 114 88 39 38 39 62 3 12 134 72 137 35 75 81 115 106 140 112 11 123 41 103 45 95 84 71 107 13 26 110 96 62 16 109 84 59 53 38 27 8 28 13 32 137 17 138 41 122 36 99 65 99 83 36 112 29 49 70 96 126 136 131 116 3 18 17 126 142 14 37 141 141 123 42 13 20 83 42 139 83 54 49 58 42 7 137 29 48 16 121 127 34 52 140 106 128 58 36 124 83 24 69 54 61 112 17 6 95 97 24 57 86 124 59 71 119 67 1 109 54 68 49 57 132 32 5 71 113 40 80 104 75 106 133 31 126 130 104 62 9 39 44 66 116 141 135 96 132 19 41 121 126 124 77 8 4 60 82 6 101 124 89 51 123 48 40 85 77 21 112 10 69 66 115 87 16 108 30 84 65 80 103 32 131 134 73 47 10 63 39 50 93 37 135 114 69 48 34 58 23 27 133 37 9 40 98 41 115 99 70 83 29 42 67 133 55 79 80 91 122 12 2 115 112 47 ^'}}, + {OUT=>'0706D414B4AA7FB4A9051AA70D6856A7264054FB'}], + ['150', {IN=> {f=> '293 1 33 13 99 138 1 42 89 118 87 113 99 12 134 142 100 38 5 55 75 14 110 108 42 64 130 79 138 62 64 69 57 11 123 25 59 16 111 94 24 65 30 51 119 48 107 92 84 69 28 136 143 54 20 6 70 47 142 64 4 65 59 73 99 134 146 102 125 116 57 137 137 72 48 128 78 5 80 63 54 85 30 22 129 68 21 21 74 28 128 107 27 60 2 93 95 71 37 11 37 15 39 102 3 104 65 80 59 52 113 34 20 67 60 27 81 135 46 106 106 102 68 128 17 15 100 124 15 43 136 122 100 67 142 35 14 53 120 2 89 93 99 73 9 122 39 77 15 96 90 43 79 134 60 92 105 55 96 31 119 77 97 72 23 140 38 30 43 83 136 88 107 117 72 109 118 58 91 119 73 95 100 59 138 123 54 49 143 50 133 66 106 45 80 88 42 93 5 59 77 101 74 110 104 40 92 19 77 76 86 102 129 3 144 101 139 134 56 90 18 91 94 85 55 10 137 11 58 1 107 113 70 22 7 56 29 143 111 8 46 45 116 122 129 89 7 121 53 95 14 49 118 62 125 91 37 97 15 35 100 63 140 63 50 51 58 26 127 6 45 59 102 121 114 85 141 135 10 72 19 106 66 66 41 53 13 38 1 21 103 50 108 46 119 ^'}}, + {OUT=>'3CBF8151F3A00B1D5A809CBB8C4F3135055A6BD1'}], + ['151', {IN=> {f=> '297 1 46 31 132 112 28 63 124 97 129 43 40 72 99 107 132 137 96 139 99 145 121 144 118 37 81 39 94 60 55 109 47 109 110 75 42 12 139 137 43 128 106 107 19 126 12 101 148 127 15 117 125 125 62 96 13 76 70 96 101 110 138 8 95 76 143 17 32 97 79 149 39 31 94 123 21 41 135 55 84 70 33 135 118 50 62 121 81 1 45 144 93 60 5 64 137 8 105 91 82 67 27 113 119 53 18 98 79 48 84 32 135 128 5 1 20 76 17 85 108 72 36 141 140 49 150 105 104 3 149 14 54 18 148 64 49 125 37 28 28 101 22 104 91 32 82 117 12 114 69 58 2 58 115 9 108 47 59 65 14 92 7 4 86 98 16 82 92 95 38 94 10 10 48 97 104 66 115 97 142 115 122 119 40 97 16 32 47 34 88 89 26 50 12 76 80 51 40 9 133 24 44 40 122 84 108 22 142 140 99 44 15 54 8 42 125 150 130 21 79 124 62 46 119 15 29 91 57 150 42 138 71 61 68 80 114 6 1 70 121 18 35 113 56 87 86 10 73 14 29 41 72 89 1 133 87 101 123 59 90 142 77 133 52 78 48 34 138 134 27 17 60 131 147 61 93 148 39 132 49 62 71 36 91 4 139 49 100 120 43 113 144 30 94 73 127 40 125 ^'}}, + {OUT=>'DA5D6A0319272BBCCEA63ACFA6799756FFDA6840'}], + ['152', {IN=> {f=> '313 1 35 97 95 76 105 88 32 138 30 69 61 40 47 21 107 6 39 81 114 53 125 53 147 14 4 73 146 96 98 13 136 11 98 117 138 153 67 146 71 99 88 7 139 24 13 35 47 97 145 74 36 119 3 51 84 48 119 53 49 15 79 17 120 103 148 64 30 41 97 120 75 111 63 58 131 134 18 13 10 48 18 16 48 43 15 54 18 41 47 122 144 80 92 145 77 1 33 89 54 46 78 48 21 54 43 40 53 24 16 73 42 94 29 44 34 151 152 23 123 12 142 140 43 37 88 29 19 35 72 96 151 130 62 112 34 36 91 120 50 112 138 2 105 60 68 137 131 5 17 19 139 74 11 120 78 149 58 128 15 104 16 126 78 20 57 134 71 49 90 76 108 126 100 54 68 39 132 153 42 147 146 124 62 87 35 75 61 65 46 100 82 105 113 31 63 5 95 54 71 77 127 150 80 36 144 2 130 59 74 39 3 152 121 122 18 117 12 117 141 118 135 62 36 69 5 39 53 150 52 153 143 30 66 96 126 131 56 137 8 7 86 142 14 7 111 141 93 136 137 134 43 12 89 23 44 9 152 146 121 97 19 38 110 91 67 14 32 110 66 68 8 130 84 73 118 59 24 41 72 121 150 55 37 138 27 104 66 124 9 51 109 47 125 109 148 8 29 47 72 146 149 61 93 10 20 54 15 76 133 125 106 110 67 ^'}}, + {OUT=>'FB4429C95F6277B346D3B389413758DFFFEEDC98'}], + ['153', {IN=> {f=> '330 0 23 9 26 136 27 51 115 122 44 106 6 146 108 113 85 51 8 96 47 56 137 62 59 89 143 71 140 14 85 156 139 99 154 30 53 115 35 147 108 148 58 52 28 103 19 92 95 152 152 10 11 13 155 67 11 83 101 69 153 152 45 141 14 120 129 140 119 59 2 89 73 70 83 29 16 67 81 29 1 54 65 96 117 2 37 47 128 33 3 89 108 98 139 49 78 27 103 39 119 94 132 90 38 132 55 65 131 90 58 2 54 100 69 118 22 44 19 7 148 93 25 29 123 81 64 131 55 30 1 89 38 97 82 64 9 28 86 123 151 10 133 40 154 102 4 111 65 9 63 59 124 116 72 105 76 57 137 97 32 145 108 78 112 50 43 34 75 20 22 129 68 11 118 74 125 118 57 17 20 129 53 65 61 144 1 17 142 156 52 100 54 15 20 59 52 63 131 20 57 124 31 125 46 106 76 92 8 98 154 152 80 114 15 140 136 112 100 17 92 25 151 150 80 99 69 83 49 43 156 102 19 57 122 96 30 3 39 134 40 32 75 5 76 127 138 99 17 57 52 150 130 18 127 33 23 116 107 78 77 77 42 69 68 48 41 69 33 75 40 49 128 103 4 146 93 10 83 66 96 152 30 38 12 33 5 39 47 41 34 60 74 20 42 156 67 46 56 102 89 3 124 81 99 104 56 50 8 61 74 55 15 87 108 28 138 47 93 60 2 124 46 126 103 91 145 36 25 116 122 51 ^'}}, + {OUT=>'2C6E30D9C895B42DCCCFC84C906EC88C09B20DE1'}], + ['154', {IN=> {f=> '322 0 75 7 107 158 81 105 154 90 20 125 77 114 69 92 7 58 21 98 154 50 128 149 117 127 153 45 3 18 121 86 29 71 79 101 2 5 22 143 10 27 53 146 157 148 112 33 22 80 123 24 147 1 112 82 159 63 74 97 109 33 151 32 89 87 132 117 46 129 59 115 91 114 118 37 21 9 94 60 25 89 47 79 110 55 12 143 99 87 43 88 56 57 160 76 12 71 128 77 146 117 95 105 42 66 3 76 20 76 101 100 118 149 45 26 143 148 32 57 39 129 19 31 84 123 1 152 135 5 54 30 13 125 68 30 62 101 51 142 5 94 83 20 116 24 107 109 105 91 42 17 27 93 69 3 139 68 79 38 84 2 85 128 126 122 131 46 17 35 98 42 26 111 100 29 120 55 84 114 109 145 14 18 138 14 9 85 7 18 129 91 2 94 51 133 82 87 123 64 39 8 103 38 75 110 78 7 9 45 115 42 138 135 86 78 16 62 52 75 159 54 151 121 149 77 74 16 85 47 102 105 82 119 10 67 137 153 148 135 28 49 26 151 153 36 80 11 130 113 24 44 30 102 24 58 133 122 140 99 24 156 54 119 42 115 140 90 132 19 94 2 157 99 136 19 71 7 130 153 108 51 21 58 70 74 137 1 40 111 149 5 103 6 27 76 141 23 125 140 1 72 29 152 103 87 51 93 29 80 132 77 123 153 68 159 14 98 114 158 121 158 81 131 ^'}}, + {OUT=>'3DE3189A5E19F225CDCE254DFF23DACD22C61363'}], + ['155', {IN=> {f=> '322 0 35 93 109 125 119 10 10 19 135 26 4 74 135 35 120 129 113 92 17 29 47 88 14 159 149 87 45 36 75 68 22 138 20 59 61 144 151 11 107 6 153 81 114 43 85 157 97 148 118 73 126 56 58 137 96 11 98 67 98 103 57 146 21 59 88 151 139 148 127 25 17 47 115 34 160 109 107 51 64 28 69 13 49 149 69 141 90 93 118 64 10 1 67 80 35 111 13 58 101 124 132 147 154 18 162 6 162 33 5 34 142 41 161 82 114 70 92 145 57 155 137 114 79 44 36 48 48 21 14 13 40 33 14 150 33 32 54 143 14 4 101 142 23 93 136 132 120 147 17 38 163 143 5 52 46 151 130 32 72 34 124 150 51 100 112 128 126 65 10 28 87 81 159 131 19 99 54 125 110 58 119 28 78 129 104 140 126 38 154 27 114 61 153 90 66 98 76 50 158 48 39 82 123 22 147 136 114 52 37 35 75 41 15 150 60 52 55 103 21 23 129 95 24 71 47 97 130 50 140 144 106 100 9 64 19 117 122 71 92 8 77 156 97 121 98 85 2 36 39 109 143 23 120 156 133 93 154 36 66 116 131 160 127 162 161 46 142 14 141 81 141 63 86 117 104 3 146 39 127 34 133 102 106 91 57 9 28 60 61 7 158 12 80 26 8 122 80 44 63 68 49 158 21 32 81 150 15 141 108 161 64 46 124 123 31 99 27 105 109 98 112 144 ^'}}, + {OUT=>'93530A9BC9A817F6922518A73A1505C411D05DA2'}], + ['156', {IN=> {f=> '336 1 34 161 107 149 48 67 138 109 156 104 37 133 60 80 84 81 160 9 16 96 164 1 95 112 4 86 163 116 98 103 55 31 8 56 37 36 127 32 9 89 103 31 100 161 85 106 119 89 154 43 115 162 137 108 128 38 42 155 103 9 62 65 102 122 10 138 160 125 47 158 43 91 69 123 132 35 121 4 110 89 130 69 29 139 69 53 70 83 29 163 67 41 9 108 34 45 76 87 2 144 164 98 33 160 79 78 48 89 9 38 134 93 146 79 54 122 80 38 112 55 55 101 70 8 129 44 70 59 98 149 24 136 124 138 63 25 166 83 51 34 91 45 30 118 59 28 87 72 44 116 28 36 103 101 113 10 114 62 111 71 65 126 53 19 114 86 42 85 36 57 137 57 159 95 88 78 72 20 23 14 65 10 22 129 68 1 68 74 75 108 7 7 147 109 13 35 51 104 158 164 122 126 2 50 4 132 127 59 52 13 81 20 47 107 74 148 115 46 106 46 82 115 68 144 142 60 104 15 90 136 102 100 134 42 15 141 100 40 49 49 73 166 13 156 82 166 37 82 96 137 130 166 134 20 139 45 122 56 107 98 79 124 17 32 130 120 165 77 23 130 96 67 68 47 37 12 29 18 38 158 19 160 55 147 39 118 83 121 96 43 137 33 66 86 112 147 155 149 140 5 19 17 148 161 10 44 159 146 57 16 26 102 49 3 104 61 59 74 56 10 165 31 54 25 142 157 37 58 165 128 154 73 50 149 94 137 ^'}}, + {OUT=>'E31354345F832D31E05C1B842D405D4BD4588EC8'}], + ['157', {IN=> {f=> '330 1 61 51 65 132 23 169 116 122 14 66 7 98 131 72 69 127 72 163 125 68 69 51 47 159 31 164 71 118 50 83 113 81 127 153 45 137 134 121 68 163 26 43 65 127 166 138 98 144 18 53 137 139 148 76 158 4 62 78 167 102 144 94 55 141 63 29 97 91 24 115 166 80 69 132 99 1 120 23 88 64 87 118 37 137 152 94 60 168 71 47 52 110 37 155 125 63 42 43 52 11 12 151 31 12 44 110 32 128 117 68 87 24 39 164 76 145 58 101 91 100 140 151 143 130 32 21 3 111 1 31 75 123 153 116 135 130 27 164 165 116 23 12 62 83 24 133 139 49 74 154 80 158 80 64 105 91 6 142 27 75 24 128 112 41 79 29 84 145 40 128 99 95 95 19 17 160 89 15 17 84 64 11 93 10 66 78 73 127 148 18 129 139 143 49 150 9 84 82 154 85 15 88 82 60 87 19 12 133 58 20 39 65 51 141 134 27 70 167 120 117 86 60 16 44 16 57 132 18 142 85 104 59 47 141 58 2 66 96 46 119 153 40 110 126 103 90 144 13 26 106 144 80 145 134 103 95 24 44 21 84 140 13 97 104 140 99 6 147 54 83 42 106 131 54 96 135 67 118 121 81 109 10 53 132 112 117 81 33 155 49 61 38 119 1 13 102 131 148 94 131 143 67 123 148 89 104 135 72 145 152 76 87 6 66 2 71 123 77 114 108 59 123 166 62 96 140 94 149 116 169 ^'}}, + {OUT=>'3FF76957E80B60CF74D015AD431FCA147B3AF232'}], + ['158', {IN=> {f=> '349 0 125 17 93 82 80 110 156 147 156 99 154 4 29 90 163 120 84 113 56 8 157 29 61 169 141 113 78 48 50 13 138 11 50 61 99 106 2 107 6 117 81 114 34 49 112 52 130 82 73 108 20 22 110 60 11 98 22 62 58 48 146 149 23 88 142 139 121 91 16 163 2 88 171 133 100 62 51 46 10 24 150 49 131 60 114 63 84 91 64 165 138 40 44 172 111 141 58 74 115 96 129 145 164 153 170 126 24 169 16 115 41 125 46 87 61 92 145 39 155 92 78 70 35 27 21 48 21 151 159 40 15 5 132 170 23 18 107 160 150 56 133 23 66 109 123 102 102 172 166 145 116 151 34 1 151 130 5 36 34 97 114 15 82 128 112 119 99 29 138 165 42 36 159 95 19 63 36 89 101 40 92 1 33 93 104 113 126 2 136 96 52 108 90 57 89 31 5 113 30 39 37 96 4 147 127 105 43 165 35 75 23 143 105 24 25 10 94 12 160 102 95 170 71 20 70 112 23 95 144 61 73 137 55 1 81 95 26 65 172 41 147 79 103 80 40 121 36 12 64 98 169 93 111 115 48 127 9 39 107 131 115 118 162 161 10 142 14 123 54 141 36 41 99 77 140 128 167 82 25 106 57 70 64 21 19 15 34 126 149 167 53 163 127 86 35 8 54 23 40 140 3 169 45 150 152 96 81 143 28 28 124 87 13 90 9 87 109 53 67 164 28 131 89 149 42 55 126 79 132 74 19 133 30 68 72 75 148 9 10 72 152 144 83 106 153 74 163 98 152 ^'}}, + {OUT=>'34AE3B806BE143A84DCE82E4B830EB7D3D2BAC69'}], + ['159', {IN=> {f=> '375 1 94 28 13 8 20 28 18 118 5 140 89 67 171 64 152 85 61 101 80 154 149 34 115 135 128 108 110 20 33 128 103 35 38 57 95 10 111 151 98 29 149 7 82 69 96 114 26 103 171 101 53 121 24 2 121 51 35 70 83 29 154 67 5 167 63 16 27 58 60 2 99 128 71 33 160 70 51 3 44 149 2 89 84 101 43 18 113 71 38 94 55 46 74 52 139 102 35 43 50 80 122 6 100 88 129 36 25 148 47 24 7 55 36 30 82 32 19 78 63 26 71 28 167 85 56 167 95 159 78 26 66 35 65 90 44 159 105 59 15 67 57 137 21 132 50 70 78 36 169 5 172 56 1 22 129 68 168 23 74 30 99 138 174 120 91 153 8 42 68 158 155 104 99 133 5 135 96 82 59 52 144 36 20 38 62 29 112 106 46 106 19 73 70 41 135 133 42 95 15 45 136 93 100 98 173 6 132 55 4 4 31 64 130 162 156 64 157 19 46 96 92 103 139 134 2 94 18 86 38 89 62 61 79 157 14 112 111 156 32 14 85 78 31 59 20 1 161 169 149 29 122 150 133 37 102 30 109 65 85 51 174 110 164 66 77 76 111 119 131 95 5 1 166 103 134 141 17 158 123 137 48 165 175 102 13 3 86 43 23 47 56 150 165 4 36 174 115 157 168 13 147 119 109 55 41 140 67 27 31 27 53 126 17 163 116 122 160 60 7 92 113 66 45 109 60 151 125 62 39 39 17 153 13 152 53 94 50 53 89 57 127 153 45 119 104 121 56 145 172 19 41 103 166 108 68 126 12 53 131 127 148 52 134 168 50 48 155 72 132 82 37 129 63 175 160 ^'}}, + {OUT=>'D7447E53D66BB5E4C26E8B41F83EFD107BF4ADDA'}], + ['160', {IN=> {f=> '366 1 73 15 79 139 71 51 132 81 135 111 166 61 37 60 118 37 92 134 94 60 150 53 47 25 110 19 137 107 27 176 43 16 145 146 142 165 12 17 92 166 110 117 41 69 6 12 164 76 109 40 101 82 82 131 134 115 143 112 32 164 146 93 162 31 66 123 144 80 135 94 137 156 107 157 173 62 65 176 124 112 4 65 127 44 131 53 19 105 91 149 106 27 57 158 92 85 14 79 20 84 127 174 128 72 68 59 171 17 124 80 167 8 57 28 172 66 144 48 42 37 109 121 18 120 103 116 13 132 39 73 145 76 158 43 82 33 51 153 164 97 13 2 3 20 24 114 98 9 25 131 102 99 86 42 16 26 159 39 105 161 133 49 59 41 20 105 31 136 30 87 10 119 135 13 83 99 58 45 99 156 26 61 135 143 80 118 107 76 77 24 44 12 66 95 147 61 86 140 99 167 138 54 47 42 97 122 18 60 90 40 73 85 63 82 1 35 96 94 81 54 15 128 40 52 2 101 1 165 93 113 130 85 95 98 58 105 112 53 68 108 72 100 152 49 87 140 39 154 62 114 77 105 63 50 87 157 26 78 122 67 140 71 170 119 5 93 64 50 104 144 129 138 75 130 4 178 60 139 120 54 113 32 2 133 17 43 163 129 89 72 149 155 30 38 7 138 5 44 61 69 76 175 107 6 93 81 114 28 25 82 22 118 58 73 96 175 177 92 36 11 98 171 38 28 42 146 125 178 88 136 139 103 67 10 151 151 70 153 115 94 32 51 34 177 173 132 49 119 54 96 45 78 73 64 159 120 22 20 154 111 117 58 56 109 72 143 ^'}}, + {OUT=>'77DD2A4482705BC2E9DC96EC0A13395771AC850C'}], + ['161', {IN=> {f=> '372 1 136 146 144 170 90 15 169 180 88 41 89 10 60 52 92 145 21 155 47 42 61 26 18 176 48 21 124 141 40 179 178 114 143 14 164 71 142 132 11 124 23 39 82 114 84 57 163 130 127 89 133 16 138 151 130 160 34 70 78 161 64 92 112 110 72 175 102 138 179 173 159 59 19 27 18 53 92 22 65 156 170 57 104 86 126 148 118 155 78 43 63 90 48 80 168 142 68 12 39 174 69 168 147 118 96 34 129 35 75 5 107 60 170 180 147 85 3 133 75 95 152 71 175 43 94 178 50 144 16 46 101 46 165 45 68 163 38 172 5 138 61 85 62 177 76 36 167 19 53 151 66 66 97 3 100 164 12 98 131 70 109 162 161 156 142 14 105 27 141 9 178 81 50 113 110 131 37 16 79 12 34 37 167 173 10 152 7 81 140 158 26 136 82 50 172 154 45 160 31 122 167 142 9 150 125 51 54 125 174 10 124 51 177 81 173 69 109 8 22 155 19 86 62 149 33 37 108 34 96 29 174 133 167 50 54 66 130 9 1 36 134 108 65 97 126 56 163 71 83 88 10 1 8 178 22 6 112 169 116 89 43 153 40 146 85 31 89 74 154 137 28 115 117 122 108 98 8 27 110 103 176 17 20 27 77 10 93 145 80 17 143 165 76 69 78 102 20 91 171 95 29 115 176 166 109 39 23 70 83 29 148 67 163 161 33 4 15 46 42 2 69 104 53 33 160 64 33 155 14 131 160 59 78 71 19 176 107 65 38 82 55 40 56 40 115 84 29 25 44 68 104 176 76 64 123 18 25 136 23 6 171 31 30 30 58 14 13 72 57 14 41 177 ^'}}, + {OUT=>'EAA1465DB1F59DE3F25EB8629602B568E693BB57'}], + ['162', {IN=> {f=> '363 0 135 69 16 167 79 143 46 178 26 3 65 58 36 135 97 35 175 51 152 57 137 173 108 10 54 78 4 153 173 164 48 177 22 129 68 168 167 74 174 91 106 174 96 75 129 168 34 36 158 147 88 75 101 149 103 64 42 59 52 112 180 20 30 22 173 80 98 46 106 179 65 30 17 127 125 26 87 15 5 136 85 100 66 141 182 124 15 156 148 15 56 98 146 156 48 149 3 14 96 52 79 115 134 170 54 178 54 22 73 30 45 39 133 182 96 103 148 176 6 45 62 183 51 180 153 145 145 117 21 90 118 109 21 62 22 101 49 53 11 142 86 132 66 69 44 79 87 115 55 5 169 150 63 110 109 177 150 91 129 40 149 159 102 165 3 70 27 175 23 56 126 165 164 20 158 91 157 136 157 131 111 69 39 33 132 43 19 175 179 37 118 9 155 116 122 128 52 7 84 89 58 13 85 44 135 125 54 183 23 161 145 173 136 29 62 50 13 57 25 127 153 45 95 64 121 40 121 140 171 9 71 166 68 28 102 4 53 123 111 148 20 102 160 34 8 139 32 116 66 13 113 63 143 97 63 10 59 124 66 41 132 71 115 106 151 46 22 45 118 37 67 124 94 60 140 43 47 10 110 9 127 97 7 156 43 180 125 126 137 145 12 2 82 146 100 117 26 59 180 181 164 76 89 30 101 77 72 126 114 95 143 102 32 149 131 83 157 31 61 123 139 60 135 74 169 122 151 102 137 168 62 55 166 119 97 163 60 112 24 116 38 178 105 91 134 86 27 47 138 72 70 183 79 15 84 117 154 128 57 53 39 161 88 ^'}}, + {OUT=>'9329D5B40E0DC43AA25FED69A0FA9C211A948411'}], + ['163', {IN=> {f=> '393 1 92 72 151 33 183 164 42 112 32 10 5 93 97 18 112 71 92 168 116 179 186 65 137 68 134 3 82 9 19 121 148 65 160 173 158 167 90 66 180 172 99 86 83 86 26 16 10 135 23 81 137 125 17 19 25 183 73 7 104 185 79 165 119 119 176 59 75 18 5 59 132 26 21 127 119 80 94 83 52 61 24 44 4 50 55 115 29 70 140 99 159 130 54 15 42 89 114 173 28 50 16 33 53 47 58 180 19 64 78 49 30 186 104 32 44 157 85 1 149 85 97 114 77 63 58 50 89 80 21 36 84 72 60 152 25 87 108 15 138 54 106 77 97 23 42 55 149 181 62 106 43 132 31 138 111 176 93 40 10 96 128 105 114 43 98 4 146 20 107 120 14 113 181 101 1 19 155 113 57 64 117 131 6 22 186 138 184 36 61 29 36 175 107 6 61 81 114 20 180 42 169 102 26 73 80 151 153 68 4 11 98 139 6 175 34 146 93 154 88 128 139 79 35 2 135 119 46 129 91 86 179 51 18 169 141 108 49 103 46 72 21 70 49 64 151 96 185 175 130 111 85 58 32 101 40 101 131 136 139 170 70 10 169 175 73 41 69 177 45 47 92 145 11 155 22 22 56 21 13 166 48 21 109 131 40 174 178 104 128 9 149 51 132 122 173 119 23 24 67 109 74 32 158 110 117 74 123 6 118 151 130 150 167 34 55 58 146 54 72 112 105 57 160 82 123 159 153 159 39 19 7 8 33 87 12 50 146 150 37 104 71 126 133 108 145 68 38 38 90 43 75 148 122 43 2 39 154 54 163 147 113 91 29 109 35 75 182 87 35 155 170 127 80 185 118 60 95 142 71 165 28 84 168 25 144 178 31 81 41 160 25 53 143 ^'}}, + {OUT=>'E94C0B6AA62AA08C625FAF817DDF8F51EC645273'}], + ['164', {IN=> {f=> '381 1 14 172 163 130 45 69 46 145 36 36 151 169 13 135 42 26 81 153 76 148 178 90 131 30 101 162 161 132 142 14 89 3 141 175 146 65 26 89 94 99 187 8 55 162 2 13 143 173 2 120 173 41 132 150 2 112 42 18 140 130 37 128 23 106 159 118 167 150 101 11 30 109 150 184 124 19 169 73 165 53 109 158 172 147 11 46 38 149 25 21 92 184 64 179 158 133 135 34 38 58 114 9 183 4 118 76 49 89 102 40 163 47 75 80 176 175 8 154 14 180 104 153 84 89 11 129 8 138 85 181 73 66 154 121 20 115 93 114 108 82 182 19 86 103 176 183 186 177 53 10 69 137 56 1 135 141 68 69 54 86 12 75 171 87 187 107 144 150 93 23 7 70 83 29 140 67 139 153 183 178 189 30 18 2 29 72 29 33 160 56 9 123 164 107 136 19 70 31 177 152 99 57 38 66 55 32 32 24 83 60 21 1 36 52 80 168 44 32 115 184 25 120 181 172 155 189 22 30 26 180 5 64 49 188 1 28 111 57 176 167 67 131 22 160 186 169 65 34 30 117 91 17 163 39 134 57 137 155 90 170 42 78 170 141 167 158 42 177 22 129 68 168 143 74 150 85 82 174 78 63 111 156 28 12 158 141 76 57 77 125 79 40 12 59 52 88 156 20 24 182 149 56 92 46 106 167 59 189 121 119 14 81 15 165 136 79 100 42 117 182 118 175 138 124 3 50 74 134 156 36 143 181 180 96 22 61 97 134 164 24 166 30 10 61 6 33 9 115 176 84 97 142 152 15 50 165 45 168 135 133 127 93 15 66 94 91 9 32 16 95 37 29 171 118 68 108 66 63 20 55 186 ^'}}, + {OUT=>'7FF02B909D82AD668E31E547E0FB66CB8E213771'}], + ['165', {IN=> {f=> '396 1 97 10 5 160 132 18 83 73 159 141 55 120 31 131 141 102 138 3 52 9 148 189 56 99 165 146 2 140 64 157 100 121 113 102 24 21 24 123 16 10 139 152 19 109 146 116 122 92 43 7 75 62 49 170 58 26 117 125 45 147 5 125 136 155 118 2 26 50 161 21 182 127 153 45 68 19 121 22 94 104 144 166 35 166 23 176 75 188 53 114 93 148 177 66 151 16 156 121 180 98 48 179 95 63 107 97 45 1 23 97 57 23 132 53 79 97 124 19 188 18 118 37 22 106 94 60 122 25 47 176 110 184 109 79 164 120 43 153 89 90 128 109 12 168 64 110 82 117 192 41 171 163 164 76 53 12 101 68 54 117 78 59 143 84 32 122 104 65 148 31 52 123 130 24 135 38 151 95 142 93 101 159 62 37 148 110 70 127 51 85 181 89 11 142 105 91 107 50 27 29 102 36 43 165 79 6 84 99 118 128 30 26 3 143 17 68 66 139 187 15 165 158 24 88 20 179 174 81 79 18 106 47 74 150 104 179 162 59 131 62 116 166 82 184 188 97 136 41 136 167 140 143 175 72 42 174 148 75 74 71 86 14 16 191 117 11 63 119 119 186 182 13 171 49 182 80 167 73 147 119 107 164 41 57 181 168 29 114 26 184 121 101 80 76 65 34 49 24 44 191 38 25 91 5 58 140 99 153 124 54 184 42 83 108 155 4 20 191 3 29 35 40 180 7 40 66 25 12 180 86 26 38 139 73 1 137 79 85 102 71 39 28 44 77 56 190 12 66 72 30 152 7 87 84 190 126 48 100 77 91 186 36 31 143 163 50 94 25 126 1 114 105 170 93 22 173 90 116 87 96 19 74 4 122 183 83 120 177 113 169 181 77 182 1 149 186 ^'}}, + {OUT=>'5BB3570858FA1744123BAC2873B0BB9810F53FA1'}], + ['166', {IN=> {f=> '384 1 25 56 85 107 177 6 186 138 184 28 61 184 191 175 107 6 29 81 114 12 156 2 137 86 189 73 64 127 129 44 167 11 98 107 169 143 26 146 61 130 88 120 139 55 3 189 119 87 22 105 67 78 147 51 2 161 109 84 49 87 38 48 192 62 25 64 143 72 169 151 106 111 53 58 8 93 8 85 123 120 131 170 38 2 169 167 49 41 37 153 21 39 92 145 190 155 177 185 48 13 5 150 48 21 85 115 40 166 178 88 104 1 125 19 116 106 141 111 23 43 101 58 187 150 78 101 50 107 185 86 151 130 134 143 34 31 26 122 38 40 112 97 33 136 50 99 127 121 159 7 19 170 187 1 79 191 26 130 118 5 104 47 126 109 92 129 52 30 193 90 35 67 116 90 3 181 39 122 30 155 147 105 83 21 77 35 75 174 55 190 131 154 95 72 185 94 36 95 126 71 149 4 68 152 180 144 146 7 49 33 152 188 29 111 194 172 148 125 35 59 36 125 11 36 141 149 183 125 27 1 71 133 61 138 168 85 131 5 96 162 161 117 142 14 79 183 141 165 126 55 11 74 84 79 167 3 40 142 177 193 128 173 192 100 163 16 127 145 182 97 17 193 120 115 32 108 18 96 154 103 152 150 86 181 15 99 135 179 124 194 164 68 160 43 109 138 152 142 6 21 23 149 20 11 82 164 44 159 148 133 115 24 28 53 104 9 183 179 108 56 39 84 87 30 163 32 70 75 166 170 8 139 9 175 99 143 64 89 186 114 183 133 85 161 63 61 154 111 15 115 78 109 108 72 177 14 71 103 176 173 176 157 38 10 54 132 41 186 130 126 63 69 39 76 7 65 171 82 172 102 124 140 83 113 ^'}}, + {OUT=>'905F43940B3591CE39D1145ACB1ECA80AB5E43CD'}], + ['167', {IN=> {f=> '396 1 189 70 83 29 132 67 115 145 151 170 181 14 192 2 187 40 5 33 160 48 183 91 132 83 112 177 62 189 153 128 91 49 38 50 55 24 8 8 51 36 13 175 28 36 56 160 12 107 168 25 104 157 156 139 165 14 30 192 164 195 56 41 180 159 28 79 41 144 167 51 115 188 136 154 145 65 2 22 93 83 191 147 23 110 57 137 131 66 138 26 78 146 125 159 150 34 177 22 129 68 168 111 74 118 77 50 174 54 47 87 140 20 178 158 133 60 33 45 93 47 8 170 59 52 56 124 20 16 150 117 24 84 46 106 151 51 158 173 113 111 196 73 15 133 136 71 100 10 85 182 110 143 114 92 185 42 42 118 156 20 135 173 156 96 180 37 73 134 156 182 150 196 192 45 172 17 167 91 168 68 89 134 120 190 173 34 141 37 152 111 117 103 61 7 34 62 67 191 190 8 87 21 195 139 86 44 76 66 55 186 23 31 87 183 5 155 122 191 68 53 149 136 35 115 26 121 131 102 123 3 42 197 133 179 56 84 165 136 190 130 49 157 80 101 103 97 197 11 19 118 1 5 119 137 9 104 193 141 116 122 72 38 7 70 47 44 155 43 16 107 125 40 127 193 105 131 145 108 185 6 50 141 1 167 127 153 45 53 192 121 12 79 84 129 151 15 166 196 156 60 188 53 109 83 148 162 46 146 6 136 111 160 88 38 169 85 63 87 97 35 194 3 82 52 13 132 43 59 92 109 4 178 3 118 37 195 96 94 60 112 15 47 166 110 179 99 69 149 100 43 138 69 70 123 89 12 158 54 90 72 117 182 31 166 153 164 76 33 2 101 63 44 112 58 39 143 74 32 107 89 55 143 31 47 123 125 4 135 18 141 80 137 88 81 154 187 ^'}}, + {OUT=>'336C79FBD82F33E490C577E3F791C3CBFE842AFF'}], + ['168', {IN=> {f=> '406 0 23 134 103 49 99 44 64 160 68 190 114 105 91 86 22 27 15 74 8 22 151 79 199 84 85 90 128 9 5 175 129 17 40 59 125 187 194 144 151 3 60 6 158 153 67 58 18 99 19 53 129 90 179 134 52 124 55 95 138 82 170 167 69 122 13 108 160 119 115 161 51 14 167 120 47 60 57 86 16 184 96 197 42 98 112 165 154 199 157 21 168 52 146 66 126 119 93 150 20 36 153 140 194 93 26 156 114 80 80 55 44 13 35 24 44 191 24 190 63 177 44 140 99 146 117 54 163 42 76 101 134 176 185 177 168 1 21 19 180 193 12 52 197 191 173 65 19 31 118 59 1 123 72 71 88 64 11 193 37 63 28 169 184 45 72 195 152 186 87 56 176 112 41 93 77 84 158 29 3 136 142 36 80 4 119 166 86 98 163 93 1 145 83 102 66 75 191 46 4 94 155 55 120 149 113 148 181 49 175 180 142 87 5 51 65 92 167 196 186 138 184 23 61 164 171 175 107 6 9 81 114 7 141 177 117 76 174 73 54 112 114 29 152 11 98 87 154 123 21 146 41 115 88 115 139 40 183 189 109 67 7 90 52 73 127 51 192 156 89 69 49 77 33 33 182 57 10 64 138 57 159 136 91 111 33 58 193 88 188 75 118 110 126 170 18 197 169 162 34 41 17 138 6 34 92 145 185 155 157 170 43 8 140 48 21 70 105 40 161 178 78 89 196 110 199 106 96 121 106 23 185 28 96 48 167 145 58 91 35 97 180 66 151 130 124 128 34 16 6 107 28 20 112 92 18 121 30 84 107 101 159 187 19 155 182 181 74 186 11 120 98 185 104 32 126 94 82 119 42 25 173 90 30 62 96 70 178 176 39 102 15 150 147 100 78 16 57 35 75 169 35 170 116 144 75 146 ^'}}, + {OUT=>'5C6D07A6B44F7A75A64F6CE592F3BAE91E022210'}], + ['169', {IN=> {f=> '409 1 185 70 12 95 110 71 133 183 52 136 148 144 114 186 17 25 144 164 5 79 178 172 124 117 19 43 20 93 174 36 125 117 151 109 3 164 55 101 37 122 152 77 131 168 88 162 161 93 142 14 63 167 141 149 94 39 190 50 68 47 135 198 16 110 153 177 104 173 192 68 147 179 119 137 166 73 180 169 88 91 24 76 10 80 146 79 128 150 62 149 194 83 111 171 124 170 156 60 152 27 109 106 120 134 201 184 202 149 12 198 66 132 12 127 132 133 83 8 12 45 88 9 183 155 92 24 23 76 63 14 163 8 62 67 150 162 8 115 1 167 91 127 32 89 162 90 159 125 85 129 47 53 154 95 7 115 54 101 108 56 169 6 47 103 176 157 160 125 14 10 30 124 17 178 122 102 55 69 15 60 202 49 171 74 148 94 92 124 67 200 184 70 83 29 127 67 100 140 131 165 176 4 182 2 167 20 193 33 160 43 173 71 112 68 97 157 57 169 138 113 86 44 38 40 55 19 196 201 31 21 8 165 23 26 41 155 195 183 102 158 25 94 142 146 129 150 9 30 177 154 195 51 36 175 139 28 59 31 124 167 41 105 173 121 134 130 65 185 17 78 78 181 137 13 95 57 137 116 51 118 16 78 131 115 154 145 29 177 22 129 68 168 91 74 98 72 30 174 39 37 72 130 15 163 158 128 50 18 25 73 27 191 150 59 52 36 104 20 11 130 97 4 79 46 106 141 46 138 163 108 106 191 68 15 113 136 66 100 193 65 182 105 123 99 72 180 37 22 108 156 10 130 168 141 96 160 22 58 134 151 162 140 181 187 35 157 7 147 76 163 58 84 129 100 190 153 24 126 32 142 96 107 88 41 2 14 42 52 186 170 3 82 11 180 119 66 29 56 66 50 171 3 11 77 163 5 150 112 128 ^'}}, + {OUT=>'7E0D3E9D33127F4A30EB8D9C134A58409FA8695B'}], + ['170', {IN=> {f=> '413 1 47 25 135 129 7 108 19 107 117 102 102 3 28 190 112 165 56 63 165 122 183 116 28 157 52 73 89 90 169 202 12 111 185 203 91 116 200 97 193 134 116 122 44 31 7 63 26 37 134 22 2 93 125 33 99 186 77 124 131 94 171 183 50 113 178 146 127 153 45 32 164 121 203 58 56 108 130 192 166 168 128 39 188 53 102 69 148 141 18 139 197 108 97 132 74 24 155 71 63 59 97 21 194 180 61 45 204 132 29 31 85 88 188 164 187 118 37 167 82 94 60 98 1 47 152 110 172 85 55 128 72 43 117 41 42 116 61 12 144 40 62 58 117 168 17 159 139 164 76 5 193 101 56 30 105 30 11 143 60 32 86 68 41 136 31 40 123 118 181 135 195 127 59 130 81 53 147 62 13 124 98 34 79 39 49 145 53 180 94 105 91 71 2 27 5 54 193 7 141 79 199 84 75 70 128 199 195 160 119 17 20 54 115 187 184 129 146 193 40 201 143 138 57 43 18 94 204 38 114 80 179 114 47 119 50 80 118 82 160 152 49 112 198 88 155 104 95 151 36 199 162 100 27 50 47 86 195 16 179 81 192 27 83 107 150 134 194 147 1 158 32 131 61 111 119 83 140 5 21 133 120 174 78 26 136 109 65 80 40 29 203 25 24 44 191 14 170 43 162 34 140 99 141 112 54 148 42 71 96 119 161 165 167 148 186 11 4 180 188 197 42 182 181 168 50 14 26 103 49 1 113 67 61 78 59 196 173 32 53 8 154 169 30 72 175 152 176 87 36 166 102 36 88 77 79 138 24 188 131 127 26 70 194 114 146 66 93 158 93 191 125 78 92 51 60 176 26 4 74 135 35 120 129 113 133 181 29 170 170 137 77 190 46 45 77 157 191 186 138 184 18 61 144 151 175 107 6 194 81 114 2 126 110 ^'}}, + {OUT=>'9A5F50DFCFB19286206C229019F0ABF25283028C'}], + ['171', {IN=> {f=> '427 1 85 60 150 73 38 88 90 5 128 11 98 55 130 91 13 146 9 91 88 107 139 16 159 189 93 35 191 66 28 65 95 51 184 148 57 45 49 61 25 9 166 49 194 64 130 33 143 112 67 111 1 58 177 80 164 59 110 94 118 170 194 197 169 154 10 41 193 114 190 26 92 145 177 155 125 146 35 200 124 48 21 46 89 40 153 178 62 65 196 86 175 90 80 89 98 23 169 4 88 32 135 137 26 75 11 81 172 34 151 130 108 104 34 200 182 83 12 196 112 84 202 97 206 60 75 69 159 163 19 131 174 157 66 178 195 104 66 161 104 8 126 70 66 103 26 17 141 90 22 54 64 38 146 168 39 70 199 142 147 92 70 8 25 35 75 161 3 138 92 128 43 59 185 55 205 95 100 71 123 173 42 126 128 144 94 176 205 20 139 149 198 59 168 172 109 112 9 33 10 73 154 36 115 97 131 99 196 144 45 81 22 112 142 72 131 148 83 162 161 78 142 14 53 157 141 139 74 29 180 35 58 27 115 198 1 90 138 167 89 173 192 48 137 159 114 132 156 58 160 154 68 76 19 56 5 70 141 64 113 150 47 129 184 73 96 166 124 155 151 55 147 17 109 86 100 129 201 164 192 149 7 193 56 112 200 107 122 133 63 206 2 40 78 9 183 140 82 4 13 71 48 4 163 201 57 62 140 157 8 100 204 162 86 117 12 89 147 75 144 120 85 109 37 48 154 85 2 115 39 96 108 46 164 1 32 103 176 147 150 105 207 10 15 119 2 173 117 87 50 69 50 202 39 171 69 133 89 72 114 57 195 179 70 83 29 122 67 85 135 111 160 171 202 172 2 147 183 33 160 38 163 51 92 53 82 137 52 149 123 98 81 39 38 30 55 14 186 196 11 6 3 155 18 16 26 150 180 168 97 148 25 84 127 136 119 135 4 30 162 144 195 46 31 170 119 28 190 ^'}}, + {OUT=>'DCA737E269F9D8626D488988C996E06B352C0708'}], + ['172', {IN=> {f=> '443 1 17 96 167 27 91 152 100 106 109 65 164 10 57 71 167 123 209 74 57 137 95 30 90 2 78 110 101 147 138 22 177 22 129 68 168 63 74 70 65 2 174 18 23 51 116 8 142 158 121 36 207 207 45 209 170 122 59 52 8 76 20 4 102 69 186 72 46 106 127 39 110 149 101 99 184 61 15 85 136 59 100 172 37 182 98 95 78 44 173 30 204 94 156 206 123 161 120 96 132 1 37 134 144 134 126 160 180 21 136 203 119 55 156 44 77 122 72 190 125 10 105 25 128 75 93 67 13 205 196 14 31 179 142 206 75 207 159 91 38 8 28 66 43 150 185 193 63 135 5 143 98 143 32 5 125 124 197 103 14 97 107 102 87 3 18 185 97 155 56 48 165 112 178 106 13 157 32 53 79 85 149 197 7 106 175 203 71 101 195 92 193 129 116 122 24 26 7 58 11 32 119 7 202 83 125 28 79 181 57 119 121 84 161 168 50 93 163 131 127 153 45 17 144 121 198 43 36 93 115 177 166 148 108 24 188 53 97 59 148 126 208 134 192 88 87 112 64 14 145 61 63 39 97 11 194 165 46 40 199 132 19 11 80 73 178 154 177 118 37 147 72 94 60 88 201 47 142 110 167 75 45 113 52 43 102 21 22 111 41 12 134 30 42 48 117 158 7 154 129 164 76 195 188 101 51 20 100 10 201 143 50 32 71 53 31 131 31 35 123 113 166 135 180 117 44 125 76 33 142 62 3 114 93 19 59 34 34 130 38 170 74 105 91 56 192 27 205 34 178 202 131 79 199 84 65 50 128 189 185 145 109 17 49 105 187 174 114 141 183 20 196 128 123 47 28 18 89 189 23 99 70 179 94 42 114 45 65 98 82 150 137 29 102 183 68 150 89 75 141 21 184 157 80 7 40 37 86 190 16 174 66 187 12 68 102 135 114 189 137 191 148 12 116 56 96 119 73 130 200 6 113 100 154 63 26 116 104 50 80 25 14 193 83 ^'}}, + {OUT=>'B8FFC1D4972FCE63241E0E77850AC46DDE75DBFA'}], + ['173', {IN=> {f=> '436 1 24 44 191 211 138 11 138 18 140 99 133 104 54 124 42 63 88 95 137 133 151 116 162 208 193 180 180 173 26 158 165 160 26 6 18 79 33 1 97 59 45 62 51 172 141 24 37 189 130 145 6 72 143 152 160 87 4 150 86 28 80 77 71 106 16 164 123 103 10 54 178 106 114 34 85 150 93 175 93 70 76 27 36 152 207 4 42 103 3 120 97 113 109 181 210 162 154 129 61 166 38 13 53 141 183 186 138 184 10 61 112 119 175 107 6 170 81 114 207 102 125 65 50 135 73 28 73 75 203 113 11 98 35 115 71 8 146 202 76 88 102 139 1 144 189 83 15 181 51 13 60 75 51 179 143 37 30 49 51 20 207 156 44 184 64 125 18 133 97 52 111 194 58 167 75 149 49 105 84 113 170 179 197 169 149 208 41 178 99 180 21 92 145 172 155 105 131 30 208 200 114 48 21 31 79 40 148 178 52 50 196 71 160 80 70 69 93 23 159 202 83 22 115 132 6 65 209 71 167 14 151 130 98 89 34 190 167 68 2 181 112 79 192 82 191 45 55 49 159 148 19 116 169 142 61 173 185 94 46 146 104 206 126 55 56 93 16 12 121 90 17 49 44 18 126 163 39 50 189 137 147 87 65 3 5 35 75 156 196 118 77 118 23 54 185 40 195 95 90 71 113 163 32 116 108 144 74 166 190 15 134 134 188 39 158 172 94 107 212 23 53 134 36 105 77 111 89 186 124 35 61 7 102 132 67 131 128 78 162 161 63 142 14 43 147 141 129 54 19 170 20 48 7 95 198 199 70 123 157 74 173 192 28 127 139 109 127 146 43 140 139 48 61 14 36 60 136 49 98 150 32 109 174 63 81 161 124 140 146 50 142 7 109 66 80 124 201 144 182 149 2 188 46 92 185 87 112 133 43 201 205 35 68 9 183 125 72 197 3 66 33 207 163 191 52 57 130 152 8 85 204 157 81 107 205 187 ^'}}, + {OUT=>'E9C9BF41C8549354151B977003CE1D830BE667DB'}], + ['174', {IN=> {f=> '462 1 126 54 123 113 85 81 23 41 154 71 210 115 18 89 108 32 157 209 11 103 176 133 136 77 193 10 209 112 196 166 110 66 43 69 194 36 202 25 171 62 112 82 44 100 43 188 172 70 83 29 115 67 64 128 83 153 164 195 158 2 119 187 169 33 160 31 149 23 64 32 61 109 45 121 102 77 74 32 38 16 55 7 172 189 198 200 211 141 11 2 5 143 159 147 90 134 25 70 106 122 105 114 212 30 141 130 195 39 24 163 91 28 11 7 76 167 17 81 137 85 86 94 65 149 5 42 66 157 113 204 59 57 137 80 15 70 207 78 95 91 142 133 17 177 22 129 68 168 43 74 50 60 197 174 3 13 36 106 3 127 158 116 26 197 192 25 194 155 102 59 52 203 56 20 214 82 49 171 67 46 106 117 34 90 139 96 94 179 56 15 65 136 54 100 157 17 182 93 75 63 24 168 25 189 84 156 201 118 156 105 96 112 201 22 134 139 114 116 145 175 11 121 198 99 40 151 34 72 117 52 190 105 90 20 118 60 83 52 208 205 181 209 16 174 122 206 70 202 144 71 18 208 8 66 38 135 170 178 53 115 5 138 88 123 17 200 115 119 182 98 9 87 97 102 72 3 8 180 82 145 56 33 165 102 173 96 213 157 12 33 69 80 129 192 2 101 165 203 51 86 190 87 193 124 116 122 4 21 7 53 211 27 104 207 197 73 125 23 59 176 37 114 111 74 151 153 50 73 148 116 127 153 45 2 124 121 193 28 16 78 100 162 166 128 88 9 188 53 92 49 148 111 193 129 187 68 77 92 54 4 135 51 63 19 97 1 194 150 31 35 194 132 9 206 75 58 168 144 167 118 37 127 62 94 60 78 196 47 132 110 162 65 35 98 32 43 87 1 2 106 21 12 124 20 22 38 117 148 212 149 119 164 76 180 183 101 46 10 95 205 186 143 40 32 56 38 21 126 31 30 123 108 151 135 165 107 29 120 71 13 137 62 208 104 88 4 39 29 19 115 23 160 54 105 91 41 177 27 200 14 163 124 ^'}}, + {OUT=>'0942908960B54F96CB43452E583F4F9CB66E398A'}], + ['175', {IN=> {f=> '453 0 115 79 199 84 49 18 128 173 169 121 93 17 186 41 89 187 158 90 133 167 206 188 104 99 31 4 18 81 165 217 75 54 179 62 34 106 37 41 66 82 134 113 215 86 159 36 142 65 43 125 215 160 149 48 193 24 21 86 182 16 166 42 179 206 44 94 111 82 181 121 167 132 198 92 48 72 119 57 114 184 200 81 68 122 39 26 84 96 26 80 1 208 177 217 24 44 191 206 118 209 123 8 140 99 128 99 54 109 42 58 83 80 122 113 141 96 147 203 183 180 175 158 16 143 155 155 11 1 13 64 23 1 87 54 35 52 46 157 121 19 27 174 115 130 209 72 123 152 150 87 202 140 76 23 75 77 66 86 11 149 118 88 44 168 101 94 14 80 145 93 165 73 65 66 12 21 137 192 4 22 83 201 120 77 113 94 181 195 157 144 124 51 151 33 211 38 131 178 186 138 184 5 61 92 99 175 107 6 155 81 114 207 87 105 45 40 120 73 18 58 60 193 98 11 98 15 100 51 3 146 187 61 88 97 139 204 129 189 73 213 171 36 216 55 55 51 174 138 17 15 49 41 15 197 146 39 174 64 120 3 123 82 37 111 179 58 157 70 134 39 100 74 108 170 164 197 169 144 198 41 163 84 170 16 92 145 167 155 85 116 25 208 200 104 48 21 16 69 40 143 178 42 35 196 56 145 70 60 49 88 23 149 192 78 12 95 127 204 55 199 61 162 212 151 130 88 74 34 180 152 53 210 166 112 74 182 67 176 30 35 29 159 133 19 101 164 127 56 168 175 84 26 131 104 196 126 40 46 83 6 7 101 90 12 44 24 216 106 158 39 30 179 132 147 82 60 216 203 35 75 151 181 98 62 108 3 49 185 25 185 95 80 71 103 153 22 106 88 144 54 156 175 10 129 119 178 19 148 172 79 102 207 13 208 33 114 36 95 57 91 79 176 104 25 41 210 92 122 62 131 108 73 162 161 48 142 14 33 137 141 119 34 9 160 5 38 205 75 198 189 50 108 112 ^'}}, + {OUT=>'FCE34051C34D4B81B85DDC4B543CDE8007E284B3'}], + ['176', {IN=> {f=> '454 1 53 173 192 113 111 102 120 132 22 112 118 20 40 7 8 213 46 129 28 77 150 11 81 160 49 60 154 124 119 139 43 135 213 109 38 52 117 201 116 168 149 215 181 32 64 164 59 98 133 15 194 198 28 54 9 183 104 58 176 209 59 12 200 163 177 45 50 116 145 8 64 204 150 74 93 184 89 111 39 108 108 85 61 13 36 154 61 210 115 3 84 108 22 152 209 216 103 176 123 126 57 183 10 199 107 186 161 105 51 38 69 184 26 202 15 171 57 97 77 24 90 33 183 167 70 83 29 110 67 49 123 63 148 159 190 148 2 99 172 159 33 160 26 139 3 44 17 46 89 40 101 87 62 69 27 38 6 55 2 162 184 183 190 211 131 6 212 210 138 144 132 85 124 25 60 91 112 95 99 212 30 126 120 195 34 19 158 71 28 211 217 56 167 7 71 122 70 66 79 65 134 27 61 147 103 199 44 57 137 65 50 202 78 80 81 137 128 12 177 22 129 68 168 23 74 30 55 182 174 208 3 21 96 218 112 158 111 16 187 177 5 179 140 82 59 52 188 36 20 214 62 29 156 62 46 106 107 29 70 129 91 89 174 51 15 45 136 49 100 142 217 182 88 55 48 4 163 20 174 74 156 196 113 151 90 96 92 191 7 134 134 94 106 130 170 1 106 193 79 25 146 24 67 112 32 190 85 210 75 15 108 45 73 37 193 205 166 194 1 169 102 206 65 197 129 51 218 198 208 66 33 120 155 163 43 95 5 133 78 103 2 185 105 114 167 93 4 77 87 102 57 3 218 175 67 135 56 18 165 92 168 86 203 157 212 13 59 75 109 187 217 96 155 203 31 71 185 82 193 119 116 122 204 16 7 48 201 22 89 197 192 63 125 18 39 171 17 109 101 64 141 138 50 53 133 101 127 153 45 207 104 121 188 13 216 63 85 147 166 108 68 214 188 53 87 39 148 96 178 124 182 48 67 72 44 214 125 41 63 219 97 211 194 135 16 30 189 132 219 191 70 43 158 181 ^'}}, + {OUT=>'61E8916532503627F4024D13884640A46F1D61D4'}], + ['177', {IN=> {f=> '475 0 153 118 37 99 48 94 60 64 189 47 118 110 155 51 21 77 4 43 66 195 196 99 215 12 110 6 216 24 117 134 205 142 105 164 76 159 176 101 39 218 88 184 165 143 26 32 35 17 7 119 31 23 123 101 130 135 144 93 8 113 64 207 130 62 201 90 81 205 11 22 220 94 2 146 26 105 91 20 156 27 193 208 142 178 107 79 199 84 41 2 128 165 161 109 85 17 174 37 81 187 150 78 129 159 194 184 92 87 23 214 18 77 153 209 63 46 179 46 30 102 33 29 50 82 126 101 203 78 147 20 138 53 27 117 207 148 145 32 181 16 13 86 178 16 162 30 175 198 32 90 99 66 177 113 155 124 186 80 44 60 119 49 106 176 192 65 52 106 27 26 68 92 14 80 211 200 169 213 24 44 191 202 102 197 111 140 99 124 95 54 97 42 54 79 68 110 97 133 80 135 199 175 180 171 146 8 131 147 151 221 219 9 52 15 1 79 50 27 44 42 145 105 15 19 162 103 118 201 72 107 152 142 87 190 132 68 19 71 77 62 70 7 137 114 76 214 36 160 97 78 220 76 141 93 157 57 61 58 9 125 180 4 6 67 189 120 61 113 82 181 183 153 136 120 43 139 29 199 26 123 174 186 138 184 1 61 76 83 175 107 6 143 81 114 207 75 89 29 32 108 73 10 46 48 185 86 11 98 221 88 35 221 146 175 49 88 93 139 196 117 189 65 201 163 24 208 51 39 51 170 134 1 3 49 33 11 189 138 35 166 64 116 213 115 70 25 111 167 58 149 66 122 31 96 66 104 170 152 197 169 140 190 41 151 72 162 12 92 145 163 155 69 104 21 208 200 96 48 21 4 61 40 139 178 34 23 196 44 133 62 52 33 84 23 141 184 74 4 79 123 192 47 191 53 158 200 151 130 80 62 34 172 140 41 206 154 112 70 174 55 164 18 19 13 159 121 19 89 160 115 52 164 167 76 10 119 104 188 126 28 38 75 220 3 85 90 8 40 8 204 90 154 39 14 171 128 147 78 56 216 191 35 75 147 169 82 50 100 209 45 185 13 177 95 150 ^'}}, + {OUT=>'F008D5D7853B6A17B7466CD9E18BD135E520FAF4'}], + ['178', {IN=> {f=> '471 0 71 89 139 8 92 60 144 26 142 154 3 122 98 164 216 134 172 58 95 200 224 201 5 86 36 81 29 63 65 162 76 11 13 196 78 108 55 131 80 66 162 161 27 142 14 19 123 141 105 6 220 146 209 24 184 47 198 175 22 87 133 38 173 192 205 103 91 97 115 122 7 92 103 25 2 213 213 36 124 13 62 150 221 61 150 39 45 149 124 104 134 38 130 208 109 18 32 112 201 96 158 149 215 176 22 44 149 39 88 133 220 189 193 23 44 9 183 89 48 161 204 54 222 195 163 167 40 45 106 140 8 49 204 145 69 83 169 89 96 24 93 103 85 41 3 31 154 51 210 115 213 79 108 12 147 209 206 103 176 113 116 37 173 10 189 102 176 156 100 36 33 69 174 16 202 5 171 52 82 72 4 80 23 178 162 70 83 29 105 67 34 118 43 143 154 185 138 2 79 157 149 33 160 21 129 208 24 2 31 69 35 81 72 47 64 22 38 221 55 222 152 179 168 180 211 121 1 207 200 133 129 117 80 114 25 50 76 102 85 84 212 30 111 110 195 29 14 153 51 28 196 212 36 167 222 61 107 55 46 64 65 119 220 12 56 137 93 194 29 57 137 50 210 30 197 78 65 71 132 123 7 177 22 129 68 168 3 74 10 50 167 174 198 218 6 86 218 97 158 106 6 177 162 210 164 125 62 59 52 173 16 20 214 42 9 141 57 46 106 97 24 50 119 86 84 169 46 15 25 136 44 100 127 202 182 83 35 33 209 158 15 159 64 156 191 108 146 75 96 72 181 217 134 129 74 96 115 165 216 91 188 59 10 141 14 62 107 12 190 65 205 60 10 98 30 63 22 178 205 151 179 211 164 82 206 60 192 114 31 203 188 193 66 28 105 140 148 33 75 5 128 68 83 212 170 95 109 152 88 224 67 77 102 42 3 213 170 52 125 56 3 165 82 163 76 193 157 197 218 49 70 89 182 217 91 145 203 11 56 180 77 193 114 116 122 189 11 7 43 191 17 74 187 187 53 125 13 19 166 222 104 91 54 131 123 50 33 118 86 127 167 ^'}}, + {OUT=>'BD8D2E873CF659B5C77AAC1616827EF8A3B1A3B3'}], + ['179', {IN=> {f=> '480 1 45 193 76 121 181 219 195 42 64 126 166 80 40 200 188 53 80 25 148 75 157 117 175 20 53 44 30 207 111 27 63 198 97 204 194 114 222 23 182 132 212 170 63 22 144 120 143 118 37 79 38 94 60 54 184 47 108 110 150 41 11 62 211 43 51 180 181 94 200 12 100 223 201 14 117 124 200 137 95 164 76 144 171 101 34 213 83 169 150 143 16 32 20 2 224 114 31 18 123 96 115 135 129 83 220 108 59 192 125 62 196 80 76 195 218 17 210 79 214 136 6 105 91 5 141 27 188 193 127 168 97 79 199 84 31 209 128 155 151 94 75 17 159 32 71 187 140 63 124 149 179 179 77 72 13 204 18 72 138 199 48 36 179 26 25 97 28 14 30 82 116 86 188 68 132 133 38 7 107 197 133 140 12 166 6 3 86 173 16 157 15 170 188 17 85 84 46 172 103 140 114 171 65 39 45 119 39 96 166 182 45 32 86 12 26 48 87 226 80 201 190 159 208 24 44 191 197 82 182 96 217 140 99 119 90 54 82 42 49 74 53 95 77 123 60 120 194 165 180 166 131 225 116 137 146 211 219 4 37 5 1 69 45 17 34 37 130 85 10 9 147 88 103 191 72 87 152 132 87 175 122 58 14 66 77 57 50 2 122 109 61 209 26 150 92 58 205 71 136 93 147 37 56 48 212 221 110 165 4 213 47 174 120 41 113 67 181 168 148 126 115 33 124 24 184 11 113 169 186 138 184 223 61 56 63 175 107 6 128 81 114 207 60 69 9 22 93 73 31 33 175 71 11 98 206 73 15 221 146 160 34 88 88 139 186 102 189 55 186 153 9 198 46 19 51 165 129 208 215 49 23 6 179 128 30 156 64 111 203 105 55 10 111 152 58 139 61 107 21 91 56 99 170 137 197 169 135 180 41 136 57 152 7 92 145 158 155 49 89 16 208 200 86 48 21 216 51 40 134 178 24 8 196 29 118 52 42 13 79 23 131 174 69 221 59 118 177 37 181 43 153 185 151 130 70 47 34 162 125 26 201 139 112 65 164 40 149 3 226 220 159 106 19 74 155 100 47 159 157 193 ^'}}, + {OUT=>'B25A04DD425302ED211A1C2412D2410FA10C63B6'}], + ['180', {IN=> {f=> '471 0 211 98 104 174 126 7 24 61 213 225 57 90 1 33 209 183 62 147 39 215 157 121 147 71 49 216 170 35 75 140 148 54 29 86 188 38 185 221 163 95 58 71 81 131 84 44 144 10 134 142 228 118 86 156 204 126 172 46 91 196 220 197 218 70 36 73 13 47 57 154 60 3 226 188 70 100 51 131 64 62 162 161 15 142 14 11 115 141 97 219 216 138 201 16 172 31 198 167 6 75 125 26 173 192 193 95 75 93 111 114 224 76 91 213 13 227 201 213 28 120 1 50 150 213 45 142 31 33 145 124 92 130 34 126 204 109 2 16 108 201 80 150 149 215 172 14 28 137 23 80 133 208 185 189 19 36 9 183 77 40 149 200 50 214 191 163 159 36 41 98 136 8 37 204 141 65 75 157 89 84 12 81 99 85 25 224 27 154 43 210 115 205 75 108 4 143 209 198 103 176 105 108 21 165 10 181 98 168 152 96 24 29 69 166 8 202 226 171 48 70 68 217 72 15 174 158 70 83 29 101 67 22 114 27 139 150 181 130 2 63 145 141 33 160 17 121 196 8 219 19 53 31 65 60 35 60 18 38 217 55 222 144 175 156 172 211 113 226 203 192 129 117 105 76 106 25 42 64 94 77 72 212 30 99 102 195 25 10 149 35 28 184 208 20 167 218 53 95 43 30 52 65 107 220 52 129 85 190 17 57 137 38 202 14 193 78 53 63 128 119 3 177 22 129 68 168 216 74 223 46 155 174 190 214 223 78 218 85 158 102 227 169 150 198 152 113 46 59 52 161 20 214 26 222 129 53 46 106 89 20 34 111 82 80 165 42 15 9 136 40 100 115 190 182 79 19 21 197 154 11 147 56 156 187 104 142 63 96 56 173 209 134 125 58 88 103 161 212 79 184 43 227 137 6 58 103 225 190 49 201 48 6 90 18 55 10 166 205 139 167 203 160 66 206 56 188 102 15 191 180 181 66 24 93 128 136 25 59 5 124 60 67 204 158 87 105 140 84 224 59 69 102 30 3 209 166 40 117 56 220 165 74 159 68 185 157 185 206 41 66 167 ^'}}, + {OUT=>'A404E21588123E0893718B4B44E91414A785B91F'}], + ['181', {IN=> {f=> '490 1 176 217 85 133 203 218 38 174 71 193 108 116 122 171 5 7 37 179 11 56 175 181 41 125 7 226 160 204 98 79 42 119 105 50 9 100 68 127 153 45 185 60 121 177 211 183 30 52 114 166 64 24 192 188 53 76 17 148 63 145 113 171 4 45 28 22 203 103 19 63 186 97 200 194 102 214 19 178 132 208 158 59 10 136 112 135 118 37 63 30 94 60 46 180 47 100 110 146 33 3 50 199 43 39 168 169 90 188 12 92 219 189 6 117 116 196 133 87 164 76 132 167 101 30 209 79 157 138 143 8 32 8 221 220 110 31 14 123 92 103 135 117 75 212 104 55 180 121 62 192 72 72 187 206 13 202 67 206 128 221 105 91 224 129 27 184 181 115 160 89 79 199 84 23 197 128 147 143 82 67 17 147 28 63 187 132 51 120 141 167 175 65 60 5 196 18 68 126 191 36 28 179 10 21 93 24 2 14 82 108 74 176 60 120 215 129 26 222 99 189 121 136 227 154 229 226 86 169 16 153 3 166 180 5 81 72 30 168 95 128 106 159 53 35 33 119 31 88 158 174 29 16 70 26 32 83 218 80 193 182 151 204 24 44 191 193 66 170 84 213 140 99 115 86 54 70 42 45 70 41 83 61 115 44 108 190 157 180 162 119 221 104 129 142 203 219 25 228 1 61 41 9 26 33 118 69 6 1 135 76 91 183 72 71 152 124 87 163 114 50 10 62 77 53 34 229 110 105 49 205 18 142 88 42 193 67 132 93 139 21 52 40 204 213 98 153 4 201 31 162 120 25 113 55 181 156 144 118 111 25 112 20 172 230 105 165 186 138 184 223 61 40 47 175 107 6 116 81 114 207 48 53 224 14 81 73 223 19 21 167 59 11 98 194 61 230 221 146 148 22 88 84 139 178 90 189 47 174 145 228 190 42 3 51 161 125 196 207 49 15 2 171 120 26 148 64 107 195 97 43 229 111 140 58 131 57 95 13 87 48 95 170 125 197 169 131 172 41 124 45 144 3 92 145 154 155 33 77 12 208 200 78 48 21 208 43 40 130 178 16 227 196 17 106 44 34 228 75 23 123 166 65 217 43 114 165 29 173 35 200 ^'}}, + {OUT=>'A1E13BC55BF6DAD83CF3AABDA3287AD68681EA64'}], + ['182', {IN=> {f=> '479 0 167 151 130 58 29 34 150 107 8 195 121 112 59 152 22 131 218 208 202 159 88 19 56 149 82 41 153 145 54 199 86 104 166 126 228 16 53 209 225 41 90 230 29 197 171 46 143 39 203 149 117 147 67 45 216 158 35 75 136 136 38 17 78 176 34 185 213 155 95 50 71 73 123 225 76 28 144 227 126 130 228 114 74 148 192 118 172 34 87 192 216 193 206 54 36 65 230 31 49 146 44 228 214 180 62 92 47 131 48 58 162 161 3 142 14 3 107 141 89 207 212 130 193 8 160 15 198 159 223 63 117 14 173 192 181 87 59 89 107 106 216 60 79 201 1 227 189 213 20 116 222 38 150 205 29 134 23 21 141 124 80 126 30 122 200 109 219 104 201 64 142 149 215 168 6 12 125 7 72 133 196 181 185 15 28 9 183 65 32 137 196 46 206 187 163 151 32 37 90 132 8 25 204 137 61 67 145 89 72 69 95 85 9 220 23 154 35 210 115 197 71 108 229 139 209 190 103 176 97 100 5 157 10 173 94 160 148 92 12 25 69 158 202 222 171 44 58 64 205 64 7 170 154 70 83 29 97 67 10 110 11 135 146 177 122 2 47 133 133 33 160 13 113 184 225 211 7 37 27 49 48 23 56 14 38 213 55 222 136 171 144 164 211 105 226 199 184 125 105 93 72 98 25 34 52 86 69 60 212 30 87 94 195 21 6 145 19 28 172 204 4 167 214 45 83 31 14 40 65 95 220 221 48 121 77 186 5 57 137 26 194 231 189 78 41 55 124 115 232 177 22 129 68 168 204 74 211 42 143 174 182 210 215 70 218 73 158 98 223 161 138 186 140 101 30 59 52 149 217 20 214 10 210 117 49 46 106 81 16 18 103 78 76 161 38 15 226 136 36 100 103 178 182 75 3 9 185 150 7 135 48 156 183 100 138 51 96 40 165 201 134 121 42 80 91 157 208 67 180 27 219 133 231 54 99 213 190 33 197 36 2 82 6 47 231 154 205 127 155 195 156 50 206 52 184 90 232 179 172 169 66 20 81 116 124 17 43 5 120 52 51 196 146 79 101 128 80 224 65 ^'}}, + {OUT=>'D5FD35FFABED6733C92365929DF0FB4CAE864D15'}], + ['183', {IN=> {f=> '503 1 55 102 9 3 202 159 19 103 56 206 165 60 152 54 171 157 164 185 27 59 45 171 217 80 123 203 203 23 169 66 193 103 116 122 156 7 32 169 6 41 165 176 31 125 2 211 155 189 93 69 32 109 90 50 225 85 53 127 153 45 175 40 121 172 201 168 15 37 99 166 44 4 182 188 53 71 7 148 48 130 108 166 220 35 8 12 198 93 9 63 171 97 195 194 87 204 14 173 132 203 143 54 231 126 102 125 118 37 43 20 94 60 36 175 47 90 110 141 23 229 35 184 43 24 153 154 85 173 12 82 214 174 232 117 106 191 128 77 164 76 117 162 101 25 204 74 142 123 143 234 32 229 211 215 105 31 9 123 87 88 135 102 65 202 99 50 165 116 62 187 62 67 177 191 8 192 52 196 118 206 105 91 214 114 27 179 166 100 150 79 79 199 84 13 182 128 137 133 67 57 17 132 23 53 187 122 36 115 131 152 170 50 45 231 186 18 63 111 181 21 18 179 226 16 88 19 223 230 82 98 59 161 50 105 200 124 11 207 89 179 106 131 212 139 224 221 86 164 16 148 224 161 170 226 76 57 10 163 85 113 96 144 38 30 18 119 21 78 148 164 9 232 50 221 26 12 78 208 80 183 172 141 199 24 44 191 188 46 155 69 208 140 99 110 81 54 55 42 40 65 26 68 41 105 24 93 185 147 180 157 104 216 89 119 137 193 219 231 10 223 1 51 36 235 16 28 103 49 1 227 120 61 76 173 72 51 152 114 87 148 104 40 5 57 77 48 14 229 95 100 34 200 8 132 83 22 178 62 127 93 129 1 47 30 194 203 83 138 4 186 11 147 120 5 113 40 181 141 139 108 106 15 97 15 157 220 95 160 186 138 184 223 61 20 27 175 107 6 101 81 114 207 33 33 209 4 66 73 218 4 6 157 44 11 98 179 46 215 221 146 133 7 88 79 139 168 75 189 37 159 135 218 180 37 219 51 156 120 181 197 49 5 233 161 110 21 138 64 102 185 87 28 219 111 125 58 121 52 80 3 82 38 90 170 110 197 169 126 162 41 109 30 134 234 92 145 149 155 13 62 7 208 200 68 48 21 198 33 40 125 178 6 217 196 2 91 34 24 213 70 23 113 161 ^'}}, + {OUT=>'C12E9C280EE9C079E0506FF89F9B20536E0A83EF'}], + ['184', {IN=> {f=> '470 0 58 210 15 107 144 15 159 21 142 152 151 130 48 14 34 140 92 231 190 106 112 54 142 7 116 208 193 187 159 73 19 41 144 67 36 148 135 44 184 71 104 156 126 218 6 43 204 225 21 90 230 24 182 156 26 138 39 188 139 112 147 62 40 216 143 35 75 131 121 18 2 68 161 29 185 203 145 95 40 71 63 113 220 66 8 144 212 116 115 228 109 59 138 177 108 172 19 82 187 211 188 191 34 36 55 215 11 39 136 24 223 199 170 52 82 42 131 28 53 162 161 226 142 14 231 97 141 79 192 207 120 183 236 145 233 198 149 208 48 107 237 173 192 166 77 39 84 102 96 206 40 64 186 224 227 174 213 10 111 212 23 150 195 9 124 13 6 136 124 65 121 25 117 195 109 204 218 99 201 44 132 149 215 163 234 230 110 225 62 133 181 176 180 10 18 9 183 50 22 122 191 41 196 182 163 141 27 32 80 127 8 10 204 132 56 57 130 89 57 223 54 90 85 227 215 18 154 25 210 115 187 66 108 224 134 209 180 103 176 87 90 223 147 10 163 89 150 143 87 235 20 69 148 228 202 217 171 39 43 59 190 54 235 165 149 70 83 29 92 67 233 105 229 130 141 172 112 2 27 118 123 33 160 8 103 169 210 201 230 17 22 29 33 8 51 9 38 208 55 222 126 166 129 154 211 95 226 194 174 120 90 78 67 88 25 24 37 76 59 45 212 30 72 84 195 16 1 140 237 28 157 199 222 167 209 35 68 16 232 25 65 80 220 211 43 111 67 181 228 57 137 11 184 216 184 78 26 45 119 110 232 177 22 129 68 168 189 74 196 37 128 174 172 205 205 60 218 58 158 93 218 151 123 171 125 86 10 59 52 134 202 20 214 228 195 102 44 46 106 71 11 236 93 73 71 156 33 15 211 136 31 100 88 163 182 70 221 232 170 145 2 120 38 156 178 95 133 36 96 20 155 191 134 116 22 70 76 152 203 52 175 7 209 128 226 49 94 198 190 13 192 21 235 72 229 37 221 139 205 112 140 185 151 30 206 47 179 75 217 101 ^'}}, + {OUT=>'E22769DC00748A9BBD6C05BBC8E81F2CD1DC4E2D'}], + ['185', {IN=> {f=> '502 0 158 148 66 13 60 95 103 3 15 5 113 38 23 182 125 65 94 107 73 224 37 47 102 237 3 198 155 7 95 56 198 165 52 148 46 163 157 152 173 19 55 29 167 217 76 115 203 191 11 165 62 193 99 116 122 144 236 7 28 161 2 29 157 172 23 125 238 199 151 177 89 61 24 101 78 50 213 73 41 127 153 45 167 24 121 168 193 156 3 25 87 166 28 228 174 188 53 67 239 148 36 118 104 162 208 27 232 4 194 85 1 63 159 97 191 194 75 196 10 169 132 199 131 50 223 118 94 117 118 37 27 12 94 60 28 171 47 82 110 137 15 225 23 172 43 12 141 142 81 161 12 74 210 162 228 117 98 187 124 69 164 76 105 158 101 21 200 70 130 111 143 230 32 221 203 211 101 31 5 123 83 76 135 90 57 194 95 46 153 112 62 183 54 63 169 179 4 184 40 188 110 194 105 91 206 102 27 175 154 88 142 71 79 199 84 5 170 128 129 125 55 49 17 120 19 45 187 114 24 111 123 140 166 38 33 227 178 18 59 99 173 9 10 179 214 12 84 15 215 218 82 90 47 149 42 93 188 120 239 195 81 171 94 127 200 127 220 217 86 160 16 144 216 157 162 218 72 45 234 159 77 101 88 132 26 26 6 119 13 70 140 156 233 220 34 213 26 236 74 200 80 175 164 133 195 24 44 191 184 30 143 57 204 140 99 106 77 54 43 42 36 61 14 56 25 97 8 81 181 139 180 153 92 212 77 111 133 185 219 231 238 219 1 43 32 231 8 24 91 33 237 223 108 49 64 165 72 35 152 106 87 136 96 32 1 53 77 44 238 229 83 96 22 196 124 79 6 166 58 123 93 121 225 43 22 186 195 71 126 4 174 235 135 120 229 113 28 181 129 135 100 102 7 85 11 145 212 87 156 186 138 184 223 61 4 11 175 107 6 89 81 114 207 21 17 197 236 54 73 214 232 234 149 32 11 98 167 34 203 221 146 121 235 88 75 139 160 63 189 29 147 127 210 172 33 207 51 152 116 169 189 49 237 233 153 102 17 130 64 98 177 79 16 211 111 113 58 113 48 68 235 78 30 86 170 98 197 169 122 154 41 97 18 126 234 92 145 145 155 237 50 209 ^'}}, + {OUT=>'F29835A93475740E888E8C14318F3CA45A3C8606'}], + ['186', {IN=> {f=> '481 1 208 200 56 48 21 186 21 40 119 178 236 205 196 226 73 22 12 195 64 23 101 144 54 206 241 103 132 7 151 13 138 140 151 130 40 2 34 132 80 223 186 94 112 50 134 237 104 200 181 175 159 61 19 29 140 55 32 144 127 36 172 59 104 148 126 210 240 35 200 225 5 90 230 20 170 144 10 134 39 176 131 108 147 58 36 216 131 35 75 127 109 2 232 60 149 25 185 195 137 95 32 71 55 105 216 58 234 144 200 108 103 228 105 47 130 165 100 172 7 78 183 207 184 179 18 36 47 203 237 31 128 8 219 187 162 44 74 38 131 12 49 162 161 218 142 14 227 89 141 71 180 203 112 175 232 133 221 198 141 196 36 99 229 173 192 154 69 23 80 98 88 198 24 52 174 216 227 162 213 2 107 204 11 150 187 235 116 5 236 132 124 53 117 21 113 191 109 192 206 95 201 28 124 149 215 159 230 218 98 213 54 133 169 172 176 6 10 9 183 38 14 110 187 37 188 178 163 133 23 28 72 123 8 240 204 128 52 49 118 89 45 215 42 86 85 215 211 14 154 17 210 115 179 62 108 220 130 209 172 103 176 79 82 211 139 10 155 85 142 139 83 227 16 69 140 224 202 213 171 35 31 55 178 46 231 161 145 70 83 29 88 67 225 101 217 126 137 168 104 2 11 106 115 33 160 4 95 157 198 193 222 1 18 13 21 238 47 5 38 204 55 222 118 162 117 146 211 87 226 190 166 116 78 66 63 80 25 16 25 68 51 33 212 30 60 76 195 12 239 136 225 28 145 195 210 167 205 27 56 4 220 13 65 68 220 203 39 103 59 177 220 57 137 241 176 204 180 78 14 37 115 106 232 177 22 129 68 168 177 74 184 33 116 174 164 201 197 52 218 46 158 89 214 143 111 159 113 74 236 59 52 122 190 20 214 216 183 90 40 46 106 63 7 224 85 69 67 152 29 15 199 136 27 100 76 151 182 66 209 224 158 141 240 108 30 156 174 91 129 24 96 4 147 183 134 112 6 62 64 148 199 40 171 233 201 124 222 45 90 186 190 239 188 9 235 64 221 29 213 127 178 ^'}}, + {OUT=>'1A1D77C6D0F97C4B620FAA90F3F8644408E4B13D'}], + ['187', {IN=> {f=> '508 1 94 122 173 145 6 206 41 173 57 199 146 150 136 66 9 48 83 91 239 243 5 109 30 7 174 113 57 90 95 69 224 29 39 102 229 3 194 151 239 87 56 190 165 44 144 38 155 157 140 161 11 51 13 163 217 72 107 203 179 243 161 58 193 95 116 122 132 236 7 24 153 242 17 149 168 15 125 238 187 147 165 85 53 16 93 66 50 201 61 29 127 153 45 159 8 121 164 185 144 235 13 75 166 12 216 166 188 53 63 235 148 24 106 100 158 196 19 220 240 190 77 237 63 147 97 187 194 63 188 6 165 132 195 119 46 215 110 86 109 118 37 11 4 94 60 20 167 47 74 110 133 7 221 11 160 43 129 130 77 149 12 66 206 150 224 117 90 183 120 61 164 76 93 154 101 17 196 66 118 99 143 226 32 213 195 207 97 31 1 123 79 64 135 78 49 186 91 42 141 108 62 179 46 59 161 167 176 28 180 102 182 105 91 198 90 27 171 142 76 134 63 79 199 84 241 158 128 121 117 43 41 17 108 15 37 187 106 12 107 115 128 162 26 21 223 170 18 55 87 165 241 2 179 202 8 80 11 207 206 82 82 35 137 34 81 176 116 231 183 73 163 82 123 188 115 216 213 86 156 16 140 208 153 154 210 68 33 222 155 69 89 80 120 14 22 238 119 5 62 132 148 221 208 18 205 26 224 70 192 80 167 156 125 191 24 44 191 180 14 131 45 200 140 99 102 73 54 31 42 32 57 2 44 9 89 236 69 177 131 180 149 80 208 65 103 129 177 219 231 230 215 1 35 28 227 20 79 17 237 219 96 37 52 157 72 19 152 98 87 124 88 24 241 49 77 40 226 229 71 92 10 192 236 116 75 234 154 54 119 93 113 213 39 14 178 187 59 114 4 162 223 123 120 217 113 16 181 117 131 92 98 243 73 7 133 204 79 152 186 138 184 223 61 232 239 175 107 6 77 81 114 207 9 1 185 232 42 73 210 224 226 141 20 11 98 155 22 191 221 146 109 227 88 71 139 152 51 189 21 135 119 202 164 29 195 51 148 112 157 181 49 233 233 145 94 13 122 64 94 169 71 4 203 111 101 58 105 44 56 231 74 22 82 170 86 197 169 118 146 41 85 6 118 234 92 145 141 149 ^'}}, + {OUT=>'4EC84870E9BDD25F523C6DFB6EDD605052CA4EAA'}], + ['188', {IN=> {f=> '484 1 219 32 243 208 200 48 48 21 178 13 40 115 178 232 197 196 218 61 14 4 183 60 23 93 136 50 202 229 99 120 245 143 5 134 128 151 130 32 236 34 124 68 215 182 82 112 46 126 229 92 192 169 163 159 49 19 17 136 43 28 140 119 28 160 47 104 140 126 202 236 27 196 225 235 90 230 16 158 132 240 130 39 164 123 104 147 54 32 216 119 35 75 123 97 232 224 52 137 21 185 187 129 95 24 71 47 97 212 50 222 144 188 100 91 228 101 35 122 153 92 172 241 74 179 203 180 167 2 36 39 191 225 23 120 238 215 175 154 36 66 34 131 242 45 162 161 210 142 14 223 81 141 63 168 199 104 167 228 121 209 198 133 184 24 91 221 173 192 142 61 7 76 94 80 190 8 40 162 208 227 150 213 240 103 196 245 150 179 223 108 243 228 128 124 41 113 17 109 187 109 180 194 91 201 12 116 149 215 155 226 206 86 201 46 133 157 168 172 2 2 9 183 26 6 98 183 33 180 174 163 125 19 24 64 119 8 232 204 124 48 41 106 89 33 207 30 82 85 203 207 10 154 9 210 115 171 58 108 216 126 209 164 103 176 71 74 199 131 10 147 81 134 135 79 219 12 69 132 220 202 209 171 31 19 51 166 38 227 157 141 70 83 29 84 67 217 97 205 122 133 164 96 2 241 94 107 33 160 87 145 186 185 214 231 14 243 9 230 43 1 38 200 55 222 110 158 105 138 211 79 226 186 158 112 66 54 59 72 25 8 13 60 43 21 212 30 48 68 195 8 239 132 213 28 133 191 198 167 201 19 44 238 208 1 65 56 220 195 35 95 51 173 212 57 137 233 168 192 176 78 2 29 111 102 232 177 22 129 68 168 165 74 172 29 104 174 156 197 189 44 218 34 158 85 210 135 99 147 101 62 224 59 52 110 178 20 214 204 171 78 36 46 106 55 3 212 77 65 63 148 25 15 187 136 23 100 64 139 182 62 197 216 146 137 240 96 22 156 170 87 125 12 96 234 139 175 134 108 236 54 52 144 195 28 167 221 193 120 218 41 86 174 190 227 184 243 235 56 213 21 205 115 205 71 ^'}}, + {OUT=>'D689513FED08B80C39B67371959BC4E3FECB0537'}], + ['189', {IN=> {f=> '506 0 110 165 141 238 206 37 169 45 187 134 142 124 66 5 36 71 79 235 231 5 105 22 239 166 101 49 86 83 65 224 21 31 102 221 3 190 147 231 79 56 182 165 36 140 30 147 157 128 149 3 47 245 159 217 68 99 203 167 235 157 54 193 91 116 122 120 236 7 20 145 242 5 141 164 7 125 238 175 143 153 81 45 8 85 54 50 189 49 17 127 153 45 151 240 121 160 177 132 227 1 63 166 244 204 158 188 53 59 231 148 12 94 96 154 184 11 208 236 186 69 233 63 135 97 183 194 51 180 2 161 132 191 107 42 207 102 78 101 118 37 243 244 94 60 12 163 47 66 110 129 247 217 247 148 43 236 117 118 73 137 12 58 202 138 220 117 82 179 116 53 164 76 81 150 101 13 192 62 106 87 143 222 32 205 187 203 93 31 245 123 75 52 135 66 41 178 87 38 129 104 62 175 38 55 153 155 244 168 16 172 94 170 105 91 190 78 27 167 130 64 126 55 79 199 84 237 146 128 113 109 31 33 17 96 11 29 187 98 103 107 116 158 14 9 219 162 18 51 75 157 233 242 179 190 4 76 7 199 194 82 74 23 125 26 69 164 112 223 171 65 155 70 119 176 103 212 209 86 152 16 136 200 149 146 202 64 21 210 151 61 77 72 108 2 18 230 119 245 54 124 140 209 196 2 197 26 212 66 184 80 159 148 117 187 24 44 191 176 246 119 33 196 140 99 98 69 54 19 42 28 53 238 32 241 81 224 57 173 123 180 145 68 204 53 95 125 169 219 231 222 211 1 27 24 223 240 16 67 1 237 215 84 25 40 149 72 3 152 90 87 112 80 16 241 45 77 36 214 229 59 88 246 188 232 108 71 222 142 50 115 93 105 201 35 6 170 179 47 102 4 150 211 111 120 205 113 4 181 105 127 84 94 239 61 3 121 196 71 148 186 138 184 223 61 220 227 175 107 6 65 81 114 207 245 233 173 228 30 73 206 216 218 133 8 11 98 143 10 179 221 146 97 219 88 67 139 144 39 189 13 123 111 194 156 25 183 51 144 108 145 173 49 229 233 137 86 9 114 64 90 161 63 240 195 111 89 58 97 40 44 227 70 14 78 170 74 197 169 114 138 41 73 242 110 234 177 ^'}}, + {OUT=>'C4FED58F209FC3C34AD19F86A6DACADC86C04D33'}], + ['190', {IN=> {f=> '491 0 145 135 155 207 20 243 208 200 40 48 21 170 5 40 111 178 228 189 196 210 49 6 246 171 56 23 85 128 46 198 217 95 108 241 135 247 130 116 151 130 24 228 34 116 56 207 178 70 112 42 118 221 80 184 157 151 159 37 19 5 132 31 24 136 111 20 148 35 104 132 126 194 232 19 192 225 223 90 230 12 146 120 228 126 39 152 115 100 147 50 28 216 107 35 75 119 85 220 216 44 125 17 185 179 121 95 16 71 39 89 208 42 210 144 176 92 79 228 97 23 114 141 84 172 233 70 175 199 176 155 236 36 31 179 213 15 112 226 211 163 146 28 58 30 131 230 41 162 161 202 142 14 219 73 141 55 156 195 96 159 224 109 197 198 125 172 12 83 213 173 192 130 53 241 72 90 72 182 242 28 150 200 227 138 213 236 99 188 237 150 171 211 100 239 220 124 124 29 109 13 105 183 109 168 182 87 201 246 108 149 215 151 222 194 74 189 38 133 145 164 168 248 244 9 183 14 248 86 179 29 172 170 163 117 15 20 56 115 8 224 204 120 44 33 94 89 21 199 18 78 85 191 203 6 154 1 210 115 163 54 108 212 122 209 156 103 176 63 66 187 123 10 139 77 126 131 75 211 8 69 124 216 202 205 171 27 7 47 154 30 223 153 137 70 83 29 80 67 209 93 193 118 129 160 88 2 229 82 99 33 160 246 79 133 174 177 206 219 10 231 247 222 39 247 38 196 55 222 102 154 93 130 211 71 226 182 150 108 54 42 55 64 25 1 52 35 9 212 30 36 60 195 4 239 128 201 28 121 187 186 167 197 11 32 230 196 239 65 44 220 187 31 87 43 169 204 57 137 225 160 180 172 78 240 21 107 98 232 177 22 129 68 168 153 74 160 25 92 174 148 193 181 36 218 22 158 81 206 127 87 135 89 50 212 59 52 98 166 20 214 192 159 66 32 46 106 47 249 200 69 61 59 144 21 15 175 136 19 100 52 127 182 58 185 208 134 133 240 84 14 156 166 83 121 96 222 131 167 134 104 224 46 40 140 191 16 163 209 185 116 214 37 82 162 190 215 180 235 235 48 205 13 197 103 205 76 104 161 139 232 146 ^'}}, + {OUT=>'051888C6D00029C176DE792B84DECE2DC1C74B00'}], + ['191', {IN=> {f=> '516 0 33 165 33 175 122 134 112 66 1 24 59 67 231 219 5 101 14 227 158 89 41 82 71 61 224 13 23 102 213 3 186 143 223 71 56 174 165 28 136 22 139 157 116 137 247 43 233 155 217 64 91 203 155 227 153 50 193 87 116 122 108 236 7 16 137 242 245 133 160 251 125 238 163 139 141 77 37 77 42 50 177 37 5 127 153 45 143 228 121 156 169 120 219 241 51 166 232 192 150 188 53 55 227 148 82 92 150 172 3 196 232 182 61 229 63 123 97 179 194 39 172 250 157 132 187 95 38 199 94 70 93 118 37 231 240 94 60 4 159 47 58 110 125 243 213 239 136 43 228 105 106 69 125 12 50 198 126 216 117 74 175 112 45 164 76 69 146 101 9 188 58 94 75 143 218 32 197 179 199 89 31 245 123 71 40 135 54 33 170 83 34 117 100 62 171 30 51 145 143 244 160 4 164 86 158 105 91 182 66 27 163 118 52 118 47 79 199 84 233 134 128 105 101 19 25 17 84 7 21 187 90 240 99 99 104 154 2 249 215 154 18 47 63 149 225 238 179 178 72 3 191 182 82 66 11 113 18 57 152 108 215 159 57 147 58 115 164 91 208 205 86 148 16 132 192 145 138 194 60 9 198 147 53 65 64 96 242 14 222 119 241 46 116 132 197 184 238 189 26 200 62 176 80 151 140 109 183 24 44 191 172 234 107 21 192 140 99 94 65 54 7 42 24 49 230 20 229 73 212 45 169 115 180 141 56 200 41 87 121 161 219 231 214 207 1 19 20 219 236 12 55 237 237 211 72 13 28 141 72 239 152 82 87 100 72 8 241 41 77 32 202 229 47 84 238 184 228 100 67 210 130 46 111 93 97 189 31 250 162 171 35 90 4 138 199 99 120 193 113 244 181 93 123 76 90 235 49 251 109 188 63 144 186 138 184 223 61 208 215 175 107 6 53 81 114 207 237 221 161 224 18 73 202 208 210 125 248 11 98 131 250 167 221 146 85 211 88 63 139 136 27 189 5 111 103 186 148 21 171 51 140 104 133 165 49 225 233 129 78 5 106 64 86 153 55 232 187 111 77 58 89 36 32 223 66 6 74 170 62 197 169 110 130 41 61 234 102 234 92 145 133 155 201 14 243 208 200 36 48 21 166 1 40 109 178 147 ^'}}, + {OUT=>'1A3540BEE05518505827954F58B751C475AEECE0'}], + ['192', {IN=> {f=> '522 0 179 196 200 34 251 241 156 51 23 75 118 41 193 202 90 93 236 125 242 125 101 151 130 14 218 34 106 41 197 173 55 112 37 108 211 65 174 142 136 159 22 19 245 127 16 19 131 101 10 133 20 104 122 126 184 227 9 187 225 208 90 230 7 131 105 213 121 39 137 105 95 147 45 23 216 92 35 75 114 70 205 206 34 110 12 185 169 111 95 6 71 29 79 203 32 195 144 161 82 64 228 92 8 104 126 74 172 223 65 170 194 171 140 221 36 21 164 198 5 102 211 206 148 136 18 48 25 131 215 36 162 161 192 142 14 214 63 141 45 141 190 86 149 219 94 182 198 115 157 252 73 203 173 192 115 43 226 67 85 62 172 227 13 135 190 227 123 213 231 94 178 227 150 161 196 90 234 210 119 124 14 104 8 100 178 109 153 167 82 201 231 98 149 215 146 217 179 59 174 28 133 130 159 163 248 239 9 183 254 243 71 174 24 162 165 163 107 10 15 46 110 8 214 204 115 39 23 79 89 6 189 3 73 85 176 198 1 154 246 210 115 153 49 108 207 117 209 146 103 176 53 56 172 113 10 129 72 116 126 70 201 3 69 114 211 202 200 171 22 247 42 139 20 218 148 132 70 83 29 75 67 199 88 178 113 124 155 78 2 214 67 89 33 160 246 69 118 159 167 196 204 5 216 237 212 34 247 38 191 55 222 92 149 78 120 211 61 226 177 140 103 39 27 50 54 25 245 241 42 25 249 212 30 21 50 195 254 239 123 186 28 106 182 171 167 192 1 17 220 181 229 65 29 220 177 26 77 33 164 194 57 137 215 150 165 167 78 230 11 102 93 232 177 22 129 68 168 138 74 145 20 77 174 138 188 171 26 218 7 158 76 201 117 72 120 74 35 197 59 52 83 151 20 214 177 144 51 27 46 106 37 249 185 59 56 54 139 16 15 160 136 14 100 37 112 182 53 170 198 119 128 240 69 4 156 161 78 116 240 96 207 121 157 134 99 209 36 25 135 186 1 158 194 175 111 209 32 77 147 190 200 175 225 235 38 195 3 187 88 205 61 89 151 134 217 206 30 162 24 166 113 128 103 66 253 15 50 58 228 210 5 98 8 218 152 80 35 79 62 58 224 7 17 102 207 3 183 140 217 65 56 168 165 22 133 16 133 157 107 128 244 12 ^'}}, + {OUT=>'DFA19180359D5A7A38E842F172359CAF4208FC05'}], + ['193', {IN=> {f=> '517 1 218 150 217 59 81 203 140 217 148 45 193 82 116 122 93 236 7 11 127 242 235 123 155 246 125 238 148 134 126 72 27 247 67 27 50 162 22 247 127 153 45 133 213 121 151 159 105 209 231 36 166 217 177 140 188 53 50 222 148 242 67 87 145 157 250 181 227 177 51 224 63 108 97 174 194 24 162 250 152 132 182 80 33 189 84 60 83 118 37 216 235 94 60 251 154 47 48 110 120 238 208 229 121 43 218 90 91 64 110 12 40 193 111 211 117 64 170 107 35 164 76 54 141 101 4 183 53 79 60 143 213 32 187 169 194 84 31 245 123 66 25 135 39 23 160 78 29 102 95 62 166 20 46 135 128 244 150 246 154 76 143 105 91 172 51 27 158 103 37 108 37 79 199 84 228 119 128 95 91 4 15 17 69 2 11 187 80 230 94 89 89 149 244 239 210 144 18 42 48 139 215 233 179 163 252 67 255 181 167 82 56 253 98 8 42 137 103 205 144 47 137 43 110 149 76 203 200 86 143 16 127 182 140 128 184 55 251 183 142 43 50 54 81 232 9 212 119 236 36 106 122 182 169 223 179 26 185 57 166 80 141 130 99 178 24 44 191 167 219 92 6 187 140 99 89 60 54 249 42 19 44 220 5 214 63 197 30 164 105 180 136 41 195 26 77 116 151 219 231 204 202 1 9 15 214 231 7 40 222 237 206 57 255 13 131 72 224 152 72 87 85 62 255 241 36 77 27 187 229 32 79 228 179 223 90 62 195 115 41 106 93 87 174 26 245 152 161 20 75 4 123 184 84 120 178 113 234 181 78 118 66 85 230 34 251 94 178 53 139 186 138 184 223 61 193 200 175 107 6 38 81 114 207 227 206 146 219 3 73 197 198 200 115 238 11 98 116 240 152 221 146 70 201 88 58 139 126 12 189 252 96 93 176 138 16 156 51 135 99 118 155 49 220 233 119 68 96 64 81 143 45 222 177 111 62 58 79 31 17 218 61 253 69 170 47 197 169 105 120 41 46 224 92 234 92 145 128 155 186 256 243 208 200 26 48 21 156 248 40 104 178 221 175 196 196 28 249 239 150 49 23 71 114 39 191 196 88 87 234 121 240 123 95 151 130 10 214 34 102 35 193 171 49 112 35 104 207 59 170 136 130 159 16 19 241 125 213 ^'}}, + {OUT=>'7B0FA84EBBCFF7D7F4500F73D79660C4A3431B67'}], + ['194', {IN=> {f=> '529 1 15 127 93 2 121 8 104 114 126 176 223 1 183 225 196 90 230 3 119 93 201 117 39 125 97 91 147 41 19 216 80 35 75 110 58 193 198 26 98 8 185 161 103 95 257 71 21 71 199 24 183 144 149 74 52 228 88 255 96 114 66 172 215 61 166 190 167 128 209 36 13 152 186 256 94 199 202 136 128 10 40 21 131 203 32 162 161 184 142 14 210 55 141 37 129 186 78 141 215 82 170 198 107 145 244 65 195 173 192 103 35 214 63 81 54 164 215 1 123 182 227 111 213 227 90 170 219 150 153 184 82 230 202 115 124 2 100 4 96 174 109 141 155 78 201 219 90 149 215 142 213 167 47 162 20 133 118 155 159 248 235 9 183 246 239 59 170 20 154 161 163 99 6 11 38 106 8 206 204 111 35 15 67 89 253 181 250 69 85 164 194 256 154 242 210 115 145 45 108 203 113 209 138 103 176 45 48 160 105 10 121 68 108 122 66 193 258 69 106 207 202 196 171 18 239 38 127 12 214 144 128 70 83 29 71 67 191 84 166 109 120 151 70 2 202 55 81 33 160 246 61 106 147 159 188 192 1 204 229 204 30 247 38 187 55 222 84 145 66 112 211 53 226 173 132 99 27 15 46 46 25 241 233 34 17 241 212 30 9 42 195 254 239 119 174 28 94 178 159 167 188 252 5 212 169 221 65 17 220 169 22 69 25 160 186 57 137 207 142 153 163 78 222 3 98 89 232 177 22 129 68 168 126 74 133 16 65 174 130 184 163 18 218 254 158 72 197 109 60 108 62 23 185 59 52 71 139 20 214 165 132 39 23 46 106 29 249 173 51 52 50 135 12 15 148 136 10 100 25 100 182 49 158 190 107 124 240 57 255 156 157 74 112 232 96 195 113 149 134 95 197 28 13 131 182 248 154 182 167 107 205 28 73 135 190 188 171 217 235 30 187 254 179 76 205 49 77 143 130 205 206 26 158 12 154 101 120 91 66 253 3 38 46 224 198 5 94 206 144 68 27 75 50 54 224 258 9 102 199 3 179 136 209 57 56 160 165 14 129 8 125 157 95 116 240 36 212 148 217 57 77 203 134 213 146 43 193 80 116 122 87 236 7 9 123 242 231 119 153 244 125 238 142 132 120 70 23 245 63 21 50 156 16 243 127 153 45 129 207 121 149 155 99 205 227 30 166 211 57 ^'}}, + {OUT=>'9E886081C9ACAAD0F97B10810D1DE6FCDCE6B5F4'}], + ['195', {IN=> {f=> '548 0 134 188 53 47 219 148 236 58 84 142 148 247 172 224 174 45 221 63 99 97 171 194 15 156 250 149 132 179 71 30 183 78 54 77 118 37 207 232 94 60 248 151 47 42 110 117 235 205 223 112 43 212 81 82 61 101 12 34 190 102 208 117 58 167 104 29 164 76 45 138 101 1 180 50 70 51 143 210 32 181 163 191 81 31 245 123 63 16 135 30 17 154 75 26 93 92 62 163 14 43 129 119 244 144 240 148 70 134 105 91 166 42 27 155 94 28 102 31 79 199 84 225 110 128 89 85 255 9 17 60 259 5 187 74 224 91 83 80 146 238 233 207 138 18 39 39 133 209 230 179 154 252 64 255 175 158 82 50 247 89 2 33 128 100 199 135 41 131 34 107 140 67 200 197 86 140 16 124 176 137 122 178 52 245 174 139 37 41 48 72 226 6 206 119 233 30 100 116 173 160 214 173 26 176 54 160 80 135 124 93 175 24 44 191 164 210 83 257 184 140 99 86 57 54 243 42 16 41 214 256 205 57 188 21 161 99 180 133 32 192 17 71 113 145 219 231 198 199 1 3 12 211 228 4 31 213 237 203 48 249 4 125 72 215 152 66 87 76 56 252 241 33 77 24 178 229 23 76 222 176 220 84 59 186 106 38 103 93 81 165 23 242 146 155 11 66 4 114 175 75 120 169 113 228 181 69 115 60 82 227 25 251 85 172 47 136 186 138 184 223 61 184 191 175 107 6 29 81 114 207 221 197 137 216 254 73 194 192 194 109 232 11 98 107 234 143 221 146 61 195 88 55 139 120 3 189 249 87 87 170 132 13 147 51 132 96 109 149 49 217 233 113 62 257 90 64 78 137 39 216 171 111 53 58 73 28 8 215 58 250 66 170 38 197 169 102 114 41 37 218 86 234 92 145 125 155 177 250 243 208 200 20 48 21 150 245 40 101 178 218 169 196 190 19 246 236 141 46 23 65 108 36 188 187 85 78 231 115 237 120 86 151 130 4 208 34 96 26 187 168 40 112 32 98 201 50 164 127 121 159 7 19 235 122 1 14 126 91 118 5 104 112 126 174 222 259 182 225 193 90 230 2 116 90 198 116 39 122 95 90 147 40 18 216 77 35 75 109 55 190 196 24 95 7 185 159 101 95 256 71 19 69 198 22 180 144 146 72 49 228 87 253 94 111 64 172 213 60 165 189 166 125 206 36 11 149 183 255 92 196 201 133 126 8 38 20 131 213 ^'}}, + {OUT=>'A4D46E4BA0AE4B012F75B1B50D0534D578AE9CB6'}], + ['196', {IN=> {f=> '547 0 29 162 161 178 142 14 207 49 141 31 120 183 72 135 212 73 161 198 101 136 238 59 189 173 192 94 29 205 60 78 48 158 206 254 114 176 227 102 213 224 87 164 213 150 147 175 76 227 196 112 124 255 97 1 93 171 109 132 146 75 201 210 84 149 215 139 210 158 38 153 14 133 109 152 156 248 232 9 183 240 236 50 167 17 148 158 163 93 3 8 32 103 8 200 204 108 32 9 58 89 247 175 244 66 85 155 191 256 154 239 210 115 139 42 108 200 110 209 132 103 176 39 42 151 99 10 115 65 102 119 63 187 258 69 100 204 202 193 171 15 233 35 118 6 211 141 125 70 83 29 68 67 185 81 157 106 117 148 64 2 193 46 75 33 160 246 55 97 138 153 182 183 260 195 223 198 27 247 38 184 55 222 78 142 57 106 211 47 226 170 126 96 18 6 43 40 25 238 227 28 11 235 212 30 36 195 254 239 116 165 28 85 175 150 167 185 249 258 206 160 215 65 8 220 163 19 63 19 157 180 57 137 201 136 144 160 78 216 259 95 86 232 177 22 129 68 168 117 74 124 13 56 174 124 181 157 12 218 248 158 69 194 103 51 99 53 14 176 59 52 62 130 20 214 156 123 30 20 46 106 23 249 164 45 49 47 132 9 15 139 136 7 100 16 91 182 46 149 184 98 121 240 48 252 156 154 71 109 226 96 186 107 143 134 92 188 22 4 128 179 242 151 173 161 104 202 25 70 126 190 179 168 211 235 24 181 251 173 67 205 40 68 137 127 196 206 23 155 3 145 92 114 82 66 253 256 29 37 221 189 5 91 256 197 138 59 21 72 41 51 224 255 3 102 193 3 176 133 203 51 56 154 165 8 126 2 119 157 86 107 237 33 203 145 217 54 71 203 125 207 143 40 193 77 116 122 78 236 7 6 117 242 225 113 150 241 125 238 133 129 111 67 17 242 57 12 50 147 7 237 127 153 45 123 198 121 146 149 90 199 221 21 166 202 162 130 188 53 45 217 148 232 52 82 140 142 245 166 222 172 41 219 63 93 97 169 194 9 152 250 147 132 177 65 28 179 74 50 73 118 37 201 230 94 60 246 149 47 38 110 115 233 203 219 106 43 208 75 76 59 95 12 30 188 96 206 117 54 165 102 25 164 76 39 136 101 261 178 48 64 45 143 208 32 177 159 189 79 31 245 123 61 10 135 24 13 150 73 24 87 90 62 161 10 41 125 209 ^'}}, + {OUT=>'6342B199EE64C7B2C9CBCD4F2DCB65ACEF51516F'}], + ['197', {IN=> {f=> '542 1 244 136 232 140 62 122 105 91 158 30 27 151 82 16 94 23 79 199 84 221 98 128 81 77 247 1 17 48 259 261 187 66 216 87 75 68 142 230 225 203 130 18 35 27 125 201 226 179 142 252 60 255 167 146 82 42 239 77 258 21 116 96 191 123 33 123 22 103 128 55 196 193 86 136 16 120 168 133 114 170 48 237 162 135 29 29 40 60 218 2 198 119 229 22 92 108 161 148 202 165 26 164 50 152 80 127 116 85 171 24 44 191 160 198 71 249 180 140 99 82 53 54 235 42 12 37 206 248 193 49 176 9 157 91 180 129 20 188 5 63 109 137 219 231 190 195 1 259 8 207 224 19 201 237 199 36 241 256 117 72 203 152 58 87 64 48 248 241 29 77 20 166 229 11 72 214 172 216 76 55 174 94 34 99 93 73 153 19 238 138 147 263 54 4 102 163 63 120 157 113 220 181 57 111 52 78 223 13 251 73 164 39 132 186 138 184 223 61 172 179 175 107 6 17 81 114 207 213 185 125 212 246 73 190 184 186 101 224 11 98 95 226 131 221 146 49 187 88 51 139 112 255 189 245 75 79 162 124 9 135 51 128 92 97 141 49 213 233 105 54 257 82 64 74 129 31 208 163 111 41 58 65 24 260 211 54 246 62 170 26 197 169 98 106 41 25 210 78 234 92 145 121 155 165 242 243 208 200 12 48 21 142 241 40 97 178 214 161 196 182 7 242 232 129 42 23 57 100 32 184 175 81 66 227 107 233 116 74 151 130 260 200 34 88 14 179 164 28 112 28 90 193 38 156 115 109 159 259 19 227 118 253 10 122 83 256 106 257 104 104 126 166 218 255 178 225 181 90 230 262 104 78 186 112 39 110 87 86 147 36 14 216 65 35 75 105 43 178 188 16 83 3 185 151 93 95 252 71 11 61 194 14 168 144 134 64 37 228 83 245 86 99 56 172 205 56 161 185 162 113 194 36 3 137 171 251 84 184 197 121 118 30 16 131 188 27 162 161 174 142 14 205 45 141 27 114 181 68 131 210 67 155 198 97 130 234 55 185 173 192 88 25 199 58 76 44 154 200 250 108 172 227 96 213 222 85 160 209 150 143 169 72 225 192 110 124 251 95 263 91 169 109 126 140 73 201 204 80 149 215 137 208 152 32 147 10 133 103 150 154 248 230 9 183 236 234 44 165 15 144 156 163 89 1 6 28 101 8 196 204 106 164 ^'}}, + {OUT=>'AABFD63688EB678357869130083E1B52F6EA861D'}], + ['198', {IN=> {f=> '567 0 1 46 89 239 167 236 62 85 143 187 256 154 235 210 115 131 38 108 196 106 209 124 103 176 31 34 139 91 10 107 61 94 115 59 179 258 69 92 200 202 189 171 11 225 31 106 264 207 137 121 70 83 29 64 67 177 77 145 102 113 144 56 2 181 34 67 33 160 246 47 85 126 145 174 171 260 183 215 190 23 247 38 180 55 222 70 138 45 98 211 39 226 166 118 92 6 260 39 32 25 234 219 20 3 227 212 30 254 28 195 254 239 112 153 28 73 171 138 167 181 245 250 198 148 207 65 262 220 155 15 55 11 153 172 57 137 193 128 132 156 78 208 255 91 82 232 177 22 129 68 168 105 74 112 9 44 174 116 177 149 4 218 240 158 65 190 95 39 87 41 2 164 59 52 50 118 20 214 144 111 18 16 46 106 15 249 152 37 45 43 128 5 15 127 136 3 100 4 79 182 42 137 176 86 117 240 36 248 156 150 67 105 218 96 174 99 135 134 88 176 14 258 124 175 234 147 161 153 100 198 21 66 114 190 167 164 203 235 16 173 247 165 55 205 28 56 129 123 184 206 19 151 257 133 80 106 70 66 253 248 17 25 217 177 5 87 252 185 130 47 13 68 29 47 224 251 261 102 185 3 172 129 195 43 56 146 165 122 260 111 157 74 95 233 29 191 141 217 50 63 203 113 199 139 36 193 73 116 122 66 236 7 2 109 242 217 105 146 237 125 238 121 125 99 63 9 238 49 50 135 261 229 127 153 45 115 186 121 142 141 78 191 213 9 166 190 150 122 188 53 41 213 148 224 40 78 136 130 241 154 218 168 33 215 63 81 97 165 194 263 144 250 143 132 173 53 24 171 66 42 65 118 37 189 226 94 60 242 145 47 30 110 111 229 199 211 94 43 200 63 64 55 83 12 22 184 84 202 117 46 161 98 17 164 76 27 132 101 261 174 44 52 33 143 204 32 169 151 185 75 31 245 123 57 264 135 12 5 142 69 20 75 86 62 157 2 37 117 101 244 132 228 136 58 116 105 91 154 24 27 149 76 10 90 19 79 199 84 219 92 128 77 73 243 263 17 42 259 259 187 62 212 85 71 62 140 226 221 201 126 18 33 21 121 197 224 179 136 252 58 255 163 140 82 38 235 71 256 15 110 94 187 117 29 119 16 101 122 49 194 191 86 134 16 118 164 131 110 166 46 233 156 133 25 23 36 54 214 194 119 227 18 88 104 155 142 196 161 26 158 48 148 80 123 112 81 169 24 44 191 158 192 65 245 178 140 223 ^'}}, + {OUT=>'F732B7372DAF44801F81EFFE3108726239837936'}], + ['199', {IN=> {f=> '551 1 78 49 54 227 42 8 33 198 240 181 41 164 265 153 83 180 125 8 184 261 55 105 129 219 231 182 191 1 255 4 203 220 264 7 189 237 195 24 233 248 109 72 191 152 50 87 52 40 244 241 25 77 16 154 229 267 68 206 168 212 68 51 162 82 30 95 93 65 141 15 234 130 139 255 42 4 90 151 51 120 145 113 212 181 45 107 44 74 219 1 251 61 156 31 128 186 138 184 223 61 160 167 175 107 6 5 81 114 207 205 173 113 208 238 73 186 176 178 93 216 11 98 83 218 119 221 146 37 179 88 47 139 104 247 189 241 63 71 154 116 5 123 51 124 88 85 133 49 209 233 97 46 257 74 64 70 121 23 200 155 111 29 58 57 20 252 207 50 242 58 170 14 197 169 94 98 41 13 202 70 234 92 145 117 155 153 234 243 208 200 4 48 21 134 237 40 93 178 210 153 196 174 263 238 228 117 38 23 49 92 28 180 163 77 54 223 99 229 112 62 151 130 256 192 34 80 2 171 160 16 112 24 82 185 26 148 103 97 159 251 19 219 114 245 6 118 75 252 94 249 104 96 126 158 214 251 174 225 169 90 230 262 92 66 174 108 39 98 79 82 147 32 10 216 53 35 75 101 31 166 180 8 71 267 185 143 85 95 248 71 3 53 190 6 156 144 122 56 25 228 79 237 78 87 48 172 197 52 157 181 158 101 182 36 263 125 159 247 76 172 193 109 110 260 22 12 131 176 23 162 161 166 142 14 201 37 141 19 102 177 60 123 206 55 143 198 89 118 226 47 177 173 192 76 17 187 54 72 36 146 188 242 96 164 227 84 213 218 81 152 201 150 135 157 64 221 184 106 124 243 91 263 87 165 109 114 128 69 201 192 72 149 215 133 204 140 20 135 2 133 91 146 150 248 226 9 183 228 230 32 161 11 136 152 163 81 265 2 20 97 8 188 204 102 26 265 40 89 235 163 232 60 85 137 185 256 154 233 210 115 127 36 108 194 104 209 120 103 176 27 30 133 87 10 103 59 90 113 57 175 258 69 88 198 202 187 171 9 221 29 100 262 205 135 119 70 83 29 62 67 173 75 139 100 111 142 52 2 175 28 63 33 160 246 43 79 120 141 170 165 260 177 211 186 21 247 38 178 55 222 66 136 39 94 211 35 226 164 114 90 256 37 28 25 232 215 16 267 223 212 30 250 24 195 254 239 110 147 28 67 169 132 167 179 243 246 194 142 203 65 263 ^'}}, + {OUT=>'5E9347FE4574CDCB80281ED092191199BADD7B42'}], + ['200', {IN=> {f=> '578 0 220 147 11 47 3 149 164 57 137 185 120 120 152 78 200 251 87 78 232 177 22 129 68 168 93 74 100 5 32 174 108 173 141 266 218 232 158 61 186 87 27 75 29 260 152 59 52 38 106 20 214 132 99 6 12 46 106 7 249 140 29 41 39 124 1 15 115 136 269 100 262 67 182 38 125 168 74 113 240 24 244 156 146 63 101 210 96 162 91 127 134 84 164 6 250 120 171 226 143 149 145 96 194 17 62 102 190 155 160 195 235 8 165 243 157 43 205 16 44 121 119 172 206 15 147 249 121 68 98 58 66 253 240 5 13 213 165 5 83 248 173 122 35 5 64 17 43 224 247 257 102 177 3 168 125 187 35 56 138 165 262 118 256 103 157 62 83 229 25 179 137 217 46 55 203 101 191 135 32 193 69 116 122 54 236 7 268 101 242 209 97 142 233 125 238 109 121 87 59 1 234 41 258 50 123 253 221 127 153 45 107 174 121 138 133 66 183 205 267 166 178 138 114 188 53 37 209 148 216 28 74 132 118 237 142 214 164 25 211 63 69 97 161 194 255 136 250 139 132 169 41 20 163 58 34 57 118 37 177 222 94 60 238 141 47 22 110 107 225 195 203 82 43 192 51 52 51 71 12 14 180 72 198 117 38 157 94 9 164 76 15 128 101 261 170 40 40 21 143 200 32 161 143 181 71 31 245 123 53 256 135 267 134 65 16 63 82 62 153 264 33 109 89 244 124 220 128 50 104 105 91 146 12 27 145 64 268 82 11 79 199 84 215 80 128 69 65 235 259 17 30 259 255 187 54 204 81 63 50 136 218 213 197 118 18 29 9 113 189 220 179 124 252 54 255 155 128 82 30 227 59 252 3 98 90 179 105 21 111 4 97 110 37 190 187 86 130 16 114 156 127 102 158 42 225 144 129 17 11 28 42 206 266 186 119 223 10 80 96 143 130 184 153 26 146 44 140 80 115 104 73 165 24 44 191 154 180 53 237 174 140 99 76 47 54 223 42 6 31 194 236 175 37 158 261 151 79 180 123 2 182 257 51 103 125 219 231 178 189 1 253 2 201 218 264 1 183 237 193 18 229 244 105 72 185 152 46 87 46 36 242 241 23 77 14 148 229 263 66 202 166 210 64 49 156 76 28 93 93 61 135 13 232 126 135 251 36 4 84 145 45 120 139 113 208 181 39 105 40 72 217 265 251 55 152 27 126 186 138 184 223 61 154 161 175 107 6 269 81 114 207 201 167 107 206 234 73 184 172 174 89 212 11 98 77 214 113 221 146 31 175 88 45 139 100 243 189 213 ^'}}, + {OUT=>'D5776B7DFFF75C1358ABDBBB3F27A20BB6CA7C55'}], + ['201', {IN=> {f=> '578 1 51 63 146 108 1 111 51 120 84 73 125 49 205 233 89 38 257 66 64 66 113 15 192 147 111 17 58 49 16 244 203 46 238 54 170 2 197 169 90 90 41 1 194 62 234 92 145 113 155 141 226 243 208 200 268 48 21 126 233 40 89 178 206 145 196 166 255 234 224 105 34 23 41 84 24 176 151 73 42 219 91 225 108 50 151 130 252 184 34 72 262 163 156 4 112 20 74 177 14 140 91 85 159 243 19 211 110 237 2 114 67 248 82 241 104 88 126 150 210 247 170 225 157 90 230 262 80 54 162 104 39 86 71 78 147 28 6 216 41 35 75 97 19 154 172 59 267 185 135 77 95 244 71 267 45 186 270 144 144 110 48 13 228 75 229 70 75 40 172 189 48 153 177 154 89 170 36 259 113 147 243 68 160 189 97 102 256 14 8 131 164 19 162 161 158 142 14 197 29 141 11 90 173 52 115 202 43 131 198 81 106 218 39 169 173 192 64 9 175 50 68 28 138 176 234 84 156 227 72 213 214 77 144 193 150 127 145 56 217 176 102 124 235 87 263 83 161 109 102 116 65 201 180 64 149 215 129 200 128 8 123 266 133 79 142 146 248 222 9 183 220 226 20 157 7 128 148 163 73 265 270 12 93 8 180 204 98 22 261 28 89 227 155 224 56 85 125 181 256 154 229 210 115 119 32 108 190 100 209 112 103 176 19 22 121 79 10 95 55 82 109 53 167 258 69 80 194 202 183 171 5 213 25 88 258 201 131 115 70 83 29 58 67 165 71 127 96 107 138 44 2 163 16 55 33 160 246 35 67 108 133 162 153 260 165 203 178 17 247 38 174 55 222 58 132 27 86 211 27 226 160 106 86 260 248 33 20 25 228 207 8 263 215 212 30 242 16 195 254 239 106 135 28 55 165 120 167 175 239 238 186 130 195 65 250 220 143 9 43 271 147 160 57 137 181 116 114 150 78 196 249 85 76 232 177 22 129 68 168 87 74 94 3 26 174 104 171 137 264 218 228 158 59 184 83 21 69 23 256 146 59 52 32 100 20 214 126 93 10 46 106 3 249 134 25 39 37 122 271 15 109 136 269 100 258 61 182 36 119 164 68 111 240 18 242 156 144 61 99 206 96 156 87 123 134 82 158 2 246 118 169 222 141 143 141 94 192 15 60 96 190 149 158 191 235 4 161 241 153 37 205 10 38 117 117 166 206 13 145 245 115 62 94 52 66 253 236 271 7 211 159 5 81 246 167 118 29 1 62 11 41 224 245 255 102 173 3 166 123 183 31 56 134 165 260 116 254 81 ^'}}, + {OUT=>'022B7ADA472FB7A9DA9219621C9C5F563D3792F6'}], + ['202', {IN=> {f=> '583 1 157 50 71 225 21 167 133 217 42 47 203 89 183 131 28 193 65 116 122 42 236 7 268 93 242 201 89 138 229 125 238 97 117 75 55 267 230 33 250 50 111 245 213 127 153 45 99 162 121 134 125 54 175 197 259 166 166 126 106 188 53 33 205 148 208 16 70 128 106 233 130 210 160 17 207 63 57 97 157 194 247 128 250 135 132 165 29 16 155 50 26 49 118 37 165 218 94 60 234 137 47 14 110 103 221 191 195 70 43 184 39 40 47 59 12 6 176 60 194 117 30 153 90 1 164 76 3 124 101 261 166 36 28 9 143 196 32 153 135 177 67 31 245 123 49 248 135 262 263 126 61 12 51 78 62 149 260 29 101 77 244 116 212 120 42 92 105 91 138 27 141 52 260 74 3 79 199 84 211 68 128 61 57 227 255 17 18 259 251 187 46 196 77 55 38 132 210 205 193 110 18 25 271 105 181 216 179 112 252 50 255 147 116 82 22 219 47 248 265 86 86 171 93 13 103 266 93 98 25 186 183 86 126 16 110 148 123 94 150 38 217 132 125 9 273 20 30 198 266 178 119 219 2 72 88 131 118 172 145 26 134 40 132 80 107 96 65 161 24 44 191 150 168 41 229 170 140 99 72 43 54 215 42 2 27 186 228 163 29 146 253 147 71 180 119 264 178 249 43 99 117 219 231 170 185 1 249 272 197 214 264 263 171 237 189 6 221 236 97 72 173 152 38 87 34 28 238 241 19 77 10 136 229 255 62 194 162 206 56 45 144 64 24 89 93 53 123 9 228 118 127 243 24 4 72 133 33 120 127 113 200 181 27 101 32 68 213 257 251 43 144 19 122 186 138 184 223 61 142 149 175 107 6 261 81 114 207 193 155 95 202 226 73 180 164 166 81 204 11 98 65 206 101 221 146 19 167 88 41 139 92 235 189 235 45 59 142 104 273 105 51 118 82 67 121 49 203 233 85 34 257 62 64 64 109 11 188 143 111 11 58 45 14 240 201 44 236 52 170 270 197 169 88 86 41 269 190 58 234 92 145 111 155 135 222 243 208 200 266 48 21 122 231 40 87 178 204 141 196 162 251 232 222 99 32 23 37 80 22 174 145 71 36 217 87 223 106 44 151 130 250 180 34 68 258 159 154 272 112 18 70 173 8 136 85 79 159 239 19 207 108 233 112 63 246 76 237 104 84 126 146 208 245 168 225 151 90 230 262 74 48 156 102 39 80 67 76 147 26 4 216 35 35 75 95 13 148 168 270 53 267 185 131 73 95 242 71 265 41 184 268 138 144 104 44 7 228 73 225 66 69 36 272 ^'}}, + {OUT=>'7F1DE4ECA20362DA624653D225A5B3F7964A9FF2'}], + ['203', {IN=> {f=> '588 0 181 44 149 173 150 77 158 36 255 101 135 239 60 148 185 85 94 252 6 4 131 152 15 162 161 150 142 14 193 21 141 3 78 169 44 107 198 31 119 198 73 94 210 31 161 173 192 52 1 163 46 64 20 130 164 226 72 148 227 60 213 210 73 136 185 150 119 133 48 213 168 98 124 227 83 263 79 157 109 90 104 61 201 168 56 149 215 125 196 116 272 111 262 133 67 138 142 248 218 9 183 212 222 8 153 3 120 144 163 65 265 270 4 89 8 172 204 94 18 257 16 89 219 147 216 52 85 113 177 256 154 225 210 115 111 28 108 186 96 209 104 103 176 11 14 109 71 10 87 51 74 105 49 159 258 69 72 190 202 179 171 1 205 21 76 254 197 127 111 70 83 29 54 67 157 67 115 92 103 134 36 2 151 4 47 33 160 246 27 55 96 125 154 141 260 153 195 170 13 247 38 170 55 222 50 128 15 78 211 19 226 156 98 82 252 240 29 12 25 224 199 259 207 212 30 234 8 195 254 239 102 123 28 43 161 108 167 171 235 230 178 118 187 65 242 220 135 5 35 267 143 152 57 137 173 108 102 146 78 188 245 81 72 232 177 22 129 68 168 75 74 82 275 14 174 96 167 129 260 218 220 158 55 180 75 9 57 11 248 134 59 52 20 88 20 214 114 81 264 6 46 106 271 249 122 17 35 33 118 271 15 97 136 269 100 250 49 182 32 107 156 56 107 240 6 238 156 140 57 95 198 96 144 79 115 134 78 146 270 238 114 165 214 137 131 133 90 188 11 56 84 190 137 154 183 235 272 153 237 145 25 205 274 26 109 113 154 206 9 141 237 103 50 86 40 66 253 228 263 271 207 147 5 77 242 155 110 17 269 58 275 37 224 241 251 102 165 3 162 119 175 23 56 126 165 256 112 250 91 157 44 65 223 19 161 131 217 40 43 203 83 179 129 26 193 63 116 122 36 236 7 268 89 242 197 85 136 227 125 238 91 115 69 53 265 228 29 246 50 105 241 209 127 153 45 95 156 121 132 121 48 171 193 255 166 160 120 102 188 53 31 203 148 204 10 68 126 100 231 124 208 158 13 205 63 51 97 155 194 243 124 250 133 132 163 23 14 151 46 22 45 118 37 159 216 94 60 232 135 47 10 110 101 219 189 191 64 43 180 33 34 45 53 12 2 174 54 192 117 26 151 88 273 164 76 273 122 101 261 164 34 22 3 143 194 32 149 131 175 65 31 245 123 47 244 135 258 261 122 59 10 45 76 62 147 258 27 97 71 244 112 208 116 38 86 105 91 134 270 27 139 46 256 70 275 79 199 160 ^'}}, + {OUT=>'CA0F2B1BFB4469C11ED006A994734F0F2F5EFD17'}], + ['204', {IN=> {f=> '594 0 207 56 128 53 49 219 251 17 6 259 247 187 38 188 73 47 26 128 202 197 189 102 18 21 263 97 173 212 179 100 252 46 255 139 104 82 14 211 35 244 257 74 82 163 81 5 95 258 89 86 13 182 179 86 122 16 106 140 119 86 142 34 209 120 121 1 265 12 18 190 266 170 119 215 272 64 80 119 106 160 137 26 122 36 124 80 99 88 57 157 24 44 191 146 156 29 221 166 140 99 68 39 54 207 42 276 23 178 220 151 21 134 245 143 63 180 115 256 174 241 35 95 109 219 231 162 181 1 245 272 193 210 264 255 159 237 185 272 213 228 89 72 161 152 30 87 22 20 234 241 15 77 6 124 229 247 58 186 158 202 48 41 132 52 20 85 93 45 111 5 224 110 119 235 12 4 60 121 21 120 115 113 192 181 15 97 24 64 209 249 251 31 136 11 118 186 138 184 223 61 130 137 175 107 6 253 81 114 207 185 143 83 198 218 73 176 156 158 73 196 11 98 53 198 89 221 146 7 159 88 37 139 84 227 189 231 33 51 134 96 273 93 51 114 78 55 113 49 199 233 77 26 257 54 64 60 101 3 180 135 111 277 58 37 10 232 197 40 232 48 170 262 197 169 84 78 41 261 182 50 234 92 145 107 155 123 214 243 208 200 262 48 21 114 227 40 83 178 200 133 196 154 243 228 218 87 28 23 29 72 18 170 133 67 24 213 79 219 102 32 151 130 246 172 34 60 250 151 150 264 112 14 62 165 274 128 73 67 159 231 19 199 104 225 274 108 55 242 64 229 104 76 126 138 204 241 164 225 139 90 230 262 62 36 144 98 39 68 59 72 147 22 216 23 35 75 91 1 136 160 266 41 267 185 123 65 95 238 71 261 33 180 264 126 144 92 36 273 228 69 217 58 57 28 172 177 42 147 171 148 71 152 36 253 95 129 237 56 142 183 79 90 250 2 2 131 146 13 162 161 146 142 14 191 17 141 277 72 167 40 103 196 25 113 198 69 88 206 27 157 173 192 46 275 157 44 62 16 126 158 222 66 144 227 54 213 208 71 132 181 150 115 127 44 211 164 96 124 223 81 263 77 155 109 84 98 59 201 162 52 149 215 123 194 110 268 105 260 133 61 136 140 248 216 9 183 208 220 2 151 1 116 142 163 61 265 270 87 8 168 204 92 16 255 10 89 215 143 212 50 85 107 175 256 154 223 210 115 107 26 108 184 94 209 100 103 176 7 10 103 67 10 83 49 70 103 47 155 258 69 68 188 202 177 171 277 201 19 70 252 195 125 109 70 83 29 52 67 153 65 109 90 101 132 32 2 145 276 43 33 160 246 23 259 ^'}}, + {OUT=>'833D63F5C2EA0CD43EC15F2B9DD97FF12B030479'}], + ['205', {IN=> {f=> '600 1 87 119 148 132 260 144 189 164 10 247 38 167 55 222 44 125 6 72 211 13 226 153 92 79 246 234 26 6 25 221 193 273 256 201 212 30 228 2 195 254 239 99 114 28 34 158 99 167 168 232 224 172 109 181 65 236 220 129 2 29 264 140 146 57 137 167 102 93 143 78 182 242 78 69 232 177 22 129 68 168 66 74 73 275 5 174 90 164 123 257 218 214 158 52 177 69 48 2 242 125 59 52 11 79 20 214 105 72 258 3 46 106 268 249 113 11 32 30 115 271 15 88 136 269 100 244 40 182 29 98 150 47 104 240 276 235 156 137 54 92 192 96 135 73 109 134 75 137 267 232 111 162 208 134 122 127 87 185 8 53 75 190 128 151 177 235 269 147 234 139 16 205 268 17 103 110 145 206 6 138 231 94 41 80 31 66 253 222 257 265 204 138 5 74 239 146 104 8 266 55 269 34 224 238 248 102 159 3 159 116 169 17 56 120 165 253 109 247 85 157 35 56 220 16 152 128 217 37 37 203 74 173 126 23 193 60 116 122 27 236 7 268 83 242 191 79 133 224 125 238 82 112 60 50 262 225 23 240 50 96 235 203 127 153 45 89 147 121 129 115 39 165 187 249 166 151 111 96 188 53 28 200 148 198 1 65 123 91 228 115 205 155 7 202 63 42 97 152 194 237 118 250 130 132 160 14 11 145 40 16 39 118 37 150 213 94 60 229 132 47 4 110 98 216 186 185 55 43 174 24 25 42 44 12 275 171 45 189 117 20 148 85 270 164 76 267 119 101 261 161 31 13 273 143 191 32 143 125 172 62 31 245 123 44 238 135 252 258 116 56 7 36 73 62 144 255 24 91 62 244 106 202 110 32 77 105 91 128 264 27 136 37 250 64 272 79 199 84 206 53 128 51 47 217 250 17 3 259 246 187 36 186 72 45 23 127 200 195 188 100 18 20 261 95 171 211 179 97 252 45 255 137 101 82 12 209 32 243 255 71 81 161 78 3 93 256 88 83 10 181 178 86 121 16 105 138 118 84 140 33 207 117 120 278 263 10 15 188 266 168 119 214 271 62 78 116 103 157 135 26 119 35 122 80 97 86 55 156 24 44 191 145 153 26 219 165 140 99 67 38 54 205 42 276 22 176 218 148 19 131 243 142 61 180 114 254 173 239 33 94 107 219 231 160 180 1 244 272 192 209 264 253 156 237 184 270 211 226 87 72 158 152 28 87 19 18 233 241 14 77 5 121 229 245 57 184 157 201 46 40 129 49 19 84 93 43 108 4 223 108 117 233 9 4 57 118 18 120 112 113 190 181 12 96 22 63 208 247 251 28 134 9 117 186 138 184 223 61 127 216 ^'}}, + {OUT=>'14FD356190416C00592B86FF7CA50B622F85593A'}], + ['206', {IN=> {f=> '590 1 175 107 6 247 81 114 207 179 134 74 195 212 73 173 150 152 67 190 11 98 44 192 80 221 146 279 153 88 34 139 78 221 189 228 24 45 128 90 273 84 51 111 75 46 107 49 196 233 71 20 257 48 64 57 95 278 174 129 111 271 58 31 7 226 194 37 229 45 170 256 197 169 81 72 41 255 176 44 234 92 145 104 155 114 208 243 208 200 259 48 21 108 224 40 80 178 197 127 196 148 237 225 215 78 25 23 23 66 15 167 124 64 15 210 73 216 99 23 151 130 243 166 34 54 244 145 147 258 112 11 56 159 268 122 64 58 159 225 19 193 101 219 274 105 49 239 55 223 104 70 126 132 201 238 161 225 130 90 230 262 53 27 135 95 39 59 53 69 147 19 278 216 14 35 75 88 273 127 154 263 32 267 185 117 59 95 235 71 258 27 177 261 117 144 83 30 267 228 66 211 52 48 22 172 171 39 144 168 145 62 143 36 250 86 120 234 50 133 180 70 84 247 277 280 131 137 10 162 161 140 142 14 188 11 141 274 63 164 34 97 193 16 104 198 63 79 200 21 151 173 192 37 272 148 41 59 10 120 149 216 57 138 227 45 213 205 68 126 175 150 109 118 38 208 158 93 124 217 78 263 74 152 109 75 89 56 201 153 46 149 215 120 191 101 262 96 257 133 52 133 137 248 213 9 183 202 217 274 148 279 110 139 163 55 265 270 275 84 8 162 204 89 13 252 1 89 209 137 206 47 85 98 172 256 154 220 210 115 101 23 108 181 91 209 94 103 176 1 4 94 61 10 77 46 64 100 44 149 258 69 62 185 202 174 171 277 195 16 61 249 192 122 106 70 83 29 49 67 147 62 100 87 98 129 26 2 136 270 37 33 160 246 17 40 81 115 144 126 260 138 185 160 8 247 38 165 55 222 40 123 68 211 9 226 151 88 77 242 230 24 2 25 219 189 271 254 197 212 30 224 279 195 254 239 97 108 28 28 156 93 167 166 230 220 168 103 177 65 232 220 125 25 262 138 142 57 137 163 98 87 141 78 178 240 76 67 232 177 22 129 68 168 60 74 67 275 280 174 86 162 119 255 218 210 158 50 175 65 275 42 277 238 119 59 52 5 73 20 214 99 66 254 1 46 106 266 249 107 7 30 28 113 271 15 82 136 269 100 240 34 182 27 92 146 41 102 240 272 233 156 135 52 90 188 96 129 69 105 134 73 131 265 228 109 160 204 132 116 123 85 183 6 51 69 190 122 149 173 235 267 143 232 135 10 205 264 11 99 108 139 206 4 136 227 88 35 76 25 66 253 218 253 261 202 132 5 72 237 140 203 ^'}}, + {OUT=>'4AB6B57EDDEF1CE935622F935C1619AE7C1667D6'}], + ['207', {IN=> {f=> '620 0 279 262 51 261 30 224 234 244 102 151 3 155 112 161 9 56 112 165 249 105 243 77 157 23 44 216 12 140 124 217 33 29 203 62 165 122 19 193 56 116 122 15 236 7 268 75 242 183 71 129 220 125 238 70 108 48 46 258 221 15 232 50 84 227 195 127 153 45 81 135 121 125 107 27 157 179 241 166 139 99 88 188 53 24 196 148 190 272 61 119 79 224 103 201 151 282 198 63 30 97 148 194 229 110 250 126 132 156 2 7 137 32 8 31 118 37 138 209 94 60 225 128 47 279 110 94 212 182 177 43 43 166 12 13 38 32 12 271 167 33 185 117 12 144 81 266 164 76 259 115 101 261 157 27 1 265 143 187 32 135 117 168 58 31 245 123 40 230 135 244 254 108 52 3 24 69 62 140 251 20 83 50 244 98 194 102 24 65 105 91 120 256 27 132 25 242 56 268 79 199 84 202 41 128 43 39 209 246 17 274 259 242 187 28 178 68 37 11 123 192 187 184 92 18 16 253 87 163 207 179 85 252 41 255 129 89 82 4 201 20 239 247 59 77 153 66 278 85 248 84 71 281 177 174 86 117 16 101 130 114 76 132 29 199 105 116 274 255 2 3 180 266 160 119 210 267 54 70 104 91 145 127 26 107 31 114 80 89 78 47 152 24 44 191 141 141 14 211 161 140 99 63 34 54 197 42 276 18 168 210 136 11 119 235 138 53 180 110 246 169 231 25 90 99 219 231 152 176 1 240 272 188 205 264 245 144 237 180 262 203 218 79 72 146 152 20 87 7 10 229 241 10 77 1 109 229 237 53 176 153 197 38 36 117 37 15 80 93 35 96 219 100 109 225 280 4 45 106 6 120 100 113 182 181 92 14 59 204 239 251 16 126 1 113 186 138 184 223 61 115 122 175 107 6 243 81 114 207 175 128 68 193 208 73 171 146 148 63 186 11 98 38 188 74 221 146 275 149 88 32 139 74 217 189 226 18 41 124 86 273 78 51 109 73 40 103 49 194 233 67 16 257 44 64 55 91 276 170 125 111 267 58 27 5 222 192 35 227 43 170 252 197 169 79 68 41 251 172 40 234 92 145 102 155 108 204 243 208 200 257 48 21 104 222 40 78 178 195 123 196 144 233 223 213 72 23 23 19 62 13 165 118 62 9 208 69 214 97 17 151 130 241 162 34 50 240 141 145 254 112 9 52 155 264 118 58 52 159 221 19 189 99 215 274 103 45 237 49 219 104 66 126 128 199 236 159 225 124 90 230 262 47 21 129 93 39 53 49 67 147 17 278 216 8 35 75 86 269 121 150 261 26 267 185 113 55 95 233 71 256 23 175 259 111 144 77 26 263 228 64 207 48 42 18 172 167 37 142 166 143 56 137 36 248 80 114 232 46 127 257 ^'}}, + {OUT=>'B456A6A968ACD66CAA974F96A9A916E700AA3C5D'}], + ['208', {IN=> {f=> '605 1 58 76 243 273 280 131 125 6 162 161 132 142 14 184 3 141 270 51 160 26 89 189 4 92 198 55 67 192 13 143 173 192 25 268 136 37 55 2 112 137 208 45 130 227 33 213 201 64 118 167 150 101 106 30 204 150 89 124 209 74 263 70 148 109 63 77 52 201 141 38 149 215 116 187 89 254 84 253 133 40 129 133 248 209 9 183 194 213 266 144 279 102 135 163 47 265 270 271 80 8 154 204 85 9 248 274 89 201 129 198 43 85 86 168 256 154 216 210 115 93 19 108 177 87 209 86 103 176 278 281 82 53 10 69 42 56 96 40 141 258 69 54 181 202 170 171 277 187 12 49 245 188 118 102 70 83 29 45 67 139 58 88 83 94 125 18 2 124 262 29 33 160 246 9 28 69 107 136 114 260 126 177 152 4 247 38 161 55 222 32 119 273 60 211 1 226 147 80 73 234 222 20 279 25 215 181 267 250 189 212 30 216 275 195 254 239 93 96 28 16 152 81 167 162 226 212 160 91 169 65 224 220 117 281 17 258 134 134 57 137 155 90 75 137 78 170 236 72 63 232 177 22 129 68 168 48 74 55 275 272 174 78 158 111 251 218 202 158 46 171 57 267 30 269 230 107 59 52 278 61 20 214 87 54 246 282 46 106 262 249 95 284 26 24 109 271 15 70 136 269 100 232 22 182 23 80 138 29 98 240 264 229 156 131 48 86 180 96 117 61 97 134 69 119 261 220 105 156 196 128 104 115 81 179 2 47 57 190 110 145 165 235 263 135 228 127 283 205 256 284 91 104 127 206 132 219 76 23 68 13 66 253 210 245 253 198 120 5 68 233 128 92 275 260 49 257 28 224 232 242 102 147 3 153 110 157 5 56 108 165 247 103 241 73 157 17 38 214 10 134 122 217 31 25 203 56 161 120 17 193 54 116 122 9 236 7 268 71 242 179 67 127 218 125 238 64 106 42 44 256 219 11 228 50 78 223 191 127 153 45 77 129 121 123 103 21 153 175 237 166 133 93 84 188 53 22 194 148 186 268 59 117 73 222 97 199 149 280 196 63 24 97 146 194 225 106 250 124 132 154 281 5 133 28 4 27 118 37 132 207 94 60 223 126 47 277 110 92 210 180 173 37 43 162 6 7 36 26 12 269 165 27 183 117 8 142 79 264 164 76 255 113 101 261 155 25 280 261 143 185 32 131 113 166 56 31 245 123 38 226 135 240 252 104 50 1 18 67 62 138 249 18 79 44 244 94 190 98 20 59 105 91 116 252 27 130 19 238 52 266 79 199 84 200 35 128 39 35 205 244 17 270 259 240 187 24 174 66 33 5 121 188 183 182 88 18 14 249 83 159 205 179 79 252 186 ^'}}, + {OUT=>'FD1C257FE046B2A27E2F0CD55ED2DECA845F01D7'}], + ['209', {IN=> {f=> '615 0 255 121 77 82 283 193 8 235 239 47 73 145 54 274 77 240 80 59 273 173 170 86 113 16 97 122 110 68 124 25 191 93 112 270 247 281 278 172 266 152 119 206 263 46 62 92 79 133 119 26 95 27 106 80 81 70 39 148 24 44 191 137 129 2 203 157 140 99 59 30 54 189 42 276 14 160 202 124 3 107 227 134 45 180 106 238 165 223 17 86 91 219 231 144 172 1 236 272 184 201 264 237 132 237 176 254 195 210 71 72 134 152 12 87 282 2 225 241 6 77 284 97 229 229 49 168 149 193 30 32 105 25 11 76 93 27 84 283 215 92 101 217 272 4 33 94 281 120 88 113 174 181 275 88 6 55 200 231 251 4 118 280 109 186 138 184 223 61 103 110 175 107 6 235 81 114 207 167 116 56 189 200 73 167 138 140 55 178 11 98 26 180 62 221 146 267 141 88 28 139 66 209 189 222 6 33 116 78 273 66 51 105 69 28 95 49 190 233 59 8 257 36 64 51 83 272 162 117 111 259 58 19 1 214 188 31 223 39 170 244 197 169 75 60 41 243 164 32 234 92 145 98 155 96 196 243 208 200 253 48 21 96 218 40 74 178 191 115 196 136 225 219 209 60 19 23 11 54 9 161 106 58 284 204 61 210 93 5 151 130 237 154 34 42 232 133 141 246 112 5 44 147 256 110 46 40 159 213 19 181 95 207 274 99 37 233 37 211 104 58 126 120 195 232 155 225 112 90 230 262 35 9 117 89 39 41 41 63 147 13 278 216 283 35 75 82 261 109 142 257 14 267 185 105 47 95 229 71 252 15 171 255 99 144 65 18 255 228 60 199 40 30 10 172 159 33 138 162 139 44 125 36 244 68 102 228 38 115 174 52 72 241 271 280 131 119 4 162 161 128 142 14 182 286 141 268 45 158 22 85 187 285 86 198 51 61 188 9 139 173 192 19 266 130 35 53 285 108 131 204 39 126 227 27 213 199 62 114 163 150 97 100 26 202 146 87 124 205 72 263 68 146 109 57 71 50 201 135 34 149 215 114 185 83 250 78 251 133 34 127 131 248 207 9 183 190 211 262 142 279 98 133 163 43 265 270 269 78 8 150 204 83 7 246 270 89 197 125 194 41 85 80 166 256 154 214 210 115 89 17 108 175 85 209 82 103 176 276 279 76 49 10 65 40 52 94 38 137 258 69 50 179 202 168 171 277 183 10 43 243 186 116 100 70 83 29 43 67 135 56 82 81 92 123 14 2 118 258 25 33 160 246 5 22 63 103 132 108 260 120 173 148 2 247 38 159 55 222 28 117 269 56 211 284 226 145 76 71 230 218 18 277 25 213 177 265 248 185 212 30 212 273 195 254 239 91 90 28 10 150 75 167 160 224 175 ^'}}, + {OUT=>'66E0D01780F1063E2929EAAD74826BC64060E38C'}], + ['210', {IN=> {f=> '613 0 152 79 161 65 216 220 109 281 9 254 130 126 57 137 147 82 63 133 78 162 232 68 59 232 177 22 129 68 168 36 74 43 275 264 174 70 154 103 247 218 194 158 42 167 49 259 18 261 222 95 59 52 270 49 20 214 75 42 238 282 46 106 258 249 83 280 22 20 105 271 15 58 136 269 100 224 10 182 19 68 130 17 94 240 256 225 156 127 44 82 172 96 105 53 89 134 65 107 257 212 101 152 188 124 92 107 77 175 287 43 45 190 98 141 157 235 259 127 224 119 275 205 248 276 83 100 115 206 285 128 211 64 11 60 1 66 253 202 237 245 194 108 5 64 229 116 84 267 256 45 249 24 224 228 238 102 139 3 149 106 149 286 56 100 165 243 99 237 65 157 5 26 210 6 122 118 217 27 17 203 44 153 116 13 193 50 116 122 286 236 7 268 63 242 171 59 123 214 125 238 52 102 30 40 252 215 3 220 50 66 215 183 127 153 45 69 117 121 119 95 9 145 167 229 166 121 81 76 188 53 18 190 148 178 260 55 113 61 218 85 195 145 276 192 63 12 97 142 194 217 98 250 120 132 150 273 1 125 20 285 19 118 37 120 203 94 60 219 122 47 273 110 88 206 176 165 25 43 154 283 284 32 14 12 265 161 15 179 117 138 75 260 164 76 247 109 101 261 151 21 272 253 143 181 32 123 105 162 52 31 245 123 34 218 135 232 248 96 46 286 6 63 62 134 245 14 71 32 244 86 182 90 12 47 105 91 108 244 27 126 7 230 44 262 79 199 84 196 23 128 31 27 197 240 17 262 259 236 187 16 166 62 25 282 117 180 175 178 80 18 10 241 75 151 201 179 67 252 35 255 117 71 82 281 189 2 233 235 41 71 141 48 272 73 236 78 53 269 171 168 86 111 16 95 118 108 64 120 23 187 87 110 268 243 279 274 168 266 148 119 204 261 42 58 86 73 127 115 26 89 25 102 80 77 66 35 146 24 44 191 135 123 285 199 155 140 99 57 28 54 185 42 276 12 156 198 118 288 101 223 132 41 180 104 234 163 219 13 84 87 219 231 140 170 1 234 272 182 199 264 233 126 237 174 250 191 206 67 72 128 152 8 87 278 287 223 241 4 77 284 91 229 225 47 164 147 191 26 30 99 19 9 74 93 23 78 283 213 88 97 213 268 4 27 88 277 120 82 113 170 181 271 86 2 53 198 227 251 287 114 278 107 186 138 184 223 61 97 104 175 107 6 231 81 114 207 163 110 50 187 196 73 165 134 136 51 174 11 98 20 176 56 221 146 263 137 88 26 139 62 205 189 220 29 112 74 273 60 51 103 67 22 91 49 188 233 55 4 257 32 64 49 79 270 158 113 111 255 58 15 288 210 213 ^'}}, + {OUT=>'A8478DF406F179FD4EF97F4574D7F99EA1CE9EB8'}], + ['211', {IN=> {f=> '624 1 28 220 36 170 238 197 169 72 54 41 237 158 26 234 92 145 95 155 87 190 243 208 200 250 48 21 90 215 40 71 178 188 109 196 130 219 216 206 51 16 23 5 48 6 158 97 55 278 201 55 207 90 286 151 130 234 148 34 36 226 127 138 240 112 2 38 141 250 104 37 31 159 207 19 175 92 201 274 96 31 230 28 205 104 52 126 114 192 229 152 225 103 90 230 262 26 108 86 39 32 35 60 147 10 278 216 277 35 75 79 255 100 136 254 5 267 185 99 41 95 226 71 249 9 168 252 90 144 56 12 249 228 57 193 34 21 4 172 153 30 135 159 136 35 116 36 241 59 93 225 32 106 171 43 66 238 268 280 131 110 1 162 161 122 142 14 179 283 141 265 36 155 16 79 184 279 77 198 45 52 182 3 133 173 192 10 263 121 32 50 282 102 122 198 30 120 227 18 213 196 59 108 157 150 91 91 20 199 140 84 124 199 69 263 65 143 109 48 62 47 201 126 28 149 215 111 182 74 244 69 248 133 25 124 128 248 204 9 183 184 208 256 139 279 92 130 163 37 265 270 266 75 8 144 204 80 4 243 264 89 191 119 188 38 85 71 163 256 154 211 210 115 83 14 108 172 82 209 76 103 176 273 276 67 43 10 59 37 46 91 35 131 258 69 44 176 202 165 171 277 177 7 34 240 183 113 97 70 83 29 40 67 129 53 73 78 89 120 8 2 109 252 19 33 160 246 289 13 54 97 126 99 260 111 167 142 289 247 38 156 55 222 22 114 263 50 211 281 226 142 70 68 224 212 15 274 25 210 171 262 245 179 212 30 206 270 195 254 239 88 81 28 1 147 66 167 157 221 202 150 76 159 65 214 220 107 281 7 253 129 124 57 137 145 80 60 132 78 160 231 67 58 232 177 22 129 68 168 33 74 40 275 262 174 68 153 101 246 218 192 158 41 166 47 257 15 259 220 92 59 52 268 46 20 214 72 39 236 282 46 106 257 249 80 279 21 19 104 271 15 55 136 269 100 222 7 182 18 65 128 14 93 240 254 224 156 126 43 81 170 96 102 51 87 134 64 104 256 210 100 151 186 123 89 105 76 174 287 42 42 190 95 140 155 235 258 125 223 117 273 205 246 274 81 99 112 206 285 127 209 61 8 58 288 66 253 200 235 243 193 105 5 63 228 113 82 265 255 44 247 23 224 227 237 102 137 3 148 105 147 285 56 98 165 242 98 236 63 157 2 23 209 5 119 117 217 26 15 203 41 151 115 12 193 49 116 122 284 236 7 268 61 242 169 57 122 213 125 238 49 101 27 39 251 214 1 218 50 63 213 181 127 153 45 67 114 121 118 93 6 143 165 227 166 118 78 74 188 53 17 189 148 176 258 54 112 58 217 82 194 144 275 191 141 ^'}}, + {OUT=>'248E58CF09A372114FC2F93B09C5FC14F3D0059E'}], + ['212', {IN=> {f=> '628 1 3 97 139 194 211 92 250 117 132 147 267 290 119 14 282 13 118 37 111 200 94 60 216 119 47 270 110 85 203 173 159 16 43 148 277 278 29 5 12 262 158 6 176 117 286 135 72 257 164 76 241 106 101 261 148 18 266 247 143 178 32 117 99 159 49 31 245 123 31 212 135 226 245 90 43 286 289 60 62 131 242 11 65 23 244 80 176 84 6 38 105 91 102 238 27 123 290 224 38 259 79 199 84 193 14 128 25 21 191 237 17 256 259 233 187 10 160 59 19 276 114 174 169 175 74 18 7 235 69 145 198 179 58 252 32 255 111 62 82 278 183 285 230 229 32 68 135 39 269 67 230 75 44 263 168 165 86 108 16 92 112 105 58 114 20 181 78 107 265 237 276 268 162 266 142 119 201 258 36 52 77 64 118 109 26 80 22 96 80 71 60 29 143 24 44 191 132 114 279 193 152 140 99 54 25 54 179 42 276 9 150 192 109 285 92 217 129 35 180 101 228 160 213 7 81 81 219 231 134 167 1 231 272 179 196 264 227 117 237 171 244 185 200 61 72 119 152 2 87 272 284 220 241 1 77 284 82 229 219 44 158 144 188 20 27 90 10 6 71 93 17 69 283 210 82 91 207 262 4 18 79 271 120 73 113 164 181 265 83 288 50 195 221 251 281 108 275 104 186 138 184 223 61 88 95 175 107 6 225 81 114 207 157 101 41 184 190 73 162 128 130 45 168 11 98 11 170 47 221 146 257 131 88 23 139 56 199 189 217 283 23 106 68 273 51 51 100 64 13 85 49 185 233 49 290 257 26 64 46 73 267 152 107 111 249 58 9 288 204 183 26 218 34 170 234 197 169 70 50 41 233 154 22 234 92 145 93 155 81 186 243 208 200 248 48 21 86 213 40 69 178 186 105 196 126 215 214 204 45 14 23 1 44 4 156 91 53 274 199 51 205 88 282 151 130 232 144 34 32 222 123 136 236 112 34 137 246 100 31 25 159 203 19 171 90 197 274 94 27 228 22 201 104 48 126 110 190 227 150 225 97 90 230 262 20 286 102 84 39 26 31 58 147 8 278 216 273 35 75 77 251 94 132 252 291 267 185 95 37 95 224 71 247 5 166 250 84 144 50 8 245 228 55 189 30 15 172 149 28 133 157 134 29 110 36 239 53 87 223 28 100 169 37 62 236 266 280 131 104 291 162 161 118 142 14 177 281 141 263 30 153 12 75 182 275 71 198 41 46 178 291 129 173 192 4 261 115 30 48 280 98 116 194 24 116 227 12 213 194 57 104 153 150 87 85 16 197 136 82 124 195 67 263 63 141 109 42 56 45 201 120 24 149 215 109 180 68 240 63 246 133 19 122 126 248 202 9 183 180 206 252 137 279 88 128 163 33 265 270 264 73 8 140 204 78 2 241 76 ^'}}, + {OUT=>'F15767DE91796A6816977EFA4FCED4B7FD9B8A57'}], + ['213', {IN=> {f=> '622 0 89 183 111 180 34 85 59 159 256 154 207 210 115 75 10 108 168 78 209 68 103 176 269 272 55 35 10 51 33 38 87 31 123 258 69 36 172 202 161 171 277 169 3 22 236 179 109 93 70 83 29 36 67 121 49 61 74 85 116 2 97 244 11 33 160 246 285 1 42 89 118 87 260 99 159 134 289 247 38 152 55 222 14 110 255 42 211 277 226 138 62 64 216 204 11 270 25 206 163 258 241 171 212 30 198 266 195 254 239 84 69 28 283 143 54 167 153 217 194 142 64 151 65 206 220 99 281 293 249 125 116 57 137 137 72 48 128 78 152 227 63 54 232 177 22 129 68 168 21 74 28 275 254 174 60 149 93 242 218 184 158 37 162 39 249 3 251 212 80 59 52 260 34 20 214 60 27 228 282 46 106 253 249 68 275 17 15 100 271 15 43 136 269 100 214 289 182 14 53 120 2 89 240 246 220 156 122 39 77 162 96 90 43 79 134 60 92 252 202 96 147 178 119 77 97 72 170 287 38 30 190 83 136 147 235 254 117 219 109 265 205 238 266 73 95 100 206 285 123 201 49 290 50 280 66 253 192 227 235 189 93 5 59 224 101 74 257 251 40 239 19 224 223 233 102 129 3 144 101 139 281 56 90 165 238 94 232 55 157 284 11 205 1 107 113 217 22 7 203 29 143 111 8 193 45 116 122 276 236 7 268 53 242 161 49 118 209 125 238 37 97 15 35 247 210 287 210 50 51 205 173 127 153 45 59 102 121 114 85 288 135 157 219 166 106 66 66 188 53 13 185 148 168 250 50 108 46 213 70 190 140 271 187 63 291 97 137 194 207 88 250 115 132 145 263 290 115 10 280 9 118 37 105 198 94 60 214 117 47 268 110 83 201 171 155 10 43 144 273 274 27 293 12 260 156 174 117 284 133 70 255 164 76 237 104 101 261 146 16 262 243 143 176 32 113 95 157 47 31 245 123 29 208 135 222 243 86 41 286 285 58 62 129 240 9 61 17 244 76 172 80 2 32 105 91 98 234 27 121 286 220 34 257 79 199 84 191 8 128 21 17 187 235 17 252 259 231 187 6 156 57 15 272 112 170 165 173 70 18 5 231 65 141 196 179 52 252 30 255 107 56 82 276 179 281 228 225 26 66 131 33 267 63 226 73 38 259 166 163 86 106 16 90 108 103 54 110 18 177 72 105 263 233 274 264 158 266 138 119 199 256 32 48 71 58 112 105 26 74 20 92 80 67 56 25 141 24 44 191 130 108 275 189 150 140 99 52 23 54 175 42 276 7 146 188 103 283 86 213 127 31 180 99 224 158 209 3 79 77 219 231 130 165 1 229 272 177 194 264 223 111 237 169 240 181 196 57 72 113 152 292 87 268 282 218 241 293 77 284 76 229 80 ^'}}, + {OUT=>'36A6BC5E680E15675D9696338C88B36248BBBAF4'}], + ['214', {IN=> {f=> '635 1 40 150 140 184 12 23 78 294 2 67 93 9 57 283 206 74 83 199 254 4 6 67 263 120 61 113 156 181 257 79 284 46 191 213 251 273 100 271 100 186 138 184 223 61 76 83 175 107 6 217 81 114 207 149 89 29 180 182 73 158 120 122 37 160 11 98 295 162 35 221 146 249 123 88 19 139 48 191 189 213 275 15 98 60 273 39 51 96 60 1 77 49 181 233 41 286 257 18 64 42 65 263 144 99 111 241 58 1 288 196 179 22 214 30 170 226 197 169 66 42 41 225 146 14 234 92 145 89 155 69 178 243 208 200 244 48 21 78 209 40 65 178 182 97 196 118 207 210 200 33 10 23 289 36 152 79 49 266 195 43 201 84 274 151 130 228 136 34 24 214 115 132 228 112 292 26 129 238 92 19 13 159 195 19 163 86 189 274 90 19 224 10 193 104 40 126 102 186 223 146 225 85 90 230 262 8 278 90 80 39 14 23 54 147 4 278 216 265 35 75 73 243 82 124 248 283 267 185 87 29 95 220 71 243 293 162 246 72 144 38 237 228 51 181 22 3 288 172 141 24 129 153 130 17 98 36 235 41 75 219 20 88 165 25 54 232 262 280 131 92 291 162 161 110 142 14 173 277 141 259 18 149 4 67 178 267 59 198 33 34 170 287 121 173 192 288 257 103 26 44 276 90 104 186 12 108 227 213 190 53 96 145 150 79 73 8 193 128 78 124 187 63 263 59 137 109 30 44 41 201 108 16 149 215 105 176 56 232 51 242 133 7 118 122 248 198 9 183 172 202 244 133 279 80 124 163 25 265 270 260 69 8 132 204 74 294 237 252 89 179 107 176 32 85 53 157 256 154 205 210 115 71 8 108 166 76 209 64 103 176 267 270 49 31 10 47 31 34 85 29 119 258 69 32 170 202 159 171 277 165 1 16 234 177 107 91 70 83 29 34 67 117 47 55 72 83 114 292 2 91 240 7 33 160 246 283 291 36 85 114 81 260 93 155 130 289 247 38 150 55 222 10 108 251 38 211 275 226 136 58 62 212 200 9 268 25 204 159 256 239 167 212 30 194 264 195 254 239 82 63 28 279 141 48 167 151 215 190 138 58 147 65 202 220 95 281 291 247 123 112 57 137 133 68 42 126 78 148 225 61 52 232 177 22 129 68 168 15 74 22 275 250 174 56 147 89 240 218 180 158 35 160 35 245 293 247 208 74 59 52 256 28 20 214 54 21 224 282 46 106 251 249 62 273 15 13 98 271 15 37 136 269 100 210 285 182 12 47 116 292 87 240 242 218 156 120 37 75 158 96 84 39 75 134 58 86 250 198 94 145 174 117 71 93 70 168 287 36 24 190 77 134 143 235 252 113 217 105 261 205 234 262 69 93 94 206 285 121 197 43 286 46 276 66 253 188 223 231 187 87 5 57 222 95 285 ^'}}, + {OUT=>'4DEA6251B2A6DF017A8093AB066EE3863A4EC369'}], + ['215', {IN=> {f=> '636 0 251 248 37 233 16 224 220 230 102 123 3 141 98 133 278 56 84 165 235 91 229 49 157 278 2 202 295 98 110 217 19 1 203 20 137 108 5 193 42 116 122 270 236 7 268 47 242 155 43 115 206 125 238 28 94 6 32 244 207 284 204 50 42 199 167 127 153 45 53 93 121 111 79 282 129 151 213 166 97 57 60 188 53 10 182 148 162 244 47 105 37 210 61 187 137 268 184 63 285 97 134 194 201 82 250 112 132 142 257 290 109 4 277 3 118 37 96 195 94 60 211 114 47 265 110 80 198 168 149 1 43 138 267 268 24 287 12 257 153 288 171 117 281 130 67 252 164 76 231 101 101 261 143 13 256 237 143 173 32 107 89 154 44 31 245 123 26 202 135 216 240 80 38 286 279 55 62 126 237 6 55 8 244 70 166 74 293 23 105 91 92 228 27 118 280 214 28 254 79 199 84 188 296 128 15 11 181 232 17 246 259 228 187 150 54 9 266 109 164 159 170 64 18 2 225 59 135 193 179 43 252 27 255 101 47 82 273 173 275 225 219 17 63 125 24 264 57 220 70 29 253 163 160 86 103 16 87 102 100 48 104 15 171 63 102 260 227 271 258 152 266 132 119 196 253 26 42 62 49 103 99 26 65 17 86 80 61 50 19 138 24 44 191 127 99 269 183 147 140 99 49 20 54 169 42 276 4 140 182 94 280 77 207 124 25 180 96 218 155 203 294 76 71 219 231 124 162 1 226 272 174 191 264 217 102 237 166 234 175 190 51 72 104 152 289 87 262 279 215 241 293 77 284 67 229 209 39 148 139 183 10 22 75 292 1 66 93 7 54 283 205 72 81 197 252 4 3 64 261 120 58 113 154 181 255 78 283 45 190 211 251 271 98 270 99 186 138 184 223 61 73 80 175 107 6 215 81 114 207 147 86 26 179 180 73 157 118 120 35 158 11 98 293 160 32 221 146 247 121 88 18 139 46 189 189 212 273 13 96 58 273 36 51 95 59 295 75 49 180 233 39 285 257 16 64 41 63 262 142 97 111 239 58 296 288 194 178 21 213 29 170 224 197 169 65 40 41 223 144 12 234 92 145 88 155 66 176 243 208 200 243 48 21 76 208 40 64 178 181 95 196 116 205 209 199 30 9 23 288 34 296 151 76 48 264 194 41 200 83 272 151 130 227 134 34 22 212 113 131 226 112 292 24 127 236 90 16 10 159 193 19 161 85 187 274 89 17 223 7 191 104 38 126 100 185 222 145 225 82 90 230 262 5 276 87 79 39 11 21 53 147 3 278 216 263 35 75 72 241 79 122 247 281 267 185 85 27 95 219 71 242 292 161 245 69 144 35 295 235 228 50 179 20 287 172 139 23 128 152 129 14 95 36 234 38 72 218 18 85 164 22 52 231 261 280 131 89 291 162 161 108 142 14 172 276 91 ^'}}, + {OUT=>'D30E70E357D57E3D82CA554B8A3D58DFF528FA94'}], + ['216', {IN=> {f=> '635 1 256 9 146 297 61 175 261 50 198 27 25 164 284 115 173 192 282 254 94 23 41 273 84 95 180 3 102 227 290 213 187 50 90 139 150 73 64 2 190 122 75 124 181 60 263 56 134 109 21 35 38 201 99 10 149 215 102 173 47 226 42 239 133 297 115 119 248 195 9 183 166 199 238 130 279 74 121 163 19 265 270 257 66 8 126 204 71 294 234 246 89 173 101 170 29 85 44 154 256 154 202 210 115 65 5 108 163 73 209 58 103 176 264 267 40 25 10 41 28 28 82 26 113 258 69 26 167 202 156 171 277 159 297 7 231 174 104 88 70 83 29 31 67 111 44 46 69 80 111 289 2 82 234 1 33 160 246 280 285 27 79 108 72 260 84 149 124 289 247 38 147 55 222 4 105 245 32 211 272 226 133 52 59 206 194 6 265 25 201 153 253 236 161 212 30 188 261 195 254 239 79 54 28 273 138 39 167 148 212 184 132 49 141 65 196 220 89 281 288 244 120 106 57 137 127 62 33 123 78 142 222 58 49 232 177 22 129 68 168 6 74 13 275 244 174 50 144 83 237 218 174 158 32 157 29 239 287 241 202 65 59 52 250 19 20 214 45 12 218 282 46 106 248 249 53 270 12 10 95 271 15 28 136 269 100 204 279 182 9 38 110 286 84 240 236 215 156 117 34 72 152 96 75 33 69 134 55 77 247 192 91 142 168 114 62 87 67 165 287 33 15 190 68 131 137 235 249 107 214 99 255 205 228 256 63 90 85 206 285 118 191 34 280 40 270 66 253 182 217 225 184 78 5 54 219 86 64 247 246 35 229 14 224 218 228 102 119 3 139 96 129 276 56 80 165 233 89 227 45 157 274 295 200 295 92 108 217 17 296 203 14 133 106 3 193 40 116 122 266 236 7 268 43 242 151 39 113 204 125 238 22 92 30 242 205 282 200 50 36 195 163 127 153 45 49 87 121 109 75 278 125 147 209 166 91 51 56 188 53 8 180 148 158 240 45 103 31 208 55 185 135 266 182 63 281 97 132 194 197 78 250 110 132 140 253 290 105 275 298 118 37 90 193 94 60 209 112 47 263 110 78 196 166 145 294 43 134 263 264 22 283 12 255 151 284 169 117 279 128 65 250 164 76 227 99 101 261 141 11 252 233 143 171 32 103 85 152 42 31 245 123 24 198 135 212 238 76 36 286 275 53 62 124 235 4 51 2 244 66 162 70 291 17 105 91 88 224 27 116 276 210 24 252 79 199 84 186 292 128 11 7 177 230 17 242 259 226 187 295 146 52 5 262 107 160 155 168 60 18 221 55 131 191 179 37 252 25 255 97 41 82 271 169 271 223 215 11 61 121 18 262 53 216 68 23 249 161 158 86 101 16 85 98 98 44 100 13 167 57 100 258 223 269 254 148 266 128 119 194 251 22 38 56 43 275 ^'}}, + {OUT=>'70CA84D827F7FD61446233F88CF2F990B0F3E2AA'}], + ['217', {IN=> {f=> '642 0 91 26 53 13 78 80 53 42 11 134 24 44 191 123 87 261 175 143 140 99 45 16 54 161 42 276 132 174 82 276 65 199 120 17 180 92 210 151 195 290 72 63 219 231 116 158 1 222 272 170 187 264 209 90 237 162 226 167 182 43 72 92 152 285 87 254 275 211 241 293 77 284 55 229 201 35 140 135 179 2 18 63 284 298 62 93 300 42 283 201 64 73 189 244 4 292 52 253 120 46 113 146 181 247 74 279 41 186 203 251 263 90 266 95 186 138 184 223 61 61 68 175 107 6 207 81 114 207 139 74 14 175 172 73 153 110 112 27 150 11 98 285 152 20 221 146 239 113 88 14 139 38 181 189 208 265 5 88 50 273 24 51 91 55 287 67 49 176 233 31 281 257 8 64 37 55 258 134 89 111 231 58 292 288 186 174 17 209 25 170 216 197 169 61 32 41 215 136 4 234 92 145 84 155 54 168 243 208 200 239 48 21 68 204 40 60 178 177 87 196 108 197 205 195 18 5 23 284 26 296 147 64 44 256 190 33 196 79 264 151 130 223 126 34 14 204 105 127 218 112 292 16 119 228 82 4 299 159 185 19 153 81 179 274 85 9 219 296 183 104 30 126 92 181 218 141 225 70 90 230 262 294 268 75 75 39 300 13 49 147 300 278 216 255 35 75 68 233 67 114 243 273 267 185 77 19 95 215 71 238 288 157 241 57 144 23 291 227 228 46 171 12 289 283 172 131 19 124 148 125 2 83 36 230 26 60 214 10 73 160 10 44 227 257 280 131 77 291 162 161 100 142 14 168 272 141 254 3 144 295 57 173 257 44 198 23 19 160 282 111 173 192 278 252 88 21 39 271 80 89 176 298 98 227 286 213 185 48 86 135 150 69 58 299 188 118 73 124 177 58 263 54 132 109 15 29 36 201 93 6 149 215 100 171 41 222 36 237 133 293 113 117 248 193 9 183 162 197 234 128 279 70 119 163 15 265 270 255 64 8 122 204 69 294 232 242 89 169 97 166 27 85 38 152 256 154 200 210 115 61 3 108 161 71 209 54 103 176 262 265 34 21 10 37 26 24 80 24 109 258 69 22 165 202 154 171 277 155 297 1 229 172 102 86 70 83 29 29 67 107 42 40 67 78 109 287 2 76 230 298 33 160 246 278 281 21 75 104 66 260 78 145 120 289 247 38 145 55 222 103 241 28 211 270 226 131 48 57 202 190 4 263 25 199 149 251 234 157 212 30 184 259 195 254 239 77 48 28 269 136 33 167 146 210 180 128 43 137 65 192 220 85 281 286 242 118 102 57 137 123 58 27 121 78 138 220 56 47 232 177 22 129 68 168 74 7 275 240 174 46 142 79 235 218 170 158 30 155 25 235 283 237 198 59 59 52 246 13 20 214 39 6 214 282 46 106 246 249 47 268 10 8 93 271 15 22 136 269 100 200 275 42 ^'}}, + {OUT=>'8D500C9CFDE0288530A2106B70BED39326C52C3C'}], + ['218', {IN=> {f=> '644 0 6 29 104 280 81 240 230 212 156 114 31 69 146 96 66 27 63 134 52 68 244 186 88 139 162 111 53 81 64 162 287 30 6 190 59 128 131 235 246 101 211 93 249 205 222 250 57 87 76 206 285 115 185 25 274 34 264 66 253 176 211 219 181 69 5 51 216 77 58 241 243 32 223 11 224 215 225 102 113 3 136 93 123 273 56 74 165 230 86 224 39 157 268 289 197 295 83 105 217 14 293 203 5 127 103 193 37 116 122 260 236 7 268 37 242 145 33 110 201 125 238 13 89 293 27 239 202 279 194 50 27 189 157 127 153 45 43 78 121 106 69 272 119 141 203 166 82 42 50 188 53 5 177 148 152 234 42 100 22 205 46 182 132 263 179 63 275 97 129 194 191 72 250 107 132 137 247 290 99 296 272 295 118 37 81 190 94 60 206 109 47 260 110 75 193 163 139 288 43 128 257 258 19 277 12 252 148 278 166 117 276 125 62 247 164 76 221 96 101 261 138 8 246 227 143 168 32 97 79 149 39 31 245 123 21 192 135 206 235 70 33 286 269 50 62 121 232 1 45 295 244 60 156 64 288 8 105 91 82 218 27 113 270 204 18 249 79 199 84 183 286 128 5 1 171 227 17 236 259 223 187 292 140 49 301 256 104 154 149 165 54 18 299 215 49 125 188 179 28 252 22 255 91 32 82 268 163 265 220 209 2 58 115 9 259 47 210 65 14 243 158 155 86 98 16 82 92 95 38 94 10 161 48 97 255 217 266 248 142 266 122 119 191 248 16 32 47 34 88 89 26 50 12 76 80 51 40 9 133 24 44 191 122 84 259 173 142 140 99 44 15 54 159 42 276 301 130 172 79 275 62 197 119 15 180 91 208 150 193 289 71 61 219 231 114 157 1 221 272 169 186 264 207 87 237 161 224 165 180 41 72 89 152 284 87 252 274 210 241 293 77 284 52 229 199 34 138 134 178 17 60 282 298 61 93 299 39 283 200 62 71 187 242 4 290 49 251 120 43 113 144 181 245 73 278 40 185 201 251 261 88 265 94 186 138 184 223 61 58 65 175 107 6 205 81 114 207 137 71 11 174 170 73 152 108 110 25 148 11 98 283 150 17 221 146 237 111 88 13 139 36 179 189 207 263 3 86 48 273 21 51 90 54 285 65 49 175 233 29 280 257 6 64 36 53 257 132 87 111 229 58 291 288 184 173 16 208 24 170 214 197 169 60 30 41 213 134 2 234 92 145 83 155 51 166 243 208 200 238 48 21 66 203 40 59 178 176 85 196 106 195 204 194 15 4 23 283 24 296 146 61 43 254 189 31 195 78 262 151 130 222 124 34 12 202 103 126 216 112 292 14 117 226 80 1 297 159 183 19 151 80 177 274 84 7 218 294 181 104 28 126 90 180 217 140 225 67 90 230 262 292 266 72 74 39 298 11 48 147 300 278 216 253 265 ^'}}, + {OUT=>'F3D4D139EDFC24596377BC97A96FB7621F27FFC7'}], + ['219', {IN=> {f=> '638 1 75 65 227 58 108 240 267 267 185 71 13 95 212 71 235 285 154 238 48 144 14 288 221 228 43 165 6 283 280 172 125 16 121 145 122 297 74 36 227 17 51 211 4 64 157 1 38 224 254 280 131 68 291 162 161 94 142 14 165 269 141 251 298 141 292 51 170 251 35 198 17 10 154 279 105 173 192 272 249 79 18 36 268 74 80 170 292 92 227 280 213 182 45 80 129 150 63 49 296 185 112 70 124 171 55 263 51 129 109 6 20 33 201 84 149 215 97 168 32 216 27 234 133 287 110 114 248 190 9 183 156 194 228 125 279 64 116 163 9 265 270 252 61 8 116 204 66 294 229 236 89 163 91 160 24 85 29 149 256 154 197 210 115 55 108 158 68 209 48 103 176 259 262 25 15 10 31 23 18 77 21 103 258 69 16 162 202 151 171 277 149 297 296 226 169 99 83 70 83 29 26 67 101 39 31 64 75 106 284 2 67 224 295 33 160 246 275 275 12 69 98 57 260 69 139 114 289 247 38 142 55 222 298 100 235 22 211 267 226 128 42 54 196 184 1 260 25 196 143 248 231 151 212 30 178 256 195 254 239 74 39 28 263 133 24 167 143 207 174 122 34 131 65 186 220 79 281 283 239 115 96 57 137 117 52 18 118 78 132 217 53 44 232 177 22 129 68 168 295 74 302 275 234 174 40 139 73 232 218 164 158 27 152 19 229 277 231 192 50 59 52 240 4 20 214 30 301 208 282 46 106 243 249 38 265 7 5 90 271 15 13 136 269 100 194 269 182 4 23 100 276 79 240 226 210 156 112 29 67 142 96 60 23 59 134 50 62 242 182 86 137 158 109 47 77 62 160 287 28 190 53 126 127 235 244 97 209 89 245 205 218 246 53 85 70 206 285 113 181 19 270 30 260 66 253 172 207 215 179 63 5 49 214 71 54 237 241 30 219 9 224 213 223 102 109 3 134 91 119 271 56 70 165 228 84 222 35 157 264 285 195 295 77 103 217 12 291 203 303 123 101 302 193 35 116 122 256 236 7 268 33 242 141 29 108 199 125 238 7 87 289 25 237 200 277 190 50 21 185 153 127 153 45 39 72 121 104 65 268 115 137 199 166 76 36 46 188 53 3 175 148 148 230 40 98 16 203 40 180 130 261 177 63 271 97 127 194 187 68 250 105 132 135 243 290 95 294 270 293 118 37 75 188 94 60 204 107 47 258 110 73 191 161 135 284 43 124 253 254 17 273 12 250 146 274 164 117 274 123 60 245 164 76 217 94 101 261 136 6 242 223 143 166 32 93 75 147 37 31 245 123 19 188 135 202 233 66 31 286 265 48 62 119 230 303 41 291 244 56 152 60 286 2 105 91 78 214 27 111 266 200 14 247 79 199 84 181 282 128 1 301 167 225 17 232 259 221 187 290 136 47 299 252 102 150 145 163 157 ^'}}, + {OUT=>'5509BAFFAC6D507860CEFC5AB5832CB63CD4B687'}], + ['220', {IN=> {f=> '653 0 18 299 207 41 117 184 179 16 252 18 255 83 20 82 264 155 257 216 201 296 54 107 303 255 39 202 61 2 235 154 151 86 94 16 78 84 91 30 86 6 153 36 93 251 209 262 240 134 266 114 119 187 244 8 24 35 22 76 81 26 38 8 68 80 43 32 1 129 24 44 191 118 72 251 165 138 140 99 40 11 54 151 42 276 301 122 164 67 271 50 189 115 7 180 87 200 146 185 285 67 53 219 231 106 153 1 217 272 165 182 264 199 75 237 157 216 157 172 33 72 77 152 280 87 244 270 206 241 293 77 284 40 229 191 30 130 130 174 298 13 48 274 298 57 93 295 27 283 196 54 63 179 234 4 282 37 243 120 31 113 136 181 237 69 274 36 181 193 251 253 80 261 90 186 138 184 223 61 46 53 175 107 6 197 81 114 207 129 59 305 170 162 73 148 100 102 17 140 11 98 275 142 5 221 146 229 103 88 9 139 28 171 189 203 255 301 78 40 273 9 51 86 50 277 57 49 171 233 21 276 257 304 64 32 45 253 124 79 111 221 58 287 288 176 169 12 204 20 170 206 197 169 56 22 41 205 126 300 234 92 145 79 155 39 158 243 208 200 234 48 21 58 199 40 55 178 172 77 196 98 187 200 190 3 23 279 16 296 142 49 39 246 185 23 191 74 254 151 130 218 116 34 4 194 95 122 208 112 292 6 109 218 72 295 289 159 175 19 143 76 169 274 80 305 214 286 173 104 20 126 82 176 213 136 225 55 90 230 262 284 258 60 70 39 290 3 44 147 300 278 216 245 35 75 63 223 52 104 238 263 267 185 67 9 95 210 71 233 283 152 236 42 144 8 286 217 228 41 161 2 279 278 172 121 14 119 143 120 293 68 36 225 11 45 209 58 155 301 34 222 252 280 131 62 291 162 161 90 142 14 163 267 141 249 294 139 290 47 168 247 29 198 13 4 150 277 101 173 192 268 247 73 16 34 266 70 74 166 288 88 227 276 213 180 43 76 125 150 59 43 294 183 108 68 124 167 53 263 49 127 109 14 31 201 78 302 149 215 95 166 26 212 21 232 133 283 108 112 248 188 9 183 152 192 224 123 279 60 114 163 5 265 270 250 59 8 112 204 64 294 227 232 89 159 87 156 22 85 23 147 256 154 195 210 115 51 304 108 156 66 209 44 103 176 257 260 19 11 10 27 21 14 75 19 99 258 69 12 160 202 149 171 277 145 297 292 224 167 97 81 70 83 29 24 67 97 37 25 62 73 104 282 2 61 220 293 33 160 246 273 271 6 65 94 51 260 63 135 110 289 247 38 140 55 222 296 98 231 18 211 265 226 126 38 52 192 180 305 258 25 194 139 246 229 147 212 30 174 254 195 254 239 72 33 28 259 131 18 167 141 205 170 118 28 127 65 182 220 75 281 281 237 113 92 57 137 113 48 12 116 78 128 215 51 42 232 177 22 129 68 168 291 161 ^'}}, + {OUT=>'0C0AEA0C2FD7A620C77866B1A177481E26B4F592'}], + ['221', {IN=> {f=> '653 0 296 275 228 174 34 136 67 229 218 158 158 24 149 13 223 271 225 186 41 59 52 234 302 20 214 21 295 202 282 46 106 240 249 29 262 4 2 87 271 15 4 136 269 100 188 263 182 1 14 94 270 76 240 220 207 156 109 26 64 136 96 51 17 53 134 47 53 239 176 83 134 152 106 38 71 59 157 287 25 298 190 44 123 121 235 241 91 206 83 239 205 212 240 47 82 61 206 285 110 175 10 264 24 254 66 253 166 201 209 176 54 5 46 211 62 48 231 238 27 213 6 224 210 220 102 103 3 131 88 113 268 56 64 165 225 81 219 29 157 258 279 192 295 68 100 217 9 288 203 297 117 98 302 193 32 116 122 250 236 7 268 27 242 135 23 105 196 125 238 305 84 283 22 234 197 274 184 50 12 179 147 127 153 45 33 63 121 101 59 262 109 131 193 166 67 27 40 188 53 172 148 142 224 37 95 7 200 31 177 127 258 174 63 265 97 124 194 181 62 250 102 132 132 237 290 89 291 267 290 118 37 66 185 94 60 201 104 47 255 110 70 188 158 129 278 43 118 247 248 14 267 12 247 143 268 161 117 271 120 57 242 164 76 211 91 101 261 133 3 236 217 143 163 32 87 69 144 34 31 245 123 16 182 135 196 230 60 28 286 259 45 62 116 227 303 35 285 244 50 146 54 283 300 105 91 72 208 27 108 260 194 8 244 79 199 84 178 276 128 302 298 161 222 17 226 259 218 187 287 130 44 296 246 99 144 139 160 44 18 299 205 39 115 183 179 13 252 17 255 81 17 82 263 153 255 215 199 294 53 105 301 254 37 200 60 306 233 153 150 86 93 16 77 82 90 28 84 5 151 33 92 250 207 261 238 132 266 112 119 186 243 6 22 32 19 73 79 26 35 7 66 80 41 30 306 128 24 44 191 117 69 249 163 137 140 99 39 10 54 149 42 276 301 120 162 64 270 47 187 114 5 180 86 198 145 183 284 66 51 219 231 104 152 1 216 272 164 181 264 197 72 237 156 214 155 170 31 72 74 152 279 87 242 269 205 241 293 77 284 37 229 189 29 128 129 173 297 12 45 272 298 56 93 294 24 283 195 52 61 177 232 4 280 34 241 120 28 113 134 181 235 68 273 35 180 191 251 251 78 260 89 186 138 184 223 61 43 50 175 107 6 195 81 114 207 127 56 303 169 160 73 147 98 100 15 138 11 98 273 140 2 221 146 227 101 88 8 139 26 169 189 202 253 300 76 38 273 6 51 85 49 275 55 49 170 233 19 275 257 303 64 31 43 252 122 77 111 219 58 286 288 174 168 11 203 19 170 204 197 169 55 20 41 203 124 299 234 92 145 78 155 36 156 243 208 200 233 48 21 56 198 40 54 178 171 75 196 96 185 199 189 306 23 278 14 296 141 46 38 244 184 21 190 73 252 151 130 217 114 34 2 192 93 121 206 112 292 4 107 216 70 293 112 ^'}}, + {OUT=>'149176007FEE58A591E3F00F8DB658B605F8390C'}], + ['222', {IN=> {f=> '646 1 159 169 19 137 73 163 274 77 302 211 280 167 104 14 126 76 173 210 133 225 46 90 230 262 278 252 51 67 39 284 306 41 147 300 278 216 239 35 75 60 217 43 98 235 257 267 185 61 3 95 207 71 230 280 149 233 33 144 308 283 211 228 38 155 305 273 275 172 115 11 116 140 117 287 59 36 222 2 36 206 303 49 152 295 28 219 249 280 131 53 291 162 161 84 142 14 160 264 141 246 288 136 287 41 165 241 20 198 7 304 144 274 95 173 192 262 244 64 13 31 263 64 65 160 282 82 227 270 213 177 40 70 119 150 53 34 291 180 102 65 124 161 50 263 46 124 109 300 5 28 201 69 299 149 215 92 163 17 206 12 229 133 277 105 109 248 185 9 183 146 189 218 120 279 54 111 163 308 265 270 247 56 8 106 204 61 294 224 226 89 153 81 150 19 85 14 144 256 154 192 210 115 45 304 108 153 63 209 38 103 176 254 257 10 5 10 21 18 8 72 16 93 258 69 6 157 202 146 171 277 139 297 286 221 164 94 78 70 83 29 21 67 91 34 16 59 70 101 279 2 52 214 290 33 160 246 270 265 306 59 88 42 260 54 129 104 289 247 38 137 55 222 293 95 225 12 211 262 226 123 32 49 186 174 305 255 25 191 133 243 226 141 212 30 168 251 195 254 239 69 24 28 253 128 9 167 138 202 164 112 19 121 65 176 220 69 281 278 234 110 86 57 137 107 42 3 113 78 122 212 48 39 232 177 22 129 68 168 285 74 292 275 224 174 30 134 63 227 218 154 158 22 147 9 219 267 221 182 35 59 52 230 298 20 214 15 291 198 282 46 106 238 249 23 260 2 85 271 15 307 136 269 100 184 259 182 308 8 90 266 74 240 216 205 156 107 24 62 132 96 45 13 49 134 45 47 237 172 81 132 148 104 32 67 57 155 287 23 294 190 38 121 117 235 239 87 204 79 235 205 208 236 43 80 55 206 285 108 171 4 260 20 250 66 253 162 197 205 174 48 5 44 209 56 44 227 236 25 209 4 224 208 218 102 99 3 129 86 109 266 56 60 165 223 79 217 25 157 254 275 190 295 62 98 217 7 286 203 293 113 96 302 193 30 116 122 246 236 7 268 23 242 131 19 103 194 125 238 301 82 279 20 232 195 272 180 50 6 175 143 127 153 45 29 57 121 99 55 258 105 127 189 166 61 21 36 188 53 307 170 148 138 220 35 93 1 198 25 175 125 256 172 63 261 97 122 194 177 58 250 100 132 130 233 290 85 289 265 288 118 37 60 183 94 60 199 102 47 253 110 68 186 156 125 274 43 114 243 244 12 263 12 245 141 264 159 117 269 118 55 240 164 76 207 89 101 261 131 1 232 213 143 161 32 83 65 142 32 31 245 123 14 178 135 192 228 56 26 286 255 43 62 114 225 303 31 281 244 46 142 50 281 296 105 91 238 ^'}}, + {OUT=>'17C0D7B0256159F3626786FFDB20237AE154FA84'}], + ['223', {IN=> {f=> '647 0 200 27 104 252 186 240 79 199 84 174 268 128 298 294 153 218 17 218 259 214 187 283 122 40 292 238 95 136 131 156 36 18 299 197 31 107 179 179 1 252 13 255 73 5 82 259 145 247 211 191 286 49 97 293 250 29 192 56 298 225 149 146 86 89 16 73 74 86 20 76 1 143 21 88 246 199 257 230 124 266 104 119 182 239 309 14 20 7 61 71 26 23 3 58 80 33 22 302 124 24 44 191 113 57 241 155 133 140 99 35 6 54 141 42 276 301 112 154 52 266 35 179 110 308 180 82 190 141 175 280 62 43 219 231 96 148 1 212 272 160 177 264 189 60 237 152 206 147 162 23 72 62 152 275 87 234 265 201 241 293 77 284 25 229 181 25 120 125 169 293 8 33 264 298 52 93 290 12 283 191 44 53 169 224 4 272 22 233 120 16 113 126 181 227 64 269 31 176 183 251 243 70 256 85 186 138 184 223 61 31 38 175 107 6 187 81 114 207 119 44 295 165 152 73 143 90 92 7 130 11 98 265 132 301 221 146 219 93 88 4 139 18 161 189 198 245 296 68 30 273 305 51 81 45 267 47 49 166 233 11 271 257 299 64 27 35 248 114 69 111 211 58 282 288 166 164 7 199 15 170 196 197 169 51 12 41 195 116 295 234 92 145 74 155 24 148 243 208 200 229 48 21 48 194 40 50 178 167 67 196 88 177 195 185 299 306 23 274 6 296 137 34 34 236 180 13 186 69 244 151 130 213 106 34 305 184 85 117 198 112 292 307 99 208 62 285 279 159 165 19 133 71 159 274 75 300 209 276 163 104 10 126 72 171 208 131 225 40 90 230 262 274 248 45 65 39 280 304 39 147 300 278 216 235 35 75 58 213 37 94 233 253 267 185 57 310 95 205 71 228 278 147 231 27 144 304 281 207 228 36 151 303 269 273 172 111 9 114 138 115 283 53 36 220 307 30 204 301 43 150 291 24 217 247 280 131 47 291 162 161 80 142 14 158 262 141 244 284 134 285 37 163 237 14 198 3 300 140 272 91 173 192 258 242 58 11 29 261 60 59 156 278 78 227 266 213 175 38 66 115 150 49 28 289 178 98 63 124 157 48 263 44 122 109 296 310 26 201 63 297 149 215 90 161 11 202 6 227 133 273 103 107 248 183 9 183 142 187 214 118 279 50 109 163 306 265 270 245 54 8 102 204 59 294 222 222 89 149 77 146 17 85 8 142 256 154 190 210 115 41 304 108 151 61 209 34 103 176 252 255 4 1 10 17 16 4 70 14 89 258 69 2 155 202 144 171 277 135 297 282 219 162 92 76 70 83 29 19 67 87 32 10 57 68 99 277 2 46 210 288 33 160 246 268 261 302 55 84 36 260 48 125 100 289 247 38 135 55 222 291 93 221 8 211 260 226 121 28 47 182 170 305 253 25 189 129 241 224 137 212 30 164 249 195 254 239 86 ^'}}, + {OUT=>'741A58618ABEB1D983D67AFDCBC49AA397A3B8E0'}], + ['224', {IN=> {f=> '665 0 15 28 247 125 167 135 199 158 106 10 115 65 170 220 63 281 275 231 107 80 57 137 101 36 306 110 78 116 209 45 36 232 177 22 129 68 168 279 74 286 275 218 174 24 131 57 224 218 148 158 19 144 3 213 261 215 176 26 59 52 224 292 20 214 6 285 192 282 46 106 235 249 14 257 311 309 82 271 15 301 136 269 100 178 253 182 308 311 84 260 71 240 210 202 156 104 21 59 126 96 36 7 43 134 42 38 234 166 78 129 142 101 23 61 54 152 287 20 288 190 29 118 111 235 236 81 201 73 229 205 202 230 37 77 46 206 285 105 165 307 254 14 244 66 253 156 191 199 171 39 5 41 206 47 38 221 233 22 203 1 224 205 215 102 93 3 126 83 103 263 56 54 165 220 76 214 19 157 248 269 187 295 53 95 217 4 283 203 287 107 93 302 193 27 116 122 240 236 7 268 17 242 125 13 100 191 125 238 295 79 273 17 229 192 269 174 50 309 169 137 127 153 45 23 48 121 96 49 252 99 121 183 166 52 12 30 188 53 307 167 148 132 214 32 90 304 195 16 172 122 253 169 63 255 97 119 194 171 52 250 97 132 127 227 290 79 286 262 285 118 37 51 180 94 60 196 99 47 250 110 65 183 153 119 268 43 108 237 238 9 257 12 242 138 258 156 117 266 115 52 237 164 76 201 86 101 261 128 310 226 207 143 158 32 77 59 139 29 31 245 123 11 172 135 186 225 50 23 286 249 40 62 111 222 303 25 275 244 40 136 44 278 290 105 91 62 198 27 103 250 184 310 239 79 199 84 173 266 128 297 293 151 217 17 216 259 213 187 282 120 39 291 236 94 134 129 155 34 18 299 195 29 105 178 179 310 252 12 255 71 2 82 258 143 245 210 189 284 48 95 291 249 27 190 55 296 223 148 145 86 88 16 72 72 85 18 74 141 18 87 245 197 256 228 122 266 102 119 181 238 308 12 17 4 58 69 26 20 2 56 80 31 20 301 123 24 44 191 112 54 239 153 132 140 99 34 5 54 139 42 276 301 110 152 49 265 32 177 109 307 180 81 188 140 173 279 61 41 219 231 94 147 1 211 272 159 176 264 187 57 237 151 204 145 160 21 72 59 152 274 87 232 264 200 241 293 77 284 22 229 179 24 118 124 168 292 7 30 262 298 51 93 289 9 283 190 42 51 167 222 4 270 19 231 120 13 113 124 181 225 63 268 30 175 181 251 241 68 255 84 186 138 184 223 61 28 35 175 107 6 185 81 114 207 117 41 293 164 150 73 142 88 90 5 128 11 98 263 130 299 221 146 217 91 88 3 139 16 159 189 197 243 295 66 28 273 303 51 80 44 265 45 49 165 233 9 270 257 298 64 26 33 247 112 67 111 209 58 281 288 164 163 6 198 14 170 194 197 169 50 10 41 193 114 294 234 92 145 73 155 21 146 243 208 200 228 48 21 46 193 40 49 178 166 65 196 86 175 194 184 297 306 23 273 206 ^'}}, + {OUT=>'B738D6B3409EB9ED2F1719B84D13F7C36169CDEC'}], + ['225', {IN=> {f=> '641 0 296 134 25 31 230 177 7 183 66 238 151 130 210 100 34 302 178 79 114 192 112 292 304 93 202 56 279 273 159 159 19 127 68 153 274 72 297 206 270 157 104 4 126 66 168 205 128 225 31 90 230 262 268 242 36 62 39 274 301 36 147 300 278 216 229 35 75 55 207 28 88 230 247 267 185 51 307 95 202 71 225 275 144 228 18 144 298 278 201 228 33 145 300 263 270 172 105 6 111 135 112 277 44 36 217 301 21 201 298 34 147 285 18 214 244 280 131 38 291 162 161 74 142 14 155 259 141 241 278 131 282 31 160 231 5 198 311 294 134 269 85 173 192 252 239 49 8 26 258 54 50 150 272 72 227 260 213 172 35 60 109 150 43 19 286 175 92 60 124 151 45 263 41 119 109 290 304 23 201 54 294 149 215 87 158 2 196 311 224 133 267 100 104 248 180 9 183 136 184 208 115 279 44 106 163 303 265 270 242 51 8 96 204 56 294 219 216 89 143 71 140 14 85 313 139 256 154 187 210 115 35 304 108 148 58 209 28 103 176 249 252 309 309 10 11 13 312 67 11 83 258 69 310 152 202 141 171 277 129 297 276 216 159 89 73 70 83 29 16 67 81 29 1 54 65 96 274 2 37 204 285 33 160 246 265 255 296 49 78 27 260 39 119 94 289 247 38 132 55 222 288 90 215 2 211 257 226 118 22 44 176 164 305 250 25 186 123 238 221 131 212 30 158 246 195 254 239 64 9 28 243 123 308 167 133 197 154 102 4 111 65 166 220 59 281 273 229 105 76 57 137 97 32 302 108 78 112 207 43 34 232 177 22 129 68 168 275 74 282 275 214 174 20 129 53 222 218 144 158 17 142 313 209 257 211 172 20 59 52 220 288 20 214 281 188 282 46 106 233 249 8 255 311 309 80 271 15 297 136 269 100 174 249 182 308 307 80 256 69 240 206 200 156 102 19 57 122 96 30 3 39 134 40 32 232 162 76 127 138 99 17 57 52 150 287 18 284 190 23 116 107 235 234 77 199 69 225 205 198 226 33 75 40 206 285 103 161 303 250 10 240 66 253 152 187 195 169 33 5 39 204 41 34 217 231 20 199 313 224 203 213 102 89 3 124 81 99 261 56 50 165 218 74 212 15 157 244 265 185 295 47 93 217 2 281 203 283 103 91 302 193 25 116 122 236 236 7 268 13 242 121 9 98 189 125 238 291 77 269 15 227 190 267 170 50 305 165 133 127 153 45 19 42 121 94 45 248 95 117 179 166 46 6 26 188 53 307 165 148 128 210 30 88 300 193 10 170 120 251 167 63 251 97 117 194 167 48 250 95 132 125 223 290 75 284 260 283 118 37 45 178 94 60 194 97 47 248 110 63 181 151 115 264 43 104 233 234 7 253 12 240 136 254 154 117 264 113 50 235 164 76 197 84 101 261 126 310 222 203 143 276 ^'}}, + {OUT=>'3D33DE31F64055D3B128AC9A6AA3F92DFD4F5330'}], + ['226', {IN=> {f=> '656 0 32 69 51 135 25 31 245 123 7 164 135 178 221 42 19 286 241 36 62 107 218 303 17 267 244 32 128 36 274 282 105 91 54 190 27 99 242 176 306 235 79 199 84 169 258 128 293 289 143 213 17 208 259 209 187 278 112 35 287 228 90 126 121 151 26 18 299 187 21 97 174 179 302 252 8 255 63 306 82 254 135 237 206 181 276 44 87 283 245 19 182 51 288 215 144 141 86 84 16 68 64 81 10 66 312 133 6 83 241 189 252 220 114 266 94 119 177 234 304 4 5 308 46 61 26 8 314 48 80 23 12 297 119 24 44 191 108 42 231 145 128 140 99 30 1 54 131 42 276 301 102 144 37 261 20 169 105 303 180 77 180 136 165 275 57 33 219 231 86 143 1 207 272 155 172 264 179 45 237 147 196 137 152 13 72 47 152 270 87 224 260 196 241 293 77 284 10 229 171 20 110 120 164 288 3 18 254 298 47 93 285 313 283 186 34 43 159 214 4 262 7 223 120 1 113 116 181 217 59 264 26 171 173 251 233 60 251 80 186 138 184 223 61 16 23 175 107 6 177 81 114 207 109 29 285 160 142 73 138 80 82 313 120 11 98 255 122 291 221 146 209 83 88 315 139 8 151 189 193 235 291 58 20 273 295 51 76 40 257 37 49 161 233 1 266 257 294 64 22 25 243 104 59 111 201 58 277 288 156 159 2 194 10 170 186 197 169 46 2 41 185 106 290 234 92 145 69 155 9 138 243 208 200 224 48 21 38 189 40 45 178 162 57 196 78 167 190 180 289 306 23 269 312 296 132 19 29 226 175 3 181 64 234 151 130 208 96 34 300 174 75 112 188 112 292 302 89 198 52 275 269 159 155 19 123 66 149 274 70 295 204 266 153 104 126 62 166 203 126 225 25 90 230 262 264 238 30 60 39 270 299 34 147 300 278 216 225 35 75 53 203 22 84 228 243 267 185 47 305 95 200 71 223 273 142 226 12 144 294 276 197 228 31 141 298 259 268 172 101 4 109 133 110 273 38 36 215 297 15 199 296 28 145 281 14 212 242 280 131 32 291 162 161 70 142 14 153 257 141 239 274 129 280 27 158 227 315 198 309 290 130 267 81 173 192 248 237 43 6 24 256 50 44 146 268 68 227 256 213 170 33 56 105 150 39 13 284 173 88 58 124 147 43 263 39 117 109 286 300 21 201 48 292 149 215 85 156 312 192 307 222 133 263 98 102 248 178 9 183 132 182 204 113 279 40 104 163 301 265 270 240 49 8 92 204 54 294 217 212 89 139 67 136 12 85 309 137 256 154 185 210 115 31 304 108 146 56 209 24 103 176 247 250 305 307 10 7 11 310 65 9 79 258 69 308 150 202 139 171 277 125 297 272 214 157 87 71 70 83 29 14 67 77 27 311 52 63 94 272 2 31 200 283 33 160 246 263 251 292 45 74 21 260 33 115 90 289 247 38 130 55 222 286 88 211 227 ^'}}, + {OUT=>'B6925F4DF94949B8844C867428BA3DEDF4CF2B51'}], + ['227', {IN=> {f=> '668 0 211 254 226 115 16 41 170 158 305 247 25 183 117 235 218 125 212 30 152 243 195 254 239 61 28 237 120 302 167 130 194 148 96 312 105 65 160 220 53 281 270 226 102 70 57 137 91 26 296 105 78 106 204 40 31 232 177 22 129 68 168 269 74 276 275 208 174 14 126 47 219 218 138 158 14 139 310 203 251 205 166 11 59 52 214 282 20 214 308 275 182 282 46 106 230 249 316 252 311 309 77 271 15 291 136 269 100 168 243 182 308 301 74 250 66 240 200 197 156 99 16 54 116 96 21 314 33 134 37 23 229 156 73 124 132 96 8 51 49 147 287 15 278 190 14 113 101 235 231 71 196 63 219 205 192 220 27 72 31 206 285 100 155 297 244 4 234 66 253 146 181 189 166 24 5 36 201 32 28 211 228 17 193 313 224 200 210 102 83 3 121 78 93 258 56 44 165 215 71 209 9 157 238 259 182 295 38 90 217 316 278 203 277 97 88 302 193 22 116 122 230 236 7 268 7 242 115 3 95 186 125 238 285 74 263 12 224 187 264 164 50 299 159 127 127 153 45 13 33 121 91 39 242 89 111 173 166 37 314 20 188 53 307 162 148 122 204 27 85 294 190 1 167 117 248 164 63 245 97 114 194 161 42 250 92 132 122 217 290 69 281 257 280 118 37 36 175 94 60 191 94 47 245 110 60 178 148 109 258 43 98 227 228 4 247 12 237 133 248 151 117 261 110 47 232 164 76 191 81 101 261 123 310 216 197 143 153 32 67 49 134 24 31 245 123 6 162 135 176 220 40 18 286 239 35 62 106 217 303 15 265 244 30 126 34 273 280 105 91 52 188 27 98 240 174 305 234 79 199 84 168 256 128 292 288 141 212 17 206 259 208 187 277 110 34 286 226 89 124 119 150 24 18 299 185 19 95 173 179 300 252 7 255 61 304 82 253 133 235 205 179 274 43 85 281 244 17 180 50 286 213 143 140 86 83 16 67 62 80 8 64 312 131 3 82 240 187 251 218 112 266 92 119 176 233 303 2 2 306 43 59 26 5 314 46 80 21 10 296 118 24 44 191 107 39 229 143 127 140 99 29 54 129 42 276 301 100 142 34 260 17 167 104 302 180 76 178 135 163 274 56 31 219 231 84 142 1 206 272 154 171 264 177 42 237 146 194 135 150 11 72 44 152 269 87 222 259 195 241 293 77 284 7 229 169 19 108 119 163 287 2 15 252 298 46 93 284 311 283 185 32 41 157 212 4 260 4 221 120 315 113 114 181 215 58 263 25 170 171 251 231 58 250 79 186 138 184 223 61 13 20 175 107 6 175 81 114 207 107 26 283 159 140 73 137 78 80 312 118 11 98 253 120 289 221 146 207 81 88 315 139 6 149 189 192 233 290 56 18 273 293 51 75 39 255 35 49 160 233 316 265 257 293 64 21 23 242 102 57 111 199 58 276 288 154 158 1 193 9 170 184 197 169 45 41 183 104 289 234 92 145 68 155 6 136 243 208 203 ^'}}, + {OUT=>'CF5E7256292ABEC431D8E8B9CBEAF22AF072377E'}], + ['228', {IN=> {f=> '656 0 221 48 21 32 186 40 42 178 159 51 196 72 161 187 177 283 306 23 266 309 296 129 10 26 220 172 316 178 61 228 151 130 205 90 34 297 168 69 109 182 112 292 299 83 192 46 269 263 159 149 19 117 63 143 274 67 292 201 260 147 104 313 126 56 163 200 123 225 16 90 230 262 258 232 21 57 39 264 296 31 147 300 278 216 219 35 75 50 197 13 78 225 237 267 185 41 302 95 197 71 220 270 139 223 3 144 288 273 191 228 28 135 295 253 265 172 95 1 106 130 107 267 29 36 212 291 6 196 293 19 142 275 8 209 239 280 131 23 291 162 161 64 142 14 150 254 141 236 268 126 277 21 155 221 309 198 306 284 124 264 75 173 192 242 234 34 3 21 253 44 35 140 262 62 227 250 213 167 30 50 99 150 33 4 281 170 82 55 124 141 40 263 36 114 109 280 294 18 201 39 289 149 215 82 153 306 186 301 219 133 257 95 99 248 175 9 183 126 179 198 110 279 34 101 163 298 265 270 237 46 8 86 204 51 294 214 206 89 133 61 130 9 85 303 134 256 154 182 210 115 25 304 108 143 53 209 18 103 176 244 247 299 304 10 1 8 307 62 6 73 258 69 305 147 202 136 171 277 119 297 266 211 154 84 68 70 83 29 11 67 71 24 305 49 60 91 269 2 22 194 280 33 160 246 260 245 286 39 68 12 260 24 109 84 289 247 38 127 55 222 283 85 205 311 211 252 226 113 12 39 166 154 305 245 25 181 113 233 216 121 212 30 148 241 195 254 239 59 313 28 233 118 298 167 128 192 144 92 308 101 65 156 220 49 281 268 224 100 66 57 137 87 22 292 103 78 102 202 38 29 232 177 22 129 68 168 265 74 272 275 204 174 10 124 43 217 218 134 158 12 137 308 199 247 201 162 5 59 52 210 278 20 214 304 271 178 282 46 106 228 249 312 250 311 309 75 271 15 287 136 269 100 164 239 182 308 297 70 246 64 240 196 195 156 97 14 52 112 96 15 312 29 134 35 17 227 152 71 122 128 94 2 47 47 145 287 13 274 190 8 111 97 235 229 67 194 59 215 205 188 216 23 70 25 206 285 98 151 293 240 230 66 253 142 177 185 164 18 5 34 199 26 24 207 226 15 189 313 224 198 208 102 79 3 119 76 89 256 56 40 165 213 69 207 5 157 234 255 180 295 32 88 217 316 276 203 273 93 86 302 193 20 116 122 226 236 7 268 3 242 111 318 93 184 125 238 281 72 259 10 222 185 262 160 50 295 155 123 127 153 45 9 27 121 89 35 238 85 107 169 166 31 310 16 188 53 307 160 148 118 200 25 83 290 188 314 165 115 246 162 63 241 97 112 194 157 38 250 90 132 120 213 290 65 279 255 278 118 37 30 173 94 60 189 92 47 243 110 58 176 146 105 254 43 94 223 224 2 243 12 235 131 244 149 117 259 108 45 230 164 76 187 79 101 261 109 ^'}}, + {OUT=>'975DCE94902923977F129C0E4ACF40AD28DDB9AA'}], + ['229', {IN=> {f=> '656 0 310 208 189 143 149 32 59 41 130 20 31 245 123 2 154 135 168 216 32 14 286 231 31 62 102 213 303 7 257 244 22 118 26 269 272 105 91 44 180 27 94 232 166 301 230 79 199 84 164 248 128 288 284 133 208 17 198 259 204 187 273 102 30 282 218 85 116 111 146 16 18 299 177 11 87 169 179 292 252 3 255 53 296 82 249 125 227 201 171 266 39 77 273 240 9 172 46 278 205 139 136 86 79 16 63 54 76 56 312 123 312 78 236 179 247 210 104 266 84 119 172 229 299 315 311 298 31 51 26 314 314 38 80 13 2 292 114 24 44 191 103 27 221 135 123 140 99 25 317 54 121 42 276 301 92 134 22 256 5 159 100 298 180 72 170 131 155 270 52 23 219 231 76 138 1 202 272 150 167 264 169 30 237 142 186 127 142 3 72 32 152 265 87 214 255 191 241 293 77 284 316 229 161 15 100 115 159 283 319 3 244 298 42 93 280 303 283 181 24 33 149 204 4 252 313 213 120 307 113 106 181 207 54 259 21 166 163 251 223 50 246 75 186 138 184 223 61 1 8 175 107 6 167 81 114 207 99 14 275 155 132 73 133 70 72 308 110 11 98 245 112 281 221 146 199 73 88 315 139 319 141 189 188 225 286 48 10 273 285 51 71 35 247 27 49 156 233 312 261 257 289 64 17 15 238 94 49 111 191 58 272 288 146 154 318 189 5 170 176 197 169 41 313 41 175 96 285 234 92 145 64 155 315 128 243 208 200 219 48 21 28 184 40 40 178 157 47 196 68 157 185 175 279 306 23 264 307 296 127 4 24 216 170 314 176 59 224 151 130 203 86 34 295 164 65 107 178 112 292 297 79 188 42 265 259 159 145 19 113 61 139 274 65 290 199 256 143 104 311 126 52 161 198 121 225 10 90 230 262 254 228 15 55 39 260 294 29 147 300 278 216 215 35 75 48 193 7 74 223 233 267 185 37 300 95 195 71 218 268 137 221 318 144 284 271 187 228 26 131 293 249 263 172 91 320 104 128 105 263 23 36 210 287 194 291 13 140 271 4 207 237 280 131 17 291 162 161 60 142 14 148 252 141 234 264 124 275 17 153 217 305 198 304 280 120 262 71 173 192 238 232 28 1 19 251 40 29 136 258 58 227 246 213 165 28 46 95 150 29 319 279 168 78 53 124 137 38 263 34 112 109 276 290 16 201 33 287 149 215 80 151 302 182 297 217 133 253 93 97 248 173 9 183 122 177 194 108 279 30 99 163 296 265 270 235 44 8 82 204 49 294 212 202 89 129 57 126 7 85 299 132 256 154 180 210 115 21 304 108 141 51 209 14 103 176 242 245 295 302 10 318 6 305 60 4 69 258 69 303 145 202 134 171 277 115 297 262 209 152 82 66 70 83 29 9 67 67 22 301 47 58 89 267 2 16 190 278 33 160 246 258 241 282 35 64 6 260 18 105 80 289 247 38 125 55 292 ^'}}, + {OUT=>'333B0259B18CE64D6B52CF563DD3041E5F63A516'}], + ); + +sub binary_expand ($$) +{ + my ($test_name, $line) = @_; + my ($n, $b, $rest) = split ' ', $line, 3; + defined $n && defined $b or die "$test_name: too few args\n"; + my @a = split ' ', $rest, $n + 1; + my $caret = pop @a; + $caret eq '^' or die "test $test_name: @a missing '^'\n"; + $b eq '1' || $b eq '0' or die "test $test_name: bad 'b'=$b\n"; + my $n_bad = @a; + @a == $n or + die "test $test_name: wrong number of args (expected $n, found $n_bad)\n"; + my $bit_string = ''; + foreach my $a (@a) + { + $bit_string .= $b x $a; + $b = 1 - $b; + } + my $t = pack ("B*", $bit_string); + # print "$bit_string\n $t\n"; + return $t; +} + +my $t; +foreach $t (@Tests) + { + # Expand each input. + my $in = $t->[1]->{IN}; + $in->{f} = binary_expand $t->[0], $in->{f}; + + # Convert each expected output string to lower case, and append " f\n". + my $h = $t->[2]; + $h->{OUT} = lc $h->{OUT} . " f\n"; + + # Insert the '--text' argument for each test. + splice @$t, 1, 0, '--text'; + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'sha1sum'; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/sha1sum.pl b/tests/misc/sha1sum.pl new file mode 100755 index 0000000..9fe9483 --- /dev/null +++ b/tests/misc/sha1sum.pl @@ -0,0 +1,94 @@ +#!/usr/bin/perl +# Test "sha1sum". + +# Copyright (C) 2000-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $prog = 'sha1sum'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $sha_degenerate = "da39a3ee5e6b4b0d3255bfef95601890afd80709"; + +my @Tests = + ( + ['s1', {IN=> {f=> ''}}, + {OUT=>"$sha_degenerate f\n"}], + ['s2', {IN=> {f=> 'a'}}, + {OUT=>"86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 f\n"}], + ['s3', {IN=> {f=> 'abc'}}, + {OUT=>"a9993e364706816aba3e25717850c26c9cd0d89d f\n"}], + ['s4', + {IN=> {f=> 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'}}, + {OUT=>"84983e441c3bd26ebaae4aa1f95129e5e54670f1 f\n"}], + ['s5', {IN=> {f=> 'abcdefghijklmnopqrstuvwxyz'}}, + {OUT=>"32d10c7b8cf96570ca04ce37f2a19d84240d3a89 f\n"}], + ['s6', {IN=> {f=> join ('', 'A'..'Z', 'a'..'z', '0'..'9')}}, + {OUT=>"761c457bf73b14d27e9e9265c46f4b4dda11f940 f\n"}], + ['s7', {IN=> {f=> '1234567890' x 8}}, + {OUT=>"50abf5706a150990a08b2c5ea40fa0e585554732 f\n"}], + ['million-a', {IN=> {f=> 'a' x 1000000}}, + {OUT=>"34aa973cd4c4daa4f61eeb2bdbad27316534016f f\n"}], + ['bs-sha-1', {IN=> {".\nfoo"=> ''}}, + {OUT=>"\\$sha_degenerate .\\nfoo\n"}], + ['bs-sha-2', {IN=> {".\\foo"=> ''}}, + {OUT=>"\\$sha_degenerate .\\\\foo\n"}], + ['bs-sha-3', {IN=> {".\rfoo"=> ''}}, + {OUT=>"\\$sha_degenerate .\\rfoo\n"}], + # The sha1sum and md5sum drivers share a lot of code. + # Ensure that sha1sum does *not* share the part that makes + # md5sum accept BSD format. + ['check-bsd', '--check', {IN=> {'f.md5' => "MD5 (f) = $sha_degenerate\n"}}, + {AUX=> {f=> ''}}, + {ERR=>"sha1sum: f.md5: no properly formatted " + . "checksum lines found\n"}, + {EXIT=> 1}], + ['check-bsd2', '--check', + {IN=> {'f.sha1' => "SHA1 (f) = $sha_degenerate\n"}}, + {AUX=> {f=> ''}}, {OUT=>"f: OK\n"}], + ['check-bsd3', '--check', '--status', + {IN=> {'f.sha1' => "SHA1 (f) = $sha_degenerate\n"}}, + {AUX=> {f=> 'bar'}}, {EXIT=> 1}], + ['check-openssl', '--check', + {IN=> {'f.md5' => "MD5(f)= $sha_degenerate\n"}}, + {AUX=> {f=> ''}}, + {ERR=>"sha1sum: f.md5: no properly formatted " + . "checksum lines found\n"}, + {EXIT=> 1}], + ['check-openssl2', '--check', + {IN=> {'f.sha1' => "SHA1(f)= $sha_degenerate\n"}}, + {AUX=> {f=> ''}}, {OUT=>"f: OK\n"}], + ['check-openssl3', '--check', '--status', + {IN=> {'f.sha1' => "SHA1(f)= $sha_degenerate\n"}}, + {AUX=> {f=> 'bar'}}, {EXIT=> 1}], + ['bsd-segv', '--check', {IN=> {'z' => "SHA1 ("}}, {EXIT=> 1}, + {ERR=> "$prog: z: no properly formatted checksum lines found\n"}], + ); + +# Insert the '--text' argument for each test. +my $t; +foreach $t (@Tests) + { + splice @$t, 1, 0, '--text' unless @$t[1] =~ /--check/; + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/sha224sum.pl b/tests/misc/sha224sum.pl new file mode 100755 index 0000000..aba0535 --- /dev/null +++ b/tests/misc/sha224sum.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl +# Test "sha224sum". + +# Copyright (C) 2005-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + ['s3', {IN=> {f=> 'abc'}}, + {OUT=>"23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7 f\n"}], + ['s4', + {IN=> {f=> 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'}}, + {OUT=>"75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525 f\n"}], + ['s8', {IN=> {f=> 'a' x 1000000}}, + {OUT=>"20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67 f\n"}], + ); + +# Insert the '--text' argument for each test. +my $t; +foreach $t (@Tests) + { + splice @$t, 1, 0, '--text' unless @$t[1] =~ /--check/; + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'sha224sum'; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/sha256sum.pl b/tests/misc/sha256sum.pl new file mode 100755 index 0000000..ec69915 --- /dev/null +++ b/tests/misc/sha256sum.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl +# Test "sha256sum". + +# Copyright (C) 2005-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $sha_degenerate = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; + +my @Tests = + ( + ['s1', {IN=> {f=> ''}}, + {OUT=>"$sha_degenerate f\n"}], + ['s2', {IN=> {f=> 'a'}}, + {OUT=>"ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb f\n"}], + ['s3', {IN=> {f=> 'abc'}}, + {OUT=>"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad f\n"}], + ['s4', + {IN=> {f=> 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'}}, + {OUT=>"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1 f\n"}], + ['s8', {IN=> {f=> 'a' x 1000000}}, + {OUT=>"cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0 f\n"}], + ); + +# Insert the '--text' argument for each test. +my $t; +foreach $t (@Tests) + { + splice @$t, 1, 0, '--text' unless @$t[1] =~ /--check/; + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'sha256sum'; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/sha384sum.pl b/tests/misc/sha384sum.pl new file mode 100755 index 0000000..3614a02 --- /dev/null +++ b/tests/misc/sha384sum.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl +# Test "sha384sum". + +# Copyright (C) 2005-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $sha_degenerate = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"; + +my @Tests = + ( + ['s1', {IN=> {f=> ''}}, + {OUT=>"$sha_degenerate f\n"}], + ['s2', {IN=> {f=> 'a'}}, + {OUT=>"54a59b9f22b0b80880d8427e548b7c23abd873486e1f035dce9cd697e85175033caa88e6d57bc35efae0b5afd3145f31 f\n"}], + ['s3', {IN=> {f=> 'abc'}}, + {OUT=>"cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7 f\n"}], + ['s4', + {IN=> {f=> 'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'}}, + {OUT=>"09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039 f\n"}], + ['s8', {IN=> {f=> 'a' x 1000000}}, + {OUT=>"9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985 f\n"}], + ); + +# Insert the '--text' argument for each test. +my $t; +foreach $t (@Tests) + { + splice @$t, 1, 0, '--text' unless @$t[1] =~ /--check/; + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'sha384sum'; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/sha512sum.pl b/tests/misc/sha512sum.pl new file mode 100755 index 0000000..84d0d13 --- /dev/null +++ b/tests/misc/sha512sum.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl +# Test "sha512sum". + +# Copyright (C) 2005-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $sha_degenerate = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; + +my @Tests = + ( + ['s1', {IN=> {f=> ''}}, + {OUT=>"$sha_degenerate f\n"}], + ['s2', {IN=> {f=> 'a'}}, + {OUT=>"1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75 f\n"}], + ['s3', {IN=> {f=> 'abc'}}, + {OUT=>"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f f\n"}], + ['s4', + {IN=> {f=> 'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'}}, + {OUT=>"8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909 f\n"}], + ['s8', {IN=> {f=> 'a' x 1000000}}, + {OUT=>"e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b f\n"}], + ); + +# Insert the '--text' argument for each test. +my $t; +foreach $t (@Tests) + { + splice @$t, 1, 0, '--text' unless @$t[1] =~ /--check/; + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'sha512sum'; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/shred-exact.sh b/tests/misc/shred-exact.sh new file mode 100755 index 0000000..2c8f983 --- /dev/null +++ b/tests/misc/shred-exact.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# Test functionality of --exact + +# Copyright (C) 2000-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ shred + + +# make sure that neither --exact nor --zero gobbles a command line argument +for opt in --exact --zero; do + echo a > a || framework_failure_ + echo bb > b || framework_failure_ + echo ccc > c || framework_failure_ + + shred --remove $opt a b || fail=1 + test -f a && fail=1 + test -f b && fail=1 + + shred --remove $opt c || fail=1 + test -f c && fail=1 +done + + +# make sure direct I/O is handled appropriately at end of file +# Create a 1MiB file as we'll probably not be using blocks larger than that +# (i.e., we want to test failed writes not at the start). +truncate -s1MiB file.slop || framework_failure_ +truncate -s+1 file.slop || framework_failure_ +shred --exact -n2 file.slop || fail=1 + +# make sure direct I/O is handled appropriately at start of file +truncate -s1 file.slop || framework_failure_ +shred --exact -n2 file.slop || fail=1 + +Exit $fail diff --git a/tests/misc/shred-passes.sh b/tests/misc/shred-passes.sh new file mode 100755 index 0000000..61ca60b --- /dev/null +++ b/tests/misc/shred-passes.sh @@ -0,0 +1,91 @@ +#!/bin/sh +# Verify the operations done by shred + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ shred + + +# shred a single letter, which should result in +# 3 random passes and a single rename. +printf 1 > f || framework_failure_ +echo "\ +shred: f: pass 1/3 (random)... +shred: f: pass 2/3 (random)... +shred: f: pass 3/3 (random)... +shred: f: removing +shred: f: renamed to 0 +shred: f: removed" > exp || framework_failure_ + +shred -v -u f 2>out || fail=1 +compare exp out || fail=1 + + +# Likewise but for a zero length file +# to bypass the data passes +touch f || framework_failure_ +echo "\ +shred: f: removing +shred: f: renamed to 0 +shred: f: removed" > exp || framework_failure_ + +shred -v -u f 2>out || fail=1 +compare exp out || fail=1 + + +# shred data 20 times and verify the passes used. +# This would consume all random data between 5.93 and 8.24 inclusive. +dd bs=100K count=1 if=/dev/zero | tr '\0' 'U' > Us || framework_failure_ +printf 1 > f || framework_failure_ +echo "\ +shred: f: pass 1/20 (random)... +shred: f: pass 2/20 (ffffff)... +shred: f: pass 3/20 (924924)... +shred: f: pass 4/20 (888888)... +shred: f: pass 5/20 (db6db6)... +shred: f: pass 6/20 (777777)... +shred: f: pass 7/20 (492492)... +shred: f: pass 8/20 (bbbbbb)... +shred: f: pass 9/20 (555555)... +shred: f: pass 10/20 (aaaaaa)... +shred: f: pass 11/20 (random)... +shred: f: pass 12/20 (6db6db)... +shred: f: pass 13/20 (249249)... +shred: f: pass 14/20 (999999)... +shred: f: pass 15/20 (111111)... +shred: f: pass 16/20 (000000)... +shred: f: pass 17/20 (b6db6d)... +shred: f: pass 18/20 (eeeeee)... +shred: f: pass 19/20 (333333)... +shred: f: pass 20/20 (random)... +shred: f: removing +shred: f: renamed to 0 +shred: f: removed" > exp || framework_failure_ + +shred -v -u -n20 -s4096 --random-source=Us f 2>out || fail=1 +compare exp out || fail=1 + +# Trigger an issue in shred before v8.27 where single +# bytes in the pattern space were not initialized correctly +# for particular sizes, like 7,13,... +# This failed under both valgrind and ASAN. +for size in 1 2 6 7 8; do + touch shred.pattern.umr.size + shred -n4 -s$size shred.pattern.umr.size || fail=1 +done + +Exit $fail diff --git a/tests/misc/shred-remove.sh b/tests/misc/shred-remove.sh new file mode 100755 index 0000000..a4f5117 --- /dev/null +++ b/tests/misc/shred-remove.sh @@ -0,0 +1,70 @@ +#!/bin/sh +# Exercise shred --remove + +# Copyright (C) 1999-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ shred +skip_if_root_ + +# The length of the basename is what matters. +# In this case, shred-4.0l would try to rename the file 256^10 times +# before terminating. +file=0123456789 +touch $file || framework_failure_ +chmod u-w $file || framework_failure_ + +# This would take so long that it appears to infloop +# when using version from fileutils-4.0k. +# When the command completes, expect it to fail. +returns_ 1 shred -u $file > /dev/null 2>&1 || fail=1 +rm -f $file || framework_failure_ + +# Ensure all --remove methods at least unlink the file +for mode in '' '=unlink' '=wipe' '=wipesync'; do + touch $file || framework_failure_ + shred -n0 --remove"$mode" $file || fail=1 + test -e $file && fail=1 +done + +# Ensure incorrect params are diagnosed +touch $file || framework_failure_ +returns_ 1 shred -n0 --remove=none $file 2>/dev/null || fail=1 + +# Ensure rename passes complete. +# coreutils-8.28 did not do the decreasing length rename +# which may have leaked the length of the removed file name + # test level exhaustion +touch \ + 0 1 2 3 4 5 6 7 8 9 \ + a b c d e f g h i j k l m n o p q r s t u v w x y z \ + A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ || framework_failure_ +touch test 000 || framework_failure_ # test level increment +shred -vu test 2>out || fail=1 +cat <<\EOF >exp || framework_failure_ +shred: test: removing +shred: test: renamed to 0000 +shred: 0000: renamed to 001 +shred: 001: renamed to 00 +shred: test: removed +EOF +compare exp out || fail=1 + +# Ensure renames are only retried for EEXIST +mkdir rodir && cd rodir && touch $file && chmod a-w . || framework_failure_ +returns_ 1 timeout 10 shred -u $file || fail=1 + +Exit $fail diff --git a/tests/misc/shred-size.sh b/tests/misc/shred-size.sh new file mode 100755 index 0000000..07255cf --- /dev/null +++ b/tests/misc/shred-size.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Exercise shred --size + +# Copyright (C) 2014-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ shred + +# Negative size +echo "shred: invalid file size: '-2'" > exp || framework_failure_ +echo 1234 > f || framework_failure_ +shred -s-2 f 2>err && fail=1 +compare exp err || fail=1 + +# Octal/Hex +shred -s010 f || fail=1 +test $(stat --printf=%s f) = 8 || fail=1 +shred -s0x10 f || fail=1 +test $(stat --printf=%s f) = 16 || fail=1 + +Exit $fail diff --git a/tests/misc/shuf-reservoir.sh b/tests/misc/shuf-reservoir.sh new file mode 100755 index 0000000..fb0aad3 --- /dev/null +++ b/tests/misc/shuf-reservoir.sh @@ -0,0 +1,73 @@ +#!/bin/sh +# Exercise shuf's reservoir-sampling code +# NOTE: +# These tests do not check valid randomness, +# they just check memory allocation related code. + +# Copyright (C) 2013-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ shuf +expensive_ +require_valgrind_ + +# Only exit with error for leaks when in development mode +# in which case we enable code to suppress inconsequential leaks. +grep '^#define lint 1' "$CONFIG_HEADER" && leaklevel=full || leaklevel=summary + +# Run "shuf" with specific number of input lines and output lines +# Check the output for expected number of lines. +run_shuf_n() +{ + INPUT_LINES="$1" + OUTPUT_LINES="$2" + + # Critical memory-related bugs will cause a segfault here + # (with varying numbers of input/output lines) + seq "$INPUT_LINES" | valgrind --leak-check=$leaklevel --error-exitcode=1 \ + shuf -n "$OUTPUT_LINES" -o "out_${INPUT_LINES}_${OUTPUT_LINES}" || return 1 + + EXPECTED_LINES="$OUTPUT_LINES" + test "$INPUT_LINES" -lt "$OUTPUT_LINES" && EXPECTED_LINES="$INPUT_LINES" + + # There is no sure way to verify shuffled output (as it is random). + # Ensure we have the correct number of all numeric lines non duplicated lines. + GOOD_LINES=$(grep '^[0-9][0-9]*$' "out_${INPUT_LINES}_${OUTPUT_LINES}" | + sort -un | wc -l) || framework_failure_ + LINES=$(wc -l < "out_${INPUT_LINES}_${OUTPUT_LINES}") || framework_failure_ + + test "$EXPECTED_LINES" -eq "$GOOD_LINES" || return 1 + test "$EXPECTED_LINES" -eq "$LINES" || return 1 + + return 0 +} + +# Test multiple combinations of input lines and output lines. +# (e.g. small number of input lines and large number of output lines, +# and vice-versa. Also, each reservoir allocation uses a 1024-lines batch, +# so test 1023/1024/1025 and related values). +TEST_LINES="0 1 5 1023 1024 1025 3071 3072 3073" + +for IN_N in $TEST_LINES; do + for OUT_N in $TEST_LINES; do + run_shuf_n "$IN_N" "$OUT_N" || { + fail=1 + echo "shuf-reservoir-sampling failed with IN_N=$IN_N OUT_N=$OUT_N" >&2; + } + done +done + +Exit $fail diff --git a/tests/misc/shuf.sh b/tests/misc/shuf.sh new file mode 100755 index 0000000..e75d17d --- /dev/null +++ b/tests/misc/shuf.sh @@ -0,0 +1,178 @@ +#!/bin/sh +# Ensure that shuf randomizes its input. + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ shuf +getlimits_ + +seq 100 > in || framework_failure_ + +shuf in >out || fail=1 + +# Fail if the input is the same as the output. +# This is a probabilistic test :-) +# However, the odds of failure are very low: 1 in 100! (~ 1 in 10^158) +compare in out > /dev/null && { fail=1; echo "not random?" 1>&2; } + +# Fail if the sorted output is not the same as the input. +sort -n out > out1 +compare in out1 || { fail=1; echo "not a permutation" 1>&2; } + +# Exercise shuf's -i option. +shuf -i 1-100 > out || fail=1 +compare in out > /dev/null && { fail=1; echo "not random?" 1>&2; } +sort -n out > out1 +compare in out1 || { fail=1; echo "not a permutation" 1>&2; } + +# Exercize shuf's -r -n 0 options, with no standard input. +shuf -r -n 0 in <&- >out || fail=1 +compare /dev/null out || fail=1 + +# Exercise shuf's -e option. +t=$(shuf -e a b c d e | sort | fmt) +test "$t" = 'a b c d e' || { fail=1; echo "not a permutation" 1>&2; } + +# coreutils-8.22 dumps core. +shuf -er +test $? -eq 1 || fail=1 + +# coreutils-8.22 and 8.23 dump core +# with a single redundant operand with --input-range +shuf -i0-0 1 +test $? -eq 1 || fail=1 + +# Before coreutils-6.3, this would infloop. +# "seq 1860" produces 8193 (8K + 1) bytes of output. +seq 1860 | shuf > /dev/null || fail=1 + +# coreutils-6.12 and earlier would output a newline terminator, not \0. +shuf --zero-terminated -i 1-1 > out || fail=1 +printf '1\0' > exp || framework_failure_ +cmp out exp || { fail=1; echo "missing NUL terminator?" 1>&2; } + +# Ensure shuf -n operates efficiently for small n. Before coreutils-8.13 +# this would try to allocate $SIZE_MAX * sizeof(size_t) +timeout 10 shuf -i1-$SIZE_MAX -n2 >/dev/null || + { fail=1; echo "couldn't get a small subset" >&2; } + +# Ensure shuf -n0 doesn't read any input or open specified files +touch unreadable || framework_failure_ +chmod 0 unreadable || framework_failure_ +if ! test -r unreadable; then + shuf -n0 unreadable || fail=1 + { shuf -n1 unreadable || test $? -ne 1; } && fail=1 +fi + +# Multiple -n is accepted, should use the smallest value +shuf -n10 -i0-9 -n3 -n20 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 3 || { fail=1; echo "Multiple -n failed">&2 ; } + +# Test error conditions + +# -i and -e must not be used together +: | { shuf -i0-9 -e A B || test $? -ne 1; } && + { fail=1; echo "shuf did not detect erroneous -e and -i usage.">&2 ; } +# Test invalid value for -n +: | { shuf -nA || test $? -ne 1; } && + { fail=1; echo "shuf did not detect erroneous -n usage.">&2 ; } +# Test multiple -i +{ shuf -i0-9 -n10 -i8-90 || test $? -ne 1; } && + { fail=1; echo "shuf did not detect multiple -i usage.">&2 ; } +# Test invalid range +for ARG in '1' 'A' '1-' '1-A'; do + { shuf -i$ARG || test $? -ne 1; } && + { fail=1; echo "shuf did not detect erroneous -i$ARG usage.">&2 ; } +done + +# multiple -o are forbidden +{ shuf -i0-9 -o A -o B || test $? -ne 1; } && + { fail=1; echo "shuf did not detect erroneous multiple -o usage.">&2 ; } +# multiple random-sources are forbidden +{ shuf -i0-9 --random-source A --random-source B || test $? -ne 1; } && + { fail=1; echo "shuf did not detect multiple --random-source usage.">&2 ; } + +# Test --repeat option + +# --repeat without count should return an indefinite number of lines +shuf --rep -i 0-10 | head -n 1000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 1000 \ + || { fail=1; echo "--repeat does not repeat indefinitely">&2 ; } + +# --repeat can output more values than the input range +shuf --rep -i0-9 -n1000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 1000 || { fail=1; echo "--repeat with --count failed">&2 ; } + +# Check output values (this is not bullet-proof, but drawing 1000 values +# between 0 and 9 should produce all values, unless there's a bug in shuf +# or a very poor random source, or extremely bad luck) +c=$(sort -nu exp | paste -s -d ' ') || framework_failure_ +test "$c" = "0 1 2 3 4 5 6 7 8 9" || + { fail=1; echo "--repeat produced bad output">&2 ; } + +# check --repeat with non-zero low value +shuf --rep -i222-233 -n2000 > exp || framework_failure_ +c=$(sort -nu exp | paste -s -d ' ') || framework_failure_ +test "$c" = "222 223 224 225 226 227 228 229 230 231 232 233" || + { fail=1; echo "--repeat produced bad output with non-zero low">&2 ; } + +# --repeat,-i,count=0 should not fail and produce no output +shuf --rep -i0-9 -n0 > exp || framework_failure_ +# file size should be zero (no output from shuf) +test \! -s exp || + { fail=1; echo "--repeat,-i0-9,-n0 produced bad output">&2 ; } + +# --repeat with -e, without count, should repeat indefinitely +shuf --rep -e A B C D | head -n 1000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 1000 || + { fail=1; echo "--repeat,-e does not repeat indefinitely">&2 ; } + +# --repeat with STDIN, without count, should repeat indefinitely +printf "A\nB\nC\nD\nE\n" | shuf --rep | head -n 1000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 1000 || + { fail=1; echo "--repeat,STDIN does not repeat indefinitely">&2 ; } + +# --repeat with STDIN,count - can return move values than input lines +printf "A\nB\nC\nD\nE\n" | shuf --rep -n2000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 2000 || + { fail=1; echo "--repeat,STDIN,count failed">&2 ; } + +# Check output values (this is not bullet-proof, but drawing 2000 values +# between A and E should produce all values, unless there's a bug in shuf +# or a very poor random source, or extremely bad luck) +c=$(sort -u exp | paste -s -d ' ') || framework_failure_ +test "$c" = "A B C D E" || + { fail=1; echo "--repeat,STDIN,count produced bad output">&2 ; } + +# --repeat,stdin,count=0 should not fail and produce no output +printf "A\nB\nC\nD\nE\n" | shuf --rep -n0 > exp || framework_failure_ +# file size should be zero (no output from shuf) +test \! -s exp || + { fail=1; echo "--repeat,STDIN,-n0 produced bad output">&2 ; } + +# shuf 8.25 mishandles input if stdin is closed, due to glibc bug#15589. +# See coreutils bug#25029. +shuf /dev/null <&- >out || fail=1 +compare /dev/null out || fail=1 + +Exit $fail diff --git a/tests/misc/sleep.sh b/tests/misc/sleep.sh new file mode 100755 index 0000000..bcf6c18 --- /dev/null +++ b/tests/misc/sleep.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# Validate sleep parameters + +# Copyright (C) 2016-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sleep printf +getlimits_ + +# invalid timeouts +returns_ 1 timeout 10 sleep invalid || fail=1 +returns_ 1 timeout 10 sleep -- -1 || fail=1 +returns_ 1 timeout 10 sleep 42D || fail=1 +returns_ 1 timeout 10 sleep 42d 42day || fail=1 +returns_ 1 timeout 10 sleep nan || fail=1 +returns_ 1 timeout 10 sleep '' || fail=1 +returns_ 1 timeout 10 sleep || fail=1 + +# subsecond actual sleep +timeout 10 sleep 0.001 || fail=1 +timeout 10 sleep 0x.002p1 || fail=1 + +# Using small timeouts for larger sleeps is racy, +# but false positives should be avoided on most systems +returns_ 124 timeout 0.1 sleep 1d 2h 3m 4s || fail=1 +returns_ 124 timeout 0.1 sleep inf || fail=1 +returns_ 124 timeout 0.1 sleep $LDBL_MAX || fail=1 + +# Test locale decimal handling for printf, sleep, timeout +: ${LOCALE_FR_UTF8=none} +if test "$LOCALE_FR_UTF8" != "none"; then + f=$LOCALE_FR_UTF8 + locale_decimal=$(LC_ALL=$f env printf '%0.3f' 0.001) || fail=1 + locale_decimal=$(LC_ALL=$f env printf '%0.3f' "$locale_decimal") || fail=1 + case "$locale_decimal" in + 0?001) + LC_ALL=$f timeout 1$locale_decimal sleep "$locale_decimal" || fail=1 ;; + *) fail=1 ;; + esac +fi + +Exit $fail diff --git a/tests/misc/sm3sum.pl b/tests/misc/sm3sum.pl new file mode 100755 index 0000000..7dfd4da --- /dev/null +++ b/tests/misc/sm3sum.pl @@ -0,0 +1,56 @@ +#!/usr/bin/perl +# Test "cksum -a sm3". + +# Copyright (C) 2021-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $sha_degenerate = + "1ab21d8355cfa17f8e61194831e81a8f22bec8c728fefb747ed035eb5082aa2b"; + +my @Tests = + ( + ['s1', {IN=> {f=> ''}}, +{OUT=>"$sha_degenerate f\n"}], + ['s2', {IN=> {f=> 'a'}}, +{OUT=>"623476ac18f65a2909e43c7fec61b49c7e764a91a18ccb82f1917a29c86c5e88 f\n"}], + ['s3', {IN=> {f=> 'abc'}}, +{OUT=>"66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0 f\n"}], + ['s4', + {IN=> {f=> 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'}}, +{OUT=>"639b6cc5e64d9e37a390b192df4fa1ea0720ab747ff692b9f38c4e66ad7b8c05 f\n"}], + ['s8', {IN=> {f=> 'a' x 1000000}}, +{OUT=>"c8aaf89429554029e231941a2acc0ad61ff2a5acd8fadd25847a3a732b3b02c3 f\n"}], + ); + +# Insert the arguments for each test. +my $t; +foreach $t (@Tests) + { + splice @$t, 1, 0, '--untagged -a sm3' + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'cksum'; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/sort-NaN-infloop.sh b/tests/misc/sort-NaN-infloop.sh new file mode 100755 index 0000000..93cf9bd --- /dev/null +++ b/tests/misc/sort-NaN-infloop.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# exercise the NaN-infloop bug in coreutils-8.13 + +# Copyright (C) 2011-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +echo nan > F || framework_failure_ +printf 'nan\nnan\n' > exp || framework_failure_ +timeout 10 sort -g -m F F > out || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/sort-benchmark-random.sh b/tests/misc/sort-benchmark-random.sh new file mode 100755 index 0000000..13e911d --- /dev/null +++ b/tests/misc/sort-benchmark-random.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# Benchmark sort on randomly generated data. + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +# Written by Glen Lenker. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort +require_perl_ + +very_expensive_ + +$PERL -e ' +my $num_lines = 500000; +my $length = 100; + +for (my $i=0; $i < $num_lines; $i++) +{ + for (my $j=0; $j < $length; $j++) + { + printf "%c", 32 + rand(94); + } + print "\n"; +}' > in || framework_failure_ + +# We need to generate a lot of data for sort to show a noticeable +# improvement in performance. Sorting it in PERL may take awhile. + +$PERL -e ' +open (FILE, "<in"); +my @list = <FILE>; +print sort(@list); +close (FILE); +' > exp || framework_failure_ + +time sort in > out || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/sort-compress-hang.sh b/tests/misc/sort-compress-hang.sh new file mode 100755 index 0000000..4c2ee25 --- /dev/null +++ b/tests/misc/sort-compress-hang.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# Test for sort --compress hang + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort +very_expensive_ + +cat <<EOF >compress || framework_failure_ +#!$SHELL +tr 41 14 || exit +touch ok +EOF + +chmod +x compress + +seq -w 200000 > exp || fail=1 +tac exp > in || fail=1 + +# When the bug occurs, 'sort' hangs forever. When it doesn't occur, +# 'sort' could be running slowly on an overburdened machine. +# On a circa-2010 Linux server using NFS, a successful test completes +# in about 170 seconds, so specify 1700 seconds as a safety margin. +# Note --foreground will not kill any of the "compress" sub processes, +# assuming they're well behaved and exit in a timely manner, but will +# allow this command to be responsive to Ctrl-C +timeout --foreground 1700 sort --compress-program=./compress -S 1k in > out \ + || fail=1 + +compare exp out || fail=1 +test -f ok || fail=1 +rm -f compress ok + +# If $TMPDIR is relative, give subprocesses time to react when 'sort' exits. +# Otherwise, under NFS, when 'sort' unlinks the temp files and they +# are renamed to .nfsXXXX instead of being removed, the parent cleanup +# of this directory will fail because the files are still open. +case $TMPDIR in +/*) ;; +*) sleep 1;; +esac + +Exit $fail diff --git a/tests/misc/sort-compress-proc.sh b/tests/misc/sort-compress-proc.sh new file mode 100755 index 0000000..12f8209 --- /dev/null +++ b/tests/misc/sort-compress-proc.sh @@ -0,0 +1,90 @@ +#!/bin/sh +# Test use of compression subprocesses by sort + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort +expensive_ + +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +SORT_FAILURE=2 + +seq -w 2000 > exp || fail=1 +tac exp > in || fail=1 +insize=$(stat -c %s - <in) || fail=1 + +# This compressor's behavior is adjustable via environment variables. +export PRE_COMPRESS= +export POST_COMPRESS= + +printf '%s\n' '#!'"$SHELL" >compress || framework_failure_ +cat <<\EOF >>compress || framework_failure_ +eval "$PRE_COMPRESS" +tr 41 14 || exit +eval "$POST_COMPRESS" +EOF + +chmod +x compress + +# "Impatient exit" tests +# +# In these test cases, the biggest compressor (or decompressor) exits +# with nonzero status, after sleeping a bit. Until coreutils 8.7 +# 'sort' impatiently exited without waiting for its decompression +# subprocesses in these cases. Check compression too, while we're here. +# +for compress_arg in '' '-d' +do + POST_COMPRESS=' + test "X$1" != "X'$compress_arg'" || { + test "X$1" = "X" && exec <&1 + size=$(stat -c %s -) + exec >/dev/null 2>&1 <&1 || exit + expr $size "<" '"$insize"' / 2 || { sleep 1; exit 1; } + } + ' sort --compress-program=./compress -S 1k --batch-size=2 in > out + test $? -eq $SORT_FAILURE || fail=1 +done + +# "Pre-exec child" test +# +# Ignore a random child process created before 'sort' was exec'ed. +# This bug was also present in coreutils 8.7. +# +( (sleep 1; exec false) & pid=$! + PRE_COMPRESS='test -f ok || sleep 2' + POST_COMPRESS='touch ok' + exec sort --compress-program=./compress -S 1k in >out +) || fail=1 +compare exp out || fail=1 +test -f ok || fail=1 +rm -f ok + +rm -f compress + +# If $TMPDIR is relative, give subprocesses time to react when 'sort' exits. +# Otherwise, under NFS, when 'sort' unlinks the temp files and they +# are renamed to .nfsXXXX instead of being removed, the parent cleanup +# of this directory will fail because the files are still open. +case $TMPDIR in +/*) ;; +*) sleep 1;; +esac + +Exit $fail diff --git a/tests/misc/sort-compress.sh b/tests/misc/sort-compress.sh new file mode 100755 index 0000000..649d9a4 --- /dev/null +++ b/tests/misc/sort-compress.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# Test use of compression by sort + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort +require_trap_signame_ + +seq -w 2000 > exp || framework_failure_ +tac exp > in || framework_failure_ + +# This should force the use of temp files +sort -S 1k in > out || fail=1 +compare exp out || fail=1 + +# Create our own gzip program that will be used as the default +cat <<EOF > gzip || framework_failure_ +#!$SHELL +tr 41 14 +touch ok +EOF + +chmod +x gzip + +# Ensure 'sort' is immune to parent's SIGCHLD handler +# Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh. +( + trap '' CHLD + + # This should force the use of child processes for "compression" + PATH=.:$PATH exec sort -S 1k --compress-program=gzip in > /dev/null +) || fail=1 + +# This will find our new gzip in PATH +PATH=.:$PATH sort -S 1k --compress-program=gzip in > out || fail=1 +compare exp out || fail=1 +test -f ok || fail=1 +rm -f ok + +# This is to make sure it works with no compression. +PATH=.:$PATH sort -S 1k in > out || fail=1 +compare exp out || fail=1 +test -f ok && fail=1 + +# This is to make sure we can use something other than gzip +mv gzip dzip || fail=1 +sort --compress-program=./dzip -S 1k in > out || fail=1 +compare exp out || fail=1 +test -f ok || fail=1 +rm -f ok + +# Make sure it can find other programs in PATH correctly +PATH=.:$PATH sort --compress-program=dzip -S 1k in > out || fail=1 +compare exp out || fail=1 +test -f ok || fail=1 +rm -f dzip ok + +Exit $fail diff --git a/tests/misc/sort-continue.sh b/tests/misc/sort-continue.sh new file mode 100755 index 0000000..058f86d --- /dev/null +++ b/tests/misc/sort-continue.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# Tests for file descriptor exhaustion. + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +# Skip the test when running under valgrind. +( ulimit -n 6; sort 3<&- 4<&- 5<&- < /dev/null ) \ + || skip_ 'fd-limited sort failed; are you running under valgrind?' + +for i in $(seq 31); do + echo $i | tee -a in > __test.$i || framework_failure_ +done + +# glob before ulimit to avoid issues on bash 3.2 on OS X 10.6.8 at least +test_files=$(echo __test.*) + +( + ulimit -n 6 + sort -n -m $test_files 3<&- 4<&- 5<&- < /dev/null > out +) && +compare in out || + { fail=1; echo 'file descriptor exhaustion not handled' 1>&2; } + +echo 32 | tee -a in > in1 +( + ulimit -n 6 + sort -n -m $test_files - 3<&- 4<&- 5<&- < in1 > out +) && +compare in out || { fail=1; echo 'stdin not handled properly' 1>&2; } + +Exit $fail diff --git a/tests/misc/sort-debug-keys.sh b/tests/misc/sort-debug-keys.sh new file mode 100755 index 0000000..9a0f5cc --- /dev/null +++ b/tests/misc/sort-debug-keys.sh @@ -0,0 +1,337 @@ +#!/bin/sh +# Test annotation of sort keys + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort printf + +number() { cat -n | sed 's/^ *//'; } + +cat <<\EOF > exp +1 + ^ no match for key + +^ no match for key +44 + ^ no match for key +33 + ^ no match for key +2 + ^ no match for key +1 + ^ no match for key + +^ no match for key +44 + ^ no match for key +33 + ^ no match for key +2 + ^ no match for key + +^ no match for key +1 +_ +2 +_ +33 +__ +44 +__ +2> + ^ no match for key +3>1 + _ +1>2 + _ +1 + ^ no match for key + +^ no match for key +44 + ^ no match for key +33 + ^ no match for key +2 + ^ no match for key +1 + ^ no match for key + +^ no match for key +44 + ^ no match for key +33 + ^ no match for key +2 + ^ no match for key + +^ no match for key +1 +_ +2 +_ +33 +__ +44 +__ +2> + ^ no match for key +3>1 + _ +1>2 + _ +1 + ^ no match for key + +^ no match for key +44 + ^ no match for key +33 + ^ no match for key +2 + ^ no match for key +1 + ^ no match for key + +^ no match for key +44 + ^ no match for key +33 + ^ no match for key +2 + ^ no match for key + +^ no match for key +1 +_ +2 +_ +33 +__ +44 +__ +2> + ^ no match for key +3>1 + _ +1>2 + _ + +^ no match for key +JAN +___ +FEB +___ +FEB + ^ no match for key + +^ no match for key +JAN + ^ no match for key +JAZZ +^ no match for key + +^ no match for key +JAN +___ +FEB +___ +2>JAZZ + ^ no match for key +3> + ^ no match for key +4>JAN + ___ +1>FEB + ___ + +^ no match for key +JANZ +___ +JAN +___ +FEB +___ +3> + ^ no match for key +2>JANZ + ___ +4>JAN + ___ +1>FEB + ___ + 1.2ignore + ___ + 1.1e4ignore + _____ +>>a +___ +>b +__ +a + ^ no match for key + +^ no match for key +a +_ +b +_ +-3 +__ +-2 +__ +-0 +__ +--Mi-1 +^ no match for key +-0 +__ +1 +_ + 1 + _ +__ +1 +_ +_ + 1 + _ +1 +_ + 1 +__ +1 +_ +2,5 +_ +2.4 +___ +2.,,3 +__ +2.4 +___ +2,,3 +_ +2.4 +___ +1a +_ +2b +_ +>a + _ +A>chr10 + ^ no match for key +B>chr1 + ^ no match for key +1 2 + __ +1 3 + __ +EOF + +( +for type in n h g; do + printf '1\n\n44\n33\n2\n' | sort -s -k2$type --debug + printf '1\n\n44\n33\n2\n' | sort -s -k1.3$type --debug + printf '1\n\n44\n33\n2\n' | sort -s -k1$type --debug + printf '2\n\n1\n' | number | sort -s -k2g --debug +done + +printf 'FEB\n\nJAN\n' | sort -s -k1M --debug +printf 'FEB\n\nJAN\n' | sort -s -k2,2M --debug +printf 'FEB\nJAZZ\n\nJAN\n' | sort -s -k1M --debug +printf 'FEB\nJAZZ\n\nJAN\n' | number | sort -s -k2,2M --debug +printf 'FEB\nJANZ\n\nJAN\n' | sort -s -k1M --debug +printf 'FEB\nJANZ\n\nJAN\n' | number | sort -s -k2,2M --debug + +printf ' 1.2ignore\n 1.1e4ignore\n' | sort -s -g --debug + +printf '\tb\n\t\ta\n' | sort -s -d --debug # ignore = 1 + +printf 'a\n\n' | sort -s -k2,2 --debug #lena = 0 + +printf 'b\na\n' | sort -s -k1 --debug #otherwise key compare + +printf -- '-0\n1\n-2\n--Mi-1\n-3\n-0\n' | sort -s --debug -k1,1h + +printf ' 1\n1\n' | sort -b --debug +printf ' 1\n1\n' | sort -sb --debug +printf ' 1\n1\n' | sort --debug + +# strnumcmp is a bit weird, so we don't match exactly +printf '2,5\n2.4\n' | sort -s -k1n --debug +printf '2.,,3\n2.4\n' | sort -s -k1n --debug +printf '2,,3\n2.4\n' | sort -s -k1n --debug + +# -z means we convert \0 to \n +env printf '1a\x002b\x00' | sort -s -n -z --debug + +# Check that \0 and \t intermix. +printf '\0\ta\n' | sort -s -k2b,2 --debug | tr -d '\0' + +# Check that key end before key start is not underlined +printf 'A\tchr10\nB\tchr1\n' | sort -s -k2.4b,2.3n --debug + +# Ensure that -b applied before -k offsets +printf '1 2\n1 3\n' | sort -s -k1.2b --debug +) > out + +compare exp out || fail=1 + +cat <<\EOF > exp + 1²---++3 1,234 Mi + _ + _________ +________________________ + 1²---++3 1,234 Mi + _____ + ________ +_______________________ ++1234 1234Gi 1,234M +^ no match for key +_____ +^ no match for key + ____ + ____ + _____ + _____ + _____ + ______ +___________________ +EOF + +unset LC_ALL +f=$LOCALE_FR_UTF8 + +: ${LOCALE_FR_UTF8=none} +if test "$LOCALE_FR_UTF8" != "none"; then + ( + echo ' 1²---++3 1,234 Mi' | + LC_ALL=C sort --debug -k2g -k1b,1 + echo ' 1²---++3 1,234 Mi' | + LC_ALL=$f sort --debug -k2g -k1b,1 + echo '+1234 1234Gi 1,234M' | + LC_ALL=$f sort --debug \ + -k1,1n -k1,1g -k1,1h \ + -k2,2n -k2,2g -k2,2h \ + -k3,3n -k3,3g -k3,3h + ) | sed 's/^^ .*/^ no match for key/' > out + compare exp out || fail=1 +fi + +Exit $fail diff --git a/tests/misc/sort-debug-warn.sh b/tests/misc/sort-debug-warn.sh new file mode 100755 index 0000000..beb11c9 --- /dev/null +++ b/tests/misc/sort-debug-warn.sh @@ -0,0 +1,185 @@ +#!/bin/sh +# Test warnings for sort options + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +cat <<\EOF > exp +1 +sort: text ordering performed using simple byte comparison +sort: key 1 has zero width and will be ignored +2 +sort: text ordering performed using simple byte comparison +sort: key 1 has zero width and will be ignored +sort: note numbers use '.' as a decimal point in this locale +3 +sort: text ordering performed using simple byte comparison +sort: key 1 is numeric and spans multiple fields +sort: note numbers use '.' as a decimal point in this locale +4 +sort: text ordering performed using simple byte comparison +sort: note numbers use '.' as a decimal point in this locale +sort: options '-bghMRrV' are ignored +5 +sort: text ordering performed using simple byte comparison +sort: note numbers use '.' as a decimal point in this locale +sort: options '-bghMRV' are ignored +sort: option '-r' only applies to last-resort comparison +6 +sort: text ordering performed using simple byte comparison +sort: note numbers use '.' as a decimal point in this locale +sort: option '-r' only applies to last-resort comparison +7 +sort: text ordering performed using simple byte comparison +sort: leading blanks are significant in key 2; consider also specifying 'b' +sort: note numbers use '.' as a decimal point in this locale +sort: options '-bg' are ignored +8 +sort: text ordering performed using simple byte comparison +sort: note numbers use '.' as a decimal point in this locale +9 +sort: text ordering performed using simple byte comparison +sort: note numbers use '.' as a decimal point in this locale +sort: option '-b' is ignored +10 +sort: text ordering performed using simple byte comparison +sort: note numbers use '.' as a decimal point in this locale +11 +sort: text ordering performed using simple byte comparison +sort: leading blanks are significant in key 1; consider also specifying 'b' +12 +sort: text ordering performed using simple byte comparison +sort: leading blanks are significant in key 1; consider also specifying 'b' +13 +sort: text ordering performed using simple byte comparison +sort: leading blanks are significant in key 1; consider also specifying 'b' +sort: option '-d' is ignored +14 +sort: text ordering performed using simple byte comparison +sort: leading blanks are significant in key 1; consider also specifying 'b' +sort: option '-i' is ignored +15 +sort: text ordering performed using simple byte comparison +16 +sort: text ordering performed using simple byte comparison +17 +sort: text ordering performed using simple byte comparison +EOF + +echo 1 >> out +sort -s -k2,1 --debug /dev/null 2>>out || fail=1 +echo 2 >> out +sort -s -k2,1n --debug /dev/null 2>>out || fail=1 +echo 3 >> out +sort -s -k1,2n --debug /dev/null 2>>out || fail=1 +echo 4 >> out +sort -s -rRVMhgb -k1,1n --debug /dev/null 2>>out || fail=1 +echo 5 >> out +sort -rRVMhgb -k1,1n --debug /dev/null 2>>out || fail=1 +echo 6 >> out +sort -r -k1,1n --debug /dev/null 2>>out || fail=1 +echo 7 >> out +sort -gbr -k1,1n -k1,1r --debug /dev/null 2>>out || fail=1 +echo 8 >> out +sort -b -k1b,1bn --debug /dev/null 2>>out || fail=1 # no warning +echo 9 >> out +sort -b -k1,1bn --debug /dev/null 2>>out || fail=1 +echo 10 >> out +sort -b -k1,1bn -k2b,2 --debug /dev/null 2>>out || fail=1 # no warning +echo 11 >> out +sort -r -k1,1r --debug /dev/null 2>>out || fail=1 # no warning for redundant opt +echo 12 >> out +sort -i -k1,1i --debug /dev/null 2>>out || fail=1 # no warning +echo 13 >> out +sort -d -k1,1b --debug /dev/null 2>>out || fail=1 +echo 14 >> out +sort -i -k1,1d --debug /dev/null 2>>out || fail=1 +echo 15 >> out +sort -r --debug /dev/null 2>>out || fail=1 #no warning +echo 16 >> out +sort -rM --debug /dev/null 2>>out || fail=1 #no warning +echo 17 >> out +sort -rM -k1,1 --debug /dev/null 2>>out || fail=1 #no warning +compare exp out || fail=1 + + +cat <<\EOF > exp +sort: failed to set locale +sort: text ordering performed using simple byte comparison +EOF +LC_ALL=missing sort --debug /dev/null 2>out || fail=1 +# musl libc maps unknown locales to the default utf8 locale +# with no way to determine failures. This is discussed at: +# http://www.openwall.com/lists/musl/2016/04/02/1 +if ! grep -E 'using .*(missing|C.UTF-8).* sorting rules' out; then + compare exp out || fail=1 +fi + + +cat <<\EOF > exp +sort: text ordering performed using simple byte comparison +sort: key 1 is numeric and spans multiple fields +sort: obsolescent key '+2 -1' used; consider '-k 3,1' instead +sort: key 2 has zero width and will be ignored +sort: note numbers use '.' as a decimal point in this locale +sort: option '-b' is ignored +sort: option '-r' only applies to last-resort comparison +EOF +sort --debug -rb -k2n +2.2 -1b /dev/null 2>out || fail=1 +compare exp out || fail=1 + + +# check sign, decimal point, and grouping character warnings +cat <<\EOF > exp +sort: text ordering performed using simple byte comparison +sort: key 1 is numeric and spans multiple fields +sort: field separator ',' is treated as a group separator in numbers +EOF +if test $(printf '0,9\n0,8\n' | sort -ns | tail -n1) = '0,9'; then + # thousands_sep == , + sort -nk1 -t, --debug /dev/null 2>out || fail=1 + compare exp out || fail=1 +fi + +cat <<\EOF > exp +sort: text ordering performed using simple byte comparison +sort: key 1 is numeric and spans multiple fields +sort: field separator '.' is treated as a decimal point in numbers +EOF +sort -nk1 -t. --debug /dev/null 2>out || fail=1 +compare exp out || fail=1 + +cat <<\EOF > exp +sort: text ordering performed using simple byte comparison +sort: key 1 is numeric and spans multiple fields +sort: field separator '-' is treated as a minus sign in numbers +sort: note numbers use '.' as a decimal point in this locale +EOF +sort -nk1 -t- --debug /dev/null 2>out || fail=1 +compare exp out || fail=1 + +cat <<\EOF > exp +sort: text ordering performed using simple byte comparison +sort: key 1 is numeric and spans multiple fields +sort: field separator '+' is treated as a plus sign in numbers +sort: note numbers use '.' as a decimal point in this locale +EOF +sort -gk1 -t+ --debug /dev/null 2>out || fail=1 +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/sort-discrim.sh b/tests/misc/sort-discrim.sh new file mode 100755 index 0000000..1d955e8 --- /dev/null +++ b/tests/misc/sort-discrim.sh @@ -0,0 +1,87 @@ +#!/bin/sh +# Test discriminator-based sorting. + +# Copyright (C) 2012-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +# Set limit variables. +getlimits_ + +# These tests are designed for a 'sort' implementation that uses a +# discriminator, i.e., a brief summary of a key that may have lost info, +# but whose ordering is consistent with that of the original key. +# The tests are useful even if 'sort' does not use this representation. + +# Test lexicographic sorting. + +# A long-enough string so that it overruns a small discriminator buffer size. +long_prefix='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +seq -f "$long_prefix%5.0f" 10000 > exp || fail=1 +sort -R exp | LC_ALL=C sort > out || fail=1 +compare exp out || fail=1 + + +# Test numeric sorting. + +# These tests are designed for an internal representation that ordinarily +# looks at the number plus two decimal digits, but if -h is +# used it looks at one decimal place plus a 4-bit SI prefix value. +# In both cases, there's an extra factor of 2 for the sign. +max_int200=$(expr $UINTMAX_MAX / 200) && +max_frac200=$(printf '%.2d' $(expr $UINTMAX_MAX / 2 % 100)) && +max_int320=$(expr $UINTMAX_MAX / 320) && +max_frac320=$(expr $UINTMAX_MAX / 32 % 10) && +{ printf -- "\ + -$UINTMAX_OFLOW + -$UINTMAX_MAX + -${max_int200}0.1 + -${max_int200}0 + -${max_int200}0.0 + -${max_int320}0.1 + -${max_int320}0 + -${max_int320}0.0 + -$max_int200.${max_frac200}1 + -$max_int200.$max_frac200 + -$max_int320.${max_frac320}1 + -$max_int320.$max_frac320 +" && + seq -- -10 .001 10 && + printf "\ + $max_int320 + $max_int320.$max_frac320 + $max_int320.${max_frac320}1 + $max_int200 + $max_int200.$max_frac200 + $max_int200.${max_frac200}1 + ${max_int320}0 + ${max_int320}0.0 + ${max_int320}0.1 + ${max_int200}0 + ${max_int200}0.0 + ${max_int200}0.1 + $UINTMAX_MAX + $UINTMAX_OFLOW +" +} > exp || fail=1 + +for opts in -n -h; do + sort -R exp | LC_ALL=C sort $opts > out || fail=1 + compare exp out || fail=1 +done + +Exit $fail diff --git a/tests/misc/sort-exit-early.sh b/tests/misc/sort-exit-early.sh new file mode 100755 index 0000000..ed89478 --- /dev/null +++ b/tests/misc/sort-exit-early.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Test 'sort' exits early on inaccessible inputs or output + +# Copyright (C) 2012-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort +skip_if_root_ + +SORT_FAILURE=2 + +# Check output is writable before starting to sort +touch input +chmod a-w input +returns_ $SORT_FAILURE timeout 10 sort -o input || fail=1 + +# Check all inputs are readable before starting to sort +# Also ensure the output isn't created in this case +touch output +chmod a-r output +returns_ $SORT_FAILURE timeout 10 sort -o typo - output || fail=1 +test -e typo && fail=1 + +Exit $fail diff --git a/tests/misc/sort-files0-from.pl b/tests/misc/sort-files0-from.pl new file mode 100755 index 0000000..e26693c --- /dev/null +++ b/tests/misc/sort-files0-from.pl @@ -0,0 +1,96 @@ +#!/usr/bin/perl +# Exercise sort's --files0-from option. +# FIXME: keep this file in sync with tests/du/files0-from. + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +my $prog = 'sort'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + # invalid extra command line argument + ['f-extra-arg', '--files0-from=- no-such', {IN=>"a"}, {EXIT=>2}, + {ERR => "$prog: extra operand 'no-such'\n" + . "file operands cannot be combined with --files0-from\n" + . "Try '$prog --help' for more information.\n"} + ], + + # missing input file + ['missing', '--files0-from=missing', {EXIT=>2}, + {ERR => "$prog: open failed: missing: " + . "No such file or directory\n"}], + + # input file name of '-' + ['minus-in-stdin', '--files0-from=-', '<', {IN=>{f=>'-'}}, {EXIT=>2}, + {ERR => "$prog: when reading file names from stdin, no file name of" + . " '-' allowed\n"}], + + # empty input, regular file + ['empty', '--files0-from=@AUX@', {AUX=>''}, {EXIT=>2}, + {ERR_SUBST => 's/no input from.+$//'}, {ERR => "$prog: \n"}], + + # empty input, from non-regular file + ['empty-nonreg', '--files0-from=/dev/null', {EXIT=>2}, + {ERR => "$prog: no input from '/dev/null'\n"}], + + # one NUL + ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>2}, + {ERR => "$prog: -:1: invalid zero-length file name\n"}], + + # two NULs + # Note that the behavior here differs from 'wc' in that the + # first zero-length file name is treated as fatal, so there + # is only one line of diagnostic output. + ['nul-2', '--files0-from=-', '<', {IN=>"\0\0"}, {EXIT=>2}, + {ERR => "$prog: -:1: invalid zero-length file name\n"}], + + # one file name, no NUL + ['1', '--files0-from=-', '<', + {IN=>{f=>"g"}}, {AUX=>{g=>'a'}}, {OUT=>"a\n"} ], + + # one file name, with NUL + ['1a', '--files0-from=-', '<', + {IN=>{f=>"g\0"}}, {AUX=>{g=>'a'}}, {OUT=>"a\n"} ], + + # two file names, no final NUL + ['2', '--files0-from=-', '<', + {IN=>{f=>"g\0g"}}, {AUX=>{g=>'a'}}, {OUT=>"a\na\n"} ], + + # two file names, with final NUL + ['2a', '--files0-from=-', '<', + {IN=>{f=>"g\0g\0"}}, {AUX=>{g=>'a'}}, {OUT=>"a\na\n"} ], + + # Ensure that $prog does nothing when there is a zero-length filename. + # Note that the behavior here differs from 'wc' in that the + # first zero-length file name is treated as fatal, so there + # should be no output on STDOUT. + ['zero-len', '--files0-from=-', '<', + {IN=>{f=>"\0g\0"}}, {AUX=>{g=>''}}, + {ERR => "$prog: -:1: invalid zero-length file name\n"}, {EXIT=>2} ], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/sort-float.sh b/tests/misc/sort-float.sh new file mode 100755 index 0000000..d44c019 --- /dev/null +++ b/tests/misc/sort-float.sh @@ -0,0 +1,90 @@ +#!/bin/sh +# Ensure sort -g sorts floating point limits correctly + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +# Return 0 if LDBL_MIN is smaller than DBL_MIN, else 1. +# Dissect numbers like these, comparing first exponent, then +# whole part of mantissa, then fraction, until finding enough +# of a difference to determine the relative order of the numbers. +# These are "reversed": +# $ ./getlimits |grep DBL_MIN +# DBL_MIN=2.225074e-308 +# LDBL_MIN=2.004168e-292 +# +# These are in the expected order: +# $ ./getlimits|grep DBL_MIN +# DBL_MIN=2.225074e-308 +# LDBL_MIN=3.362103e-4932 + +dbl_minima_order() +{ + LC_ALL=C getlimits_ + set -- $(echo $LDBL_MIN | tr .e- ' ') + local ldbl_whole=$1 ldbl_frac=$2 ldbl_exp=$3 + + set -- $(echo $DBL_MIN |tr .e- ' ') + local dbl_whole=$1 dbl_frac=$2 dbl_exp=$3 + + test "$dbl_exp" -lt "$ldbl_exp" && return 0 + test "$ldbl_exp" -lt "$dbl_exp" && return 1 + test "$ldbl_whole" -lt "$dbl_whole" && return 0 + test "$dbl_whole" -lt "$ldbl_whole" && return 1 + test "$ldbl_frac" -le "$dbl_frac" && return 0 + return 1 +} + +# On some systems, DBL_MIN < LDBL_MIN. Detect that. +dbl_minima_order; reversed=$? + +for LOC in C $LOCALE_FR; do + + LC_ALL=$LOC getlimits_ + + # If DBL_MIN happens to be smaller than LDBL_MIN, swap them, + # so that out expected output is sorted. + if test $reversed = 1; then + t=$LDBL_MIN + LDBL_MIN=$DBL_MIN + DBL_MIN=$t + fi + + printf -- "\ +-$LDBL_MAX +-$DBL_MAX +-$FLT_MAX +-$FLT_MIN +-$DBL_MIN +-$LDBL_MIN +0 +$LDBL_MIN +$DBL_MIN +$FLT_MIN +$FLT_MAX +$DBL_MAX +$LDBL_MAX +" | + grep '^[0-9.,e+-]*$' > exp # restrict to numeric just in case + + tac exp | LC_ALL=$LOC sort -sg > out || fail=1 + + compare exp out || fail=1 +done + +Exit $fail diff --git a/tests/misc/sort-h-thousands-sep.sh b/tests/misc/sort-h-thousands-sep.sh new file mode 100755 index 0000000..6139145 --- /dev/null +++ b/tests/misc/sort-h-thousands-sep.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# exercise 'sort -h' in locales where thousands separator is blank + +# Copyright (C) 2016-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +TEST_LOCALE='sv_SE' + +test "$(LC_ALL="$TEST_LOCALE" locale thousands_sep)" = ' ' || + skip_ 'The Swedish locale with blank thousands separator is unavailable.' + +tee exp1 exp3 > in << _EOF_ +1 1k 1 M 4 003 1M +2k 2M 2 k 4 002 2 +3M 3 3 G 4 001 3k +_EOF_ + +cat > exp2 << _EOF_ +3M 3 3 G 4 001 3k +1 1k 1 M 4 003 1M +2k 2M 2 k 4 002 2 +_EOF_ + +cat > exp5 << _EOF_ +3M 3 3 G 4 001 3k +2k 2M 2 k 4 002 2 +1 1k 1 M 4 003 1M +_EOF_ + +for i in 1 2 3 5; do + LC_ALL="$TEST_LOCALE" sort -h -k $i "in" > "out${i}" || fail=1 + compare "exp${i}" "out${i}" || fail=1 +done + +Exit $fail diff --git a/tests/misc/sort-merge-fdlimit.sh b/tests/misc/sort-merge-fdlimit.sh new file mode 100755 index 0000000..869a616 --- /dev/null +++ b/tests/misc/sort-merge-fdlimit.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# Test whether sort avoids opening more file descriptors than it is +# allowed when merging files. + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +mkdir in err || framework_failure_ + + +for i in $(seq 17); do + echo $i >in/$i +done +seq 17 >some-data + +# When these tests are run inside the automated testing framework, they +# have one less available file descriptor than when run outside the +# automated testing framework. If a test with a batch size of b fails +# inside the ATF, then the same test with batch size b+1 may pass outside +# the ATF but fail inside it. + +# The default batch size (nmerge) is 16. +(ulimit -n 19 \ + && sort -m --batch-size=16 in/* 2>err/merge-default-err \ + || ! grep "open failed" err/merge-default-err) || fail=1 + +# If sort opens a file to sort by random hashes of keys, +# it needs to consider this file against its limit on open file +# descriptors. Test once with the default random source +# and once with an explicit source. +for randsource in '' --random-source=some-data; do + (ulimit -n 20 \ + && sort -mR $randsource --batch-size=16 in/* 2>err/merge-random-err \ + || ! grep "open failed" err/merge-random-err) || fail=1 +done + +# 'sort -m' should work in a limited file descriptor +# environment when the output is repeatedly one of its inputs. +# In coreutils 8.7 and earlier, 'sort' would dump core on this test. +# +# This test uses 'exec' to redirect file descriptors rather than +# ordinary redirection on the 'sort' command. This is intended to +# work around bugs in OpenBSD /bin/sh, and some other sh variants, +# that squirrel away file descriptors before closing them; see +# <https://lists.gnu.org/r/bug-tar/2010-10/msg00075.html>. +# This test finds the bug only with shells that do not close FDs on +# exec, and will miss the bug (if present) on other shells, but it's +# not easy to fix this without running afoul of the OpenBSD-like sh bugs. +(seq 6 && echo 6) >exp || framework_failure_ +echo 6 >out || framework_failure_ +(exec 3<&- 4<&- 5<&- 6</dev/null 7<&6 8<&6 9<&6 && + ulimit -n 10 && + sort -n -m --batch-size=7 -o out out in/1 in/2 in/3 in/4 in/5 out +) && +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/sort-merge.pl b/tests/misc/sort-merge.pl new file mode 100755 index 0000000..7eb4574 --- /dev/null +++ b/tests/misc/sort-merge.pl @@ -0,0 +1,84 @@ +#!/usr/bin/perl +# Test "sort -m". + +# Copyright (C) 2002-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $limits = getlimits (); + +(my $program_name = $0) =~ s|.*/||; +my $prog = 'sort'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# three empty files and one that says 'foo' +my @inputs = (+(map{{IN=> {"empty$_"=> ''}}}1..3), {IN=> {foo=> "foo\n"}}); + +my $big_input = "aaa\n" x 1024; + +# don't need to check for existence, since we're running in a temp dir +my $badtmp = 'does/not/exist'; + +my $bigint = $limits->{UINTMAX_OFLOW}; + +my @Tests = + ( + ['m1', '-m', @inputs, {OUT=>"foo\n"}], + + # check validation of --batch-size option + ['nmerge-0', "-m --batch-size=0", @inputs, + {ERR=>"$prog: invalid --batch-size argument '0'\n". + "$prog: minimum --batch-size argument is '2'\n"}, {EXIT=>2}], + + ['nmerge-1', "-m --batch-size=1", @inputs, + {ERR=>"$prog: invalid --batch-size argument '1'\n". + "$prog: minimum --batch-size argument is '2'\n"}, {EXIT=>2}], + + ['nmerge-neg', "-m --batch-size=-1", @inputs, + {ERR=>"$prog: invalid --batch-size argument '-1'\n"}, {EXIT=>2}], + + ['nmerge-nan', "-m --batch-size=a", @inputs, + {ERR=>"$prog: invalid --batch-size argument 'a'\n"}, {EXIT=>2}], + + ['nmerge-big', "-m --batch-size=$bigint", @inputs, + {ERR_SUBST=>'s/(current rlimit is) \d+/$1/'}, + {ERR=>"$prog: --batch-size argument '$bigint' too large\n". + "$prog: maximum --batch-size argument with current rlimit is\n"}, + {EXIT=>2}], + + # This should work since nmerge >= the number of input files + ['nmerge-yes', "-m --batch-size=4 -T$badtmp", @inputs, {OUT=>"foo\n"}], + + # this should fail since nmerge < # of input files, so + # temp files are needed + ['nmerge-no', "-m --batch-size=2 -T$badtmp", @inputs, + {ERR_SUBST=>"s|': .*|':|"}, + {ERR=>"$prog: cannot create temporary file in '$badtmp':\n"}, + {EXIT=>2}], + + # This used to fail because setting batch-size without also setting + # buffer size would cause the buffer size to be set to the minimum. + ['batch-size', "--batch-size=16 -T$badtmp", {IN=> {big=> $big_input}}, + {OUT=>$big_input}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/sort-month.sh b/tests/misc/sort-month.sh new file mode 100755 index 0000000..e91cb64 --- /dev/null +++ b/tests/misc/sort-month.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Test sorting of abbreviated months from the locale + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +locale --version >/dev/null 2>&1 || + skip_ 'The locale utility is not present' + +# C will be used if the locale is not present +for LOC in "$LOCALE_FR" "$LOCALE_FR_UTF8" "ja_JP.utf8"; do + mon="$(LC_ALL=$LOC locale abmon 2>/dev/null);" + smon=$(LC_ALL=$LOC locale abmon 2>/dev/null | + tr ';' '\n' | shuf | nl | LC_ALL=$LOC sort -k2,2M | + cut -f2 | tr '\n' ';') + test "$mon" = "$smon" || { fail=1; break; } +done + +Exit $fail diff --git a/tests/misc/sort-rand.sh b/tests/misc/sort-rand.sh new file mode 100755 index 0000000..6772c6c --- /dev/null +++ b/tests/misc/sort-rand.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# Ensure that sort --sort-random doesn't sort. + +# Copyright (C) 2005-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +seq 100 > in || framework_failure_ + + +sort --random-sort in > out || fail=1 + +# Fail if the input is the same as the output. +# This is a probabilistic test :-) +# However, the odds of failure are very low: 1 in 100! (~ 1 in 10^158) +compare in out > /dev/null && { fail=1; echo "not random?" 1>&2; } + +# Fail if the sorted output is not the same as the input. +sort -n out > out1 +compare in out1 || { fail=1; echo "not a permutation" 1>&2; } + +# If locale is available then use it to find a random non-C locale. +if (locale --version) > /dev/null 2>&1; then + locale=$(locale -a | sort --random-sort | $AWK '/^.._/{print;exit}') + LC_ALL=$locale sort --random-sort in > out1 || fail=1 + LC_ALL=$locale sort --random-sort in > out2 || fail=1 + + # Fail if the output "randomly" is the same twice in a row. + compare out1 out2 > /dev/null && + { fail=1; echo "not random with LC_ALL=$locale" 1>&2; } + + # Fail if the sorted output is not the same as the input. + sort -n out > out1 + compare in out1 || + { fail=1; echo "not a permutation with LC_ALL=$locale" 1>&2; } +fi + +Exit $fail diff --git a/tests/misc/sort-spinlock-abuse.sh b/tests/misc/sort-spinlock-abuse.sh new file mode 100755 index 0000000..5be46b6 --- /dev/null +++ b/tests/misc/sort-spinlock-abuse.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# trigger a bug that would make parallel sort use 100% of one or more +# CPU while blocked on output. + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +# This isn't terribly expensive, but it must not be run under heavy load. +# Since the "very expensive" tests are already run only with -j1, adding +# this test to the list ensures it still gets _some_ (albeit minimal) +# coverage while not causing false-positive failures in day to day runs. +very_expensive_ + +grep '^#define HAVE_PTHREAD_T 1' "$CONFIG_HEADER" > /dev/null || + skip_ 'requires pthreads' + +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +seq 100000 > in || framework_failure_ +mkfifo_or_skip_ fifo + +# Arrange for sort to require 8.0+ seconds of wall-clock time, +# while actually using far less than 1 second of CPU time. +(for i in $(seq 80); do read line; echo $i; sleep .1; done + cat > /dev/null) < fifo & pid=$! + +# However, under heavy load, it can easily take more than +# one second of CPU time, so set a permissive limit: +ulimit -t 7 +sort --parallel=2 in > fifo || fail=1 + +Exit $fail diff --git a/tests/misc/sort-stale-thread-mem.sh b/tests/misc/sort-stale-thread-mem.sh new file mode 100755 index 0000000..3c28589 --- /dev/null +++ b/tests/misc/sort-stale-thread-mem.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# Trigger a bug that would cause 'sort' to reference stale thread stack memory. + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +# written by Jim Meyering and Paul Eggert + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +very_expensive_ +require_valgrind_ + +grep '^#define HAVE_PTHREAD_T 1' "$CONFIG_HEADER" > /dev/null || + skip_ 'requires pthreads' + +# gensort output seems to trigger the failure more often, +# so prefer gensort if it is available. +(gensort -a 10000 in) 2>/dev/null || + seq -f %-98f 10000 | shuf > in || + framework_failure_ + +# On Fedora-17-beta (valgrind-3.7.0-2.fc17.x86_64), this evokes two +# "Conditional jump or move depends on uninitialised value(s)" errors, +# each originating from _dl_start. +valgrind --quiet --error-exitcode=3 sort --version > /dev/null || + framework_failure_ 'valgrind fails for trivial sort invocation' + +# With the bug, 'sort' would fail under valgrind about half the time, +# on some circa-2010 multicore Linux platforms. Run the test 100 times +# so that the probability of missing the bug should be about 1 in +# 2**100 on these hosts. +for i in $(seq 100); do + valgrind --quiet --error-exitcode=3 \ + sort -S 100K --parallel=2 in > /dev/null || + { fail=$?; echo iteration $i failed; Exit $fail; } +done + +Exit $fail diff --git a/tests/misc/sort-u-FMR.sh b/tests/misc/sort-u-FMR.sh new file mode 100755 index 0000000..3b4f939 --- /dev/null +++ b/tests/misc/sort-u-FMR.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# Before 8.19, this would trigger a free-memory read. + +# Copyright (C) 2012-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort +require_valgrind_ + +{ echo 0; printf '%0900d\n' 1; } > in || framework_failure_ + +valgrind --error-exitcode=1 sort --p=1 -S32b -u in > out || fail=1 + +compare in out || fail=1 + +Exit $fail diff --git a/tests/misc/sort-unique-segv.sh b/tests/misc/sort-unique-segv.sh new file mode 100755 index 0000000..e4a86f9 --- /dev/null +++ b/tests/misc/sort-unique-segv.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# parallel sort with --unique (-u) would segfault + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +grep '^#define HAVE_PTHREAD_T 1' "$CONFIG_HEADER" > /dev/null || + skip_ 'requires pthreads' + +cat <<\EOF > in || framework_failure_ + + + + + + + +z +zzzzzz +zzzzzzz +zzzzzzz +zzzzzzz +zzzzzzzzz +zzzzzzzzzzz +zzzzzzzzzzzz +EOF + +sort --parallel=1 -u in > exp || fail=1 + +sort --parallel=2 -u -S 10b < in > out || fail=1 +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/sort-unique.sh b/tests/misc/sort-unique.sh new file mode 100755 index 0000000..f54cad0 --- /dev/null +++ b/tests/misc/sort-unique.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# Test 'sort -u'. + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +cat > in <<\EOF +1 +2 +1 +3 +EOF + +cat > exp <<\EOF +1 +2 +3 +EOF + +for LOC in C "$LOCALE_FR" "$LOCALE_FR_UTF8"; do + test -z "$LOC" && continue + + LC_ALL=$LOC sort -u in > out || { fail=1; break; } + compare exp out || { fail=1; break; } +done + +Exit $fail diff --git a/tests/misc/sort-version.sh b/tests/misc/sort-version.sh new file mode 100755 index 0000000..10ea6a5 --- /dev/null +++ b/tests/misc/sort-version.sh @@ -0,0 +1,114 @@ +#!/bin/sh +# exercise sort's --sort=version option + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sort + +cat > in << _EOF_ +gcc-c++-10.fc9.tar.gz +gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2 +glibc-2-0.1.beta1.fc10.rpm +glibc-common-5-0.2.beta2.fc9.ebuild +glibc-common-5-0.2b.deb +glibc-common-11b.ebuild +glibc-common-11-0.6rc2.ebuild +libstdc++-0.5.8.11-0.7rc2.fc10.tar.gz +libstdc++-4a.fc8.tar.gz +libstdc++-4.10.4.20040204svn.rpm +libstdc++-devel-3.fc8.ebuild +libstdc++-devel-3a.fc9.tar.gz +libstdc++-devel-8.fc8.deb +libstdc++-devel-8.6.2-0.4b.fc8 +nss_ldap-1-0.2b.fc9.tar.bz2 +nss_ldap-1-0.6rc2.fc8.tar.gz +nss_ldap-1.0-0.1a.tar.gz +nss_ldap-10beta1.fc8.tar.gz +nss_ldap-10.11.8.6.20040204cvs.fc10.ebuild +string start 5.0.0 end of str +string start 5.1.0 end of str +string start 5.10.0 end of str +string start 5.2.0 end of str +string start 5.20.0 end of str +string start 5.3.0 end of str +string start 5.30.0 end of str +string start 5.4.0 end of str +string start 5.40.0 end of str +string start 5.5.0 end of str +string start 5.50.0 end of str +string start 5.6.0 end of str +string start 5.60.0 end of str +string start 5.7.0 end of str +string start 5.70.0 end of str +string start 5.8.0 end of str +string start 5.80.0 end of str +string start 5.9.0 end of str +string start 5.90.0 end of str +string start 5.04.0 end of str +_EOF_ + +cat > exp << _EOF_ +gcc-c++-10.fc9.tar.gz +gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2 +glibc-2-0.1.beta1.fc10.rpm +glibc-common-5-0.2.beta2.fc9.ebuild +glibc-common-5-0.2b.deb +glibc-common-11b.ebuild +glibc-common-11-0.6rc2.ebuild +libstdc++-0.5.8.11-0.7rc2.fc10.tar.gz +libstdc++-4a.fc8.tar.gz +libstdc++-4.10.4.20040204svn.rpm +libstdc++-devel-3.fc8.ebuild +libstdc++-devel-3a.fc9.tar.gz +libstdc++-devel-8.fc8.deb +libstdc++-devel-8.6.2-0.4b.fc8 +nss_ldap-1-0.2b.fc9.tar.bz2 +nss_ldap-1-0.6rc2.fc8.tar.gz +nss_ldap-1.0-0.1a.tar.gz +nss_ldap-10beta1.fc8.tar.gz +nss_ldap-10.11.8.6.20040204cvs.fc10.ebuild +string start 5.0.0 end of str +string start 5.1.0 end of str +string start 5.2.0 end of str +string start 5.3.0 end of str +string start 5.4.0 end of str +string start 5.04.0 end of str +string start 5.5.0 end of str +string start 5.6.0 end of str +string start 5.7.0 end of str +string start 5.8.0 end of str +string start 5.9.0 end of str +string start 5.10.0 end of str +string start 5.20.0 end of str +string start 5.30.0 end of str +string start 5.40.0 end of str +string start 5.50.0 end of str +string start 5.60.0 end of str +string start 5.70.0 end of str +string start 5.80.0 end of str +string start 5.90.0 end of str +_EOF_ + +sort --stable --sort=version -o out in || fail=1 +compare exp out || fail=1 + +tr ' ' '\0' <in >in0 || framework_failure_ +sort --stable --sort=version -o out0 in0 || fail=1 +tr '\0' ' ' <out0 >out1 || framework_failure_ +compare exp out1 || fail=1 + +Exit $fail diff --git a/tests/misc/sort.pl b/tests/misc/sort.pl new file mode 100755 index 0000000..0b0adca --- /dev/null +++ b/tests/misc/sort.pl @@ -0,0 +1,440 @@ +#!/usr/bin/perl + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $limits = getlimits (); + +my $prog = 'sort'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $mb_locale = $ENV{LOCALE_FR_UTF8}; +! defined $mb_locale || $mb_locale eq 'none' + and $mb_locale = 'C'; + +# Since each test is run with a file name and with redirected stdin, +# the name in the diagnostic is either the file name or "-". +# Normalize each diagnostic to use '-'. +my $normalize_filename = {ERR_SUBST => 's/^$prog: .*?:/$prog: -:/'}; + +my $no_file = "$prog: cannot read: no-file: No such file or directory\n"; + +my @Tests = +( +["n1", '-n', {IN=>".01\n0\n"}, {OUT=>"0\n.01\n"}], +["n2", '-n', {IN=>".02\n.01\n"}, {OUT=>".01\n.02\n"}], +["n3", '-n', {IN=>".02\n.00\n"}, {OUT=>".00\n.02\n"}], +["n4", '-n', {IN=>".02\n.000\n"}, {OUT=>".000\n.02\n"}], +["n5", '-n', {IN=>".021\n.029\n"}, {OUT=>".021\n.029\n"}], + +["n6", '-n', {IN=>".02\n.0*\n"}, {OUT=>".0*\n.02\n"}], +["n7", '-n', {IN=>".02\n.*\n"}, {OUT=>".*\n.02\n"}], +["n8a", '-s -n -k1,1', {IN=>".0a\n.0b\n"}, {OUT=>".0a\n.0b\n"}], +["n8b", '-s -n -k1,1', {IN=>".0b\n.0a\n"}, {OUT=>".0b\n.0a\n"}], +["n9a", '-s -n -k1,1', {IN=>".000a\n.000b\n"}, {OUT=>".000a\n.000b\n"}], +["n9b", '-s -n -k1,1', {IN=>".000b\n.000a\n"}, {OUT=>".000b\n.000a\n"}], +["n10a", '-s -n -k1,1', {IN=>".00a\n.000b\n"}, {OUT=>".00a\n.000b\n"}], +["n10b", '-s -n -k1,1', {IN=>".00b\n.000a\n"}, {OUT=>".00b\n.000a\n"}], +["n11a", '-s -n -k1,1', {IN=>".01a\n.010\n"}, {OUT=>".01a\n.010\n"}], +["n11b", '-s -n -k1,1', {IN=>".010\n.01a\n"}, {OUT=>".010\n.01a\n"}], + +# human readable suffixes +["h1", '-h', + {IN=>"1Y\n1Z\n1E\n1P\n1T\n1G\n1M\n1K\n02\n1\nY\n-1k\n-1M\n-1G\n-1T\n" + . "-1P\n-1E\n-1Z\n-1Y\n"}, + {OUT=>"-1Y\n-1Z\n-1E\n-1P\n-1T\n-1G\n-1M\n-1k\nY\n1\n02\n1K\n1M\n1G\n1T\n" + . "1P\n1E\n1Z\n1Y\n"}], +["h2", '-h', {IN=>"1M\n-2G\n-3K"}, {OUT=>"-2G\n-3K\n1M\n"}], +# check that it works with powers of 1024 +["h3", '-k 2,2h -k 1,1', {IN=>"a 1G\nb 1023M\n"}, {OUT=>"b 1023M\na 1G\n"}], +# decimal at end => allowed +["h4", '-h', {IN=>"1.E\n2.M\n"}, {OUT=>"2.M\n1.E\n"}], +# double decimal => ignore suffix +["h5", '-h', {IN=>"1..2E\n2..2M\n"}, {OUT=>"1..2E\n2..2M\n"}], +# "M" sorts before "G" regardless of the positive number attached. +["h6", '-h', {IN=>"1GiB\n1030MiB\n"}, {OUT=>"1030MiB\n1GiB\n"}], +# check option incompatibility +["h7", '-hn', {IN=>""}, {OUT=>""}, {EXIT=>2}, + {ERR=>"$prog: options '-hn' are incompatible\n"}], +# check key processing +["h8", '-n -k2,2h', {IN=>"1 1E\n2 2M\n"}, {OUT=>"2 2M\n1 1E\n"}], +# SI and IEC prefixes on separate keys allowed +["h9", '-h -k1,1 -k2,2', {IN=>"1M 1Mi\n1M 1Mi\n"}, {OUT=>"1M 1Mi\n1M 1Mi\n"}], +# This invalid SI and IEC prefix mixture is not significant so not noticed +["h10", '-h -k1,1 -k2,2', {IN=>"1M 2M\n2M 1Mi\n"}, {OUT=>"1M 2M\n2M 1Mi\n"}], + +["01a", '', {IN=>"A\nB\nC\n"}, {OUT=>"A\nB\nC\n"}], +# +["02a", '-c', {IN=>"A\nB\nC\n"}, {OUT=>''}], +["02b", '-c', {IN=>"A\nC\nB\n"}, {OUT=>''}, {EXIT=>1}, + {ERR=>"$prog: -:3: disorder: B\n"}, $normalize_filename], +["02c", '-c -k1,1', {IN=>"a\na b\n"}, {OUT=>''}], +["02d", '-C', {IN=>"A\nB\nC\n"}, {OUT=>''}], +["02e", '-C', {IN=>"A\nC\nB\n"}, {OUT=>''}, {EXIT=>1}], +# This should fail because there are duplicate keys +["02m", '-cu', {IN=>"A\nA\n"}, {OUT=>''}, {EXIT=>1}, + {ERR=>"$prog: -:2: disorder: A\n"}, $normalize_filename], +["02n", '-cu', {IN=>"A\nB\n"}, {OUT=>''}], +["02o", '-cu', {IN=>"A\nB\nB\n"}, {OUT=>''}, {EXIT=>1}, + {ERR=>"$prog: -:3: disorder: B\n"}, $normalize_filename], +["02p", '-cu', {IN=>"B\nA\nB\n"}, {OUT=>''}, {EXIT=>1}, + {ERR=>"$prog: -:2: disorder: A\n"}, $normalize_filename], +["02q", '-c -k 1,1fR', {IN=>"ABC\nABc\nAbC\nAbc\naBC\naBc\nabC\nabc\n"}], +["02r", '-c -k 1,1fV', {IN=>"ABC\nABc\nAbC\nAbc\naBC\naBc\nabC\nabc\n"}], +["02s", '-c -k 1,1dfR', + {IN=>".ABC\n.ABc.\nA.bC\nA.bc.\naB.C\naB.c.\nabC.\nabc..\n"}], +# +["03a", '-k1', {IN=>"B\nA\n"}, {OUT=>"A\nB\n"}], +["03b", '-k1,1', {IN=>"B\nA\n"}, {OUT=>"A\nB\n"}], +["03c", '-k1 -k2', {IN=>"A b\nA a\n"}, {OUT=>"A a\nA b\n"}], +# Fail with a diagnostic when -k specifies field == 0. +["03d", '-k0', {EXIT=>2}, + {ERR=>"$prog: -: invalid field specification '0'\n"}, + $normalize_filename], +# Fail with a diagnostic when -k specifies character == 0. +["03e", '-k1.0', {EXIT=>2}, + {ERR=>"$prog: character offset is zero: invalid field specification '1.0'\n"}], +["03f", '-k1.1,-k0', {EXIT=>2}, + {ERR=>"$prog: invalid number after ',': invalid count at start of '-k0'\n"}], +# This is ok. +["03g", '-k1.1,1.0', {IN=>''}], +# This is equivalent to 3f. +["03h", '-k1.1,1', {IN=>''}], +# This too, is equivalent to 3f. +["03i", '-k1,1', {IN=>''}], +# +["04a", '-nc', {IN=>"2\n11\n"}], +["04b", '-n', {IN=>"11\n2\n"}, {OUT=>"2\n11\n"}], +["04c", '-k1n', {IN=>"11\n2\n"}, {OUT=>"2\n11\n"}], +["04d", '-k1', {IN=>"11\n2\n"}, {OUT=>"11\n2\n"}], +["04e", '-k2', {IN=>"ignored B\nz-ig A\n"}, {OUT=>"z-ig A\nignored B\n"}], +# +["05a", '-k1,2', {IN=>"A B\nA A\n"}, {OUT=>"A A\nA B\n"}], +["05b", '-k1,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}], +["05c", '-k1 -k2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}], +["05d", '-k2,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}], +["05e", '-k2,2', {IN=>"A B Z\nA A A\n"}, {OUT=>"A A A\nA B Z\n"}], +["05f", '-k2,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}], +# +["06a", '-k 1,2', {IN=>"A B\nA A\n"}, {OUT=>"A A\nA B\n"}], +["06b", '-k 1,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}], +["06c", '-k 1 -k 2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}], +["06d", '-k 2,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}], +["06e", '-k 2,2', {IN=>"A B Z\nA A A\n"}, {OUT=>"A A A\nA B Z\n"}], +["06f", '-k 2,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}], +# +["07a", '-k 2,3', {IN=>"9 a b\n7 a a\n"}, {OUT=>"7 a a\n9 a b\n"}], +["07b", '-k 2,3', {IN=>"a a b\nz a a\n"}, {OUT=>"z a a\na a b\n"}], +["07c", '-k 2,3', {IN=>"y k b\nz k a\n"}, {OUT=>"z k a\ny k b\n"}], +["07d", '+1 -3', {IN=>"y k b\nz k a\n"}, {OUT=>"z k a\ny k b\n"}], +# ensure a character position of 0 includes whole field +["07e", '-k 2,3.0', {IN=>"a a b\nz a a\n"}, {OUT=>"z a a\na a b\n"}], +# ensure fields with end position before start are ignored +["07f", '-n -k1.3,1.1', {IN=>"a 2\nb 1\n"}, {OUT=>"a 2\nb 1\n"}], +["07g", '-n -k2.2,1.2', {IN=>"aa 2\nbb 1\n"}, {OUT=>"aa 2\nbb 1\n"}], +["07h", '-k1.3nb,1.3', {IN=>" a 2\n b 1\n"}, {OUT=>" a 2\n b 1\n"}], +# ensure obsolescent key limits are handled correctly +["07i", '-s +0 -1', {IN=>"a c\na b\n"}, {OUT=>"a c\na b\n"}], +["07j", '-s +0 -1.0', {IN=>"a c\na b\n"}, {OUT=>"a c\na b\n"}], +["07k", '-s +0 -1.1', {IN=>"a c\na b\n"}, {OUT=>"a c\na b\n"}], +["07l", '-s +0 -1.2', {IN=>"a c\na b\n"}, {OUT=>"a b\na c\n"}], +["07m", '-s +0 -1.1b', {IN=>"a c\na b\n"}, {OUT=>"a b\na c\n"}], +# +# report an error for '.' without following char spec +["08a", '-k 2.,3', {EXIT=>2}, + {ERR=>"$prog: invalid number after '.': invalid count at start of ',3'\n"}], +# report an error for ',' without following POS2 +["08b", '-k 2,', {EXIT=>2}, + {ERR=>"$prog: invalid number after ',': invalid count at start of ''\n"}], +# +# Test new -g option. +["09a", '-g', {IN=>"1e2\n2e1\n"}, {OUT=>"2e1\n1e2\n"}], +# Make sure -n works how we expect. +["09b", '-n', {IN=>"1e2\n2e1\n"}, {OUT=>"1e2\n2e1\n"}], +["09c", '-n', {IN=>"2e1\n1e2\n"}, {OUT=>"1e2\n2e1\n"}], +["09d", '-k2g', {IN=>"a 1e2\nb 2e1\n"}, {OUT=>"b 2e1\na 1e2\n"}], +# +# Bug reported by Roger Peel <R.Peel@ee.surrey.ac.uk> +["10a", '-t : -k 2.2,2.2', {IN=>":ba\n:ab\n"}, {OUT=>":ba\n:ab\n"}], +# Equivalent to above, but using obsolescent '+pos -pos' option syntax. +["10b", '-t : +1.1 -1.2', {IN=>":ba\n:ab\n"}, {OUT=>":ba\n:ab\n"}], +# +# The same as the preceding two, but with input lines reversed. +["10c", '-t : -k 2.2,2.2', {IN=>":ab\n:ba\n"}, {OUT=>":ba\n:ab\n"}], +# Equivalent to above, but using obsolescent '+pos -pos' option syntax. +["10d", '-t : +1.1 -1.2', {IN=>":ab\n:ba\n"}, {OUT=>":ba\n:ab\n"}], +# Try without -t... +# But note that we have to count the delimiting space at the beginning +# of each field that has it. +["10a0", '-k 2.3,2.3', {IN=>"z ba\nz ab\n"}, {OUT=>"z ba\nz ab\n"}], +["10a1", '-k 1.2,1.2', {IN=>"ba\nab\n"}, {OUT=>"ba\nab\n"}], +["10a2", '-b -k 2.2,2.2', {IN=>"z ba\nz ab\n"}, {OUT=>"z ba\nz ab\n"}], +# +# An even simpler example demonstrating the bug. +["10e", '-k 1.2,1.2', {IN=>"ab\nba\n"}, {OUT=>"ba\nab\n"}], +# +# The way sort works on these inputs (10f and 10g) seems wrong to me. +# See https://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=3c467c0d223 +# POSIX doesn't seem to say one way or the other, but that's the way all +# other sort implementations work. +["10f", '-t : -k 1.3,1.3', {IN=>":ab\n:ba\n"}, {OUT=>":ba\n:ab\n"}], +["10g", '-k 1.4,1.4', {IN=>"a ab\nb ba\n"}, {OUT=>"b ba\na ab\n"}], +# +# Exercise bug re using -b to skip trailing blanks. +["11a", '-t: -k1,1b -k2,2', {IN=>"a\t:a\na :b\n"}, {OUT=>"a\t:a\na :b\n"}], +["11b", '-t: -k1,1b -k2,2', {IN=>"a :b\na\t:a\n"}, {OUT=>"a\t:a\na :b\n"}], +["11c", '-t: -k2,2b -k3,3', {IN=>"z:a\t:a\na :b\n"}, {OUT=>"z:a\t:a\na :b\n"}], +# Before 1.22m, the first key comparison reported equality. +# With 1.22m, they compare different: "a" sorts before "a\n", +# and the second key spec isn't even used. +["11d", '-t: -k2,2b -k3,3', {IN=>"z:a :b\na\t:a\n"}, {OUT=>"a\t:a\nz:a :b\n"}], +# +# Exercise bug re comparing '-' and integers. +["12a", '-n -t: +1', {IN=>"a:1\nb:-\n"}, {OUT=>"b:-\na:1\n"}], +["12b", '-n -t: +1', {IN=>"b:-\na:1\n"}, {OUT=>"b:-\na:1\n"}], +# Try some other (e.g. 'X') invalid character. +["12c", '-n -t: +1', {IN=>"a:1\nb:X\n"}, {OUT=>"b:X\na:1\n"}], +["12d", '-n -t: +1', {IN=>"b:X\na:1\n"}, {OUT=>"b:X\na:1\n"}], +# From Karl Heuer +["13a", '+0.1n', {IN=>"axx\nb-1\n"}, {OUT=>"b-1\naxx\n"}], +["13b", '+0.1n', {IN=>"b-1\naxx\n"}, {OUT=>"b-1\naxx\n"}], +# +# From Carl Johnson <carlj@cjlinux.home.org> +["14a", '-d -u', {IN=>"mal\nmal-\nmala\n"}, {OUT=>"mal\nmala\n"}], +# Be sure to fix the (translate && ignore) case in keycompare. +["14b", '-f -d -u', {IN=>"mal\nmal-\nmala\n"}, {OUT=>"mal\nmala\n"}], +# +# Experiment with -i. +["15a", '-i -u', {IN=>"a\na\1\n"}, {OUT=>"a\n"}], +["15b", '-i -u', {IN=>"a\n\1a\n"}, {OUT=>"a\n"}], +["15c", '-i -u', {IN=>"a\1\na\n"}, {OUT=>"a\1\n"}], +["15d", '-i -u', {IN=>"\1a\na\n"}, {OUT=>"\1a\n"}], +["15e", '-i -u', {IN=>"a\n\1\1\1\1\1a\1\1\1\1\n"}, {OUT=>"a\n"}], + +# This would fail (printing only the 7) for 8.6..8.18. +# Use --parallel=1 for reproducibility, and a small buffer size +# to let us trigger the problem with a smaller input. +["unique-1", '--p=1 -S32b -u', {IN=>"7\n"x11 . "1\n"}, {OUT=>"1\n7\n"}], +# Demonstrate that 8.19's key-spec-adjusting code is required. +# These are more finicky in that they are arch-dependent. +["unique-key-i686", '-u -k2,2 --p=1 -S32b', + {IN=>"a 7\n"x10 . "b 1\n"}, {OUT=>"b 1\na 7\n"}], +["unique-key-x86_64", '-u -k2,2 --p=1 -S32b', + {IN=>"a 7\n"x11 . "b 1\n"}, {OUT=>"b 1\na 7\n"}], +# Before 8.19, this would trigger a free-memory read. +["unique-free-mem-read", '-u --p=1 -S32b', + {IN=>"a\n"."b"x900 ."\n"}, + {OUT=>"a\n"."b"x900 ."\n"}], + +# From Erick Branderhorst -- fixed around 1.19e +["16a", '-f', + {IN=>"éminence\nüberhaupt\n's-Gravenhage\naëroclub\nAag\naagtappels\n"}, + {OUT=>"'s-Gravenhage\nAag\naagtappels\naëroclub\néminence\nüberhaupt\n"}], + +# This provokes a one-byte memory overrun of a malloc'd block for versions +# of sort from textutils-1.19p and before. +["17", '-c', {IN=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"}], + +# POSIX says -n no longer implies -b, so here we're comparing ' 9' and '10'. +["18a", '-k1.1,1.2n', {IN=>" 901\n100\n"}, {OUT=>" 901\n100\n"}], + +# Just like above, because the global '-b' has no effect on the +# key specifier when a key-specific option ('n' in this case) is used. +["18b", '-b -k1.1,1.2n', {IN=>" 901\n100\n"}, {OUT=>" 901\n100\n"}], + +# Here we're comparing ' 90' and '10', because the 'b' on the key-end specifier +# makes sort ignore leading blanks when determining that key's *end*. +["18c", '-k1.1,1.2nb', {IN=>" 901\n100\n"}, {OUT=>"100\n 901\n"}], + +# Here we're comparing '9' and '10', because the 'b' on the key-start specifier +# makes sort ignore leading blanks when determining that key's *start*. +["18d", '-k1.1b,1.2n', {IN=>" 901\n100\n"}, {OUT=>" 901\n100\n"}], + +# This compares '90' and '10', as it ignores leading blanks for both +# key start and key end. +["18e", '-nb -k1.1,1.2', {IN=>" 901\n100\n"}, {OUT=>"100\n 901\n"}], + +# When ignoring leading blanks for end position, ensure blanks from +# next field are not included in the sort. I.e., order should not change here. +["18f", '-k1,1b', {IN=>"a y\na z\n"}, {OUT=>"a y\na z\n"}], + +# When ignoring leading blanks for start position, ensure blanks from +# next field are not included in the sort. I.e., order should not change here. +# This was noticed as an issue on fedora 8 (only in multibyte locales). +["18g", '-k1b,1', {IN=>"a y\na z\n"}, {OUT=>"a y\na z\n"}, + {ENV => "LC_ALL=$mb_locale"}], + +# This looks odd, but works properly -- 2nd keyspec is never +# used because all lines are different. +["19a", '+0 +1nr', {IN=>"b 2\nb 1\nb 3\n"}, {OUT=>"b 1\nb 2\nb 3\n"}], + +# The test *intended* by the author of the above, but using the +# more-intuitive POSIX-style -k options. +["19b", '-k1,1 -k2nr', {IN=>"b 2\nb 1\nb 3\n"}, {OUT=>"b 3\nb 2\nb 1\n"}], + +# This test failed when sort-1.22 was compiled on a Next x86 system +# without optimization. Without optimization gcc uses the buggy version +# of memcmp in the Next C library. With optimization, gcc uses its +# (working) builtin version. Test case form William Lewis. +["20a", '', + {IN=>"_________U__free\n_________U__malloc\n_________U__abort\n" + . "_________U__memcpy\n_________U__memset\n" + . "_________U_dyld_stub_binding_helper\n_________U__malloc\n" + . "_________U___iob\n_________U__abort\n_________U__fprintf\n"}, + {OUT=>"_________U___iob\n_________U__abort\n_________U__abort\n" + . "_________U__fprintf\n_________U__free\n_________U__malloc\n" + . "_________U__malloc\n_________U__memcpy\n_________U__memset\n" + . "_________U_dyld_stub_binding_helper\n"}], + +# Demonstrate that folding changes the ordering of e.g. A, a, and _ +# because while they normally (in the C locale) collate like A, _, a, +# when using -f, 'a' is compared as if it were 'A'. +["21a", '', {IN=>"A\na\n_\n"}, {OUT=>"A\n_\na\n"}], +["21b", '-f', {IN=>"A\na\n_\n"}, {OUT=>"A\na\n_\n"}], +["21c", '-f', {IN=>"a\nA\n_\n"}, {OUT=>"A\na\n_\n"}], +["21d", '-f', {IN=>"_\na\nA\n"}, {OUT=>"A\na\n_\n"}], +["21e", '-f', {IN=>"a\n_\nA\n"}, {OUT=>"A\na\n_\n"}], +["21f", '-fs', {IN=>"A\na\n_\n"}, {OUT=>"A\na\n_\n"}], +["21g", '-fu', {IN=>"a\n_\n"}, {OUT=>"a\n_\n"}], + +# This test failed until 1.22f. From Zvi Har'El. +["22a", '-k 2,2fd -k 1,1r', {IN=>"3 b\n4 B\n"}, {OUT=>"4 B\n3 b\n"}], +["22b", '-k 2,2d -k 1,1r', {IN=>"3 b\n4 b\n"}, {OUT=>"4 b\n3 b\n"}], + +# This fails in Fedora 20, per Göran Uddeborg in: https://bugs.gnu.org/18540 +["23", '-s -k1,1 -t/', {IN=>"a b/x\na-b-c/x\n"}, {OUT=>"a b/x\na-b-c/x\n"}, + {ENV => "LC_ALL=$mb_locale"}], + +["no-file1", 'no-file', {EXIT=>2}, {ERR=>$no_file}], +# This test failed until 1.22f. Sort didn't give an error. +# From Will Edgington. +["o-no-file1", qw(-o no-file no-file), {EXIT=>2}, {ERR=>$no_file}], + +["create-empty", qw(-o no/such/file /dev/null), {EXIT=>2}, + {ERR=>"$prog: open failed: no/such/file: No such file or directory\n"}], + +# From Paul Eggert. This was fixed in textutils-1.22k. +["neg-nls", '-n', {IN=>"-1\n-9\n"}, {OUT=>"-9\n-1\n"}], + +# From Paul Eggert. This was fixed in textutils-1.22m. +# The bug was visible only when using the internationalized sorting code +# (i.e., not when configured with --disable-nls). +["nul-nls", '', {IN=>"\0b\n\0a\n"}, {OUT=>"\0a\n\0b\n"}], + +# Paul Eggert wrote: +# A previous version of POSIX incorrectly required that the newline +# at the end of the input line contributed to the sort, which would +# mean that an empty line should sort after a line starting with a tab +# (because \t precedes \n in the ASCII collating sequence). +# GNU 'sort' was altered to do this, but was changed back once it +# was discovered to be a POSIX bug (and the POSIX bug was fixed). +# Check that 'sort' conforms to the fixed POSIX, not to the buggy one. +["use-nl", '', {IN=>"\n\t\n"}, {OUT=>"\n\t\n"}], + +# Specifying two -o options should evoke a failure +["o2", qw(-o x -o y), {EXIT=>2}, + {ERR=>"foo\n"}, {ERR_SUBST => 's/^$prog: .*/foo/'}], + +# Specifying incompatible options should evoke a failure. +["incompat1", '-in', {EXIT=>2}, + {ERR=>"$prog: options '-in' are incompatible\n"}], +["incompat2", '-nR', {EXIT=>2}, + {ERR=>"$prog: options '-nR' are incompatible\n"}], +["incompat3", '-dfgiMnR', {EXIT=>2}, + {ERR=>"$prog: options '-dfgMnR' are incompatible\n"}], +["incompat4", qw(-c -o /dev/null), {EXIT=>2}, + {ERR=>"$prog: options '-co' are incompatible\n"}], +["incompat5", qw(-C -o /dev/null), {EXIT=>2}, + {ERR=>"$prog: options '-Co' are incompatible\n"}], +["incompat6", '-cC', {EXIT=>2}, + {ERR=>"$prog: options '-cC' are incompatible\n"}], +["incompat7", qw(--sort=random -n), {EXIT=>2}, + {ERR=>"$prog: options '-nR' are incompatible\n"}], + +# -t '\0' is accepted, as of coreutils-5.0.91 +['nul-tab', "-k2,2 -t '\\0'", + {IN=>"a\0z\01\nb\0y\02\n"}, {OUT=>"b\0y\02\na\0z\01\n"}], + +# fields > SIZE_MAX are silently interpreted as SIZE_MAX +["bigfield1", "-k $limits->{UINTMAX_OFLOW}", + {IN=>"2\n1\n"}, {OUT=>"1\n2\n"}], +["bigfield2", "-k $limits->{SIZE_OFLOW}", + {IN=>"2\n1\n"}, {OUT=>"1\n2\n"}], + +# Using an old-style key-specifying option like +1 with an invalid +# ordering-option character would cause sort to try to free an invalid +# (non-malloc'd) pointer. This bug affects coreutils-6.5 through 6.9. +['obs-inval', '+1x', {EXIT=>2}, + {ERR=>"foo\n"}, {ERR_SUBST => 's/^$prog: .*/foo/'}], + +# Exercise the code that enlarges the line buffer. +['realloc-buf', '-S1', {IN=>'a'x4000 ."\n"}, {OUT=>'a'x4000 ."\n"}], +['realloc-buf-2', '-S1', {IN=>'a'x5 ."\n"}, {OUT=>'a'x5 ."\n"}], + +["sort-numeric", '--sort=numeric', {IN=>".01\n0\n"}, {OUT=>"0\n.01\n"}], +["sort-gennum", '--sort=general-numeric', + {IN=>"1e2\n2e1\n"}, {OUT=>"2e1\n1e2\n"}], + +# -m with output file also used as an input file +# In coreutils-7.2, this caused a segfault. +# This test looks a little strange. Here's why: +# since we're using "-o f", standard output will be empty, hence OUT=>'' +# We still want to ensure that the output file, "f" has expected contents, +# hence the added CMP=> directive. +["output-is-input", '-m -o f', {IN=> {f=> "a\n"}}, {OUT=>''}, + {CMP=> ["a\n", {'f'=> undef}]} ], +["output-is-input-2", '-m -o f', {OUT=>''}, + {IN=> {f=> "a\n"}}, {IN=> {g=> "b\n"}}, {IN=> {h=> "c\n"}}, + {CMP=> ["a\nb\nc\n", {'f'=> undef}]} ], +["output-is-input-3", '-m -o f', {OUT=>''}, + {IN=> {g=> "a\n"}}, {IN=> {h=> "b\n"}}, {IN=> {f=> "c\n"}}, + {CMP=> ["a\nb\nc\n", {'f'=> undef}]} ], + +# --zero-terminated +['zero-1', '-z', {IN=>"2\0001\000"}, {OUT=>"1\0002\000"}], +['zero-2', '-z -k2,2', {IN=>"1\n2\0002\n1\000"}, {OUT=>"2\n1\0001\n2\000"}], +['zero-3', '-zb -k2,2', {IN=>"1\n\n2\0002\n1\0"}, {OUT=>"2\n1\0001\n\n2\0"}], +); + +# Add _POSIX2_VERSION=199209 to the environment of each test +# that uses an old-style option like +1. +foreach my $t (@Tests) + { + foreach my $e (@$t) + { + !ref $e && $e =~ /\+\d/ + and push (@$t, {ENV=>'_POSIX2_VERSION=199209'}), last; + } + } + +@Tests = triple_test \@Tests; + +# Remember that triple_test creates from each test with exactly one "IN" +# file two more tests (.p and .r suffix on name) corresponding to reading +# input from a file and from a pipe. The pipe-reading test would fail +# due to a race condition about 1 in 20 times. +# Remove the IN_PIPE version of the "output-is-input" test above. +# The others aren't susceptible because they have three inputs each. +@Tests = grep {$_->[0] ne 'output-is-input.p'} @Tests; + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/stat-birthtime.sh b/tests/misc/stat-birthtime.sh new file mode 100755 index 0000000..647ea67 --- /dev/null +++ b/tests/misc/stat-birthtime.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# ensure that stat attempts birthtime access + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stat + +# Whether birthtime is supported or not, it better not change even when +# [acm]time are modified. :) +touch a || fail=1 +btime=$(stat --format %W a) || fail=1 +atime=$(stat --format %X a) || fail=1 +mtime=$(stat --format %Y a) || fail=1 +ctime=$(stat --format %Z a) || fail=1 + +# Wait up to 2.17s for timestamps to change. +# ---------------------------------------- +# iterations file system resolution e.g. +# ---------------------------------------- +# 1 nano or micro second ext4 +# 4 1 second ext3 +# 5 2 second FAT +# ---------------------------------------- +check_timestamps_updated() +{ + local delay="$1" + sleep $delay + touch a || fail=1 + + test "x$btime" = x$(stat --format %W a) && + test "x$atime" != x$(stat --format %X a) && + test "x$mtime" != x$(stat --format %Y a) && + test "x$ctime" != x$(stat --format %Z a) +} +retry_delay_ check_timestamps_updated .07 5 || fail=1 + +Exit $fail diff --git a/tests/misc/stat-fmt.sh b/tests/misc/stat-fmt.sh new file mode 100755 index 0000000..7f557f2 --- /dev/null +++ b/tests/misc/stat-fmt.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# stat --format tests + +# Copyright (C) 2003-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stat + + +# ensure that stat properly handles a format string ending with % +for i in $(seq 50); do + fmt=$(printf "%${i}s" %) + out=$(stat --form="$fmt" .) + test "$out" = "$fmt" || fail=1 +done + + +# ensure QUOTING_STYLE is honored by %N +touch "'" || framework_failure_ +# Default since v8.25 +stat -c%N \' >> out || fail=1 +# Default before v8.25 +QUOTING_STYLE=locale stat -c%N \' >> out || fail=1 +cat <<\EOF >exp +"'" +'\'' +EOF +compare exp out || fail=1 + +# ensure %H and %L modifiers are handled +stat -c '%r %R %Hd,%Ld %Hr,%Lr' . > out || fail=1 +grep -F '?' out && fail=1 + +Exit $fail diff --git a/tests/misc/stat-hyphen.sh b/tests/misc/stat-hyphen.sh new file mode 100755 index 0000000..9520402 --- /dev/null +++ b/tests/misc/stat-hyphen.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# demonstrate that stat - works and stat -f - does not. + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stat + +printf -- '-\n' > exp || framework_failure_ +touch f || framework_failure_ + +stat --format=%n - < f > out || fail=1 +returns_ 1 stat -f - < f || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/stat-mount.sh b/tests/misc/stat-mount.sh new file mode 100755 index 0000000..2237a9d --- /dev/null +++ b/tests/misc/stat-mount.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# Test stat -c%m + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stat + +stat_mnt=$(stat -c%m .) || fail=1 +case "$stat_mnt" in + /*) ;; + *) fail=1;; +esac + +Exit $fail diff --git a/tests/misc/stat-nanoseconds.sh b/tests/misc/stat-nanoseconds.sh new file mode 100755 index 0000000..f64cb91 --- /dev/null +++ b/tests/misc/stat-nanoseconds.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# Exercise format strings involving %:X, %:Y, etc. + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +print_ver_ stat +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src + +# Set this to avoid problems with weird time zones. +TZ=UTC0 +export TZ + +# Use a timestamp near the Epoch to avoid trouble with leap seconds. +touch -d '1970-01-01 18:43:33.023456789' k || framework_failure_ + +ls --full-time | grep 18:43:33.023456789 \ + || skip_ this file system does not support sub-second timestamps + +test "$(stat -c %X k)" = 67413 || fail=1 +test "$(stat -c %.X k)" = 67413.023456789 || fail=1 +test "$(stat -c %.1X k)" = 67413.0 || fail=1 +test "$(stat -c %.3X k)" = 67413.023 || fail=1 +test "$(stat -c %.6X k)" = 67413.023456 || fail=1 +test "$(stat -c %.9X k)" = 67413.023456789 || fail=1 +test "$(stat -c %13.6X k)" = ' 67413.023456' || fail=1 +test "$(stat -c %013.6X k)" = 067413.023456 || fail=1 +test "$(stat -c %-13.6X k)" = '67413.023456 ' || fail=1 +test "$(stat -c %18.10X k)" = ' 67413.0234567890' || fail=1 +test "$(stat -c %I18.10X k)" = ' 67413.0234567890' || fail=1 +test "$(stat -c %018.10X k)" = 0067413.0234567890 || fail=1 +test "$(stat -c %-18.10X k)" = '67413.0234567890 ' || fail=1 + +Exit $fail diff --git a/tests/misc/stat-printf.pl b/tests/misc/stat-printf.pl new file mode 100755 index 0000000..32459b1 --- /dev/null +++ b/tests/misc/stat-printf.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl +# Test "stat --printf". + +# Copyright (C) 2005-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $ME = $0) =~ s|.*/||; +my $prog = 'stat'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + # test-name, [option, option, ...] {OUT=>"expected-output"} + # + ['nl', q!--printf='\n' .!, {OUT=>"\n"}], + ['no-nl', "--printf=%n .", {OUT=>"."}], + ['pct-and-esc', q!--printf='\0%n\0' .!, {OUT=>"\0.\0"}], + ['backslash', q!--printf='\\\\' .!, {OUT=>"\\"}], + ['nul', q!--printf='\0' .!, {OUT=>"\0"}], + # Don't bother testing \v, since Perl doesn't handle it. + ['bel-etc', q!--printf='\a\b\f\n\r\t' .!, {OUT=>"\a\b\f\n\r\t"}], + ['octal-1', q!--printf='\012\377' .!, {OUT=>"\012\377"}], + ['octal-2', q!--printf='.\012a\377b' .!, {OUT=>".\012a\377b"}], + ['hex-1', q!--printf='\x34\xf' .!, {OUT=>"\x34\xf"}], + ['hex-2', q!--printf='.\x18p\xfq' .!, {OUT=>".\x18p\x0fq"}], + ['hex-3', q!--printf='\x' .!, {OUT=>'x'}, + {ERR=>"$prog: warning: unrecognized escape '\\x'\n"}], + + # With --format, there *is* a trailing newline. + ['f-nl', "--format=%n .", {OUT=>".\n"}], + ['f-nl2', "--format=%n . .", {OUT=>".\n.\n"}], + + ['end-pct', "--printf=% .", {OUT=>"%"}], + ['pct-pct', "--printf=%% .", {OUT=>"%"}], + ['end-bs', "--printf='\\' .", {OUT=>'\\'}, + {ERR=>"$prog: warning: backslash at end of format\n"}], + + ['err-1', "--printf=%9% .", {EXIT => 1}, + {ERR=>"$prog: '%9%': invalid directive\n"}], + ['err-2', "--printf=%9 .", {EXIT => 1}, + {ERR=>"$prog: '%9': invalid directive\n"}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/stat-slash.sh b/tests/misc/stat-slash.sh new file mode 100755 index 0000000..51358ab --- /dev/null +++ b/tests/misc/stat-slash.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# demonstrate that stat handles trailing slashes correctly + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stat + +touch file || framework_failure_ +mkdir dir || framework_failure_ +ln -s file link1 || framework_failure_ +ln -s dir link2 || framework_failure_ + +cat <<EOF > exp || framework_failure_ +link1 +symbolic link +directory +directory +EOF + +# This failed on Solaris 9 for coreutils 8.0. +stat --format=%n link1 > out || fail=1 +returns_ 1 stat --format=%n link1/ >> out || fail=1 + +stat --format=%F link2 >> out || fail=1 +stat -L --format=%F link2 >> out || fail=1 +stat --format=%F link2/ >> out || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/stdbuf.sh b/tests/misc/stdbuf.sh new file mode 100755 index 0000000..6a21592 --- /dev/null +++ b/tests/misc/stdbuf.sh @@ -0,0 +1,125 @@ +#!/bin/sh +# Exercise stdbuf functionality + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stdbuf env + +getlimits_ + +# stdbuf fails when the absolute top build dir name contains e.g., +# space, TAB, NL +lf=' +' +case $abs_top_builddir in + *[\\\"\#\$\&\'\`$lf\ \ ]*) + skip_ "unsafe absolute build directory name: $abs_top_builddir";; +esac + +# Use a fifo rather than a pipe in the tests below +# so that the producer (uniq) will wait until the +# consumer (dd) opens the fifo therefore increasing +# the chance that dd will read the data from each +# write separately. +mkfifo_or_skip_ fifo + + +# Verify input parameter checking +stdbuf -o1 true || fail=1 # verify size syntax +stdbuf -oK true || fail=1 # verify size syntax +stdbuf -o0 true || fail=1 # verify unbuffered syntax +stdbuf -oL true || fail=1 # verify line buffered syntax + +# Capital 'L' required +# Internal error is a particular status +returns_ 125 stdbuf -ol true || fail=1 + +returns_ 125 stdbuf -o$SIZE_OFLOW true || fail=1 # size too large +returns_ 125 stdbuf -iL true || fail=1 # line buffering stdin disallowed +returns_ 125 stdbuf true || fail=1 # a buffering mode must be specified +stdbuf -i0 -o0 -e0 true || fail=1 #check all files +returns_ 126 env . && { returns_ 126 stdbuf -o1 . || fail=1; } # invalid command +returns_ 127 stdbuf -o1 no_such || fail=1 # no such command + +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +# Ensure line buffering stdout takes effect +stdbuf_linebuffer() +{ + local delay="$1" + + printf '1\n' > exp + > out || framework_failure_ + dd count=1 if=fifo > out 2> err & pid=$! + (printf '1\n'; sleep $delay; printf '2\n') | stdbuf -oL uniq > fifo + wait $pid + compare exp out +} + +retry_delay_ stdbuf_linebuffer .1 6 || fail=1 + +stdbuf_unbuffer() +{ + local delay="$1" + + # Ensure un buffering stdout takes effect + printf '1\n' > exp + > out || framework_failure_ + dd count=1 if=fifo > out 2> err & pid=$! + (printf '1\n'; sleep $delay; printf '2\n') | stdbuf -o0 uniq > fifo + wait $pid + compare exp out +} + +retry_delay_ stdbuf_unbuffer .1 6 || fail=1 + +# Ensure un buffering stdin takes effect +# The following works for me, but is racy. I.e., we're depending +# on dd to run and close the fifo before the second write by uniq. +# If we add a sleep, then we're just testing -oL + # printf '3\n' > exp + # dd count=1 if=fifo > /dev/null 2> err & + # printf '1\n\2\n3\n' | (stdbuf -i0 -oL uniq > fifo; cat) > out + # wait # for dd to complete + # compare exp out || fail=1 +# One could remove the need for dd (used to close the fifo to get uniq to quit +# early), if head -n1 read stdin char by char. Note uniq | head -c2 doesn't +# suffice due to the buffering implicit in the pipe. sed currently does read +# stdin char by char, so we can test with 'sed 1q'. However I'm wary about +# adding this dependency on a program outside of coreutils. + # printf '2\n' > exp + # printf '1\n2\n' | (stdbuf -i0 sed 1q >/dev/null; cat) > out + # compare exp out || fail=1 + +# Ensure block buffering stdout takes effect +# We don't currently test block buffering failures as +# this doesn't work on GLIBC-2.7 or GLIBC-2.9 at least. + # stdbuf_blockbuffer() + # { + # local delay="$1" + # + # printf '1\n2\n' > exp + # dd count=1 if=fifo > out 2> err & + # (printf '1\n'; sleep $delay; printf '2\n') | stdbuf -o4 uniq > fifo + # wait # for dd to complete + # compare exp out + # } + # + # retry_delay_ stdbuf_blockbuffer .1 6 || fail=1 + +Exit $fail diff --git a/tests/misc/stty-invalid.sh b/tests/misc/stty-invalid.sh new file mode 100755 index 0000000..58e5131 --- /dev/null +++ b/tests/misc/stty-invalid.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# Ensure that stty diagnoses invalid inputs, rather than silently misbehaving. + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stty +require_controlling_input_terminal_ +require_trap_signame_ + +trap '' TTOU # Ignore SIGTTOU + + +saved_state=$(stty -g) || fail=1 +stty $saved_state || fail=1 + +# Before coreutils-6.9.90, if stty were given an argument with 35 colons +# separating 36 hexadecimal strings, stty would fail to diagnose as invalid +# any number that was out of range as long as sscanf happened to +# overflow/wrap it back into the range of the corresponding type (either +# tcflag_t or cc_t). + +# For each of the following, with coreutils-6.9 and earlier, +# stty would fail to diagnose the error on at least Solaris 10. +hex_2_64=10000000000000000 +returns_ 1 stty $(echo $saved_state |sed 's/^[^:]*:/'$hex_2_64:/) \ + 2>/dev/null || fail=1 +returns_ 1 stty $(echo $saved_state |sed 's/:[0-9a-f]*$/:'$hex_2_64/) \ + 2>/dev/null || fail=1 + +# From coreutils 5.3.0 to 8.28, the following would crash +# due to incorrect argument handling. +if tty -s </dev/tty; then + returns_ 1 stty eol -F /dev/tty || fail=1 + returns_ 1 stty -F /dev/tty eol || fail=1 + returns_ 1 stty -F/dev/tty eol || fail=1 + returns_ 1 stty eol -F/dev/tty eol || fail=1 +fi + +# Just in case either of the above mistakenly succeeds (and changes +# the state of our tty), try to restore the initial state. +stty $saved_state || fail=1 + +Exit $fail diff --git a/tests/misc/stty-pairs.sh b/tests/misc/stty-pairs.sh new file mode 100755 index 0000000..cae750a --- /dev/null +++ b/tests/misc/stty-pairs.sh @@ -0,0 +1,65 @@ +#!/bin/sh +# Make sure stty can parse most of its options - in pairs [expensive]. + +# Copyright (C) 1998-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stty + +expensive_ + +# Make sure there's a tty on stdin. +require_controlling_input_terminal_ +require_trap_signame_ + +trap '' TTOU # Ignore SIGTTOU + +# Get the reversible settings from stty.c. +stty_reversible_init_ + +saved_state=.saved-state +stty --save > $saved_state || fail=1 +stty $(cat $saved_state) || fail=1 + +# Build a list of all boolean options stty accepts on this system. +# Don't depend on terminal width. Put each option on its own line, +# remove all non-boolean ones, remove 'parenb' and 'cread' explicitly, +# then remove any leading hyphens. +sed_del='/^speed/d;/^rows/d;/^columns/d;/ = /d;s/parenb//;s/cread//' +options=$(stty -a | tr -s ';' '\n' | sed "s/^ //;$sed_del;s/-//g") + +# Take them in pairs, with and without the leading '-'. +for opt1 in $options; do + for opt2 in $options; do + + stty $opt1 $opt2 || fail=1 + + if stty_reversible_query_ "$opt1" ; then + stty -$opt1 $opt2 || fail=1 + fi + if stty_reversible_query_ "$opt2" ; then + stty $opt1 -$opt2 || fail=1 + fi + if stty_reversible_query_ "$opt1" \ + && stty_reversible_query_ "$opt2" ; then + stty -$opt1 -$opt2 || fail=1 + fi + done +done + +stty $(cat $saved_state) + +Exit $fail diff --git a/tests/misc/stty-row-col.sh b/tests/misc/stty-row-col.sh new file mode 100755 index 0000000..89460ac --- /dev/null +++ b/tests/misc/stty-row-col.sh @@ -0,0 +1,91 @@ +#!/bin/sh +# Test "stty" with rows and columns. + +# Copyright (C) 1998-2022 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 <https://www.gnu.org/licenses/>. + +# Setting this envvar to a very small value used to cause e.g., 'stty size' +# to generate slightly different output on certain systems. +COLUMNS=80 +export COLUMNS + +# Make sure we get English-language behavior. +# See the report about a possibly-related Solaris problem by Alexandre Peshansky +# <https://lists.gnu.org/r/bug-coreutils/2004-10/msg00035.html>. +# Currently stty isn't localized, but it might be in the future. +LC_ALL=C +export LC_ALL + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stty + +require_controlling_input_terminal_ +require_trap_signame_ + +trap '' TTOU # Ignore SIGTTOU + +# Versions of GNU stty from shellutils-1.9.2c and earlier failed +# tests #2 and #4 when run on SunOS 4.1.3. + +tests=' +1 rows_40_columns_80 40_80 +2 rows_1_columns_1 1_1 +3 rows_40_columns_80 40_80 +4 rows_1 1_80 +5 columns_1 1_1 +6 rows_40 40_1 +7 rows_1 1_1 +8 columns_80 1_80 +9 rows_30 30_80 +10 rows_0x1E 30_80 +11 rows_036 30_80 +NA LAST NA +' +set $tests + +saved_size=$(stty size) && test -n "$saved_size" \ + || skip_ "can't get window size" + +# Linux virtual consoles issue an error if you +# try to increase their size. So skip in that case. +if test "x$saved_size" != "x0 0"; then + srow=$(echo $saved_size | cut -d ' ' -f1) + scol=$(echo $saved_size | cut -d ' ' -f2) + stty rows $(expr $srow + 1) cols $(expr $scol + 1) || + skip_ "can't increase window size" +fi + +while :; do + test_name=$1 + args=$2 + expected_result="$(echo $3|tr _ ' ')" + test "$args" = empty && args='' + test "x$args" = xLAST && break + args=$(echo x$args|tr _ ' '|sed 's/^x//') + if test "$VERBOSE" = yes; then + # echo "testing \$(stty $args; stty size\) = $expected_result ..." + echo "test $test_name... " | tr -d '\n' + fi + stty $args || exit 1 + test x"$(stty size 2> /dev/null)" = "x$expected_result" \ + && ok=ok || ok=FAIL fail=1 + test "$VERBOSE" = yes && echo $ok + shift; shift; shift +done + +set x $saved_size +stty rows $2 columns $3 || exit 1 + +Exit $fail diff --git a/tests/misc/stty.sh b/tests/misc/stty.sh new file mode 100755 index 0000000..bcdc80e --- /dev/null +++ b/tests/misc/stty.sh @@ -0,0 +1,92 @@ +#!/bin/sh +# Make sure stty can parse most of its options. + +# Copyright (C) 1998-2022 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 <https://www.gnu.org/licenses/>. + +# Make sure there's a tty on stdin. +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stty + +require_controlling_input_terminal_ +require_trap_signame_ +require_strace_ ioctl + +trap '' TTOU # Ignore SIGTTOU + +# Get the reversible settings from stty.c. +stty_reversible_init_ + +saved_state=.saved-state +stty --save > $saved_state || fail=1 +stty $(cat $saved_state) || fail=1 + +# This would segfault prior to sh-utils-2.0j. +stty erase - || fail=1 + +# Ensure "immediate" and "wait" mode supported, with and without settings +for mode in '-drain' 'drain'; do + for opt in 'echo' ''; do + stty "$mode" $opt || fail=1 + done +done + +# These would improperly ignore invalid options through coreutils 5.2.1. +returns_ 1 stty -F 2>/dev/null || fail=1 +returns_ 1 stty -raw -F no/such/file 2>/dev/null || fail=1 +returns_ 1 stty -raw -a 2>/dev/null || fail=1 + +# Build a list of all boolean options stty accepts on this system. +# Don't depend on terminal width. Put each option on its own line, +# remove all non-boolean ones, then remove any leading hyphens. +sed_del='/^speed/d;/^rows/d;/^columns/d;/ = /d' +options=$(stty -a | tr -s ';' '\n' | sed "s/^ //;$sed_del;s/-//g") + +# Take them one at a time, with and without the leading '-'. +for opt in $options; do + # 'stty parenb' and 'stty -parenb' fail with this message + # stty: standard input: unable to perform all requested operations + # on Linux 2.2.0-pre4 kernels. Also since around Linux 2.6.30 + # other serial control settings give the same error. So skip them. + # Also on ppc*|sparc* glibc platforms 'icanon' gives the same error. + # See: https://bugs.gnu.org/7228#14 + case $opt in + parenb|parodd|cmspar) continue;; + cstopb|crtscts|cdtrdsr|icanon) continue;; + esac + + # This is listed as supported on FreeBSD + # but the ioctl returns ENOTTY. + test $opt = extproc && continue + + stty $opt || fail=1 + + # Likewise, 'stty -cread' would fail, so skip that, too. + test $opt = cread && continue + if stty_reversible_query_ "$opt" ; then + stty -$opt || { fail=1; echo -$opt; } + fi +done + +stty $(cat $saved_state) + +# Ensure we validate options before accessing the device +strace -o log1 -e ioctl stty --version || fail=1 +n_ioctl1=$(wc -l < log1) || framework_failure_ +returns_ 1 strace -o log2 -e ioctl stty -blahblah || fail=1 +n_ioctl2=$(wc -l < log2) || framework_failure_ +test "$n_ioctl1" = "$n_ioctl2" || fail=1 + +Exit $fail diff --git a/tests/misc/sum-sysv.sh b/tests/misc/sum-sysv.sh new file mode 100755 index 0000000..a11e017 --- /dev/null +++ b/tests/misc/sum-sysv.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# make sure 'sum -s' works for input whose sum of bytes is larger than 2^32 + +# Copyright (C) 2001-2022 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 <https://www.gnu.org/licenses/>. + +# Avoid a problem when run in a UTF-8 locale. +# Otherwise, Perl would try to (and fail to) interpret +# each string below as a sequence of multi-byte characters. +LC_ALL=C +export LC_ALL + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sum + +require_perl_ + +# FYI, 16843009 is floor (2^32 / 255). + +# aka: perl -e 'print chr(255) x 16843009' +$PERL -e '$s = chr(255) x 65537; foreach (1..257) {print $s}' \ + | sum -s > out || fail=1 +cat > exp <<\EOF +65535 32897 +EOF +compare exp out || fail=1 + +rm -f out exp + +# aka: perl -e 'print chr(255) x 16843010' +$PERL -e '$s = chr(255) x 65537; foreach (1..257) {print $s}; print chr(255)' \ + | sum -s > out || fail=1 +cat > exp <<\EOF +254 32897 +EOF +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/sum.pl b/tests/misc/sum.pl new file mode 100755 index 0000000..88b53d3 --- /dev/null +++ b/tests/misc/sum.pl @@ -0,0 +1,61 @@ +#!/usr/bin/perl +# Test "sum". + +# Copyright (C) 2000-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $in_1k = 'a' x 1024; +my $in_2k = 'b' x 2048; + +my @Tests = + ( + ['1', {IN=> {f=> ''}}, {OUT=>"00000 0 f\n"}], + ['2', {IN=> {f=> 'a'}}, {OUT=>"00097 1 f\n"}], + ['3', {IN=> {f=> 'abc'}}, {OUT=>"16556 1 f\n"}], + ['4', {IN=> {f=> 'message digest'}}, {OUT=>"26423 1 f\n"}], + ['5', {IN=> {f=> 'abcdefghijklmnopqrstuvwxyz'}}, {OUT=>"53553 1 f\n"}], + ['6', {IN=> {f=> join ('', 'A'..'Z', 'a'..'z', '0'..'9')}}, + {OUT=>"25587 1 f\n"}], + ['7', {IN=> {f=> '1234567890' x 8}}, {OUT=>"21845 1 f\n"}], + + ['a-r-1k', '-r', {IN=> {f=> $in_1k}}, {OUT=>"65409 1 f\n"}], + ['a-s-1k', '-s', {IN=> {f=> $in_1k}}, {OUT=>"33793 2 f\n"}], + ['b-r-2k', '-r', {IN=> {f=> $in_2k}}, {OUT=>"65223 2 f\n"}], + ['b-s-2k', '-s', {IN=> {f=> $in_2k}}, {OUT=>"4099 4 f\n"}], + + ['1s', '-s', {IN=> {f=> ''}}, {OUT=>"0 0 f\n"}], + ['2s', '-s', {IN=> {f=> 'a'}}, {OUT=>"97 1 f\n"}], + ['3s', '-s', {IN=> {f=> 'abc'}}, {OUT=>"294 1 f\n"}], + ['4s', '-s', {IN=> {f=> 'message digest'}}, {OUT=>"1413 1 f\n"}], + ['5s', '-s', {IN=> {f=> 'abcdefghijklmnopqrstuvwxyz'}}, + {OUT=>"2847 1 f\n"}], + ['6s', '-s', {IN=> {f=> join ('', 'A'..'Z', 'a'..'z', '0'..'9')}}, + {OUT=>"5387 1 f\n"}], + ['7s', '-s', {IN=> {f=> '1234567890' x 8}}, {OUT=>"4200 1 f\n"}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'sum'; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/sync.sh b/tests/misc/sync.sh new file mode 100755 index 0000000..d7cc92c --- /dev/null +++ b/tests/misc/sync.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# Test various sync(1) operations + +# Copyright (C) 2015-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sync + +touch file || framework_failure_ + +# fdatasync+syncfs is nonsensical +returns_ 1 sync --data --file-system || fail=1 + +# fdatasync needs an operand +returns_ 1 sync -d || fail=1 + +# Test syncing of file (fsync) (little side effects) +sync file || fail=1 + +# Test syncing of write-only file - which failed since adding argument +# support to sync in coreutils-8.24. +chmod 0200 file || framework_failure_ +sync file || fail=1 + +# Ensure multiple args are processed and diagnosed +returns_ 1 sync file nofile || fail=1 + +# Ensure inaccessible dirs give an appropriate error +mkdir norw || framework_failure_ +chmod 0 norw || framework_failure_ +if ! test -r norw; then + returns_ 1 sync norw 2>errt || fail=1 + # AIX gives "Is a directory" + sed 's/Is a directory/Permission denied/' <errt >err || framework_failure_ + printf "sync: error opening 'norw': Permission denied\n" >exp + compare exp err || fail=1 +fi + +if test "$fail" != '1'; then + # Ensure a fifo doesn't block + mkfifo_or_skip_ fifo + returns_ 124 timeout 10 sync fifo && fail=1 +fi + +Exit $fail diff --git a/tests/misc/tac-2-nonseekable.sh b/tests/misc/tac-2-nonseekable.sh new file mode 100755 index 0000000..38c82a8 --- /dev/null +++ b/tests/misc/tac-2-nonseekable.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# ensure that tac works with non-seekable or quasi-seekable inputs + +# Copyright (C) 2011-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tac + +echo x | tac - - > out 2> err || fail=1 +echo x > exp || framework_failure_ +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Make sure it works on funny files in /proc and /sys. + +for file in /proc/version /sys/kernel/profiling; do + if test -r $file; then + cp -f $file copy && + tac copy > exp1 || framework_failure_ + + tac $file > out1 || fail=1 + compare exp1 out1 || fail=1 + fi +done + +# Assume timeout is due to failure to close stdin with <&- +# which was seen on NetBSD 7.1 / x86_64 +returns_ 124 timeout 10 tac - - <&- 2>err && skip_ 'error closing stdin' +# This failed due to heap corruption from v8.15-v8.25 inclusive. +returns_ 1 timeout 10 tac - - <&- 2>err || fail=1 + +Exit $fail diff --git a/tests/misc/tac-continue.sh b/tests/misc/tac-continue.sh new file mode 100755 index 0000000..c7f98ac --- /dev/null +++ b/tests/misc/tac-continue.sh @@ -0,0 +1,76 @@ +#!/bin/sh +# Ensure that tac processes all command line arguments, even +# when it encounters an error with say the first one. +# With coreutils-5.2.1 and earlier, this test would fail. + +# Copyright (C) 2004-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tac + +# See if the envvar is defined. +if test x = "x$FULL_PARTITION_TMPDIR"; then + skip_ "FULL_PARTITION_TMPDIR not defined" +fi + +if ! test -d "$FULL_PARTITION_TMPDIR"; then + echo "$0: $FULL_PARTITION_TMPDIR:" \ + "\$FULL_PARTITION_TMPDIR does not specify a directory" 1>&2 + Exit 1 +fi + +fp_tmp="$FULL_PARTITION_TMPDIR/tac-cont-$$" +cleanup_() +{ + # Terminate any background process + # and remove tmp dir + rm -f "$fp_tmp" + kill $pid 2>/dev/null && wait $pid +} + +# Make sure we can create an empty file there (i.e., no shortage of inodes). +if ! touch $fp_tmp; then + echo "$0: $fp_tmp: cannot create empty file" 1>&2 + Exit 1 +fi + +# Make sure that we fail when trying to create a file large enough +# to consume a non-inode block. +if seq 1000 > $fp_tmp 2>/dev/null; then + echo "$0: $FULL_PARTITION_TMPDIR: not a full partition" 1>&2 + Exit 1 +fi + +seq 5 > in + + +# Give tac a fifo command line argument. +# This makes it try to create a temporary file in $TMPDIR. +mkfifo_or_skip_ fifo +seq 1000 > fifo & pid=$! +TMPDIR=$FULL_PARTITION_TMPDIR tac fifo in >out 2>err && fail=1 + +cat <<\EOF > exp || framework_failure_ +5 +4 +3 +2 +1 +EOF + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/tac.pl b/tests/misc/tac.pl new file mode 100755 index 0000000..ad9fc17 --- /dev/null +++ b/tests/misc/tac.pl @@ -0,0 +1,91 @@ +#!/usr/bin/perl + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $prog = 'tac'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $bad_dir = 'no/such/dir'; + +# This must be longer than 16KiB to trigger the double free in coreutils-8.5. +my $long_line = 'o' x (16 * 1024 + 1); + +my @Tests = +( + ['segfault', '-r', {IN=>"a\n"}, {IN=>"b\n"}, {OUT=>"a\nb\n"}], + ['segfault2','-r', {IN=>"a\nb\n"}, {IN=>"1\n2\n"}, {OUT=>"b\na\n2\n1\n"}], + + ['basic-0', '', {IN=>""}, {OUT=>""}], + ['basic-a', '', {IN=>"a"}, {OUT=>"a"}], + ['basic-b', '', {IN=>"\n"}, {OUT=>"\n"}], + ['basic-c', '', {IN=>"a\n"}, {OUT=>"a\n"}], + ['basic-d', '', {IN=>"a\nb"}, {OUT=>"ba\n"}], + ['basic-e', '', {IN=>"a\nb\n"}, {OUT=>"b\na\n"}], + ['basic-f', '', {IN=>"1234567\n8\n"}, {OUT=>"8\n1234567\n"}], + ['basic-g', '', {IN=>"12345678\n9\n"}, {OUT=>"9\n12345678\n"}], + ['basic-h', '', {IN=>"123456\n8\n"}, {OUT=>"8\n123456\n"}], + ['basic-i', '', {IN=>"12345\n8\n"}, {OUT=>"8\n12345\n"}], + ['basic-j', '', {IN=>"1234\n8\n"}, {OUT=>"8\n1234\n"}], + ['basic-k', '', {IN=>"123\n8\n"}, {OUT=>"8\n123\n"}], + + ['nul-0', '-s ""', {IN=>""}, {OUT=>""}], + ['nul-a', '-s ""', {IN=>"a"}, {OUT=>"a"}], + ['nul-b', '-s ""', {IN=>"\0"}, {OUT=>"\0"}], + ['nul-c', '-s ""', {IN=>"a\0"}, {OUT=>"a\0"}], + ['nul-d', '-s ""', {IN=>"a\0b"}, {OUT=>"ba\0"}], + ['nul-e', '-s ""', {IN=>"a\0b\0"}, {OUT=>"b\0a\0"}], + + ['opt-b', '-b', {IN=>"\na\nb\nc"}, {OUT=>"\nc\nb\na"}], + ['opt-s', '-s:', {IN=>"a:b:c:"}, {OUT=>"c:b:a:"}], + ['opt-sb', qw(-s : -b), {IN=>":a:b:c"}, {OUT=>":c:b:a"}], + ['opt-r', qw(-r -s '\._+'), + {IN=>"1._2.__3.___4._"}, + {OUT=>"4._3.___2.__1._"}], + + ['opt-r2', qw(-r -s '\._+'), + {IN=>"a.___b.__1._2.__3.___4._"}, + {OUT=>"4._3.___2.__1._b.__a.___"}], + + # This gave incorrect output (.___4._2.__3._1) with tac-1.22. + ['opt-br', qw(-b -r -s '\._+'), + {IN=>"._1._2.__3.___4"}, {OUT=>".___4.__3._2._1"}], + + ['opt-br2', qw(-b -r -s '\._+'), + {IN=>".__x.___y.____z._1._2.__3.___4"}, + {OUT=>".___4.__3._2._1.____z.___y.__x"}], + + ['pipe-bad-tmpdir', + {ENV => "TMPDIR=$bad_dir"}, + {IN_PIPE => "a\n"}, + {ERR_SUBST => "s,'$bad_dir': .*,...,"}, + {ERR => "$prog: failed to create temporary file in ...\n"}, + {EXIT => 1}], + + # coreutils-8.5's tac would double-free its primary buffer. + ['double-free', {IN=>$long_line}, {OUT=>$long_line}], +); + +@Tests = triple_test \@Tests; + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/tail.pl b/tests/misc/tail.pl new file mode 100755 index 0000000..c3b0a66 --- /dev/null +++ b/tests/misc/tail.pl @@ -0,0 +1,148 @@ +#!/usr/bin/perl +# Test tail. + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $prog = 'tail'; +my $normalize_strerror = "s/': .*/'/"; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @tv = ( +# test name, options, input, expected output, expected return code +# +['obs-plus-c1', '+2c', 'abcd', 'bcd', 0], +['obs-plus-c2', '+8c', 'abcd', '', 0], +['obs-c3', '-1c', 'abcd', 'd', 0], +['obs-c4', '-9c', 'abcd', 'abcd', 0], +['obs-c5', '-12c', 'x' . ('y' x 12) . 'z', ('y' x 11) . 'z', 0], + +['obs-l1', '-1l', 'x', 'x', 0], +['obs-l2', '-1l', "x\ny\n", "y\n", 0], +['obs-l3', '-1l', "x\ny", "y", 0], +['obs-plus-l4', '+1l', "x\ny\n", "x\ny\n", 0], +['obs-plus-l5', '+2l', "x\ny\n", "y\n", 0], + +# Same as -l tests, but without the 'l'. +['obs-1', '-1', 'x', 'x', 0], +['obs-2', '-1', "x\ny\n", "y\n", 0], +['obs-3', '-1', "x\ny", "y", 0], +['obs-plus-4', '+1', "x\ny\n", "x\ny\n", 0], +['obs-plus-5', '+2', "x\ny\n", "y\n", 0], + +# This is equivalent to +10c +['obs-plus-x1', '+c', 'x' . ('y' x 10) . 'z', 'yyz', 0], +# This is equivalent to +10l +['obs-plus-x2', '+l', "x\n" . ("y\n" x 10) . 'z', "y\ny\nz", 0], +# With no number, this is like -10l +['obs-l', '-l', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0], + +['obs-b', '-b', "x\n" x (512 * 10 / 2 + 1), "x\n" x (512 * 10 / 2), 0], + +['err-1', '+cl', '', '', 1, + "$prog: cannot open '+cl' for reading: No such file or directory\n"], + +['err-2', '-cl', '', '', 1, + "$prog: invalid number of bytes: 'l'\n", $normalize_strerror], + +['err-3', '+2cz', '', '', 1, + "$prog: cannot open '+2cz' for reading: No such file or directory\n"], + +# This should get 'tail: invalid option -- 2' +['err-4', '-2cX', '', '', 1, + "$prog: option used in invalid context -- 2\n"], + +# Since the number is larger than 2^64, this should provoke +# the diagnostic: 'tail: 99999999999999999999: invalid number of bytes' +# on all systems... probably, for now, maybe. +['err-5', '-c99999999999999999999', '', '', 1, + "$prog: invalid number of bytes: '99999999999999999999'\n", + $normalize_strerror], +['err-6', '-c --', '', '', 1, + "$prog: invalid number of bytes: '-'\n", $normalize_strerror], + +# Same as -n 10 +['minus-1', '-', '', '', 0], +['minus-2', '-', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0], + +['c-2', '-c 2', "abcd\n", "d\n", 0], +['c-2-minus', '-c 2 --', "abcd\n", "d\n", 0], +['c2', '-c2', "abcd\n", "d\n", 0], +['c2-minus', '-c2 --', "abcd\n", "d\n", 0], + +['n-1', '-n 10', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0], +['n-2', '-n -10', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0], +['n-3', '-n +10', "x\n" . ("y\n" x 10) . 'z', "y\ny\nz", 0], + +# Accept +0 as synonym for +1. +['n-4', '-n +0', "y\n" x 5, "y\n" x 5, 0], +['n-4a', '-n +1', "y\n" x 5, "y\n" x 5, 0], + +# Note that -0 is *not* a synonym for -1. +['n-5', '-n -0', "y\n" x 5, '', 0], +['n-5a', '-n -1', "y\n" x 5, "y\n", 0], +['n-5b', '-n 0', "y\n" x 5, '', 0], + +# With textutils-1.22, this failed. +['f-pipe-1', '-f -n 1', "a\nb\n", "b\n", 0], + +# --zero-terminated +['zero-1', '-z -n 1', "x\0y", "y", 0], +['zero-2', '-z -n 2', "x\0y", "x\0y", 0], +); + +my @Tests; + +foreach my $t (@tv) + { + my ($test_name, $flags, $in, $exp, $ret, $err_msg, $err_sub) = @$t; + my $e = [$test_name, $flags, {IN=>$in}, {OUT=>$exp}]; + $ret + and push @$e, {EXIT=>$ret}, {ERR=>$err_msg}, {ERR_SUBST=>$err_sub}; + + $test_name =~ /^minus-/ + and push @$e, {ENV=>'_POSIX2_VERSION=199209'}; + + $test_name =~ /^(err-6|c-2)$/ + and push @$e, {ENV=>'_POSIX2_VERSION=200112'}; + + $test_name =~ /^obs-plus-/ + and push @$e, {ENV=>'_POSIX2_VERSION=200809'}; + + $test_name =~ /^f-pipe-/ + and push @$e, {ENV=>'POSIXLY_CORRECT=1'}; + + push @Tests, $e; + } + +@Tests = triple_test \@Tests; + +# If you run the minus* tests with a FILE arg they'd hang. +# If you run the err-1 or err-3 tests with a FILE, they'd misinterpret +# the arg unless we are using the obsolete form. +@Tests = grep { $_->[0] !~ /^(minus|err-[13])/ || $_->[0] =~ /\.[rp]$/ } @Tests; + +# Using redirection or a file would make this hang. +@Tests = grep { $_->[0] !~ /^f-/ || $_->[0] =~ /\.p$/ } @Tests; + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/tee.sh b/tests/misc/tee.sh new file mode 100755 index 0000000..0bd91b6 --- /dev/null +++ b/tests/misc/tee.sh @@ -0,0 +1,109 @@ +#!/bin/sh +# test for basic tee functionality. + +# Copyright (C) 2005-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tee + +echo line >sample || framework_failure_ + +# POSIX says: "Processing of at least 13 file operands shall be supported." +for n in 0 1 2 12 13; do + files=$(seq $n) + rm -f $files + tee $files <sample >out || fail=1 + for f in out $files; do + compare sample $f || fail=1 + done +done + +# Ensure tee treats '-' as the name of a file, as mandated by POSIX. +# Between v5.3.0 and v8.23, a '-' argument caused tee to send another +# copy of input to standard output. +tee - <sample >out 2>err || fail=1 +compare sample ./- || fail=1 +compare sample out || fail=1 +compare /dev/null err || fail=1 + +# Ensure tee exits early if no more writable outputs +if test -w /dev/full && test -c /dev/full; then + yes | returns_ 1 timeout 10 tee /dev/full 2>err >/dev/full || fail=1 + # Ensure an error for each of the 2 outputs + # (and no redundant errors for stdout). + test $(wc -l < err) = 2 || { cat err; fail=1; } + + + # Ensure we continue with outputs that are OK + seq 10000 > multi_read || framework_failure_ + + returns_ 1 tee /dev/full out2 2>err >out1 <multi_read || fail=1 + cmp multi_read out1 || fail=1 + cmp multi_read out2 || fail=1 + # Ensure an error for failing output + test $(wc -l < err) = 1 || { cat err; fail=1; } + + returns_ 1 tee out1 out2 2>err >/dev/full <multi_read || fail=1 + cmp multi_read out1 || fail=1 + cmp multi_read out2 || fail=1 + # Ensure an error for failing output + test $(wc -l < err) = 1 || { cat err; fail=1; } +fi + + +# Ensure tee honors --output-error modes +mkfifo_or_skip_ fifo +read_fifo() { timeout 10 dd count=1 if=fifo of=/dev/null status=none & } + +# Determine platform sigpipe exit status +read_fifo +yes >fifo +pipe_status=$? + +# Default operation is to continue on output errors but exit silently on SIGPIPE +read_fifo +yes | returns_ $pipe_status timeout 10 tee ./e/noent 2>err >fifo || fail=1 +test $(wc -l < err) = 1 || { cat err; fail=1; } + +# With -p, SIGPIPE is suppressed, exit 0 for EPIPE when all outputs finished +read_fifo +yes | timeout 10 tee -p 2>err >fifo || fail=1 +test $(wc -l < err) = 0 || { cat err; fail=1; } + +# With --output-error=warn, exit 1 for EPIPE when all outputs finished +read_fifo +yes | returns_ 1 timeout 10 tee --output-error=warn 2>err >fifo || fail=1 +test $(wc -l < err) = 1 || { cat err; fail=1; } + +# With --output-error=exit, exit 1 immediately for EPIPE +read_fifo +yes | returns_ 1 timeout 10 tee --output-error=exit /dev/null 2>err >fifo \ + || fail=1 +test $(wc -l < err) = 1 || { cat err; fail=1; } + +# With --output-error=exit, exit 1 immediately on output error +read_fifo +yes | returns_ 1 timeout 10 tee --output-error=exit ./e/noent 2>err >fifo \ + || fail=1 +test $(wc -l < err) = 1 || { cat err; fail=1; } + +# With --output-error=exit-nopipe, exit 0 for EPIPE +read_fifo +yes | timeout 10 tee --output-error=exit-nopipe 2>err >fifo || fail=1 +test $(wc -l < err) = 0 || { cat err; fail=1; } + +wait +Exit $fail diff --git a/tests/misc/test-N.sh b/tests/misc/test-N.sh new file mode 100755 index 0000000..e3b1b56 --- /dev/null +++ b/tests/misc/test-N.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# Test 'test -N file'. + +# Copyright (C) 2018-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ test stat + +stat_test_N() { + mtime=$(env stat -c '%.Y' "$1") + atime=$(env stat -c '%.X' "$1") + test "$mtime" = "$atime" && return 1 + latest=$(printf '%s\n' "$mtime" "$atime" | sort -g | tail -n1) + test "$mtime" = "$latest" +} + +# For a freshly touched file, atime should equal mtime: 'test -N' returns 1. +touch file || framework_failure_ +if ! stat_test_N file; then + returns_ 1 env test -N file || fail=1 +fi + +# Set access time to 2 days ago: 'test -N' returns 0. +touch -a -d '12:00 today -2 days' file || framework_failure_ +if stat_test_N file; then + env test -N file || fail=1 +fi + +# Set mtime to 2 days before atime: 'test -N' returns 1; +touch -m -d '12:00 today -4 days' file || framework_failure_ +if ! stat_test_N file; then + returns_ 1 env test -N file || fail=1 +fi + +# Now modify the file: 'test -N' returns 0. +echo 'data' > file || framework_failure_ +if stat_test_N file; then + env test -N file || fail=1 +fi + +Exit $fail diff --git a/tests/misc/test-diag.pl b/tests/misc/test-diag.pl new file mode 100755 index 0000000..d00a4e9 --- /dev/null +++ b/tests/misc/test-diag.pl @@ -0,0 +1,38 @@ +#!/usr/bin/perl +# Test the diagnostics of "test". + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + # In coreutils-5.93, this diagnostic lacked the newline. + ['o', '-o arg', {ERR => "test: '-o': unary operator expected\n"}, + {ERR_SUBST => 's!^.*test:!test:!'}, + {EXIT => 2}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; +my $prog = 'test'; +my $fail = run_tests ($program_name, \$prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/test.pl b/tests/misc/test.pl new file mode 100755 index 0000000..b77ef71 --- /dev/null +++ b/tests/misc/test.pl @@ -0,0 +1,197 @@ +#!/usr/bin/perl + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $limits = getlimits (); + +my $prog = 'test'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +sub digest_test ($) +{ + my ($t) = @_; + my @args; + my $ret = 0; + my @list_of_hashref; + foreach my $e (@$t) + { + !ref $e + and push (@args, $e), next; + ref $e eq 'HASH' + or (warn "$0: $t->[0]: unexpected entry type\n"), next; + + exists $e->{EXIT} + and $ret = $e->{EXIT}, next; + + push @list_of_hashref, $e; + } + shift @args; # discard test name + my $flags = join ' ', @args; + + return ($flags, $ret, \@list_of_hashref); +} + +sub add_inverse_op_tests($) +{ + my ($tests) = @_; + my @new; + + my %inverse_op = + ( + eq => 'ne', + lt => 'ge', + gt => 'le', + ); + + foreach my $t (@$tests) + { + push @new, $t; + + my $test_name = $t->[0]; + my ($flags, $ret, $LoH) = digest_test $t; + + # Generate corresponding tests of inverse ops. + # E.g. generate tests of '-ge' from those of '-lt'. + foreach my $op (qw(gt lt eq)) + { + if ($test_name =~ /$op-/ && $flags =~ / -$op /) + { + my $inv = $inverse_op{$op}; + $test_name =~ s/$op/$inv/; + $flags =~ s/-$op/-$inv/; + $ret = 1 - $ret; + push (@new, [$test_name, $flags, {EXIT=>$ret}, @$LoH]); + } + } + } + return @new; +} + +sub add_pn_tests($) +{ + my ($tests) = @_; + my @new; + + # Generate parenthesized and negated versions of each test. + # There are a few exceptions. + my %not_N = map {$_ => 1} qw (1a); + my %not_P = map {$_ => 1} qw (1a + streq-6 strne-6 + paren-1 paren-2 paren-3 paren-4 paren-5); + foreach my $t (@$tests) + { + push @new, $t; + + my $test_name = $t->[0]; + my ($flags, $ret, $LoH) = digest_test $t; + next if $ret == 2; + + push (@new, ["N-$test_name", "! $flags", {EXIT=>1-$ret}, @$LoH]) + unless $not_N{$test_name}; + push (@new, ["P-$test_name", "'(' $flags ')'", {EXIT=>$ret}, @$LoH]) + unless $not_P{$test_name}; + push (@new, ["NP-$test_name", "! '(' $flags ')'", {EXIT=>1-$ret}, @$LoH]) + unless $not_P{$test_name}; + push (@new, ["NNP-$test_name", "! ! '(' $flags ')'", {EXIT=>$ret, @$LoH}]) + unless $not_P{$test_name}; + } + + return @new; +} + +my @Tests = +( + ['1a', {EXIT=>1}], + ['1b', qw(-z '')], + ['1c', 'any-string'], + ['1d', qw(-n any-string)], + ['1e', "''", {EXIT=>1}], + ['1f', '-'], + ['1g', '--'], + ['1h', '-0'], + ['1i', '-f'], + ['1j', '--help'], + ['1k', '--version'], + + ['streq-1', qw(t = t)], + ['streq-2', qw(t = f), {EXIT=>1}], + ['streqeq-1', qw(t == t)], + ['streqeq-2', qw(t == f), {EXIT=>1}], + ['streq-3', qw(! = !)], + ['streq-4', qw(= = =)], + ['streq-5', "'(' = '('"], + ['streq-6', "'(' = ')'", {EXIT=>1}], + ['strne-1', qw(t != t), {EXIT=>1}], + ['strne-2', qw(t != f)], + ['strne-3', qw(! != !), {EXIT=>1}], + ['strne-4', qw(= != =), {EXIT=>1}], + ['strne-5', "'(' != '('", {EXIT=>1}], + ['strne-6', "'(' != ')'"], + + ['and-1', qw(t -a t)], + ['and-2', qw('' -a t), {EXIT=>1}], + ['and-3', qw(t -a ''), {EXIT=>1}], + ['and-4', qw('' -a ''), {EXIT=>1}], + + ['or-1', qw(t -o t)], + ['or-2', qw('' -o t)], + ['or-3', qw(t -o '')], + ['or-4', qw('' -o ''), {EXIT=>1}], + + ['eq-1', qw(9 -eq 9)], + ['eq-2', qw(0 -eq 0)], + ['eq-3', qw(0 -eq 00)], + ['eq-4', qw(8 -eq 9), {EXIT=>1}], + ['eq-5', qw(1 -eq 0), {EXIT=>1}], + ['eq-6', "$limits->{UINTMAX_OFLOW} -eq 0", {EXIT=>1}], + + ['gt-1', qw(5 -gt 5), {EXIT=>1}], + ['gt-2', qw(5 -gt 4)], + ['gt-3', qw(4 -gt 5), {EXIT=>1}], + ['gt-4', qw(-1 -gt -2)], + ['gt-5', "$limits->{UINTMAX_OFLOW} -gt $limits->{INTMAX_UFLOW}"], + + ['lt-1', qw(5 -lt 5), {EXIT=>1}], + ['lt-2', qw(5 -lt 4), {EXIT=>1}], + ['lt-3', qw(4 -lt 5)], + ['lt-4', qw(-1 -lt -2), {EXIT=>1}], + ['lt-5', "$limits->{INTMAX_UFLOW} -lt $limits->{UINTMAX_OFLOW}"], + + ['inv-1', qw(0x0 -eq 00), {EXIT=>2}, + {ERR=>"$prog: invalid integer '0x0'\n"}], + + ['t1', "-t"], + ['t2', qw(-t 1), {EXIT=>1}], + + ['paren-1', "'(' '' ')'", {EXIT=>1}], + ['paren-2', "'(' '(' ')'"], + ['paren-3', "'(' ')' ')'"], + ['paren-4', "'(' ! ')'"], + ['paren-5', "'(' -a ')'"], +); + +@Tests = add_inverse_op_tests \@Tests; +@Tests = add_pn_tests \@Tests; + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, \$prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/time-style.sh b/tests/misc/time-style.sh new file mode 100755 index 0000000..c900075 --- /dev/null +++ b/tests/misc/time-style.sh @@ -0,0 +1,119 @@ +#!/bin/sh +# Test --time-style in programs like 'ls'. + +# Copyright (C) 2016-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ du +print_ver_ ls +print_ver_ pr + +echo hello >a || framework_failure_ + +# The tests assume this is an old timestamp in northern hemisphere summer. +TZ=UTC0 touch -d '1970-07-08 09:10:11' a || framework_failure_ + +for tz in UTC0 PST8 PST8PDT,M3.2.0,M11.1.0 XXXYYY-12:30; do + for style in full-iso long-iso iso locale '+%Y-%m-%d %H:%M:%S %z (%Z)' \ + +%%b%b%%b%b; do + test "$style" = locale || + TZ=$tz LC_ALL=C du --time --time-style="$style" a >>duout 2>>err || fail=1 + TZ=$tz LC_ALL=C ls -no --time-style="$style" a >>lsout 2>>err || fail=1 + case $style in + (+*) TZ=$tz LC_ALL=C pr -D"$style" a >>prout 2>>err || fail=1 ;; + esac + done +done + +sed 's/[^ ]* //' duout >dued || framework_failure_ +sed 's/[^ ]* *[^ ]* *[^ ]* *[^ ]* *//' lsout >lsed || framework_failure_ +sed '/^$/d' prout >pred || framework_failure_ + +cat <<\EOF > duexp || framework_failure_ +1970-07-08 09:10:11.000000000 +0000 a +1970-07-08 09:10 a +1970-07-08 a +1970-07-08 09:10:11 +0000 (UTC) a +%bJul%bJul a +1970-07-08 01:10:11.000000000 -0800 a +1970-07-08 01:10 a +1970-07-08 a +1970-07-08 01:10:11 -0800 (PST) a +%bJul%bJul a +1970-07-08 02:10:11.000000000 -0700 a +1970-07-08 02:10 a +1970-07-08 a +1970-07-08 02:10:11 -0700 (PDT) a +%bJul%bJul a +1970-07-08 21:40:11.000000000 +1230 a +1970-07-08 21:40 a +1970-07-08 a +1970-07-08 21:40:11 +1230 (XXXYYY) a +%bJul%bJul a +EOF + +cat <<\EOF > lsexp || framework_failure_ +1970-07-08 09:10:11.000000000 +0000 a +1970-07-08 09:10 a +1970-07-08 a +Jul 8 1970 a +1970-07-08 09:10:11 +0000 (UTC) a +%bJul%bJul a +1970-07-08 01:10:11.000000000 -0800 a +1970-07-08 01:10 a +1970-07-08 a +Jul 8 1970 a +1970-07-08 01:10:11 -0800 (PST) a +%bJul%bJul a +1970-07-08 02:10:11.000000000 -0700 a +1970-07-08 02:10 a +1970-07-08 a +Jul 8 1970 a +1970-07-08 02:10:11 -0700 (PDT) a +%bJul%bJul a +1970-07-08 21:40:11.000000000 +1230 a +1970-07-08 21:40 a +1970-07-08 a +Jul 8 1970 a +1970-07-08 21:40:11 +1230 (XXXYYY) a +%bJul%bJul a +EOF + +cat <<\EOF > prexp || framework_failure_ ++1970-07-08 09:10:11 +0000 (UTC) a Page 1 +hello ++%bJul%bJul a Page 1 +hello ++1970-07-08 01:10:11 -0800 (PST) a Page 1 +hello ++%bJul%bJul a Page 1 +hello ++1970-07-08 02:10:11 -0700 (PDT) a Page 1 +hello ++%bJul%bJul a Page 1 +hello ++1970-07-08 21:40:11 +1230 (XXXYYY) a Page 1 +hello ++%bJul%bJul a Page 1 +hello +EOF + +compare duexp dued || fail=1 +compare lsexp lsed || fail=1 +compare prexp pred || fail=1 +compare /dev/null err || fail=1 + +Exit $fail diff --git a/tests/misc/timeout-blocked.pl b/tests/misc/timeout-blocked.pl new file mode 100755 index 0000000..0ea6a86 --- /dev/null +++ b/tests/misc/timeout-blocked.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl +# Test that timeout handles blocked SIGALRM from its parent. + +# Copyright (C) 2013-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $ME = $0) =~ s|.*/||; + +eval { require POSIX; }; +$@ + and CuSkip::skip "$ME: this script requires Perl's POSIX module\n"; + +use POSIX qw(:signal_h); +my $sigset = POSIX::SigSet->new(SIGALRM); # define the signals to block +my $old_sigset = POSIX::SigSet->new; # where the old sigmask will be kept +unless (defined sigprocmask(SIG_BLOCK, $sigset, $old_sigset)) { + CuSkip::skip "$ME: sigprocmask failed; skipped"; +} + +my @Tests = + ( + # test-name, [option, option, ...] {OUT=>"expected-output"} + # + + ['block-alrm', ".1 sleep 10", {EXIT => 124}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'timeout'; +my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose); + +exit $fail; diff --git a/tests/misc/timeout-group.sh b/tests/misc/timeout-group.sh new file mode 100755 index 0000000..27cfdb7 --- /dev/null +++ b/tests/misc/timeout-group.sh @@ -0,0 +1,103 @@ +#!/bin/sh +# test program group handling + +# Copyright (C) 2011-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ timeout +require_trap_signame_ +require_kill_group_ + +# construct a program group hierarchy as follows: +# timeout-group - foreground group +# group.sh - separate group +# timeout.cmd - same group as group.sh +# +# We then send a SIGINT to the "separate group" +# to simulate what happens when a Ctrl-C +# is sent to the foreground group. + +setsid true || skip_ "setsid required to control groups" + +printf '%s\n' '#!'"$SHELL" > timeout.cmd || framework_failure_ +cat >> timeout.cmd <<\EOF +trap 'touch int.received; exit' INT +touch timeout.running +count=$1 +until test -e int.received || test $count = 0; do + sleep 1 + count=$(expr $count - 1) +done +EOF +chmod a+x timeout.cmd + +cat > group.sh <<EOF +#!$SHELL +trap '' INT +timeout --foreground 25 ./timeout.cmd 20& +wait +EOF +chmod a+x group.sh + +check_timeout_cmd_running() +{ + local delay="$1" + test -e timeout.running || + { sleep $delay; return 1; } +} + +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +# Start above script in its own group. +# We could use timeout for this, but that assumes an implementation. +setsid ./group.sh & pid=$! +# Wait 6.3s for timeout.cmd to start +retry_delay_ check_timeout_cmd_running .1 6 || fail=1 +# Simulate a Ctrl-C to the group to test timely exit +kill -INT -- -$pid +wait +test -e int.received || fail=1 + +rm -f int.received timeout.running + + +# Ensure cascaded timeouts work +# or more generally, ensure we timeout +# commands that create their own group +# This didn't work before 8.13. + +start=$(date +%s) + +# Note the first timeout must send a signal that +# the second is handling for it to be propagated to the command. +# SIGINT, SIGTERM, SIGALRM etc. are implicit. +timeout -sALRM 30 timeout -sINT 25 ./timeout.cmd 20 & pid=$! +# Wait 6.3s for timeout.cmd to start +retry_delay_ check_timeout_cmd_running .1 6 || fail=1 +kill -ALRM $pid # trigger the alarm of the first timeout command +wait $pid +ret=$? +test $ret -eq 124 || + skip_ "timeout returned $ret. SIGALRM not handled?" +test -e int.received || fail=1 + +end=$(date +%s) + +test $(expr $end - $start) -lt 20 || + skip_ "timeout.cmd didn't receive a signal until after sleep?" + +Exit $fail diff --git a/tests/misc/timeout-large-parameters.sh b/tests/misc/timeout-large-parameters.sh new file mode 100755 index 0000000..dc7c88b --- /dev/null +++ b/tests/misc/timeout-large-parameters.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# Validate large timeout parameters +# Separated from standard parameter testing due to kernel overflow bugs. + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ timeout +getlimits_ + +# It was seen on 32 bit Linux/HPPA and OpenIndiana 11 +# that a kernel time_t overflowing cause the timer to fire immediately. +# This is still racy, but unlikely to cause an issue unless +# timeout can't process the timer firing within 3 seconds. +timeout $TIME_T_OFLOW sleep 3 +if test $? = 124; then + skip_ 'timeout $TIME_T_OFLOW ..., timed out immediately!' +fi + +# timeout overflow +timeout $UINT_OFLOW sleep 0 || fail=1 + +# timeout overflow +timeout ${TIME_T_OFLOW}d sleep 0 || fail=1 + +# floating point notation +timeout 2.34e+5d sleep 0 || fail=1 + +# floating point overflow +timeout $LDBL_MAX sleep 0 || fail=1 +returns_ 125 timeout -- -$LDBL_MAX sleep 0 || fail=1 + +Exit $fail diff --git a/tests/misc/timeout-parameters.sh b/tests/misc/timeout-parameters.sh new file mode 100755 index 0000000..8c8c29b --- /dev/null +++ b/tests/misc/timeout-parameters.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# Validate timeout parameter combinations + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ timeout env +getlimits_ + + +# internal errors are 125, distinct from execution failure + +# invalid timeout +returns_ 125 timeout invalid sleep 0 || fail=1 + +# invalid kill delay +returns_ 125 timeout --kill-after=invalid 1 sleep 0 || fail=1 + +# invalid timeout suffix +returns_ 125 timeout 42D sleep 0 || fail=1 + +# floating point notation +timeout 10.34 sleep 0 || fail=1 + +# nanoseconds potentially supported +timeout 9.999999999 sleep 0 || fail=1 + +# invalid signal spec +returns_ 125 timeout --signal=invalid 1 sleep 0 || fail=1 + +# invalid command +returns_ 126 env . && { returns_ 126 timeout 10 . || fail=1; } + +# no such command +returns_ 127 timeout 10 no_such || fail=1 + +Exit $fail diff --git a/tests/misc/timeout.sh b/tests/misc/timeout.sh new file mode 100755 index 0000000..dc6dc96 --- /dev/null +++ b/tests/misc/timeout.sh @@ -0,0 +1,74 @@ +#!/bin/sh +# Validate timeout basic operation + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ timeout +require_trap_signame_ + +# no timeout +timeout 10 true || fail=1 + +# no timeout (suffix check) +timeout 1d true || fail=1 + +# disabled timeout +timeout 0 true || fail=1 + +# exit status propagation +returns_ 2 timeout 10 sh -c 'exit 2' || fail=1 + +# timeout +returns_ 124 timeout .1 sleep 10 || fail=1 + +# exit status propagation even on timeout +# exit status should be 128+TERM +returns_ 124 timeout --preserve-status .1 sleep 10 && fail=1 + +# kill delay. Note once the initial timeout triggers, +# the exit status will be 124 even if the command +# exits on its own accord. +# exit status should be 128+KILL +returns_ 124 timeout -s0 -k1 .1 sleep 10 && fail=1 +# Ensure a consistent exit status with --foreground +returns_ 124 timeout --foreground -s0 -k1 .1 sleep 10 && fail=1 + +# Ensure 'timeout' is immune to parent's SIGCHLD handler +# Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh. +( + trap '' CHLD + + exec timeout 10 true +) || fail=1 + +# Don't be confused when starting off with a child (Bug#9098). +out=$(sleep .1 & exec timeout .5 sh -c 'sleep 2; echo foo') +status=$? +test "$out" = "" && test $status = 124 || fail=1 + +# Verify --verbose output +cat > exp <<\EOF +timeout: sending signal EXIT to command 'sleep' +timeout: sending signal KILL to command 'sleep' +EOF +for opt in -v --verbose; do + timeout $opt -s0 -k .1 .1 sleep 10 2> errt + sed '/^Killed/d' < errt > err || framework_failure_ + compare exp err || fail=1 +done + +Exit $fail diff --git a/tests/misc/tr-case-class.sh b/tests/misc/tr-case-class.sh new file mode 100755 index 0000000..09108e9 --- /dev/null +++ b/tests/misc/tr-case-class.sh @@ -0,0 +1,116 @@ +#!/bin/sh +# Test case conversion classes + +# Copyright (C) 2010-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tr + +# Ensure we support translation of case classes with extension +echo '01234567899999999999999999' > exp +echo 'abcdefghijklmnopqrstuvwxyz' | +tr '[:lower:]' '0-9' > out || fail=1 +compare exp out || fail=1 +echo 'abcdefghijklmnopqrstuvwxyz' | +tr '[:lower:][:lower:]' '[:upper:]0-9' > out || fail=1 +compare exp out || fail=1 + +# Validate the alignment of case classes +returns_ 1 tr 'A-Z[:lower:]' 'a-y[:upper:]' </dev/null || fail=1 +returns_ 1 tr '[:upper:][:lower:]' 'a-y[:upper:]' </dev/null || fail=1 +returns_ 1 tr 'A-Y[:lower:]' 'a-z[:upper:]' </dev/null || fail=1 +returns_ 1 tr 'A-Z[:lower:]' '[:lower:][:upper:]' </dev/null || fail=1 +returns_ 1 tr 'A-Z[:lower:]' '[:lower:]A-Z' </dev/null || fail=1 +tr '[:upper:][:lower:]' 'a-z[:upper:]' < /dev/null || fail=1 +tr '[:upper:][:lower:]' '[:upper:]a-z' < /dev/null || fail=1 + +# Before coreutils 8.6 the trailing space in string1 +# caused the case class in string2 to be extended. +# However that was not portable, dependent on locale +# and in contravention of POSIX. +tr '[:upper:] ' '[:lower:]' < /dev/null 2>out && fail=1 +echo 'tr: when translating with string1 longer than string2, +the latter string must not end with a character class' > exp +compare exp out || fail=1 + +# Up to coreutils-6.9, tr rejected an unmatched [:lower:] or [:upper:] in SET1. +echo '#$%123abcABC' | tr '[:lower:]' '[.*]' > out || fail=1 +echo '#$%123...ABC' > exp +compare exp out || fail=1 +echo '#$%123abcABC' | tr '[:upper:]' '[.*]' > out || fail=1 +echo '#$%123abc...' > exp +compare exp out || fail=1 + +# When doing a case-converting translation with something after the +# [:upper:] and [:lower:] elements, ensure that tr honors the following byte. +echo 'abc.' | tr '[:lower:].' '[:upper:]x' > out || fail=1 +echo 'ABCx' > exp +compare exp out || fail=1 + +# Before coreutils 8.6 the disparate number of upper and lower +# characters in some locales, triggered abort()s and invalid behavior +export LC_ALL=en_US.ISO-8859-1 + +if test "$(locale charmap 2>/dev/null)" = ISO-8859-1; then + # Up to coreutils-6.9.91, this would fail with the diagnostic: + # tr: misaligned [:upper:] and/or [:lower:] construct + # with LC_CTYPE=en_US.ISO-8859-1. + tr '[:upper:]' '[:lower:]' < /dev/null || fail=1 + + tr '[:upper:] ' '[:lower:]' < /dev/null 2>out && fail=1 + echo 'tr: when translating with string1 longer than string2, +the latter string must not end with a character class' > exp + compare exp out || fail=1 + + # Ensure when there are a different number of elements + # in each string, we validate the case mapping correctly + echo 'abc.xyz' | + tr 'ab[:lower:]' '0-1[:upper:]' > out || fail=1 + echo 'ABC.XYZ' > exp + compare exp out || fail=1 + + # Ensure we extend string2 appropriately + echo 'ABC- XYZ' | + tr '[:upper:]- ' '[:lower:]_' > out || fail=1 + echo 'abc__xyz' > exp + compare exp out || fail=1 + + # Ensure the size of the case classes are accounted + # for as a unit. + echo 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | + tr '[:upper:]A-B' '[:lower:]0' >out || fail=1 + echo '00cdefghijklmnopqrstuvwxyz' > exp + compare exp out || fail=1 + + # Ensure the size of the case classes are accounted + # for as a unit. + echo 'a' | + tr -t '[:lower:]a' '[:upper:]0' >out || fail=1 + echo '0' > exp + compare exp out || fail=1 + + # Ensure the size of the case classes are accounted + # for as a unit. + echo 'a' | + tr -t '[:lower:][:lower:]a' '[:lower:][:upper:]0' >out || fail=1 + echo '0' > exp + compare exp out || fail=1 +fi + +# coreutils 8.6 - 8.32 inclusive, would abort trying to validate the following +returns_ 1 tr -c '[:upper:]\000-\370' '[:lower:]' < /dev/null || fail=1 + +Exit $fail diff --git a/tests/misc/tr.pl b/tests/misc/tr.pl new file mode 100755 index 0000000..76bcfbd --- /dev/null +++ b/tests/misc/tr.pl @@ -0,0 +1,174 @@ +#!/usr/bin/perl + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $prog = 'tr'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $map_all_to_1 = + "$prog: when translating with complemented character classes,\n" + . "string2 must map all characters in the domain to one\n"; + +my @Tests = +( + ['1', qw(abcd '[]*]'), {IN=>'abcd'}, {OUT=>']]]]'}], + ['2', qw(abc '[%*]xyz'), {IN=>'abc'}, {OUT=>'xyz'}], + ['3', qw('' '[.*]'), {IN=>'abc'}, {OUT=>'abc'}], + + # Test --truncate-set1 behavior when string1 is longer than string2 + ['4', qw(-t abcd xy), {IN=>'abcde'}, {OUT=>'xycde'}], + # Test bsd behavior (the default) when string1 is longer than string2 + ['5', qw(abcd xy), {IN=>'abcde'}, {OUT=>'xyyye'}], + # Do it the posix way + ['6', qw(abcd 'x[y*]'), {IN=>'abcde'}, {OUT=>'xyyye'}], + ['7', qw(-s a-p '%[.*]$'), {IN=>'abcdefghijklmnop'}, {OUT=>'%.$'}], + ['8', qw(-s a-p '[.*]$'), {IN=>'abcdefghijklmnop'}, {OUT=>'.$'}], + ['9', qw(-s a-p '%[.*]'), {IN=>'abcdefghijklmnop'}, {OUT=>'%.'}], + ['a', qw(-s '[a-z]'), {IN=>'aabbcc'}, {OUT=>'abc'}], + ['b', qw(-s '[a-c]'), {IN=>'aabbcc'}, {OUT=>'abc'}], + ['c', qw(-s '[a-b]'), {IN=>'aabbcc'}, {OUT=>'abcc'}], + ['d', qw(-s '[b-c]'), {IN=>'aabbcc'}, {OUT=>'aabc'}], + ['e', qw(-s '[\0-\5]'), + {IN=>"\0\0a\1\1b\2\2\2c\3\3\3d\4\4\4\4e\5\5"}, {OUT=>"\0a\1b\2c\3d\4e\5"}], + # tests of delete + ['f', qw(-d '[=[=]'), {IN=>'[[[[[[[]]]]]]]]'}, {OUT=>']]]]]]]]'}], + ['g', qw(-d '[=]=]'), {IN=>'[[[[[[[]]]]]]]]'}, {OUT=>'[[[[[[['}], + ['h', qw(-d '[:xdigit:]'), {IN=>'0123456789acbdefABCDEF'}, {OUT=>''}], + ['i', qw(-d '[:xdigit:]'), {IN=>'w0x1y2z3456789acbdefABCDEFz'}, + {OUT=>'wxyzz'}], + ['j', qw(-d '[:digit:]'), {IN=>'0123456789'}, {OUT=>''}], + ['k', qw(-d '[:digit:]'), + {IN=>'a0b1c2d3e4f5g6h7i8j9k'}, {OUT=>'abcdefghijk'}], + ['l', qw(-d '[:lower:]'), {IN=>'abcdefghijklmnopqrstuvwxyz'}, {OUT=>''}], + ['m', qw(-d '[:upper:]'), {IN=>'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}, {OUT=>''}], + ['n', qw(-d '[:lower:][:upper:]'), + {IN=>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'}, {OUT=>''}], + ['o', qw(-d '[:alpha:]'), + {IN=>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'}, {OUT=>''}], + ['p', qw(-d '[:alnum:]'), + {IN=>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'}, + {OUT=>''}], + ['q', qw(-d '[:alnum:]'), + {IN=>'.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.'}, + {OUT=>'..'}], + ['r', qw(-ds '[:alnum:]' .), + {IN=>'.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.'}, + {OUT=>'.'}], + + # The classic example, with string2 BSD-style + ['s', qw(-cs '[:alnum:]' '\n'), + {IN=>'The big black fox jumped over the fence.'}, + {OUT=>"The\nbig\nblack\nfox\njumped\nover\nthe\nfence\n"}], + + # The classic example, POSIX-style + ['t', qw(-cs '[:alnum:]' '[\n*]'), + {IN=>'The big black fox jumped over the fence.'}, + {OUT=>"The\nbig\nblack\nfox\njumped\nover\nthe\nfence\n"}], + ['u', qw(-ds b a), {IN=>'aabbaa'}, {OUT=>'a'}], + ['v', qw(-ds '[:xdigit:]' Z), {IN=>'ZZ0123456789acbdefABCDEFZZ'}, {OUT=>'Z'}], + + # Try some data with 8th bit set in case something is mistakenly + # sign-extended. + ['w', qw(-ds '\350' '\345'), + {IN=>"\300\301\377\345\345\350\345"}, + {OUT=>"\300\301\377\345"}], + ['x', qw(-s abcdefghijklmn '[:*016]'), + {IN=>'abcdefghijklmnop'}, {OUT=>':op'}], + ['y', qw(-d a-z), {IN=>'abc $code'}, {OUT=>' $'}], + ['z', qw(-ds a-z '$.'), {IN=>'a.b.c $$$$code\\'}, {OUT=>'. $\\'}], + + # Make sure that a-a is accepted. + ['range-a-a', qw(a-a z), {IN=>'abc'}, {OUT=>'zbc'}], + # + ['null', qw(a ''), {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR=>"$prog: when not truncating set1, string2 must be non-empty\n"}], + ['upcase', qw('[:lower:]' '[:upper:]'), + {IN=>'abcxyzABCXYZ'}, + {OUT=>'ABCXYZABCXYZ'}], + ['dncase', qw('[:upper:]' '[:lower:]'), + {IN=>'abcxyzABCXYZ'}, + {OUT=>'abcxyzabcxyz'}], + # + ['rep-cclass', qw('a[=*2][=c=]' xyyz), {IN=>'a=c'}, {OUT=>'xyz'}], + ['rep-1', qw('[:*3][:digit:]' a-m), {IN=>':1239'}, {OUT=>'cefgm'}], + ['rep-2', qw('a[b*512]c' '1[x*]2'), {IN=>'abc'}, {OUT=>'1x2'}], + ['rep-3', qw('a[b*513]c' '1[x*]2'), {IN=>'abc'}, {OUT=>'1x2'}], + # Another couple octal repeat count tests. + ['o-rep-1', qw('[b*08]' '[x*]'), {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR=>"$prog: invalid repeat count '08' in [c*n] construct\n"}], + ['o-rep-2', qw('[b*010]cd' '[a*7]BC[x*]'), {IN=>'bcd'}, {OUT=>'BCx'}], + + ['esc', qw('a\-z' A-Z), {IN=>'abc-z'}, {OUT=>'AbcBC'}], + ['bs-055', qw('a\055b' def), {IN=>"a\055b"}, {OUT=>'def'}], + ['bs-at-end', qw('\\' x), {IN=>"\\"}, {OUT=>'x'}, + {ERR=>"$prog: warning: an unescaped backslash at end of " + . "string is not portable\n"}], + + # + # From Ross + ['ross-0a', qw(-cs '[:upper:]' 'X[Y*]'), {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR=>$map_all_to_1}], + ['ross-0b', qw(-cs '[:cntrl:]' 'X[Y*]'), {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR=>$map_all_to_1}], + ['ross-1a', qw(-cs '[:upper:]' '[X*]'), + {IN=>'AMZamz123.-+AMZ'}, {OUT=>'AMZXAMZ'}], + ['ross-1b', qw(-cs '[:upper:][:digit:]' '[Z*]'), {IN=>''}, {OUT=>''}], + ['ross-2', qw(-dcs '[:lower:]' n-rs-z), + {IN=>'amzAMZ123.-+amz'}, {OUT=>'amzamz'}], + ['ross-3', qw(-ds '[:xdigit:]' '[:alnum:]'), + {IN=>'.ZABCDEFGzabcdefg.0123456788899.GG'}, {OUT=>'.ZGzg..G'}], + ['ross-4', qw(-dcs '[:alnum:]' '[:digit:]'), {IN=>''}, {OUT=>''}], + ['ross-5', qw(-dc '[:lower:]'), {IN=>''}, {OUT=>''}], + ['ross-6', qw(-dc '[:upper:]'), {IN=>''}, {OUT=>''}], + + # Ensure that these fail. + # Prior to 2.0.20, each would evoke a failed assertion. + ['empty-eq', qw('[==]' x), {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR=>"$prog: missing equivalence class character '[==]'\n"}], + ['empty-cc', qw('[::]' x), {IN=>''}, {OUT=>''}, {EXIT=>1}, + {ERR=>"$prog: missing character class name '[::]'\n"}], + + # Weird repeat counts. + ['repeat-bs-9', qw(abc '[b*\9]'), {IN=>'abcd'}, {OUT=>'[b*d'}], + ['repeat-0', qw(abc '[b*0]'), {IN=>'abcd'}, {OUT=>'bbbd'}], + ['repeat-zeros', qw(abc '[b*00000000000000000000]'), + {IN=>'abcd'}, {OUT=>'bbbd'}], + ['repeat-compl', qw(-c '[a*65536]\n' '[b*]'), {IN=>'abcd'}, {OUT=>'abbb'}], + ['repeat-xC', qw(-C '[a*65536]\n' '[b*]'), {IN=>'abcd'}, {OUT=>'abbb'}], + + # From Glenn Fowler. + ['fowler-1', qw(ah -H), {IN=>'aha'}, {OUT=>'-H-'}], + + # Up to coreutils-6.9, this would provoke a failed assertion. + ['no-abort-1', qw(-c a '[b*256]'), {IN=>'abc'}, {OUT=>'abb'}], +); + +@Tests = triple_test \@Tests; + +# tr takes its input only from stdin, not from a file argument, so +# remove the tests that provide file arguments and keep only the ones +# generated by triple_test (identifiable by their .r and .p suffixes). +@Tests = grep {$_->[0] =~ /\.[pr]$/} @Tests; + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/truncate-dangling-symlink.sh b/tests/misc/truncate-dangling-symlink.sh new file mode 100755 index 0000000..80a6a24 --- /dev/null +++ b/tests/misc/truncate-dangling-symlink.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# Make sure truncate can create a file through a dangling symlink. + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + +ln -s truncate-target t-symlink + +truncate -s0 t-symlink || fail=1 + +test -f truncate-target || fail=1 + +Exit $fail diff --git a/tests/misc/truncate-dir-fail.sh b/tests/misc/truncate-dir-fail.sh new file mode 100755 index 0000000..e74cd46 --- /dev/null +++ b/tests/misc/truncate-dir-fail.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Make sure truncate fails for a directory. + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + +# truncate on dir not allowed +returns_ 1 truncate -s+0 . || fail=1 + +Exit $fail diff --git a/tests/misc/truncate-fail-diag.sh b/tests/misc/truncate-fail-diag.sh new file mode 100755 index 0000000..6e11d15 --- /dev/null +++ b/tests/misc/truncate-fail-diag.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# make sure truncate gives reasonable diagnostics +# Note open() checks for trailing '/' before checking for existence +# open (".", O_CREAT & (O_WRONLY | O_RDWR), ...) -> EISDIR +# open ("missing/", O_CREAT & (O_WRONLY | O_RDWR), ...) -> EISDIR +# open ("missing/file", O_CREAT & (O_WRONLY | O_RDWR), ...) -> ENOENT + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate +skip_if_root_ + + +d1=no + +dir=$d1/such-dir +truncate -s0 $dir > out 2>&1 && fail=1 +cat <<EOF > exp +truncate: cannot open '$dir' for writing: No such file or directory +EOF +compare exp out || fail=1 + +dir=$d1/ +truncate -s0 $dir > out 2>&1 && fail=1 +#The following can be returned at least +#truncate: cannot open '$dir' for writing: Not a directory +#truncate: cannot open '$dir' for writing: Is a directory + +Exit $fail diff --git a/tests/misc/truncate-fifo.sh b/tests/misc/truncate-fifo.sh new file mode 100755 index 0000000..4c91f8e --- /dev/null +++ b/tests/misc/truncate-fifo.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Make sure truncate works on fifos without hanging + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + +mkfifo_or_skip_ fifo + +timeout 10 truncate -s0 fifo +test "$?" = 124 && fail=1 + +Exit $fail diff --git a/tests/misc/truncate-no-create-missing.sh b/tests/misc/truncate-no-create-missing.sh new file mode 100755 index 0000000..2b1802c --- /dev/null +++ b/tests/misc/truncate-no-create-missing.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Ensure that truncate -c no-such-file doesn't fail. + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + + +# truncate -c no-such-file should not fail. +truncate -s0 -c no-such-file || fail=1 + +Exit $fail diff --git a/tests/misc/truncate-overflow.sh b/tests/misc/truncate-overflow.sh new file mode 100755 index 0000000..d06ad57 --- /dev/null +++ b/tests/misc/truncate-overflow.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# Validate truncate integer overflow + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate +getlimits_ + + +# -= overflow +truncate -s-1 create-zero-len-file || fail=1 + +echo > non-empty-file + +# signed overflow +returns_ 1 truncate -s$OFF_T_OFLOW file || fail=1 + +# += signed overflow +returns_ 1 truncate -s+$OFF_T_MAX non-empty-file || fail=1 + +# *= signed overflow +IO_BLOCK_OFLOW=$(expr $OFF_T_MAX / $(stat -f -c%s .) + 1) +returns_ 1 truncate --io-blocks --size=$IO_BLOCK_OFLOW file || fail=1 + +Exit $fail diff --git a/tests/misc/truncate-owned-by-other.sh b/tests/misc/truncate-owned-by-other.sh new file mode 100755 index 0000000..0b3836f --- /dev/null +++ b/tests/misc/truncate-owned-by-other.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# Demonstrate that "truncate -s0 writable-but-owned-by-other" works. + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + +require_root_ + +# Create a file owned by root, and writable by $NON_ROOT_USERNAME. +echo > root-owned || framework_failure_ +chgrp +$NON_ROOT_GID . root-owned || framework_failure_ +chmod g+w root-owned + +# Ensure that the current directory is searchable by $NON_ROOT_USERNAME. +chmod g+x . + +chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ + truncate -s0 root-owned || fail=1 + +Exit $fail diff --git a/tests/misc/truncate-parameters.sh b/tests/misc/truncate-parameters.sh new file mode 100755 index 0000000..826ea63 --- /dev/null +++ b/tests/misc/truncate-parameters.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# Validate truncate parameter combinations + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + + +# must specify at least 1 file +returns_ 1 truncate --size=0 || fail=1 + +# must specify size. don't default to 0 +returns_ 1 truncate file || fail=1 + +# mixture of absolute size & reference not allowed +returns_ 1 truncate --size=0 --reference=file file || fail=1 + +# blocks without size is not valid +returns_ 1 truncate --io-blocks --reference=file file || fail=1 + +# must specify valid numbers +returns_ 1 truncate --size="invalid" file || fail=1 + +# spaces not significant around size +returns_ 1 truncate --size="> -1" file || fail=1 +truncate --size=" >1" file || fail=1 #file now 1 +truncate --size=" +1" file || fail=1 #file now 2 +test $(stat --format %s file) = 2 || fail=1 + +# reference allowed with relative size +truncate --size=" +1" -r file file || fail=1 #file now 3 +test $(stat --format %s file) = 3 || fail=1 + +# reference allowed alone also +truncate -r file file || fail=1 #file still 3 +test $(stat --format %s file) = 3 || fail=1 +truncate -r file file2 || fail=1 #file2 now 3 +test $(stat --format %s file2) = 3 || fail=1 + +Exit $fail diff --git a/tests/misc/truncate-relative.sh b/tests/misc/truncate-relative.sh new file mode 100755 index 0000000..9f7a2bb --- /dev/null +++ b/tests/misc/truncate-relative.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# Validate truncate relative sizes + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + + +# mixture of relative modifiers not allowed +returns_ 1 truncate --size="+>0" file || fail=1 + +# mixture of relative modifiers not allowed +returns_ 1 truncate --size=">+0" file || fail=1 + +# division by zero +returns_ 1 truncate --size="/0" file || fail=1 + +# division by zero +returns_ 1 truncate --size="%0" file || fail=1 + +Exit $fail diff --git a/tests/misc/tsort.pl b/tests/misc/tsort.pl new file mode 100755 index 0000000..7580180 --- /dev/null +++ b/tests/misc/tsort.pl @@ -0,0 +1,66 @@ +#!/usr/bin/perl +# Test "tsort". + +# Copyright (C) 1999-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + ['cycle-1', {IN => {f => "t b\nt s\ns t\n"}}, {OUT => "s\nt\nb\n"}, + {EXIT => 1}, + {ERR => "tsort: f: input contains a loop:\ntsort: s\ntsort: t\n"} ], + ['cycle-2', {IN => {f => "t x\nt s\ns t\n"}}, {OUT => "s\nt\nx\n"}, + {EXIT => 1}, + {ERR => "tsort: f: input contains a loop:\ntsort: s\ntsort: t\n"} ], + + ['posix-1', {IN => "a b c c d e\ng g\nf g e f\nh h\n"}, + {OUT => "a\nc\nd\nh\nb\ne\nf\ng\n"}], + ['posix-2', {IN => "b a\nd c\nz h x h r h\n"}, + {OUT => "b\nd\nr\nx\nz\na\nc\nh\n"}], + + ['linear-1', {IN => "a b b c c d d e e f f g\n"}, + {OUT => "a\nb\nc\nd\ne\nf\ng\n"}], + + ['tree-1', {IN => "a b b c c d d e e f f g\nc x x y y z\n"}, + {OUT => "a\nb\nc\nx\nd\ny\ne\nz\nf\ng\n"}], + ['tree-2', {IN => "a b b c c d d e e f f g\nc x x y y z\nf r r s s t\n"}, + {OUT => "a\nb\nc\nx\nd\ny\ne\nz\nf\nr\ng\ns\nt\n"}], + + # Before coreutils-5.0.1, given an odd number of input tokens, + # tsort would accept that and treat the input as if an additional + # copy of the final token were appended. + ['odd', {IN => "a\n"}, + {EXIT => 1}, + {ERR => "tsort: odd.1: input contains an odd number of tokens\n"}], + + ['only-one', {IN => {f => ""}}, {IN => {g => ""}}, + {EXIT => 1}, + {ERR => "tsort: extra operand 'g'\n" + . "Try 'tsort --help' for more information.\n"}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = 'tsort'; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/tty-eof.pl b/tests/misc/tty-eof.pl new file mode 100755 index 0000000..291460f --- /dev/null +++ b/tests/misc/tty-eof.pl @@ -0,0 +1,114 @@ +#!/usr/bin/perl +# Test whether programs exit upon a single EOF from a tty. +# Ensure that e.g., cat exits upon a single EOF (^D) from a tty. +# Do the same for all programs that can read stdin, +# require no arguments and that write to standard output. + +# Copyright (C) 2003-2022 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 <https://www.gnu.org/licenses/>. + +use strict; +(my $ME = $0) =~ s|.*/||; + +# Some older versions of Expect.pm (e.g. 1.07) lack the log_user method, +# so check for that, too. +eval { require Expect; Expect->require_version('1.11') }; +$@ + and CuSkip::skip "$ME: this script requires Perl's Expect package >=1.11\n"; + +{ + my $fail = 0; + my @stdin_reading_commands = qw( + b2sum + base32 + base64 + cat + cksum + dd + expand + fmt + fold + head + md5sum + nl + od + paste + pr + ptx + sha1sum + sha224sum + sha256sum + sha384sum + sha512sum + shuf + sort + sum + tac + tail + tee + tsort + unexpand + uniq + wc + ); + my $stderr = 'tty-eof.err'; + foreach my $cmd ((@stdin_reading_commands), 'basenc --z85', 'cut -f2', + 'numfmt --invalid=ignore') + { + my $exp = new Expect; + $exp->log_user(0); + $ENV{built_programs} =~ /\b$cmd\b/ || next; + $exp->spawn("$cmd 2> $stderr") + or (warn "$ME: cannot run '$cmd': $!\n"), $fail=1, next; + # No input for cut -f2. + $cmd =~ /^cut/ + or $exp->send("a b\n"); + $exp->send("\cD"); # This is Control-D. FIXME: what if that's not EOF? + $exp->expect (0, '-re', "^a b\\r?\$"); + my $found = $exp->expect (1, '-re', "^.+\$"); + $found and warn "F: $found: " . $exp->exp_match () . "\n"; + $exp->expect(10, 'eof'); + # Expect no output from cut, since we gave it no input. + defined $found || $cmd =~ /^cut/ + or (warn "$ME: $cmd didn't produce expected output\n"), + $fail=1, next; + defined $exp->exitstatus + or (warn "$ME: $cmd didn't exit after ^D from standard input\n"), + $fail=1, next; + my $s = $exp->exitstatus; + $s == 0 + or (warn "$ME: $cmd exited with status $s (expected 0)\n"), + $fail=1; + $exp->hard_close(); + + # dd normally writes to stderr. If it exits successfully, we're done. + $cmd eq 'dd' && $s == 0 + and next; + + if (-s $stderr) + { + warn "$ME: $cmd wrote to stderr:\n"; + system "cat $stderr"; + $fail = 1; + } + } + continue + { + unlink $stderr + or warn "$ME: failed to remove stderr file from $cmd, $stderr: $!\n"; + } + + exit $fail +} diff --git a/tests/misc/tty.sh b/tests/misc/tty.sh new file mode 100755 index 0000000..c87ec59 --- /dev/null +++ b/tests/misc/tty.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# Test 'tty'. + +# Copyright 2017-2022 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 <https://www.gnu.org/licenses/>. + +# Make sure there's a tty on stdin. +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tty + +if test -t 0; then + tty || fail=1 + tty -s || fail=1 +fi + +returns_ 1 tty </dev/null || fail=1 +returns_ 1 tty -s </dev/null || fail=1 +returns_ 1 tty <&- 2>/dev/null || fail=1 +returns_ 1 tty -s <&- || fail=1 + +returns_ 2 tty a || fail=1 +returns_ 2 tty -s a || fail=1 + +if test -w /dev/full && test -c /dev/full; then + if test -t 0; then + returns_ 3 tty >/dev/full || fail=1 + fi + returns_ 3 tty </dev/null >/dev/full || fail=1 +fi + +Exit $fail diff --git a/tests/misc/unexpand.pl b/tests/misc/unexpand.pl new file mode 100755 index 0000000..2e1906f --- /dev/null +++ b/tests/misc/unexpand.pl @@ -0,0 +1,135 @@ +#!/usr/bin/perl +# Test "unexpand". + +# Copyright (C) 2000-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $limits = getlimits (); + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $prog = 'unexpand'; + +my @Tests = + ( + ['a1', {IN=> ' 'x 1 ."y\n"}, {OUT=> ' 'x 1 ."y\n"}], + ['a2', {IN=> ' 'x 2 ."y\n"}, {OUT=> ' 'x 2 ."y\n"}], + ['a3', {IN=> ' 'x 3 ."y\n"}, {OUT=> ' 'x 3 ."y\n"}], + ['a4', {IN=> ' 'x 4 ."y\n"}, {OUT=> ' 'x 4 ."y\n"}], + ['a5', {IN=> ' 'x 5 ."y\n"}, {OUT=> ' 'x 5 ."y\n"}], + ['a6', {IN=> ' 'x 6 ."y\n"}, {OUT=> ' 'x 6 ."y\n"}], + ['a7', {IN=> ' 'x 7 ."y\n"}, {OUT=> ' 'x 7 ."y\n"}], + ['a8', {IN=> ' 'x 8 ."y\n"}, {OUT=> "\ty\n"}], + + ['aa-1', '-a', {IN=> 'w'.' 'x 1 ."y\n"}, {OUT=> 'w'.' 'x 1 ."y\n"}], + ['aa-2', '-a', {IN=> 'w'.' 'x 2 ."y\n"}, {OUT=> 'w'.' 'x 2 ."y\n"}], + ['aa-3', '-a', {IN=> 'w'.' 'x 3 ."y\n"}, {OUT=> 'w'.' 'x 3 ."y\n"}], + ['aa-4', '-a', {IN=> 'w'.' 'x 4 ."y\n"}, {OUT=> 'w'.' 'x 4 ."y\n"}], + ['aa-5', '-a', {IN=> 'w'.' 'x 5 ."y\n"}, {OUT=> 'w'.' 'x 5 ."y\n"}], + ['aa-6', '-a', {IN=> 'w'.' 'x 6 ."y\n"}, {OUT=> 'w'.' 'x 6 ."y\n"}], + ['aa-7', '-a', {IN=> 'w'.' 'x 7 ."y\n"}, {OUT=> "w\ty\n"}], + ['aa-8', '-a', {IN=> 'w'.' 'x 8 ."y\n"}, {OUT=> "w\t y\n"}], + + ['b-1', '-t', '2,4', {IN=> " ."}, {OUT=>"\t\t ."}], + # These would infloop prior to textutils-2.0d. + + ['infloop-1', '-t', '1,2', {IN=> " \t\t .\n"}, {OUT=>"\t\t\t .\n"}], + ['infloop-2', '-t', '4,5', {IN=> ' 'x4 . "\t\t \n"}, {OUT=>"\t\t\t \n"}], + ['infloop-3', '-t', '2,3', {IN=> "x \t\t \n"}, {OUT=>"x\t\t\t \n"}], + ['infloop-4', '-t', '1,2', {IN=> " \t\t \n"}, {OUT=>"\t\t\t \n"}], + ['c-1', '-t', '1,2', {IN=> "x\t\t .\n"}, {OUT=>"x\t\t .\n"}], + + # -t implies -a + # Feature addition (--first-only) prompted by a report from Jie Xu. + ['tabs-1', qw(-t 3), {IN=> " a b\n"}, {OUT=>"\ta\tb\n"}], + ['tabs-2', qw(-t 3 --first-only), {IN=> " a b\n"}, {OUT=>"\ta b\n"}], + + # blanks + ['blanks-1', qw(-t 1), {IN=> " b c d\n"}, {OUT=> "\tb\t\tc\t\t\td\n"}], + ['blanks-2', qw(-t 1), {IN=> "a \n"}, {OUT=> "a \n"}], + ['blanks-3', qw(-t 1), {IN=> "a \n"}, {OUT=> "a\t\t\n"}], + ['blanks-4', qw(-t 1), {IN=> "a \n"}, {OUT=> "a\t\t\t\n"}], + ['blanks-5', qw(-t 1), {IN=> "a "}, {OUT=> "a "}], + ['blanks-6', qw(-t 1), {IN=> "a "}, {OUT=> "a\t\t"}], + ['blanks-7', qw(-t 1), {IN=> "a "}, {OUT=> "a\t\t\t"}], + ['blanks-8', qw(-t 1), {IN=> " a a a\n"}, {OUT=> "\ta a\t\ta\n"}], + ['blanks-9', qw(-t 2), {IN=> " a a a\n"}, {OUT=> "\t a\ta\t a\n"}], + ['blanks-10', '-t', '3,4', {IN=> "0 2 4 6\t8\n"}, {OUT=> "0 2 4 6\t8\n"}], + ['blanks-11', '-t', '3,4', {IN=> " 4\n"}, {OUT=> "\t\t4\n"}], + ['blanks-12', '-t', '3,4', {IN=> "01 4\n"}, {OUT=> "01\t\t4\n"}], + ['blanks-13', '-t', '3,4', {IN=> "0 4\n"}, {OUT=> "0\t\t4\n"}], + + # POSIX says spaces should only follow tabs. Also a single + # trailing space is not converted to a tab, when before + # a field starting with non blanks + ['posix-1', '-a', {IN=> "1234567 \t1\n"}, {OUT=>"1234567\t\t1\n"}], + ['posix-2', '-a', {IN=> "1234567 \t1\n"}, {OUT=>"1234567\t\t1\n"}], + ['posix-3', '-a', {IN=> "1234567 \t1\n"}, {OUT=>"1234567\t\t1\n"}], + ['posix-4', '-a', {IN=> "1234567\t1\n"}, {OUT=>"1234567\t1\n"}], + ['posix-5', '-a', {IN=> "1234567 1\n"}, {OUT=>"1234567\t 1\n"}], + ['posix-6', '-a', {IN=> "1234567 1\n"}, {OUT=>"1234567 1\n"}], + + # It is debatable whether this test should require an environment + # setting of e.g., _POSIX2_VERSION=1. + ['obs-ovflo', "-$limits->{UINTMAX_OFLOW}", {IN=>''}, {OUT=>''}, + {EXIT => 1}, {ERR => "$prog: tab stop value is too large\n"}], + + + # Test input with backspaces '\b' ('bs1' is the baseline, without \b) + # Note: If users report errors in these tests, copy&pasting results from + # their terminate output might be confusing due to '\b' overriding + # characters. For details see '\b' tests in 'expand.pl'. + ['bs1', '-a -t4', {IN=>"aa c\n"}, {OUT=>"aa\tc\n"}], + ['bs2', '-a -t4', {IN=>"aa\b c\n"}, {OUT=>"aa\b c\n"}], + ['bs3', '-a -t4', {IN=>"aa\b c\n"}, {OUT=>"aa\b\tc\n"}], + ['bs4', '-a -t3', {IN=>"aa\b c\n"}, {OUT=>"aa\b\tc\n"}], + + # Undocumented feature: + # treat "unexpand -7" as "unexpand --first-only --tabs 7" , + # and "unexpand -90" as "unexpand --first-only --tabs 90", + ['u1', '-a -3', {IN=>"a b c"}, {OUT=>"a\tb\tc"}], + ['u2', '-a -4,9', {IN=>"a b c"}, {OUT=>"a\tb\tc"}], + ['u3', '-a -11', {IN=>"a b"}, {OUT=>"a\tb"}], + # Test all digits (for full code coverage) + ['u4', '-a -2,6', {IN=>"a b c"}, {OUT=>"a b\tc"}], + ['u5', '-a -7', {IN=>"a b"}, {OUT=>"a\tb"}], + ['u6', '-a -8', {IN=>"a b"}, {OUT=>"a\tb"}], + # This syntax is handled internally as "-3, -9" + ['u7', '-a -3,9', {IN=>"a b c"}, {OUT=>"a\tb\tc"}], + # Default (without -a) is --first-only: + ['u8', '-3', {IN=>" a b"}, {OUT=>"\ta b"}], + + # Arguably this should minimize translation as is done on Solaris. + # I.e., not modify the input. But since the result is equivalent, + # and to be consistent in output with older versions, we output + # a '\t' rather than a space for the second tab position. + # For more detailed comparison with other implementations see: + # https://lists.gnu.org/r/coreutils/2016-06/msg00015.html + # https://lists.gnu.org/r/coreutils/2016-07/msg00011.html + ['ts1', '-t8,9', {IN=>"x\t \t y\n"}, {OUT=>"x\t\t\t y\n"}], + # There is no ambiguity here. This should always be the output. + ['ts2', '-t5,8', {IN=>"x\t \t y\n"}, {OUT=>"x\t\t y\n"}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/uniq-collate.sh b/tests/misc/uniq-collate.sh new file mode 100755 index 0000000..8f2cfcf --- /dev/null +++ b/tests/misc/uniq-collate.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# before coreutils-8.32, uniq would not distinguish +# items which compared equal with strcoll() +# So ensure we avoid strcoll() for the following cases. + +# Copyright (C) 2020-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ uniq printf + +gen_input() +{ + env LC_ALL=$LOCALE_FR_UTF8 printf "$@" > in || framework_failure_ +} + +# strcoll() used to return 0 comparing the following strings +# which was fixed somewhere between glibc-2.22 and glibc-2.30 +gen_input '%s\n' 'ⁿᵘˡˡ' 'ܥܝܪܐܩ' +test $(LC_ALL=$LOCALE_FR_UTF8 uniq < in | wc -l) = 2 || fail=1 + +# normalization in strcoll is inconsistent across platforms. +# glibc based systems at least do _not_ normalize in strcoll, +# while cygwin systems for example may do so. +# á composed and decomposed, are generally not compared equal +gen_input '\u00E1\na\u0301\n' +test $(LC_ALL=$LOCALE_FR_UTF8 uniq < in | wc -l) = 2 || fail=1 +# Similarly with the following equivalent hangul characters +gen_input '\uAC01\n\u1100\u1161\u11A8\n' +test $(LC_ALL=ko_KR.utf8 uniq < in | wc -l) = 2 || fail=1 + +# Note if running in the wrong locale, +# strcoll may indicate the strings match when they don't. +# I.e., cjk and hangul will now work even if +# uniq is running in the wrong locale +# hangul (ko_KR.utf8) +gen_input '\uAC00\n\uAC01\n' +test $(LC_ALL=en_US.utf8 uniq < in | wc -l) = 2 || fail=1 +# CJK (zh_CN.utf8) +gen_input '\u3400\n\u3401\n' +test $(LC_ALL=en_US.utf8 uniq < in | wc -l) = 2 || fail=1 + +# Note strcoll() ignores certain characters, +# but not if the strings are otherwise equal. +# I.e., the following on glibc-2.30 at least, +# as expected, does not print a single item, +# but testing here for illustration +gen_input ',a\n.a\n' +test $(LC_ALL=$LOCALE_FR_UTF8 uniq < in | wc -l) = 2 || fail=1 + +Exit $fail diff --git a/tests/misc/uniq-perf.sh b/tests/misc/uniq-perf.sh new file mode 100755 index 0000000..41cde32 --- /dev/null +++ b/tests/misc/uniq-perf.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# before coreutils-8.10, seq 100000|uniq -f 10000000000 would run for days + +# Copyright (C) 2011-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ uniq + +seq 100 > in || fail=1 +timeout 10 uniq -f 10000000000 in || fail=1 + +Exit $fail diff --git a/tests/misc/uniq.pl b/tests/misc/uniq.pl new file mode 100755 index 0000000..aa163cd --- /dev/null +++ b/tests/misc/uniq.pl @@ -0,0 +1,272 @@ +#!/usr/bin/perl +# Test uniq. + +# Copyright (C) 2008-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $limits = getlimits (); + +my $prog = 'uniq'; +my $try = "Try '$prog --help' for more information.\n"; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# When possible, create a "-z"-testing variant of each test. +sub add_z_variants($) +{ + my ($tests) = @_; + my @new; + TEST: + foreach my $t (@$tests) + { + push @new, $t; + + # skip the obsolete-syntax tests + $t->[0] =~ /^obs-plus/ + and next; + + my @args; + my @list_of_hash; + + foreach my $e (@$t) + { + !ref $e + and push (@args, $e), next; + + ref $e && ref $e eq 'HASH' + or (warn "$0: $t->[0]: unexpected entry type\n"), next; + my $tmp = $e; + foreach my $k (qw(IN OUT)) + { + my $val = $e->{$k}; + # skip any test whose input or output already contains a NUL byte + if (defined $val) + { + $val =~ /\0/ + and next TEST; + + # Convert each NL in input or output to \0. + $val =~ s/\n/\0/g; + $tmp = {$k => $val}; + last; + } + } + push @list_of_hash, $tmp; + } + + shift @args; # discard test name + + # skip any test that uses the -z option + grep /z/, @args + and next; + + push @new, ["$t->[0]-z", '-z', @args, @list_of_hash]; + } + return @new; +} + +my @Tests = +( + ['1', '', {IN=>''}, {OUT=>''}], + ['2', '', {IN=>"a\na\n"}, {OUT=>"a\n"}], + ['3', '', {IN=>"a\na"}, {OUT=>"a\n"}], + ['4', '', {IN=>"a\nb"}, {OUT=>"a\nb\n"}], + ['5', '', {IN=>"a\na\nb"}, {OUT=>"a\nb\n"}], + ['6', '', {IN=>"b\na\na\n"}, {OUT=>"b\na\n"}], + ['7', '', {IN=>"a\nb\nc\n"}, {OUT=>"a\nb\nc\n"}], + + # Ensure that newlines are not interpreted with -z. + ['2z', '-z', {IN=>"a\na\n"}, {OUT=>"a\na\n\0"}], + ['3z', '-z', {IN=>"a\na"}, {OUT=>"a\na\0"}], + ['4z', '-z', {IN=>"a\nb"}, {OUT=>"a\nb\0"}], + ['5z', '-z', {IN=>"a\na\nb"}, {OUT=>"a\na\nb\0"}], + ['10z', '-z -f1', {IN=>"a\nb\n\0c\nb\n\0"}, {OUT=>"a\nb\n\0"}], + ['20z', '-dz', {IN=>"a\na\n"}, {OUT=>""}], + + # Make sure that eight bit characters work + ['8', '', {IN=>"ö\nv\n"}, {OUT=>"ö\nv\n"}], + # Test output of -u option; only unique lines + ['9', '-u', {IN=>"a\na\n"}, {OUT=>""}], + ['10', '-u', {IN=>"a\nb\n"}, {OUT=>"a\nb\n"}], + ['11', '-u', {IN=>"a\nb\na\n"}, {OUT=>"a\nb\na\n"}], + ['12', '-u', {IN=>"a\na\n"}, {OUT=>""}], + ['13', '-u', {IN=>"a\na\n"}, {OUT=>""}], + #['5', '-u', "a\na\n", "", 0], + # Test output of -d option; only repeated lines + ['20', '-d', {IN=>"a\na\n"}, {OUT=>"a\n"}], + ['21', '-d', {IN=>"a\nb\n"}, {OUT=>""}], + ['22', '-d', {IN=>"a\nb\na\n"}, {OUT=>""}], + ['23', '-d', {IN=>"a\na\nb\n"}, {OUT=>"a\n"}], + # Check the key options + # If we skip over fields or characters, is the output deterministic? + ['obs30', '-1', {IN=>"a a\nb a\n"}, {OUT=>"a a\n"}], + ['31', qw(-f 1), {IN=>"a a\nb a\n"}, {OUT=>"a a\n"}], + ['32', qw(-f 1), {IN=>"a a\nb b\n"}, {OUT=>"a a\nb b\n"}], + ['33', qw(-f 1), {IN=>"a a a\nb a c\n"}, {OUT=>"a a a\nb a c\n"}], + ['34', qw(-f 1), {IN=>"b a\na a\n"}, {OUT=>"b a\n"}], + ['35', qw(-f 2), {IN=>"a a c\nb a c\n"}, {OUT=>"a a c\n"}], + # Skip over characters. + ['obs-plus40', '+1', {IN=>"aaa\naaa\n"}, {OUT=>"aaa\n"}], + ['obs-plus41', '+1', {IN=>"baa\naaa\n"}, {OUT=>"baa\n"}], + ['42', qw(-s 1), {IN=>"aaa\naaa\n"}, {OUT=>"aaa\n"}], + ['43', qw(-s 2), {IN=>"baa\naaa\n"}, {OUT=>"baa\n"}], + ['obs-plus44', qw(+1 --), {IN=>"aaa\naaa\n"}, {OUT=>"aaa\n"}], + ['obs-plus45', qw(+1 --), {IN=>"baa\naaa\n"}, {OUT=>"baa\n"}], + # Skip over fields and characters + ['50', qw(-f 1 -s 1), {IN=>"a aaa\nb ab\n"}, {OUT=>"a aaa\nb ab\n"}], + ['51', qw(-f 1 -s 1), {IN=>"a aaa\nb aaa\n"}, {OUT=>"a aaa\n"}], + ['52', qw(-s 1 -f 1), {IN=>"a aaa\nb ab\n"}, {OUT=>"a aaa\nb ab\n"}], + ['53', qw(-s 1 -f 1), {IN=>"a aaa\nb aaa\n"}, {OUT=>"a aaa\n"}], + # Fixed in 2.0.15 + ['54', qw(-s 4), {IN=>"abc\nabcd\n"}, {OUT=>"abc\n"}], + # Supported in 2.0.15 + ['55', qw(-s 0), {IN=>"abc\nabcd\n"}, {OUT=>"abc\nabcd\n"}], + ['56', qw(-s 0), {IN=>"abc\n"}, {OUT=>"abc\n"}], + ['57', qw(-w 0), {IN=>"abc\nabcd\n"}, {OUT=>"abc\n"}], + # Only account for a number of characters + ['60', qw(-w 1), {IN=>"a a\nb a\n"}, {OUT=>"a a\nb a\n"}], + ['61', qw(-w 3), {IN=>"a a\nb a\n"}, {OUT=>"a a\nb a\n"}], + ['62', qw(-w 1 -f 1), {IN=>"a a a\nb a c\n"}, {OUT=>"a a a\n"}], + ['63', qw(-f 1 -w 1), {IN=>"a a a\nb a c\n"}, {OUT=>"a a a\n"}], + # The blank after field one is checked too + ['64', qw(-f 1 -w 4), {IN=>"a a a\nb a c\n"}, {OUT=>"a a a\nb a c\n"}], + ['65', qw(-f 1 -w 3), {IN=>"a a a\nb a c\n"}, {OUT=>"a a a\n"}], + # Make sure we don't break if the file contains \0 + ['90', '', {IN=>"a\0a\na\n"}, {OUT=>"a\0a\na\n"}], + # Check fields separated by tabs and by spaces + ['91', '', {IN=>"a\ta\na a\n"}, {OUT=>"a\ta\na a\n"}], + ['92', qw(-f 1), {IN=>"a\ta\na a\n"}, {OUT=>"a\ta\na a\n"}], + ['93', qw(-f 2), {IN=>"a\ta a\na a a\n"}, {OUT=>"a\ta a\n"}], + ['94', qw(-f 1), {IN=>"a\ta\na\ta\n"}, {OUT=>"a\ta\n"}], + # Check the count option; add tests for other options too + ['101', '-c', {IN=>"a\nb\n"}, {OUT=>" 1 a\n 1 b\n"}], + ['102', '-c', {IN=>"a\na\n"}, {OUT=>" 2 a\n"}], + # Check the local -D (--all-repeated) option + ['110', '-D', {IN=>"a\na\n"}, {OUT=>"a\na\n"}], + ['111', qw(-D -w1), {IN=>"a a\na b\n"}, {OUT=>"a a\na b\n"}], + ['112', qw(-D -c), {IN=>"a a\na b\n"}, {OUT=>""}, {EXIT=>1}, {ERR=> + "$prog: printing all duplicated lines and repeat counts is meaningless\n$try"} + ], + ['113', '--all-repeated=separate', {IN=>"a\na\n"}, {OUT=>"a\na\n"}], + ['114', '--all-repeated=separate', + {IN=>"a\na\nb\nc\nc\n"}, {OUT=>"a\na\n\nc\nc\n"}], + ['115', '--all-repeated=separate', + {IN=>"a\na\nb\nb\nc\n"}, {OUT=>"a\na\n\nb\nb\n"}], + ['116', '--all-repeated=prepend', {IN=>"a\na\n"}, {OUT=>"\na\na\n"}], + ['117', '--all-repeated=prepend', + {IN=>"a\na\nb\nc\nc\n"}, {OUT=>"\na\na\n\nc\nc\n"}], + ['118', '--all-repeated=prepend', {IN=>"a\nb\n"}, {OUT=>""}], + ['119', '--all-repeated=badoption', {IN=>"a\n"}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: invalid argument 'badoption' for '--all-repeated'\n" + . "Valid arguments are:\n" + . " - 'none'\n" + . " - 'prepend'\n" + . " - 'separate'\n" + . $try}], + # Check that -d and -u suppress all output, as POSIX requires. + ['120', qw(-d -u), {IN=>"a\na\n\b"}, {OUT=>""}], + ['121', "-d -u -w$limits->{UINTMAX_OFLOW}", {IN=>"a\na\n\b"}, {OUT=>""}], + ['122', "-d -u -w$limits->{SIZE_OFLOW}", {IN=>"a\na\n\b"}, {OUT=>""}], + # Check that --zero-terminated is synonymous with -z. + ['123', '--zero-terminated', {IN=>"a\na\nb"}, {OUT=>"a\na\nb\0"}], + ['124', '--zero-terminated', {IN=>"a\0a\0b"}, {OUT=>"a\0b\0"}], + # Check ignore-case + ['125', '', {IN=>"A\na\n"}, {OUT=>"A\na\n"}], + ['126', '-i', {IN=>"A\na\n"}, {OUT=>"A\n"}], + ['127', '--ignore-case', {IN=>"A\na\n"}, {OUT=>"A\n"}], + # Check grouping + ['128', '--group=prepend', {IN=>"a\na\nb\n"}, {OUT=>"\na\na\n\nb\n"}], + ['129', '--group=append', {IN=>"a\na\nb\n"}, {OUT=>"a\na\n\nb\n\n"}], + ['130', '--group=separate',{IN=>"a\na\nb\n"}, {OUT=>"a\na\n\nb\n"}], + # no explicit grouping = separate + ['131', '--group', {IN=>"a\na\nb\n"}, {OUT=>"a\na\n\nb\n"}], + ['132', '--group=both', {IN=>"a\na\nb\n"}, {OUT=>"\na\na\n\nb\n\n"}], + # Grouping in the special case of a single group + ['133', '--group=prepend', {IN=>"a\na\n"}, {OUT=>"\na\na\n"}], + ['134', '--group=append', {IN=>"a\na\n"}, {OUT=>"a\na\n\n"}], + ['135', '--group=separate',{IN=>"a\na\n"}, {OUT=>"a\na\n"}], + ['136', '--group', {IN=>"a\na\n"}, {OUT=>"a\na\n"}], + # Grouping with empty input - should never print anything + ['137', '--group=prepend', {IN=>""}, {OUT=>""}], + ['138', '--group=append', {IN=>""}, {OUT=>""}], + ['139', '--group=separate', {IN=>""}, {OUT=>""}], + ['140', '--group=both', {IN=>""}, {OUT=>""}], + # Grouping with other options - must fail + ['141', '--group -c', {IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: --group is mutually exclusive with -c/-d/-D/-u\n" . + "Try 'uniq --help' for more information.\n"}], + ['142', '--group -d', {IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: --group is mutually exclusive with -c/-d/-D/-u\n" . + "Try 'uniq --help' for more information.\n"}], + ['143', '--group -u', {IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: --group is mutually exclusive with -c/-d/-D/-u\n" . + "Try 'uniq --help' for more information.\n"}], + ['144', '--group -D', {IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: --group is mutually exclusive with -c/-d/-D/-u\n" . + "Try 'uniq --help' for more information.\n"}], + # Grouping with badoption + ['145', '--group=badoption',{IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: invalid argument 'badoption' for '--group'\n" . + "Valid arguments are:\n" . + " - 'prepend'\n" . + " - 'append'\n" . + " - 'separate'\n" . + " - 'both'\n" . + "Try '$prog --help' for more information.\n"}], +); + +# Locale related tests + +my $locale = $ENV{LOCALE_FR}; +if ( defined $locale && $locale ne 'none' ) + { + # I've only ever triggered the problem in a non-C locale. + + # See if isblank returns true for nbsp. + my $x = qx!env printf '\xa0'| LC_ALL=$locale tr '[:blank:]' x!; + # If so, expect just one line of output in the schar test. + # Otherwise, expect two. + my $in = " y z\n\xa0 y z\n"; + my $schar_exp = $x eq 'x' ? " y z\n" : $in; + + my @Locale_Tests = + ( + # Test for a subtle, system-and-locale-dependent bug in uniq. + ['schar', '-f1', {IN => $in}, {OUT => $schar_exp}, + {ENV => "LC_ALL=$locale"}] + ); + + push @Tests, @Locale_Tests; + } + + +# Set _POSIX2_VERSION=199209 in the environment of each obs-plus* test. +foreach my $t (@Tests) + { + $t->[0] =~ /^obs-plus/ + and push @$t, {ENV=>'_POSIX2_VERSION=199209'}; + } + +@Tests = add_z_variants \@Tests; +@Tests = triple_test \@Tests; + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/usage_vs_getopt.sh b/tests/misc/usage_vs_getopt.sh new file mode 100755 index 0000000..a489acc --- /dev/null +++ b/tests/misc/usage_vs_getopt.sh @@ -0,0 +1,96 @@ +#!/bin/sh +# Verify that all options mentioned in usage are recognized by getopt. + +# Copyright (C) 2017-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src + +checkprg () { + prg="$1" + + # Get stderr output for unrecognized options for later use as a pattern. + # Also consider the expected exit status of each program. + rcexp=1 + case "$prg" in + dir | ls | printenv | sort | tty | vdir ) rcexp=2 ;; + env | chroot | nice | nohup | stdbuf | timeout ) rcexp=125 ;; + esac + # Write the pattern for a long, unknown option into a pattern file. + o='thisoptiondoesnotexist' + returns_ $rcexp $prg --$o >/dev/null 2> err || fail=1 + grep -F "$o" err || framework_failure_ + sed -n "1s/--$o/OPT/p" < err > pat || framework_failure_ + + # Append the pattern for a short unknown option. + returns_ $rcexp $prg -/ >/dev/null 2> err || fail=1 + grep " '*/'*" err || framework_failure_ + # The following only handles the common case that has single quotes, + # as it simplifies to identify missing options only on common systems. + sed -n "1s/'\/'/'OPT'/p" < err >> pat || framework_failure_ + + # Get output for --help. + $prg --help > help || fail=1 + + # Extract all options mention in the above --help output. + nl=" + " + sed -n -e '/--version/q' \ + -e 's/^ \{2,6\}-/-/; s/ .*//; s/[=[].*//; s/, /\'"$nl"'/g; s/^-/-/p' help \ + > opts || framework_failure_ + cat opts # for debugging purposes + + # Test all options mentioned in usage (but --version). + while read opt; do + test "x$opt" = 'x--help' \ + && continue + # Append --help to be on the safe side: the option under test either + # requires a further argument, or --help triggers usage(); so $prg should + # exit without performing its regular operation. + # Add a 2nd --help for the 'env -u --help' case. + $prg "$opt" --help --help </dev/null >out 2>err1 + rc=$? + # In the --help case, i.e., when the option under test has been accepted, + # the exit code should be Zero. + if [ $rc = 0 ]; then + compare help out || fail=1 + else + # Else $prg should have complained about a missing argument. + # Catch false positives. + case "$prg/$opt" in + 'pr/-COLUMN') continue;; + esac + # Replace $opt in stderr output by the neutral placeholder. + # Handle both long and short option error messages. + sed -e "s/$opt/OPT/" -e "s/'.'/'OPT'/" < err1 > err || framework_failure_ + # Fail if the stderr output matches the above provoked error. + grep -Ff pat err && { fail=1; cat err1; } + fi + done < opts +} + +for prg in $built_programs; do + case "$prg" in + # Skip utilities entirely which have special option parsing. + '[' | expr | stty ) + continue;; + # Wrap some utilities known by the shell by env. + echo | false | kill | printf | pwd | test | true ) + prg="env $prg";; + esac + checkprg $prg +done + +Exit $fail diff --git a/tests/misc/wc-files0-from.pl b/tests/misc/wc-files0-from.pl new file mode 100755 index 0000000..597b647 --- /dev/null +++ b/tests/misc/wc-files0-from.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl +# Exercise wc's --files0-from option. +# FIXME: keep this file in sync with tests/du/files0-from. + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +my $prog = 'wc'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + # invalid extra command line argument + ['f-extra-arg', '--files0-from=- no-such', {IN=>"a"}, {EXIT=>1}, + {ERR => "$prog: extra operand 'no-such'\n" + . "file operands cannot be combined with --files0-from\n" + . "Try '$prog --help' for more information.\n"} + ], + + # missing input file + ['missing', '--files0-from=missing', {EXIT=>1}, + {ERR => "$prog: cannot open 'missing' for reading: " + . "No such file or directory\n"}], + + # input file name of '-' + ['minus-in-stdin', '--files0-from=-', '<', {IN=>{f=>'-'}}, {EXIT=>1}, + {ERR => "$prog: when reading file names from stdin, no file name of" + . " '-' allowed\n"}], + + # empty input, regular file + ['empty', '--files0-from=@AUX@', {AUX=>''}], + + # empty input, from non-regular file + ['empty-nonreg', '--files0-from=/dev/null'], + + # one NUL + ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1}, + {ERR => "$prog: -:1: invalid zero-length file name\n"}], + + # two NULs + ['nul-2', '--files0-from=-', '<', {IN=>"\0\0"}, {EXIT=>1}, + {OUT=>"0 0 0 total\n"}, + {ERR => "$prog: -:1: invalid zero-length file name\n" + . "$prog: -:2: invalid zero-length file name\n"}], + + # one file name, no NUL + ['1', '--files0-from=-', '<', + {IN=>{f=>"g"}}, {AUX=>{g=>''}}, {OUT=>"0 0 0 g\n"} ], + + # one file name, with NUL + ['1a', '--files0-from=-', '<', + {IN=>{f=>"g\0"}}, {AUX=>{g=>''}}, {OUT=>"0 0 0 g\n"} ], + + # two file names, no final NUL + ['2', '--files0-from=-', '<', + {IN=>{f=>"g\0g"}}, {AUX=>{g=>''}}, + {OUT=>"0 0 0 g\n0 0 0 g\n0 0 0 total\n"} ], + + # two file names, with final NUL + ['2a', '--files0-from=-', '<', + {IN=>{f=>"g\0g\0"}}, {AUX=>{g=>''}}, + {OUT=>"0 0 0 g\n0 0 0 g\n0 0 0 total\n"} ], + + # Ensure that $prog processes FILEs following a zero-length name. + ['zero-len', '--files0-from=-', '<', + {IN=>{f=>"\0g\0"}}, {AUX=>{g=>''}}, + {OUT=>"0 0 0 g\n0 0 0 total\n"}, + {ERR => "$prog: -:1: invalid zero-length file name\n"}, {EXIT=>1} ], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/wc-files0.sh b/tests/misc/wc-files0.sh new file mode 100755 index 0000000..657b1ff --- /dev/null +++ b/tests/misc/wc-files0.sh @@ -0,0 +1,62 @@ +#!/bin/sh +# Show that wc's new --files0-from option works. + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ wc + +echo 2 > 2b || framework_failure_ +echo 2 words > 2w || framework_failure_ +printf '2b\n2w\n' |tr '\n' '\0' > names || framework_failure_ + + +wc --files0-from=names > out || fail=1 +cat <<\EOF > exp || framework_failure_ + 1 1 2 2b + 1 2 8 2w + 2 3 10 total +EOF + +compare exp out || fail=1 + +if ! test "$fail" = 1; then + # Repeat the above test, but read the file name list from stdin. + rm -f out + wc --files0-from=- < names > out || fail=1 + compare exp out || fail=1 +fi + +# Ensure file name containing new lines are output on a single line +nlname='1 +2' +touch "$nlname" || framework_failure_ +printf '%s\0' "$nlname" | wc --files0-from=- > out || fail=1 +printf '%s\n' "0 0 0 '1'\$'\\n''2'" > exp || framework_failure_ +compare exp out || fail=1 + +# Ensure correct byte counts, which fails between v8.24 and v8.26 inclusive +truncate -s1G wc.big || framework_failure_ +touch wc.small || framework_failure_ +printf '%s\0' wc.big wc.small | wc -c --files0-from=- >out || fail=1 +cat <<\EOF > exp || framework_failure_ +1073741824 wc.big +0 wc.small +1073741824 total +EOF +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/wc-nbsp.sh b/tests/misc/wc-nbsp.sh new file mode 100755 index 0000000..7b2658f --- /dev/null +++ b/tests/misc/wc-nbsp.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# Test non breaking space handling + +# Copyright (C) 2019-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ wc printf + +# Before coreutils 8.31 nbsp was treated as part of a word, +# rather than a word delimiter + +check_word_sep() { + char="$1" + # Use -L to determine whether NBSP is printable. + # FreeBSD 11 and OS X treat NBSP as non printable ? + if test "$(env printf "=$char=" | wc -L)" = 3; then + test $(env printf "=$char=" | wc -w) = 2 || fail=1 + fi +} + +export LC_ALL=en_US.iso8859-1 # only lowercase form works on macOS 10.15.7 +if test "$(locale charmap 2>/dev/null | sed 's/iso/ISO-/')" = ISO-8859-1; then + check_word_sep '\xA0' +fi + +export LC_ALL=en_US.UTF-8 +if test "$(locale charmap 2>/dev/null)" = UTF-8; then + check_word_sep '\u00A0' + check_word_sep '\u2007' + check_word_sep '\u202F' + check_word_sep '\u2060' +fi + +export LC_ALL=ru_RU.KOI8-R +if test "$(locale charmap 2>/dev/null)" = KOI8-R; then + check_word_sep '\x9A' +fi + +Exit $fail diff --git a/tests/misc/wc-parallel.sh b/tests/misc/wc-parallel.sh new file mode 100755 index 0000000..6a28e7f --- /dev/null +++ b/tests/misc/wc-parallel.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# Ensure that wc prints counts atomically +# so that concurrent processes don't intersperse their output + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ wc + +xargs -P2 </dev/null >/dev/null 2>&1 \ + || skip_ 'xargs -P is required' + +(mkdir tmp && cd tmp && seq 2000 | xargs touch) + +# This will output at least 16KiB per process +# and start 3 processes, with 2 running concurrently, +# which triggers often on Fedora 11 at least. +(find tmp tmp tmp -type f | xargs -n2000 -P2 wc 2>err) | +sed -n '/0 0 0 /!p' | +grep . > /dev/null && fail=1 +compare /dev/null err || fail=1 + +Exit $fail diff --git a/tests/misc/wc-proc.sh b/tests/misc/wc-proc.sh new file mode 100755 index 0000000..581890d --- /dev/null +++ b/tests/misc/wc-proc.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# Test wc on /proc and /sys files. + +# Copyright 2014-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ wc + +# Ensure we read() /proc files to determine content length +for file in /proc/version /sys/kernel/profiling; do + if test -r $file; then + cp -f $file copy && + wc -c < copy > exp1 || framework_failure_ + + wc -c < $file > out1 || fail=1 + compare exp1 out1 || fail=1 + fi +done + +# Ensure we handle cases where we don't read() +truncate -s 2 no_read || framework_failure_ +# read() used when multiple of page size +truncate -s 1048576 do_read || framework_failure_ +wc -c no_read do_read > out || fail=1 +cat <<\EOF > exp + 2 no_read +1048576 do_read +1048578 total +EOF +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/wc.pl b/tests/misc/wc.pl new file mode 100755 index 0000000..5fbe03d --- /dev/null +++ b/tests/misc/wc.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl +# Basic tests for "wc". + +# Copyright (C) 1997-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $prog = 'wc'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + ['a0', '-c', {IN_PIPE=>''}, {OUT=>"0\n"}], + ['a1', '-l', {IN_PIPE=>''}, {OUT=>"0\n"}], + ['a2', '-w', {IN_PIPE=>''}, {OUT=>"0\n"}], + ['a3', '-c', {IN_PIPE=>'x'}, {OUT=>"1\n"}], + ['a4', '-w', {IN_PIPE=>'x'}, {OUT=>"1\n"}], + ['a5', '-w', {IN_PIPE=>"x y\n"}, {OUT=>"2\n"}], + ['a6', '-w', {IN_PIPE=>"x y\nz"}, {OUT=>"3\n"}], + # Remember, -l counts *newline* bytes, not logical lines. + ['a7', '-l', {IN_PIPE=>"x y"}, {OUT=>"0\n"}], + ['a8', '-l', {IN_PIPE=>"x y\n"}, {OUT=>"1\n"}], + ['a9', '-l', {IN_PIPE=>"x\ny\n"}, {OUT=>"2\n"}], + ['b0', '', {IN_PIPE=>""}, {OUT=>" 0 0 0\n"}], + ['b1', '', {IN_PIPE=>"a b\nc\n"}, {OUT=>" 2 3 6\n"}], + ['c0', '-L', {IN_PIPE=>"1\n12\n"}, {OUT=>"2\n"}], + ['c1', '-L', {IN_PIPE=>"1\n123\n1\n"}, {OUT=>"3\n"}], + ['c2', '-L', {IN_PIPE=>"\n123456"}, {OUT=>"6\n"}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/xattr.sh b/tests/misc/xattr.sh new file mode 100755 index 0000000..e901a05 --- /dev/null +++ b/tests/misc/xattr.sh @@ -0,0 +1,130 @@ +#!/bin/sh +# Ensure that cp --preserve=xattr, cp --preserve=all and mv preserve extended +# attributes and install does not preserve extended attributes. +# cp -a should preserve xattr, error diagnostics should not be displayed + +# Copyright (C) 2009-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cp mv ginstall + +# Skip this test if cp was built without xattr support: +touch src dest || framework_failure_ +cp --preserve=xattr -n src dest \ + || skip_ "coreutils built without xattr support" + +# this code was taken from test mv/backup-is-src +cleanup_() { rm -rf "$other_partition_tmpdir"; } +. "$abs_srcdir/tests/other-fs-tmpdir" +b_other="$other_partition_tmpdir/b" +rm -f "$b_other" || framework_failure_ + +# testing xattr name-value pair +xattr_name="user.foo" +xattr_value="bar" +xattr_pair="$xattr_name=\"$xattr_value\"" + +# create new file and check its xattrs +touch a || framework_failure_ +getfattr -d a >out_a || skip_ "failed to get xattr of file" +grep -F "$xattr_pair" out_a && framework_failure_ + +# try to set user xattr on file +setfattr -n "$xattr_name" -v "$xattr_value" a >out_a \ + || skip_ "failed to set xattr of file" +getfattr -d a >out_a || skip_ "failed to get xattr of file" +grep -F "$xattr_pair" out_a \ + || skip_ "failed to set xattr of file" + + +# cp should not preserve xattr by default +cp a b || fail=1 +getfattr -d b >out_b || skip_ "failed to get xattr of file" +grep -F "$xattr_pair" out_b && fail=1 + +# test if --preserve=xattr option works +cp --preserve=xattr a b || fail=1 +getfattr -d b >out_b || skip_ "failed to get xattr of file" +grep -F "$xattr_pair" out_b || fail=1 + +# test if --preserve=all option works +cp --preserve=all a c || fail=1 +getfattr -d c >out_c || skip_ "failed to get xattr of file" +grep -F "$xattr_pair" out_c || fail=1 + +# cp's -a option must produce no diagnostics. +cp -a a d 2>err && { compare /dev/null err || fail=1; } +getfattr -d d >out_d || skip_ "failed to get xattr of file" +grep -F "$xattr_pair" out_d || fail=1 + +# test if --preserve=xattr works even for files without write access +chmod a-w a || framework_failure_ +rm -f e +cp --preserve=xattr a e || fail=1 +getfattr -d e >out_e || skip_ "failed to get xattr of file" +grep -F "$xattr_pair" out_e || fail=1 + +# Ensure that permission bits are preserved, too. +src_perm=$(stat --format=%a a) +dst_perm=$(stat --format=%a e) +test "$dst_perm" = "$src_perm" || fail=1 + +chmod u+w a || framework_failure_ + +rm b || framework_failure_ + +# install should never preserve xattr +ginstall a b || fail=1 +getfattr -d b >out_b || skip_ "failed to get xattr of file" +grep -F "$xattr_pair" out_b && fail=1 + +# mv should preserve xattr when renaming within a file system. +# This is implicitly done by rename () and doesn't need explicit +# xattr support in mv. +mv a b || fail=1 +getfattr -d b >out_b || skip_ "failed to get xattr of file" +grep -F "$xattr_pair" out_b || cat >&2 <<EOF +================================================================= +$0: WARNING!!! +rename () does not preserve extended attributes +================================================================= +EOF + +# try to set user xattr on file on other partition +test_mv=1 +touch "$b_other" || framework_failure_ +setfattr -n "$xattr_name" -v "$xattr_value" "$b_other" >out_a \ + || test_mv=0 +getfattr -d "$b_other" >out_b || test_mv=0 +grep -F "$xattr_pair" out_b || test_mv=0 +rm -f "$b_other" || framework_failure_ + +if test $test_mv -eq 1; then + # mv should preserve xattr when copying content from one partition to another + mv b "$b_other" || fail=1 + getfattr -d "$b_other" >out_b || + skip_ "failed to get xattr of file" + grep -F "$xattr_pair" out_b || fail=1 +else + cat >&2 <<EOF +================================================================= +$0: WARNING!!! +failed to set xattr of file $b_other +================================================================= +EOF +fi + +Exit $fail diff --git a/tests/misc/xstrtol.pl b/tests/misc/xstrtol.pl new file mode 100755 index 0000000..5b59b05 --- /dev/null +++ b/tests/misc/xstrtol.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl +# exercise xstrtol's diagnostics via pr + +# Copyright (C) 2007-2022 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $ME = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $prog = 'pr'; +my $too_big = '9' x 81; # Big enough to overflow a 256-bit integer. +my @Tests = + ( + # test-name, [option, option, ...] {OUT=>"expected-output"} + + ['inval-suffix', "--pages=${too_big}h", {EXIT => 1}, + {ERR=>"$prog: invalid suffix in --pages argument '${too_big}h'\n"}], + + ['too-big', "--pages=$too_big", {EXIT => 1}, + {ERR=>"$prog: --pages argument '$too_big' too large\n"}], + + ['simply-inval', "--pages=x", {EXIT => 1}, + {ERR=>"$prog: invalid --pages argument 'x'\n"}], + + ['inv-pg-range', "--pages=9x", {EXIT => 1}, + {ERR=>"$prog: invalid page range '9x'\n"}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/yes.sh b/tests/misc/yes.sh new file mode 100755 index 0000000..9ba6a03 --- /dev/null +++ b/tests/misc/yes.sh @@ -0,0 +1,59 @@ +#!/bin/sh +# Validate yes buffer handling + +# Copyright (C) 2015-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ yes + +# Check basic operation +test "$(yes | head -n1)" = 'y' || fail=1 + +# Check various single item sizes, with the most important +# size being BUFSIZ used for the local buffer to yes(1). +# Note a \n is added, so actual sizes required internally +# are 1 more than the size used here. +for size in 1 1999 4095 4096 8191 8192 16383 16384; do + printf "%${size}s\n" '' > out.1 + yes "$(printf %${size}s '')" | head -n2 | uniq > out.2 + compare out.1 out.2 || fail=1 +done + +# Check the many small items case, +# both fitting and overflowing the internal buffer. +# First check that 4000 arguments supported. +if test 4000 -eq $(sh -c 'echo $#' 0 $(seq 4000)); then + for i in 100 4000; do + seq $i | paste -s -d ' ' | sed p > out.1 + yes $(seq $i) | head -n2 > out.2 + compare out.1 out.2 || fail=1 + done +fi + +# Check a single appropriate diagnostic is output on write error +if test -w /dev/full && test -c /dev/full; then + # The single output diagnostic expected, + # (without the possibly varying :strerror(ENOSPC) suffix). + printf '%s\n' "yes: standard output" > exp + + for size in 1 16384; do + returns_ 1 yes "$(printf %${size}s '')" >/dev/full 2>errt || fail=1 + sed 's/\(yes:.*\):.*/\1/' errt > err + compare exp err || fail=1 + done +fi + +Exit $fail |