]>
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 Log::Log4perl qw/get_logger/; | |
10 | use POSIX qw/mkfifo/; | |
11 | use Try::Tiny; | |
12 | ||
13 | our $VERSION = '5999.000_005'; | |
14 | ||
15 | ################################################## | |
16 | ||
17 | sub run{ | |
18 | my ($test, $meta) = @_; | |
19 | get_logger->trace("Running on test $test..."); | |
20 | ||
21 | mkfifo 'fifo1', 0600 or die "$!\n" unless -e 'fifo1'; | |
22 | mkfifo 'fifo2', 0600 or die "$!\n" unless -e 'fifo2'; | |
23 | ||
24 | my @fds = $ENV{GRUNTMASTER_VM} ? qw,0 /dev/ttyS1 1 >/dev/ttyS1, : qw/0 fifo1 1 >fifo2/; | |
25 | $meta->{files}{prog}{run}->($meta->{files}{prog}{name}, nonblocking => 1, fds => \@fds, map { $_ => $meta->{$_} } qw/timeout mlimit/); | |
26 | ||
27 | my $fail; | |
28 | @fds = $ENV{GRUNTMASTER_VM} ? qw,1 >/dev/ttyS1 0 /dev/ttyS1, : qw/1 >fifo1 0 fifo2/; | |
29 | try { | |
30 | $meta->{files}{ver}{run}->($meta->{files}{ver}{name}, fds => [@fds, qw,3 input 4 >result,], args => [$test], map { $_ => $meta->{$_} } qw/timeout mlimit/); | |
31 | } catch { | |
32 | $fail = [WA, 'Wrong Answer']; | |
33 | }; | |
34 | ||
35 | try { | |
36 | Gruntmaster::Daemon::Format::execlist_finish(prog => !$fail); | |
37 | } catch { | |
38 | $fail = $_; | |
39 | }; | |
40 | ||
41 | unlink 'fifo1'; | |
42 | unlink 'fifo2'; | |
43 | ||
44 | die $fail if $fail; ## no critic (RequireCarping) | |
45 | scalar slurp 'result' or 'Ok' | |
46 | } | |
47 | ||
48 | 1; | |
49 | __END__ | |
50 | ||
51 | =encoding utf-8 | |
52 | ||
53 | =head1 NAME | |
54 | ||
55 | Gruntmaster::Daemon::Runner::Interactive - Make an interactive verifier talk to the program | |
56 | ||
57 | =head1 SYNOPSIS | |
58 | ||
59 | use Gruntmaster::Daemon::Runner::Interactive; | |
60 | Gruntmaster::Daemon::Runner::Interactive::run(5, $meta); | |
61 | ||
62 | =head1 DESCRIPTION | |
63 | ||
64 | B<WARNING: This runner is experimental!> | |
65 | ||
66 | 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. | |
67 | ||
68 | =head1 AUTHOR | |
69 | ||
70 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> | |
71 | ||
72 | =head1 COPYRIGHT AND LICENSE | |
73 | ||
74 | Copyright (C) 2014 by Marius Gavrilescu | |
75 | ||
76 | This library is free software: you can redistribute it and/or modify | |
77 | it under the terms of the GNU Affero General Public License as published by | |
78 | the Free Software Foundation, either version 3 of the License, or | |
79 | (at your option) any later version. | |
80 | ||
81 | ||
82 | =cut |