summaryrefslogtreecommitdiff
path: root/tests/run_test.pl
blob: 3a1c44a903f0c6a90810360814282a7aad3544b9 (plain)
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# $Id$
# -*- perl -*-
# This file is for running the tests in the ACE tests directory.
# It is usually used for auto_compiles.

unshift @INC, '../bin';
require ACEutils;

if ($^O ne "MSWin32") {
  #### On platforms other than Windows, use run_tests.sh because
  #### it knows about the various test peculiarities.

  (my $scriptname = $0) =~ s/run_test.pl/run_tests.sh/;
  exec "$scriptname";
  die "$0: unable to exec $scriptname\n";
}

use Cwd;
use English;
use Getopt::Std;

if (!getopts ('tc:') || $opt_h) {
    print "run_test.pl [-h] [-c config] [-t] [file1 file2 ...]\n";
    print "\n";
    print "Runs the tests listed in run_test.lst\n";
    print "\n";
    print "Options:\n";
    print "    -c config  Run the tests for the <config> platform\n";
    print "    -h         display this help\n";
    print "    -t         Runs all the tests passed via the cmd line\n";
    print "\n";
    print "Configs: MSVC\n";
    exit (1);
}

if ($OSNAME eq 'MSWin32') {
  $config = 'MSVC';
} else {
  $config = 'UNIX';
}

if ($opt_c) {
    $config = $opt_c;
}
else {
    print "Defaulting to configuration: $config\n";
}

if (!($tmp = $ENV{TMP})) {
  $tmp="/tmp";
}

################################################################################

@tests = ();

# Loads the list and runs it
sub read_run_test_list ()
{
    my $line;
    open (LIST, "<run_test.lst")
        || die "Cannot open run_test.lst";

    while (<LIST>) {
        next if (/^#/ || /^\s*$/);  # ignore comments and blank lines

        chomp;
        my @stuff = split ":";

        if (!/$config/) {
            my $program = shift @stuff;
            $program =~ s/\s*//g;  #remove any extra whitepace
            push @tests, $program;
        }
    }

    close (LIST);
}

sub run_program ($)
{
    my $program = shift;

    $program_exe = $EXEPREFIX.$program.$EXE_EXT;

    unlink "core";
    local $log = "log/".$program.".log";
    unlink $log;

    ### Try to run the program

    if (! -x $program_exe) {
        print STDERR "Error: $program_exe does not exist\n";
        return;
    }

    print STDERR "Running $program\n";
    $P = Process::Create ($program_exe, "");
    $status = $P->TimedWait (300);

    if ($status == -1) {
        print STDERR "Error: $program FAILED (time out)\n";
        $P->Kill (); $P->TimedWait (1);
    } elsif ($status != 0) {
        print STDERR "Error: $program FAILED with exit status $status\n";
    }

    check_log ($log);
}

sub check_log ($)
{
    my $log = shift;
    ### Check the logs
    if (-e "core") {
        print STDERR "$program dumped core!!!!\n";
    }
    if (! -e $log ) {
        print STDERR "Error: No log file ($log) is present\n";
    } else {
        if (open (LOG, "<".$log) == 0) {
            print STDERR "Error: Cannot open log file $log\n";
        } else {
            my $starting_matched = 0;
            my $ending_matched = 0;

            while (<LOG>) {
                chomp;

                if (m/Starting/) {
                    $starting_matched = 1;
                }

                if (m/Ending/) {
                    $ending_matched = 1;
                }

                if (/LM\_ERROR\@(.*)$/) {
                    print STDERR "Error: ($log): $1\n";
                }
            }

            close (LOG); # ignore errors

            if ($starting_matched == 0) {
                print STDERR "Error ($log): no line with 'starting'\n";
            }

            if ($ending_matched == 0) {
                print STDERR "Error ($log): no line with 'Ending'\n";
            }

        }
    }
}

sub delete_temp_files ()
{
    my @files = ('ace_pipe_name', 'pattern');
    my $file = '';

    if (!opendir (DIR, $tmp)) {
        warn "Cannot open temp directory $tmp\n";
        return;
    }

    foreach $file (readdir (DIR)) {
      if ($file =~ /^ace_temp_file/ || $file =~ /^Naming_Test/) {
          push @files, $tmp.$DIR_SEPARATOR.$file;
      }
    }
    closedir (DIR);

    push @files, glob ('backing_store_*');

    foreach $file (@files) {
      unlink $file;
    }

}

################################################################################

if (!$opt_t) {
    read_run_test_list ();
}
else {
    @tests = @ARGV;
}

foreach $test (@tests) {
  run_program ($test);
}

delete_temp_files ();

exit ();