Copy input to Scaleway in Interactive.pm
[gruntmaster-daemon.git] / lib / Gruntmaster / Daemon / Runner / Interactive.pm
CommitLineData
5c5cd38a
MG
1package Gruntmaster::Daemon::Runner::Interactive;
2
3use 5.014000;
4use strict;
5use warnings;
6
7use File::Slurp qw/slurp/;
8use Gruntmaster::Daemon::Constants qw/WA/;
a7a946e3 9use Gruntmaster::Daemon::Format qw/copy_from_vm copy_to_vm/;
5c5cd38a
MG
10use Log::Log4perl qw/get_logger/;
11use POSIX qw/mkfifo/;
12use Try::Tiny;
13
3fa65372 14our $VERSION = '5999.000_005';
bc372959 15
5c5cd38a
MG
16##################################################
17
18sub run{
a722431b
MG
19 my ($test, $meta) = @_;
20 get_logger->trace("Running on test $test...");
a7a946e3 21 copy_to_vm 'input';
a722431b 22
1cebb7de 23 my @fds = $ENV{GRUNTMASTER_VM} ? qw,0 ../fifo1 1 >../fifo2, : qw/0 fifo1 1 >fifo2/;
61470035
MG
24 $meta->{files}{prog}{run}->($meta->{files}{prog}{name}, nonblocking => 1, fds => \@fds, map { $_ => $meta->{$_} } qw/timeout mlimit/);
25
26 my $fail;
1cebb7de 27 @fds = $ENV{GRUNTMASTER_VM} ? qw,1 >../fifo1 0 ../fifo2, : qw/1 >fifo1 0 fifo2/;
61470035 28 try {
b59254d7 29 $meta->{files}{ver}{run}->($meta->{files}{ver}{name}, fds => [@fds, qw,3 input 4 >result,], args => [$test], map { $_ => $meta->{$_} } qw/timeout mlimit/);
61470035
MG
30 } catch {
31 $fail = [WA, 'Wrong Answer'];
32 };
33
34 try {
35 Gruntmaster::Daemon::Format::execlist_finish(prog => !$fail);
36 } catch {
37 $fail = $_;
38 };
a722431b 39
61470035 40 die $fail if $fail; ## no critic (RequireCarping)
1cebb7de 41 copy_from_vm 'result';
34a91d9a 42 scalar slurp 'result' or 'Ok'
5c5cd38a
MG
43}
44
8aec2ffe
MG
451;
46__END__
47
48=encoding utf-8
49
50=head1 NAME
51
52Gruntmaster::Daemon::Runner::Interactive - Make an interactive verifier talk to the program
53
54=head1 SYNOPSIS
55
56 use Gruntmaster::Daemon::Runner::Interactive;
0005d3ad 57 Gruntmaster::Daemon::Runner::Interactive::run(5, $meta);
8aec2ffe
MG
58
59=head1 DESCRIPTION
60
61B<WARNING: This runner is experimental!>
62
0005d3ad 63Gruntmaster::Daemon::Runner::Interactive is a runner which runs the program and an interactive verifier in parallel, connecting each program's STDIN to the other's STDOUT. The verifier, C<< $meta->{files}{ver} >>, should return nonzero if the program gives an incorrect answer, or print the test score to fd 4 then return 0 if the answer is correct.
8aec2ffe
MG
64
65=head1 AUTHOR
66
67Marius Gavrilescu E<lt>marius@ieval.roE<gt>
68
69=head1 COPYRIGHT AND LICENSE
70
71Copyright (C) 2014 by Marius Gavrilescu
72
73This library is free software: you can redistribute it and/or modify
74it under the terms of the GNU Affero General Public License as published by
75the Free Software Foundation, either version 3 of the License, or
76(at your option) any later version.
77
78
79=cut
This page took 0.022723 seconds and 4 git commands to generate.