Skip to content
Open
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
49 changes: 31 additions & 18 deletions tests/ffi/qm-oom-score-adj/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,27 @@ trap disk_cleanup EXIT
prepare_test
reload_config

# Function to inspect a container with optional exec into another container
podman_inspect() {
local outer_container=$1
local container_name=$2
local format_string=$3

if [[ -n "$outer_container" ]]; then
podman exec -it "$outer_container" /bin/bash -c "podman inspect $container_name --format '$format_string'" | tail -1 | tr -d '\r'
else
podman inspect "$container_name" --format "$format_string" | tail -1 | tr -d '\r'
fi
}

# Function to retrieve the PID with retries for a container
get_pid_with_retries() {
local container_name=$1
local retries=10
local pid=""

while [[ $retries -gt 0 ]]; do
pid=$(podman inspect "$container_name" --format '{{.State.Pid}}' | tr -d '\r')
pid=$(podman_inspect "" "$container_name" '{{.State.Pid}}')
if [[ -n "$pid" && "$pid" =~ ^[0-9]+$ ]]; then
echo "$pid"
return
Expand All @@ -36,7 +49,7 @@ get_pid_with_retries() {
sleep 1
done

echo "Error: Failed to retrieve a valid PID for the container '$container_name' after multiple attempts." >&2
info_message "Error: Failed to retrieve a valid PID for the container '$container_name' after multiple attempts." >&2
exit 1
}

Expand All @@ -45,9 +58,9 @@ get_oom_score_adj() {
local pid=$1

if [[ -f "/proc/$pid/oom_score_adj" ]]; then
tr -d '\r\n' < "/proc/$pid/oom_score_adj"
tail -1 < "/proc/$pid/oom_score_adj" | tr -d '\r\n'
else
echo "Error: /proc/$pid/oom_score_adj does not exist" >&2
info_message "Error: /proc/$pid/oom_score_adj does not exist" >&2
exit 1
fi
}
Expand All @@ -56,31 +69,31 @@ get_oom_score_adj() {
running_container_in_qm

# Check if ffi-qm container started successfully
QM_FFI_STATUS=$(podman exec -it qm /bin/bash -c "podman inspect ffi-qm --format '{{.State.Status}}'" | tr -d '\r')
QM_FFI_STATUS=$(podman_inspect "qm" "ffi-qm" '{{.State.Status}}')
if [[ "$QM_FFI_STATUS" != "running" ]]; then
echo "Error: ffi-qm container failed to start. Status: $QM_FFI_STATUS" >&2
info_message "Error: ffi-qm container failed to start. Status: $QM_FFI_STATUS" >&2
exit 1
fi

# Retrieve the PID of the outer container (qm) with retries
QM_PID=$(get_pid_with_retries "qm")

# Retrieve the PID of the inner container (ffi-qm) directly within the qm container
QM_FFI_PID=$(podman exec -it qm /bin/bash -c "podman inspect ffi-qm --format '{{.State.Pid}}'" | tr -d '\r')
QM_FFI_PID=$(podman_inspect "qm" "ffi-qm" '{{.State.Pid}}')

# Debugging: Output the retrieved PIDs
echo "Retrieved QM_PID: $QM_PID"
echo "Retrieved QM_FFI_PID: $QM_FFI_PID"
info_message "Retrieved QM_PID: $QM_PID"
info_message "Retrieved QM_FFI_PID: $QM_FFI_PID"

# Ensure that PIDs are valid before proceeding
if [[ -z "$QM_PID" || ! "$QM_PID" =~ ^[0-9]+$ ]]; then
echo "Error: Invalid QM_PID: $QM_PID" >&2
info_message "Error: Invalid QM_PID: $QM_PID" >&2
exit 1
fi

if [[ -z "$QM_FFI_PID" || ! "$QM_FFI_PID" =~ ^[0-9]+$ ]]; then
echo "Error: Invalid QM_FFI_PID: $QM_FFI_PID" >&2
echo "Check if the ffi-qm container was successfully started."
info_message "Error: Invalid QM_FFI_PID: $QM_FFI_PID" >&2
info_message "Check if the ffi-qm container was successfully started."
exit 1
fi

Expand All @@ -89,26 +102,26 @@ QM_OOM_SCORE_ADJ=$(get_oom_score_adj "$QM_PID")
QM_FFI_OOM_SCORE_ADJ=$(podman exec -it qm /bin/bash -c "cat /proc/$QM_FFI_PID/oom_score_adj" | tr -d '\r\n')

# Debugging: Output the retrieved oom_score_adj values
echo "Retrieved QM_OOM_SCORE_ADJ: '$QM_OOM_SCORE_ADJ'"
echo "Retrieved QM_FFI_OOM_SCORE_ADJ: '$QM_FFI_OOM_SCORE_ADJ'"
info_message "Retrieved QM_OOM_SCORE_ADJ: '$QM_OOM_SCORE_ADJ'"
info_message "Retrieved QM_FFI_OOM_SCORE_ADJ: '$QM_FFI_OOM_SCORE_ADJ'"

# Define the expected oom_score_adj values
OOM_SCORE_ADJ_EXPECTED=500
FFI_OOM_SCORE_ADJ_EXPECTED=750

# Check the oom_score_adj for the outer container
if [[ "$QM_OOM_SCORE_ADJ" -eq "$OOM_SCORE_ADJ_EXPECTED" ]]; then
echo "PASS: qm.container oom_score_adj value == $OOM_SCORE_ADJ_EXPECTED"
info_message "PASS: qm.container oom_score_adj value == $OOM_SCORE_ADJ_EXPECTED"
else
echo "FAIL: qm.container oom_score_adj value != $OOM_SCORE_ADJ_EXPECTED. Current value is ${QM_OOM_SCORE_ADJ}"
info_message "FAIL: qm.container oom_score_adj value != $OOM_SCORE_ADJ_EXPECTED. Current value is ${QM_OOM_SCORE_ADJ}"
exit 1
fi

# Check the oom_score_adj for the inner container
if [[ "$QM_FFI_OOM_SCORE_ADJ" -eq "$FFI_OOM_SCORE_ADJ_EXPECTED" ]]; then
echo "PASS: ffi-qm container oom_score_adj == $FFI_OOM_SCORE_ADJ_EXPECTED"
info_message "PASS: ffi-qm container oom_score_adj == $FFI_OOM_SCORE_ADJ_EXPECTED"
else
echo "FAIL: ffi-qm container oom_score_adj != $FFI_OOM_SCORE_ADJ_EXPECTED. Current value is '${QM_FFI_OOM_SCORE_ADJ}'"
info_message "FAIL: ffi-qm container oom_score_adj != $FFI_OOM_SCORE_ADJ_EXPECTED. Current value is '${QM_FFI_OOM_SCORE_ADJ}'"
exit 1
fi

Expand Down