beautysh: re-format
beautysh is enabled in the openbmc-build-scripts on Bash/Zsh/POSIX-sh
files to have a consistent formatting. Re-run the formatter on the
whole repository.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I584c76da2eb35af2177a97d5cd4b882f9881fb80
diff --git a/bin/gen_list.sh b/bin/gen_list.sh
index 080e61a..2c464dd 100755
--- a/bin/gen_list.sh
+++ b/bin/gen_list.sh
@@ -6,7 +6,7 @@
# example.
if ! test "${default_delim+defined}" ; then
- readonly default_delim=" "
+ readonly default_delim=" "
fi
# Performance note: It is important for these functions to run quickly. One way to increase their speed is
@@ -15,104 +15,104 @@
# the functions. The cost of this is that it makes the functions slightly more difficult to read.
-function add_list_element {
- # local list_element="${1}"
- # local list_name="${2}"
- # local delim="${3:-${default_delim}}"
- # local position="${4:-back}"
+function add_list_element() {
+ # local list_element="${1}"
+ # local list_name="${2}"
+ # local delim="${3:-${default_delim}}"
+ # local position="${4:-back}"
- # Add the list_element to the list named in list_name.
+ # Add the list_element to the list named in list_name.
- # Description of argument(s):
- # list_element The list element to be added.
- # list_name The name of the list to be modified.
- # delim The delimiter used to separate list elements.
- # position Indicates the position in the list where the new element should be added
- # ("front"/"back").
+ # Description of argument(s):
+ # list_element The list element to be added.
+ # list_name The name of the list to be modified.
+ # delim The delimiter used to separate list elements.
+ # position Indicates the position in the list where the new element should be added
+ # ("front"/"back").
- if [ -z "${!2}" ] ; then
- # The list is blank. Simply assign it the list_element value and return.
- eval "${2}=\"${1}\""
- return
- fi
+ if [ -z "${!2}" ] ; then
+ # The list is blank. Simply assign it the list_element value and return.
+ eval "${2}=\"${1}\""
+ return
+ fi
- if [ "${4:-back}" == "back" ] ; then
- # Append the list_element to the back of the list and return.
- eval "${2}=\"\${${2}}\${3-${default_delim}}\${1}\""
- return
- fi
+ if [ "${4:-back}" == "back" ] ; then
+ # Append the list_element to the back of the list and return.
+ eval "${2}=\"\${${2}}\${3-${default_delim}}\${1}\""
+ return
+ fi
- # Append the list_element to the front of the list and return.
- eval "${2}=\"\${1}\${3-${default_delim}}\${${2}}\""
+ # Append the list_element to the front of the list and return.
+ eval "${2}=\"\${1}\${3-${default_delim}}\${${2}}\""
}
-function remove_list_element {
- # local list_element="${1}"
- # local list_name="${2}"
- local delim="${3:-${default_delim}}"
+function remove_list_element() {
+ # local list_element="${1}"
+ # local list_name="${2}"
+ local delim="${3:-${default_delim}}"
- # Remove all occurrences of list_element from the list named in list_name.
+ # Remove all occurrences of list_element from the list named in list_name.
- # Description of argument(s):
- # list_element The list element to be removed.
- # list_name The name of the list to be modified.
- # delim The delimiter used to separate list elements.
+ # Description of argument(s):
+ # list_element The list element to be removed.
+ # list_name The name of the list to be modified.
+ # delim The delimiter used to separate list elements.
- local __rle_new_list__="${!2}"
+ local __rle_new_list__="${!2}"
- # Special case: The list contains one element which matches the specified list element:
- if [ "${1}" == "${__rle_new_list__}" ] ; then
- eval ${2}=\"\"
- return
- fi
+ # Special case: The list contains one element which matches the specified list element:
+ if [ "${1}" == "${__rle_new_list__}" ] ; then
+ eval ${2}=\"\"
+ return
+ fi
- # Replace all occurrences of list_element that are bounded by the delimiter on both sides.
- __rle_new_list__="${__rle_new_list__//${delim}${1}${delim}/${delim}}"
- # Replace list_item if it occurs at the beginning of the string and is bounded on the right by the
- # delimiter.
- __rle_new_list__="${__rle_new_list__#${1}${delim}}"
- # Replace list_item if it occurs at the end of the string and is bounded on the left by the delimiter.
- __rle_new_list__="${__rle_new_list__%${delim}${1}}"
+ # Replace all occurrences of list_element that are bounded by the delimiter on both sides.
+ __rle_new_list__="${__rle_new_list__//${delim}${1}${delim}/${delim}}"
+ # Replace list_item if it occurs at the beginning of the string and is bounded on the right by the
+ # delimiter.
+ __rle_new_list__="${__rle_new_list__#${1}${delim}}"
+ # Replace list_item if it occurs at the end of the string and is bounded on the left by the delimiter.
+ __rle_new_list__="${__rle_new_list__%${delim}${1}}"
- # Set caller's variable to new value.
- eval ${2}=\"\${__rle_new_list__}\"
+ # Set caller's variable to new value.
+ eval ${2}=\"\${__rle_new_list__}\"
}
-function cleanup_path_slashes {
- local var_name="${1}" ; shift
+function cleanup_path_slashes() {
+ local var_name="${1}" ; shift
- # For the variable named in var_name, replace all multiple-slashes with single slashes and strip any
- # trailing slash.
+ # For the variable named in var_name, replace all multiple-slashes with single slashes and strip any
+ # trailing slash.
- # Description of argument(s):
- # var_name The name of the variable whose contents are to be changed.
+ # Description of argument(s):
+ # var_name The name of the variable whose contents are to be changed.
- local cmd_buf
+ local cmd_buf
- cmd_buf="${var_name}=\$(echo \"\${${var_name}}\" | sed -re 's#[/]+#/#g' -e 's#/\$##g')"
- eval "${cmd_buf}"
+ cmd_buf="${var_name}=\$(echo \"\${${var_name}}\" | sed -re 's#[/]+#/#g' -e 's#/\$##g')"
+ eval "${cmd_buf}"
}
-function remove_path {
- local dir_path="${1}" ; shift
- local path_var="${1:-PATH}" ; shift
+function remove_path() {
+ local dir_path="${1}" ; shift
+ local path_var="${1:-PATH}" ; shift
- # Remove all occurrences of dir_path from the path variable named in path_var.
+ # Remove all occurrences of dir_path from the path variable named in path_var.
- # Note that this function will remove extraneous slashes from the elements of path_var.
+ # Note that this function will remove extraneous slashes from the elements of path_var.
- # Description of argument(s):
- # dir_path The directory to be removed from the path variable.
- # path_var The name of a variable containing directory paths separated by colons.
+ # Description of argument(s):
+ # dir_path The directory to be removed from the path variable.
+ # path_var The name of a variable containing directory paths separated by colons.
- cleanup_path_slashes dir_path || return 1
- cleanup_path_slashes ${path_var} || return 1
- remove_list_element "${dir_path}" "${path_var}" : || return 1
+ cleanup_path_slashes dir_path || return 1
+ cleanup_path_slashes ${path_var} || return 1
+ remove_list_element "${dir_path}" "${path_var}" : || return 1
}
diff --git a/bin/gen_setup.sh b/bin/gen_setup.sh
index 2aed0ea..148fe4b 100755
--- a/bin/gen_setup.sh
+++ b/bin/gen_setup.sh
@@ -13,43 +13,43 @@
shopt -s extglob
-function get_pgm_path_info {
- local program_path_var="${1:-program_path}" ; shift
- local program_name_var="${1:-program_name}" ; shift
- local program_dir_path_var="${1:-program_dir_path}" ; shift
- local follow_links="${1:-0}" ; shift
+function get_pgm_path_info() {
+ local program_path_var="${1:-program_path}" ; shift
+ local program_name_var="${1:-program_name}" ; shift
+ local program_dir_path_var="${1:-program_dir_path}" ; shift
+ local follow_links="${1:-0}" ; shift
- # Determine the program path, name and dir path and assign them to the variables indicated by the caller.
+ # Determine the program path, name and dir path and assign them to the variables indicated by the caller.
- # Description of argument(s):
- # program_path_var The name of the variable to receive the program path.
- # program_name_var The name of the variable to receive the program name.
- # program_dir_path_var The name of the variable to receive the program dir path.
- # follow_links If the program running is actually a link to another file, use that file
- # when calculating the above values.
+ # Description of argument(s):
+ # program_path_var The name of the variable to receive the program path.
+ # program_name_var The name of the variable to receive the program name.
+ # program_dir_path_var The name of the variable to receive the program dir path.
+ # follow_links If the program running is actually a link to another file, use that file
+ # when calculating the above values.
- local _spn_loc_program_path_="${0}"
+ local _spn_loc_program_path_="${0}"
- # The program name is the program path minus all characters up to and including the first slash.
- local _spn_loc_program_name_=${_spn_loc_program_path_##*/}
- # The program dir path is the program path minus everything from the last slash to the end of the string.
- local _spn_loc_program_dir_path_=${_spn_loc_program_path_%${_spn_loc_program_name_}}
+ # The program name is the program path minus all characters up to and including the first slash.
+ local _spn_loc_program_name_=${_spn_loc_program_path_##*/}
+ # The program dir path is the program path minus everything from the last slash to the end of the string.
+ local _spn_loc_program_dir_path_=${_spn_loc_program_path_%${_spn_loc_program_name_}}
- # If program dir path does not start with a slash then it is relative. Convert it to absolute.
- if [ "${_spn_loc_program_dir_path_:0:1}" != "/" ] ; then
- _spn_loc_program_dir_path_="$(readlink -f ${_spn_loc_program_dir_path_})/"
- # Re-assemble the parts into program path variable.
- _spn_loc_program_path_="${_spn_loc_program_dir_path_}${_spn_loc_program_name_}"
- fi
+ # If program dir path does not start with a slash then it is relative. Convert it to absolute.
+ if [ "${_spn_loc_program_dir_path_:0:1}" != "/" ] ; then
+ _spn_loc_program_dir_path_="$(readlink -f ${_spn_loc_program_dir_path_})/"
+ # Re-assemble the parts into program path variable.
+ _spn_loc_program_path_="${_spn_loc_program_dir_path_}${_spn_loc_program_name_}"
+ fi
- if (( follow_links )) ; then
- _spn_loc_program_path_=$(readlink -f ${_spn_loc_program_path_})
- # Re-calculate program_name in case it is different now.
- _spn_loc_program_name_=${_spn_loc_program_path_##*/}
- fi
+ if (( follow_links )) ; then
+ _spn_loc_program_path_=$(readlink -f ${_spn_loc_program_path_})
+ # Re-calculate program_name in case it is different now.
+ _spn_loc_program_name_=${_spn_loc_program_path_##*/}
+ fi
- # Set caller's variables.
- cmd_buf="${program_path_var}=\"\${_spn_loc_program_path_}\" ; ${program_name_var}=\"\${_spn_loc_program_name_}\" ; ${program_dir_path_var}=\"\${_spn_loc_program_dir_path_}\""
- eval "${cmd_buf}"
+ # Set caller's variables.
+ cmd_buf="${program_path_var}=\"\${_spn_loc_program_path_}\" ; ${program_name_var}=\"\${_spn_loc_program_name_}\" ; ${program_dir_path_var}=\"\${_spn_loc_program_dir_path_}\""
+ eval "${cmd_buf}"
}
diff --git a/bin/jenkins_funcs.sh b/bin/jenkins_funcs.sh
index 5524cac..61c55ce 100755
--- a/bin/jenkins_funcs.sh
+++ b/bin/jenkins_funcs.sh
@@ -3,171 +3,171 @@
# This file contains bash functions which may be of use to our Jenkins jobs.
-function process_git {
- # Do not echo all commands to terminal.
- set +x
- local git_dir_path="${1}" ; shift || :
- local post_clone_command="${1}" ; shift || :
+function process_git() {
+ # Do not echo all commands to terminal.
+ set +x
+ local git_dir_path="${1}" ; shift || :
+ local post_clone_command="${1}" ; shift || :
- # Do git processing for this Jenkins job which includes:
- # - Recognizing existing git repo if appropriate.
- # - Cloning git repo.
- # - Running caller's post_clone_command.
+ # Do git processing for this Jenkins job which includes:
+ # - Recognizing existing git repo if appropriate.
+ # - Cloning git repo.
+ # - Running caller's post_clone_command.
- # Description of argument(s):
- # git_dir_path The location of the git dir path (e.g.
- # "/home/johndoe/git/"). If the
- # git_dir_path already exists and it was
- # specified explicitly by the user, this
- # function will neither clone the git repo
- # to this path nor run the
- # post_clone_commands, i.e. the indicated
- # git repo will be used as-is.
- # post_clone_command Any valid bash command to be run after git
- # clone of openbmc-test-automation. Note
- # that this is intended primarily for Open
- # BMC Test code developers who may wish to
- # cherry pick code changes for testing.
+ # Description of argument(s):
+ # git_dir_path The location of the git dir path (e.g.
+ # "/home/johndoe/git/"). If the
+ # git_dir_path already exists and it was
+ # specified explicitly by the user, this
+ # function will neither clone the git repo
+ # to this path nor run the
+ # post_clone_commands, i.e. the indicated
+ # git repo will be used as-is.
+ # post_clone_command Any valid bash command to be run after git
+ # clone of openbmc-test-automation. Note
+ # that this is intended primarily for Open
+ # BMC Test code developers who may wish to
+ # cherry pick code changes for testing.
- if [ -d "${git_dir_path}" -a "${git_dir_path}" != "${WORKSPACE}" ] ; then
- echo "\"${git_dir_path}\" already exists and is not the standard" \
- "location of \"${WORKSPACE}\" so no git processing is required."
- return
- fi
+ if [ -d "${git_dir_path}" -a "${git_dir_path}" != "${WORKSPACE}" ] ; then
+ echo "\"${git_dir_path}\" already exists and is not the standard" \
+ "location of \"${WORKSPACE}\" so no git processing is required."
+ return
+ fi
- # Echo all subsequent commands to terminal.
- set -x
- mkdir -p "${git_dir_path}" || return 1
- cd "${git_dir_path}" || return 1
+ # Echo all subsequent commands to terminal.
+ set -x
+ mkdir -p "${git_dir_path}" || return 1
+ cd "${git_dir_path}" || return 1
- echo "Remove old git repo files."
- rm -Rf ./openbmc-build-scripts
- rm -Rf ./openbmc-test-automation
+ echo "Remove old git repo files."
+ rm -Rf ./openbmc-build-scripts
+ rm -Rf ./openbmc-test-automation
- git clone https://gerrit.openbmc-project.xyz/openbmc/openbmc-build-scripts\
- || return 1
- git clone https://github.com/openbmc/openbmc-test-automation.git || return 1
+ git clone https://gerrit.openbmc-project.xyz/openbmc/openbmc-build-scripts\
+ || return 1
+ git clone https://github.com/openbmc/openbmc-test-automation.git || return 1
- if [ ! -z "${post_clone_command}" ] ; then
- cd openbmc-test-automation || return 1
- echo "Run the caller's post clone command."
- eval "${post_clone_command}" || return 1
- fi
+ if [ ! -z "${post_clone_command}" ] ; then
+ cd openbmc-test-automation || return 1
+ echo "Run the caller's post clone command."
+ eval "${post_clone_command}" || return 1
+ fi
}
-function process_docker {
- # Do not echo all commands to terminal.
- set +x
- local git_dir_path="${1}" ; shift || :
+function process_docker() {
+ # Do not echo all commands to terminal.
+ set +x
+ local git_dir_path="${1}" ; shift || :
- # Source the docker script to prepare our environment for calling docker.
+ # Source the docker script to prepare our environment for calling docker.
- # Description of argument(s):
- # git_dir_path The location of the git dir path (e.g.
- # "/home/johndoe/git/") to be used.
+ # Description of argument(s):
+ # git_dir_path The location of the git dir path (e.g.
+ # "/home/johndoe/git/") to be used.
- # Set global DOCKER_IMG_NAME.
- DOCKER_IMG_NAME="openbmc/obmc-docker-image"
+ # Set global DOCKER_IMG_NAME.
+ DOCKER_IMG_NAME="openbmc/obmc-docker-image"
- echo "Build the docker image required to execute the robot tests."
- # Echo all subsequent commands to terminal.
- set -x
- cd "${git_dir_path}openbmc-build-scripts" || return 1
- . "./scripts/build-qemu-robot-docker.sh" || return 1
+ echo "Build the docker image required to execute the robot tests."
+ # Echo all subsequent commands to terminal.
+ set -x
+ cd "${git_dir_path}openbmc-build-scripts" || return 1
+ . "./scripts/build-qemu-robot-docker.sh" || return 1
- cd "${git_dir_path}" || return 1
+ cd "${git_dir_path}" || return 1
}
if ! test "${stock_robot_program_parms+defined}" ; then
- readonly stock_robot_program_parms="openbmc_host openbmc_username"\
-" openbmc_password os_host os_username os_password quiet debug test_mode"
- readonly master_robot_gen_parms="console consolecolors outputdir output log"\
-" report loglevel include"
+ readonly stock_robot_program_parms="openbmc_host openbmc_username"\
+ " openbmc_password os_host os_username os_password quiet debug test_mode"
+ readonly master_robot_gen_parms="console consolecolors outputdir output log"\
+ " report loglevel include"
fi
-function run_docker_robot {
- # Do not echo all commands to terminal.
- set +x
- local robot_file_path="${1}" ; shift || :
- local robot_pgm_parms="${1-}" ; shift || :
- local robot_gen_parms="${1:-${master_robot_gen_parms}}" ; shift || :
+function run_docker_robot() {
+ # Do not echo all commands to terminal.
+ set +x
+ local robot_file_path="${1}" ; shift || :
+ local robot_pgm_parms="${1-}" ; shift || :
+ local robot_gen_parms="${1:-${master_robot_gen_parms}}" ; shift || :
- # Compose a robot command string and run it in a docker environment.
+ # Compose a robot command string and run it in a docker environment.
- # Description of argument(s):
- # robot_file_path The file path of the robot file (with or
- # without .robot suffix). This file path is
- # relative to the base git repository.
- # robot_pgm_parms A space-separated list of parms which are
- # to be passed to the robot program via the
- # -v robot parameter. These parms will be
- # processed in addition to the
- # stock_robot_program_parms listed above.
- # robot_gen_parms A space-separated list of general robot
- # parameters understood by the robot program
- # (e.g. consolecolors, etc).
+ # Description of argument(s):
+ # robot_file_path The file path of the robot file (with or
+ # without .robot suffix). This file path is
+ # relative to the base git repository.
+ # robot_pgm_parms A space-separated list of parms which are
+ # to be passed to the robot program via the
+ # -v robot parameter. These parms will be
+ # processed in addition to the
+ # stock_robot_program_parms listed above.
+ # robot_gen_parms A space-separated list of general robot
+ # parameters understood by the robot program
+ # (e.g. consolecolors, etc).
- # Strip, then re-append ".robot" so that the user can pass with or without
- # the .robot suffix.
- robot_file_path="${robot_file_path%.robot}.robot"
+ # Strip, then re-append ".robot" so that the user can pass with or without
+ # the .robot suffix.
+ robot_file_path="${robot_file_path%.robot}.robot"
- # Determine the robot_file_name form the robot_file_path.
- local robot_file_name="${robot_file_path%.robot}"
- robot_file_name="${robot_file_name##*/}"
- local robot_short_file_name="${robot_file_name%.robot}"
+ # Determine the robot_file_name form the robot_file_path.
+ local robot_file_name="${robot_file_path%.robot}"
+ robot_file_name="${robot_file_name##*/}"
+ local robot_short_file_name="${robot_file_name%.robot}"
- # Set default values for robot_gen_parms.
- local dft_console=dotted
- local dft_consolecolors=off
- local dft_outputdir=/status_dir
- local dft_output=${robot_short_file_name}.output.xml
- local dft_log=${robot_short_file_name}.log.html
- local dft_report=${robot_short_file_name}.report.html
- local dft_loglevel='TRACE'
- local dft_include=''
+ # Set default values for robot_gen_parms.
+ local dft_console=dotted
+ local dft_consolecolors=off
+ local dft_outputdir=/status_dir
+ local dft_output=${robot_short_file_name}.output.xml
+ local dft_log=${robot_short_file_name}.log.html
+ local dft_report=${robot_short_file_name}.report.html
+ local dft_loglevel='TRACE'
+ local dft_include=''
- local cmd_buf
- # Loop through robot general parms setting any that have no value to a
- # default value (defined above).
- for parm_name in ${robot_gen_parms} ; do
- # If the parm already has a value, continue to next loop iteration.
- [ ! -z "${!parm_name-}" ] && continue || :
- cmd_buf="${parm_name}=\"\${dft_${parm_name}}\""
- eval ${cmd_buf}
- done
+ local cmd_buf
+ # Loop through robot general parms setting any that have no value to a
+ # default value (defined above).
+ for parm_name in ${robot_gen_parms} ; do
+ # If the parm already has a value, continue to next loop iteration.
+ [ ! -z "${!parm_name-}" ] && continue || :
+ cmd_buf="${parm_name}=\"\${dft_${parm_name}}\""
+ eval ${cmd_buf}
+ done
- local robot_cmd_buf='robot'
- # Process our stock robot program parms along with the caller's
- # robot_pgm_parms to add to the robot_cmd_buf.
- local parm_name
- local escape_quote_char="'\''"
- for parm_name in ${stock_robot_program_parms} ${robot_pgm_parms} ; do
- [ -z "${parm_name-}" ] && continue
- robot_cmd_buf="${robot_cmd_buf} -v ${parm_name}:${!parm_name-}"
- done
+ local robot_cmd_buf='robot'
+ # Process our stock robot program parms along with the caller's
+ # robot_pgm_parms to add to the robot_cmd_buf.
+ local parm_name
+ local escape_quote_char="'\''"
+ for parm_name in ${stock_robot_program_parms} ${robot_pgm_parms} ; do
+ [ -z "${parm_name-}" ] && continue
+ robot_cmd_buf="${robot_cmd_buf} -v ${parm_name}:${!parm_name-}"
+ done
- # Process the robot general parms to add to the robot_cmd_buf.
- for parm_name in ${robot_gen_parms} ; do
- robot_cmd_buf="${robot_cmd_buf} --${parm_name}=${!parm_name-}"
- done
+ # Process the robot general parms to add to the robot_cmd_buf.
+ for parm_name in ${robot_gen_parms} ; do
+ robot_cmd_buf="${robot_cmd_buf} --${parm_name}=${!parm_name-}"
+ done
- # Finally append the robot file path to the robot_cmd_buf.
- additional_parms=" ${additional_parms-}"
- robot_cmd_buf="${robot_cmd_buf}${additional_parms} ${HOME}/openbmc-test"
- robot_cmd_buf="${robot_cmd_buf}-automation/${robot_file_path}"
+ # Finally append the robot file path to the robot_cmd_buf.
+ additional_parms=" ${additional_parms-}"
+ robot_cmd_buf="${robot_cmd_buf}${additional_parms} ${HOME}/openbmc-test"
+ robot_cmd_buf="${robot_cmd_buf}-automation/${robot_file_path}"
- # Run the docker container to execute the code update.
- # The test results will be put in ${WORKSPACE}.
+ # Run the docker container to execute the code update.
+ # The test results will be put in ${WORKSPACE}.
- cmd_buf="docker run --user=root --env=HOME=${HOME} --env=PYTHONPATH=${HOME}"
- cmd_buf="${cmd_buf}/openbmc-test-automation/lib --workdir=${HOME} --volume"
- cmd_buf="${cmd_buf}=${git_dir_path}:${HOME} --volume=${WORKSPACE}:/status_"
- cmd_buf="${cmd_buf}dir --tty ${DOCKER_IMG_NAME} python -m ${robot_cmd_buf}"
- # Echo all subsequent commands to terminal.
- set -x
- eval "${cmd_buf}"
+ cmd_buf="docker run --user=root --env=HOME=${HOME} --env=PYTHONPATH=${HOME}"
+ cmd_buf="${cmd_buf}/openbmc-test-automation/lib --workdir=${HOME} --volume"
+ cmd_buf="${cmd_buf}=${git_dir_path}:${HOME} --volume=${WORKSPACE}:/status_"
+ cmd_buf="${cmd_buf}dir --tty ${DOCKER_IMG_NAME} python -m ${robot_cmd_buf}"
+ # Echo all subsequent commands to terminal.
+ set -x
+ eval "${cmd_buf}"
}
diff --git a/bin/plug_ins/Mem_tracker/memcheck.sh b/bin/plug_ins/Mem_tracker/memcheck.sh
index 836604e..4ee9977 100755
--- a/bin/plug_ins/Mem_tracker/memcheck.sh
+++ b/bin/plug_ins/Mem_tracker/memcheck.sh
@@ -22,128 +22,127 @@
# pid The pid for which you desire statistics. If this is not specified,
# statistics will be gathered for all active pids.
-function get_parms {
+function get_parms() {
- # Get program parms.
+ # Get program parms.
- pids="${1:-$(ls /proc | grep -v [A-Za-z])}" ; shift
+ pids="${1:-$(ls /proc | grep -v [A-Za-z])}" ; shift
- return 0
+ return 0
}
-function exit_function {
+function exit_function() {
- # Used to clean up tmp files.
+ # Used to clean up tmp files.
- rm -f ${temp_file_list}
- return
+ rm -f ${temp_file_list}
+ return
}
-function validate_parms {
+function validate_parms() {
- # Validate program parameters.
+ # Validate program parameters.
- # Making sure only root can run our script.
- if [ "${USER}" != "root" ] ; then
- echo "This script must be run as root" 1>&2
- return 1
- fi
+ # Making sure only root can run our script.
+ if [ "${USER}" != "root" ] ; then
+ echo "This script must be run as root" 1>&2
+ return 1
+ fi
- trap "exit_function $signal \$?" EXIT
- return 0
+ trap "exit_function $signal \$?" EXIT
+ return 0
}
-function get_process_mem {
+function get_process_mem() {
- local pid="${1}" ; shift
- # Count memory statistic for passed pid.
+ local pid="${1}" ; shift
+ # Count memory statistic for passed pid.
- # Description of argument(s):
- # pid The process ID for which you desire statistics.
- [ ! -f /proc/${pid}/status -o ! -f /proc/${pid}/smaps ] && return 0
+ # Description of argument(s):
+ # pid The process ID for which you desire statistics.
+ [ ! -f /proc/${pid}/status -o ! -f /proc/${pid}/smaps ] && return 0
- # pss_total Total proportional set size of a process.
- # private_total Total number of clean and dirty private pages in the
- # mapping.
- # shared_total The difference between pss_total and private_total.
+ # pss_total Total proportional set size of a process.
+ # private_total Total number of clean and dirty private pages in the
+ # mapping.
+ # shared_total The difference between pss_total and private_total.
- local pss_total private_total shared_total sum name
- pss_total=$(grep -e "^Pss:" /proc/${pid}/smaps | awk '{print $2}' | awk '{sum += $1} END {print sum}')
- private_total=$(grep -e "^Private" /proc/${pid}/smaps | awk '{print $2}' | awk '{sum += $1} END {print sum}')
+ local pss_total private_total shared_total sum name
+ pss_total=$(grep -e "^Pss:" /proc/${pid}/smaps | awk '{print $2}' | awk '{sum += $1} END {print sum}')
+ private_total=$(grep -e "^Private" /proc/${pid}/smaps | awk '{print $2}' | awk '{sum += $1} END {print sum}')
- [ -z "${pss_total}" -o -z "${private_total}" ] && return 0
- (( shared_total=pss_total-private_total ))
- name=$(cut -d "" -f 1 /proc/${pid}/cmdline)
- (( sum=shared_total+private_total ))
- echo -e "${private_total} + ${shared_total} = ${sum} ${name}"
+ [ -z "${pss_total}" -o -z "${private_total}" ] && return 0
+ (( shared_total=pss_total-private_total ))
+ name=$(cut -d "" -f 1 /proc/${pid}/cmdline)
+ (( sum=shared_total+private_total ))
+ echo -e "${private_total} + ${shared_total} = ${sum} ${name}"
}
-function mainf {
+function mainf() {
- get_parms "$@" || return 1
+ get_parms "$@" || return 1
- validate_parms || return 1
+ validate_parms || return 1
- # To ensure temp files not exist.
- rm -f ${temp_file_list}
+ # To ensure temp files not exist.
+ rm -f ${temp_file_list}
- for pid in ${pids} ; do
- get_process_mem ${pid} >> ${temp_file_path_1}
- done
+ for pid in ${pids} ; do
+ get_process_mem ${pid} >> ${temp_file_path_1}
+ done
- # This is used to sort results by memory usage.
- sort -gr -k 5 ${temp_file_path_1} > ${temp_file_path_2}
+ # This is used to sort results by memory usage.
+ sort -gr -k 5 ${temp_file_path_1} > ${temp_file_path_2}
- # Find duplicates in the process list output and combine them. In such
- # cases, adjust the process name by including a (<count>) suffix. In the
- # following example of output, 4 instances of "phosphor-hwmon-readd" have
- # been combined.
- # 974848 + 925696 = 1900544 phosphor-hwmon-readd(4)
- for proc_name in $(awk '{print $6}' ${temp_file_path_2} | sort -u) ; do
- count=$(awk -v src=${proc_name} '{if ($6==src) {print $6}}' ${temp_file_path_2} | wc -l)
- [ "${count}" = "1" ] && count_string="" || count_string="(${count})"
- vmsize_in_kb=$(awk -v src=${proc_name} '{if ($6==src) {print $1}}' ${temp_file_path_2} | awk '{sum += $1} END {print sum}')
- vmrss_in_kb=$(awk -v src=${proc_name} '{if ($6==src) {print $3}}' ${temp_file_path_2} | awk '{sum += $1} END {print sum}')
- total=$(awk '{print $5}' ${temp_file_path_2} | awk '{sum += $1} END {print sum}')
- (( sum=vmrss_in_kb+vmsize_in_kb ))
- echo -e "${vmsize_in_kb} + ${vmrss_in_kb} = ${sum} \t ${proc_name}${count_string}" >> ${temp_file_path_3}
- done
+ # Find duplicates in the process list output and combine them. In such
+ # cases, adjust the process name by including a (<count>) suffix. In the
+ # following example of output, 4 instances of "phosphor-hwmon-readd" have
+ # been combined.
+ # 974848 + 925696 = 1900544 phosphor-hwmon-readd(4)
+ for proc_name in $(awk '{print $6}' ${temp_file_path_2} | sort -u) ; do
+ count=$(awk -v src=${proc_name} '{if ($6==src) {print $6}}' ${temp_file_path_2} | wc -l)
+ [ "${count}" = "1" ] && count_string="" || count_string="(${count})"
+ vmsize_in_kb=$(awk -v src=${proc_name} '{if ($6==src) {print $1}}' ${temp_file_path_2} | awk '{sum += $1} END {print sum}')
+ vmrss_in_kb=$(awk -v src=${proc_name} '{if ($6==src) {print $3}}' ${temp_file_path_2} | awk '{sum += $1} END {print sum}')
+ total=$(awk '{print $5}' ${temp_file_path_2} | awk '{sum += $1} END {print sum}')
+ (( sum=vmrss_in_kb+vmsize_in_kb ))
+ echo -e "${vmsize_in_kb} + ${vmrss_in_kb} = ${sum} \t ${proc_name}${count_string}" >> ${temp_file_path_3}
+ done
- # Sort once more.
- sort -gr -k 5 ${temp_file_path_3} > ${temp_file_path_1}
+ # Sort once more.
+ sort -gr -k 5 ${temp_file_path_3} > ${temp_file_path_1}
- # Read results from temp file and convert it to csv.
- csv_line1=""
- csv_line2=""
- while read line ; do
- while read private plus_operator shared equal_sign sum name ; do
- (( sum == 0 )) && continue
- csv_line1+=",${name}"
- csv_line2+=",${sum}"
- done<<<${line}
- done < ${temp_file_path_1}
+ # Read results from temp file and convert it to csv.
+ csv_line1=""
+ csv_line2=""
+ while read line ; do
+ while read private plus_operator shared equal_sign sum name ; do
+ (( sum == 0 )) && continue
+ csv_line1+=",${name}"
+ csv_line2+=",${sum}"
+ done <<<${line}
+ done < ${temp_file_path_1}
- # Strip leading commas.
- csv_line1="${csv_line1#,}"
- csv_line2="${csv_line2#,}"
- { echo "${csv_line1}" ; echo "${csv_line2}" ; } >> ${csv_file_path}
+ # Strip leading commas.
+ csv_line1="${csv_line1#,}"
+ csv_line2="${csv_line2#,}"
+ { echo "${csv_line1}" ; echo "${csv_line2}" ; } >> ${csv_file_path}
- return 0
+ return 0
}
# Main
- mainf "${@}"
- rc="${?}"
- exit "${rc}"
-
+mainf "${@}"
+rc="${?}"
+exit "${rc}"
diff --git a/bin/run_robot_pgm_jenk.sh b/bin/run_robot_pgm_jenk.sh
index 1fa668c..9191387 100755
--- a/bin/run_robot_pgm_jenk.sh
+++ b/bin/run_robot_pgm_jenk.sh
@@ -32,25 +32,25 @@
git_dir_path="${git_dir_path%/}/"
-function mainf {
+function mainf() {
- # Delete leftover output from prior runs.
- rm -f ${WORKSPACE}*.html ${WORKSPACE}*.xml || return 1
- process_git "${git_dir_path}" "${post_clone_command-}" || return 1
- process_docker "${git_dir_path}" || return 1
+ # Delete leftover output from prior runs.
+ rm -f ${WORKSPACE}*.html ${WORKSPACE}*.xml || return 1
+ process_git "${git_dir_path}" "${post_clone_command-}" || return 1
+ process_docker "${git_dir_path}" || return 1
- if [ -z "${robot_file_path-}" ] ; then
- echo "robot_file_path is blank so no there is no need to continue."
- return
- fi
+ if [ -z "${robot_file_path-}" ] ; then
+ echo "robot_file_path is blank so no there is no need to continue."
+ return
+ fi
- run_docker_robot "${robot_file_path}" || return 1
+ run_docker_robot "${robot_file_path}" || return 1
}
# Main
- mainf "${@}"
- rc="${?}"
- exit "${rc}"
+mainf "${@}"
+rc="${?}"
+exit "${rc}"
diff --git a/bin/select_version b/bin/select_version
index d6fca43..4ba61eb 100755
--- a/bin/select_version
+++ b/bin/select_version
@@ -24,86 +24,86 @@
program_uppercase_name=${program_name^^}
-function get_target_program_path {
- local target_program_path_var="${1:-target_program_path}" ; shift
+function get_target_program_path() {
+ local target_program_path_var="${1:-target_program_path}" ; shift
- # Get the full path to the "real" program and assign it to the variable named in target_program_path_var.
+ # Get the full path to the "real" program and assign it to the variable named in target_program_path_var.
- # Description of argument(s):
- # target_program_path_var The name of the variable to receive the result.
+ # Description of argument(s):
+ # target_program_path_var The name of the variable to receive the result.
- # Example result:
+ # Example result:
- # /usr/bin/python3
+ # /usr/bin/python3
- local version_var_name
- local alternate_program_name
- local base_program_path
- local base_program_name
- local candidate
- local candidates
- local base_file_path
+ local version_var_name
+ local alternate_program_name
+ local base_program_path
+ local base_program_name
+ local candidate
+ local candidates
+ local base_file_path
- # The typical use of this program would be to create a link to it like this:
- # ln -s select_version python
- # That being the case, get the name of this actual program (rather than the name of the link to it).
- base_program_path=$(readlink -f "${0}")
- base_program_name=${base_program_path##*/}
+ # The typical use of this program would be to create a link to it like this:
+ # ln -s select_version python
+ # That being the case, get the name of this actual program (rather than the name of the link to it).
+ base_program_path=$(readlink -f "${0}")
+ base_program_name=${base_program_path##*/}
- if [ "${program_name}" == "${base_program_name}" ] ; then
- {
- echo -n "**ERROR** ${base_program_name} should never be called directly."
- echo " Only links to ${base_program_name} should be called."
- } >&2
- exit 1
- fi
-
- # Compose the version_var_name value (e.g. PYTHON_VERSION).
- version_var_name=${program_uppercase_name}_VERSION
- # Compose the alternate_program_name (e.g. python3).
- alternate_program_name=${program_name}${!version_var_name}
-
- # Now use the "type" built-in to search the PATH variable for a list of target program candidates.
- candidates=$(type -ap ${alternate_program_name})
-
- # Example candidates:
- # /home/robot/openbmc-test-automation/bin/python
- # /usr/bin/python
-
- # In this example, the first candidate is actually a link to
- # /home/robot/openbmc-test-automation/bin/select_version. As such it will be rejected.
-
- for candidate in ${candidates}
- do
- if [ -L "${candidate}" ] ; then
- # The candidate is a link so we need to see if it's a link to this program file.
- base_file_path=$(readlink "${candidate}")
- [ "${base_file_path}" == "${base_program_name}" ] && continue
+ if [ "${program_name}" == "${base_program_name}" ] ; then
+ {
+ echo -n "**ERROR** ${base_program_name} should never be called directly."
+ echo " Only links to ${base_program_name} should be called."
+ } >&2
+ exit 1
fi
- # The candidate is NOT a link so it qualifies as the desired target program path.
- eval ${target_program_path_var}=\"\${candidate}\"
- return
+ # Compose the version_var_name value (e.g. PYTHON_VERSION).
+ version_var_name=${program_uppercase_name}_VERSION
+ # Compose the alternate_program_name (e.g. python3).
+ alternate_program_name=${program_name}${!version_var_name}
- done
+ # Now use the "type" built-in to search the PATH variable for a list of target program candidates.
+ candidates=$(type -ap ${alternate_program_name})
+
+ # Example candidates:
+ # /home/robot/openbmc-test-automation/bin/python
+ # /usr/bin/python
+
+ # In this example, the first candidate is actually a link to
+ # /home/robot/openbmc-test-automation/bin/select_version. As such it will be rejected.
+
+ for candidate in ${candidates}
+ do
+ if [ -L "${candidate}" ] ; then
+ # The candidate is a link so we need to see if it's a link to this program file.
+ base_file_path=$(readlink "${candidate}")
+ [ "${base_file_path}" == "${base_program_name}" ] && continue
+ fi
+
+ # The candidate is NOT a link so it qualifies as the desired target program path.
+ eval ${target_program_path_var}=\"\${candidate}\"
+ return
+
+ done
}
# Main
- get_target_program_path target_program_path
+get_target_program_path target_program_path
- # Compose program path var name (e.g. PYTHON_PGM_PATH).
- pgm_path_var_name=${program_uppercase_name}_PGM_PATH
- # Set and export pgm_path_var_name (e.g. PYTHON_PGM_PATH=/usr/bin/python3). This value can be used by
- # child programs for debug.
- eval export ${pgm_path_var_name}=${target_program_path}
+# Compose program path var name (e.g. PYTHON_PGM_PATH).
+pgm_path_var_name=${program_uppercase_name}_PGM_PATH
+# Set and export pgm_path_var_name (e.g. PYTHON_PGM_PATH=/usr/bin/python3). This value can be used by
+# child programs for debug.
+eval export ${pgm_path_var_name}=${target_program_path}
- if [ "${1}" == "--print_only" ] ; then
+if [ "${1}" == "--print_only" ] ; then
echo "${target_program_path}"
- else
+else
# Use exec in order to replace this process with the target process.
exec ${target_program_path} "${@}"
- fi
+fi