X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Fcommand%2Fsort.sh;h=d66681be7bf9e9b588d4c7be3886f4f9936df6e2;hb=1fe8ef2486ef1e853d68bbab967ccb812900128f;hp=c53c19720583637e6cce2353a13dc95a10057227;hpb=b70dc1a6b7b15967ceb111f80dff65c44f0fac57;p=pspp-builds.git diff --git a/tests/command/sort.sh b/tests/command/sort.sh index c53c1972..d66681be 100755 --- a/tests/command/sort.sh +++ b/tests/command/sort.sh @@ -3,17 +3,29 @@ # This program tests the sort command TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps +: ${PERL:=perl} -here=`pwd`; +# ensure that top_builddir are absolute +if [ -z "$top_builddir" ] ; then top_builddir=. ; fi +if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi +top_builddir=`cd $top_builddir; pwd` +PSPP=$top_builddir/src/ui/terminal/pspp # ensure that top_srcdir is absolute -cd $top_srcdir; top_srcdir=`pwd` +top_srcdir=`cd $top_srcdir; pwd` -export STAT_CONFIG_PATH=$top_srcdir/config +STAT_CONFIG_PATH=$top_srcdir/config +export STAT_CONFIG_PATH cleanup() { + if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then + echo "NOT cleaning $TEMPDIR" + return ; + fi + cd / rm -rf $TEMPDIR } @@ -45,38 +57,76 @@ mkdir -p $TEMPDIR cd $TEMPDIR +activity="write perl program for generating data" +cat > gen-data.pl <<'EOF' +use strict; +use warnings; -activity="generate stat program" -cat > $TEMPDIR/sort.stat <sort.in"); +print SHUFFLED "$data[$_] $_\n" foreach 0...$#data; + +# Output sorted data. +my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled; +open (SORTED, ">sort.exp"); +print SORTED "$_->[0] $_->[1]\n" foreach @sorted; + +# From perlfaq4. +sub fisher_yates_shuffle { + my $deck = shift; # $deck is a reference to an array + my $i = @$deck; + while ($i--) { + my $j = int rand ($i+1); + @$deck[$i,$j] = @$deck[$j,$i]; + } +} EOF -if [ $? -ne 0 ] ; then no_result ; fi - -activity="run program" -$SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/sort.stat -if [ $? -ne 0 ] ; then no_result ; fi - -# Now there should be some sorted data in $TEMPDIR/pspp.list -# We have to do some checks on it. - -# 1. Is it sorted ? - -activity="check sorted" -sort $TEMPDIR/pspp.list > $TEMPDIR/sortsort -if [ $? -ne 0 ] ; then no_result ; fi - -diff -B -b $TEMPDIR/sortsort $TEMPDIR/pspp.list -if [ $? -ne 0 ] ; then fail ; fi - -# 2. It should be six elements wide -activity="check data width" -awk '!/^\ *$/{if (NF!=6) exit 1}' $TEMPDIR/pspp.list -if [ $? -ne 0 ] ; then fail ; fi - +for count_repeat_buffers in \ + "100 5 2" "100 5 3" "100 5 4" "100 5 5" "100 5 10" "100 5 50" "100 5 100" "100 5" \ + "100 10 2" "100 10 3" "100 10 5" "100 10" \ + "1000 5 5" "1000 5 50" "1000 5" \ + "100 100 3" "100 100 5" "100 100" \ + "10000 5 500" \ + "50000 1"; do + set $count_repeat_buffers + count=$1 + repeat=$2 + buffers=$3 + + printf . + + activity="generate data for $count_repeat_buffers run" + $PERL gen-data.pl $count $repeat > sort.data + if [ $? -ne 0 ] ; then no_result ; fi + + activity="generate test program for $count_repeat_buffers run" + { + echo "data list list file='sort.in'/x y (f8)." + if test "$buffers" != ""; then + echo "sort by x/buffers=$buffers." + else + echo "sort by x." + fi + echo "print outfile='sort.out'/x y." + echo "execute." + } > sort.pspp || no_result + + activity="run program" + $SUPERVISOR $PSPP --testing-mode sort.pspp + if [ $? -ne 0 ] ; then no_result ; fi + + perl -pi -e 's/^\s*$//g' sort.exp sort.out + diff -w sort.exp sort.out + if [ $? -ne 0 ] ; then fail ; fi +done +echo pass;