Skip to content

Commit c04548d

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: Abhishek Sinha <[email protected]>
1 parent 2ef8a98 commit c04548d

File tree

7 files changed

+362
-0
lines changed

7 files changed

+362
-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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# checkFailedServices Validation Test
2+
3+
## Overview
4+
5+
This test script checks for any failed systemd services on the device. It is intended for use on platforms running systemd and is part of the Qualcomm Linux Testkit.
6+
7+
## Usage
8+
9+
1. Ensure the testkit environment is set up and the board has systemd as init manager.
10+
2. Make the script executable if not already so:
11+
```sh
12+
chmod +x run.sh
13+
```
14+
3. Run the test:
15+
```sh
16+
./run.sh
17+
```
18+
4. Check the result:
19+
- If the test passes, `checkFailedServices.res` will contain `checkFailedServices PASS`.
20+
- If the test fails, `checkFailedServices.res` will contain `checkFailedServices FAIL` and the failed services will be logged.
21+
22+
## Integration
23+
24+
This test can be invoked by the top-level runner as:
25+
```sh
26+
cd Runner
27+
./run-test.sh checkFailedServices
28+
```
29+
The `.res` file can be parsed by CI/LAVA to determine the overall test status.
30+
31+
## Result Format
32+
33+
- **PASS**: No failed services detected.
34+
- **FAIL**: One or more services are in a failed state.
35+
36+
The result is written to `checkFailedServices.res` in the same directory.
37+
38+
## Dependencies
39+
40+
- **systemctl**: Must be available and functional (systemd-based system).
41+
- **POSIX shell**: Script is written for `/bin/sh`.
42+
43+
## Logging
44+
45+
- Uses `log_info`, `log_pass`, and `log_fail` from `functestlib.sh` for standardized output.
46+
47+
## License
48+
49+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
50+
SPDX-License-Identifier: BSD-3-Clause-Clear
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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# systemctlStartStop
2+
3+
## Overview
4+
5+
This script tests the ability to stop and start the `systemd-user-sessions.service` using `systemctl`. It is intended for use on platforms running systemd and is part of the Qualcomm Linux Testkit.
6+
7+
## How It Works
8+
9+
- The script robustly locates and sources the `init_env` environment setup file.
10+
- It sources `functestlib.sh` for logging and utility functions.
11+
- It checks if `systemd-user-sessions.service` is active.
12+
- It attempts to stop the service and verifies it is stopped.
13+
- It then starts the service again and verifies it is running.
14+
- Results are logged and written to `systemctlStartStop.res`.
15+
16+
## Usage
17+
18+
1. Ensure the testkit environment is set up and the board is running systemd.
19+
2. Make the script executable if not already so:
20+
```sh
21+
chmod +x run.sh
22+
```
23+
3. Run the test(requires sudo access):
24+
```sh
25+
./run.sh
26+
```
27+
4. Check the result in `systemctlStartStop.res`:
28+
- `systemctlStartStop PASS` if the service was stopped and started successfully.
29+
- `systemctlStartStop FAIL` if any step failed.
30+
31+
## Integration
32+
33+
This test can be invoked by the top-level runner as:
34+
```sh
35+
cd Runner
36+
./run-test.sh systemctlStartStop
37+
```
38+
The `.res` file will be parsed by CI/LAVA to determine the overall test status.
39+
40+
## Dependencies
41+
42+
- `systemctl` (systemd-based system)
43+
- POSIX shell (`/bin/sh`)
44+
- `init_env` and `functestlib.sh` from the testkit
45+
46+
## Logging
47+
48+
- Uses `log_info`, `log_pass`, and `log_fail` from `functestlib.sh` for standardized output.
49+
50+
## License
51+
52+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
53+
SPDX-License-Identifier: BSD-3-Clause-Clear
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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# systemdPID
2+
3+
## Overview
4+
5+
This script verifies that the `systemd` process is running as PID 1 on the device. It is intended for use on platforms running systemd and is part of the Qualcomm Linux Testkit.
6+
7+
## How It Works
8+
9+
- The script robustly locates and sources the `init_env` environment setup file.
10+
- It sources `functestlib.sh` for logging and utility functions.
11+
- It checks if the process with PID 1 is `systemd` using `ps`.
12+
- If `systemd` is PID 1, the test passes; otherwise, it fails.
13+
14+
## Usage
15+
16+
1. Ensure the testkit environment is set up and the board is having systemd as init manager.
17+
2. Make the script executable if not already so:
18+
```sh
19+
chmod +x run.sh
20+
```
21+
3. Run the test:
22+
```sh
23+
./run.sh
24+
```
25+
4. Check the result in `systemdPID.res`:
26+
- `systemdPID PASS` if `systemd` is PID 1.
27+
- `systemdPID FAIL` if not.
28+
29+
## Integration
30+
31+
This test can be invoked by the top-level runner as:
32+
```sh
33+
cd Runner
34+
./run-test.sh systemdPID
35+
```
36+
The `.res` file can be parsed by CI/LAVA to determine the overall test status.
37+
38+
## Dependencies
39+
40+
- `ps`
41+
- POSIX shell (`/bin/sh`)
42+
- `init_env` and `functestlib.sh` from the testkit
43+
44+
## Logging
45+
46+
- Uses `log_info`, `log_pass`, and `log_fail` from `functestlib.sh` for standardized output.
47+
48+
## License
49+
50+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
51+
SPDX-License-Identifier: BSD-3-Clause-Clear
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)