Skip to content

Commit f344afe

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 f344afe

File tree

4 files changed

+112
-94
lines changed

4 files changed

+112
-94
lines changed

Runner/init_env

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
#!/bin/sh
2-
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
32
# SPDX-License-Identifier: BSD-3-Clause-Clear
4-
5-
# Source this file to setup the test suite environment
6-
BASEDIR=$(pwd)
7-
export BASEDIR
8-
TOOLS=$(pwd)/utils
9-
export TOOLS
10-
SUITES=$(pwd)/suites
11-
export SUITES
3+
4+
# Base directory of Runner
5+
BASE_DIR="$(CDPATH= cd -- "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
6+
export TOOLS="${BASE_DIR}/utils"
7+
export __RUNNER_SUITES_DIR="${BASE_DIR}/suites"

Runner/run-test.sh

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,88 @@
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="$(CDPATH= cd -- "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
7+
# shellcheck source=/dev/null
8+
. "${SCRIPT_DIR}/init_env"
9+
# shellcheck source=/dev/null
10+
. "${TOOLS}/functestlib.sh"
811

9-
#import test functions library
10-
. "${TOOLS}"/functestlib.sh
11-
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-
}
12+
# Store results
13+
RESULTS_PASS=""
14+
RESULTS_FAIL=""
3715

3816
# Execute a test case
3917
execute_test_case() {
4018
local test_path="$1"
19+
local test_name
20+
test_name=$(basename "$test_path")
21+
4122
if [ -d "$test_path" ]; then
4223
run_script="$test_path/run.sh"
4324
if [ -f "$run_script" ]; then
44-
log "Executing test case: $test_path"
45-
sh "$run_script" 2>&1
25+
log "Executing test case: $test_name"
26+
if (cd "$test_path" && sh "./run.sh"); then
27+
log_pass "$test_name passed"
28+
RESULTS_PASS="${RESULTS_PASS}\n$test_name"
29+
else
30+
log_fail "$test_name failed"
31+
RESULTS_FAIL="${RESULTS_FAIL}\n$test_name"
32+
fi
4633
else
47-
log "No run.sh found in $test_path"
34+
log_error "No run.sh found in $test_path"
35+
RESULTS_FAIL="${RESULTS_FAIL}\n$test_name (missing run.sh)"
4836
fi
4937
else
50-
log "Test case directory not found: $test_path"
38+
log_error "Test case directory not found: $test_path"
39+
RESULTS_FAIL="${RESULTS_FAIL}\n$test_name (directory not found)"
5140
fi
5241
}
5342

54-
# Function to run a specific test case by name
43+
# Run test by name
5544
run_specific_test_by_name() {
5645
test_name="$1"
57-
test_path=$(find_test_case_by_name ".")
46+
test_path=$(find_test_case_by_name "$test_name")
5847
if [ -z "$test_path" ]; then
59-
log "Test case with name $test_name not found."
48+
log_error "Test case with name $test_name not found."
49+
RESULTS_FAIL="${RESULTS_FAIL}\n$test_name (not found)"
6050
else
6151
execute_test_case "$test_path"
6252
fi
6353
}
6454

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

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

72-
run_specific_test_by_name "$1"
90+
print_summary

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

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

6-
. "${PWD}/init_env"
6+
# Resolve and source functestlib.sh
7+
FUNCLIB="$(CDPATH= cd -- "$(dirname "$0")/../../../../utils" >/dev/null 2>&1 && pwd)/functestlib.sh"
8+
9+
# shellcheck source=/dev/null
10+
. "$FUNCLIB"
11+
712
TESTNAME="CPUFreq_Validation"
8-
. "$TOOLS/functestlib.sh"
913

1014
test_path=$(find_test_case_by_name "$TESTNAME")
1115
log_info "-----------------------------------------------------------------------------------------"

Runner/utils/functestlib.sh

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,37 @@
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+
# Resolve the path to init_env
7+
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
8+
INIT_ENV_PATH="${SCRIPT_DIR}/../init_env"
9+
10+
# shellcheck source=/dev/null
11+
. "$INIT_ENV_PATH"
1012

11-
__RUNNER_SUITES_DIR="/var/Runner/suites"
12-
__RUNNER_UTILS_BIN_DIR="/var/common"
13+
# Set common directories (fallback if init_env not sourced)
14+
__RUNNER_SUITES_DIR="${__RUNNER_SUITES_DIR:-${ROOT_DIR}/suites}"
15+
#__RUNNER_UTILS_BIN_DIR="${__RUNNER_UTILS_BIN_DIR:-${ROOT_DIR}/common}"
1316

14-
#This function used for test logging
17+
# Logging function
1518
log() {
1619
local level="$1"
1720
shift
18-
# echo "$(date '+%Y-%m-%d %H:%M:%S') - $message" | tee -a /var/test_framework.log
1921
echo "[$level] $(date '+%Y-%m-%d %H:%M:%S') - $*" | tee -a /var/test_output.log
2022
}
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-
}
3223

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-
}
24+
# Logging levels
25+
log_info() { log "INFO" "$@"; }
26+
log_pass() { log "PASS" "$@"; }
27+
log_fail() { log "FAIL" "$@"; }
28+
log_error() { log "ERROR" "$@"; }
3829

30+
# Dependency check
3931
check_dependencies() {
4032
local missing=0
4133
for cmd in "$@"; do
42-
if ! command -v "$cmd" > /dev/null 2>&1; then
34+
if ! command -v "$cmd" >/dev/null 2>&1; then
4335
log_error "ERROR: Required command '$cmd' not found in PATH."
4436
missing=1
4537
fi
@@ -48,38 +40,46 @@ check_dependencies() {
4840
log_error "Exiting due to missing dependencies."
4941
exit 1
5042
else
51-
log_pass "Test related dependencies are present."
43+
log_pass "Test related dependencies are present."
5244
fi
5345
}
5446

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

53+
find_test_case_bin_by_name() {
54+
local test_name="$1"
55+
find "$__RUNNER_UTILS_BIN_DIR" -type f -iname "$test_name" 2>/dev/null
56+
}
6157

62-
## this doc fn comes last
58+
find_test_case_script_by_name() {
59+
local test_name="$1"
60+
find "$__RUNNER_UTILS_BIN_DIR" -type d -iname "$test_name" 2>/dev/null
61+
}
62+
63+
# Documentation printer
6364
FUNCTIONS="\
6465
log_info \
6566
log_pass \
6667
log_fail \
6768
log_error \
6869
find_test_case_by_name \
6970
find_test_case_bin_by_name \
70-
find_test_case_script_by_name \
71+
find_test_case_script_by_name \
7172
log \
7273
"
7374

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"
75+
functestlibdoc() {
76+
echo "functestlib.sh"
8277
echo ""
83-
done
84-
echo "Note, these functions will probably not work with >=32 CPUs"
78+
echo "Functions:"
79+
for fn in $FUNCTIONS; do
80+
echo "$fn"
81+
eval "$fn""_doc"
82+
echo ""
83+
done
84+
echo "Note: These functions may not behave as expected on systems with >=32 CPUs"
8585
}

0 commit comments

Comments
 (0)