Skip to content

Commit cc45795

Browse files
committed
Test script to check functional usage of systemd.
Following check are implemented : systemdPID\run.sh Check systemd starts with PID 1. systemctlStartStop\run.sh Check if systemctl is able to start and stop a service. CheckFailedServices\run.sh Check for failed service on device using systemctl status. Usage Command Verified : ./run-test.sh systemPID ./run-test.sh systemctlStartStop ./run-test.sh CheckFailedServices Signed-off-by: Abhi Sinha <[email protected]>
1 parent 0d12ca5 commit cc45795

File tree

4 files changed

+208
-0
lines changed

4 files changed

+208
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# systemd Suite
2+
3+
This folder contains test scripts for validating `systemd` functionality on the platform. Particularly for **Qualcomm RB3Gen2** and platforms based on `meta-qcom` and `meta-qcom-distros`.
4+
5+
## Contents
6+
7+
- **directory/**: Each directory contains individual test script run.sh for specific `systemd` features.
8+
- **README.md**: This documentation file.
9+
10+
## Usage
11+
12+
1. Ensure all dependencies are installed as specified in the root documentation.
13+
2. Run the suite using run-test.sh in root directory Runner/:
14+
```
15+
./run-test.sh <directory-name>
16+
for e.g. ./run-test.sh systemdPID
17+
```
18+
3. Review the test results stored in file named <directory-name.res> in respective directory.
19+
20+
## Purpose
21+
22+
The `systemd` suite helps maintain reliability by ensuring that service management and related features work as expected on QCOM platforms.
23+
24+
These scripts focus on
25+
- Validate systemctl commands
26+
- Check failed services
27+
- Basic systemd validation
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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="checkFailedServices"
33+
test_path=$(find_test_case_by_name "$TESTNAME")
34+
cd "$test_path" || exit 1
35+
res_file="./$TESTNAME.res"
36+
37+
# Function to check for any failed services and print them
38+
check_failed_services() {
39+
log_info "----------------------------------------------------"
40+
log_info "-------- Starting $TESTNAME Functional Test --------"
41+
failed_services=$(systemctl --failed --no-legend --plain | awk '{print $1}')
42+
if [ -z "$failed_services" ]; then
43+
log_pass "No service is in failed state on device"
44+
echo "$TESTNAME PASS" >> "$res_file"
45+
else
46+
log_fail "------ List of failed services --------"
47+
log_fail "$failed_services"
48+
log_fail "--------------------------------------"
49+
echo "$TESTNAME FAIL" >> "$res_file"
50+
fi
51+
log_info "----------------------------------------------------"
52+
log_info "-------- Stopping $TESTNAME Functional Test --------"
53+
}
54+
55+
# Call the functions
56+
check_failed_services
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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="systemctlStartStop"
33+
test_path=$(find_test_case_by_name "$TESTNAME")
34+
cd "$test_path" || exit 1
35+
res_file="./$TESTNAME.res"
36+
37+
# Function to check if systemctl start command works for systemd-user-sessions.service
38+
check_systemctl_start_stop() {
39+
log_info "----------------------------------------------------"
40+
log_info "-------- Starting $TESTNAME Functional Test --------"
41+
log_info "-------- Stopping systemd-user-sessions.service --------"
42+
if ! systemctl is-active --quiet systemd-user-sessions.service; then
43+
log_info "Service is not active before proceeding with stop command"
44+
echo "$TESTNAME Fail" >> "$res_file"
45+
exit 1
46+
fi
47+
systemctl stop systemd-user-sessions.service
48+
sleep 5
49+
if systemctl is-active --quiet systemd-user-sessions.service; then
50+
log_fail "Failed to stop service systemd-user-sessions.service"
51+
echo "$TESTNAME FAIL" >> "$res_file"
52+
exit 1
53+
fi
54+
log_pass "Successfully stopped service systemd-user-sessions.service"
55+
log_info "-------- Starting systemd-user-sessions.service --------"
56+
systemctl start systemd-user-sessions.service
57+
sleep 5
58+
if systemctl is-active --quiet systemd-user-sessions.service; then
59+
log_pass "systemd-user-sessions.service started successfully with systemctl command"
60+
echo "$TESTNAME PASS" >> "$res_file"
61+
else
62+
log_fail "Failed to start systemd-user-sessions.service with systemctl start command"
63+
echo "$TESTNAME FAIL" >> "$res_file"
64+
fi
65+
log_info "----------------------------------------------------"
66+
log_info "-------- Stopping $TESTNAME Functional Test --------"
67+
}
68+
69+
70+
# Call the functions
71+
check_systemctl_start_stop
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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="systemdPID"
33+
test_path=$(find_test_case_by_name "$TESTNAME")
34+
cd "$test_path" || exit 1
35+
res_file="./$TESTNAME.res"
36+
37+
# Function to check if systemd is running with PID 1
38+
39+
check_systemd_pid() {
40+
log_info "----------------------------------------------------"
41+
log_info "-------- Starting $TESTNAME Functional Test --------"
42+
if [ "$(ps -p 1 -o comm=)" = "systemd" ]; then
43+
log_pass "Systemd init started with PID 1"
44+
echo "$TESTNAME PASS" >> "$res_file"
45+
else
46+
log_fail "Systemd init did not start with PID 1"
47+
echo "$TESTNAME FAIL" >> "$res_file"
48+
fi
49+
log_info "----------------------------------------------------"
50+
log_info "-------- Stopping $TESTNAME Functional Test --------"
51+
}
52+
53+
# Call the functions
54+
check_systemd_pid

0 commit comments

Comments
 (0)