Skip to content

Commit 6bbb509

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 cb65b42 commit 6bbb509

File tree

1 file changed

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

1 file changed

+130
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
37+
ANY_SUBTEST_FAILED="false"
38+
39+
update_test_pass(){
40+
subtestname=$1
41+
msg=$2
42+
echo "$subtestname PASS" >> "$res_file"
43+
log_pass "$msg"
44+
}
45+
46+
update_test_fail(){
47+
subtestname=$1
48+
msg=$2
49+
echo "$subtestname FAIL" >> "$res_file"
50+
log_fail "$msg"
51+
ANY_SUBTEST_FAILED="true"
52+
}
53+
54+
# Function to check if systemd is running with PID 1
55+
56+
check_systemd_pid() {
57+
SUBTESTNAME="CheckSystemdPID"
58+
log_info "----------------------------------------------------"
59+
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
60+
if [ "$(ps -p 1 -o comm=)" = "systemd" ]; then
61+
update_test_pass "$SUBTESTNAME" "Systemd init started with PID 1"
62+
else
63+
update_test_fail "$SUBTESTNAME" "Systemd init did not start with PID 1"
64+
fi
65+
log_info "----------------------------------------------------"
66+
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
67+
}
68+
69+
# Function to check if systemctl stop command works for systemd-user-sessions.service
70+
71+
check_systemctl_stop() {
72+
SUBTESTNAME="CheckSystemctlStop"
73+
log_info "----------------------------------------------------"
74+
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
75+
systemctl stop systemd-user-sessions.service
76+
sleep 5
77+
if systemctl is-active --quiet systemd-user-sessions.service; then
78+
update_test_fail "$SUBTESTNAME" "Not able to stop the service systemd-user-sessions with systemctl"
79+
else
80+
update_test_pass "$SUBTESTNAME" "Able to stop the service systemd-user-sessions with systemctl"
81+
fi
82+
log_info "----------------------------------------------------"
83+
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
84+
}
85+
86+
# Function to check if systemctl start command works for systemd-user-sessions.service
87+
check_systemctl_start() {
88+
SUBTESTNAME="CheckSystemctlStart"
89+
log_info "----------------------------------------------------"
90+
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
91+
systemctl start systemd-user-sessions.service
92+
if systemctl is-active --quiet systemd-user-sessions.service; then
93+
update_test_pass "$SUBTESTNAME" "Service started successfully with systemctl command"
94+
else
95+
update_test_fail "$SUBTESTNAME" "Failed to start service with systemctl command"
96+
fi
97+
log_info "----------------------------------------------------"
98+
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
99+
}
100+
101+
# Function to check for any failed services and print them
102+
check_failed_services() {
103+
SUBTESTNAME="CheckFailedServices"
104+
log_info "----------------------------------------------------"
105+
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
106+
failed_services=$(systemctl --failed --no-legend --plain | awk '{print $1}')
107+
if [ -z "$failed_services" ]; then
108+
update_test_pass "$SUBTESTNAME" "No service is in failed state on device"
109+
else
110+
update_test_fail "$SUBTESTNAME" "------ List of failed services --------"
111+
log_fail $failed_services
112+
log_fail "--------------------------------------"
113+
fi
114+
log_info "----------------------------------------------------"
115+
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
116+
}
117+
118+
# Call the functions
119+
check_systemd_pid
120+
check_systemctl_stop
121+
check_systemctl_start
122+
check_failed_services
123+
124+
125+
if [ "$ANY_SUBTEST_FAILED" = "true" ]; then
126+
exit 1
127+
else
128+
exit 0
129+
fi
130+

0 commit comments

Comments
 (0)