-
Notifications
You must be signed in to change notification settings - Fork 139
/
runit_test.pl
executable file
·64 lines (51 loc) · 1.22 KB
/
runit_test.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/perl -w
## No license, we won't release this file.
###############################################################################
use strict;
use File::stat;
use File::Temp;
use Cwd;
# 0 : success
# 1 : timeout
# 2 : ...
sub runit ($$$) {
my ($command, $timeout, $out) = @_;
print "\n\ntimeout is $timeout\n";
my $res;
eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
alarm $timeout;
system "$command";
alarm 0;
$res = $?;
};
my $success = 0;
my $exit_value;
if ($@ eq "alarm\n") {
print "'$command' timed out after $timeout second(s)\n";
$exit_value = -1;
goto out;
}
if ($res & 127) {
print "died while executing '$command'\n";
goto out;
}
if ($res == -1) {
print "can't execute '$command'\n";
goto out;
}
$success = 1;
$exit_value = $res >> 8;
out:
print "command '$command' has success = $success, exit value = $exit_value\n";
return ($success, $exit_value);
}
if (1) {
while (1) {
runit ("./nonterm.pl", 1+int(rand(3)), "");
}
} else {
runit ("sleep 5", 1, "/dev/null");
runit ("sleep 1", 5, "/dev/null");
runit ("gleep 1", 5, "/dev/null");
}