scaleway commit
[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/;
1cebb7de 9use Gruntmaster::Daemon::Format qw/copy_from_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...");
21
1cebb7de 22 my @fds = $ENV{GRUNTMASTER_VM} ? qw,0 ../fifo1 1 >../fifo2, : qw/0 fifo1 1 >fifo2/;
61470035
MG
23 $meta->{files}{prog}{run}->($meta->{files}{prog}{name}, nonblocking => 1, fds => \@fds, map { $_ => $meta->{$_} } qw/timeout mlimit/);
24
25 my $fail;
1cebb7de 26 @fds = $ENV{GRUNTMASTER_VM} ? qw,1 >../fifo1 0 ../fifo2, : qw/1 >fifo1 0 fifo2/;
61470035 27 try {
b59254d7 28 $meta->{files}{ver}{run}->($meta->{files}{ver}{name}, fds => [@fds, qw,3 input 4 >result,], args => [$test], map { $_ => $meta->{$_} } qw/timeout mlimit/);
61470035
MG
29 } catch {
30 $fail = [WA, 'Wrong Answer'];
31 };
32
33 try {
34 Gruntmaster::Daemon::Format::execlist_finish(prog => !$fail);
35 } catch {
36 $fail = $_;
37 };
a722431b 38
61470035 39 die $fail if $fail; ## no critic (RequireCarping)
1cebb7de 40 copy_from_vm 'result';
34a91d9a 41 scalar slurp 'result' or 'Ok'
5c5cd38a
MG
42}
43
8aec2ffe
MG
441;
45__END__
46
47=encoding utf-8
48
49=head1 NAME
50
51Gruntmaster::Daemon::Runner::Interactive - Make an interactive verifier talk to the program
52
53=head1 SYNOPSIS
54
55 use Gruntmaster::Daemon::Runner::Interactive;
0005d3ad 56 Gruntmaster::Daemon::Runner::Interactive::run(5, $meta);
8aec2ffe
MG
57
58=head1 DESCRIPTION
59
60B<WARNING: This runner is experimental!>
61
0005d3ad 62Gruntmaster::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
63
64=head1 AUTHOR
65
66Marius Gavrilescu E<lt>marius@ieval.roE<gt>
67
68=head1 COPYRIGHT AND LICENSE
69
70Copyright (C) 2014 by Marius Gavrilescu
71
72This library is free software: you can redistribute it and/or modify
73it under the terms of the GNU Affero General Public License as published by
74the Free Software Foundation, either version 3 of the License, or
75(at your option) any later version.
76
77
78=cut
This page took 0.023701 seconds and 4 git commands to generate.