Skip to content

Commit 3ab6a37

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 fb0be66 commit 3ab6a37

File tree

7 files changed

+385
-0
lines changed

7 files changed

+385
-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 if any mandatory service is not failed 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**: All monitored services are present and not in failed state.
34+
- **FAIL**: List of failed or missing monitored services.
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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 specific services for failures
38+
check_failed_services() {
39+
log_info "----------------------------------------------------"
40+
log_info "-------- Starting $TESTNAME Functional Test --------"
41+
42+
# List of services to check
43+
services_to_check="android-tools-adbd.service NetworkManager.service pd-mapper.service"
44+
45+
# Initialize variables
46+
test_passed=true
47+
48+
# Check each service individually
49+
for service in $services_to_check; do
50+
# Check if service exists
51+
if ! systemctl list-unit-files "$service" --no-legend --no-pager | grep -q "$service"; then
52+
failed_or_missing_services="${failed_or_missing_services}${service} (missing)\n"
53+
test_passed=false
54+
continue
55+
fi
56+
57+
# Check if service is failed
58+
status=$(systemctl is-failed "$service" 2>/dev/null)
59+
if [ "$status" = "failed" ]; then
60+
failed_or_missing_services="${failed_or_missing_services}${service} (failed)\n"
61+
test_passed=false
62+
fi
63+
done
64+
65+
if $test_passed; then
66+
log_pass "All monitored services are present and not in failed state"
67+
echo "$TESTNAME PASS" > "$res_file"
68+
else
69+
log_fail "------ List of failed or missing monitored services --------"
70+
log_fail "$failed_or_missing_services"
71+
log_fail "--------------------------------------"
72+
echo "$TESTNAME FAIL" > "$res_file"
73+
fi
74+
log_info "----------------------------------------------------"
75+
log_info "-------- Stopping $TESTNAME Functional Test --------"
76+
}
77+
78+
# Call the functions
79+
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)