From 1cebb7de90ce9e5a25ef5805ff9b54936f64ac71 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Tue, 2 Feb 2016 23:13:41 +0000 Subject: [PATCH] scaleway commit --- environ | 9 ++++++ gruntmaster-exec | 9 ++---- lib/Gruntmaster/Daemon.pm | 3 +- lib/Gruntmaster/Daemon/Format.pm | 29 ++++++++++++++++---- lib/Gruntmaster/Daemon/Runner/File.pm | 3 ++ lib/Gruntmaster/Daemon/Runner/Interactive.pm | 12 +++----- lib/Gruntmaster/Daemon/Runner/Verifier.pm | 3 ++ t/01-jobs.t | 4 +-- 8 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 environ diff --git a/environ b/environ new file mode 100644 index 0000000..f99e88f --- /dev/null +++ b/environ @@ -0,0 +1,9 @@ +#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 + + diff --git a/gruntmaster-exec b/gruntmaster-exec index d280765..97ac555 100755 --- a/gruntmaster-exec +++ b/gruntmaster-exec @@ -58,7 +58,6 @@ sub test_pipes { $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 @@ -73,11 +72,7 @@ if ($ret) { 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); @@ -108,7 +103,7 @@ if ($ret) { } } 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; diff --git a/lib/Gruntmaster/Daemon.pm b/lib/Gruntmaster/Daemon.pm index 9597572..7285c96 100644 --- a/lib/Gruntmaster/Daemon.pm +++ b/lib/Gruntmaster/Daemon.pm @@ -7,7 +7,7 @@ use warnings; 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/; @@ -88,6 +88,7 @@ sub process{ 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} diff --git a/lib/Gruntmaster/Daemon/Format.pm b/lib/Gruntmaster/Daemon/Format.pm index 6d6bd8f..2f117d7 100644 --- a/lib/Gruntmaster/Daemon/Format.pm +++ b/lib/Gruntmaster/Daemon/Format.pm @@ -18,27 +18,43 @@ use Time::HiRes qw/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 = (); } @@ -47,7 +63,7 @@ sub execlist_finish { 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; @@ -56,6 +72,7 @@ sub execlist_finish { 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; @@ -115,6 +132,7 @@ sub prepare{ 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'; @@ -135,6 +153,7 @@ sub prepare_files{ $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"; diff --git a/lib/Gruntmaster/Daemon/Runner/File.pm b/lib/Gruntmaster/Daemon/Runner/File.pm index c081163..d521acf 100644 --- a/lib/Gruntmaster/Daemon/Runner/File.pm +++ b/lib/Gruntmaster/Daemon/Runner/File.pm @@ -6,6 +6,7 @@ use warnings; 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/; @@ -16,7 +17,9 @@ our $VERSION = '5999.000_005'; 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 diff --git a/lib/Gruntmaster/Daemon/Runner/Interactive.pm b/lib/Gruntmaster/Daemon/Runner/Interactive.pm index 3595e4a..45f4ae4 100644 --- a/lib/Gruntmaster/Daemon/Runner/Interactive.pm +++ b/lib/Gruntmaster/Daemon/Runner/Interactive.pm @@ -6,6 +6,7 @@ use warnings; 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; @@ -18,14 +19,11 @@ sub run{ 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 { @@ -38,10 +36,8 @@ sub run{ $fail = $_; }; - unlink 'fifo1'; - unlink 'fifo2'; - die $fail if $fail; ## no critic (RequireCarping) + copy_from_vm 'result'; scalar slurp 'result' or 'Ok' } diff --git a/lib/Gruntmaster/Daemon/Runner/Verifier.pm b/lib/Gruntmaster/Daemon/Runner/Verifier.pm index 4145954..0690ddc 100644 --- a/lib/Gruntmaster/Daemon/Runner/Verifier.pm +++ b/lib/Gruntmaster/Daemon/Runner/Verifier.pm @@ -5,6 +5,7 @@ use strict; 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; @@ -16,6 +17,7 @@ our $VERSION = '5999.000_005'; 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 { @@ -23,6 +25,7 @@ sub run{ } catch { die [WA, 'Wrong answer'] ## no critic (RequireCarping) }; + copy_from_vm 'result'; scalar slurp 'result' or 'Ok'; } diff --git a/t/01-jobs.t b/t/01-jobs.t index c37e081..b486371 100644 --- a/t/01-jobs.t +++ b/t/01-jobs.t @@ -98,8 +98,8 @@ for my $problem (@problems) { 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; -- 2.39.2