- my $basename = fileparse $name, qr/\.[^.]*/;
- my $ret = fork // die 'Cannot fork';
- if ($ret) {
- my $tle;
- local $SIG{ALRM} = sub { kill KILL => $ret; $tle = 1};
- alarm $args{timeout} if exists $args{timeout};
- wait;
- alarm 0;
- my $sig = $? & 127;
- my $signame = sig_name $sig;
- die [TLE, "Time Limit Exceeded"] if $tle;
- die [OLE, 'Output Limit Exceeded'] if $sig && $signame eq 'XFSZ';
- die [DIED, "Crash (SIG$signame)"] if $sig;
- die [NZX, "Non-zero exit status: " . ($? >> 8)] if $?;
- } else {
- my @fds = exists $args{fds} ? @{$args{fds}} : ();
- $^F = 50;
- POSIX::close $_ for 0 .. $^F;
- my $it = natatime 2, @fds;
- while (my ($fd, $file) = $it->()) {
- open my $fh, $file or die $!;
- my $oldfd = fileno $fh;
- if ($oldfd != $fd) {
- POSIX::dup2 $oldfd, $fd or die $!;
- POSIX::close $oldfd or die $!;
- }
+ get_logger->trace("Running $name...");
+ my $basename = fileparse $name, qr/[.][^.]*/s;
+ my @args = ('--sudo');
+ push @args, '--keep-stderr' if $ENV{TEST_VERBOSE};
+ push @args, '--timeout', $args{timeout} if $args{timeout};
+ push @args, '--mlimit', $args{mlimit} if $args{mlimit};
+ push @args, '--olimit', $args{olimit} if $args{olimit};
+ my @fds = exists $args{fds} ? @{$args{fds}} : ();
+ my $it = natatime 2, @fds;
+ while (my ($fd, $file) = $it->()) {
+ push @args, "--fd=$fd $file";
+ }
+ execlist $basename, @args, '--', "./$basename", @{$args{args}};
+ execlist_finish $basename unless $args{nonblocking}
+ }
+}
+
+sub prepare{
+ my ($name, $format) = @_;
+ get_logger->trace("Preparing file $name...");
+
+ try {
+ execlist prog => '--fd=1 >>errors', '--fd=2 >>errors', 'gruntmaster-compile', $format, $name;
+ execlist_finish 'prog';
+ } catch {
+ my $exmsg = $_->[1];
+ die "Compile error ($exmsg)\n"
+ } finally {
+ copy_from_vm 'errors';
+ $Gruntmaster::Daemon::errors .= read_file 'errors';
+ $Gruntmaster::Daemon::errors .= "\n" if -s 'errors';
+ unlink 'errors';
+ };
+}
+
+sub prepare_files{
+ my $meta = shift;
+ if ($meta->{runner} eq 'Interactive') {
+ runvm ver => '-serial unix:vm.sock,nowait,server';
+ runvm prog => '-serial unix:vm.sock,nowait';
+ } else {
+ runvm $_ for keys %{$meta->{files}};
+ }
+
+ for my $file (values %{$meta->{files}}) {
+ my ($format, $name, $content) = @{$file}{qw/format name content/};
+
+ $file->{run} = mkrun($format);
+ write_file $name, $content;
+ copy_to_vm $name;
+ if ($ENV{GRUNTMASTER_CCACHE}) {
+ my $key = lc sha256_hex($content) . '-' . $format;
+ my $cachefn = "$ENV{GRUNTMASTER_CCACHE}/$key";
+ my $exefn = fileparse $name, qr/[.][^.]*/s;
+ if (cp $cachefn, $exefn) {
+ get_logger->trace("File $name found in compilation cache")
+ } else {
+ prepare $name, $format;
+ cp $exefn, $cachefn