Skip to content

Commit

Permalink
kselftest: Add new option -E for specifying environment variables
Browse files Browse the repository at this point in the history
Currently we are not able to run the subtests of a kselftest
due to lack of support for passing the parameters to the
test case. Hence, solve this problem by adding support
for passing environment variables in KernelCI kselftest.

Signed-off-by: Shreeya Patel <[email protected]>
  • Loading branch information
crazoes committed Jun 11, 2024
1 parent 4fc8e57 commit 4e0544f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
19 changes: 17 additions & 2 deletions automated/linux/kselftest/kselftest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ usage() {
[-S kselftest-skipfile]
[-b board]
[-g branch]
[-e environment]" 1>&2
[-e environment]
[-E ENV_NAME=ENV_VAL]" 1>&2
exit 1
}

while getopts "i:n:c:T:t:s:u:p:L:S:b:g:e:h" opt; do
while getopts "i:n:c:T:t:s:u:p:L:S:b:g:e:E:h" opt; do
case "${opt}" in
i) SHARD_INDEX="${OPTARG}" ;;
n) SHARD_NUMBER="${OPTARG}" ;;
Expand Down Expand Up @@ -107,6 +108,20 @@ while getopts "i:n:c:T:t:s:u:p:L:S:b:g:e:h" opt; do
e)
export ENVIRONMENT="${OPTARG}"
;;
E)
if [ -n "${OPTARG}" ]; then
IFS='=' read -r env_name env_val << EOF
${OPTARG}
EOF
if [ -z "${env_name}" ] || [ -z "${env_val}" ]; then
echo "Option -E requires an argument of format ENV_NAME=ENV_VAL"
exit 1
fi
# Use eval to set an environment variable dynamically
eval "export ${env_name}=${env_val}"
eval "echo \"${env_name}='\$${env_name}'\""
fi
;;
h|*) usage ;;
esac
done
Expand Down
11 changes: 10 additions & 1 deletion automated/linux/kselftest/kselftest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ params:
BOARD: ""
BRANCH: ""
ENVIRONMENT: ""
# Set an arbitrary environment variable like so ENV_VAR=ENV_VAL.
# Since the parsing assumes only one variable per `-E` option, we can only set
# one variable here.
#
# If multiple variable needs to be set, it might be a good idea to edit the test
# definition and add more -E directly in the invocation. The kselftest.sh script
# supports setting an arbitrary number of variables, just use
# `-E ENV_1_NAME=ENV_1_VAL -E ENV_2_NAME=ENV_2_VAL ...`.
ENV: ""

# Number of shards that will be done, default 1 which is the same as no sharding.
SHARD_NUMBER: 1
Expand All @@ -60,5 +69,5 @@ params:
run:
steps:
- cd ./automated/linux/kselftest/
- ./kselftest.sh -c "${TST_CMDFILES}" -T "${TST_CASENAME}" -t "${TESTPROG}" -s "${SKIP_INSTALL}" -u "${TESTPROG_URL}" -L "${SKIPLIST}" -S "${SKIPFILE}" -b "${BOARD}" -g "${BRANCH}" -e "${ENVIRONMENT}" -p "${KSELFTEST_PATH}" -n "${SHARD_NUMBER}" -i "${SHARD_INDEX}"
- ./kselftest.sh -c "${TST_CMDFILES}" -T "${TST_CASENAME}" -t "${TESTPROG}" -s "${SKIP_INSTALL}" -u "${TESTPROG_URL}" -L "${SKIPLIST}" -S "${SKIPFILE}" -b "${BOARD}" -g "${BRANCH}" -e "${ENVIRONMENT}" -p "${KSELFTEST_PATH}" -n "${SHARD_NUMBER}" -i "${SHARD_INDEX}" -E "${ENV}"
- ../../utils/send-to-lava.sh ./output/result.txt

0 comments on commit 4e0544f

Please sign in to comment.