Skip to content

test script for systemd validation #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
133 changes: 133 additions & 0 deletions Runner/suites/Platform/systemd/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/bin/sh
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause-Clear

# Robustly find and source init_env
SCRIPT_DIR="$(cd "$(dirname "$0")" && 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

# Only source if not already loaded (idempotent)
if [ -z "$__INIT_ENV_LOADED" ]; then
# shellcheck disable=SC1090
. "$INIT_ENV"
fi

# Always source functestlib.sh, using $TOOLS exported by init_env
# shellcheck disable=SC1090,SC1091
. "$TOOLS/functestlib.sh"

TESTNAME="systemd"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to change name of the test. As it is doing for process check here.

test_path=$(find_test_case_by_name "$TESTNAME")
cd "$test_path" || exit 1
res_file="./$TESTNAME.res"
subres_file="./${TESTNAME}_subresults"

ANY_SUBTEST_FAILED="false"

update_test_pass(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be moved to common functions

subtestname=$1
msg=$2
echo "$subtestname PASS" >> "$subres_file"
log_pass "$msg"
}

update_test_fail(){
subtestname=$1
msg=$2
echo "$subtestname FAIL" >> "$subres_file"
log_fail "$msg"
ANY_SUBTEST_FAILED="true"
}

# Function to check if systemd is running with PID 1

check_systemd_pid() {
SUBTESTNAME="CheckSystemdPID"
log_info "----------------------------------------------------"
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
if [ "$(ps -p 1 -o comm=)" = "systemd" ]; then
update_test_pass "$SUBTESTNAME" "Systemd init started with PID 1"
else
update_test_fail "$SUBTESTNAME" "Systemd init did not start with PID 1"
fi
log_info "----------------------------------------------------"
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
}

# Function to check if systemctl stop command works for systemd-user-sessions.service

check_systemctl_stop() {
SUBTESTNAME="CheckSystemctlStop"
log_info "----------------------------------------------------"
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
systemctl stop systemd-user-sessions.service
sleep 5
if systemctl is-active --quiet systemd-user-sessions.service; then
update_test_fail "$SUBTESTNAME" "Not able to stop the service systemd-user-sessions with systemctl"
else
update_test_pass "$SUBTESTNAME" "Able to stop the service systemd-user-sessions with systemctl"
fi
log_info "----------------------------------------------------"
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
}

# Function to check if systemctl start command works for systemd-user-sessions.service
check_systemctl_start() {
SUBTESTNAME="CheckSystemctlStart"
log_info "----------------------------------------------------"
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
systemctl start systemd-user-sessions.service
if systemctl is-active --quiet systemd-user-sessions.service; then
update_test_pass "$SUBTESTNAME" "Service started successfully with systemctl command"
else
update_test_fail "$SUBTESTNAME" "Failed to start service with systemctl command"
fi
log_info "----------------------------------------------------"
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
}

# Function to check for any failed services and print them
check_failed_services() {
SUBTESTNAME="CheckFailedServices"
log_info "----------------------------------------------------"
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
failed_services=$(systemctl --failed --no-legend --plain | awk '{print $1}')
if [ -z "$failed_services" ]; then
update_test_pass "$SUBTESTNAME" "No service is in failed state on device"
else
update_test_fail "$SUBTESTNAME" "------ List of failed services --------"
log_fail "$failed_services"
log_fail "--------------------------------------"
fi
log_info "----------------------------------------------------"
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
}

# Call the functions
check_systemd_pid
check_systemctl_stop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better move services check to different script. Any reason to club together?

check_systemctl_start
check_failed_services


if [ "$ANY_SUBTEST_FAILED" = "true" ]; then
echo "$TESTNAME FAIL" > "$res_file"
exit 1
else
echo "$TESTNAME PASS" > "$res_file"
exit 0
fi

Loading