summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjolsa@redhat.com <jolsa@redhat.com>2011-05-25 00:20:13 +0200
committerJiri Olsa <Jiri Olsa jolsa@redhat.com>2011-05-29 19:05:24 +0200
commitec2866f5e5236a260b4d823a3435c2704f28bed5 (patch)
tree0416dcb0586076429b0c4e2dec77000939099cef
parent9dff12d15a587ea8604172d057f6a0c3f6666591 (diff)
downloadlatrace-ec2866f5e5236a260b4d823a3435c2704f28bed5.tar.gz
latrace-ec2866f5e5236a260b4d823a3435c2704f28bed5.tar.xz
latrace-ec2866f5e5236a260b4d823a3435c2704f28bed5.zip
adding tests for latrace termination
-rw-r--r--ChangeLog1
-rw-r--r--test/Makefile16
-rw-r--r--test/script/functions.sh20
-rw-r--r--test/script/test_kill.sh133
-rw-r--r--test/script/test_tty_output.sh9
-rw-r--r--test/test-kill.c45
-rwxr-xr-xtest/test.sh6
7 files changed, 216 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 7c9d52b..0bac9b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
2011-05-25 Jiri Olsa <olsajiri@gmail.com>
* adding SIGTERM/SIGINT handlers,
refactoring lt_run to check the latrace got killed
+ * adding tests for latrace termination
2011-05-24 Jiri Olsa <olsajiri@gmail.com>
* args - use isprint to decide whether to print the character,
diff --git a/test/Makefile b/test/Makefile
index 2849b40..30de2a1 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -13,16 +13,20 @@ test-common: test/test-lib.o test/test-common.o
test-args: test/test-lib.o test/test-args.o test/sysdeps/$(CONFIG_SYSDEP_DIR)/test-args.o
$(QUIET_LD)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ lib-test-args.so
+test-kill: test/test-kill.o
+ $(QUIET_LD)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+
OBJS+=test/test-lib.o
-OBJS+=\
- test/lib-test-args.o \
+PROGRAMS+=lib-test-args.so test-args
+OBJS+=test/lib-test-args.o \
test/test-args.o \
test/sysdeps/$(CONFIG_SYSDEP_DIR)/test-args.o
-OBJS+=\
- test/lib-test-common.o \
- test/test-common.o
PROGRAMS+=lib-test-common.so test-common
-PROGRAMS+=lib-test-args.so test-args
+OBJS+=test/lib-test-common.o \
+ test/test-common.o
+
+PROGRAMS+=test-kill
+OBJS+= test/test-kill.o
diff --git a/test/script/functions.sh b/test/script/functions.sh
new file mode 100644
index 0000000..361b364
--- /dev/null
+++ b/test/script/functions.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+function CHECK_RET
+{
+ if [ $? -ne 0 ]; then
+ echo "FAILED"
+ else
+ echo -n "."
+ fi
+}
+
+function TEST
+{
+ func=$1
+
+ source $PWD/test/script/$1.sh
+ echo -n "$1"
+ eval $1
+ echo OK
+}
diff --git a/test/script/test_kill.sh b/test/script/test_kill.sh
new file mode 100644
index 0000000..90a62f7
--- /dev/null
+++ b/test/script/test_kill.sh
@@ -0,0 +1,133 @@
+#!/bin/sh
+
+. $PWD/test/script/functions.sh
+
+function tk_init
+{
+ arg=$1
+
+ if [ x$arg == xnopipe ]; then
+ cat > /tmp/tk_latrace.conf <<EOF
+OPTIONS {
+ PIPE=NO
+}
+EOF
+ else
+ echo > /tmp/tk_latrace.conf
+ fi
+}
+
+function tk_cleanup
+{
+ rm -f /tmp/tk_latrace.conf
+ rm -f test-kill.expect
+ rm -f test-kill.out
+}
+
+
+function tk_wait_start
+{
+ name=$1
+
+ while [ -z `pgrep $name` ];
+ do
+ usleep 100
+ done
+}
+
+function tk_wait_stop
+{
+ pid=$1
+
+ while [ `kill -0 $pid 2> /dev/null; echo $?` == "0" ];
+ do
+ usleep 100
+ done
+}
+
+function test_kill_handlers
+{
+ tk_init $1
+ ./latrace -N /tmp/tk_latrace.conf -q $PWD/test-kill 1 > test-kill.out &
+
+ tk_wait_start test-kill
+
+ pid_latrace=$!
+ pid_test=`pgrep test-kill`
+
+ kill -2 $pid_latrace
+
+ tk_wait_stop $pid_latrace
+ tk_wait_stop $pid_test
+
+ echo -e "\nlatrace interrupted, killing child (pid $pid_test)" > test-kill.expect
+ echo -e "\n$PWD/test-kill finished - exited, status=0" >> test-kill.expect
+
+ diff test-kill.out test-kill.expect
+ CHECK_RET
+}
+
+function test_kill_nohandlers
+{
+ tk_init $1
+ ./latrace -N /tmp/tk_latrace.conf -q $PWD/test-kill 2 > test-kill.out &
+
+ tk_wait_start test-kill
+
+ pid_latrace=$!
+ pid_test=`pgrep test-kill`
+
+ kill -2 $pid_latrace
+
+ tk_wait_stop $pid_latrace
+ tk_wait_stop $pid_test
+
+ echo -e "\nlatrace interrupted, killing child (pid $pid_test)" > test-kill.expect
+ echo -e "\n$PWD/test-kill finished - killed by signal 15" >> test-kill.expect
+
+ diff test-kill.out test-kill.expect
+ if [ $? -ne 0 ]; then
+ echo "FAILED test_kill"
+ read
+ exit
+ fi
+
+ echo -n .
+}
+
+
+function test_kill_blocked
+{
+ tk_init $1
+ ./latrace -N /tmp/tk_latrace.conf -q $PWD/test-kill 3 > test-kill.out &
+
+ tk_wait_start test-kill
+
+ pid_latrace=$!
+ pid_test=`pgrep test-kill`
+
+ kill -2 $pid_latrace
+
+ tk_wait_stop $pid_latrace
+ tk_wait_stop $pid_test
+
+ echo -e "\nlatrace interrupted, killing child (pid $pid_test)" > test-kill.expect
+ echo -e "\n$PWD/test-kill finished - killed by signal 9" >> test-kill.expect
+
+ diff test-kill.out test-kill.expect
+ CHECK_RET
+}
+
+function test_kill
+{
+ test_kill_handlers
+ test_kill_handlers nopipe
+
+ test_kill_nohandlers
+ test_kill_nohandlers nopipe
+
+ test_kill_blocked
+ test_kill_blocked nopipe
+
+ tk_cleanup
+}
diff --git a/test/script/test_tty_output.sh b/test/script/test_tty_output.sh
index d1014d6..70d7b07 100644
--- a/test/script/test_tty_output.sh
+++ b/test/script/test_tty_output.sh
@@ -1,5 +1,7 @@
#!/bin/sh
+. $PWD/test/script/functions.sh
+
function tto_init
{
cat > /tmp/tto_latrace.conf <<EOF
@@ -23,12 +25,7 @@ function test_tty_output
$PWD/test/script/test_tty_output.sh > /dev/null
diff /tmp/tto_latrace.output $PWD/test/script/test_tty_output.sh
- if [ $? -ne 0 ]; then
- echo "FAILED test_tty_output"
- exit
- fi
+ CHECK_RET
tto_cleanup
-
- echo .
}
diff --git a/test/test-kill.c b/test/test-kill.c
new file mode 100644
index 0000000..5803e39
--- /dev/null
+++ b/test/test-kill.c
@@ -0,0 +1,45 @@
+
+#include <signal.h>
+#include <unistd.h>
+
+static int exit_flag = 0;
+
+static void sig_term_handler(int sig)
+{
+ exit_flag = 1;
+}
+
+int main(int argc, char **argv)
+{
+ int ignore = 0;
+ int handlers = 1;;
+
+ if (argc != 2)
+ return -1;
+
+ /*
+ * 1 - handlers
+ * 2 - no handlers
+ * 3 - ignore term/int
+ */
+
+ switch(*argv[1]) {
+ case '1': handlers = 1; break;
+ case '2': handlers = 0; break;
+ case '3': ignore = 1; break;
+ default:
+ return -1;
+ }
+
+ if (handlers) {
+ if ((signal(SIGTERM, sig_term_handler) == SIG_ERR) ||
+ (signal(SIGINT, sig_term_handler) == SIG_ERR))
+ return -1;
+ }
+
+ while(!exit_flag || ignore) {
+ usleep(100);
+ }
+
+ return 0;
+}
diff --git a/test/test.sh b/test/test.sh
index 769adf4..296c91a 100755
--- a/test/test.sh
+++ b/test/test.sh
@@ -13,5 +13,7 @@ LD_LIBRARY_PATH=$PWD ./latrace -qR -a $PWD/test/lib-test-args.conf ./test-args
# script tests
echo "[SCRIPTS]"
-. $PWD/test/script/test_tty_output.sh
-test_tty_output
+. $PWD/test/script/functions.sh
+
+TEST test_tty_output
+TEST test_kill