From: Frantisek Sumsal Date: Mon, 20 Nov 2023 22:34:09 +0000 (+0100) Subject: test: clean up the save_journal() stuff a bit X-Git-Tag: v255~69^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09bdb9f121f0097461dba40d1689087fc3112462;p=platform%2Fupstream%2Fsystemd.git 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). --- diff --git a/test/test-functions b/test/test-functions index dfe4b8e..674ba1c 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() {