Skip to content

Commit a3a05fe

Browse files
committed
Update suspend/resume scripts, init env, and add utils similar like runner to run independently.
Signed-off-by: Nitin Nakka <nitinn@qti.qualcomm.com>
1 parent 8a6ac9b commit a3a05fe

3 files changed

Lines changed: 4533 additions & 33 deletions

File tree

host-tools/SuspendResume/run.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@ if [ -z "$__INIT_ENV_LOADED" ]; then
2525
# shellcheck disable=SC1090
2626
. "$INIT_ENV"
2727
fi
28-
# Always source functestlib.sh, using $TOOLS exported by init_env
29-
# shellcheck disable=SC1090,SC1091
30-
. "$TOOLS/functestlib.sh"
3128

3229
TESTNAME="SuspendResume"
33-
test_path=$(find_test_case_by_name "$TESTNAME")
34-
cd "$test_path" || exit 1
3530
# shellcheck disable=SC2034
3631
res_file="./$TESTNAME.res"
3732

host-tools/init_env

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,45 @@
77
[ -n "$__INIT_ENV_LOADED" ] && return
88
__INIT_ENV_LOADED=1
99

10-
# (Optional) Remove/comment log line below to keep CI logs clean:
11-
# echo "[INFO] init_env loaded."
12-
13-
# --- Robust root detection ---
10+
# --- Robust root detection for host-tools ---
1411
if [ -z "$ROOT_DIR" ]; then
15-
# Fast path: current working directory is root
16-
if [ -d "./utils" ] && [ -d "./suites" ]; then
17-
ROOT_DIR="$(pwd)"
18-
# Check if we're in host-tools and Runner exists as sibling
19-
elif [ -d "../Runner/utils" ] && [ -d "../Runner/suites" ]; then
20-
ROOT_DIR="$(cd ../Runner && pwd)"
12+
# When sourced, we need to find the directory containing this init_env file
13+
# Try multiple methods to get the script location
14+
if [ -n "${BASH_SOURCE:-}" ]; then
15+
# Bash
16+
_script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17+
elif [ -n "${ZSH_VERSION:-}" ]; then
18+
# Zsh
19+
_script_dir="$(cd "$(dirname "${(%):-%x}")" && pwd)"
20+
else
21+
# POSIX fallback: assume init_env is in a known location relative to caller
22+
# The caller (run.sh) sets INIT_ENV variable before sourcing
23+
if [ -n "${INIT_ENV:-}" ]; then
24+
_script_dir="$(cd "$(dirname "$INIT_ENV")" && pwd)"
25+
else
26+
_script_dir="$(cd "$(dirname "$0")" && pwd)"
27+
fi
28+
fi
29+
30+
# For host-tools, ROOT_DIR is the host-tools directory itself
31+
if [ -d "$_script_dir/utils" ] && [ -f "$_script_dir/utils/functestlib.sh" ]; then
32+
ROOT_DIR="$_script_dir"
2133
else
22-
# Fallback: walk up from this script's location
23-
_script_dir="$(cd "$(dirname "$0")" && pwd)"
24-
_search="$_script_dir"
25-
while [ "$_search" != "/" ]; do
26-
if [ -d "$_search/utils" ] && [ -d "$_search/suites" ]; then
27-
ROOT_DIR="$_search"
28-
break
29-
fi
30-
# Also check for Runner subdirectory
31-
if [ -d "$_search/Runner/utils" ] && [ -d "$_search/Runner/suites" ]; then
32-
ROOT_DIR="$_search/Runner"
33-
break
34-
fi
35-
_search=$(dirname "$_search")
36-
done
34+
echo "[ERROR] Could not detect host-tools root (missing utils/ or functestlib.sh)" >&2
35+
echo "[DEBUG] Tried _script_dir=$_script_dir" >&2
36+
exit 1
3737
fi
3838
fi
3939

4040
# --- Validate and export key environment paths ---
4141
if [ -z "${ROOT_DIR:-}" ] || [ ! -d "$ROOT_DIR/utils" ] || [ ! -f "$ROOT_DIR/utils/functestlib.sh" ]; then
42-
echo "[ERROR] Could not detect testkit root (missing utils/ or functestlib.sh)" >&2
42+
echo "[ERROR] Could not detect host-tools root (missing utils/ or functestlib.sh)" >&2
4343
exit 1
4444
fi
4545

4646
export ROOT_DIR
4747
export TOOLS="$ROOT_DIR/utils"
48-
export __RUNNER_SUITES_DIR="$ROOT_DIR/suites"
48+
export __RUNNER_SUITES_DIR="$ROOT_DIR"
4949
export __RUNNER_UTILS_BIN_DIR="$ROOT_DIR/common"
5050

5151
# --- Ensure TOOLS is usable in all shells ---
@@ -58,7 +58,6 @@ case ":$PATH:" in
5858
esac
5959

6060
# --- Source functestlib.sh to make functions available ---
61-
# Note: functestlib.sh must be sourced for run-test.sh to work properly
6261
if [ -f "$TOOLS/functestlib.sh" ]; then
6362
# shellcheck disable=SC1090,SC1091
6463
. "$TOOLS/functestlib.sh"

0 commit comments

Comments
 (0)