TEST_DESC="UST - Clock override plugin"
-CURDIR=$(dirname $0)/
+CURDIR=$(dirname "$0")/
TESTDIR=$CURDIR/../../..
SESSION_NAME="clock_override"
LTTNG_UST_CLOCK_PLUGIN_SO="lttng-ust-clock-override-test.so"
LIBS_DIR=".libs"
-METADATA_CLOCK_START_TOKEN="clock {"
-METADATA_CLOCK_END_TOKEN="};"
-
-METADATA_TOKEN_LIST=(
- "name"
- "uuid"
- "description"
- "freq"
-)
-
-UST_CLOCK_TOKEN_VALUE=(
- "lttng_test_clock_override"
- "83c63deb-7aa4-48fb-abda-946f400d76e6"
- "Freeze time with 1KHz for regression test"
- "1000"
-)
-
-NUM_TESTS=33
-
source $TESTDIR/utils/utils.sh
+if [ "$TRACE_FORMAT_OUTPUT" == "ctf1" ]; then
+ NUM_TESTS=33
+elif [ "$TRACE_FORMAT_OUTPUT" == "ctf2" ]; then
+ NUM_TESTS=31
+fi
+
# MUST set TESTDIR before calling those functions
function run_app()
{
ok $? "Application done"
}
-function extract_clock_metadata()
+function extract_clock_metadata_ctf1()
{
+ local metadata_clock_start_token="clock {"
+ local metadata_clock_end_token="};"
+
local metadata_file=$1
local clock_metadata_file_destination=$2
- cat $metadata_file \
- | sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \
- > $clock_metadata_file_destination
+
+ sed -n "/$metadata_clock_start_token/,/$metadata_clock_end_token/p" "$metadata_file" > "$clock_metadata_file_destination"
ok $? "Clock metadata extraction"
}
-function extract_clock_metadata_token()
+function extract_clock_metadata_token_ctf1()
{
local clock_metadata_file=$1
local token=$2
# Look for token and get value between ""
- cat $clock_metadata_file | grep $token | awk -F"= |;" '{print $2}' | tr -d '"'
+ grep "$token" "$clock_metadata_file" | awk -F"= |;" '{print $2}' | tr -d '"'
+}
+
+function validate_tokens_ctf1
+{
+
+ local metadata_token_list=(
+ "name"
+ "uuid"
+ "description"
+ "freq"
+ )
+
+ local ust_clock_token_value=(
+ "lttng_test_clock_override"
+ "83c63deb-7aa4-48fb-abda-946f400d76e6"
+ "Freeze time with 1KHz for regression test"
+ "1000"
+ )
+
+ test ${#metadata_token_list[@]} -eq ${#ust_clock_token_value[@]}
+ ok $? "Tokens to check(${#metadata_token_list[@]}) and provided values(${#ust_clock_token_value[@]}) count is equal"
+
+ local metadata_directory_path=$1
+ local ctf_metadata_file
+ local clock_metadata_file
+
+ clock_metadata_file=$(mktemp --tmpdir -p "$TRACE_PATH" clock-metadata.XXXXXX)
+ ctf_metadata_file=$(mktemp --tmpdir -p "$TRACE_PATH" ctf-metadata.XXXXXX)
+
+ $BABELTRACE_BIN -o ctf-metadata -w "$ctf_metadata_file" "$metadata_directory_path"
+ ok $? "Metadata extraction from babeltrace"
+
+ extract_clock_metadata_ctf1 "$ctf_metadata_file" "$clock_metadata_file"
+
+ local counter=0
+ while [ "$counter" -lt "${#metadata_token_list[@]}" ]; do
+ result=$(extract_clock_metadata_token_ctf1 "$clock_metadata_file" \
+ "${metadata_token_list[$counter]}")
+ test "$result" == "${ust_clock_token_value[$counter]}"
+ ok $? "Token \"${metadata_token_list[$counter]}\" expect:${ust_clock_token_value[$counter]} got:$result"
+ (( counter++ ))
+ done
+
+ rm -rf "$ctf_metadata_file"
+ rm -rf "$clock_metadata_file"
+}
+
+function validate_tokens_ctf2
+{
+ local metadata_token_list=(
+ "name"
+ "uuid"
+ "description"
+ "frequency"
+ )
+
+ local ust_clock_token_value=(
+ "lttng_test_clock_override"
+ "[131,198,61,235,122,164,72,251,171,218,148,111,64,13,118,230]"
+ "Freeze time with 1KHz for regression test"
+ "1000"
+ )
+
+ test ${#metadata_token_list[@]} -eq ${#ust_clock_token_value[@]}
+ ok $? "Tokens to check(${#metadata_token_list[@]}) and provided values(${#ust_clock_token_value[@]}) count is equal"
+
+ local metadata_path=$1
+
+ local counter=0
+ while [ "$counter" -lt "${#metadata_token_list[@]}" ]; do
+ result=$(jq -c -r "select(.type == \"clock-class\").${metadata_token_list[$counter]}" "$metadata_path")
+ test "$result" == "${ust_clock_token_value[$counter]}"
+ ok $? "Token \"${metadata_token_list[$counter]}\" expect:${ust_clock_token_value[$counter]} got:$result"
+ (( counter++ ))
+ done
+
}
function test_getcpu_override_metadata()
{
- local ctf_metadata_file=$(mktemp --tmpdir -p $TRACE_PATH ctf-metadata.XXXXXX)
- local clock_metadata_file=$(mktemp --tmpdir -p $TRACE_PATH clock-metadata.XXXXXX)
local result=""
+ local metadata_file
+ local metadata_directory_path
diag "Clock override plugin metadata test"
start_lttng_sessiond
unset LTTNG_UST_CLOCK_PLUGIN
- create_lttng_session_ok $SESSION_NAME $TRACE_PATH
+ create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
start_lttng_tracing_ok $SESSION_NAME
run_app
destroy_lttng_session_ok $SESSION_NAME
stop_lttng_sessiond
- local TRACE_METADATA_FILE_PATH="$(find "$TRACE_PATH" -name metadata -type f)"
- local TRACE_METADATA_DIR="$(dirname "$TRACE_METADATA_FILE_PATH")"
-
- $BABELTRACE_BIN -o ctf-metadata -w $ctf_metadata_file $TRACE_METADATA_DIR
- ok $? "Metadata extraction from babeltrace"
-
- extract_clock_metadata $ctf_metadata_file $clock_metadata_file
-
- test ${#METADATA_TOKEN_LIST[@]} -eq ${#UST_CLOCK_TOKEN_VALUE[@]}
- ok $? "Tokens to check(${#METADATA_TOKEN_LIST[@]}) and provided values(${#UST_CLOCK_TOKEN_VALUE[@]}) count is equal"
+ metadata_file="$(find "$TRACE_PATH" -name metadata -type f)"
+ metadata_directory_path="$(dirname "$metadata_file")"
- local counter=0
- while [ "$counter" -lt "${#METADATA_TOKEN_LIST[@]}" ]; do
- result=$(extract_clock_metadata_token $clock_metadata_file \
- ${METADATA_TOKEN_LIST[$counter]})
- test "$result" == "${UST_CLOCK_TOKEN_VALUE[$counter]}"
- ok $? "Token \"${METADATA_TOKEN_LIST[$counter]}\" expect:${UST_CLOCK_TOKEN_VALUE[$counter]} got:$result"
- let "counter++"
- done
- rm -rf $ctf_metadata_file
- rm -rf $clock_metadata_file
+ if [ "$TRACE_FORMAT_OUTPUT" == "ctf1" ]; then
+ validate_tokens_ctf1 "$metadata_directory_path"
+ elif [ "$TRACE_FORMAT_OUTPUT" == "ctf2" ]; then
+ validate_tokens_ctf2 "$metadata_file"
+ fi
}
function test_getcpu_override_timestamp()