]>
Commit | Line | Data |
---|---|---|
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/; | |
9 | use Gruntmaster::Daemon::Format qw/copy_from_vm copy_to_vm/; | |
10 | use Log::Log4perl qw/get_logger/; | |
11 | use POSIX qw/mkfifo/; | |
12 | use Try::Tiny; | |
13 | ||
14 | our $VERSION = '5999.000_005'; | |
15 | ||
16 | ################################################## | |
17 | ||
18 | sub run{ | |
19 | my ($test, $meta) = @_; | |
20 | get_logger->trace("Running on test $test..."); | |
21 | copy_to_vm 'input'; | |
22 | ||
23 | my @fds = $ENV{GRUNTMASTER_VM} ? qw,0 ../fifo1 1 >../fifo2, : qw/0 fifo1 1 >fifo2/; | |
24 | $meta->{files}{prog}{run}->($meta->{files}{prog}{name}, nonblocking => 1, fds => \@fds, map { $_ => $meta->{$_} } qw/timeout mlimit/); | |
25 | ||
26 | my $fail; | |
27 | @fds = $ENV{GRUNTMASTER_VM} ? qw,1 >../fifo1 0 ../fifo2, : qw/1 >fifo1 0 fifo2/; | |
28 | try { | |
29 | $meta->{files}{ver}{run}->($meta->{files}{ver}{name}, fds => [@fds, qw,3 input 4 >result,], args => [$test], map { $_ => $meta->{$_} } qw/timeout mlimit/); | |
30 | } catch { | |
31 | $fail = [WA, 'Wrong Answer']; | |
32 | }; | |
33 | ||
34 | try { | |
35 | Gruntmaster::Daemon::Format::execlist_finish(prog => !$fail); | |
36 | } catch { | |
37 | $fail = $_; | |
38 | }; | |
39 | ||
40 | die $fail if $fail; ## no critic (RequireCarping) | |
41 | copy_from_vm 'result'; | |
42 | scalar slurp 'result' or 'Ok' | |
43 | } | |
44 | ||
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; | |
57 | Gruntmaster::Daemon::Runner::Interactive::run(5, $meta); | |
58 | ||
59 | =head1 DESCRIPTION | |
60 | ||
61 | B<WARNING: This runner is experimental!> | |
62 | ||
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. | |
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 |