From 45ec17b7eb8e50f82f35b22c384a79cb81edef39 Mon Sep 17 00:00:00 2001 From: Urmas Rist Date: Thu, 18 Apr 2024 11:07:41 +0300 Subject: [PATCH 1/2] fix(tests): Various fixes for the testing framework This is a series of 3 commits: tidy(tests): Remove unnecessary ticks This messes up some editor syntax highlighting fix(tests): Fix binary output being outputted The variable used in the conditional is different from the actual filename used. This conditional would always succeed since awk would return 0 if the conditional in awk would not match, which it didn't since stdout was empty (only stderr was populated with the error message, but it is disregarded). fix(tests): Coredumps not being generated At least 3 years ago, `sudo` had a change of behaviour regarding coredumps. This fixes that by setting the default for cores as the system. --- tests/run-test.sh | 12 +++++++----- tests/setup_machine.sh | 1 + tests/tools/assert.sh | 4 ++-- tests/tools/test.sh | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/run-test.sh b/tests/run-test.sh index f84186df1..199670022 100755 --- a/tests/run-test.sh +++ b/tests/run-test.sh @@ -94,20 +94,22 @@ unwrap_generators $1 nice nice sudo -HEu saunafstest sh -c "chmod -Rf a+rwX ${ERROR_DIR}" for log_file in "$ERROR_DIR"/* ; do - log_file_name=$(basename "$log_file") + log_file_basename=$(basename "$log_file") if [[ -s ${log_file} ]]; then status=1 - if [[ $log_file_name != syslog.log ]]; then + if [[ $log_file_basename != syslog.log ]]; then # Do not inform users that there is nonempty syslog # It is always nonempty if the test failed - echo "(FATAL) Errors in ${log_file_name}" | tee "${ERROR_FILE}" #error file lifetime is: all tests + echo "(FATAL) Errors in ${log_file_basename}" | tee "${ERROR_FILE}" #error file lifetime is: all tests # print all non-binary files to stdout - if file --mime-encoding "${log_file_name}" | awk '{exit $2=="binary"}'; then + # awk will return 0 if it doesn't find binary, and 1 if + # it does, which is what we want for the return value + if file --mime-encoding "${log_file}" | awk '{exit $2=="binary"}'; then cat "${log_file}" fi fi if [[ $TEST_OUTPUT_DIR ]]; then - cp "${log_file}" "$TEST_OUTPUT_DIR/$(date '+%F_%T')__$(basename $1 .sh)__${log_file_name}" + cp "${log_file}" "$TEST_OUTPUT_DIR/$(date '+%F_%T')__$(basename $1 .sh)__${log_file_basename}" fi fi done diff --git a/tests/setup_machine.sh b/tests/setup_machine.sh index a4ff54874..37112b606 100755 --- a/tests/setup_machine.sh +++ b/tests/setup_machine.sh @@ -289,6 +289,7 @@ fi if ! [[ -f /etc/sudoers.d/saunafstest ]] || \ ! grep drop_caches /etc/sudoers.d/saunafstest >/dev/null; then cat >/etc/sudoers.d/saunafstest <<-END + Defaults rlimit_core=default ALL ALL = (saunafstest) NOPASSWD: ALL ALL ALL = NOPASSWD: /usr/bin/pkill -9 -u saunafstest ALL ALL = NOPASSWD: /bin/rm -rf /tmp/saunafs_error_dir diff --git a/tests/tools/assert.sh b/tests/tools/assert.sh index 999ac0316..b50af5233 100644 --- a/tests/tools/assert.sh +++ b/tests/tools/assert.sh @@ -178,8 +178,8 @@ assert_template_eventually_equals_() { local timeout=$(rescale_timeout_for_assert_eventually_ "${3:-}") if ! wait_for "[[ \$($command1) == \$($command2) ]]" "$timeout"; then diff="$(diff -u5 <(eval "$command1") <(eval "$command2") || true)" - $FAIL_FUNCTION "'$command1' didn't output the same as '$command2' within $timeout` - `"$'\n'"$diff" + $FAIL_FUNCTION "'$command1' didn't output the same as '$command2' within $timeout + "$'\n'"$diff" fi } diff --git a/tests/tools/test.sh b/tests/tools/test.sh index 8d13bb84f..c19f32ed7 100644 --- a/tests/tools/test.sh +++ b/tests/tools/test.sh @@ -86,8 +86,8 @@ debug_command() { fi if (( depth <= DEBUG_LEVEL )); then local indent=">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" - echo "${indent:0:$depth} $(basename "${BASH_SOURCE[1]}"):${BASH_LINENO[0]}:` - `${FUNCNAME[1]}(): ${BASH_COMMAND}" >&2 | true + echo "${indent:0:$depth} $(basename "${BASH_SOURCE[1]}"):${BASH_LINENO[0]}: + ${FUNCNAME[1]}(): ${BASH_COMMAND}" >&2 | true fi } From f4ac140987e0f18e69aca33de454c64e78e362ad Mon Sep 17 00:00:00 2001 From: Urmas Rist Date: Tue, 30 Apr 2024 14:07:53 +0300 Subject: [PATCH 2/2] tidy(tests): Fix broken output on strings Removing the backticks caused the output to not behave correctly. This fixes that by ensuring they remain on one line. --- tests/tools/assert.sh | 3 +-- tests/tools/test.sh | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/tools/assert.sh b/tests/tools/assert.sh index b50af5233..9bfaf0f2e 100644 --- a/tests/tools/assert.sh +++ b/tests/tools/assert.sh @@ -178,8 +178,7 @@ assert_template_eventually_equals_() { local timeout=$(rescale_timeout_for_assert_eventually_ "${3:-}") if ! wait_for "[[ \$($command1) == \$($command2) ]]" "$timeout"; then diff="$(diff -u5 <(eval "$command1") <(eval "$command2") || true)" - $FAIL_FUNCTION "'$command1' didn't output the same as '$command2' within $timeout - "$'\n'"$diff" + $FAIL_FUNCTION "'$command1' didn't output the same as '$command2' within $timeout "$'\n'"$diff" fi } diff --git a/tests/tools/test.sh b/tests/tools/test.sh index c19f32ed7..8d84bf937 100644 --- a/tests/tools/test.sh +++ b/tests/tools/test.sh @@ -86,8 +86,12 @@ debug_command() { fi if (( depth <= DEBUG_LEVEL )); then local indent=">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" - echo "${indent:0:$depth} $(basename "${BASH_SOURCE[1]}"):${BASH_LINENO[0]}: - ${FUNCNAME[1]}(): ${BASH_COMMAND}" >&2 | true + local level=${indent:0:$depth} + local source=$(basename "${BASH_SOURCE[1]}") + local line=${BASH_LINENO[0]} + local function=${FUNCNAME[1]} + local command=${BASH_COMMAND} + echo "${level} ${source}:${line}: ${function}(): ${command}" >&2 | true fi }