1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
#!/usr/bin/env perl
# $Header: /cvs/src/jbofihe/testing/testpak.pl,v 1.4 2001/01/14 14:07:14 richard Exp $
# Perl package for supporting regression tests.
#
# Copyright (C) Richard P. Curnow 1998-2001
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# 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, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
#
#
local *LOG;
my $inited = 0;
#######################################################################
sub putfile {
my ($text, $name) = @_;
open (OUT, ">$name") || die "Can't open $name for output";
print OUT $text;
close(OUT);
}
#######################################################################
sub copy {
my ($from, $log) = @_;
open (IN, "<$from") || die "Can't open $from for input";
while (<IN>) {
print $log $_;
}
close (IN);
}
#######################################################################
sub preen {
my ($x) = @_;
$x =~ s/\t/ /go;
$x =~ s/^ +//o;
$x =~ s/ +$//o;
return $x;
}
#######################################################################
sub openlog {
my $name = $ARGV[0];
if (defined $name) {
open (LOG, ">$name");
} else {
open (LOG, ">&STDOUT");
}
}
#######################################################################
sub test {
local %_ = @_;
if (!$inited) {
$inited = 1;
&openlog();
}
my ($program, $stdin, $inputs, $outputs, $notes, $expect, $pid);
$program = $_{prog};
$program = $_{program} unless (defined $program);
$program = $prog unless (defined $program);
die "No program defined" unless (defined $program);
$stdin = $_{stdin};
$stdin = $_{text} unless (defined $stdin);
$stdin = $_{in} unless (defined $stdin);
$inputs = $_{inputs};
$outputs = $_{outputs};
$expect = $_{expect};
$notes = $_{notes};
$notes = $_{note} unless (defined $notes);
if (defined $stdin) {
&putfile($stdin, "__STDIN");
}
my $testsep = ('#' x 60)."\n";
my $bigsep = ('=' x 40)."\n";
my $medsep = ('-' x 25)."\n";
my $sep = ('-' x 10)."\n";
print LOG $testsep;
print LOG "PROGRAM : $program\n";
print LOG $bigsep;
if (defined $stdin) {
print LOG "STDIN :\n";
print LOG $sep;
print LOG $stdin."\n";
print LOG $medsep;
}
if (defined $inputs) {
$inputs = &preen($inputs);
my @inputs = split / +/, $inputs;
foreach my $x (@inputs) {
print LOG "$x\n";
print LOG $sep;
©($x, *LOG);
print $medsep;
}
}
print LOG $bigsep;
if (defined $notes) {
print LOG "NOTE : ";
print LOG $notes."\n";
print LOG $bigsep;
}
# Now actually do the run
if (defined $stdin) {
open (STDIN, "<__STDIN");
}
open (STDOUT, ">__STDOUT");
open (STDERR, ">__STDERR");
$program =~ s/\'/\\'/go;
my $cmd = "/bin/sh -c \"$program\"";
system ($cmd);
my $status = $? >> 8;
my $dumped_core = $? & 128;
my $signal = $? & 127;
print LOG "Exit status : $status\n";
if (defined $expect && $status != $expect) {
print LOG " ###FAILURE### ---> EXPECTED STATUS WAS $expect\n";
}
print LOG "Core dumped : ", ($dumped_core ? "YES" : "NO"), "\n";
print LOG "Signal : $signal\n";
print LOG $bigsep;
foreach my $x ("__STDOUT", "__STDERR", @outputs) {
print LOG "$x\n";
print LOG $sep;
©($x, *LOG);
print LOG $medsep;
}
unlink("__STDIN");
unlink("__STDOUT");
unlink("__STDERR");
}
#######################################################################
1;
|