Gen-ust-events: use options instead of arguments
[lttng-tools.git] / tests / regression / ust / getcpu-override / test_getcpu_override
index 2492c9c1133eb7b3bd170afd15b9e36d584676cc..75a3d6d4daf0335418a6d0e64373ec9abbc30a99 100755 (executable)
@@ -25,6 +25,7 @@ TESTAPP_NAME="gen-ust-events"
 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
 TESTAPP_WRAPPER="run-getcpu-override"
 NUM_EVENT=256
+EVENT_WAIT_USEC=1
 EVENT_NAME="tp:tptest"
 
 NUM_TESTS=20
@@ -44,28 +45,24 @@ SEQUENCE_SEED=(
 89 13 63 6 136 153 23 16 47 130 75 62
 )
 
-# Equivalent to the syconf(_SC_NPROCESSORS_CONF) call.
-NPROC=`nproc --all`
-
 source $TESTDIR/utils/utils.sh
 
-if [ ! -x "$CURDIR/.libs/lttng-ust-getcpu-override-test.so" ]; then
-       BAIL_OUT "No shared object generated"
-fi
+# Equivalent to the syconf(_SC_NPROCESSORS_CONF) call.
+num_cpus=$(conf_proc_count)
 
 # MUST set TESTDIR before calling those functions
 
 run_app()
 {
        diag "Launching app without getcpu-plugin wrapper"
-       $TESTAPP_BIN $NUM_EVENT
+       $TESTAPP_BIN -i $NUM_EVENT -w $EVENT_WAIT_USEC
        ok $? "Application without wrapper done"
 }
 
 run_getcpu_plugin_app()
 {
        diag "Launching app with getcpu-plugin wrapper"
-       $CURDIR/$TESTAPP_WRAPPER $TESTAPP_BIN $NUM_EVENT
+       $CURDIR/$TESTAPP_WRAPPER $TESTAPP_BIN -i $NUM_EVENT -w $EVENT_WAIT_USEC
        ok $? "Application with wrapper done"
 }
 
@@ -86,10 +83,10 @@ compare()
        local valid=0
 
        test ${#array_to_compare[*]} -eq ${#SEQUENCE_SEED[*]}
-       ok $? "Sequence seed and cpuid sequence are equal ${#SEQUENCE_SEED[*]}/${#array_to_compare[*]}"
+       ok $? "Sequence seed and cpuid sequence have the same size ${#SEQUENCE_SEED[*]}/${#array_to_compare[*]}"
 
        for (( i = 0; i < ${#SEQUENCE_SEED[*]}; i++ )); do
-               if [ "${array_to_compare[$i]}" -ne "$(( ${SEQUENCE_SEED[$i]} % $NPROC))" ]; then
+               if [ "${array_to_compare[$i]}" -ne "$(( ${SEQUENCE_SEED[$i]} % $num_cpus))" ]; then
                        valid=1
                        break
                fi
@@ -97,15 +94,26 @@ compare()
 
        if [[ $expected_to_fail -eq "1" ]]; then
                test $valid -ne "0"
-               ok $? "Cpuid extraction and seed sequence comparison fail as expected"
+               ok $? "Cpuid extraction and seed sequence comparison fails as expected"
        else
                ok $valid "Cpuid extraction and seed sequence comparison"
+               if [[ $valid -ne "0" ]]; then
+                       diag "Dumping arrays after failed comparison"
+                       for (( i = 0; i < ${#SEQUENCE_SEED[*]}; i++ )); do
+                               echo -n "# array value is "
+                               echo -n "${array_to_compare[$i]}"
+                               echo -n " expected "
+                               echo "$(( ${SEQUENCE_SEED[$i]} % $num_cpus))"
+                       done
+                       diag "Dumping trace"
+                       $BABELTRACE_BIN $TRACE_PATH | awk '{print "# " $0}'
+               fi
        fi
 }
 
-test_getcpu_override()
+test_getcpu_override_fail()
 {
-       diag "Getcpu plugin"
+       diag "Getcpu plugin - no preloaded plugin"
 
        create_lttng_session_ok $SESSION_NAME $TRACE_PATH
        enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
@@ -115,12 +123,19 @@ test_getcpu_override()
        destroy_lttng_session_ok $SESSION_NAME
 
        # Move output to an array by using =($())
-       cpuid_events=($($BABELTRACE_BIN $TRACE_PATH | sed -n 's/.*cpu_id = \([0-9]*\).*/\1/p'))
-       num_events=${#cpuid_events[*]}
+       local cpuid_events=($($BABELTRACE_BIN $TRACE_PATH | sed -n 's/.*cpu_id = \([0-9]*\).*/\1/p'))
+       local num_events=${#cpuid_events[*]}
        test $num_events -eq $NUM_EVENT
        ok $? "Extraction without getcpu plugin have $num_events/$NUM_EVENT"
        compare_fail cpuid_events[@]
 
+       return $?
+}
+
+test_getcpu_override()
+{
+       diag "Getcpu plugin - with plugin preloaded"
+
        create_lttng_session_ok $SESSION_NAME $TRACE_PATH
        enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
        start_lttng_tracing_ok $SESSION_NAME
@@ -128,10 +143,10 @@ test_getcpu_override()
        stop_lttng_tracing_ok $SESSION_NAME
        destroy_lttng_session_ok $SESSION_NAME
 
-       cpuid_events=($($BABELTRACE_BIN $TRACE_PATH | sed -n 's/.*cpu_id = \([0-9]*\).*/\1/p'))
-       num_events=${#cpuid_events[*]}
+       local cpuid_events=($($BABELTRACE_BIN $TRACE_PATH | sed -n 's/.*cpu_id = \([0-9]*\).*/\1/p'))
+       local num_events=${#cpuid_events[*]}
        test $num_events -eq $NUM_EVENT
-       ok $? "Extraction without getcpu plugin have $num_events/$NUM_EVENT"
+       ok $? "Extraction with getcpu plugin have $num_events/$NUM_EVENT"
 
        compare_ok cpuid_events[@]
 
@@ -142,8 +157,17 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
+if [ -x "$CURDIR/.libs/lttng-ust-getcpu-override-test.so" ]; then
+       foundobj=1
+else
+       foundobj=0
+fi
+
+skip $foundobj "No shared object generated. Skipping all tests." $NUM_TESTS && exit 0
+
 TESTS=(
-       "test_getcpu_override"
+       test_getcpu_override_fail
+       test_getcpu_override
 )
 
 TEST_COUNT=${#TESTS[@]}
@@ -151,16 +175,16 @@ i=0
 
 start_lttng_sessiond
 
-while [ "$i" -lt "$TEST_COUNT" ]; do
-
+for fct_test in ${TESTS[@]};
+do
        TRACE_PATH=$(mktemp -d)
 
-       # Execute test
-       ${TESTS[$i]}
+       ${fct_test}
+       if [ $? -ne 0 ]; then
+               break;
+       fi
 
        rm -rf $TRACE_PATH
-
-       let "i++"
 done
 
 stop_lttng_sessiond
This page took 0.038252 seconds and 5 git commands to generate.