|
| 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 |
0 commit comments