Skip to content

Commit

Permalink
automated: linux: mmtests: added override feature
Browse files Browse the repository at this point in the history
Sometimes benchmarks used in MMTests require configuration tweaks.
This can be done with manual config file edits or can be done with
override feature, which takes a string in format
"KEY1=VAL1;KEY2=VAL2;..." and replaces values for required keys
automatically. Usually such tweaks are required to control the number
of iterations and execution time on benchmark level, not on MMTests
level (with MMTEST_ITERATIONS). For example, for aim9 benchmark
user can specify "AIM9_TESTTIME=5;AIM9_TESTLIST=page_test" to
reduce test time and use only one test instead of all.

Signed-off-by: Konstantin Belov <[email protected]>
  • Loading branch information
Konstantin Belov committed Nov 7, 2024
1 parent 34ed5c2 commit fc543d9
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions automated/linux/mmtests/mmtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ usage() {
Usage: $0 [-s] [-v <TEST_PROG_VERSION>] [-u <TEST_GIT_URL>] [-p <TEST_DIR>]
[-c <MMTESTS_CONFIG_FILE>] [-r <MMTESTS_MAX_RETRIES>]
[-i <MMTEST_ITERATIONS>] [-f] [-k] [-m] [-w RESULTS_DIR]
[-o <OVERRIDE_STRING>]
-v <TEST_PROG_VERSION>
If this parameter is set, then the ${TEST_PROGRAM} suite is cloned. In
Expand Down Expand Up @@ -55,11 +56,17 @@ usage() {
Requires python3 installed.
-m
Use monitors in MMTests run."
Use monitors in MMTests run.
-o <OVERRIDE_STRING>
This parameter is used to override the default values in MMTests config.
Override string must be in the following format:
-o 'key1=value1;key2=value2;...;keyN=valueN'
"
exit 1
}

while getopts "c:p:r:su:v:i:w:fkm" opt; do
while getopts "c:p:r:su:v:i:w:fkmo:" opt; do
case "${opt}" in
c)
if [[ ! "${OPTARG}" == config* ]]; then
Expand Down Expand Up @@ -102,6 +109,9 @@ while getopts "c:p:r:su:v:i:w:fkm" opt; do
m)
USE_MONITORS=true
;;
o)
OVERRIDE_STRING="${OPTARG}"
;;
*)
usage
;;
Expand Down Expand Up @@ -212,6 +222,41 @@ collect_results() {
fi
}

backup_config() {
if [[ -f "$MMTESTS_CONFIG_FILE" ]]; then
cp "$MMTESTS_CONFIG_FILE" "${MMTESTS_CONFIG_FILE}.bak"
info_msg "Backup saved as $(realpath "$MMTESTS_CONFIG_FILE".bak)"
else
error_msg "Config file '$MMTESTS_CONFIG_FILE' not found. Aborting."
exit 1
fi
}

apply_override() {
backup_config
if [[ -n "$OVERRIDE_STRING" ]]; then
OVERRIDE_STRING="${OVERRIDE_STRING#-o }"
# Split by semicolon and process each pair
OLD_IFS="$IFS"
IFS=';'
for pair in $OVERRIDE_STRING; do
# Split into key and value
IFS='=' read -r key value <<< "$pair"
[ -z "$key" ] || [ -z "$value" ] && continue

sed -i "s/^[[:space:]]*export[[:space:]]\+${key}=.*/export ${key}=${value}/" "$MMTESTS_CONFIG_FILE"

if grep -q "^[[:space:]]*export[[:space:]]*${key}=${value}" "$MMTESTS_CONFIG_FILE"; then
info_msg "Updated ${key} with ${value}"
else
warn_msg "Failed to update ${key}"
fi
done
IFS="$OLD_IFS"
info_msg "Overrides applied to ${MMTESTS_CONFIG_FILE}"
fi
}

! check_root && error_msg "Please run this script as root."

if [ "${SKIP_INSTALL}" = "true" ]; then
Expand All @@ -237,6 +282,7 @@ if [[ ! -f "${TEST_DIR}/${MMTESTS_CONFIG_FILE}" ]]; then
exit 1
fi

apply_override
run_test

if [ "${COLLECT_RESULTS}" = "true" ]; then
Expand Down

0 comments on commit fc543d9

Please sign in to comment.