--- /dev/null
+#export PURGE_HOSTS=127.0.0.1:8000
+#export GRUNTMASTER_CCACHE=/var/lib/gruntmasterd/ccache
+#export GRUNTMASTER_KILL_USER=nobody
+export GRUNTMASTER_DAEMON=user0@212.47.237.202
+export GRUNTMASTER_VM=sshvm
+export GRUNTMASTER_COPY_TO_VM=copy-to-vm
+export GRUNTMASTER_COPY_FROM_VM=copy-from-vm
+
+
$ARGV[0] =~ /prog/ ? test_pipe_read : test_pipe_write
}
-my $killuser = $ENV{GRUNTMASTER_KILL_USER};
my @sudo;
@sudo = (shellwords ($ENV{GRUNTMASTER_SUDO}), '--') if $ENV{GRUNTMASTER_SUDO} && $sudo;
undef $mlimit if @sudo; # sudo wants a lot of address space
exit !say ERR, "\nNo response from gruntmaster-exec child";
}
local $SIG{ALRM} = sub {
- if ($killuser) {
- system @sudo, 'pkill', '-KILL', '-u', $killuser;
- } else {
- kill KILL => $ret
- }
+ kill KILL => $ret;
$tle = 1
};
alarm ($timeout || 10);
}
}
test_pipes if grep /tty|fifo/, @fds;
- my $nproc = $killuser ? 15 : 1;
+ my $nproc = 15;
my $debug = $ENV{TEST_VERBOSE};
%ENV = (ONLINE_JUDGE => 1, PATH => $ENV{PATH}, HOME => $ENV{HOME});
setrlimit RLIMIT_AS, $mlimit, $mlimit or die $! if $mlimit;
our $VERSION = '5999.000_005';
use Gruntmaster::Daemon::Constants qw/ERR/;
-use Gruntmaster::Daemon::Format qw/prepare_files stopvms/;
+use Gruntmaster::Daemon::Format qw/prepare_files copy_from_vm stopvms/;
use Gruntmaster::SendResults qw/send_results_request/;
use File::Slurp qw/read_file/;
unlink 'time-start-prog', 'time-stop-prog';
if (ref $result) {
my $result_text = $result->[1];
+ copy_from_vm 'result';
$result_text .= ': ' . read_file 'result' if -s 'result';
get_logger->trace("Test $test result is " . $result_text);
push @full_results, {id => $test, result => $result->[0], result_text => $result_text, time => $time}
use Try::Tiny;
our $VERSION = '5999.000_005';
-our @EXPORT_OK = qw/prepare_files stopvms/;
+our @EXPORT_OK = qw/copy_from_vm copy_to_vm prepare_files stopvms/;
##################################################
our (%vm, %pid);
+sub copy_from_vm {
+ my ($file) = @_;
+ return unless $ENV{GRUNTMASTER_COPY_FROM_VM};
+ get_logger->trace("Copying $file from VM");
+ system $ENV{GRUNTMASTER_COPY_FROM_VM}, $file
+}
+
+sub copy_to_vm {
+ my ($file) = @_;
+ return unless $ENV{GRUNTMASTER_COPY_TO_VM};
+ get_logger->trace("Copying $file to VM");
+ system $ENV{GRUNTMASTER_COPY_TO_VM}, $file
+}
+
sub runvm {
my ($name, $arg) = @_;
return unless $ENV{GRUNTMASTER_VM};
- my $cmd = $ENV{GRUNTMASTER_VM};
+ my $cmd = $ENV{GRUNTMASTER_VM} . ' ' . $name;
$cmd .= ' ' . $arg if $arg;
get_logger->trace("Starting VM $name ($cmd)");
$vm{$name} = Expect->new;
$vm{$name}->raw_pty(1);
$vm{$name}->log_stdout(0);
$vm{$name}->spawn($cmd);
- $vm{$name}->expect(5, '# ') or get_logger->logdie("Error while starting VM $name: ". $vm{$name}->error);
+ $vm{$name}->expect(50, '# ') or get_logger->logdie("Error while starting VM $name: ". $vm{$name}->error);
+ $vm{$name}->send("rm -rf ~/work/*\n");
+ $vm{$name}->expect(50, '# ')
}
sub stopvms {
- kill KILL => $_->pid for values %vm;
+ $_->hard_close for values %vm;
%vm = %pid = ();
}
if ($vm{$vm}) {
warn "Cannot kill VM\n" if $kill;
- $vm{$vm}->expect(5, '# ');
+ $vm{$vm}->expect(50, '# ');
} else {
kill KILL => $pid{$vm} if $kill;
waitpid $pid{$vm}, 0;
return if $kill;
my $er = "exec-result-$vm";
+ copy_from_vm $er;
die "gruntmaster-exec died\n" if -z $er;
my ($excode, $exmsg) = read_file $er;
unlink $er;
my $exmsg = $_->[1];
die "Compile error ($exmsg)\n"
} finally {
+ copy_from_vm 'errors';
$Gruntmaster::Daemon::errors .= read_file 'errors';
$Gruntmaster::Daemon::errors .= "\n" if -s 'errors';
unlink 'errors';
$file->{run} = mkrun($format);
write_file $name, $content;
+ copy_to_vm $name;
if ($ENV{GRUNTMASTER_CCACHE}) {
my $key = lc sha256_hex($content) . '-' . $format;
my $cachefn = "$ENV{GRUNTMASTER_CCACHE}/$key";
use re '/s';
use Gruntmaster::Daemon::Constants qw/WA/;
+use Gruntmaster::Daemon::Format qw/copy_to_vm copy_from_vm/;
use File::Slurp qw/slurp/;
use Log::Log4perl qw/get_logger/;
sub run{
my ($test, $meta) = @_;
get_logger->trace("Running on test $test...");
+ copy_to_vm 'input';
$meta->{files}{prog}{run}->($meta->{files}{prog}{name}, fds => [qw/0 input 1 >output/], map { $_ => $meta->{$_} } qw/timeout olimit mlimit/);
+ copy_from_vm 'output';
my $out = slurp 'output';
my $ok;
if (exists $meta->{okfile}) { # uncoverable branch false
use File::Slurp qw/slurp/;
use Gruntmaster::Daemon::Constants qw/WA/;
+use Gruntmaster::Daemon::Format qw/copy_from_vm/;
use Log::Log4perl qw/get_logger/;
use POSIX qw/mkfifo/;
use Try::Tiny;
my ($test, $meta) = @_;
get_logger->trace("Running on test $test...");
- mkfifo 'fifo1', 0600 or die "$!\n" unless -e 'fifo1';
- mkfifo 'fifo2', 0600 or die "$!\n" unless -e 'fifo2';
-
- my @fds = $ENV{GRUNTMASTER_VM} ? qw,0 /dev/ttyS1 1 >/dev/ttyS1, : qw/0 fifo1 1 >fifo2/;
+ my @fds = $ENV{GRUNTMASTER_VM} ? qw,0 ../fifo1 1 >../fifo2, : qw/0 fifo1 1 >fifo2/;
$meta->{files}{prog}{run}->($meta->{files}{prog}{name}, nonblocking => 1, fds => \@fds, map { $_ => $meta->{$_} } qw/timeout mlimit/);
my $fail;
- @fds = $ENV{GRUNTMASTER_VM} ? qw,1 >/dev/ttyS1 0 /dev/ttyS1, : qw/1 >fifo1 0 fifo2/;
+ @fds = $ENV{GRUNTMASTER_VM} ? qw,1 >../fifo1 0 ../fifo2, : qw/1 >fifo1 0 fifo2/;
try {
$meta->{files}{ver}{run}->($meta->{files}{ver}{name}, fds => [@fds, qw,3 input 4 >result,], args => [$test], map { $_ => $meta->{$_} } qw/timeout mlimit/);
} catch {
$fail = $_;
};
- unlink 'fifo1';
- unlink 'fifo2';
-
die $fail if $fail; ## no critic (RequireCarping)
+ copy_from_vm 'result';
scalar slurp 'result' or 'Ok'
}
use warnings;
use Gruntmaster::Daemon::Constants qw/WA/;
+use Gruntmaster::Daemon::Format qw/copy_to_vm copy_from_vm/;
use File::Slurp qw/slurp/;
use Log::Log4perl qw/get_logger/;
use Try::Tiny;
sub run{
my ($test, $meta) = @_;
get_logger->trace("Running on test $test...");
+ copy_to_vm 'input';
$meta->{files}{prog}{run}->($meta->{files}{prog}{name}, fds => [qw/0 input 1 >output/], map { $_ => $meta->{$_} } qw/timeout olimit mlimit/);
try {
} catch {
die [WA, 'Wrong answer'] ## no critic (RequireCarping)
};
+ copy_from_vm 'result';
scalar slurp 'result' or 'Ok';
}
if ($meta->{files}{prog}) {
my $format = $meta->{files}{prog}{format};
my $compiler = COMPILER->{$format};
- skip "$compiler not found in path", 3 unless $ENV{GRUNTMASTER_VM} || which $compiler;
- skip "$format requires multiple processes. Set GRUNTMASTER_KILL_USER and GRUNTMASTER_SUDO to allow multiple processes.", 3 if !$ENV{GRUNTMASTER_KILL_USER} && $needs_fork{$format};
+# skip "$compiler not found in path", 3 unless $ENV{GRUNTMASTER_VM} || which $compiler;
+# skip "$format requires multiple processes. Set GRUNTMASTER_KILL_USER and GRUNTMASTER_SUDO to allow multiple processes.", 3 if !$ENV{GRUNTMASTER_KILL_USER} && $needs_fork{$format};
$meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}";
}
$meta = merge $meta, $pbmeta;