Pass the test number to the interactive verifier
[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/;
9use Log::Log4perl qw/get_logger/;
10use POSIX qw/mkfifo/;
11use Try::Tiny;
12
d6a1ae0d 13our $VERSION = '5999.000_002';
bc372959 14
5c5cd38a
MG
15##################################################
16
17sub run{
a722431b
MG
18 my ($test, $meta) = @_;
19 get_logger->trace("Running on test $test...");
20
21 mkfifo 'fifo1', 0600 or die $! unless -e 'fifo1';
22 mkfifo 'fifo2', 0600 or die $! unless -e 'fifo2';
23
24 my $ret = fork // get_logger->logdie("Fork failed: $!");
25 if ($ret) {
26 $meta->{files}{prog}{run}->($meta->{files}{prog}{name}, fds => [qw/0 fifo1 1 >fifo2/], map {defined $meta->{$_} ? ($_ => $meta->{$_}) : () } qw/timeout mlimit/);
27 waitpid $ret, 0;
28 die [WA, "Wrong Answer"] if $?;
29 } else {
30 try {
967faabc 31 $meta->{files}{ver}{run}->($meta->{files}{ver}{name}, fds => [qw/1 >fifo1 0 fifo2 4 >result/], args => [$test]);
a722431b
MG
32 } catch {
33 exit 1;
34 };
35 exit
36 }
37
38 scalar slurp 'result'
5c5cd38a
MG
39}
40
8aec2ffe
MG
411;
42__END__
43
44=encoding utf-8
45
46=head1 NAME
47
48Gruntmaster::Daemon::Runner::Interactive - Make an interactive verifier talk to the program
49
50=head1 SYNOPSIS
51
52 use Gruntmaster::Daemon::Runner::Interactive;
53 Gruntmaster::Daemon::Runner::Interactive->run(5, $meta);
54
55=head1 DESCRIPTION
56
57B<WARNING: This runner is experimental!>
58
59Gruntmaster::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}{int} >>, should return nonzero if the program gives an incorrect answer, and print the test score to fd 4 then return 0 if the answer is correct.
60
61=head1 AUTHOR
62
63Marius Gavrilescu E<lt>marius@ieval.roE<gt>
64
65=head1 COPYRIGHT AND LICENSE
66
67Copyright (C) 2014 by Marius Gavrilescu
68
69This library is free software: you can redistribute it and/or modify
70it under the terms of the GNU Affero General Public License as published by
71the Free Software Foundation, either version 3 of the License, or
72(at your option) any later version.
73
74
75=cut
This page took 0.015977 seconds and 4 git commands to generate.