1 package Gruntmaster
::Daemon
::Runner
::Interactive
;
7 use File
::Slurp qw
/slurp/;
8 use Gruntmaster
::Daemon
::Constants qw
/WA/;
9 use Log
::Log4perl qw
/get_logger/;
13 our $VERSION = '5999.000_004';
15 ##################################################
18 my ($test, $meta) = @_;
19 get_logger
->trace("Running on test $test...");
21 mkfifo
'fifo1', 0600 or die "$!\n" unless -e
'fifo1';
22 mkfifo
'fifo2', 0600 or die "$!\n" unless -e
'fifo2';
24 if ($test == 1 && $ENV{GRUNTMASTER_VM
}) {
25 exec 'cat <prog.out >ver.in' if fork;
26 exec 'cat <ver.out >prog.in' if fork;
29 my $ret = fork // get_logger
->logdie("Fork failed: $!");
32 my @fds = $ENV{GRUNTMASTER_VM
} ? qw
,0 /dev/ttyS1
1 >/dev/ttyS1
, : qw
/0 fifo1 1 >fifo2/;
33 $meta->{files
}{prog
}{run
}->($meta->{files
}{prog
}{name
}, fds
=> \
@fds, map {defined $meta->{$_} ?
($_ => $meta->{$_}) : () } qw
/timeout mlimit/);
35 die $_ ## no critic (RequireCarping)
39 die [WA
, 'Wrong Answer'] if $?
; ## no critic (RequireCarping)
42 my @fds = $ENV{GRUNTMASTER_VM
} ? qw
,1 >/dev/ttyS1
0 /dev/ttyS1
, : qw
/1 >fifo1 0 fifo2/;
43 $meta->{files
}{ver
}{run
}->($meta->{files
}{ver
}{name
}, fds
=> [@fds, qw
,4 >result
,], args
=> [$test], map {defined $meta->{$_} ?
($_ => $meta->{$_}) : () } qw
/timeout mlimit/);
63 Gruntmaster::Daemon::Runner::Interactive - Make an interactive verifier talk to the program
67 use Gruntmaster::Daemon::Runner::Interactive;
68 Gruntmaster::Daemon::Runner::Interactive::run(5, $meta);
72 B<WARNING: This runner is experimental!>
74 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.
78 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
80 =head1 COPYRIGHT AND LICENSE
82 Copyright (C) 2014 by Marius Gavrilescu
84 This library is free software: you can redistribute it and/or modify
85 it under the terms of the GNU Affero General Public License as published by
86 the Free Software Foundation, either version 3 of the License, or
87 (at your option) any later version.
This page took 0.02811 seconds and 5 git commands to generate.