From 7642e909a5b6666f529f452a435c3a3b5e5a562a Mon Sep 17 00:00:00 2001 From: Wolfram Schneider Date: Thu, 6 Feb 2014 16:54:20 +0100 Subject: [PATCH] bomb.pl - wrapper to stop a process after N seconds, MKWS-110 --- test/Makefile | 2 +- test/bomb.pl | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100755 test/bomb.pl mode change 100755 => 100644 test/bomp.pl diff --git a/test/Makefile b/test/Makefile index bf0f561..b44cf64 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,7 +3,7 @@ # For running on Mike's local install of node.js MIKE = PATH=$$PATH:/usr/local/lib/node-v0.10.24-linux-x64/bin NPM_INSTALL_FLAGS=-q -PHANTOMJS= ./node_modules/phantomjs/bin/phantomjs +PHANTOMJS= ./bomb.pl ./node_modules/phantomjs/bin/phantomjs PHANTOMJS_URL= https://mkws-dev.indexdata.com/jasmine-popup.html PHANTOMJS_TIMEOUT= 12 IMAGES= ./images diff --git a/test/bomb.pl b/test/bomb.pl new file mode 100755 index 0000000..d78d2cc --- /dev/null +++ b/test/bomb.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl +# Copyright (c) 2014 IndexData ApS. http://indexdata.com +# +# bomb.pl - wrapper to stop a process after N seconds +# + +use Getopt::Long; + +use strict; +use warnings; + +my $debug = 0; +my $help; +my $timeout = 100; + +binmode \*STDOUT, ":utf8"; +binmode \*STDERR, ":utf8"; + +# timeout handler +sub set_alarm { + my $time = shift; + my $message = shift || ""; + + $time = 100 if !defined $time; + + $SIG{ALRM} = sub { + + warn "Time out alarm $time\n"; + + # sends a hang-up signal to all processes in the current process group + # and kill running java processes + local $SIG{HUP} = "IGNORE"; + kill 1, -$$; + + local $SIG{TERM} = "IGNORE"; + kill 15, -$$; + kill 15, -$$; + + warn "Send a hang-up to all childs.\n"; + + #exit 1; + }; + + warn "set alarm time to: $time seconds $message\n" if $debug >= 1; + alarm($time); +} + +sub usage () { + < \$help, + "debug=i" => \$debug, + "timeout=i" => \$timeout, +) or die usage; + +my @system = @ARGV; + +die usage if $help; +die usage if !@system; + +set_alarm( $timeout, join( " ", @system ) ); + +system(@system) == 0 + or die "@system failed with exit code: $?\n"; + +exit(0); diff --git a/test/bomp.pl b/test/bomp.pl old mode 100755 new mode 100644 -- 1.7.10.4