commit
authorMarius Gavrilescu <marius@ieval.ro>
Tue, 2 Feb 2016 23:13:41 +0000 (23:13 +0000)
committerMarius Gavrilescu <marius@ieval.ro>
Tue, 2 Feb 2016 23:13:41 +0000 (23:13 +0000)
environ [new file with mode: 0644]
gruntmaster-exec
lib/Gruntmaster/Daemon.pm
lib/Gruntmaster/Daemon/Format.pm
lib/Gruntmaster/Daemon/Runner/File.pm
lib/Gruntmaster/Daemon/Runner/Interactive.pm
lib/Gruntmaster/Daemon/Runner/Verifier.pm
t/01-jobs.t

diff --git a/environ b/environ
new file mode 100644 (file)
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
+
+
index d2807656d506909f27e14d68897b2317f20c4f53..97ac555311340538bb1271704b6a63fbf1c3b704 100755 (executable)
@@ -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;
index 7189c84185b9a4b343e1c4c78ea4ebd1366c0a3c..59ee1650c8a05a8f939e301bdb361234ea590b64 100644 (file)
@@ -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 File::Slurp qw/read_file/;
 use File::Temp qw/tempdir/;
@@ -83,6 +83,7 @@ sub process{
 
                        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 - $start_time}
index 2ad6f9519f4b8d82b3d7a892b8360bf514f0707c..41f235499d6928579eca84be9150bcde888cea8e 100644 (file)
@@ -17,27 +17,43 @@ use String::ShellQuote qw/shell_quote/;
 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 = ();
 }
 
@@ -46,7 +62,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;
@@ -54,6 +70,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;
@@ -112,6 +129,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';
@@ -132,6 +150,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";
index c0811634b4e244f790739b22c4ddedcd9294e1bd..d521acf40c033c0056884b6ac5859df554473040 100644 (file)
@@ -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
index d16e08e12a4f7d6b894d942a851d2d86e872de05..9006dfe90814b296d7b6f020bd90d3357b3d3fb7 100644 (file)
@@ -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,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'
 }
 
index 4145954dc6a3017ef664e1ef4f03a70263671df6..0690ddcb4a33b1eb085a8af7463a775b504f0b55 100644 (file)
@@ -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';
 }
 
index 2cb1eb19ed57b6da83d5e5dcea85aa38e306a83d..ee9cb27a6cdc25d9e662512d8be49755856f55f0 100644 (file)
@@ -95,8 +95,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;
This page took 0.019878 seconds and 4 git commands to generate.