Skip to content

Commit 7752308

Browse files
committed
Added init_env file for host-tools folder, run-test.sh file for running tests similar to runner if more tests are added in future and modified the readme file
Signed-off-by: Nitin Nakka <nitinn@qti.qualcomm.com>
1 parent 44270f5 commit 7752308

3 files changed

Lines changed: 330 additions & 8 deletions

File tree

host-tools/SuspendResume/README.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,52 @@ This test case validates the system suspend/resume functionality on the target d
2222
- Complete qcom_stats and suspend_stats dumps
2323

2424
## Usage
25-
Instructions:
26-
1. **Copy repo to Host Machine**: Clone or download the repository to your host machine where ADB is installed.
27-
2. **Connect Device**: Ensure exactly **one** target device is connected via ADB and visible with `adb devices`.
28-
3. **Run Test**: Execute the test script which will remotely control the device via ADB.
2925

30-
Run the SuspendResume test using:
31-
---
26+
### Directory Structure
27+
This test is located in the `host-tools` directory structure:
28+
```
29+
qcom-linux-testkit/
30+
├── Runner/ # Main test framework
31+
│ ├── utils/ # Shared utilities (functestlib.sh, etc.)
32+
│ └── suites/ # Standard test suites
33+
└── host-tools/ # Host-based tests (ADB, remote control)
34+
├── init_env # Environment setup (finds Runner/utils)
35+
├── run-test.sh # Test orchestrator for host-tools tests
36+
└── SuspendResume/ # This test
37+
├── run.sh
38+
├── README.md
39+
└── SuspendResume.yaml
40+
```
41+
42+
### Running the Test
43+
44+
#### Method 1: Direct Execution (Recommended for LAVA)
45+
```sh
46+
cd host-tools/SuspendResume
47+
./run.sh
48+
```
49+
50+
#### Method 2: Using Test Orchestrator
51+
```sh
52+
cd host-tools
53+
./run-test.sh SuspendResume
54+
```
55+
56+
#### Method 3: Run All Host-Tools Tests
57+
```sh
58+
cd host-tools
59+
./run-test.sh all
60+
```
3261

33-
#### Quick Example
62+
### Quick Example
3463
```sh
3564
git clone <this-repo>
3665
cd <this-repo>
3766

3867
# Ensure exactly one device is connected
3968
adb devices
4069

41-
# Run the test from the new location
70+
# Run the test
4271
cd host-tools/SuspendResume
4372
./run.sh
4473
```

host-tools/init_env

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause-Clear
5+
6+
# Idempotency guard: only initialize ONCE per shell session
7+
[ -n "$__INIT_ENV_LOADED" ] && return
8+
__INIT_ENV_LOADED=1
9+
10+
# (Optional) Remove/comment log line below to keep CI logs clean:
11+
# echo "[INFO] init_env loaded."
12+
13+
# --- Robust root detection ---
14+
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)"
21+
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
37+
fi
38+
fi
39+
40+
# --- Validate and export key environment paths ---
41+
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
43+
exit 1
44+
fi
45+
46+
export ROOT_DIR
47+
export TOOLS="$ROOT_DIR/utils"
48+
export __RUNNER_SUITES_DIR="$ROOT_DIR/suites"
49+
export __RUNNER_UTILS_BIN_DIR="$ROOT_DIR/common"
50+
51+
# --- Ensure TOOLS is usable in all shells ---
52+
case ":$PATH:" in
53+
*":$TOOLS:"*) : ;;
54+
*)
55+
PATH="$TOOLS:$PATH"
56+
export PATH
57+
;;
58+
esac
59+
60+
# --- Source functestlib.sh to make functions available ---
61+
# Note: functestlib.sh must be sourced for run-test.sh to work properly
62+
if [ -f "$TOOLS/functestlib.sh" ]; then
63+
# shellcheck disable=SC1090,SC1091
64+
. "$TOOLS/functestlib.sh"
65+
fi
66+
67+
###############################################################################
68+
# Stdout/stderr capture (per-test folder)
69+
#
70+
# Controls (set BEFORE sourcing this file):
71+
# RUN_STDOUT_ENABLE = 1 | 0 (default: 1)
72+
# RUN_STDOUT_TAG = <string> (default: basename of $PWD)
73+
# RUN_STDOUT_FILE = <path> (default: $PWD/<tag>_stdout_<ts>.log)
74+
#
75+
# Behavior:
76+
# - Writes the capture file into the CURRENT DIRECTORY (usually the test dir).
77+
# - No global logs/stdout directory is created/used.
78+
###############################################################################
79+
_runner_stdout_cleanup() {
80+
st=$?
81+
# restore original fds (if they were saved)
82+
exec 1>&3 2>&4
83+
if [ -n "${__TEE_PID:-}" ]; then
84+
kill "$__TEE_PID" 2>/dev/null
85+
fi
86+
if [ -n "${PIPE:-}" ]; then
87+
rm -f "$PIPE" 2>/dev/null
88+
fi
89+
exit "$st"
90+
}
91+
92+
if [ "${RUN_STDOUT_ENABLE:-1}" -eq 1 ] && [ -z "${__RUN_STDOUT_ACTIVE:-}" ]; then
93+
_tag="${RUN_STDOUT_TAG:-$(basename "$(pwd)")}"
94+
_ts="$(date +%Y%m%d-%H%M%S)"
95+
RUN_STDOUT_FILE="${RUN_STDOUT_FILE:-$(pwd)/${_tag}_stdout_${_ts}.log}"
96+
export RUN_STDOUT_FILE
97+
98+
# Save original stdout/stderr
99+
exec 3>&1 4>&2
100+
101+
if command -v tee >/dev/null 2>&1; then
102+
PIPE="$(mktemp -u "/tmp/stdout_pipe.XXXXXX")"
103+
if mkfifo "$PIPE" 2>/dev/null; then
104+
( tee -a "$RUN_STDOUT_FILE" >&3 ) < "$PIPE" &
105+
__TEE_PID=$!
106+
exec > "$PIPE" 2>&1
107+
__RUN_STDOUT_ACTIVE=1
108+
trap _runner_stdout_cleanup EXIT INT TERM
109+
else
110+
# Fallback: file-only capture
111+
exec >> "$RUN_STDOUT_FILE" 2>&1
112+
__RUN_STDOUT_ACTIVE=1
113+
trap _runner_stdout_cleanup EXIT INT TERM
114+
fi
115+
else
116+
# Fallback: file-only capture
117+
exec >> "$RUN_STDOUT_FILE" 2>&1
118+
__RUN_STDOUT_ACTIVE=1
119+
trap _runner_stdout_cleanup EXIT INT TERM
120+
fi
121+
fi

host-tools/run-test.sh

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause-Clear
5+
6+
# Resolve the real path of this script
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8+
9+
# Disable wrapper-level capture; each test will capture in its own folder
10+
export RUN_STDOUT_ENABLE=0
11+
unset RUN_STDOUT_TAG RUN_STDOUT_FILE
12+
13+
# Safely source init_env from the same directory as this script
14+
# init_env will set TOOLS, ROOT_DIR, __RUNNER_SUITES_DIR, etc.
15+
if [ -f "$SCRIPT_DIR/init_env" ]; then
16+
# shellcheck source=/dev/null
17+
. "$SCRIPT_DIR/init_env"
18+
else
19+
echo "[ERROR] init_env not found at $SCRIPT_DIR/init_env"
20+
exit 1
21+
fi
22+
23+
# Verify that init_env set up the environment correctly
24+
if [ -z "$TOOLS" ] || [ ! -f "$TOOLS/functestlib.sh" ]; then
25+
echo "[ERROR] functestlib.sh not found at $TOOLS/functestlib.sh"
26+
echo "[ERROR] init_env may not have set up the environment correctly"
27+
exit 1
28+
fi
29+
30+
# Export key vars so they are visible to child scripts like ./run.sh
31+
export ROOT_DIR
32+
export TOOLS
33+
export __RUNNER_SUITES_DIR
34+
export __RUNNER_UTILS_BIN_DIR
35+
36+
# Set host-tools specific suites directory
37+
HOST_TOOLS_DIR="$SCRIPT_DIR"
38+
export HOST_TOOLS_DIR
39+
40+
# Store results
41+
RESULTS_PASS=""
42+
RESULTS_FAIL=""
43+
RESULTS_SKIP=""
44+
45+
execute_test_case() {
46+
test_path=$1
47+
shift
48+
49+
test_name=$(basename "$test_path")
50+
51+
if [ -d "$test_path" ]; then
52+
run_script="$test_path/run.sh"
53+
if [ -f "$run_script" ]; then
54+
log "Executing test case: $test_name"
55+
(
56+
cd "$test_path" || exit 2
57+
# Enable per-test capture in the test folder with a clear tag
58+
RUN_STDOUT_ENABLE=1 RUN_STDOUT_TAG="$test_name" sh "./run.sh" "$@"
59+
)
60+
res_file="$test_path/$test_name.res"
61+
if [ -f "$res_file" ]; then
62+
if grep -q "SKIP" "$res_file"; then
63+
log_skip "$test_name skipped"
64+
if [ -z "$RESULTS_SKIP" ]; then
65+
RESULTS_SKIP="$test_name"
66+
else
67+
RESULTS_SKIP=$(printf "%s\n%s" "$RESULTS_SKIP" "$test_name")
68+
fi
69+
elif grep -q "PASS" "$res_file"; then
70+
log_pass "$test_name passed"
71+
if [ -z "$RESULTS_PASS" ]; then
72+
RESULTS_PASS="$test_name"
73+
else
74+
RESULTS_PASS=$(printf "%s\n%s" "$RESULTS_PASS" "$test_name")
75+
fi
76+
elif grep -q "FAIL" "$res_file"; then
77+
log_fail "$test_name failed"
78+
if [ -z "$RESULTS_FAIL" ]; then
79+
RESULTS_FAIL="$test_name"
80+
else
81+
RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name")
82+
fi
83+
else
84+
log_fail "$test_name: unknown result in .res file"
85+
RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (unknown result)")
86+
fi
87+
else
88+
log_fail "$test_name: .res file not found"
89+
RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (.res not found)")
90+
fi
91+
else
92+
log_error "No run.sh found in $test_path"
93+
RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (missing run.sh)")
94+
fi
95+
else
96+
log_error "Test case directory not found: $test_path"
97+
RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (directory not found)")
98+
fi
99+
}
100+
101+
run_specific_test_by_name() {
102+
test_name=$1
103+
shift
104+
test_path=$(find_test_case_by_name "$test_name")
105+
if [ -z "$test_path" ]; then
106+
log_error "Test case with name $test_name not found."
107+
RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (not found)")
108+
else
109+
execute_test_case "$test_path" "$@"
110+
fi
111+
}
112+
113+
run_all_tests() {
114+
# Search for tests in host-tools directory (not Runner/suites)
115+
find "${HOST_TOOLS_DIR}" -maxdepth 2 -type d -name '[A-Za-z]*' | while IFS= read -r test_dir; do
116+
# Skip the host-tools directory itself
117+
if [ "$test_dir" = "$HOST_TOOLS_DIR" ]; then
118+
continue
119+
fi
120+
if [ -f "$test_dir/run.sh" ]; then
121+
execute_test_case "$test_dir"
122+
fi
123+
done
124+
}
125+
126+
print_summary() {
127+
echo
128+
log_info "========== Test Summary =========="
129+
echo "PASSED:"
130+
[ -n "$RESULTS_PASS" ] && printf "%s\n" "$RESULTS_PASS" || echo " None"
131+
echo
132+
echo "FAILED:"
133+
[ -n "$RESULTS_FAIL" ] && printf "%s\n" "$RESULTS_FAIL" || echo " None"
134+
echo
135+
echo "SKIPPED:"
136+
[ -n "$RESULTS_SKIP" ] && printf "%s\n" "$RESULTS_SKIP" || echo " None"
137+
log_info "=================================="
138+
}
139+
140+
print_usage() {
141+
cat >&2 <<EOF
142+
Usage:
143+
"${0##*/}" all
144+
"${0##*/}" <testcase_name> [arg1 arg2 ...]
145+
146+
Notes:
147+
- Extra args are forwarded only when a single <testcase_name> is specified.
148+
- 'all' runs every test and does not accept additional args.
149+
- Each test captures stdout/stderr next to its .res file as:
150+
<testname>_stdout_<timestamp>.log
151+
EOF
152+
}
153+
154+
if [ "$#" -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
155+
print_usage
156+
if [ "$#" -eq 0 ]; then
157+
log_error "No arguments provided"
158+
exit 1
159+
else
160+
exit 0
161+
fi
162+
fi
163+
164+
if [ "$1" = "all" ]; then
165+
run_all_tests
166+
else
167+
test_case_name="$1"
168+
shift
169+
run_specific_test_by_name "$test_case_name" "$@"
170+
fi
171+
172+
print_summary

0 commit comments

Comments
 (0)