From c85acb7ba71b153806632256b511b915b872c5bc Mon Sep 17 00:00:00 2001 From: netblue30 Date: Wed, 13 Apr 2016 20:47:18 -0400 Subject: wait up to 10 seconds for sandbox shutdown --- test/catchsignal-master.sh | 4 +++ test/catchsignal.sh | 27 +++++++++++++++++++ test/catchsignal2.sh | 49 ++++++++++++++++++++++++++++++++++ test/option-shutdown2.exp | 42 +++++++++++++++++++++++++++++ test/option-shutdown3.exp | 62 +++++++++++++++++++++++++++++++++++++++++++ test/option-shutdown4.exp | 66 ++++++++++++++++++++++++++++++++++++++++++++++ test/pid.exp | 2 +- test/test.sh | 9 +++++++ 8 files changed, 260 insertions(+), 1 deletion(-) create mode 100755 test/catchsignal-master.sh create mode 100755 test/catchsignal.sh create mode 100755 test/catchsignal2.sh create mode 100755 test/option-shutdown2.exp create mode 100755 test/option-shutdown3.exp create mode 100755 test/option-shutdown4.exp (limited to 'test') diff --git a/test/catchsignal-master.sh b/test/catchsignal-master.sh new file mode 100755 index 000000000..62a1801cc --- /dev/null +++ b/test/catchsignal-master.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +./catchsignal.sh & +./catchsignal.sh & diff --git a/test/catchsignal.sh b/test/catchsignal.sh new file mode 100755 index 000000000..87a1d0adf --- /dev/null +++ b/test/catchsignal.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +_term() { + echo "Caught Signal" + echo 1 + sleep 1 + echo 2 + sleep 1 + echo 3 + sleep 1 + echo 4 + sleep 1 + echo 5 + sleep 1 + + kill $pid + exit +} + +trap _term SIGTERM +trap _term SIGINT + +echo "Sleeping..." + +sleep inf & +pid=$! +wait $pid diff --git a/test/catchsignal2.sh b/test/catchsignal2.sh new file mode 100755 index 000000000..424350397 --- /dev/null +++ b/test/catchsignal2.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +_term() { + echo "Caught Signal" + echo 1 + sleep 1 + echo 2 + sleep 1 + echo 3 + sleep 1 + echo 4 + sleep 1 + echo 5 + sleep 1 + + echo 10 + sleep 1 + echo 20 + sleep 1 + echo 30 + sleep 1 + echo 40 + sleep 1 + echo 50 + sleep 1 + + echo 100 + sleep 1 + echo 200 + sleep 1 + echo 300 + sleep 1 + echo 400 + sleep 1 + echo 500 + sleep 1 + + kill $pid + exit +} + +trap _term SIGTERM +trap _term SIGINT + +echo "Sleeping..." + +sleep inf & +pid=$! +wait $pid diff --git a/test/option-shutdown2.exp b/test/option-shutdown2.exp new file mode 100755 index 000000000..403bc30be --- /dev/null +++ b/test/option-shutdown2.exp @@ -0,0 +1,42 @@ +#!/usr/bin/expect -f + +set timeout 10 +spawn $env(SHELL) +match_max 100000 + +set firstspawn $spawn_id + +send -- "firejail --name=shutdowntesting ./catchsignal.sh\r" +expect { + timeout {puts "TESTING ERROR 0\n";exit} + "Child process initialized" +} +sleep 2 + +spawn $env(SHELL) +send -- "firejail --shutdown=shutdowntesting\r" + +set spawn_id $firstspawn +expect { + timeout {puts "TESTING ERROR 1\n";exit} + "1" +} +expect { + timeout {puts "TESTING ERROR 2\n";exit} + "2" +} +expect { + timeout {puts "TESTING ERROR 3\n";exit} + "3" +} +expect { + timeout {puts "TESTING ERROR 4\n";exit} + "4" +} +expect { + timeout {puts "TESTING ERROR 5\n";exit} + "5" +} +sleep 1 + +puts "\nalldone\n" diff --git a/test/option-shutdown3.exp b/test/option-shutdown3.exp new file mode 100755 index 000000000..0ef371cd8 --- /dev/null +++ b/test/option-shutdown3.exp @@ -0,0 +1,62 @@ +#!/usr/bin/expect -f + +set timeout 10 +spawn $env(SHELL) +match_max 100000 + +set firstspawn $spawn_id + +send -- "firejail --name=shutdowntesting ./catchsignal-master.sh\r" +expect { + timeout {puts "TESTING ERROR 0\n";exit} + "Child process initialized" +} +sleep 2 + +spawn $env(SHELL) +send -- "firejail --shutdown=shutdowntesting\r" + +set spawn_id $firstspawn +expect { + timeout {puts "TESTING ERROR 1\n";exit} + "1" +} +expect { + timeout {puts "TESTING ERROR 2\n";exit} + "1" +} +expect { + timeout {puts "TESTING ERROR 3\n";exit} + "2" +} +expect { + timeout {puts "TESTING ERROR 4\n";exit} + "2" +} +expect { + timeout {puts "TESTING ERROR 5\n";exit} + "3" +} +expect { + timeout {puts "TESTING ERROR 6\n";exit} + "3" +} +expect { + timeout {puts "TESTING ERROR 7\n";exit} + "4" +} +expect { + timeout {puts "TESTING ERROR 8\n";exit} + "4" +} +expect { + timeout {puts "TESTING ERROR 9\n";exit} + "5" +} +expect { + timeout {puts "TESTING ERROR 10\n";exit} + "5" +} +sleep 1 + +puts "\nalldone\n" diff --git a/test/option-shutdown4.exp b/test/option-shutdown4.exp new file mode 100755 index 000000000..f188ec66d --- /dev/null +++ b/test/option-shutdown4.exp @@ -0,0 +1,66 @@ +#!/usr/bin/expect -f + +set timeout 10 +spawn $env(SHELL) +match_max 100000 + +set firstspawn $spawn_id + +send -- "firejail --name=shutdowntesting ./catchsignal2.sh\r" +expect { + timeout {puts "TESTING ERROR 0\n";exit} + "Child process initialized" +} +sleep 2 + +spawn $env(SHELL) +send -- "firejail --shutdown=shutdowntesting\r" + +set spawn_id $firstspawn +expect { + timeout {puts "TESTING ERROR 1\n";exit} + "1" +} +expect { + timeout {puts "TESTING ERROR 2\n";exit} + "2" +} +expect { + timeout {puts "TESTING ERROR 3\n";exit} + "3" +} +expect { + timeout {puts "TESTING ERROR 4\n";exit} + "4" +} +expect { + timeout {puts "TESTING ERROR 5\n";exit} + "5" +} +expect { + timeout {puts "TESTING ERROR 10\n";exit} + "10" +} +expect { + timeout {puts "TESTING ERROR 20\n";exit} + "20" +} +expect { + timeout {puts "TESTING ERROR 30\n";exit} + "30" +} +expect { + timeout {puts "TESTING ERROR 40\n";exit} + "40" +} +expect { + timeout {puts "TESTING ERROR 50\n";exit} + "50" +} +expect { + timeout {puts "TESTING ERROR 60\n";exit} + "Killed" +} +sleep 1 + +puts "\nalldone\n" diff --git a/test/pid.exp b/test/pid.exp index fb5b90f04..cdeb9d5fb 100755 --- a/test/pid.exp +++ b/test/pid.exp @@ -37,7 +37,7 @@ sleep 1 send -- "ps aux |wc -l; pwd\r" expect { timeout {puts "TESTING ERROR 5\n";exit} - "6" {puts "normal system\n'} + "6" {puts "normal system\n"} "5" {puts "grsecurity\n"} } expect { diff --git a/test/test.sh b/test/test.sh index 96ef8f423..c6fe4f299 100755 --- a/test/test.sh +++ b/test/test.sh @@ -133,6 +133,15 @@ echo "TESTING: rlimit (option_rlimit.exp)" echo "TESTING: shutdown (option_shutdown.exp)" ./option-shutdown.exp +echo "TESTING: shutdown2 (option_shutdown2.exp)" +./option-shutdown2.exp + +echo "TESTING: shutdown3 (option_shutdown3.exp)" +./option-shutdown3.exp + +echo "TESTING: shutdown4 (option_shutdown4.exp)" +./option-shutdown4.exp + echo "TESTING: join (option-join.exp)" ./option-join.exp -- cgit v1.2.3-54-g00ecf