Skip to content

Commit afba7d5

Browse files
committed
Stop resolving benchmark binary location
This is a back-port of commit ba6a2b7 (PR #2860) from `main`. Both `pbench-fio` and `pbench-uperf`: * No longer allow for the benchmark binary to be overriden by an environment variable -- this was an out-dated way for the unit tests to mock the respective benchmark behavior * No longer resolve and check that the benchmark binary is executable There was an ordering problem with the old `benchmark_bin` variable initial value and where it is used in the rest of the script (both for `pbench-fio` and `pbench-uperf`). The existence check was not always performed locally (no clients or servers specified which are local), but the commands run remotely required `benchmark_bin` to be set during creation of the commands for remote execution. By only checking for the existence of the benchmark binary when performing the version check, and allowing the shell to resolve the location of the benchmark binary at run time, we avoid the interdependency altogether. Mock commands for `fio` and `uperf` are provided on the `PATH` for tests. For the CLI tests, those mocks are removed so that we can verify that help and usage text is emitted before the checks for the particular command existence (which is shown by the failing `test-CL`). We also add failing tests for `uperf` and `fio` behaviors: * `pbench-fio` * `test-22` -- missing `fio` command * `test-50` -- `fio -V` reports a bad version * `pbench-uperf` * `test-02` -- missing `uperf` command * `test-51` -- `uperf -V` reports a bad version The existence check of the `fio` and `uperf` benchmark commands now occurs after any help requests or command usage errors. This fixes issue #2841 [1]. Finally, we correct the way `pbench-uperf` checked the status of the `uperf` command execution of the benchmark by making sure the `local` declaration is performed before the assigment, so that the return code check is not overridden by the "status" of the `local` declaration. This fixes issue #2842 [2]. [1] #2841 [2] #2842
1 parent 36263d0 commit afba7d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+644
-435
lines changed

agent/base

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,20 +291,18 @@ function generate_inventory {
291291
done
292292
}
293293

294-
function resolve_benchmark_bin {
295-
# Encapsulation of method for resolving the actual benchmark
296-
# binary.
297-
which --skip-alias --skip-functions "${1}"
298-
}
299-
300294
function vercmp {
301295
# Compare two package versions via `rpmdev-vercmp`.
302296
local _package="${1}"
303297
local _match="${2}"
304298
local _exp_ver="${3}"
305299
local _ins_ver="${4}"
306300

307-
local _stderr=$(rpmdev-vercmp "${_ins_ver}" "${_exp_ver}" 2>&1 > /dev/null)
301+
# Note we declare `_stderr` local without an initializer because the return
302+
# code of rpmdev-vercmp would be overwritten by the return code of the
303+
# "local" declaration.
304+
local _stderr
305+
_stderr=$(rpmdev-vercmp "${_ins_ver}" "${_exp_ver}" 2>&1 > /dev/null)
308306
local _res=${?}
309307
if [[ ${_res} -ne 0 && ${_res} -ne 11 && ${_res} -ne 12 ]]; then
310308
error_log "rpmdev-vercmp - ${_stderr}"

agent/bench-scripts/pbench-dbench

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ warn_log "${script_name} is deprecated and will be removed in the next release"
2424
benchmark_rpm=$script_name
2525
export benchmark="dbench"
2626
if [[ -z "${benchmark_bin}" ]]; then
27-
benchmark_bin="$(resolve_benchmark_bin "${benchmark}")"
27+
benchmark_bin="$(command -v "${benchmark}")"
2828
if [[ -z "${benchmark_bin}" ]]; then
2929
error_log "[${script_name}] ${benchmark} executable not found on PATH=${PATH}"
3030
exit 1

agent/bench-scripts/pbench-fio

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,7 @@ pbench_bin="`cd ${script_path}/..; /bin/pwd`"
1111
. "$pbench_bin"/base
1212

1313
export benchmark="fio"
14-
benchmark_rpm=${benchmark}
1514
export benchmark_run_dir=""
16-
# allow unit tests to override
17-
if [[ -z "${benchmark_bin}" ]]; then
18-
benchmark_bin="$(resolve_benchmark_bin "${benchmark}")"
19-
if [[ -z "${benchmark_bin}" ]]; then
20-
error_log "[${script_name}] ${benchmark} executable not found on PATH=${PATH}"
21-
exit 1
22-
fi
23-
fi
2415

2516
job_file="${script_path}/templates/fio.job"
2617

@@ -168,6 +159,7 @@ function usage {
168159
}
169160

170161
function fio_process_options() {
162+
local opts
171163
opts=$(getopt -q -o b:c:d:hj:r:s:t: --longoptions "help,max-stddev:,max-failures:,samples:,direct:,sync:,pre-check,clients:,client-file:,iodepth:,ioengine:,config:,jobs-per-dev:,job-mode:,rate-iops:,ramptime:,runtime:,test-types:,block-sizes:,file-size:,targets:,tool-group:,postprocess-only:,run-dir:,numjobs:,job-file:,sysinfo:,pre-iteration-script:,histogram-interval-sec:,histogram-interval-msec:,unique-ports" -n "getopt.sh" -- "$@")
172164
if [ $? -ne 0 ]; then
173165
printf -- "${script_name} $*\n"
@@ -177,6 +169,7 @@ function fio_process_options() {
177169
exit 1
178170
fi
179171
eval set -- "$opts"
172+
local arg
180173
while true; do
181174
arg="${1}"
182175
shift
@@ -479,7 +472,12 @@ function local_pre_check() {
479472

480473
# First check for the supported version of fio in use.
481474

482-
local _stdout=$(${benchmark_bin} --version)
475+
local _stdout
476+
_stdout=$(${benchmark} --version 2>&1)
477+
if [[ ${?} -ne 0 ]]; then
478+
error_log "[${script_name}] ${benchmark} failed reporting its version: '${_stdout}'"
479+
exit 1
480+
fi
483481
local ver_installed=${_stdout##*-}
484482

485483
vercmp "${benchmark}" "${match}" "${ver}" "${ver_installed}"
@@ -528,8 +526,7 @@ function fio_pre_check() {
528526
fi
529527
if [[ ${do_local_pre_check} -eq 1 ]]; then
530528
debug_log "Running pre-check locally"
531-
local_pre_check "${devs}" "${ver}" "${match}"
532-
rc=${?}
529+
local_pre_check "${devs}" "${ver}" "${match}" || rc=${?}
533530
fi
534531
if [[ ${rc} -ne 0 ]]; then
535532
error_log "pre-check(s) failed, exiting"
@@ -598,7 +595,7 @@ function fio_run_job() {
598595

599596
if [ -n "${clients}" ]; then
600597
for client in "${client_names[@]}"; do
601-
local bash_c_cmd="'${benchmark_bin}' --server=,${client_ports[${client}]} > client-result.txt 2> client-result.err"
598+
local bash_c_cmd="${benchmark} --server=,${client_ports[${client}]} > client-result.txt 2> client-result.err"
602599
local screen_it="screen -L -Logfile fio-server.screen.log -dmS fio-server bash -c ${bash_c_cmd}"
603600
if pbench-is-local ${client}; then
604601
debug_log "killing any old local fio processes and starting new a fio process for the local client"
@@ -653,9 +650,9 @@ function fio_run_job() {
653650
pbench-start-tools --group=$tool_group --dir=$benchmark_results_dir
654651

655652
# create a command file and keep it with the results for debugging later, or user can run outside of pbench
656-
echo "$benchmark_bin $client_opts $bench_opts" >$benchmark_results_dir/fio.cmd
653+
echo "$benchmark $client_opts $bench_opts" >$benchmark_results_dir/fio.cmd
657654
chmod +x $benchmark_results_dir/fio.cmd
658-
debug_log "$benchmark: Going to run [$benchmark_bin $bench_opts $client_opts]"
655+
debug_log "$benchmark: Going to run [$benchmark $bench_opts $client_opts]"
659656
pushd $benchmark_results_dir >/dev/null
660657
$benchmark_results_dir/fio.cmd >$benchmark_results_dir/fio-result.txt
661658
local _fio_exit_code=$?
@@ -896,6 +893,7 @@ function fio_run_benchmark() {
896893
}
897894

898895
fio_process_options "$@"
896+
899897
if [ "$postprocess_only" = "n" ]; then
900898
ver="$(pbench-config version ${benchmark})"
901899
if [[ -z "${ver}" ]]; then

agent/bench-scripts/pbench-iozone

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ warn_log "${script_name} is deprecated and will be removed in the next release"
2525
benchmark_rpm=$script_name
2626
export benchmark="iozone"
2727
if [[ -z "${benchmark_bin}" ]]; then
28-
benchmark_bin="$(resolve_benchmark_bin "${benchmark}")"
28+
benchmark_bin="$(command -v "${benchmark}")"
2929
if [[ -z "${benchmark_bin}" ]]; then
3030
error_log "[${script_name}] ${benchmark} executable not found on PATH=${PATH}"
3131
exit 1

agent/bench-scripts/pbench-netperf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ warn_log "${script_name} is deprecated and will be removed in the next release"
3939
benchmark_rpm=$script_name
4040
export benchmark="netperf"
4141
if [[ -z "${benchmark_bin}" ]]; then
42-
benchmark_bin="$(resolve_benchmark_bin "${benchmark}")"
42+
benchmark_bin="$(command -v "${benchmark}")"
4343
if [[ -z "${benchmark_bin}" ]]; then
4444
error_log "[${script_name}] ${benchmark} executable not found on PATH=${PATH}"
4545
exit 1

agent/bench-scripts/pbench-uperf

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ pbench_bin="`cd ${script_path}/..; /bin/pwd`"
2525
. "$pbench_bin"/base
2626

2727
export benchmark="uperf"
28-
if [[ -z "${benchmark_bin}" ]]; then
29-
benchmark_bin="$(resolve_benchmark_bin "${benchmark}")"
30-
if [[ -z "${benchmark_bin}" ]]; then
31-
error_log "${script_name}: ${benchmark} executable not found on PATH=${PATH}"
32-
exit 1
33-
fi
34-
fi
3528

3629
# Every bench-script follows a similar sequence:
3730
# 1) process bench script arguments
@@ -204,7 +197,13 @@ function local_pre_check {
204197
local _ver="${1}"
205198
local _match="${2}"
206199

207-
local ver_installed=$(${benchmark_bin} -V | awk 'NR==1 {print $3}')
200+
local _stdout
201+
_stdout=$(${benchmark} -V 2>&1)
202+
if [[ ${?} -ne 0 ]]; then
203+
error_log "${script_name}: ${benchmark} failed reporting version: '${_stdout}'"
204+
return 1
205+
fi
206+
local ver_installed=$(awk 'NR==1 {print $3}' <<< ${_stdout})
208207
vercmp "${benchmark}" "${_match}" "${_ver}" "${ver_installed}"
209208
return ${?}
210209
}
@@ -458,6 +457,11 @@ if [[ "${postprocess_only}" != "y" ]]; then
458457
# At least one client or server is a local host, so perform the
459458
# pre-check.
460459
local_pre_check "${ver}" "${match}"
460+
res=${?}
461+
if [[ ${res} -ne 0 ]]; then
462+
error_log "[${script_name}] The local pre-check failed"
463+
exit ${res}
464+
fi
461465
fi
462466

463467
let err_cnt=0
@@ -484,7 +488,7 @@ if [[ "${postprocess_only}" != "y" ]]; then
484488
fi
485489
done
486490
if [[ ${err_cnt} -gt 0 ]]; then
487-
error_log "The following pre-checks on clients and servers failed:"
491+
error_log "[${script_name}] The following pre-checks on clients and servers failed:"
488492
error_log " clients: ${err_clients}"
489493
error_log " servers: ${err_servers}"
490494
exit 1
@@ -626,7 +630,7 @@ for protocol in ${protocols//,/ }; do
626630
# vsock protocol requires socket-type to be specified
627631
vsock_extra_opts=" -S vsock"
628632
fi
629-
benchmark_server_cmd="${benchmark_bin} -v -s -P ${server_port}${vsock_extra_opts} > ${server_log} 2>&1"
633+
benchmark_server_cmd="${benchmark} -v -s -P ${server_port}${vsock_extra_opts} > ${server_log} 2>&1"
630634
# adjust server command for NUMA binding
631635
server_node=`echo "$server_nodes," | cut -d, -f$server_nr`
632636
if [ ! -z "$server_node" ]; then
@@ -643,7 +647,7 @@ for protocol in ${protocols//,/ }; do
643647
if [ "$log_response_times" == "y" ]; then
644648
resp_opt=" -X $benchmark_results_dir/$uperf_identifier--response-times.txt"
645649
fi
646-
benchmark_client_cmd="${benchmark_bin} -v -m $xml_file -R -a -i 1 ${resp_opt}${vsock_extra_opts} -P $server_port >$result_file 2>&1"
650+
benchmark_client_cmd="${benchmark} -v -m $xml_file -R -a -i 1 ${resp_opt}${vsock_extra_opts} -P $server_port >$result_file 2>&1"
647651
# adjust client command for NUMA binding
648652
client_node=`echo "$client_nodes," | cut -d, -f$server_nr`
649653
if [ ! -z "$client_node" ]; then

agent/bench-scripts/test-bin/bm

Lines changed: 0 additions & 32 deletions
This file was deleted.

agent/bench-scripts/test-bin/bm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mock-cmd
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mock-cmd

agent/bench-scripts/test-bin/fio

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
echo "$0 $*" >> $_testlog
4+
5+
# Mock fio command behaviors.
6+
if [[ "${1%%=*}" == "--client" ]]; then
7+
client_file=${1##*=}
8+
for line in $(< ${client_file}); do
9+
ip_name="${line%%,*}"
10+
client="${ip_name#*:}"
11+
if [[ "${client%%.*}" == "hist" ]]; then
12+
# When we are mocking out a benchmark command for pbench-fio,
13+
# for each client which begins with "hist" create an empty
14+
# fio latency histogram log file so that the invocation of
15+
# our latency visualizations can be exercised.
16+
touch ./fio_clat_hist.empty.log.${client}
17+
fi
18+
done
19+
elif [[ "${1}" == "--version" ]]; then
20+
echo "fio-${_BM_FIO_VER:-3.42}"
21+
exit 0
22+
fi
23+
24+
exit ${_BM_FIO_STS:-0}

0 commit comments

Comments
 (0)