summaryrefslogtreecommitdiff
path: root/3rd-party/xfpt/testing/runtest
blob: a125ce79865f7a64971970338b4e5c2809c8c190 (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
#!/usr/bin/perl -w

# Controlling script for xfpt tests

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

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

$cmd_options = "";
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; 

  # Skip . and .. and also skip any file ending in .opt because that
  # contains options for any given test, and any file ending in .inc
  # because that is an included file. 
    
  next if $file =~ /^\.\.?$|\.opt$|\.inc$/;
  
  next if !$started && defined $starttest && $file !~ /^$starttest/;
  $started = 1; 
  
  $options .= `cat infiles/$file.opt` if -e "infiles/$file.opt";
  chomp $options; 
  
  my ($rc) = system("$xfpt $options -o test.xml infiles/$file " .
                    "2> test.err");

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

    $rc = system("$cf test.err outfiles/$file.err >test.cf");
    
    if ($rc != 0)
      {
      # printf("text cf RC=$rc\n");
      system("more 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.err outfiles/$file.err") != 0;
          unshift @files, $file; 
          print (("#" x 79) . "\n");
          last;
          }
        }

      redo;   # Repeats the test
      } 
    }  

  # Compare the main output

  CHECK_MAIN:
   
  $rc = system("$cf test.xml outfiles/$file >test.cf");
  if ($rc != 0)
    {
    # printf("cf RC=$rc\n");
    system("more 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 ("less -XF test.xml"); 
        # Stay in loop to reprompt 
        }  
      
      elsif (/^\s*u$/)
        {
        exit 1 if system("cp test.xml outfiles/$file") != 0;
        unshift @files, $file; 
        print (("#" x 79) . "\n");
        last;
        }
      }
    }
  else
    {
    printf ("Test $file OK\n");
#    system("gzip outfiles/$file"); 
    last if defined $endtest && $file =~ /^$endtest/;
    }
  }
  
die "No selected test found\n" if !$started; 

system("/bin/rm -rf test.* test-*"); 

# End