summaryrefslogtreecommitdiffstats
path: root/test/test-functions
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2023-11-20 23:34:09 +0100
committerFrantisek Sumsal <frantisek@sumsal.cz>2023-11-24 11:51:27 +0100
commit09bdb9f121f0097461dba40d1689087fc3112462 (patch)
treef015c7e8f17b5558f97b528645a7825859780172 /test/test-functions
parentMerge pull request #30172 from yuwata/analyze-verify-unit-path (diff)
downloadsystemd-09bdb9f121f0097461dba40d1689087fc3112462.tar.xz
systemd-09bdb9f121f0097461dba40d1689087fc3112462.zip
test: clean up the save_journal() stuff a bit
Let's save all journals from the test machine instead of calling export on each journal file separately, which makes the code less complicated (and probably faster).
Diffstat (limited to 'test/test-functions')
-rw-r--r--test/test-functions57
1 files changed, 31 insertions, 26 deletions
diff --git a/test/test-functions b/test/test-functions
index dfe4b8e24b..674ba1ce91 100644
--- a/test/test-functions
+++ b/test/test-functions
@@ -1765,48 +1765,53 @@ check_coverage_reports() {
}
save_journal() {
+ local source_dir="${1:?}"
+ local state="${2:?}"
# Default to always saving journal
local save="yes"
+ local dest_dir dest_name dest
- if [ "${TEST_SAVE_JOURNAL}" = "no" ]; then
+ if [[ "${TEST_SAVE_JOURNAL:-}" == "no" ]]; then
save="no"
- elif [ "${TEST_SAVE_JOURNAL}" = "fail" ] && [ "$2" = "0" ]; then
+ elif [[ "${TEST_SAVE_JOURNAL:-}" == "fail" && "$state" -eq 0 ]]; then
save="no"
fi
- if [ -n "${ARTIFACT_DIRECTORY}" ]; then
- dest="${ARTIFACT_DIRECTORY}/${testname:?}.journal"
+ if [[ -n "${ARTIFACT_DIRECTORY:-}" ]]; then
+ dest_dir="$ARTIFACT_DIRECTORY"
+ dest_name="${testname:?}.journal"
else
- dest="${TESTDIR:?}/system.journal"
+ dest_dir="${TESTDIR:?}"
+ dest_name="system.journal"
fi
- for j in "${1:?}"/*; do
- if get_bool "$save"; then
- if [ "$SYSTEMD_JOURNAL_REMOTE" = "" ]; then
- cp -a "$j" "$dest"
- else
- "$SYSTEMD_JOURNAL_REMOTE" -o "$dest" --getter="$JOURNALCTL -o export -D $j"
- fi
- fi
+ if [[ -n "$TEST_SHOW_JOURNAL" ]]; then
+ echo "---- $source_dir ----"
+ "$JOURNALCTL" --no-pager -o short-monotonic --no-hostname --priority="$TEST_SHOW_JOURNAL" -D "$source_dir"
+ fi
- if [ -n "${TEST_SHOW_JOURNAL}" ]; then
- echo "---- $j ----"
- "$JOURNALCTL" --no-pager -o short-monotonic --no-hostname --priority="${TEST_SHOW_JOURNAL}" -D "$j"
+ if get_bool "$save"; then
+ # If we don't have systemd-journal-remote copy all journals from /var/log/journal/
+ # to $dest_dir/journals/ as is, otherwise merge all journals into a single .journal
+ # file
+ if [[ -z "${SYSTEMD_JOURNAL_REMOTE:-}" ]]; then
+ dest="$dest_dir/journals"
+ mkdir -p "$dest"
+ cp -a "$source_dir/*" "$dest/"
+ else
+ dest="$dest_dir/$dest_name"
+ "$SYSTEMD_JOURNAL_REMOTE" -o "$dest" --getter="$JOURNALCTL -o export -D $source_dir"
fi
- rm -r "$j"
- done
-
- if ! get_bool "$save"; then
- return 0
- fi
+ if [[ -n "${SUDO_USER:-}" ]]; then
+ setfacl -R -m "user:$SUDO_USER:r-X" "$dest"
+ fi
- if [ -n "${SUDO_USER}" ]; then
- setfacl -m "user:${SUDO_USER:?}:r-X" "$dest"*
+ # we want to print this sometime later, so save this in a variable
+ JOURNAL_LIST="$(ls -lR "$dest")"
fi
- # we want to print this sometime later, so save this in a variable
- JOURNAL_LIST="$(ls -l "$dest"*)"
+ rm -rf "${source_dir:?}"/*
}
check_result_common() {