Skip to content

Commit 6cade03

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]> test script for systemd validation Signed-off-by: Abhishek Sinha <[email protected]> shell check failure addressed Signed-off-by: Abhishek Sinha <[email protected]> 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]> Removed usage of unused variable directory and bug in res_file variable name Signed-off-by: Abhishek Sinha <[email protected]> Update run.sh Fixed comments line Signed-off-by: Abhi Sinha <[email protected]> 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 386f5e4 commit 6cade03

File tree

1 file changed

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

1 file changed

+127
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
if systemctl is-active --quiet systemd-user-sessions.service; then
77+
update_test_fail "$SUBTESTNAME" "Not able to stop the service systemd-user-sessions with systemctl"
78+
else
79+
update_test_pass "$SUBTESTNAME" "Able to stop the service systemd-user-sessions with systemctl"
80+
fi
81+
log_info "----------------------------------------------------"
82+
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
83+
}
84+
85+
# Function to check if systemctl start command works for systemd-user-sessions.service
86+
check_systemctl_start() {
87+
SUBTESTNAME="CheckSystemctlStart"
88+
log_info "----------------------------------------------------"
89+
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
90+
systemctl start systemd-user-sessions.service
91+
if systemctl is-active --quiet systemd-user-sessions.service; then
92+
update_test_pass "$SUBTESTNAME" "Service started successfully with systemctl command"
93+
else
94+
update_test_fail "$SUBTESTNAME" "Failed to start service with systemctl command"
95+
fi
96+
log_info "----------------------------------------------------"
97+
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
98+
}
99+
100+
# Function to check for any failed services and print them
101+
check_failed_services() {
102+
SUBTESTNAME="CheckFailedServices"
103+
log_info "----------------------------------------------------"
104+
log_info "-------- Starting $SUBTESTNAME Functional Test --------"
105+
failed_services=$(systemctl --failed --no-legend --plain | awk '{print $1}')
106+
if [ -z "$failed_services" ]; then
107+
update_test_pass "$SUBTESTNAME" "No service is in failed state on device"
108+
else
109+
update_test_fail "$SUBTESTNAME" "------List of failed service--------\n$failed_services\n------------------------------------"
110+
fi
111+
log_info "----------------------------------------------------"
112+
log_info "-------- Stopping $SUBTESTNAME Functional Test --------"
113+
}
114+
115+
# Call the functions
116+
check_systemd_pid
117+
check_systemctl_stop
118+
check_systemctl_start
119+
check_failed_services
120+
121+
122+
if [ "$ANY_SUBTEST_FAILED" = "true" ]; then
123+
exit 1
124+
else
125+
exit 0
126+
fi
127+

0 commit comments

Comments
 (0)