source: git/Tst/regress.cmd @ e197f5

spielwiese
Last change on this file since e197f5 was e197f5, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
fix due to case sensitive file systems fix: tests from Manual/ with only case different names chg: updated *.uu results as well! chg: updated regress.cmd to remote the leading _ for tests starting with "_[a-z0-9]" during the TC output NOTE: the tests with lower case names got a leading underscore character (_)
  • Property mode set to 100755
File size: 30.1 KB
RevLine 
[1a300b9]1#!/usr/bin/perl -CS
[b35b93]2
3#################################################################
[341696]4# $Id$
[b21d63]5# FILE:    regress.cmd
[b35b93]6# PURPOSE: Script which runs regress test of Singular
7# CREATED: 2/16/98
8# AUTHOR:  obachman@mathematik.uni-kl.de
9
[1a300b9]10use Env;
11 
[b35b93]12#################################################################
[b21d63]13#
[b35b93]14# usage
[b21d63]15#
[b35b93]16sub Usage
17{
18  print <<_EOM_
19Usage:
20regress.cmd    -- regress test of Singular
[e960fdf]21  [-s <Singular>]   -- use <Singular> as executable to test
22  [-h]              -- print out help and exit
23  [-k]              -- keep all intermediate files
[6d01ca]24  [-v num]          -- set verbosity to num (used range 0..4, default: 2)
[e960fdf]25  [-g]              -- generate result (*.res.gz.uu) files, only
26  [-r [crit%[val]]] -- report if status differences [of crit] > val (in %)
[31f293]27  [-c regexp]       -- when comparing results, version must match this regexp
[e960fdf]28  [-e [crit%[val]]] -- throw error if status difference [of crit] > val (in %)
[31f293]29  [-a [crit]]       -- add status results [of crit] to result file
30  [-m]              -- add status result for current version to result file
[0b20296]31  [-t]              -- compute and call system("mtrack", 1) at the end, no diffs
[a7bb142]32  [-A num]          -- set timeout [in sec.] for executed Singular
[1a300b9]33  [-C name]         -- be TeamCity friendly, use "name" as a test-suite name
[0b20296]34  [-tt max]         -- compute and call system("mtrack", max) at the end
[6d01ca]35  [-T]              -- simply compute and determine timmings, no diffs
[e960fdf]36  [file.lst]        -- read tst files from file.lst
[b21d63]37  [file.tst]        -- test Singular script file.tst
[b35b93]38_EOM_
39}
40
41#################################################################
[b21d63]42#
[b35b93]43# used programs
44#
[55f154]45$sh="/bin/sh";
[b35b93]46$diff = "diff";
47$gunzip = "gunzip";
48$gzip = "gzip";
49$rm = "rm";
[d5e119]50$mv = "mv";
[b35b93]51$cp = "cp";
[d5e119]52$tr = "tr";
53$sed = "sed";
54$cat = "cat";
55$tee = "tee";
[e960fdf]56$grep = "grep";
[55f154]57
58sub mysystem
59{
60  local($call) = $_[0];
61  local($exit_status);
62
63  $call =~ s/"/\\"/g;
64  $call = "$sh -c \"$call\"";
[6d01ca]65  print "$call\n" if ($verbosity > 2);
[55f154]66  return (system $call);
67}
68
[e960fdf]69sub mysystem_catch
70{
71  local($call) = $_[0];
72  local($output) = "";
73
74  $call = "$call > catch_$$";
[93e538]75  mysystem($call);
[b21d63]76
[e960fdf]77  open(CATCH_FILE, "<catch_$$");
78  while (<CATCH_FILE>)
79  {
80    $output = $output.$_;
81  }
82  close(CATCH_FILE);
[93e538]83  mysystem("$rm -f catch_$$");
[e960fdf]84  return $output;
85}
86
[93e538]87$WINNT = 1 if (mysystem("uname -a | $grep CYGWIN > /dev/null 2>&1") == 0);
[e519027]88$uuencode = "uuencode";
89$uudecode = "uudecode";
[d5e119]90
[ff4a69]91#
92# flush stdout and stderr after every write
93#
94select(STDERR);
95$| = 1;
96select(STDOUT);
97$| = 1;
98
[b35b93]99#################################################################
[b21d63]100#
[55f154]101# the default settings
102#
[56ae4f]103$singularOptions = "--ticks-per-sec=100 -teqsr12345678 --no-rc";
[21a762]104# for testing under Windows, remove "e" option above and compile
105# res files on Linux, then copy to Windows and compare. Otherwise
106# you have problems with diff on Win. Just uncomment the next line:
[56ae4f]107# $singularOptions = "--ticks-per-sec=100 -tqsr12345678 --no-rc";
[21a762]108
[55f154]109$keep = "no";
[6d01ca]110$verbosity = 2;
[55f154]111$generate = "no";
112$exit_code = 0;
113chop($curr_dir=`pwd`);
114# singular -- use the one in curr directory or the one found above
115$ext=".exe" if ($WINNT);
116$singular = "$curr_dir/Singular$ext";
117if ( (! (-e $singular)) || (! (-x $singular)))
[b35b93]118{
[55f154]119  $singular = $curr_dir."/../Singular$ext";
[b35b93]120}
[a7bb142]121# timeout for Singular execution (in seconds!)
122$timeout  = 0;
[55f154]123# sed scripts which are applied to res files before they are diff'ed
[1cb879]124$sed_scripts = "-e '/used time:/d' -e '/tst_ignore:/d' -e '/Id[:\$]/d' -e '/error occurred in/d' -e '/tst_status/d' -e'/init >>/d' -e 's/\\[[0-9]*:[0-9]*\\]//g'";
[e960fdf]125# default value (in %) above which differences are reported on -r
[e2114af]126$report_val = 5;
[e960fdf]127# default value (in %) above which differences cause an error on -e
[e2114af]128$error_val = 5;
[374b14]129# default value in 1/100 seconds, above which time differences are reported
[a23d8e]130$mintime_val = 100;
[93e538]131$hostname = mysystem_catch("hostname");
[e960fdf]132chop $hostname;
[55f154]133
[1a300b9]134# flag indicating whether to produce TeamCity output ("" - no):
135$teamcity = "";
136# current argument: test file name?
137$test_file = "";
138
[93e538]139# all previous test_file's:
140%test_files = ();
[1a300b9]141
142
143#################################################################
144#
145# teamcity helpers:
146#
147sub myGetTCprop
148{
149  local($prop) = $_[0];
[93e538]150  return( mysystem_catch("cat \"\$TEAMCITY_BUILD_PROPERTIES_FILE\"|grep \"$prop=\"|sed \"s/$prop=//\"") );
[1a300b9]151}
152
153sub tc_filter
154{
155  local($t) = $_[0];
156
157  $t =~ s/\|/|\|/g;
158 
159  $t =~ s/\n/|n/g;
160  $t =~ s/\r/|r/g;
161
162  $t =~ s/\u0085/|x/g;
163  $t =~ s/\u2028/|l/g;
164  $t =~ s/\u2029/|p/g;
165
166  ## \x{263A}
167
168  $t =~ s/\'/|\'/g;
169  $t =~ s/\[/|\[/g;
170  $t =~ s/\]/|\]/g;
171  return ($t);
172}
173sub putTCmsg
174{
175  if( length($teamcity) > 0 )
176  {
177    local($message) = $_[0];
178    local($text) = $_[1];
179
180    print( "\n##teamcity[$message $text]\n" );
181  }
182}
183sub putTCmsgV
184{
185  local($message) = $_[0];
186  local($unquotedValue) = tc_filter($_[1]);
187   
188  putTCmsg( $message, "\'$unquotedValue\'");
189}
190sub putTCmsgNV
191{
192  local($m) = $_[0];
193  local($p) = $_[1];
194  local($v) = tc_filter($_[2]);
195  putTCmsg( $m, "$p=\'$v\'" );
196}
197sub putTCmsgNV2
198{
199  local($m) = $_[0];
200  local($p) = $_[1];
201  local($v) = tc_filter($_[2]);
202  local($pp) = $_[3];
203  local($vv) = tc_filter($_[4]);
204  putTCmsg( $m, "$p='$v' $pp='$vv'" );
205}
206
207#################################################################
208#
209# teamcity routines:
210#
211sub blockOpened
212{
213  local($v) = $_[0];
214  putTCmsgNV( "blockOpened", "name", $v);
215}
216sub blockClosed
217{
218  local($v) = $_[0];
219  putTCmsgNV( "blockClosed", "name", $v);
220}
221sub tcError
222{
[ebb444]223  local($text) = tc_filter($_[0]);
224  local($details) = tc_filter($_[1]);
225  local($status) = tc_filter($_[2]);
[1a300b9]226  # The status attribute may take following values:
227  # NORMAL, WARNING, FAILURE, ERROR.
228  # The default value is NORMAL.
229  # The errorDetails attribute is used only if status is ERROR, in other cases it is ignored.
230  # This message fails the build in case its status is ERROR and "Fail build if an error message is logged by build runner" checkbox is checked on build configuration general settings page.
231 
232  ##teamcity[message text='<message text>' errorDetails='<error details>' status='<status value>']
[ebb444]233  putTCmsg( "message", "text=\'$text\' errorDetails=\'$details\' status=\'$status\'");
234}
235
236sub tcFailure
237{
238  local($text) = tc_filter($_[0]);
239  local($details) = tc_filter($_[1]);
240  tcError( $text, $details, "FAILURE" );
241}
242
243sub tcLog
244{
245  local($text) = $_[0];
246  putTCmsgNV2( "message", "text", $text, "status", "NORMAL");
247}
248sub tcWarn
249{
250  local($text) = $_[0];
251  putTCmsgNV2( "message", "text", $text, "status", "WARNING");
[1a300b9]252}
253
254sub testSuiteStarted
255{
256  local($v) = $_[0];
257  putTCmsgNV( "testSuiteStarted", "name", $v);
258}
259sub testSuiteFinished
260{
261  local($v) = $_[0];
262  putTCmsgNV( "testSuiteFinished", "name", $v);
263}
[ebb444]264
265$failed = 0;
266
[e197f5]267sub testNameRemoveLeadingUnderscore
268{
269  # make NN/_abs.tst - > NN/abs.tst
270  local($t) = $_[0];
271  $t =~ s/^_([a-z0-9][^\/]*)$/\1/g;
272  $t =~ s/[\/]_([a-z0-9][^\/]*)$/\/\1/g;
273  return ($t); 
274}
275
[1a300b9]276sub testStarted
277{
[e197f5]278  local($v) = $_[0];
279  $v = testNameRemoveLeadingUnderscore($v);
[1a300b9]280  putTCmsgNV2( "testStarted", "name", $v, "captureStandardOutput", "true");
[ebb444]281  $failed = 0;   
[1a300b9]282}
283sub testFinished
284{
285  local($v) = $_[0];
286  local($d) = $_[1];
[e197f5]287  $v = testNameRemoveLeadingUnderscore($v);
[ebb444]288  putTCmsgNV2( "testFinished", "name", $v, "duration", $d);
289  $failed = 0;   
[1a300b9]290}
[ebb444]291
[1a300b9]292sub testFailed
293{
294  local($n) = $_[0];
295  local($m) = $_[1];
[e197f5]296
297  $n = testNameRemoveLeadingUnderscore($n);
[ebb444]298   
299  if( !$failed )
300  {
301    putTCmsgNV2( "testFailed", "name", $n, "message", $m);
302    $failed = 1;
303  } else
304  {
305    tcFailure("Test: $n => $m", "");
306  }
[1a300b9]307}
308sub testFailed2
309{
310  local($n) = tc_filter($_[0]);
311  local($m) = tc_filter($_[1]);
312  local($t) = tc_filter($_[2]);
[e197f5]313
314  $n = testNameRemoveLeadingUnderscore($n);
315 
[ebb444]316  if( !$failed )
317  {
318    putTCmsg( "testFailed", "name=\'$n\' message=\'$m\' details=\'$t\'");
319    $failed = 1;
320  } else
321  {
322    tcFailure("Test: $n => $m", $t);
323  }
324
[1a300b9]325}
326sub testFailedCMP
327{
[ebb444]328  local($name) = tc_filter($_[0]);
329  local($msg) = tc_filter($_[1]);
330  local($details) = tc_filter($_[2]);
331  local($expected) = tc_filter($_[3]);
332  local($actual) = tc_filter($_[4]);
[e197f5]333   
334  $name = testNameRemoveLeadingUnderscore($name);
335   
[ebb444]336  if( !$failed )
337  {
338    putTCmsg( "testFailed", "type=\'comparisonFailure\' name=\'$name\' message=\'$msg\' details=\'$details\' expected=\'$expected\' actual=\'$actual\'");
339    $failed = 1;
340  } else
341  {
342    tcFailure("Test: $name => $msg", "$detail\nExpected: $expected\nActual: $actual");
343  }
344
[1a300b9]345}
346
[ebb444]347##teamcity[testFailed type='comparisonFailure' name='test_file' message='failure_message' details='message and stack trace' expected='expected value' actual='actual value']
[1a300b9]348sub testIgnored
349{
350  local($n) = $_[0];
351  local($m) = $_[1];
[e197f5]352 
353  $n = testNameRemoveLeadingUnderscore($n);
354
[1a300b9]355  putTCmsgNV2( "testIgnored", "name", $n, "message", $m);
356}
357
358
359
[55f154]360#################################################################
[b21d63]361#
[55f154]362# auxiallary routines
[b21d63]363#
[e960fdf]364
[31f293]365sub GetSingularVersionDate
366{
[93e538]367  mysystem("$singular -t -v --execute=\"exit;\"> SingularVersionDate");
[31f293]368  open(FD, "<SingularVersionDate");
369  while (<FD>)
370  {
371    $singular_uname = (/for\s+([^\s]*)\s+/ ? $1 : "uname");
372    $singular_version = (/version\s+([^\s]*)\s+/ ? $1 : "0-0-0");
373    $singular_date = (/\((.*)\)/ ? $1 : "1970010100");
374    $this_time = time;
375    last;
376  }
377  close(FD);
[93e538]378  mysystem("if [ -e /proc/cpuinfo ]; then cat /proc/cpuinfo >> SingularVersionDate; fi ");
[4a7108c]379  # mysystem("sysctl -a  >> SingularVersionDate"); # sysctl is not a user cmd.
[93e538]380  mysystem("uname -a >> SingularVersionDate");
381  mysystem("if [ -e /proc/meminfo ]; then cat /proc/meminfo >> SingularVersionDate; fi ");
[4a7108c]382  # mysystem("free -h >> SingularVersionDate"); # nobody supports free -h
[31f293]383}
384
[d5e119]385sub Set_withMP
386{
387  if (! $withMP)
388  {
389    $withMP = "no";
[4c79e7]390    open(MP_TEST, ">MPTest");
391    print(MP_TEST "system(\"with\", \"MP\"); \$");
392    close(MP_TEST);
[93e538]393    mysystem("$singular -qt MPTest > withMPtest");
[d5e119]394    if (open(MP_TEST, "<withMPtest"))
395    {
396      $_ = <MP_TEST>;
397      $withMP = "yes" if (/^1/);
398      close(MP_TEST);
399    }
[93e538]400    mysystem("$rm -f withMPtest MPTest");
[d5e119]401  }
402}
[b21d63]403
404
[d5e119]405sub MPok
406{
407  local($root) = $_[0];
[b21d63]408
[d5e119]409  if (! open(TST_FILE, "<$root.tst"))
410  {
411    print (STDERR "Can not open $root.tst for reading\n");
412    return (0);
413  }
414  while (<TST_FILE>)
415  {
416    if (/\"MP.+:.*\"/)
417    {
418      &Set_withMP;
419      return (0) if ($withMP eq "no");
420    }
421  }
422  return (1);
423}
[e960fdf]424
[d5e119]425sub Diff
426{
427  local($root) = $_[0];
428  local($exit_status);
[b21d63]429
430  # prepare the result files:
[93e538]431  mysystem("$cat \"$root.res\" | $tr -d '\\013' | $sed $sed_scripts > \"$root.res.cleaned\"");
432  mysystem("$cat \"$root.new.res\" | $tr -d '\\013' | $sed $sed_scripts > \"$root.new.res.cleaned\"");
[d5e119]433
434  # doo the diff call
[93e538]435  $exit_status = mysystem("$diff -w -b \"$root.res.cleaned\" \"$root.new.res.cleaned\" > \"$root.diff\" 2>&1");
[b21d63]436
[ebb444]437 
[d5e119]438  # clean up time
[93e538]439  mysystem("$rm -f \"$root.res.cleaned\" \"$root.new.res.cleaned\"");
[b21d63]440
[d5e119]441  # there seems to be a bug here somewhere: even if diff reported
442  # differenceses and exited with status != 0, then system still
443  # returns exit status 0. Hence we manually need to find out whether
[b21d63]444  # or not differences were reported:
[d5e119]445  # iff diff-file exists and has non-zero size
446  $exit_status = $exit_status || (-e "$root.diff" && -s "$root.diff");
447
[ebb444]448  if( $exit_status && (length($teamcity) > 0) )
449  {
450    local($details) = mysystem_catch("$cat \"$root.diff\"");
451    local($expected) = mysystem_catch("$cat \"$root.res\"");
452    local($actual) = mysystem_catch("$cat \"$root.new.res\"");
453    testFailedCMP($test_file, "Differences in res files", $details, $expected, $actual )
454  }
455   
[d5e119]456  return($exit_status);
457}
[b21d63]458
[e960fdf]459sub tst_status_check
[b35b93]460{
461  local($root) = $_[0];
[e960fdf]462  local($line,$new_line,$prefix,$crit,$res,$new_res);
463  local($res_diff,$res_diff_pc,$res_diff_line);
[31f293]464  my($exit_status, $reported) = (0, 0);
[e960fdf]465  local($error_cause) = "";
[b21d63]466
467  open(RES_FILE, "<$root.stat") ||
[e2114af]468    return (1, "Can not open $root.stat \n");
469  open(NEW_RES_FILE, "<$root.new.stat") ||
470    return (1, "Can not open $root.new.stat \n");
[a23d8e]471  open(STATUS_DIFF_FILE, ">$root.stat.sdiff") ||
472    return (1, "Can not open $root.stat.sdiff \n");
[e2114af]473
[31f293]474  while (1)
[e960fdf]475  {
[31f293]476    while ($new_line = <NEW_RES_FILE>)
[e960fdf]477    {
[31f293]478      last if $new_line =~ /(\d+) >> (\w+) ::.*$hostname:(\d+)/ && $checks{$2};
479    }
480    last unless $new_line =~ /(\d+) >> (\w+) ::.*$hostname:(\d+)/;
481    $prefix = $1;
482    $crit = $2;
483    $new_res = $3;
484    next unless $new_res > $mintime_val;
485   
486    while ($line = <RES_FILE>)
487    {
488      last if $line =~ /$prefix >> $crit ::.*?$hostname:(\d+)/;
489    }
490    last unless $line =~ /$prefix >> $crit ::.*?$hostname:(\d+)/;
491    my $res_version;
492    $res = 0;
[b21d63]493
[31f293]494    # search for smallest
495    while ($line =~ /([^\s]*)$hostname:(\d+)/g)
496    {
497      my $this_res = $2;
498      my $this_res_version = $1;
499      if ((!$res || $this_res <= $res) && (!$status_check_regexp  || $this_res_version =~ /$status_check_regexp/))
500      {
501        $res = $this_res;
502        $res_version = $this_res_version;
[e960fdf]503      }
504    }
[31f293]505    next unless $res;
506    $res_diff = $new_res - $res;
507    $res_diff_pc = int((($new_res / $res) - 1)*100);
508    $res_diff_line =
509      "$prefix >> $crit :: new:$new_res old:$res_version$res diff:$res_diff %:$res_diff_pc\n";
510    print STATUS_DIFF_FILE $res_diff_line;
511   
512    if ((defined($error{$crit}) &&  $error{$crit}<abs($res_diff_pc))
513        ||
514        (defined($report{$crit}) && $report{$crit}<abs($res_diff_pc)))
515    {
516      print "$prefix >> $crit :: new:$new_res old:$res diff:$res_diff %:$res_diff_pc\n"
517        if ($verbosity > 0);
518    }
519   
520    if ($exit_status == 0)
521    {
522      $exit_status = (defined($error{$crit})
523                      && $error{$crit} < abs($res_diff_pc));
524      $error_cause = "Status error for $crit at $prefix\n"
525        if ($exit_status);
526    }
[e960fdf]527  }
528  close(RES_FILE);
529  close(NEW_RES_FILE);
530  close(STATUS_DIFF_FILE);
531  return ($exit_status, $error_cause);
532}
[b35b93]533
[e960fdf]534sub tst_status_merge
535{
536  local($root) = $_[0];
537  local($line, $new_line, $crit, $res);
[b21d63]538
[31f293]539  GetSingularVersionDate()
540    unless $singular_version;
541
542  if (! -e "$root.stat")
543  {
544    open(RES_FILE, ">$root.stat") ||
545      return (1, "Can not open $root.stat \n");
546    open(NEW_RES_FILE, "<$root.new.stat") ||
547      return (1, "Can not open $root.new.stat \n");
548
549    while (<NEW_RES_FILE>)
550    {
551      if (/(\d+) >> (\w+) :: /)
552      {
[1a300b9]553        s/$hostname:(\d+)/$this_time:$singular_date:$singular_version:$singular_uname:$hostname:$1/g;
554        print RES_FILE $_;
[31f293]555      }
556    }
557    close(RES_FILE);
558    close(NEW_RES_FILE);
559    return;
560  }
561
[b21d63]562  open(RES_FILE, "<$root.stat") ||
[e2114af]563    return (1, "Can not open $root.stat \n");
564  open(NEW_RES_FILE, "<$root.new.stat") ||
565    return (1, "Can not open $root.new.stat \n");
566  open(TEMP_FILE, ">$root.tmp.stat") ||
567    return (1, "Can not open $root.tmp.stat \n");
[b21d63]568
[31f293]569  while (1)
[e960fdf]570  {
[31f293]571    while (($new_line = <NEW_RES_FILE>) && $new_line !~ /(\d+) >> (\w+) ::/){}
572    last unless $new_line =~ /(\d+) >> (\w+) ::.*$hostname:(\d+)/;
573    my $prefix = $1;
574    my $crit = $2;
575    my $new_res = "$this_time:$singular_date:$singular_version:$singular_uname:$hostname:$3";
576    while (($line = <RES_FILE>) && $line !~ /$prefix >> $crit ::/){}
577    unless ($line)
[e960fdf]578    {
[31f293]579      close(RES_FILE);
580      close(NEW_RES_FILE);
581      close(TEMP_FILE);
[93e538]582      mysystem("$rm \"$root.tmp.stat\"");
[31f293]583      return (1, "Can not find '$prefix >> $crit' in $root.stat\n");
584    }
585    if ($merge_version)
586    {
587      $line =~ s/[^ ]*:$singular_version:$singular_uname:$hostname:\d+//g;
588      chop $line;
589      $line .= " $new_res\n";
[e960fdf]590    }
591    else
592    {
[31f293]593      chop $line;
594      $line .= " $new_res\n";
[e960fdf]595    }
[31f293]596    print TEMP_FILE $line;
[e960fdf]597  }
[31f293]598 
[e960fdf]599  close(RES_FILE);
600  close(NEW_RES_FILE);
601  close(TEMP_FILE);
[93e538]602  mysystem("$mv -f \"$root.tmp.stat\" \"$root.stat\"");
603  mysystem("$rm -f \"$root.new.stat\" \"$root.stat.sdiff\"") unless $keep eq "yes";
[31f293]604  return ;
[e960fdf]605}
606
607sub tst_check
608{
609  local($root) = $_[0];
610  local($system_call, $exit_status, $ignore_pattern, $error_cause);
[b21d63]611
[e197f5]612  local($my_test_file) = testNameRemoveLeadingUnderscore($test_file);
613   
614  if (! ($my_test_file eq $test_file))
615  {
616    tcLog("The test '$test_file' will be reported to TeamCity as '$my_test_file' as it was _renamed :-/");
617  }   
618 
[93e538]619  if( exists($test_files{$test_file}) && (length($teamcity) > 0) )
620  {
621     tcWarn("The test '$test_file' have been alreeady tests (with result: $test_files{$test_file})... skipping!");
622     return ($test_files{$test_file})
623  }
[6d01ca]624 
[93e538]625  $total_checks++;
626   
[b35b93]627  # check for existence/readablity of tst and res file
628  if (! (-r "$root.tst"))
629  {
[dfe914]630    print "--- $root " unless ($verbosity == 0);
[b35b93]631    print (STDERR "Can not read $root.tst\n");
[1a300b9]632    testIgnored($test_file, "Can not read $root.tst");
[93e538]633    $test_files{$test_file} = 1;
[b35b93]634    return (1);
635  }
[b21d63]636
[d5e119]637  # ignore MP stuff, if this singular does not have MP
[93e538]638  if (! MPok($root))
[d5e119]639  {
[dfe914]640    print "--- $root " unless ($verbosity == 0);
[d5e119]641    print "Warning: $root not tested: needs MP\n";
[1a300b9]642    testIgnored($test_file, "Warning: $root not tested: needs MP");
[93e538]643    $test_files{$test_file} = 0;
[d5e119]644    return (0);
645  }
[b21d63]646
[d5e119]647  # generate $root.res
[6d01ca]648  if ($generate ne "yes" && ! defined($mtrack) && !defined($timings_only))
[b35b93]649  {
[49d361]650    if ((-r "$root.res.gz.uu") && ! ( -z "$root.res.gz.uu"))
[b35b93]651    {
[93e538]652      $exit_status = mysystem("$uudecode \"$root.res.gz.uu\" > /dev/null 2>&1; $gunzip -f \"$root.res.gz\"");
[b35b93]653      if ($exit_status)
654      {
[dfe914]655        print "--- $root " unless ($verbosity == 0);
[b21d63]656        print (STDERR "Can not decode $root.res.gz.uu\n");
[1a300b9]657        testIgnored($test_file, "Can not decode $root.res.gz.uu");
[93e538]658        $test_files{$test_file} = $exit_status;
[b21d63]659        return ($exit_status);
[b35b93]660      }
661    }
[49d361]662    elsif (! (-r "$root.res") || ( -z "$root.res"))
663    {
[dfe914]664      print "--- $root " unless ($verbosity == 0);
[49d361]665      print (STDERR "Can not read $root.res[.gz.uu]\n");
[1a300b9]666      testIgnored($test_file, "Can not read $root.res[.gz.uu]");
[93e538]667      $test_files{$test_file} = 1;
[49d361]668      return (1);
669    }
[b35b93]670  }
[e960fdf]671
[1a300b9]672  testStarted($test_file);
[dfe914]673  print "--- $root " unless ($verbosity == 0);
[1a300b9]674 
[f5128b8]675  my $resfile = "\"$root.new.res\"";
676  $resfile = "\"$root.mtrack.res\"" if (defined($mtrack));
[31f293]677  my $statfile = "$root.new.stat";
[93e538]678  mysystem("$rm -f \"$statfile\"");
[1a300b9]679 
[0b20296]680  if (defined($mtrack))
[b35b93]681  {
[f5128b8]682    $system_call = "$cat \"$root.tst\" | sed -e 's/\\\\\$/LIB \"general.lib\"; killall(); killall(\"proc\");kill killall;system(\"mtrack\", \"$root.mtrack.unused\", $mtrack); \\\$/' | $singular $singularOptions ";
[6d01ca]683    $system_call .= ($verbosity > 3 ? " | $tee " : " > ");
[f5128b8]684    $system_call .= "\"$root.mtrack.res\"";
[6d01ca]685    $system_call .= " 2>&1 " if ($verbosity <= 3);
[b35b93]686  }
687  else
688  {
[31f293]689   
[9a50a2]690    # prepare Singular run
[6d01ca]691    if ($verbosity > 3 && !$WINNT)
[9a50a2]692    {
[f5128b8]693      $system_call = "$cat \"$root.tst\" | $singular --execute 'string tst_status_file=\"$statfile\";' $singularOptions | $tee $resfile";
[9a50a2]694    }
695    else
696    {
[f5128b8]697      $system_call = "$cat \"$root.tst\" | $singular --execute 'string tst_status_file=\"$statfile\";' $singularOptions > $resfile 2>&1";
[9a50a2]698    }
[b35b93]699  }
700  # Go Singular, Go!
[6d01ca]701 
702  my ($user_t,$system_t,$cuser_t,$csystem_t) = times;
[93e538]703  $exit_status = mysystem($system_call);
[6d01ca]704  my ($user_t,$system_t,$cuser_t2,$csystem_t2) = times;
705  $cuser_t = $cuser_t2 - $cuser_t;
706  $csystem_t = $csystem_t2 - $csystem_t;
[ebb444]707
708  tcLog("Test: $test_file, user time: $cuser_t, system time: $csystem_t" );
709   
[e960fdf]710  if ($exit_status != 0)
[b35b93]711  {
[ebb444]712    $error_cause = "Singular call exited with status ($exit_status) != 0";
713   
714    if( length($teamcity) > 0 )
715    {   
716      ### TODO: add a way to detect timeout!!!
717      if( $exit_status == 142 ) # perl sig alarm exit code? NOPE :(((
718      {
719        local($details) = mysystem_catch("$cat \"$resfile\"");     
720        testFailed2($test_file, "Exit on timeout ($timeout sec)!", $details);   
721      }
722    }
[b35b93]723  }
[e960fdf]724  else
[b35b93]725  {
[e960fdf]726    # check for Segment fault in res file
[93e538]727    $exit_status = ! (mysystem("$grep \"Segment fault\" $resfile > /dev/null 2>&1"));
[b21d63]728
[e960fdf]729    if ($exit_status)
730    {
731      $error_cause = "Segment fault";
[ebb444]732      local($details) = mysystem_catch("$cat \"$resfile\"");
733      testFailed2($test_file, $error_cause, $details);     
[e960fdf]734    }
[6d01ca]735    elsif (! defined($mtrack) && !defined($timings_only))
[e960fdf]736    {
[93e538]737      mysystem("$rm -f \"$root.diff\"");
[e960fdf]738      if ($generate eq "yes")
739      {
[93e538]740        mysystem("$cp $resfile \"$root.res\"");
[e960fdf]741      }
[b21d63]742      else
[e960fdf]743      {
[b21d63]744        # call Diff
[93e538]745        $exit_status = Diff($root);
[b21d63]746        if ($exit_status)
747        {
[2ae411d]748          unless ($verbosity == 0)
749          {
750            print "\n";
[f5128b8]751            mysystem("$cat \"$root.diff\"");
[2ae411d]752          }
[b21d63]753          $error_cause = "Differences in res files";
754        }
755        else
756        {
[93e538]757          mysystem("$rm -f \"$root.diff\"");
[b21d63]758        }
[e960fdf]759      }
760    }
[b35b93]761  }
[e960fdf]762
[f5128b8]763
764
765  mysystem("mv tst_status.out \"$statfile\"")
[31f293]766    if (! -e $statfile && -e "tst_status.out");
767
[0b20296]768  if (%checks && ! $exit_status && $generate ne "yes" && ! defined($mtrack))
[e2114af]769  {
[31f293]770    if (-e "$statfile")
[a21c9c]771    {
772      # do status checks
[93e538]773      ($exit_status, $error_cause) = tst_status_check($root);
[a21c9c]774    }
[f50a14]775    else
776    {
[31f293]777      print "Warning: no file $statfile\n";
[93e538]778      tcWarn("Warning: no file $statfile");
[f50a14]779    }
[e2114af]780  }
[b21d63]781
782
[b35b93]783  # complain even if verbosity == 0
[e960fdf]784  if ($exit_status)
[b35b93]785  {
[2ae411d]786    if (! -e "$root.diff")
787    {
788      open (DIFF_FILE, ">$root.diff");
789      print DIFF_FILE "!!! $root : $error_cause\n";
790      print "\n";
791    }
792    print STDERR "!!! $root : $error_cause\n";
[ebb444]793
794    if( length($teamcity) > 0 )
795    {
796      local($details) = mysystem_catch("$cat \"$resfile\"");     
797      testFailed2($test_file, $error_cause, $details);   
798    }
[b35b93]799  }
[e960fdf]800  else
[d5e119]801  {
[0b20296]802    unless (defined($mtrack))
[b35b93]803    {
[9a50a2]804      #clean up
805      if ($generate eq "yes")
[e2114af]806      {
[f5128b8]807        mysystem("$rm -f \"$root.stat\"") unless %merge;
[31f293]808        ($exit_status, $error_cause) = tst_status_merge($root);
[9a50a2]809        if (! $WINNT)
810        {
[93e538]811          mysystem("$gzip -cf \"$root.res\" | $uuencode \"$root.res.gz\" > \"$root.res.gz.uu\"");
[9a50a2]812        }
813        else
814        {
815          # uuencode is broken under windows
816          print "Warning: Can not generate $root.res.gz.uu under Windows\n";
817        }
[e2114af]818      }
[9a50a2]819      elsif (%merge)
[e2114af]820      {
[93e538]821        ($exit_status, $error_cause) = tst_status_merge($root);
[9a50a2]822         
[31f293]823        print (STDERR "Warning: Merge Problems: $error_cause\n")
824          if ($verbosity > 0 && $exit_status);
[e2114af]825      }
826    }
[e960fdf]827    if ($keep ne "yes")
[d5e119]828    {
[93e538]829      mysystem("$rm -f tst_status.out $resfile \"$root.res\" \"$root.diff\" \"$root.new.stat\"");
[b21d63]830    }
[b35b93]831  }
[d5e119]832  # und tschuess
[2ae411d]833  unless ($verbosity == 0 || $exit_status)
[6d01ca]834  {
835    if ($verbosity > 1 || $timings_only)
836    {
837      my $used_time = $cuser_t + $csystem_t;
838      $total_used_time += $used_time;
839      $lst_used_time += $used_time;
840      print " " x (23 - length($root));
841      printf("%.2f", $used_time);
842    }
843    print " \n";
844  }
[2ae411d]845  $total_checks_pass++ unless $exit_status;
[f5128b8]846
[93e538]847  mysystem("mv gmon.out \"gmon.$root.out\"") if (-e "gmon.out");
[ebb444]848 
[1a300b9]849  testFinished($test_file, $cuser_t + $csystem_t);
850 
[93e538]851  $test_files{$test_file} = $exit_status;
[b35b93]852  return ($exit_status);
853}
854
855
856#################################################################
[b21d63]857#
[b35b93]858# Main program
[b21d63]859#
[b35b93]860
861# process switches
862while ($ARGV[0] =~ /^-/)
863{
864  $_ = shift;
865  if (/^-s$/)
866  {
867    $singular = shift;
868  }
869  elsif (/^-h$/)
870  {
871    &Usage && exit (0);
872  }
873  elsif (/^-k$/)
874  {
875    $keep = "yes";
876  }
877  elsif (/^-g$/)
878  {
879    $generate = "yes";
880  }
881  elsif(/^-v$/)
882  {
883    $verbosity = shift;
884  }
[0b20296]885  elsif (/^-tt/)
886  {
887    $mtrack = shift;
888  }
[a7bb142]889  elsif (/^-A/)
890  {
891    $timeout = shift;
892  }
[1a300b9]893  elsif (/^-C$/)
894  {
895    $teamcity = shift;
896  }
[9a50a2]897  elsif(/^-t$/)
898  {
899    $mtrack = 1;
900  }
[6d01ca]901  elsif (/^-T/)
902  {
903    $timings_only = 1;
904  }
[e960fdf]905  elsif(/^-r$/)
906  {
907    $crit = "all";
908    $val = $report_val;
909    if ($ARGV[0] =~ /.*%.*/)
910    {
911      ($crit, $val) = split(/%/, shift);
912    }
[b21d63]913    elsif ($ARGV[0] &&
914           $ARGV[0] !~ /^-/ && $ARGV[0] !~ /.*\.tst/ && $ARGV[0] !~ /.*\.lst/)
[e960fdf]915    {
916      $crit = shift;
917    }
918    if ($crit eq "all")
919    {
920      $report{"tst_memory_0"} = $val;
921      $report{"tst_memory_1"} = $val;
922      $report{"tst_memory_2"} = $val;
923      $report{"tst_timer"} = $val;
924      $report{"tst_timer_1"} = $val;
[b21d63]925      $checks{"tst_memory_0"} = 1;
[e960fdf]926      $checks{"tst_memory_1"} = 1;
[b21d63]927      $checks{"tst_memory_2"} =  1;
928      $checks{"tst_timer"} =  1;
929      $checks{"tst_timer_1"} =  1;
[e960fdf]930    }
931    else
932    {
933      $report{$crit} = $val;
934      $checks{$crit} = 1;
935    }
936  }
937  elsif(/^-e$/)
938  {
939    $crit = "all";
940    $val = $error_val;
941    if ($ARGV[0] =~ /.*%.*/)
942    {
943      ($crit, $val) = split(/%/, shift);
944    }
[b21d63]945    elsif ($ARGV[0] &&
946            $ARGV[0] !~ /^-/ && $ARGV[0] !~ /.*\.tst/ && $ARGV[0] !~ /.*\.lst/)
[e960fdf]947    {
948      $crit = shift;
949    }
950    if ($crit eq "all")
951    {
952      $error{"tst_memory_0"} = $val;
953      $error{"tst_memory_1"} = $val;
954      $error{"tst_memory_2"} = $val;
955      $error{"tst_timer"} = $val;
956      $error{"tst_timer_1"} = $val;
[b21d63]957      $checks{"tst_memory_0"} = 1;
[e960fdf]958      $checks{"tst_memory_1"} = 1;
[b21d63]959      $checks{"tst_memory_2"} =  1;
960      $checks{"tst_timer"} =  1;
961      $checks{"tst_timer_1"} =  1;
[e960fdf]962    }
963    else
964    {
965      $error{$crit} = $val;
966      $checks{$crit} = 1;
967    }
968  }
[31f293]969  elsif(/^-a/ || /^-m/)
[e960fdf]970  {
[31f293]971    $merge_version = 1 if /^-m/;
[b21d63]972    if ($ARGV[0] &&
973        $ARGV[0] !~ /^-/ && $ARGV[0] !~ /.*\.tst/ && $ARGV[0] !~ /.*\.lst/)
[e960fdf]974    {
975      $crit = shift;
976      $merge{$crit} = 1;
977    }
978    else
979    {
[b21d63]980      $merge{"tst_memory_0"} = 1;
[e960fdf]981      $merge{"tst_memory_1"} = 1;
[b21d63]982      $merge{"tst_memory_2"} =  1;
983      $merge{"tst_timer"} =  1;
984      $merge{"tst_timer_1"} =  1;
[e960fdf]985    }
986  }
[31f293]987  elsif (/^-c/)
988  {
989    $status_check_regexp = shift;
990  }
[b21d63]991  else
[b35b93]992  {
993    print (STDERR "Unrecognised option: $_\n") && &Usage && die;
994  }
995}
996
997# if no command line arguments are left, use regress.lst
998if ($#ARGV == -1)
999{
1000  $ARGV[0] = "regress.lst";
1001}
1002
1003# make sure $singular exists and is executable
[55f154]1004$singular = "$curr_dir/$singular" unless ($singular =~ /^\/.*/);
[d5e119]1005
[4c79e7]1006if ( ! (-e $singular))
1007{
1008  $singular = "$singular$ext"   if ($WINNT && $singular !~ /.*$ext$/);
1009}
1010
[b35b93]1011if ( ! (-e $singular))
1012{
1013  print (STDERR "Can not find $singular \n") && &Usage && die;
1014}
[4c79e7]1015
1016if (! (-x $singular) && (! WINNT))
[b35b93]1017{
[d5e119]1018  print (STDERR "Can not execute $singular \n") && &Usage && die;
1019}
1020if (-d $singular)
1021{
1022  print (STDERR "$singular is a directory\n") && &Usage && die;
[b35b93]1023}
1024
[867952]1025sub ViewFile
1026{
1027  local($f) = $_[0];
1028 
1029  local($ff) = myGetTCprop($f);
1030  local($b) = "$f: " . $ff;
1031   
1032  blockOpened ($b);
[93e538]1033  mysystem("cat " . $ff);
[867952]1034  blockClosed ($b);
1035}
1036
[663baa]1037
[e1b6326]1038# if( length($teamcity) > 0 )
1039# {
1040#  #  tcLog("|Hi|\r I\'m [Alex]|\nHow are You?|");
1041#
1042#  blockOpened ("init");
1043
1044# #  print ("TEAMCITY_BUILD_PROPERTIES_FILE: $ENV{TEAMCITY_BUILD_PROPERTIES_FILE}" );
1045
1046#  tcLog("TEAMCITY_BUILD_PROPERTIES_FILE: $ENV{TEAMCITY_BUILD_PROPERTIES_FILE}");
1047#
1048#  if ( length("$ENV{TEAMCITY_BUILD_PROPERTIES_FILE}") > 0 )
1049#  {
1050#    print( "teamcity.tests.runRiskGroupTestsFirst: " . myGetTCprop("teamcity.tests.runRiskGroupTestsFirst") . "\n" );
1051#
1052#    ViewFile("teamcity.tests.recentlyFailedTests.file");
1053#    ViewFile("teamcity.build.changedFiles.file");
1054#    ViewFile("teamcity.build.properties.file");
1055#    ViewFile("teamcity.configuration.properties.file");
1056#    ViewFile("teamcity.runner.properties.file");
1057#  }
1058#   
1059#  blockClosed ("init");
1060# }
[1a300b9]1061
[a7bb142]1062if ($timeout > 0)
1063{
[ebb444]1064  $singular = "PERL_SIGNALS=unsafe perl -e 'alarm($timeout);exec(\@ARGV);' $singular";
[1a300b9]1065  tcLog ("Set exec timeout to $timeout sec.\n");
[a7bb142]1066  # die;
1067}
[1a300b9]1068
[394beb]1069# testSuiteStarted($teamcity);
[1a300b9]1070
[663baa]1071# now do the work
1072foreach (@ARGV)
[b35b93]1073{
[52f5a58]1074  if( /^([^:]*): *(.*)$/ )
1075  {
1076    $_=$2;
1077  }
1078
1079  if ( /^\s*([^ ].*)$/ )
1080  {
1081    $_ = $1;
1082  } 
1083 
1084  if ( /^\.\/(.*)$/ )
1085  {
1086    $_ = $1;
1087  }
1088
[1a300b9]1089  $test_file = $_;
[b35b93]1090
[1a300b9]1091  tcLog("test_file: $test_file");
[52f5a58]1092
[b21d63]1093  if ( /^(.*)\.([^\.\/]*)$/ )
[d5e119]1094  {
1095    $_ = $1;
1096    $extension = $2;
[52f5a58]1097  } else
1098  {
1099    print ("Wrong input: [$_] has no extension!");
1100    tcWarn("Wrong input: [$_] has no extension!");
1101    next;
[d5e119]1102  }
[52f5a58]1103   
1104 
1105   
1106   
[d5e119]1107
[b21d63]1108  if ( /^(.*)\/([^\/]*)$/ )
[d5e119]1109  {
1110    $path = $1;
1111    $base = $2;
1112    chdir($path);
[6d01ca]1113    print "cd $path\n" if ($verbosity > 2);
[b21d63]1114  }
1115  else
[d5e119]1116  {
1117    $path = "";
1118    $base = $_;
1119  }
[1a300b9]1120
1121  tcLog("path: $path, base: $base, extension: $extension");
1122
[d5e119]1123  $file = "$base.$extension";
1124  chop ($tst_curr_dir = `pwd`);
[b21d63]1125
[b35b93]1126  if ($extension eq "tst")
1127  {
[93e538]1128    $exit_code = tst_check($base) || $exit_code;
[b35b93]1129  }
1130  elsif ($extension eq "lst")
1131  {
[d5e119]1132    if (! open(LST_FILE, "<$file"))
[b35b93]1133    {
[d5e119]1134      print (STDERR "Can not open $path/$file for reading\n");
[b35b93]1135      $exit_code = 1;
[1a300b9]1136      testIgnored($test_file, "Can not open $path/$file for reading");
[b35b93]1137      next;
1138    }
[1a300b9]1139
1140    local ($b) = $test_file;
1141    blockOpened ($b);
1142   
[6d01ca]1143    $lst_used_time = 0;
1144    $lst_checks = 0;
1145    $lst_checks_pass = 0;
[b35b93]1146    while (<LST_FILE>)
1147    {
[d5e119]1148      if (/^;/)          # ignore lines starting with ;
[b35b93]1149      {
[663baa]1150        print unless ($verbosity == 0);
[b21d63]1151        next;
[b35b93]1152      }
[52f5a58]1153  if( /^([^:]*): *(.*)$/ )
1154  {
1155    $_=$2;
1156  }
1157
1158  if ( /^\s*([^\s].*)$/ )
1159  {
1160    $_ = $1;
1161  } 
1162 
1163  if ( /^\.\/(.*)$/ )
1164  {
1165    $_ = $1;
1166  }
1167       
[d5e119]1168      next if (/^\s*$/); #ignore whitespaced lines
[663baa]1169      chop if (/\n$/);   #chop of \n
[1a300b9]1170 
1171      tcLog("path: $path, test_file: $_, file: $file");
1172     
1173      if (length($path) > 0)
1174      {
1175        $test_file = "$path/$_";
1176      }
1177      else
1178      {
1179        $test_file = $_;
1180      }
[52f5a58]1181
1182      $test_file =~ s/^[ ]*\.\///;
[1a300b9]1183                     
1184     
1185      $_ = $1 if (/^(.*)\.([^\.\/]*)$/ ); # chop of extension (.tst!!!?)
[b21d63]1186      if ( /^(.*)\/([^\/]*)$/ )
[d5e119]1187      {
[b21d63]1188        $tst_path = $1;
1189        $tst_base = $2;
[d5e119]1190        chdir($tst_path);
[6d01ca]1191        print "cd $tst_path\n" if ($verbosity > 2);
[b21d63]1192      }
1193      else
[d5e119]1194      {
[b21d63]1195        $tst_path = "";
1196        $tst_base = $_;
[d5e119]1197      }
[9a50a2]1198      $tst_base =~ s/^\s*//;
1199      $tst_base =~ s/(.*?)\s+.*/$1/;
[6d01ca]1200      $lst_checks++;
[1a300b9]1201
1202      tcLog("tst_path: $tst_path, tst_base: $tst_base");
1203     
[93e538]1204      my $this_exit_code = tst_check($tst_base);
[1a300b9]1205
[6d01ca]1206      $lst_checks_pass++ unless $this_exit_code;
1207      $exit_code = $this_exit_code || $exit_code;
[d5e119]1208
1209      if ($tst_path ne "")
1210      {
[b21d63]1211        chdir($tst_curr_dir);
[6d01ca]1212        print "cd $tst_curr_dir\n" if ($verbosity > 2);
[d5e119]1213      }
[b35b93]1214    }
1215    close (LST_FILE);
[93e538]1216     
1217    printf("$base Summary: Checks:$lst_checks Failed:%d Time:%.2f\n", $lst_checks - $lst_checks_pass, $lst_used_time)
[1a300b9]1218      unless ($verbosity < 2);
[93e538]1219     
1220    tcLog( sprintf("list '$base' Summary: Checks:$lst_checks Failed:%d Time:%.2f", $lst_checks - $lst_checks_pass, $lst_used_time) );
[1a300b9]1221    blockClosed ($b);
[b35b93]1222  }
1223  else
1224  {
1225    print (STDERR "Unknown extension of $_: Need extension lst or tst\n");
1226    $exit_code = 1;
1227  }
[d5e119]1228  if ($path ne "")
1229  {
[663baa]1230    chdir($curr_dir);
[6d01ca]1231    print "cd $curr_dir\n" if ($verbosity > 2);
[d5e119]1232  }
[b35b93]1233}
1234
[6d01ca]1235unless ($verbosity < 2 || $lst_checks == $total_checks)
1236{
1237  printf("Summary: Checks:$total_checks Failed:%d Time:%.2f\n", $total_checks - $total_checks_pass, $total_used_time);
1238}
1239
[93e538]1240tcLog( sprintf("Global Summary: Checks:$total_checks Failed:%d Time:%.2f", $total_checks - $total_checks_pass, $total_used_time)) ;
1241
[1a300b9]1242if( length($teamcity) > 0 )
1243{
[394beb]1244#  testSuiteFinished($teamcity);
[617c427]1245
[867952]1246#  blockOpened ("init");
[617c427]1247 
1248#  print ("TEAMCITY_BUILD_PROPERTIES_FILE: $ENV{TEAMCITY_BUILD_PROPERTIES_FILE}" );
1249
[867952]1250#  blockClosed ("init");
[617c427]1251   
1252   
1253   
[1a300b9]1254
1255
1256
[b35b93]1257# Und Tschuess
1258exit $exit_code;
1259
1260
Note: See TracBrowser for help on using the repository browser.