Skip to content

Commit 137f7dd

Browse files
committed
test: refactor run.sh to use common functestlib.sh functions
- Integrated log_info, log_pass, log_fail, log_error, and check_dependencies - Ensured compatibility with both standalone and run-test.sh execution - Improved maintainability and consistency across test suites Signed-off-by: Srikanth Muppandam <[email protected]>
1 parent 2d02349 commit 137f7dd

File tree

3 files changed

+121
-84
lines changed

3 files changed

+121
-84
lines changed

Runner/run-test.sh

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,87 @@
33
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
44
# SPDX-License-Identifier: BSD-3-Clause-Clear
55

6-
# Import test suite definitions
7-
. "${PWD}"/init_env
6+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
. "${SCRIPT_DIR}/../init_env"
88

9-
#import test functions library
10-
. "${TOOLS}"/functestlib.sh
9+
. "${TOOLS}/functestlib.sh"
1110

12-
13-
# Find test case path by name
14-
find_test_case_by_name() {
15-
# Check if the file is a directory
16-
if [ -d "$1" ]; then
17-
# Get the directory name
18-
dir_name_in_dir=${1##*/}
19-
20-
# Check if the directory name matches the user input
21-
if [ "${dir_name_in_dir}" = "$test_name" ]; then
22-
# Get the absolute path of the directory
23-
abs_path=$(readlink -f "$1")
24-
echo "$abs_path"
25-
fi
26-
fi
27-
28-
# Recursively search for the directory in the subdirectory
29-
for file in "$1"/*; do
30-
# Check if the file is a directory
31-
if [ -d "$file" ]; then
32-
# Recursively search for the directory in the subdirectory
33-
find_test_case_by_name "$file"
34-
fi
35-
done
36-
}
11+
# Store results
12+
RESULTS_PASS=""
13+
RESULTS_FAIL=""
3714

3815
# Execute a test case
3916
execute_test_case() {
4017
local test_path="$1"
18+
local test_name
19+
test_name=$(basename "$test_path")
20+
4121
if [ -d "$test_path" ]; then
4222
run_script="$test_path/run.sh"
4323
if [ -f "$run_script" ]; then
44-
log "Executing test case: $test_path"
45-
sh "$run_script" 2>&1
24+
log "Executing test case: $test_name"
25+
if (cd "$test_path" && sh "./run.sh"); then
26+
log_pass "$test_name passed"
27+
RESULTS_PASS="${RESULTS_PASS}\n$test_name"
28+
else
29+
log_fail "$test_name failed"
30+
RESULTS_FAIL="${RESULTS_FAIL}\n$test_name"
31+
fi
4632
else
47-
log "No run.sh found in $test_path"
33+
log_error "No run.sh found in $test_path"
34+
RESULTS_FAIL="${RESULTS_FAIL}\n$test_name (missing run.sh)"
4835
fi
4936
else
50-
log "Test case directory not found: $test_path"
37+
log_error "Test case directory not found: $test_path"
38+
RESULTS_FAIL="${RESULTS_FAIL}\n$test_name (directory not found)"
5139
fi
5240
}
5341

54-
# Function to run a specific test case by name
42+
# Run test by name
5543
run_specific_test_by_name() {
5644
test_name="$1"
57-
test_path=$(find_test_case_by_name ".")
45+
test_path=$(find_test_case_by_name "$test_name")
5846
if [ -z "$test_path" ]; then
59-
log "Test case with name $test_name not found."
47+
log_error "Test case with name $test_name not found."
48+
RESULTS_FAIL="${RESULTS_FAIL}\n$test_name (not found)"
6049
else
6150
execute_test_case "$test_path"
6251
fi
6352
}
6453

65-
# Main script logic
54+
# Run all test cases
55+
run_all_tests() {
56+
for test_dir in $(find "${__RUNNER_SUITES_DIR}" -type d -name '[A-Za-z]*' -maxdepth 3); do
57+
if [ -f "$test_dir/run.sh" ]; then
58+
execute_test_case "$test_dir"
59+
fi
60+
done
61+
}
62+
63+
# Print final summary
64+
print_summary() {
65+
echo
66+
log_info "========== Test Summary =========="
67+
echo "PASSED:"
68+
[ -n "$RESULTS_PASS" ] && echo -e "$RESULTS_PASS" || echo " None"
69+
70+
echo
71+
echo "FAILED:"
72+
[ -n "$RESULTS_FAIL" ] && echo -e "$RESULTS_FAIL" || echo " None"
73+
74+
log_info "=================================="
75+
}
76+
77+
# Main
6678
if [ "$#" -eq 0 ]; then
6779
log "Usage: $0 [all | <testcase_name>]"
6880
exit 1
6981
fi
7082

83+
if [ "$1" = "all" ]; then
84+
run_all_tests
85+
else
86+
run_specific_test_by_name "$1"
87+
fi
7188

72-
run_specific_test_by_name "$1"
89+
print_summary

Runner/suites/Kernel/FunctionalArea/baseport/CPUFreq_Validation/run.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
44
# SPDX-License-Identifier: BSD-3-Clause-Clear
55

6-
. "${PWD}/init_env"
6+
# Load environment and common functions
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8+
ROOT_DIR="$(cd "$SCRIPT_DIR/../../.." && pwd)"
9+
FUNCLIB="${ROOT_DIR}/Runner/utils/functestlib.sh"
10+
11+
if [ -f "$FUNCLIB" ]; then
12+
. "$FUNCLIB"
13+
else
14+
echo "Missing functestlib.sh at $FUNCLIB"
15+
exit 1
16+
fi
17+
718
TESTNAME="CPUFreq_Validation"
8-
. "$TOOLS/functestlib.sh"
919

1020
test_path=$(find_test_case_by_name "$TESTNAME")
1121
log_info "-----------------------------------------------------------------------------------------"

Runner/utils/functestlib.sh

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
11
#!/bin/sh
22

3-
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3+
# Copyright (c) Qualcomm Technologies, Inc.
44
# SPDX-License-Identifier: BSD-3-Clause-Clear
55

6-
# Import test suite definitions
7-
. "${PWD}"/init_env
8-
#import platform
9-
. "${TOOLS}"/platform.sh
6+
# Determine script directory to make paths relative
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8+
ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
109

11-
__RUNNER_SUITES_DIR="/var/Runner/suites"
12-
__RUNNER_UTILS_BIN_DIR="/var/common"
10+
# Optional: Load init_env if available
11+
INIT_ENV_PATH="${PWD}/init_env"
12+
if [ -f "$INIT_ENV_PATH" ]; then
13+
. "$INIT_ENV_PATH"
14+
else
15+
echo "[WARN] init_env not found at $INIT_ENV_PATH, continuing without it."
16+
fi
1317

14-
#This function used for test logging
18+
# Optional: Load platform.sh if available
19+
if [ -n "$TOOLS" ] && [ -f "${TOOLS}/platform.sh" ]; then
20+
. "${TOOLS}/platform.sh"
21+
fi
22+
23+
# Set common directories (fallback if init_env not sourced)
24+
__RUNNER_SUITES_DIR="${__RUNNER_SUITES_DIR:-${ROOT_DIR}/suites}"
25+
#__RUNNER_UTILS_BIN_DIR="${__RUNNER_UTILS_BIN_DIR:-${ROOT_DIR}/common}"
26+
27+
# Logging function
1528
log() {
1629
local level="$1"
1730
shift
18-
# echo "$(date '+%Y-%m-%d %H:%M:%S') - $message" | tee -a /var/test_framework.log
1931
echo "[$level] $(date '+%Y-%m-%d %H:%M:%S') - $*" | tee -a /var/test_output.log
2032
}
21-
# Find test case path by name
22-
find_test_case_by_name() {
23-
local test_name="$1"
24-
find $__RUNNER_SUITES_DIR -type d -iname "$test_name" 2>/dev/null
25-
}
26-
27-
# Find test case path by name
28-
find_test_case_bin_by_name() {
29-
local test_name="$1"
30-
find $__RUNNER_UTILS_BIN_DIR -type f -iname "$test_name" 2>/dev/null
31-
}
3233

33-
# Find test case path by name
34-
find_test_case_script_by_name() {
35-
local test_name="$1"
36-
find $__RUNNER_UTILS_BIN_DIR -type d -iname "$test_name" 2>/dev/null
37-
}
34+
# Logging levels
35+
log_info() { log "INFO" "$@"; }
36+
log_pass() { log "PASS" "$@"; }
37+
log_fail() { log "FAIL" "$@"; }
38+
log_error() { log "ERROR" "$@"; }
3839

40+
# Dependency check
3941
check_dependencies() {
4042
local missing=0
4143
for cmd in "$@"; do
42-
if ! command -v "$cmd" > /dev/null 2>&1; then
44+
if ! command -v "$cmd" >/dev/null 2>&1; then
4345
log_error "ERROR: Required command '$cmd' not found in PATH."
4446
missing=1
4547
fi
@@ -48,38 +50,46 @@ check_dependencies() {
4850
log_error "Exiting due to missing dependencies."
4951
exit 1
5052
else
51-
log_pass "Test related dependencies are present."
53+
log_pass "Test related dependencies are present."
5254
fi
5355
}
5456

55-
# Logging levels
56-
log_info() { log "INFO" "$@"; }
57-
log_pass() { log "PASS" "$@"; }
58-
log_fail() { log "FAIL" "$@"; }
59-
log_error() { log "ERROR" "$@"; }
57+
# Test case path search functions
58+
find_test_case_by_name() {
59+
local test_name="$1"
60+
find "$__RUNNER_SUITES_DIR" -type d -iname "$test_name" 2>/dev/null
61+
}
6062

63+
find_test_case_bin_by_name() {
64+
local test_name="$1"
65+
find "$__RUNNER_UTILS_BIN_DIR" -type f -iname "$test_name" 2>/dev/null
66+
}
67+
68+
find_test_case_script_by_name() {
69+
local test_name="$1"
70+
find "$__RUNNER_UTILS_BIN_DIR" -type d -iname "$test_name" 2>/dev/null
71+
}
6172

62-
## this doc fn comes last
73+
# Documentation printer
6374
FUNCTIONS="\
6475
log_info \
6576
log_pass \
6677
log_fail \
6778
log_error \
6879
find_test_case_by_name \
6980
find_test_case_bin_by_name \
70-
find_test_case_script_by_name \
81+
find_test_case_script_by_name \
7182
log \
7283
"
7384

74-
functestlibdoc()
75-
{
76-
echo "functestlib.sh"
77-
echo ""
78-
echo "Functions:"
79-
for fn in $FUNCTIONS; do
80-
echo $fn
81-
eval $fn"_doc"
85+
functestlibdoc() {
86+
echo "functestlib.sh"
8287
echo ""
83-
done
84-
echo "Note, these functions will probably not work with >=32 CPUs"
88+
echo "Functions:"
89+
for fn in $FUNCTIONS; do
90+
echo "$fn"
91+
eval "$fn""_doc"
92+
echo ""
93+
done
94+
echo "Note: These functions may not behave as expected on systems with >=32 CPUs"
8595
}

0 commit comments

Comments
 (0)