Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
metadata:
name: logging-journalctl-validation
format: "Lava-Test Test Definition 1.0"
description: "Validate systemd-journald, journalctl access, and log propagation into /var/log on Qualcomm Linux platforms."
os:
- linux
scope:
- functional

params:
RETRY_COUNT: 5
RETRY_SLEEP_SECS: 1

run:
steps:
- REPO_PATH=$PWD
- cd Runner/suites/System/Logging/Logging_Journalctl_Validation/ || true
- RETRY_COUNT="${RETRY_COUNT}" RETRY_SLEEP_SECS="${RETRY_SLEEP_SECS}" ./run.sh || true
- $REPO_PATH/Runner/utils/send-to-lava.sh Logging_Journalctl_Validation.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# Logging_Journalctl_Validation

## Overview

`Logging_Journalctl_Validation` verifies that the system logging pipeline is working correctly after boot.

The testcase checks that:

- required logging tools are available
- `systemd-journald.service` is active
- a readable log sink exists under `/var/log`
- a custom test message can be written using `logger`
- the same test message can be retrieved using `journalctl`
- the same test message is also present in the selected `/var/log` file

This testcase is intended to validate journald and file-based logging behavior on the target system.

---

## Validation Scope

The testcase covers the following:

1. **Tool availability**
- `journalctl`
- `systemctl`
- `logger`
- `grep`
- `sed`
- `awk`
- `tail`

2. **Journald service validation**
- verifies that `systemd-journald.service` is active

3. **Log file detection**
- checks for a readable log sink under `/var/log`
- supported files include:
- `/var/log/messages`
- `/var/log/syslog`
- `/var/log/user.log`
- `/var/log/daemon.log`
- `/var/log/kern.log`

4. **Custom message injection**
- creates a unique test token
- emits the message using `logger`

5. **Journal verification**
- verifies that the emitted message is visible through `journalctl`

6. **File log verification**
- verifies that the emitted message is present in the detected log file

---

## Prerequisites

Before running the testcase, ensure that:

- the target has booted successfully
- `systemd-journald.service` is available on the target
- `logger` is available
- `journalctl` is available
- at least one readable log file exists under `/var/log`

---

## Test Location

```text
Runner/suites/System/Logging/Logging_Journalctl_Validation/
```

---

## Files

Typical contents of this testcase directory:

```text
run.sh
Logging_Journalctl_Validation.yaml
README.md
```

---

## How to Run

Run the testcase directly:

```sh
cd Runner/suites/System/Logging/Logging_Journalctl_Validation
chmod +x run.sh
./run.sh
```

---

## Optional Environment Variables

The testcase supports the following optional variables:

- `RETRY_COUNT`
- number of retries used while searching for the injected message
- default: `5`

- `RETRY_SLEEP_SECS`
- delay in seconds between retries
- default: `1`

Example:

```sh
RETRY_COUNT=10 RETRY_SLEEP_SECS=2 ./run.sh
```

---

## Expected Result

### PASS
The testcase passes when:

- required tools are present
- `systemd-journald.service` is active
- a readable `/var/log` file is detected
- the injected test message is found in `journalctl`
- the injected test message is found in the detected log file

### FAIL
The testcase fails when any of the following occurs:

- required tools are missing
- `systemd-journald.service` is not active
- no readable log file is found under `/var/log`
- the test message cannot be emitted
- the test message is not visible through `journalctl`
- the test message is not visible in the selected log file

### SKIP
The testcase is skipped when required runtime dependencies are not available.

---

## Result File

The testcase writes the result to:

```text
Logging_Journalctl_Validation.res
```

Possible values:

```text
Logging_Journalctl_Validation PASS
Logging_Journalctl_Validation FAIL
Logging_Journalctl_Validation SKIP
```

The script is expected to write the result file even when the shell exit code remains `0` for CI/LAVA flow continuity.

---

## Notes

- This testcase does **not** require `/var/log/journal` to exist.
- This testcase is intended to work on systems that use file-based logging under `/var/log`.
- This testcase does **not** validate unrelated failed services.
- This testcase is focused only on journald visibility and log propagation.

---

## Example Checks Performed

Typical validation sequence:

1. detect logging tools
2. verify `systemd-journald.service`
3. identify active log file
4. emit unique test message
5. verify message in `journalctl`
6. verify message in `/var/log/*`

---
150 changes: 150 additions & 0 deletions Runner/suites/System/Logging/Logging_Journalctl_Validation/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#!/bin/sh
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause
#
# Logging / journalctl validation:
# - verifies required logging tools are available
# - verifies systemd-journald service is active
# - prints journald service status to stdout
# - detects an active /var/log sink file
# - prints available log files under /var/log
# - emits a custom test message through logger
# - verifies the message in journalctl and prints the matched line
# - verifies the message in the detected log file and prints the matched line
# - validates journal storage mode sanity
# - validates journal boot list sanity
# - validates unit-scoped journal queries
# - validates priority-based journal filtering
# - writes PASS/FAIL to .res and exits 0 so LAVA can continue

SCRIPT_DIR="$(
cd "$(dirname "$0")" || exit 1
pwd
)"
INIT_ENV=""
SEARCH="$SCRIPT_DIR"

while [ "$SEARCH" != "/" ]; do
if [ -f "$SEARCH/init_env" ]; then
INIT_ENV="$SEARCH/init_env"
break
fi
SEARCH=$(dirname "$SEARCH")
done

if [ -z "$INIT_ENV" ]; then
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
exit 1
fi

if [ -z "${__INIT_ENV_LOADED:-}" ]; then
# shellcheck disable=SC1090
. "$INIT_ENV"
fi

# shellcheck disable=SC1090,SC1091
. "$TOOLS/functestlib.sh"
# shellcheck disable=SC1090,SC1091
. "$TOOLS/lib_logger.sh"

TESTNAME="Logging_Journalctl_Validation"
RETRY_COUNT="${RETRY_COUNT:-5}"
RETRY_SLEEP_SECS="${RETRY_SLEEP_SECS:-1}"

test_path="$(find_test_case_by_name "$TESTNAME")"
if [ -n "$test_path" ]; then
cd "$test_path" || exit 1
else
cd "$SCRIPT_DIR" || exit 1
fi

RES_FILE="./$TESTNAME.res"
rm -f "$RES_FILE"

if ! CHECK_DEPS_NO_EXIT=1 check_dependencies journalctl systemctl logger grep sed awk tail; then
log_skip "$TESTNAME SKIP: missing dependencies"
echo "$TESTNAME SKIP" > "$RES_FILE"
exit 0
fi

log_info "--------------------------------------------------------------------------"
log_info "------------------- Starting $TESTNAME Testcase --------------------------"
log_info "Config, RETRY_COUNT=$RETRY_COUNT RETRY_SLEEP_SECS=$RETRY_SLEEP_SECS"

if command -v detect_platform >/dev/null 2>&1; then
detect_platform
fi

log_info "Platform Details: machine='${PLATFORM_MACHINE:-unknown}' target='${PLATFORM_TARGET:-unknown}' kernel='$(uname -r 2>/dev/null || echo unknown)' arch='$(uname -m 2>/dev/null || echo unknown)'"

log_info "----- systemd-journald service snapshot -----"
journald_state="$(systemctl is-active systemd-journald.service 2>/dev/null || echo unknown)"
log_info "Service: systemd-journald.service state=$journald_state"
systemctl status systemd-journald.service --no-pager --full 2>/dev/null | sed -n '1,12p' | while IFS= read -r line; do
[ -n "$line" ] && log_info "[journald-status] $line"
done
log_info "----- End systemd-journald service snapshot -----"

if ! check_systemd_services systemd-journald.service; then
log_fail "$TESTNAME : FAIL"
echo "$TESTNAME FAIL" > "$RES_FILE"
exit 0
fi

if ! logging_detect_log_file; then
log_fail "$TESTNAME : FAIL"
echo "$TESTNAME FAIL" > "$RES_FILE"
exit 0
fi

if ! logging_emit_test_message; then
log_fail "$TESTNAME : FAIL"
echo "$TESTNAME FAIL" > "$RES_FILE"
exit 0
fi

if ! logging_verify_test_message_in_journalctl "$RETRY_COUNT" "$RETRY_SLEEP_SECS"; then
log_fail "$TESTNAME : FAIL"
echo "$TESTNAME FAIL" > "$RES_FILE"
exit 0
fi

if ! logging_verify_test_message_in_log_file "$RETRY_COUNT" "$RETRY_SLEEP_SECS"; then
log_fail "$TESTNAME : FAIL"
echo "$TESTNAME FAIL" > "$RES_FILE"
exit 0
fi

if ! logging_check_journal_storage_mode; then
log_fail "$TESTNAME : FAIL"
echo "$TESTNAME FAIL" > "$RES_FILE"
exit 0
fi

if ! logging_check_boot_list_sanity; then
log_fail "$TESTNAME : FAIL"
echo "$TESTNAME FAIL" > "$RES_FILE"
exit 0
fi

if ! logging_check_unit_scoped_query systemd-journald.service; then
log_fail "$TESTNAME : FAIL"
echo "$TESTNAME FAIL" > "$RES_FILE"
exit 0
fi

if ! logging_emit_priority_test_message; then
log_fail "$TESTNAME : FAIL"
echo "$TESTNAME FAIL" > "$RES_FILE"
exit 0
fi

if ! logging_verify_priority_message_in_journalctl "$RETRY_COUNT" "$RETRY_SLEEP_SECS"; then
log_fail "$TESTNAME : FAIL"
echo "$TESTNAME FAIL" > "$RES_FILE"
exit 0
fi

log_pass "$TESTNAME : PASS"
echo "$TESTNAME PASS" > "$RES_FILE"
exit 0
Loading
Loading