Commit d131058e authored by Guillaume Huard's avatar Guillaume Huard
Browse files

Cached compilation results, better colors

parent f3389f85
#!/usr/bin/perl -w
use strict;
use File::Slurp;
use File::Temp;
use File::Copy;
use Data::Dumper;
use Errno;
use IPC::Open3;
......@@ -49,7 +51,7 @@ sub title($) {
sub grade($) {
my $score = sprintf("%.2f", shift);
colored_output('GREEN', "Grade :=>>$score\n");
hidden("Grade :=>>$score\n");
}
sub error($) {
......@@ -62,8 +64,16 @@ sub error($) {
exit 1;
}
sub warning(@) {
colored_output('RED', @_);
}
sub debug(@) {
colored_output('RED', @_) if $mode{debug};
colored_output('GREEN', @_) if $mode{debug};
}
sub hidden(@) {
colored_output('YELLOW', @_);
}
sub remove(@) {
......@@ -285,10 +295,10 @@ sub dispatch_error($$$) {
my $data = shift;
my $soft_fail = shift;
print $data->{output} if length($data->{output});
print STDERR $data->{error} if length($data->{error});
warning($data->{output}) if length($data->{output});
warning($data->{error}) if length($data->{error});
if ($soft_fail) {
print $message, "\n";
warning("$message\n");
} else {
error($message);
}
......@@ -332,18 +342,26 @@ sub run_special($$$$$) {
}
}
# compile if required
if (exists($special->{compile})) { # && !$special->{compiled}) {
debug("Compiling $name with @{$special->{files}}\n");
setup_env($name, $special);
my $data = run_special($name, '.compile', $special->{compile}, $special, 0);
if ($data->{failure}) {
$data->{compilation_error} = 1;
return $data;
if (exists($special->{compile})) {
if (exists($special->{compiled})) {
my $tmp_name = $special->{compiled};
debug("Retrieving compiled file $tmp_name for $name\n");
copy($tmp_name, $name);
} else {
print("Compilation output : $data->{output}\n") if length($data->{output});
print STDERR ("Compilation error : $data->{error}\n") if length($data->{error});
my $tmp_name = mktemp("/tmp/${name}_XXXXXX");
debug("Compiling $name with @{$special->{files}}, saving it to $tmp_name\n");
setup_env($name, $special);
my $data = run_special($name, '.compile', $special->{compile}, $special, 0);
if ($data->{failure}) {
$data->{compilation_error} = 1;
return $data;
} else {
warning("Compilation output : $data->{output}\n") if length($data->{output});
warning("Compilation error : $data->{error}\n") if length($data->{error});
copy($name, $tmp_name);
$special->{compiled} = $tmp_name;
}
}
# $special->{compiled} = 1;
}
# Adds limits if any
if (exists($special->{output_limit}) || exists($special->{error_limit}) || exists($special->{timeout})) {
......@@ -359,7 +377,7 @@ sub run_special($$$$$) {
$result = run_command($test_name, "./$name", $test, $has_limits);
}
if (exists($special->{content})) {
remove("$name") unless $special->{keep}; # or $special->{compiled};
remove("$name") unless $special->{keep};
}
return $result;
}
......@@ -465,7 +483,7 @@ sub perform_tests($$) {
if (exists($test->{setup})) {
my $setup = run_special($test_name, '.setup', $test->{setup}, $test, 0);
foreach my $part ('output', 'error') {
print STDERR "Setup $part :\n$setup->{$part}" if length($setup->{$part});
warning("Setup $part :\n$setup->{$part}") if length($setup->{$part});
}
dispatch_error("*** POSSIBLE ERROR : Setup exited with ".format_error($setup), $setup, 1)
if $setup->{failure};
......@@ -479,6 +497,7 @@ sub perform_tests($$) {
$result = 0;
$break_loop = 1;
} else {
$case->{compiled} = $test->{compiled} if exists($test->{compiled});
clean_outputs($data, $test);
$details .= "With the input:\n".preformat($test->{input})."\n" if length($test->{input});
$details .= "With the arguments: '@{$test->{args}}'\n" if $test->{args};
......@@ -613,8 +632,8 @@ sub evaluate_file($) {
foreach my $arg (@ARGV) {
$mode{lc($arg)} = 1;
}
print "*** Running in local mode ***\n" if $mode{local};
print "*** Running in debug mode ***\n" if $mode{debug};
hidden("*** Running in local mode ***\n") if $mode{local};
hidden("*** Running in debug mode ***\n") if $mode{debug};
debug("VPL_SUBFILES : $ENV{VPL_SUBFILES}\n");
# read local setup and testcases to run
......@@ -641,7 +660,6 @@ foreach my $name (sort(keys(%$test_cases))) {
my $title = "Test case $name".(($weight > 1)?" (weight ".$weight.")":"");
title($title);
print("-".$title."\n") unless $mode{local};
# Tests
my $test_score = perform_tests($name, $case);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment