Fix: Tests: utils.sh: merge `validate_{directory,folder_is}_empty` functions
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 6 Mar 2020 23:18:14 +0000 (18:18 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 17 Mar 2020 17:24:16 +0000 (13:24 -0400)
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 <francis.deslauriers@efficios.com>
Change-Id: Id75baf16f42866e3b978389f9aada4a2f6b6f2ae
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/regression/tools/clear/test_ust
tests/utils/utils.sh

index e121614d239ba00c42e434c570e51636079dd4fc..62a4804093c739a4e1acadef904f6dbe56a26f41 100755 (executable)
@@ -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
 
index d0f76bc6f678adff8375397f673b1e89d95162be..b326c5bcf94166358e341217078aa1721bb2c8e7 100644 (file)
@@ -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()
This page took 0.029119 seconds and 5 git commands to generate.