From f2489409aa5ac1d21a40790399f1218c93227491 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Fri, 6 Mar 2020 18:18:14 -0500 Subject: [PATCH] Fix: Tests: utils.sh: merge `validate_{directory,folder_is}_empty` functions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Issues ====== 1. Both functions aim to do the same thing. 2. The current `validate_folder_is_empty` function uses an erroneous way of checking if a folder is empty. `ls -A` returns zero on success; it doesn't return the number of files and sub-folders. A correct way to get the number of elements in a directory is to pipe the output of `ls -A` to `wc -l`. 3. The `local_path` variable is used undefined in the current `validate_directory_empty` function. It just happens that the `local_path` variable is defined in all but one of the callsites of this function so those calls work as expected. The other call to this function was bogus (tests/regression/tools/clear/test_ust:323) because it uses the `$TRACE_PATH` variable name. Fixes ===== - Merge both functions into one, keeping the name `validate_directory_empty`, - Fix the emptiness check, - Fix usages of `validate_directory_empty` in tests. Signed-off-by: Francis Deslauriers Change-Id: Id75baf16f42866e3b978389f9aada4a2f6b6f2ae Signed-off-by: Jérémie Galarneau --- tests/regression/tools/clear/test_ust | 11 ++++++++-- tests/utils/utils.sh | 29 +++++++++++---------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/regression/tools/clear/test_ust b/tests/regression/tools/clear/test_ust index e121614d2..62a480409 100755 --- a/tests/regression/tools/clear/test_ust +++ b/tests/regression/tools/clear/test_ust @@ -223,7 +223,11 @@ function test_ust_streaming_live () do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 stop_lttng_tracing_ok $SESSION_NAME - validate_directory_empty $local_path + if [[ "$buffer_type" == "uid" ]]; then + validate_trace_empty $local_path + else # pid + validate_directory_empty $local_path + fi destroy_lttng_session_ok $SESSION_NAME } @@ -345,7 +349,10 @@ function test_ust_local () if [[ "$buffer_type" == "uid" ]]; then validate_trace_empty $TRACE_PATH else # pid - validate_directory_empty $TRACE_PATH + + # The sessiond always created a `ust/ directory + # whenever the UST domain is active + validate_directory_empty $TRACE_PATH/ust/ fi fi diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index d0f76bc6f..b326c5bcf 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -1604,18 +1604,6 @@ function add_context_kernel_fail() add_context_lttng 1 -k "$@" } -function validate_directory_empty () -{ - local trace_path=$1 - - ls -A $local_path > /dev/null 2>&1 - if [ $? -eq 0 ]; then - pass "Directory empty" - else - fail "Directory empty" - fi -} - function wait_live_trace_ready () { local url=$1 @@ -1868,17 +1856,24 @@ function validate_trace_empty() return $ret } -function validate_folder_is_empty() +function validate_directory_empty () { - local folder=$1 + local trace_path="$1" + + files="$(ls -A "$trace_path")" + ret=$? + if [ $ret -ne 0 ]; then + fail "Failed to list content of directory \"$trace_path\"" + return $ret + fi - test -z "$(ls -A "$folder")" - ok $? "Folder ${folder} is empty" + nb_files="$(echo -n "$files" | wc -l)" + ok $nb_files "Directory \"$trace_path\" is empty" } function validate_trace_session_ust_empty() { - validate_folder_is_empty "$1"/ust + validate_directory_empty "$1"/ust } function validate_trace_session_kernel_empty() -- 2.34.1