Skip to content

Commit 71999ee

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 71999ee

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: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,86 @@
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+
find "${__RUNNER_SUITES_DIR}" -type d -name '[A-Za-z]*' -maxdepth 3 | while IFS= read -r test_dir; 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" ] && printf "%s\n" "$RESULTS_PASS" || echo " None"
70+
echo
71+
echo "FAILED:"
72+
[ -n "$RESULTS_FAIL" ] && printf "%s\n" "$RESULTS_FAIL" || echo " None"
73+
log_info "=================================="
74+
}
75+
76+
# Main
6677
if [ "$#" -eq 0 ]; then
6778
log "Usage: $0 [all | <testcase_name>]"
6879
exit 1
6980
fi
7081

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

72-
run_specific_test_by_name "$1"
88+
print_summary

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
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+
# shellcheck disable=SC1007
8+
FUNCLIB="$(CDPATH= cd -- "$(dirname "$0")/../../../../utils" >/dev/null 2>&1 && pwd)/functestlib.sh"
9+
10+
# shellcheck source=/dev/null
11+
. "$FUNCLIB"
12+
713
TESTNAME="CPUFreq_Validation"
8-
. "$TOOLS/functestlib.sh"
914

1015
test_path=$(find_test_case_by_name "$TESTNAME")
1116
log_info "-----------------------------------------------------------------------------------------"

Runner/utils/functestlib.sh

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

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

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

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

31+
# Dependency check
3932
check_dependencies() {
4033
local missing=0
4134
for cmd in "$@"; do
42-
if ! command -v "$cmd" > /dev/null 2>&1; then
35+
if ! command -v "$cmd" >/dev/null 2>&1; then
4336
log_error "ERROR: Required command '$cmd' not found in PATH."
4437
missing=1
4538
fi
@@ -48,38 +41,46 @@ check_dependencies() {
4841
log_error "Exiting due to missing dependencies."
4942
exit 1
5043
else
51-
log_pass "Test related dependencies are present."
44+
log_pass "Test related dependencies are present."
5245
fi
5346
}
5447

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

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

62-
## this doc fn comes last
59+
find_test_case_script_by_name() {
60+
local test_name="$1"
61+
find "$__RUNNER_UTILS_BIN_DIR" -type d -iname "$test_name" 2>/dev/null
62+
}
63+
64+
# Documentation printer
6365
FUNCTIONS="\
6466
log_info \
6567
log_pass \
6668
log_fail \
6769
log_error \
6870
find_test_case_by_name \
6971
find_test_case_bin_by_name \
70-
find_test_case_script_by_name \
72+
find_test_case_script_by_name \
7173
log \
7274
"
7375

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

0 commit comments

Comments
 (0)