Skip to content

Commit

Permalink
test script cleanup
Browse files Browse the repository at this point in the history
|& -> 2>&1 |
remove realpath from generatetree
stat format flag
remove whitespace from wc -l output in gufi_dir2trace
change getfattr to os_getfattr
  • Loading branch information
calccrypto committed Mar 6, 2025
1 parent f927f77 commit 9bbbdff
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 40 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ if(APPLE)
find_exec_dependency(XATTR xattr)
else()
find_exec_dependency(SETFATTR setfattr)
find_exec_dependency(GETFATTR getfattr)
endif()

# Need the PkgConfig module for pkg_search_module
Expand Down
2 changes: 1 addition & 1 deletion test/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# regression test specific files
set(CORE
generatetree.sh
os_setfattr.sh
os_xattr.sh
setup.sh
)

Expand Down
2 changes: 1 addition & 1 deletion test/regression/external_databases.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ rollup() {
do_tests
rollup
do_tests
) |& tee "${OUTPUT}"
) 2>&1 | tee "${OUTPUT}"

@DIFF@ @CMAKE_CURRENT_BINARY_DIR@/external_databases.expected "${OUTPUT}"
rm "${OUTPUT}"
Expand Down
5 changes: 3 additions & 2 deletions test/regression/generatetree.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ then
return 1
fi

DIR="$(realpath $1)"
DIR="$1"

source @CMAKE_CURRENT_BINARY_DIR@/os_setfattr.sh
source @CMAKE_CURRENT_BINARY_DIR@/os_xattr.sh

rm -rf "${DIR}"
mkdir -p "${DIR}"
Expand Down Expand Up @@ -186,4 +186,5 @@ mkdir "unusual#? directory ,"
)
touch -amt 197001010000.16 "unusual#? directory ,"

cd ..
touch -amt 197001010000.17 "${DIR}"
7 changes: 4 additions & 3 deletions test/regression/gufi_dir2trace.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,16 @@ echo "/external/db" > "${SRCDIR}/external.gufi"
run_no_sort "${GUFI_DIR2TRACE} -d \"${DELIM}\" -n ${THREADS} -x \"${SRCDIR}\" \"${TRACE}\""

# count output files
found=$(find "${TRACES[@]}" | wc -l)
# shellcheck disable=SC2016
found=$(find "${TRACES[@]}" | wc -l | @AWK@ '{ print $1 }')
echo "Expecting ${THREADS} trace files. Found ${found}."

# count lines
# shellcheck disable=SC2016
trace_lines=$(cat "${TRACES[@]}" | wc -l | @AWK@ '{print $1 - 1}')
trace_lines=$(cat "${TRACES[@]}" | wc -l | @AWK@ '{ print $1 - 1} ')
contents=$(find "${SRCDIR}")
# shellcheck disable=SC2016
content_lines=$(echo "${contents}" | wc -l | @AWK@ '{print $1}')
content_lines=$(echo "${contents}" | wc -l | @AWK@ '{ print $1 }')
echo "Expecting ${content_lines} lines. Got ${trace_lines}."

# count separators
Expand Down
4 changes: 2 additions & 2 deletions test/regression/gufi_find.expected
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ $ gufi_find -printf "%% %a %b %c %d %k %g %u %D %f %G %h %i %m %M %n %p %P %s %t
% 1024 0 1024 2 0 0 0 - 1KB 0 prefix/1KB 0 664 -rw-rw-r-- 1 prefix/1KB prefix/1KB 1024 1024 0 f
% 1048576 0 1048576 2 0 0 0 - 1MB 0 prefix/1MB 0 664 -rw-rw-r-- 1 prefix/1MB prefix/1MB 1048576 1048576 0 f

$ gufi_find -empty path_after_expression |& grep "RuntimeError:"
$ gufi_find -empty path_after_expression 2>&1 | grep "RuntimeError:"
RuntimeError: gufi_find: unknown predicate `path_after_expression'

$ gufi_find -atime abc
Expand All @@ -723,7 +723,7 @@ usage: gufi_find [-help] [-maxdepth levels] [-mindepth levels] [--version]
[--aggregate-name name] [--skip-file filename] [--verbose]
gufi_find: error: argument -atime: abc is not a valid numeric argument

$ gufi_find -unknown-predicate |& grep "RuntimeError:"
$ gufi_find -unknown-predicate 2>&1 | grep "RuntimeError:"
RuntimeError: gufi_find: unknown predicate `-unknown-predicate'

$ gufi_find --skip "skip"
Expand Down
4 changes: 2 additions & 2 deletions test/regression/gufi_find.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ run_no_sort "${GUFI_QUERY} -a -w -E \"UPDATE entries SET inode = 0, uid = 0, gid
run_no_sort "${GUFI_FIND} -printf \"%% %a %b %c %d %k %g %u %D %f %G %h %i %m %M %n %p %P %s %t %U %y\" -type f" | @AWK@ '{ if ((NR > 1) && (NF > 8)) { $3=0; $6=0; $7=0; $8=0; } print }' | sort -n -k 2; echo

# path must come before expressions
run_no_sort "${GUFI_FIND} -empty path_after_expression |& @GREP@ \"RuntimeError:\""
run_no_sort "${GUFI_FIND} -empty path_after_expression 2>&1 | @GREP@ \"RuntimeError:\""

# bad numerical input
run_no_sort "${GUFI_FIND} -atime abc"

# unknown predicate
run_no_sort "${GUFI_FIND} -unknown-predicate |& @GREP@ \"RuntimeError:\""
run_no_sort "${GUFI_FIND} -unknown-predicate 2>&1 | @GREP@ \"RuntimeError:\""

# skip
run_sort "${GUFI_FIND} --skip \"${SKIP}\""
Expand Down
2 changes: 1 addition & 1 deletion test/regression/gufi_ls.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ run_sort "${GUFI_LS} --skip \"${SKIP}\" ${BASENAME}"

# bad skip
run_no_sort "${GUFI_LS} --skip \"${SKIP}.bad\" ${BASENAME}"
) |& tee "${OUTPUT}"
) 2>&1 | tee "${OUTPUT}"

@DIFF@ @CMAKE_CURRENT_BINARY_DIR@/gufi_ls.expected "${OUTPUT}"
rm "${OUTPUT}"
2 changes: 1 addition & 1 deletion test/regression/gufi_query.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ rm -f "${INDEXROOT}/directory/symlink"
echo "# Missing database file"
rm "${INDEXROOT}/db.db"
run_sort "${GUFI_QUERY} -d \" \" -m -S \"SELECT name FROM vrsummary;\" -E \"SELECT name FROM vrpentries;\" \"${INDEXROOT}\" > /dev/null"
) |& tee "${OUTPUT}"
) 2>&1 | tee "${OUTPUT}"

echo "# Print terse debug timestamps (not part of expected results)"
run_sort "${GUFI_QUERY} -d \" \" -j -S \"SELECT name FROM vrsummary;\" -E \"SELECT name FROM vrpentries;\" \"${INDEXROOT}\""
Expand Down
2 changes: 1 addition & 1 deletion test/regression/gufi_sqlite3.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ PATH="@CMAKE_BINARY_DIR@/src:${PATH}" run_no_sort "echo -n \"CREATE VIRTUAL TABL
echo "# bad SQL"
run_no_sort "(echo \"CREATE TABLE;\") |" \
"${GUFI_SQLITE3}"
) |& tee "${OUTPUT}"
) 2>&1 | tee "${OUTPUT}"

@DIFF@ @CMAKE_CURRENT_BINARY_DIR@/gufi_sqlite3.expected "${OUTPUT}"
rm "${OUTPUT}"
6 changes: 3 additions & 3 deletions test/regression/gufi_stats.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ run() {
}

run_uidgid_size() {
echo "$" "$@" |& replace
echo "$" "$@" 2>&1 | replace
# shellcheck disable=SC2294
eval "${GUFI_PYTHON_TEST_COVERAGE}" "$@" |& replace | @AWK@ "{ \$1 = ${TEST_USER_ID} ; print }"
eval "${GUFI_PYTHON_TEST_COVERAGE}" "$@" 2>&1 | replace | @AWK@ "{ \$1 = ${TEST_USER_ID} ; print }"
echo
}

Expand Down Expand Up @@ -187,7 +187,7 @@ then
run "${GUFI_STATS} median-leaf-links \"${BASENAME}\""
run "${GUFI_STATS} median-leaf-size \"${BASENAME}\""
fi
) |& tee "${OUTPUT}"
) 2>&1 | tee "${OUTPUT}"

EXPECTED="@CMAKE_CURRENT_BINARY_DIR@/gufi_stats.expected"
ACTUAL="${EXPECTED}.actual"
Expand Down
4 changes: 2 additions & 2 deletions test/regression/gufi_treesummary.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ keep_paths() {
echo "$" "$@"
# shellcheck disable=SC2016,SC2294
eval "$@" | sed '/^$/d; /tot.*/d; /min.*/d;' | @AWK@ -F "|" '{ print $1 "|" $2 }' | sort
) |& replace
) 2>&1 | replace
}

query() {
Expand Down Expand Up @@ -165,7 +165,7 @@ echo
echo "# Bad thread count"
remove_extra "${GUFI_TREESUMMARY} -n 18446744073709551615 \"${INDEXROOT}\""
echo
) |& replace | tee "${OUTPUT}"
) 2>&1 | replace | tee "${OUTPUT}"

@DIFF@ @CMAKE_CURRENT_BINARY_DIR@/gufi_treesummary.expected "${OUTPUT}"
rm "${OUTPUT}"
2 changes: 1 addition & 1 deletion test/regression/longitudinal_snapshot.expected
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ options:
# bad flat db path
$ ln -s "prefix" "flattened_index.db"

$ longitudinal_snapshot.py level "prefix" "flattened_index.db" "longitudinal_snapshot.db" --gufi_query="gufi_query" |& tail -n 2 | head -n 1
$ longitudinal_snapshot.py level "prefix" "flattened_index.db" "longitudinal_snapshot.db" --gufi_query="gufi_query" 2>&1 | tail -n 2 | head -n 1
TypeError: "flattened_index.db" is not a regular file

$ rm "flattened_index.db"
Expand Down
2 changes: 1 addition & 1 deletion test/regression/longitudinal_snapshot.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ show_schema() {
(
echo "# bad flat db path"
run_no_sort "ln -s \"${INDEXROOT}\" \"${FLATDB}\""
run_no_sort "${LONGITUDINAL_SNAPSHOT} ${grouping} \"${INDEXROOT}\" \"${FLATDB}\" \"${SNAPSHOT}\" --gufi_query=\"${GUFI_QUERY}\" |& tail -n 2 | head -n 1"
run_no_sort "${LONGITUDINAL_SNAPSHOT} ${grouping} \"${INDEXROOT}\" \"${FLATDB}\" \"${SNAPSHOT}\" --gufi_query=\"${GUFI_QUERY}\" 2>&1 | tail -n 2 | head -n 1"
run_no_sort "rm \"${FLATDB}\""

echo "# generate good flat db and snapshot db"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,25 @@ case "@CMAKE_SYSTEM_NAME@" in
# shellcheck disable=SC2215
@SETFATTR@ -n "$1" -v "$2" "$3"
}
os_getfattr() {
# shellcheck disable=SC2215
@GETFATTR@ --dump -- "$1"
}
;;
"APPLE" | "Darwin")
os_setfattr() {
# shellcheck disable=SC2215
@XATTR@ -w "$1" "$2" "$3"
}
os_getfattr() {
# shellcheck disable=SC2215
@XATTR@ "$1" | while read -r name
do
@XATTR@ -pl "${name}" "$1"
done
}
;;
esac

export -f os_setfattr
export -f os_getfattr
4 changes: 2 additions & 2 deletions test/regression/parallel_cpr.expected
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ copy/file_symlink
copy/leaf_file1
copy/leaf_file2

$ getfattr -d -m ".*" -- "copy/leaf_file1"
$ os_getfattr "copy/leaf_file1"

$ getfattr -d -m ".*" -- "copy/leaf_file2"
$ os_getfattr "copy/leaf_file2"
# file: copy/leaf_file2
user.name4="value4"
user.name5="value5"
Expand Down
7 changes: 4 additions & 3 deletions test/regression/parallel_cpr.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

set -e
source @CMAKE_CURRENT_BINARY_DIR@/setup.sh 0
source @CMAKE_CURRENT_BINARY_DIR@/os_xattr.sh

OUTPUT="parallel_cpr.out"

Expand Down Expand Up @@ -109,7 +110,7 @@ set +e
find "${SRCDIR}" | sort | while IFS= read -r name
do
echo "$ compare xattrs of \"${name}\""
@DIFF@ ${DIFF_FLAGS} <(getfattr -P -d -m ".*" -- "${name}") <(getfattr -P -d -m ".*" -- "${CPR_ROOT}/${name}" | sed 's/copy\///g')
@DIFF@ ${DIFF_FLAGS} <(os_getfattr "${name}") <(os_getfattr "${CPR_ROOT}/${name}" | sed 's/copy\///g')
done
set -e

Expand All @@ -121,8 +122,8 @@ run_no_sort "${PARALLEL_CPR} \"${SRCDIR}/leaf_directory/leaf_file1\" \"${CPR_
run_no_sort "${PARALLEL_CPR} -x \"${SRCDIR}/leaf_directory/leaf_file2\" \"${CPR_ROOT}\""
run_no_sort "${PARALLEL_CPR} \"${SRCDIR}/file_symlink\" \"${CPR_ROOT}\""
run_sort "find \"${CPR_ROOT}\" -not -type d"
run_no_sort "getfattr -d -m \".*\" -- \"${CPR_ROOT}/leaf_file1\""
run_no_sort "getfattr -d -m \".*\" -- \"${CPR_ROOT}/leaf_file2\""
run_no_sort "os_getfattr \"${CPR_ROOT}/leaf_file1\""
run_no_sort "os_getfattr \"${CPR_ROOT}/leaf_file2\""
run_no_sort "readlink \"${CPR_ROOT}/file_symlink\""

run_no_sort "rm -rf \"${CPR_ROOT}\""
Expand Down
36 changes: 32 additions & 4 deletions test/regression/rollup_tree.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@ source @CMAKE_CURRENT_BINARY_DIR@/setup.sh 0

TMP="tmp"

case "@CMAKE_SYSTEM_NAME@" in
"Linux" | "CYGWIN")
cpr_xattr() {
cp --preserve=xattr -R "$1" "$2"
}

;;
"APPLE" | "Darwin")
cpr_xattr() {
# copy files without xattrs
cp -R "$1" "2"

find "$1" | while read -r path
do
# figure out where copy went
dst=$(echo "$1" | sed "s/${1//\//\\/}/${2//\//\\/}/g;")

# list all xattrs of original file and copy one at a time
@XATTR@ "$1" | while read -r name
do
value=$(@XATTR@ -p "${name}" "$1")
@XATTR@ -w "${name}" "${value}" "${dst}"
done
done
}
;;
esac

rollup_tree_cleanup() {
rm -rf "${TMP}"
}
Expand Down Expand Up @@ -139,16 +167,16 @@ level3 "${TMP}/u" 500 3 # Level 3 500 - 3 files

mkdir -m 777 "${SRCDIR}" # Level 0

cp --preserve=xattr -R "${TMP}" "${SRCDIR}/o+rx" # Level 1
cpr_xattr "${TMP}" "${SRCDIR}/o+rx" # Level 1
chmod 007 "${SRCDIR}/o+rx"

cp --preserve=xattr -R "${TMP}" "${SRCDIR}/ugo" # Level 1
cpr_xattr "${TMP}" "${SRCDIR}/ugo" # Level 1
chmod 777 "${SRCDIR}/ugo"

cp --preserve=xattr -R "${TMP}" "${SRCDIR}/ug" # Level 1
cpr_xattr "${TMP}" "${SRCDIR}/ug" # Level 1
chmod 770 "${SRCDIR}/ug"

cp --preserve=xattr -R "${TMP}" "${SRCDIR}/u" # Level 1
cpr_xattr "${TMP}" "${SRCDIR}/u" # Level 1
chmod 700 "${SRCDIR}/u"

rm -r "${TMP}"
22 changes: 16 additions & 6 deletions test/regression/setup.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ export PYTHONPATH="@CMAKE_BINARY_DIR@/scripts:@CMAKE_CURRENT_BINARY_DIR@:${PYTHO
# fill in skip file here (after setup_cleanup)
echo "directory" > "${SKIP}"

# shellcheck disable=SC2194
case "@CMAKE_SYSTEM_NAME@" in
"Linux" | "CYGWIN")
STAT_FORMAT_FLAG="-c"
;;
"APPLE" | "Darwin")
STAT_FORMAT_FLAG="-f"
;;
esac

# paths of all executables
SQLITE3="@DEP_INSTALL_PREFIX@/sqlite3/bin/sqlite3"
GUFI_TOOL="@CMAKE_CURRENT_BINARY_DIR@/gufi_tool.py"
Expand Down Expand Up @@ -262,16 +272,16 @@ replace_argparse() {
}

run_sort() {
echo "$" "$@" |& replace
echo "$" "$@" 2>&1 | replace
# shellcheck disable=SC2294
eval "${GUFI_PYTHON_TEST_COVERAGE}" "$@" |& replace | sort
eval "${GUFI_PYTHON_TEST_COVERAGE}" "$@" 2>&1 | replace | sort
echo
}

run_no_sort() {
echo "$" "$@" |& replace
echo "$" "$@" 2>&1 | replace
# shellcheck disable=SC2294
eval "${GUFI_PYTHON_TEST_COVERAGE}" "$@" |& replace
eval "${GUFI_PYTHON_TEST_COVERAGE}" "$@" 2>&1 | replace
echo
}

Expand Down Expand Up @@ -352,8 +362,8 @@ clean_index() {
if [[ "${ACTUAL}" == "1" ]]
then
# directory/subdirectory and directory/subdirectory/repeat_name need their actual inodes
DIR="$(stat -c '%i' ${SRCDIR}/directory/subdirectory)"
FILE="$(stat -c '%i' ${SRCDIR}/directory/subdirectory/repeat_name)"
DIR="$(stat ${STAT_FORMAT_FLAG}'%i' ${SRCDIR}/directory/subdirectory)"
FILE="$(stat ${STAT_FORMAT_FLAG} '%i' ${SRCDIR}/directory/subdirectory/repeat_name)"
"${SQLITE3}" "${INDEX}/directory/subdirectory/db.db" "UPDATE summary SET inode = '${DIR}' WHERE name == 'subdirectory';"
"${SQLITE3}" "${INDEX}/directory/subdirectory/db.db" "UPDATE entries SET inode = '${FILE}' WHERE name == 'repeat_name';"
"${SQLITE3}" "${INDEX}/directory/subdirectory/db.db" "UPDATE xattrs_pwd SET inode = '${DIR}' WHERE inode == '6';"
Expand Down
4 changes: 2 additions & 2 deletions test/regression/verifytrace.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ run_no_sort "${GUFI_DIR2TRACE} -d \"${DELIM}\" -n 1 \"${SRCDIR}\" \"${TRACE}\""
order_tracefile "${TRACE}.0" > "${TRACE}"

# replace the numeric fields in the trace with 0s
sed -i 's/[[:digit:]]\+/0/g' "${TRACE}"
sed -i 's/[0-9]\+/0/g' "${TRACE}"

# replace some rows with fixed data
sed -i "s/^${DELIM}d${DELIM}.*\$/${DELIM}d${DELIM}1${DELIM}0${DELIM}0${DELIM}0${DELIM}0${DELIM}0${DELIM}0${DELIM}0${DELIM}0${DELIM}0${DELIM}0${DELIM}${DELIM}${DELIM}0${DELIM}0${DELIM}0${DELIM}0${DELIM}0${DELIM}${DELIM}${DELIM}0${DELIM}/g" "${TRACE}"
Expand Down Expand Up @@ -236,7 +236,7 @@ echo "# bad parent pinode"

cat "${BADTRACE}"
run_no_sort "${VERIFYTRACE} \"${DELIM}\" \"${BADTRACE}\""
) |& remove_indexing_time | tee "${OUTPUT}"
) 2>&1 | remove_indexing_time | tee "${OUTPUT}"

@DIFF@ @CMAKE_CURRENT_BINARY_DIR@/verifytrace.expected "${OUTPUT}"
rm "${OUTPUT}"
2 changes: 1 addition & 1 deletion test/regression/verifytraceintree.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ echo "# empty line (Pass)"
echo
) > "${COPY}"
run_no_sort "${VERIFYTRACEINTREE} \"${COPY}\" \"${DELIM}\" \"${SEARCH}\""
) |& remove_indexing_time | sed '/qptpool.*/d' | tee "${OUTPUT}"
) 2>&1 | remove_indexing_time | sed '/qptpool.*/d' | tee "${OUTPUT}"

@DIFF@ @CMAKE_CURRENT_BINARY_DIR@/verifytraceintree.expected "${OUTPUT}"
rm "${OUTPUT}"
2 changes: 1 addition & 1 deletion test/regression/xattrs.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

set -e
source @CMAKE_CURRENT_BINARY_DIR@/setup.sh 0
source @CMAKE_CURRENT_BINARY_DIR@/os_setfattr.sh
source @CMAKE_CURRENT_BINARY_DIR@/os_xattr.sh

OUTPUT="xattrs.out"

Expand Down

0 comments on commit 9bbbdff

Please sign in to comment.