Tests: notification: regroup event generators utils in a single file
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 5 May 2020 20:56:05 +0000 (16:56 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 4 Mar 2021 16:59:25 +0000 (11:59 -0500)
Regroup all "event generator" utils under a single util file to be
sourced.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I4f2598097fba4cd34161a42a7daa5b49ba457293
Depends-on: lttng-ust: I5a800fc92e588c2a6a0e26282b0ad5f31c044479

tests/regression/tools/notification/Makefile.am
tests/regression/tools/notification/test_notification_kernel_buffer_usage
tests/regression/tools/notification/test_notification_multi_app
tests/regression/tools/notification/test_notification_ust_buffer_usage
tests/regression/tools/notification/util_event_generator.sh [new file with mode: 0644]

index 89315aa765f5d39a31c2de30cf31840c63a8fcb8..558de83595cab24c91f0fe8c62d6da8922b2515f 100644 (file)
@@ -10,7 +10,7 @@ noinst_PROGRAMS = base_client notification rotation
 if NO_SHARED
 
 CLEANFILES = libpause_consumer.so libpause_consumer.so.debug
-EXTRA_DIST = test_notification_ust_error test_notification_ust_buffer_usage test_notification_kernel_error test_notification_kernel_buffer_usage test_notification_multi_app base_client.c notification.c consumer_testpoints.c
+EXTRA_DIST = test_notification_ust_error test_notification_ust_buffer_usage test_notification_kernel_error test_notification_kernel_buffer_usage test_notification_multi_app base_client.c notification.c consumer_testpoints.c util_event_generator.sh
 
 else
 
@@ -37,8 +37,8 @@ notification_LDADD = $(LIB_LTTNG_CTL) $(LIBTAP) -lm
 rotation_SOURCES = rotation.c
 rotation_LDADD = $(LIB_LTTNG_CTL) $(LIBTAP) -lm
 
-noinst_SCRIPTS = test_notification_ust_error test_notification_ust_buffer_usage test_notification_kernel_error test_notification_kernel_buffer_usage test_notification_multi_app test_rotation
-EXTRA_DIST = test_notification_ust_error test_notification_ust_buffer_usage test_notification_kernel_error test_notification_kernel_buffer_usage test_notification_multi_app test_rotation
+noinst_SCRIPTS = test_notification_ust_error test_notification_ust_buffer_usage test_notification_kernel_error test_notification_kernel_buffer_usage test_notification_multi_app test_rotation util_event_generator.sh
+EXTRA_DIST = test_notification_ust_error test_notification_ust_buffer_usage test_notification_kernel_error test_notification_kernel_buffer_usage test_notification_multi_app test_rotation util_event_generator.sh
 
 
 all-local:
index 904212f396c0d7ef318a57c241ab468c084b886f..75d22b1a00ab68d3c04406f378062d38bd7c6b70 100755 (executable)
@@ -23,36 +23,8 @@ NUM_TESTS=104
 
 # shellcheck source=../../../utils/utils.sh
 source "$TESTDIR/utils/utils.sh"
-
-function kernel_event_generator_toggle_state
-{
-       kernel_event_generator_suspended=$((kernel_event_generator_suspended==0))
-}
-
-function generate_filter_events
-{
-       /bin/echo -n "10" > /proc/lttng-test-filter-event 2> /dev/null
-}
-
-function kernel_event_generator
-{
-       command_to_run=$1
-       state_file=$2
-       kernel_event_generator_suspended=0
-       trap kernel_event_generator_toggle_state SIGUSR1
-
-       while (true); do
-               if [[ $kernel_event_generator_suspended -eq "1" ]]; then
-                       touch $state_file
-                       sleep 0.5
-               else
-                       if [[ -f $state_file ]]; then
-                               rm $state_file 2> /dev/null
-                       fi
-                       $command_to_run
-               fi
-       done
-}
+# shellcheck source=./util_event_generator.sh
+source "$CURDIR/util_event_generator.sh"
 
 function test_buffer_usage_notification
 {
@@ -84,7 +56,7 @@ function test_buffer_usage_notification
 
        destroy_lttng_session_notap $SESSION_NAME
 
-       kill -9 $APP_PID
+       kill -SIGUSR2 $APP_PID
        wait $APP_PID 2> /dev/null
 }
 
index 9468d0a0db19c8aeb66486cc2a3352a850eb3c8a..afac94d1042ad16e4ec68c7a31ff6ec2a2b52d18 100755 (executable)
@@ -32,6 +32,7 @@ NUM_TEST_KERNEL=50
 NUM_TESTS=$(($NUM_TEST_UST + $NUM_TEST_KERNEL))
 
 source $TESTDIR/utils/utils.sh
+source $CURDIR/util_event_generator.sh
 
 consumerd_pipe=()
 file_sync_after_first_event=$(mktemp -u)
@@ -43,54 +44,6 @@ print_test_banner "$TEST_DESC"
 
 app_pids=()
 
-function kernel_event_generator_toggle_state
-{
-       kernel_event_generator_suspended=$((kernel_event_generator_suspended==0))
-
-}
-function kernel_event_generator
-{
-       state_file=$1
-       kernel_event_generator_suspended=0
-       trap kernel_event_generator_toggle_state SIGUSR1
-
-       while (true); do
-               if [[ $kernel_event_generator_suspended -eq "1" ]]; then
-                       touch $state_file
-                       sleep 0.5
-               else
-                       if [[ -f $state_file ]]; then
-                               rm $state_file 2> /dev/null
-                       fi
-                       echo -n "1000" > /proc/lttng-test-filter-event
-               fi
-       done
-}
-
-function ust_event_generator_toggle_state
-{
-       ust_event_generator_suspended=$((ust_event_generator_suspended==0))
-
-}
-function ust_event_generator
-{
-       state_file=$1
-       ust_event_generator_suspended=0
-       trap ust_event_generator_toggle_state SIGUSR1
-       trap "exit" SIGTERM SIGINT
-       while (true); do
-               if [[ $ust_event_generator_suspended -eq "1" ]]; then
-                       touch $state_file
-                       sleep 0.5
-               else
-                       if [[ -f $state_file ]]; then
-                               rm $state_file 2> /dev/null
-                       fi
-                       taskset  -c 0 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT > /dev/null 2>&1
-               fi
-       done
-}
-
 function start_client {
        local pid=-1
        local output_file=$1
@@ -300,12 +253,12 @@ function test_multi_app ()
 function test_multi_app_ust ()
 {
        diag "Multi client app UST notification"
-       ust_event_generator $TESTAPP_STATE_FILE &
+       ust_event_generator "$TESTAPP_BIN" "$TESTAPP_STATE_FILE" &
        local generator_pid=$!
 
        test_multi_app ust $generator_pid
 
-       kill -s SIGTERM $generator_pid 2> /dev/null
+       kill -s SIGUSR2 $generator_pid 2> /dev/null
        wait $generator_pid 2> /dev/null
        rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null
 }
@@ -315,13 +268,13 @@ function test_multi_app_kernel ()
        diag "Multi client app kernel notification"
        modprobe lttng-test
 
-       kernel_event_generator $TESTAPP_STATE_FILE &
+       kernel_event_generator generate_filter_events $TESTAPP_STATE_FILE &
        local generator_pid=$!
 
        test_multi_app kernel $generator_pid
 
 
-       kill -s SIGTERM $generator_pid 2> /dev/null
+       kill -s SIGUSR2 $generator_pid 2> /dev/null
        wait $generator_pid 2> /dev/null
        rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null
 
@@ -333,12 +286,12 @@ function test_on_register_evaluation_ust ()
        diag "On register notification UST"
 
        # Start app in infinite loop
-       ust_event_generator $TESTAPP_STATE_FILE &
+       ust_event_generator "$TESTAPP_BIN" "$TESTAPP_STATE_FILE" &
        local generator_pid=$!
 
        test_on_register_evaluation ust $generator_pid
 
-       kill -s SIGTERM $generator_pid 2> /dev/null
+       kill -s SIGUSR2 $generator_pid 2> /dev/null
        wait $generator_pid 2> /dev/null
        rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null
 
@@ -350,13 +303,13 @@ function test_on_register_evaluation_kernel()
 
        modprobe lttng-test
 
-       kernel_event_generator $TESTAPP_STATE_FILE &
+       kernel_event_generator generate_filter_events $TESTAPP_STATE_FILE &
        local generator_pid=$!
 
        test_on_register_evaluation kernel $generator_pid
 
 
-       kill -s SIGTERM $generator_pid 2> /dev/null
+       kill -s SIGUSR2 $generator_pid 2> /dev/null
        wait $generator_pid 2> /dev/null
        rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null
 
@@ -447,7 +400,7 @@ function test_on_register_evaluation ()
        destroy_lttng_session_ok $SESSION_NAME
        stop_lttng_sessiond
 
-       kill -s SIGTERM $generator_pid 2> /dev/null
+       kill -s SIGUSR2 $generator_pid 2> /dev/null
        wait $generator_pid 2> /dev/null
 
        for pipe in "${consumerd_pipe[@]}"; do
index 7e530d8e404f6c58f984c11ee4c33f1d8e73d414..d7df67e90317f832c5b9b8afe018f4929369867f 100755 (executable)
@@ -29,31 +29,8 @@ PAGE_SIZE=$(getconf PAGE_SIZE)
 
 # shellcheck source=../../../utils/utils.sh
 source "$TESTDIR/utils/utils.sh"
-
-function ust_event_generator_toggle_state
-{
-       ust_event_generator_suspended=$((ust_event_generator_suspended==0))
-
-}
-function ust_event_generator
-{
-       test_app=$1
-       state_file=$2
-       ust_event_generator_suspended=0
-       trap ust_event_generator_toggle_state SIGUSR1
-
-       while (true); do
-               if [[ $ust_event_generator_suspended -eq "1" ]]; then
-                       touch $state_file
-                       sleep 0.5
-               else
-                       if [[ -f $state_file ]]; then
-                               rm -rf $state_file 2> /dev/null
-                       fi
-                       taskset  -c 0 $test_app -i $NR_ITER -w $NR_USEC_WAIT > /dev/null 2>&1
-               fi
-       done
-}
+# shellcheck source=./util_event_generator.sh
+source "$CURDIR/util_event_generator.sh"
 
 function test_buffer_usage_notification
 {
@@ -70,7 +47,7 @@ function test_buffer_usage_notification
                consumerd_pipe+=("$f")
        done
 
-       ust_event_generator $GEN_UST_EVENTS_TESTAPP_BIN $TESTAPP_STATE_PATH &
+       ust_event_generator "$GEN_UST_EVENTS_TESTAPP_BIN" "$TESTAPP_STATE_PATH" &
        APP_PID=$!
 
        "$CURDIR/notification" 2 LTTNG_DOMAIN_UST $SESSION_NAME $CHANNEL_NAME $APP_PID "$TESTAPP_STATE_PATH" "${consumerd_pipe[@]}"
@@ -79,7 +56,7 @@ function test_buffer_usage_notification
 
        # On ungraceful kill the app is cleaned up via the full_cleanup call
        # Suppress kill message
-       kill -9 $APP_PID
+       kill -SIGUSR2 $APP_PID
        wait $APP_PID 2> /dev/null
 
        # Just in case cleanup
diff --git a/tests/regression/tools/notification/util_event_generator.sh b/tests/regression/tools/notification/util_event_generator.sh
new file mode 100644 (file)
index 0000000..5eef0de
--- /dev/null
@@ -0,0 +1,194 @@
+#!/bin/bash
+#
+# Copyright (C) 2020 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
+#
+# SPDX-License-Identifier: LGPL-2.1-only
+
+GENERATOR_CURDIR=$(dirname "$0")/
+GENERATOR_TESTDIR=$GENERATOR_CURDIR/../../../
+TESTAPP_PATH=${TESTAPP_PATH:-"$GENERATOR_TESTDIR/utils/testapp"}
+
+SYSCALL_TESTAPP_NAME=${SYSCALL_TESTAPP_NAME:-"gen-syscall-events"}
+SYSCALL_TESTAPP_BIN=${SYSCALL_TESTAPP_BIN:-"$TESTAPP_PATH/$SYSCALL_TESTAPP_NAME/$SYSCALL_TESTAPP_NAME"}
+
+USERSPACE_PROBE_ELF_TESTAPP_NAME=${USERSPACE_PROBE_ELF_TESTAPP_NAME:-"userspace-probe-elf-binary"}
+USERSPACE_PROBE_ELF_TESTAPP_BIN=${USERSPACE_PROBE_ELF_TESTAPP_BIN:-"$TESTAPP_PATH/$USERSPACE_PROBE_ELF_TESTAPP_NAME/.libs/$USERSPACE_PROBE_ELF_TESTAPP_NAME"}
+
+function generate_filter_events
+{
+       local nr=$1
+       /bin/echo -n "$nr" > /proc/lttng-test-filter-event 2> /dev/null
+}
+
+function generate_syscalls
+{
+       local nr=$1
+       shift
+
+       for i in $(seq 1 "$nr"); do
+               # Pass /dev/null so to generate the syscall right away.
+               $SYSCALL_TESTAPP_BIN /dev/null "$@"
+       done
+}
+
+function userspace_probe_testapp
+{
+       local nr=$1
+       shift 
+
+       for i in $(seq 1 "$nr"); do
+               $USERSPACE_PROBE_ELF_TESTAPP_BIN "$@"
+       done
+}
+
+function ust_event_generator_toggle_state
+{
+       ust_event_generator_suspended=$((ust_event_generator_suspended==0))
+}
+
+function generator_quit
+{
+       generator_quit=0
+}
+
+# Note: Only one generator can be used at a time per domain type
+function ust_event_generator_run_once_per_transition
+{
+       # Used by the signal trap
+       ust_event_generator_suspended=0
+       # Used by the signal trap for SIGUSR2 to end the generator
+       generator_quit=1
+
+       local test_app=$1
+       local state_file=$2
+       local nr_iter=$3
+       local nr_usec_wait=$4
+       local run=false
+
+       # Pass any of the remaining arguments to the generator.
+       shift 4
+
+       trap ust_event_generator_toggle_state SIGUSR1
+       trap generator_quit SIGUSR2
+
+       while [ $generator_quit -ne 0  ]; do
+               if [[ $ust_event_generator_suspended -eq "1" ]]; then
+                       touch "$state_file"
+                       # Reset the "run" state
+                       run=true
+                       sleep 0.5
+               elif [ "$run" = true ]; then
+                       taskset -c 0 "$test_app" -i "$nr_iter" -w "$nr_usec_wait" "$@"> /dev/null 2>&1
+                       run=false;
+                       if [[ -f $state_file ]]; then
+                               rm -rf "$state_file" 2> /dev/null
+                       fi
+               else
+                       # Wait for a "suspend" to reset the run state
+                       sleep 0.1
+               fi
+       done
+}
+
+# Note: Only one generator can be used at a time per domain type
+function ust_event_generator
+{
+       # Used by the signal trap
+       ust_event_generator_suspended=0
+       # Used by the signal trap for SIGUSR2 to end the generator
+       generator_quit=1
+
+       local test_app=$1
+       local state_file=$2
+       local nr_iter=1000
+       local nr_usec_wait=5
+
+       # Pass any of the remaining arguments to the generator.
+       shift 2
+
+       trap ust_event_generator_toggle_state SIGUSR1
+       trap generator_quit SIGUSR2
+
+       while [ $generator_quit -ne 0 ]; do
+               if [[ $ust_event_generator_suspended -eq "1" ]]; then
+                       touch "$state_file"
+                       # Reset the "run" state
+                       sleep 0.5
+               else
+                       taskset -c 0 "$test_app" -i $nr_iter -w $nr_usec_wait "$@" > /dev/null 2>&1
+                       if [[ -f $state_file ]]; then
+                               rm -rf "$state_file" 2> /dev/null
+                       fi
+               fi
+       done
+}
+
+function kernel_event_generator_toggle_state
+{
+       kernel_event_generator_suspended=$((kernel_event_generator_suspended==0))
+}
+
+function kernel_event_generator_run_once_per_transition
+{
+       # Used by the signal trap
+       kernel_event_generator_suspended=0
+       # Used by the signal trap for SIGUSR2 to end the generator
+       generator_quit=1
+
+       local generator=$1
+       local state_file=$2
+       local nr_iter=$3
+
+       # Pass any of the remaining arguments to the generator.
+       shift 3
+
+       local run=false
+       trap kernel_event_generator_toggle_state SIGUSR1
+       trap generator_quit SIGUSR2
+
+       while [ $generator_quit -ne 0 ]; do
+               if [[ $kernel_event_generator_suspended -eq "1" ]]; then
+                       touch "$state_file"
+                       run=true
+                       sleep 0.5
+               elif [ "$run" = true ]; then
+                       $generator "$nr_iter" "$@"
+                       run=false
+                       if [[ -f $state_file ]]; then
+                               rm "$state_file" 2> /dev/null
+                       fi
+               else
+                       # Wait for a "suspend" to reset the run state
+                       sleep 0.1
+               fi
+       done
+}
+
+function kernel_event_generator
+{
+       # Used by the signal trap
+       kernel_event_generator_suspended=0
+       # Used by the signal trap for SIGUSR2 to end the generator
+       generator_quit=1
+
+       local generator=$1
+       local state_file=$2
+
+       # Pass any of the remaining arguments to the generator.
+       shift 2
+
+       trap kernel_event_generator_toggle_state SIGUSR1
+       trap generator_quit SIGUSR2
+
+       while [ $generator_quit -ne 0 ]; do
+               if [[ $kernel_event_generator_suspended -eq "1" ]]; then
+                       touch "$state_file"
+                       sleep 0.5
+               else
+                       $generator "10" "$@"
+                       if [[ -f $state_file ]]; then
+                               rm "$state_file" 2> /dev/null
+                       fi
+               fi
+       done
+}
This page took 0.031621 seconds and 4 git commands to generate.