File: runtest

package info (click to toggle)
sdop 1.10-3
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,404 kB
  • sloc: ansic: 21,477; xml: 8,536; sh: 265; perl: 199; makefile: 142
file content (265 lines) | stat: -rwxr-xr-x 6,137 bytes parent folder | download | duplicates (3)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/perl -w

# Controlling script for sdop tests

$sdop = "../src/sdop -S ../share";
$cf = (-f "/usr/local/bin/cf")? "cf" : "diff -u";

$supported = `$sdop -v`;
$jpeg = ($supported =~ /JPEG support: yes/)? 1:0;
$png = ($supported =~ /PNG support: yes/)? 1:0;

if (defined $ARGV[0] && $ARGV[0] =~ /^-?-?valgrind$/)
  {
  shift @ARGV;
  $sdop = "valgrind -q $sdop";
  }   

$force_update = 0;
$starttest = undef;
$endtest = undef;
$started = 0;

$cmd_options = "";

sub I_am_interactive {
    return -t STDIN && -t STDOUT;
}

while (defined $ARGV[0] && $ARGV[0] =~ /^-/)
  {
  my($arg) = shift @ARGV;
  $cmd_options .= "$arg ";
  } 

if (defined $ARGV[0])
  {
  $starttest = $endtest = $ARGV[0];
  $endtest = $ARGV[1] if defined $ARGV[1];
  $endtest = undef if $endtest eq "+"; 
  }   
  
opendir(DIR, "./infiles") || die "Failed to opendir ./infiles: $!\n";
@files = sort(readdir(DIR));
closedir(DIR);

while (scalar @files > 0)
  {
  my($copy) = 0;
  my($file) = shift @files;
  my($options) = $cmd_options; 

  # The names of the test files consist only of digits. Any others (apart from
  # . and .. of course) are option files or auxiliary files.
    
  next if $file !~ /^\d+$/;
  
  next if !$started && defined $starttest && $file != $starttest;
  $started = 1; 
  
  if (-e "infiles/$file.jpeg" && !$jpeg)
    {
    printf("Test $file skipped: no JPEG support\n");
    next; 
    }  
 
  if (-e "infiles/$file.png" && !$png)
    {
    printf("Test $file skipped: no PNG support\n");
    next; 
    }  
  
  $options .= `cat infiles/$file.opt` if -e "infiles/$file.opt";
  chomp $options; 
  
  my ($rc) = system("$sdop $options -o test.ps infiles/$file " .
                    "2> test.err");

  if (($rc >> 8) != 0)
    {
    if (! -e "outfiles/$file.$rc")
      { 
      printf("Test $file RC = 0x%x\n", $rc);
      system("less -XF test.err"); 
      exit 1;
      } 
    }
    
  # Compare stderr output, apart from the program version line
    
  if (! -z "test.err") 
    {
    if (! -e "outfiles/$file.err")
      {
      printf("There is stderr output, but outfiles/$file.err does not exist.\n");
      system("less -XF test.err"); 
      exit 1;
      }    

    open(IN, "test.err") || die "Failed to open test.err\n";
    open(OUT, ">test-munged.err") || die "Failed to open test-munged.err";
    
    while (<IN>)
      {
      print OUT unless /^sdop version/;
      }    
    close IN;
    close OUT;    

    $rc = system("$cf outfiles/$file.err test-munged.err >test.cf");
    
    if ($rc != 0)
      {
      # printf("text cf RC=$rc\n");
      I_am_interactive or die "test failed\n";
      system("less -XF test.cf");
    
      for (;;)
        {
        print "Continue, Update & retry, Quit? [Q] ";
    
        if ($force_update)
          {
          $_ = "u";
          print "... update forced\n";
          }
        else
          {
          open(T, "/dev/tty") || die "Failed to open /dev/tty: $!\n";
          $_ = <T>;
          close(T);
          }
    
        exit 1 if /^q?$/i;
        goto CHECK_MAIN if /^c$/i; 
        
        if (/^u$/)
          {
          exit 1 if system("cp test-munged.err outfiles/$file.err") != 0;
          unshift @files, $file; 
          print (("#" x 79) . "\n");
          last;
          }
        }

      redo;   # Repeats the test
      } 
    }  
    
  # If stderr is empty, check that it should be
  
  else
    {
    if (-e "outfiles/$file.err")
      {
      printf("There is no stderr output, but outfiles/$file.err exists.\n");
      system("less -XF outfiles/$file.err"); 
      exit 1;
      }    
    }   

  # Munge the main output before comparing. For some tests that have early
  # errors, there is no output. 

  CHECK_MAIN:
  
  if (! -e "outfiles/$file.gz" && ! -e "outfiles/$file" && ! -e "test.ps")
    {
    printf ("Test $file OK\n");
    system("/bin/rm -rf test.* test-*"); 
    last if defined $endtest && $file == $endtest;
    }
    
  else
    {  
    open(IN, "test.ps") || die "Failed to open test.ps\n";
    open(OUT, ">test-munged.out") || die "Failed to open test-munged.out";
    
    while (<IN>)
      {
      if ($copy) { print OUT; } elsif (/^%%EndProlog/)
        {
        print OUT;
        $copy = 1;
        }
      }
    close IN;
    close OUT;
    
    # Munge the stored main output too - this way the stored output is a
    # real PostScript file that can be viewed. 
    
    system ("gunzip outfiles/$file.gz") if (-e "outfiles/$file.gz");
    
    open(IN, "outfiles/$file") || die "Failed to open outfiles/$file\n";
    open(OUT, ">test-munged.$file") || die "Failed to open test-munged.$file";
    
    $copy = 0;
    while (<IN>)
      {
      if ($copy) { print OUT; } elsif (/^%%EndProlog/)
        {
        print OUT;
        $copy = 1;
        }
      }
    close IN;
    close OUT;
    
    # Now compare
    
    $rc = system("$cf test-munged.$file test-munged.out >test.cf");
    if ($rc != 0)
      {
      # printf("cf RC=$rc\n");
      printf("Test $file FAILED\n"); 
      I_am_interactive or die "test failed\n";
      system("less -XF test.cf");
    
      for (;;)
        {
        print "View, Continue, Update & retry, Quit? [Q] ";
    
        if ($force_update)
          {
          $_ = "u";
          print "... update forced\n";
          }
        else
          {
          open(T, "/dev/tty") || die "Failed to open /dev/tty: $!\n";
          $_ = <T>;
          close(T);
          }
    
        exit 1 if /^\s*q?$/i;
        last if /^\s*c$/i; 
        
        if (/^\s*v$/)
          {
          system ("gv test.ps"); 
          # Stay in loop to reprompt 
          }  
        
        elsif (/^\s*u$/)
          {
          exit 1 if system("cp test.ps outfiles/$file") != 0;
          unshift @files, $file; 
          print (("#" x 79) . "\n");
          last;
          }
        }
      }
    else
      {
      printf ("Test $file OK\n");
      system("/bin/rm -rf test.* test-*"); 
#      system("gzip outfiles/$file"); 
      last if defined $endtest && $file == $endtest;
      }
    }   
  }
  
die "No selected test found\n" if !$started; 

# End