Permalink
Browse files

allow resource limits to be set via BSD::Resource.

this should prevent runaway tests from killing the system
(by eating all the memory, for instance).
  • Loading branch information...
1 parent 8156c4e commit 3aaf6b2c07cccf12b59c191644d100b31dd4c158 @ligne committed Jun 30, 2011
Showing with 37 additions and 0 deletions.
  1. +37 −0 bin/sheba.pl
View
@@ -11,6 +11,7 @@
use IPC::Run qw( run );
use List::PowerSet qw( powerset );
use Tie::Pick;
+use BSD::Resource;
# returns a config hash thing
@@ -59,6 +60,13 @@ sub load_config
test_jobs => 6,
harness_verbosity => -2,
+
+ priority => 10, # niceness
+ limits => {
+ # see BSD::Resource docs for details
+ cpu => 600, # cpu time in seconds
+ as => 1e9, # memory usage (stack, heap, et al.)
+ },
};
}
@@ -90,6 +98,33 @@ sub random_config_generator
sub _flatten { return map { ref eq 'ARRAY' ? @$_ : $_ } @_ }
+sub set_limits
+{
+ my ($priority, $limits) = @_;
+
+ if (defined $priority) {
+ # catch exceptions when setpriority(2) isn't available.
+ # which = PRIO_PROCESS, who = self.
+ eval { setpriority(0, 0, $priority) }
+ or warn "Failed to set priority: $!\n";
+ }
+
+ return unless $limits;
+
+ my $rlimits = get_rlimits();
+
+ while (my ($name, $limit) = each %$limits) {
+ my $resource = $rlimits->{"RLIMIT_\U$name\E"};
+ say "Limiting '$name' is not supported on this system"
+ unless defined $resource;
+
+ # set both hard and soft to the same limit
+ setrlimit($resource, $limit, $limit)
+ or say "Failed to set priority: $!";
+ }
+}
+
+
# _run_command(@command, [ \%options ]);
#
# runs @command in a subprocess. returns true if it completed ok, false
@@ -156,6 +191,8 @@ sub main
local $ENV{TEST_JOBS} = $config->{test_jobs};
local $ENV{HARNESS_VERBOSE} = $config->{harness_verbosity};
+ set_limits($config->{priority}, $config->{limits});
+
# fetch the configurations to test
my @configurations = parrot_configs($config);

0 comments on commit 3aaf6b2

Please sign in to comment.