fix: tests: grep for '$key =' in metadata
authorMichael Jeanson <mjeanson@efficios.com>
Tue, 23 May 2023 19:22:04 +0000 (15:22 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 13 Jun 2023 22:23:26 +0000 (18:23 -0400)
Always grep for '$key =' to avoid a collision with a value, for example
if you are looking for the 'domain' key and your hostname contains
'domain'.

While we are here, add a bunch of logging to facilitate debugging in the
future.

Change-Id: I09197169ab7f842921c9139fdeb36007d7b20cfb
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/regression/tools/metadata/test_kernel
tests/regression/tools/metadata/test_ust
tests/regression/tools/metadata/utils.sh

index e7b9a95a72da1cb93efe442957faeead82a80289..9e1e81232128d6000fffb55df13502ff068131cf 100755 (executable)
@@ -22,12 +22,14 @@ source "$CURDIR/utils.sh"
 function test_kernel ()
 {
        local metadata_path
-       local value
+       local metadata
+       local metadata_env
 
        local expected_path="${TRACE_PATH}/lttng-traces"
        local session_name="kernel"
-       local metadata=$(mktemp -t "tmp.${FUNCNAME[0]}_metadata.XXXXXX")
-       local metadata_env=$(mktemp -t "tmp.${FUNCNAME[0]}_metadata_env.XXXXXX")
+
+       metadata=$(mktemp -t "tmp.test_kernel_metadata.XXXXXX")
+       metadata_env=$(mktemp -t "tmp.test_kernel_metadata_env.XXXXXX")
 
        diag "Test Kernel metadata env field"
        create_lttng_session_ok "$session_name"
@@ -55,33 +57,37 @@ function test_kernel ()
        # to allow trace viewer to recreate the same directory hierarchy.
 
        # Trace name
-       value=$(get_env_value "$metadata_env" trace_name)
-       ok $? "Extracting trace_name from env metadata"
-       expected_path="${expected_path}/${value}"
+       local trace_name
+       trace_name=$(get_env_value "$metadata_env" trace_name)
+       ok $? "Extracting trace_name from env metadata: \`$trace_name\`"
+       expected_path="${expected_path}/${trace_name}"
 
        # Session creation time
-       value=$(get_env_value "$metadata_env" trace_creation_datetime)
-       ok $? "Extracting trace_creation_datetime from env metadata"
-       value=$(iso8601_to_lttng_dir_datetime "$value")
-       expected_path="${expected_path}-${value}"
+       local trace_creation_datetime
+       trace_creation_datetime=$(get_env_value "$metadata_env" trace_creation_datetime)
+       ok $? "Extracting trace_creation_datetime from env metadata: \`$trace_creation_datetime\`"
+       trace_creation_datetime=$(iso8601_to_lttng_dir_datetime "$trace_creation_datetime")
+       expected_path="${expected_path}-${trace_creation_datetime}"
 
        # Domain
-       value=$(get_env_value "$metadata_env" domain)
-       ok $? "Extracting domain from env metadata"
-       expected_path="${expected_path}/${value}"
+       local domain
+       domain=$(get_env_value "$metadata_env" domain)
+       ok $? "Extracting domain from env metadata: \`$domain\`"
+       expected_path="${expected_path}/${domain}"
 
        # Append "metadata" and test that we find the file.
        expected_path="${expected_path}/metadata"
 
-       test -e "$expected_path"
-       ok $? "Reconstructed path from metadata is valid"
+       test -f "$expected_path"
+       ok $? "Reconstructed path from metadata is an existing file: \`$expected_path\`"
 
        # Hostname
        # The hostname is not part of the lttng hierarchy still we can test for
        # its validity here.
-       value=$(get_env_value "$metadata_env" hostname)
-       ok $? "Extracting hostname from env metadata"
-       is "$value" "$(hostname)" "Hostname is valid"
+       local hostname
+       hostname=$(get_env_value "$metadata_env" hostname)
+       ok $? "Extracting hostname from env metadata: \`$hostname\`"
+       is "$hostname" "$(hostname)" "Extracted hostname matches current hostname"
 
        rm -f "$metadata"
        rm -f "$metadata_env"
@@ -105,9 +111,8 @@ skip $isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_T
 
        # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
        # with "<session_name>-<datetime>/...".
-       LTTNG_HOME="$TRACE_PATH"
+       export LTTNG_HOME="$TRACE_PATH"
 
-       export LTTNG_HOME
        start_lttng_sessiond
 
        tests=( test_kernel )
index fc9aea536fbbe28086839f3d355e0730471d688a..05a2a8bec6771fc6a885ab74685d215615a1885c 100755 (executable)
@@ -32,13 +32,14 @@ fi
 function test_per_uid ()
 {
        local metadata_path
-       local value
-       local value2
+       local metadata
+       local metadata_env
 
        local expected_path="${TRACE_PATH}/lttng-traces"
        local session_name="per-uid"
-       local metadata=$(mktemp -t tmp.test_${FUNCNAME[0]}_metadata.XXXXXX)
-       local metadata_env=$(mktemp -t tmp.test_${FUNCNAME[0]}_metadata_env.XXXXXX)
+
+       metadata=$(mktemp -t tmp.test_per_uid_metadata.XXXXXX)
+       metadata_env=$(mktemp -t tmp.test_per_uid_metadata_env.XXXXXX)
 
        diag "Test UST metadata env field in per-uid mode"
        create_lttng_session_ok "$session_name"
@@ -66,51 +67,58 @@ function test_per_uid ()
        # to allow trace viewer to recreate the same directory hierarchy.
 
        # Trace name
-       value=$(get_env_value "$metadata_env" trace_name)
-       ok $? "Extracting trace_name from env metadata"
-       expected_path="${expected_path}/${value}"
+       local trace_name
+       trace_name=$(get_env_value "$metadata_env" trace_name)
+       ok $? "Extracting trace_name from env metadata: \`$trace_name\`"
+       expected_path="${expected_path}/${trace_name}"
 
        # Session creation time
-       value=$(get_env_value "$metadata_env" trace_creation_datetime)
-       ok $? "Extracting trace_creation_datetime from env metadata"
-       value=$(iso8601_to_lttng_dir_datetime "$value")
-       expected_path="${expected_path}-${value}"
+       local trace_creation_datetime
+       trace_creation_datetime=$(get_env_value "$metadata_env" trace_creation_datetime)
+       ok $? "Extracting trace_creation_datetime from env metadata: \`$trace_creation_datetime\`"
+       trace_creation_datetime=$(iso8601_to_lttng_dir_datetime "$trace_creation_datetime")
+       expected_path="${expected_path}-${trace_creation_datetime}"
 
        # Domain
-       value=$(get_env_value "$metadata_env" domain)
-       ok $? "Extracting domain from env metadata"
-       expected_path="${expected_path}/${value}"
+       local domain
+       domain=$(get_env_value "$metadata_env" domain)
+       ok $? "Extracting domain from env metadata: \`$domain\`"
+       expected_path="${expected_path}/${domain}"
 
        # Buffering scheme
-       value=$(get_env_value "$metadata_env" tracer_buffering_scheme)
-       ok $? "Extracting tracer_buffering_scheme from env metadata"
-       expected_path="${expected_path}/${value}"
+       local tracer_buffering_scheme
+       tracer_buffering_scheme=$(get_env_value "$metadata_env" tracer_buffering_scheme)
+       ok $? "Extracting tracer_buffering_scheme from env metadata: \`$tracer_buffering_scheme\`"
+       expected_path="${expected_path}/${tracer_buffering_scheme}"
 
        # tracer_buffering_id
-       value=$(get_env_value "$metadata_env" tracer_buffering_id)
-       ok $? "Extracting tracer_buffering_id from env metadata"
-       expected_path="${expected_path}/${value}"
+       local tracer_buffering_id
+       tracer_buffering_id=$(get_env_value "$metadata_env" tracer_buffering_id)
+       ok $? "Extracting tracer_buffering_id from env metadata: \`$tracer_buffering_id\`"
+       expected_path="${expected_path}/${tracer_buffering_id}"
 
        # Check that the uid is the one we expect from the current user
-       is "$value" "$(id -u)" "tracer_buffering_id match current user uid"
+       is "$tracer_buffering_id" "$(id -u)" "tracer_buffering_id match current user uid: \`$tracer_buffering_id\`"
 
        # Architecture_bit_width
-       value=$(get_env_value "$metadata_env" architecture_bit_width)
-       ok $? "Extracting architecture_bit_width from env metadata"
-       expected_path="${expected_path}/${value}-bit"
+       local architecture_bit_width
+       architecture_bit_width=$(get_env_value "$metadata_env" architecture_bit_width)
+       ok $? "Extracting architecture_bit_width from env metadata: \`$architecture_bit_width\`"
+       expected_path="${expected_path}/${architecture_bit_width}-bit"
 
        # Append "metadata" and test that we find the file.
        expected_path="${expected_path}/metadata"
 
-       test -e "$expected_path"
-       ok $? "Reconstructed path from metadata is valid"
+       test -f "$expected_path"
+       ok $? "Reconstructed path from metadata is an existing file: \`$expected_path\`"
 
        # Hostname
        # The hostname is not part of the lttng hierarchy still we can test for
        # its validity here.
-       value=$(get_env_value "$metadata_env" hostname)
-       ok $? "Extracting hostname from env metadata"
-       is "$value" "$(hostname)" "Hostname is valid"
+       local hostname
+       hostname=$(get_env_value "$metadata_env" hostname)
+       ok $? "Extracting hostname from env metadata: \`$hostname\`"
+       is "$hostname" "$(hostname)" "Extracted hostname matches current hostname"
 
        rm -f "$metadata"
        rm -f "$metadata_env"
@@ -119,14 +127,15 @@ function test_per_uid ()
 function test_per_pid ()
 {
        local metadata_path
+       local metadata
+       local metadata_env
        local testapp_pid
-       local value
-       local value2
 
        local expected_path="${TRACE_PATH}/lttng-traces"
        local session_name="per-pid"
-       local metadata=$(mktemp -t tmp.test_${FUNCNAME[0]}_metadata.XXXXXX)
-       local metadata_env=$(mktemp -t tmp.test_${FUNCNAME[0]}_metadata_env.XXXXXX)
+
+       metadata=$(mktemp -t tmp.test_per_pid_metadata.XXXXXX)
+       metadata_env=$(mktemp -t tmp.test_per_pid_metadata_env.XXXXXX)
 
        diag "Test UST metadata env field in per-pid mode"
        create_lttng_session_ok "$session_name"
@@ -157,62 +166,70 @@ function test_per_pid ()
        # to allow trace viewer to recreate the same directory hierarchy.
 
        # Trace name
-       value=$(get_env_value "$metadata_env" trace_name)
-       ok $? "Extracting trace_name from env metadata"
-       expected_path="${expected_path}/${value}"
+       local trace_name
+       trace_name=$(get_env_value "$metadata_env" trace_name)
+       ok $? "Extracting trace_name from env metadata: \`$trace_name\`"
+       expected_path="${expected_path}/${trace_name}"
 
        # Session creation time
-       value=$(get_env_value "$metadata_env" trace_creation_datetime)
-       ok $? "Extracting trace_creation_datetime from env metadata"
-       value=$(iso8601_to_lttng_dir_datetime "$value")
-       expected_path="${expected_path}-${value}"
+       local trace_creation_datetime
+       trace_creation_datetime=$(get_env_value "$metadata_env" trace_creation_datetime)
+       ok $? "Extracting trace_creation_datetime from env metadata: \`$trace_creation_datetime\`"
+       trace_creation_datetime=$(iso8601_to_lttng_dir_datetime "$trace_creation_datetime")
+       expected_path="${expected_path}-${trace_creation_datetime}"
 
        # Domain
-       value=$(get_env_value "$metadata_env" domain)
-       ok $? "Extracting domain from env metadata"
-       expected_path="${expected_path}/${value}"
+       local domain
+       domain=$(get_env_value "$metadata_env" domain)
+       ok $? "Extracting domain from env metadata: \`$domain\`"
+       expected_path="${expected_path}/${domain}"
 
        # Buffering scheme
-       value=$(get_env_value "$metadata_env" tracer_buffering_scheme)
-       ok $? "Extracting tracer_buffering_scheme from env metadata"
-       expected_path="${expected_path}/${value}"
+       local tracer_buffering_scheme
+       tracer_buffering_scheme=$(get_env_value "$metadata_env" tracer_buffering_scheme)
+       ok $? "Extracting tracer_buffering_scheme from env metadata: \`$tracer_buffering_scheme\`"
+       expected_path="${expected_path}/${tracer_buffering_scheme}"
 
        # Procname
-       value=$(get_env_value "$metadata_env" procname)
-       ok $? "Extracting procname from env metadata"
-       expected_path="${expected_path}/${value}"
+       local procname
+       procname=$(get_env_value "$metadata_env" procname)
+       ok $? "Extracting procname from env metadata: \`$procname\`"
+       expected_path="${expected_path}/${procname}"
 
        # vpid and tracer_buffering_id should be the same here.
-       # "vpid =" is used since other key have vpid in them.
-       value=$(get_env_value "$metadata_env" "vpid =")
-       ok $? "Extracting vpid from env metadata"
+       local vpid
+       vpid=$(get_env_value "$metadata_env" "vpid")
+       ok $? "Extracting vpid from env metadata: \`$vpid\`"
 
-       value2=$(get_env_value "$metadata_env" tracer_buffering_id)
-       ok $? "Extracting tracer_buffering_id from env metadata"
-       expected_path="${expected_path}-${value2}"
+       local tracer_buffering_id
+       tracer_buffering_id=$(get_env_value "$metadata_env" tracer_buffering_id)
+       ok $? "Extracting tracer_buffering_id from env metadata: \`$tracer_buffering_id\`"
+       expected_path="${expected_path}-${tracer_buffering_id}"
 
-       is "$value" "$value2" "vpid and tracer_buffering_id are identical"
-       is "$testapp_pid" "$value" "vpid and known testapp pid are identical"
-       is "$testapp_pid" "$value2" "tracer_buffering_id and known testapp pid are identical"
+       is "$vpid" "$tracer_buffering_id" "vpid and tracer_buffering_id are identical"
+       is "$testapp_pid" "$vpid" "vpid and known testapp pid are identical"
+       is "$testapp_pid" "$tracer_buffering_id" "tracer_buffering_id and known testapp pid are identical"
 
        # vpid_datetime
-       value=$(get_env_value "$metadata_env" vpid_datetime)
-       ok $? "Extracting vpid_datetime from env metadata"
-       value=$(iso8601_to_lttng_dir_datetime "$value")
-       expected_path="${expected_path}-${value}"
+       local vpid_datetime
+       vpid_datetime=$(get_env_value "$metadata_env" vpid_datetime)
+       ok $? "Extracting vpid_datetime from env metadata: \`$vpid_datetime\`"
+       vpid_datetime=$(iso8601_to_lttng_dir_datetime "$vpid_datetime")
+       expected_path="${expected_path}-${vpid_datetime}"
 
        # Append "metadata" and test that we find the file.
        expected_path="${expected_path}/metadata"
 
-       test -e "$expected_path"
-       ok $? "Reconstructed path from metadata is valid"
+       test -f "$expected_path"
+       ok $? "Reconstructed path from metadata is an existing file: \`$expected_path\`"
 
        # Hostname
        # The hostname is not part of the lttng hierarchy still we can test for
        # its validity here.
-       value=$(get_env_value "$metadata_env" hostname)
-       ok $? "Extracting hostname from env metadata"
-       is "$value" "$(hostname)" "Hostname is valid"
+       local hostname
+       hostname=$(get_env_value "$metadata_env" hostname)
+       ok $? "Extracting hostname from env metadata: \`$hostname\`"
+       is "$hostname" "$(hostname)" "Extracted hostname matches current hostname"
 
        rm -f "$metadata"
        rm -f "$metadata_env"
@@ -226,9 +243,8 @@ bail_out_if_no_babeltrace
 
 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
 # with "<session_name>-<datetime>/...".
-LTTNG_HOME="$TRACE_PATH"
+export LTTNG_HOME="$TRACE_PATH"
 
-export LTTNG_HOME
 start_lttng_sessiond
 
 tests=( test_per_uid test_per_pid )
index 99a6cc6d856caeb3af20e9188a0729717733aef6..a355936c6d2265f69faf869b82bd658a3d534743 100644 (file)
@@ -11,7 +11,7 @@ function get_env_value ()
        local result
        local ret
 
-       result=$(grep "$key" < "$env_file")
+       result=$(grep "$key =" < "$env_file")
        ret=$?
        if [ $ret -eq 1 ]; then
                echo "invalid_value_extraction"
This page took 0.0308389999999999 seconds and 4 git commands to generate.