]>
Commit | Line | Data |
---|---|---|
5c5cd38a MG |
1 | package Gruntmaster::Daemon::Runner::Interactive; |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | ||
7 | use File::Slurp qw/slurp/; | |
8 | use Gruntmaster::Daemon::Constants qw/WA/; | |
a7a946e3 | 9 | use Gruntmaster::Daemon::Format qw/copy_from_vm copy_to_vm/; |
5c5cd38a MG |
10 | use Log::Log4perl qw/get_logger/; |
11 | use POSIX qw/mkfifo/; | |
12 | use Try::Tiny; | |
13 | ||
3fa65372 | 14 | our $VERSION = '5999.000_005'; |
bc372959 | 15 | |
5c5cd38a MG |
16 | ################################################## |
17 | ||
18 | sub 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 |
45 | 1; |
46 | __END__ | |
47 | ||
48 | =encoding utf-8 | |
49 | ||
50 | =head1 NAME | |
51 | ||
52 | Gruntmaster::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 | ||
61 | B<WARNING: This runner is experimental!> | |
62 | ||
0005d3ad | 63 | Gruntmaster::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 | ||
67 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> | |
68 | ||
69 | =head1 COPYRIGHT AND LICENSE | |
70 | ||
71 | Copyright (C) 2014 by Marius Gavrilescu | |
72 | ||
73 | This library is free software: you can redistribute it and/or modify | |
74 | it under the terms of the GNU Affero General Public License as published by | |
75 | the Free Software Foundation, either version 3 of the License, or | |
76 | (at your option) any later version. | |
77 | ||
78 | ||
79 | =cut |