Skip to content

Commit dbc44a0

Browse files
committed
Test script to check functional usage of systemd.
Following check are implemented : Check systemd starts with PID 1. Check if systemctl start and stop option is able to work for a service. Check for failed service on device using systemctl status. Script returns with exit code 1 if any of the subtest is failed. Usage Command Verified : ./run-test.sh systemd Signed-off-by: Abhishek Sinha <[email protected]>
1 parent 8e078f4 commit dbc44a0

File tree

1 file changed

+133
-0
lines changed
  • Runner/suites/Platform/systemd

1 file changed

+133
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/bin/sh
2+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3+
# SPDX-License-Identifier: BSD-3-Clause-Clear
4+
5+
# Robustly find and source init_env
6+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
INIT_ENV=""
8+
SEARCH="$SCRIPT_DIR"
9+
while [ "$SEARCH" != "/" ]; do
10+
if [ -f "$SEARCH/init_env" ]; then
11+
INIT_ENV="$SEARCH/init_env"
12+
break
13+
fi
14+
SEARCH=$(dirname "$SEARCH")
15+
done
16+
17+
if [ -z "$INIT_ENV" ]; then
18+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
19+
exit 1
20+
fi
21+
22+
# Only source if not already loaded (idempotent)
23+
if [ -z "$__INIT_ENV_LOADED" ]; then
24+
# shellcheck disable=SC1090
25+
. "$INIT_ENV"
26+
fi
27+
28+
# Always source functestlib.sh, using $TOOLS exported by init_env
29+
# shellcheck disable=SC1090,SC1091
30+
. "$TOOLS/functestlib.sh"
31+
32+
TESTNAME="systemd"
33+
test_path=$(find_test_case_by_name "$TESTNAME")
34+
cd "$test_path" || exit 1
35+
res_file="./$TESTNAME.res"
36+
subres_file="./${TESTNAME}_subresults"
37+
38+
ANY_SUBTEST_FAILED="false"
39+
40+
update_test_pass(){
41+
subtestname=$1
42+
msg=$2
43+
echo "$subtestname PASS" >> "$subres_file"
44+
log_pass "$msg"
45+
}
46+
47+
update_test_fail(){
48+
subtestname=$1
49+
msg=$2
50+
echo "$subtestname FAIL" >> "$subres_file"
51+
log_fail "$msg"
52+
ANY_SUBTEST_FAILED="true"
53+
}
54+
55+
# Function to check if systemd is running with PID 1
56+
57+
check_systemd_pid() {
58+
SUBTESTNAME="CheckSystemdPID"
59+
log_info "----------------------------------------------------"
60+
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
61+
if [ "$(ps -p 1 -o comm=)" = "systemd" ]; then
62+
update_test_pass "$SUBTESTNAME" "Systemd init started with PID 1"
63+
else
64+
update_test_fail "$SUBTESTNAME" "Systemd init did not start with PID 1"
65+
fi
66+
log_info "----------------------------------------------------"
67+
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
68+
}
69+
70+
# Function to check if systemctl stop command works for systemd-user-sessions.service
71+
72+
check_systemctl_stop() {
73+
SUBTESTNAME="CheckSystemctlStop"
74+
log_info "----------------------------------------------------"
75+
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
76+
systemctl stop systemd-user-sessions.service
77+
sleep 5
78+
if systemctl is-active --quiet systemd-user-sessions.service; then
79+
update_test_fail "$SUBTESTNAME" "Not able to stop the service systemd-user-sessions with systemctl"
80+
else
81+
update_test_pass "$SUBTESTNAME" "Able to stop the service systemd-user-sessions with systemctl"
82+
fi
83+
log_info "----------------------------------------------------"
84+
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
85+
}
86+
87+
# Function to check if systemctl start command works for systemd-user-sessions.service
88+
check_systemctl_start() {
89+
SUBTESTNAME="CheckSystemctlStart"
90+
log_info "----------------------------------------------------"
91+
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
92+
systemctl start systemd-user-sessions.service
93+
if systemctl is-active --quiet systemd-user-sessions.service; then
94+
update_test_pass "$SUBTESTNAME" "Service started successfully with systemctl command"
95+
else
96+
update_test_fail "$SUBTESTNAME" "Failed to start service with systemctl command"
97+
fi
98+
log_info "----------------------------------------------------"
99+
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
100+
}
101+
102+
# Function to check for any failed services and print them
103+
check_failed_services() {
104+
SUBTESTNAME="CheckFailedServices"
105+
log_info "----------------------------------------------------"
106+
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
107+
failed_services=$(systemctl --failed --no-legend --plain | awk '{print $1}')
108+
if [ -z "$failed_services" ]; then
109+
update_test_pass "$SUBTESTNAME" "No service is in failed state on device"
110+
else
111+
update_test_fail "$SUBTESTNAME" "------ List of failed services --------"
112+
log_fail "$failed_services"
113+
log_fail "--------------------------------------"
114+
fi
115+
log_info "----------------------------------------------------"
116+
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
117+
}
118+
119+
# Call the functions
120+
check_systemd_pid
121+
check_systemctl_stop
122+
check_systemctl_start
123+
check_failed_services
124+
125+
126+
if [ "$ANY_SUBTEST_FAILED" = "true" ]; then
127+
echo "$TESTNAME FAIL" > "$res_file"
128+
exit 1
129+
else
130+
echo "$TESTNAME PASS" > "$res_file"
131+
exit 0
132+
fi
133+

0 commit comments

Comments
 (0)