run_test.pl 2.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#! /usr/bin/perl

print "Running test : $ARGV[0] \n";
open IN, "< $ARGV[0]";


my $title = <IN>;
chomp $title;
my $call = <IN>;
chomp $call;

my $nominal ;

while (my $line = <IN>) {
15 16 17 18
  chomp $line;
  if ($line =~ s/Result of verification is //) {
    $nominal = $line;
    last;
19 20 21 22 23 24 25 26 27 28 29 30 31
  }
}

close IN;

# Now run the tool# 

# print "syscalling : $call \n";
print "##teamcity[testStarted name='$title']\n";

my $tested;

my @outputs = ();
32
my @results = `$call 2>&1;`;
33 34

while (my $line = shift(@results)) {
35
  chomp $line;
36
  push (@outputs,$line);
37
  if ($line =~ s/Result of verification is //) {
38 39
    $tested = $line;
  }
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
  # report some stats to teamcity
  if ($line =~ s/^discrete states://) {
    my @splitline = split(' ',$line);
    print "##teamcity[buildStatisticValue key='discrete states' value='$splitline[0]']\n";
  }
  if ($line =~ s/^states seen://) {
    my @splitline = split(' ',$line);
    print "##teamcity[buildStatisticValue key='states seen' value='$splitline[0]']\n";
  }
  if ($line =~ s/^states explored://) {
    my @splitline = split(' ',$line);
    print "##teamcity[buildStatisticValue key='states explored' value='$splitline[0]']\n";
  }
  if ($line =~ s/^incl tests://) {
    my @splitline = split(' ',$line);
    print "##teamcity[buildStatisticValue key='inclusion tests' value='$splitline[0]']\n";
  }
  if ($line =~ s/^pos\. incl tests://) {
    my @splitline = split(' ',$line);
    print "##teamcity[buildStatisticValue key='successful inclusion tests' value='$splitline[0]']\n";
  }
61 62 63 64 65 66 67 68 69 70
}

# retrieve the exit value of the test
my $failure;
if ($? == 0) {
  $failure = 0;
} else {
  $failure = 1;
}

71
my $tc_output = join("|n", @outputs);
72 73 74 75
# escape characters for TeamCity
$tc_output =~ s/\[/\|\[/g;
$tc_output =~ s/\]/\|\]/g;
$tc_output =~ s/'/\|'/g;
76
my $reg_output = join("\n", @outputs);
77
if ( $failure ) {
78 79
  print "$reg_output\n";
  print "\n##teamcity[testFailed name='$title' message='test did not exit properly' details='$tc_output' expected='$nominal' actual='$tested'] \n";
80 81 82
  print "Expected :  $nominal  Obtained :  $tested \n"; 
  my $exitval = $? >> 8;
  print "test exited with value $exitval\n";
83 84 85 86
} elsif ( $nominal ne $tested ) {
  print "$reg_output\n";
  print "\n##teamcity[testFailed name='$title' message='regression detected' details='$tc_output' expected='$nominal' actual='$tested'] \n";
  print "Expected :  $nominal  Obtained :  $tested \n";
87 88 89 90 91 92 93 94
} else {
#   print "##teamcity[buildStatisticValue key='testDuration' value='@tested[2]']\n";
#   print "##teamcity[buildStatisticValue key='testMemory' value='@tested[3]']\n";
  print "Test successful : $title \n";
  print "Control Values/Obtained : \n$title\n$nominal\n$tested\n";
}

print "##teamcity[testFinished name='$title']\n";