Test pipes when running interactive programs before executing them
authorMarius Gavrilescu <marius@ieval.ro>
Wed, 29 Jul 2015 11:32:10 +0000 (14:32 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Wed, 29 Jul 2015 11:32:10 +0000 (14:32 +0300)
This is relevant for VM users, as the pipes used by QEMU do not work
at the beginning (all data sent to them is silently discarded).

gruntmaster-exec

index fd79d8f316c322c9008f14bbe98b402772011c77..d2807656d506909f27e14d68897b2317f20c4f53 100755 (executable)
@@ -39,6 +39,25 @@ GetOptions(
        "sudo!"        => \$sudo,
 );
 
        "sudo!"        => \$sudo,
 );
 
+sub test_pipe_read {
+       my $data = '';
+       sysread STDIN, $data, 4096 and syswrite STDOUT, "recvd\n" until $data =~ /done/;
+       syswrite STDOUT, 'done';
+}
+
+sub test_pipe_write {
+       my ($rin, $rout);
+       vec($rin, fileno STDIN, 1) = 1;
+       syswrite STDOUT, "data\n" until select $rout = $rin, undef, undef, 0.05;
+       syswrite STDOUT, 'done';
+       my $data = '';
+       sysread STDIN, $data, 4096 until $data =~ /done/;
+}
+
+sub test_pipes {
+       $ARGV[0] =~ /prog/ ? test_pipe_read : test_pipe_write
+}
+
 my $killuser = $ENV{GRUNTMASTER_KILL_USER};
 my @sudo;
 @sudo = (shellwords ($ENV{GRUNTMASTER_SUDO}), '--') if $ENV{GRUNTMASTER_SUDO} && $sudo;
 my $killuser = $ENV{GRUNTMASTER_KILL_USER};
 my @sudo;
 @sudo = (shellwords ($ENV{GRUNTMASTER_SUDO}), '--') if $ENV{GRUNTMASTER_SUDO} && $sudo;
@@ -88,6 +107,7 @@ if ($ret) {
                        POSIX::close $oldfd or die $!;
                }
        }
                        POSIX::close $oldfd or die $!;
                }
        }
+       test_pipes if grep /tty|fifo/, @fds;
        my $nproc = $killuser ? 15 : 1;
        my $debug = $ENV{TEST_VERBOSE};
        %ENV = (ONLINE_JUDGE => 1, PATH => $ENV{PATH}, HOME => $ENV{HOME});
        my $nproc = $killuser ? 15 : 1;
        my $debug = $ENV{TEST_VERBOSE};
        %ENV = (ONLINE_JUDGE => 1, PATH => $ENV{PATH}, HOME => $ENV{HOME});
This page took 0.011318 seconds and 4 git commands to generate.