Skip to content

Commit 50e6258

Browse files
authored
Merge pull request #14 from redhat-performance/code_cleanup
Harden the iozone wrapper.
2 parents 467b2a5 + 3227fb7 commit 50e6258

File tree

1 file changed

+66
-54
lines changed

1 file changed

+66
-54
lines changed

iozone/iozone_run.sh

Lines changed: 66 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121
# Automate the iozone benchmark.
2222
#
2323

24+
exit_out()
25+
{
26+
echo $1
27+
exit $2
28+
}
29+
30+
make_dir()
31+
{
32+
if [[ ! -d $1 ]]; then
33+
mkdir -p $1
34+
if [ $? -ne 0 ]; then
35+
exit_out "Failed to create directory $1" 1
36+
fi
37+
fi
38+
}
39+
2440
curdir=`pwd`
2541
if [[ $0 == "./"* ]]; then
2642
chars=`echo $0 | awk -v RS='/' 'END{print NR-1}'`
@@ -43,9 +59,12 @@ if [ ! -f "/tmp/${test_name}.out" ]; then
4359
command="${0} $@"
4460
echo $command
4561
$command &> /tmp/${test_name}.out
46-
cat /tmp/${test_name}.out
47-
rm /tmp/${test_name}.out
48-
exit
62+
rtc=$?
63+
if [[ -f /tmp/${test_name}.out ]]; then
64+
cat /tmp/${test_name}.out
65+
rm /tmp/${test_name}.out
66+
fi
67+
exit $?
4968
fi
5069

5170
exec_name=$0
@@ -271,8 +290,7 @@ done
271290
if [ ! -d "test_tools" ]; then
272291
git clone $tools_git test_tools
273292
if [ $? -ne 0 ]; then
274-
echo pulling git $tools_git failed.
275-
exit 1
293+
exit_out "pulling git $tools_git failed." 1
276294
fi
277295
fi
278296

@@ -423,6 +441,9 @@ retrieve_and_build_iozone()
423441
# We need to build iozone. Go get the kit.
424442
#
425443
wget http://www.iozone.org/src/current/${iozone_kit}.tar
444+
if [ $? -ne 0 ]; then
445+
exit_out "wget http://www.iozone.org/src/current/${iozone_kit}.tar failed" 1
446+
fi
426447
tar xf ${iozone_kit}.tar
427448
#
428449
# cd t the source directory
@@ -447,18 +468,16 @@ retrieve_and_build_iozone()
447468
build_target="linux-arm"
448469
;;
449470
*)
450-
echo "Unknown arch ${arch}. Cant continue";
451-
exit 1
471+
exit_out "Unknown arch ${arch}. Cant continue" 1
452472
;;
453473
esac
454474
make ${build_target} >> ${buildrunlog} 2>&1
455475
if [ -x "./iozone" ]; then
456476
cp iozone /usr/bin
457477
else
458-
echo Failed to build iozone, see ${buildrunlog}
459-
exit 1
478+
exit_out "Failed to build iozone, see ${buildrunlog}" 1
460479
fi
461-
popd
480+
popd >& /dev/null
462481
fi
463482
iozone_exe=`which iozone`
464483
}
@@ -468,16 +487,15 @@ retrieve_and_build_iozone()
468487
#
469488
build_eatmem()
470489
{
471-
pushd ${run_dir}
490+
pushd ${run_dir} >& /dev/null
472491
gcc -Wall -Os -o eatmem eatmem.c
473492

474493
if [ -x "$run_dir//eatmem" ]; then
475494
echo "$run_dir/eatmem"
476495
else
477-
echo Warning eatmem did not build, aborting
478-
exit 1
496+
exit_out "Warning eatmem did not build, aborting" 1
479497
fi
480-
popd
498+
popd >& /dev/null
481499
}
482500

483501
#
@@ -662,14 +680,13 @@ do_test_actual()
662680
fi
663681

664682
if [ ${status} -eq 1 ]; then
665-
touch ${testing_dir}/FAILED
666-
else
667-
if [[ ${auto} == 1 ]]; then
668-
(
669-
printf "\n${name_of_test} ANALYSIS:\n\n"
670-
${run_dir}/analysis-iozone.pl ${iozone_output_file}
671-
) > ${iozone_analysis_file};
672-
fi
683+
exit_out "Execution of iozone failed" 1
684+
fi
685+
if [[ ${auto} == 1 ]]; then
686+
(
687+
printf "\n${name_of_test} ANALYSIS:\n\n"
688+
${run_dir}/analysis-iozone.pl ${iozone_output_file}
689+
) > ${iozone_analysis_file};
673690
fi
674691

675692
if [ ${one_run} == "tuned" ]; then
@@ -792,6 +809,9 @@ set_mem_vals()
792809
(( memory_to_take = free_memory - eatmem_free_memory -80 ))
793810
${eatmem_exe} ${memory_to_take} &
794811
PID=$!
812+
#
813+
# Give it a chance to do it's thing.
814+
#
795815
sleep 180
796816
sync
797817
echo 3 > /proc/sys/vm/drop_caches
@@ -916,7 +936,7 @@ lun_setup()
916936
cp /proc/filesystems ${configdir}/filesystems
917937
else
918938
data_dir=${results_dir}/data
919-
mkdir ${data_dir};
939+
make_dir $data_dir
920940
data_lun=`df --portability ${data_dir} | tail -1 | awk '{ print $1 }'`
921941
data_mnt_pt=`df --portability ${data_dir} | tail -1 | awk '{ print $6 }'`
922942
iozone_actual_fs_types=`mount -l | grep " on ${data_mnt_pt} " | awk '{ print $5 }'`
@@ -1030,7 +1050,7 @@ verify_disk_cache()
10301050

10311051
execute_iozone()
10321052
{
1033-
mkdir ${analysis_dir}/${fstype};
1053+
make_dir ${analysis_dir}/${fstype}
10341054

10351055
if [ ${do_incache} -eq 1 ]; then
10361056
do_test "In Cache" "incache" "-n ${page_size}k -g ${incache_maxfile}m -y 1k -q 1m"
@@ -1044,9 +1064,10 @@ execute_iozone()
10441064
do_test "In Cache w/ MMAP" "incache+mmap" "-n ${page_size}k -g ${incache_maxfile}m -y 1k -q 1m -B"
10451065
fi
10461066
}
1067+
10471068
execute_iozone_full()
10481069
{
1049-
mkdir ${analysis_dir}/${fstype};
1070+
make_dir ${analysis_dir}/${fstype}
10501071

10511072
if [ ${do_incache} -eq 1 ]; then
10521073
do_test "In Cache" "incache" "-n ${page_size}k -g ${incache_maxfile}m -y 1k -q 1m"
@@ -1104,7 +1125,7 @@ invoke_test()
11041125
for ((run_number=1; run_number <= to_times_to_run ; run_number++))
11051126
do
11061127
analysis_dir=$results_dir/Run_${run_number}
1107-
mkdir -p ${analysis_dir}
1128+
make_dir ${analysis_dir}
11081129

11091130
# Loop over fstype
11101131

@@ -1184,8 +1205,7 @@ execute_it()
11841205
#
11851206
if [ ${incache_memory} -gt ${free_space} ]; then
11861207
echo data_dir $data_dir
1187-
echo "Error: Not enough disk space on this system to even run In Cache test. Cant continue ..."
1188-
exit 1
1208+
exit_out "Error: Not enough disk space on this system to even run In Cache test. Cant continue ..." 1
11891209
else
11901210
invoke_test
11911211
fi
@@ -1302,8 +1322,7 @@ obtain_disks()
13021322
if [[ $devices_to_use == "grab_disks" ]]; then
13031323
results=`${TOOLS_BIN}/grab_disks ${devices_to_use}`
13041324
if [ $? -ne 0 ]; then
1305-
echo grab disks failed.
1306-
exit 1
1325+
exit_out "grab disks failed." 1
13071326
fi
13081327
disks_found=`echo $results | cut -d: -f 2`
13091328
devices_to_use=`echo $results | cut -d: -f 1`
@@ -1319,17 +1338,15 @@ create_lvm()
13191338
lvm_devices=`echo $devices_to_use | sed "s/ /,/g"`
13201339
$TOOLS_BIN/lvm_create --devices ${lvm_devices} --lvm_vol iozone --lvm_grp iozone
13211340
if [ $? -ne 0 ]; then
1322-
echo lvm create failed, exiting
1323-
exit 1
1341+
exit_out "lvm create failed, exiting" 1
13241342
fi
13251343

13261344
mount_pnt=${mount_location}${mount_index}
1327-
mkdir -p ${mount_pnt} >& /dev/null
1345+
make_dir ${mount_pnt}
13281346
umount $mount_pnt >& /dev/null
13291347
$TOOLS_BIN/create_filesystem --fs_type $1 --mount_dir $mount_pnt --device /dev/iozone/iozone
13301348
if [ $? -ne 0 ]; then
1331-
echo create_filesystem failed, exiting
1332-
exit 1
1349+
exit_out "create_filesystem failed, exiting" 1
13331350
fi
13341351
mount_list=${mount_pnt}
13351352
let "mount_index=${mount_index}+1"
@@ -1542,8 +1559,7 @@ disk_size=`echo $to_configuration | cut -d'=' -f3 | cut -d'_' -f 1`
15421559
disk_numb=`echo $to_configuration | cut -d'=' -f4 | cut -d'_' -f 1`
15431560

15441561
if [ `id -u` -ne 0 ]; then
1545-
printf "You need to run as root\n"
1546-
exit 1
1562+
exit_out "You need to run as root" 1
15471563
fi
15481564

15491565
if [ $to_pbench -eq 1 ]; then
@@ -1573,22 +1589,19 @@ if [[ $results_dir == "" ]]; then
15731589
fi
15741590
fi
15751591

1576-
pushd $run_dir
1592+
pushd $run_dir >& /dev/null
15771593
gcc -Wall -Os -o create_file create_file.c
1578-
if [ -x "$run_dir/create_file" ]; then
1579-
echo "$run_dir/create_file"
1580-
else
1581-
echo Warning create_file did not build, aborting
1582-
exit 1
1594+
if [ ! -x "$run_dir/create_file" ]; then
1595+
exit_out "Error: create_file did not build, aborting" 1
15831596
fi
1584-
popd
1597+
popd >& /dev/null
15851598

15861599
obtain_disks
15871600

15881601
if [[ $to_sys_type != "" ]]; then
15891602
odir=results_iozone_$to_tuned_setting
15901603
out_dir="/tmp/${odir}"
1591-
mkdir $out_dir
1604+
make_dir $out_dir
15921605
exec &>> $out_dir/run_output
15931606
fi
15941607

@@ -1607,12 +1620,12 @@ if [[ $modes2run -eq 0 ]] || [[ $all_test -eq 1 ]]; then
16071620
fi
16081621

16091622
rm -rf ${results_dir} ${local_watchdog_file} >& /dev/null
1610-
mkdir ${results_dir} ${configdir}
1623+
make_dir ${results_dir}
1624+
make_dir ${configdir}
16111625
touch $buildrunlog
16121626

16131627
if [[ $mount_location = "" ]]; then
1614-
echo Need to designate a mount point
1615-
exit 1
1628+
exit_out "Need to designate a mount point" 1
16161629
fi
16171630

16181631
#
@@ -1628,13 +1641,12 @@ for fs in $filesystems; do
16281641
else
16291642
for device in $devices_to_use; do
16301643
mount_pnt=${mount_location}${mount_index}
1631-
mkdir -p ${mount_pnt} >& /dev/null
1644+
make_dir ${mount_pnt}
16321645
umount $mount_pnt >& /dev/null
16331646
wipefs $device
16341647
$TOOLS_BIN/create_filesystem --fs_type $fs --mount_dir $mount_pnt --device $device
16351648
if [ $? -ne 0 ]; then
1636-
echo create filesystem create failed.
1637-
exit 1
1649+
exit_out "echo create filesystem create failed." 1
16381650
fi
16391651
mount_list=${mount_list}${separ}${mount_pnt}
16401652
separ=" "
@@ -1670,16 +1682,16 @@ fi
16701682

16711683
# Archive results into single tarball
16721684
#
1673-
pushd /tmp > /dev/null
1685+
pushd /tmp >& /dev/null
16741686
archive_file="iozone-results.tar.gz"
16751687
cd `dirname ${results_dir}`
16761688
archive_dirname=./`basename ${results_dir}`
1677-
mkdir $archive_dirname
1689+
make_dir $archive_dirname
16781690
rm -f results_pbench.tar
16791691
echo mv /tmp/results.csv ${archive_dirname}
16801692
mv /tmp/results.csv ${archive_dirname}
16811693
find -L ${archive_dirname} -type f | tar --transform 's/.*\///g' -cf /tmp/results_pbench.tar --files-from=/dev/stdin
16821694
tar cf /tmp/results_iozone_${to_tuned_setting}.tar ${archive_dirname}
16831695
cp /tmp/${test_name}.out ${out_dir}
16841696
tar cf $odir.tar ${out_dir}
1685-
popd > /dev/null
1697+
popd >& /dev/null

0 commit comments

Comments
 (0)