| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright 2015, 2016 International Business Machines |
| 5 |
# |
| 6 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
# you may not use this file except in compliance with the License. |
| 8 |
# You may obtain a copy of the License at |
| 9 |
# |
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
# |
| 12 |
# Unless required by applicable law or agreed to in writing, software |
| 13 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
# See the License for the specific language governing permissions and |
| 16 |
# limitations under the License. |
| 17 |
# |
| 18 |
|
| 19 |
# |
| 20 |
# Purpose: Test hardware-accelerated compression/decompression for |
| 21 |
# identical results after 1 or more compression/decompression |
| 22 |
# iteration(s) of a given set of test files. |
| 23 |
|
| 24 |
# |
| 25 |
# Environment variables for the hardware compression zlib by default |
| 26 |
# distribute workload over all plugged cards. |
| 27 |
# |
| 28 |
|
| 29 |
export ZLIB_ACCELERATOR=GENWQE |
| 30 |
export ZLIB_CARD=-1 |
| 31 |
|
| 32 |
# Directories used |
| 33 |
INSTALL_DIR="/usr" # Tool RPM install directory |
| 34 |
TEST_DATA=${INSTALL_DIR}/share/testdata/testdata.tar.gz |
| 35 |
TMP_DIR="/tmp" # Temporary directory to use |
| 36 |
DATA_DIR="${TMP_DIR}/$$_testdata" # directory for testdata |
| 37 |
ORIG_DATA="${TMP_DIR}/orig" # directory for original data |
| 38 |
GZIPTOOL="genwqe_gzip" |
| 39 |
GUNZIPTOOL="genwqe_gunzip" |
| 40 |
|
| 41 |
# GenWQE Global values |
| 42 |
DEVICE_ID=":044b" |
| 43 |
SUPPORTED_APPID="GZIP" |
| 44 |
DRIVER_PREFIX=genwqe |
| 45 |
DRIVER=${DRIVER_PREFIX}_card |
| 46 |
PROGRAM=`basename $0` |
| 47 |
CWD=`pwd` |
| 48 |
ERRLOG=${TMP_DIR}/${PROGRAM}_$$_err.log |
| 49 |
CLASS_PATH="/sys/class/${DRIVER_PREFIX}/" |
| 50 |
|
| 51 |
# GenWQE add supported bit stream for version strings to this array: |
| 52 |
BIT_STREAMS=( 00000b0330342260.00000002475a4950 \ |
| 53 |
0000000330353090.00000002475a4950 ) |
| 54 |
|
| 55 |
# Helper variables |
| 56 |
driver_check=1 # flag for GenWQE card driver |
| 57 |
iterations=100 # holds the number of repeats |
| 58 |
nr_instances=10 # number of parallel tests |
| 59 |
version="https://github.com/ibm-genwqe/genwqe-user" |
| 60 |
runpids= |
| 61 |
verbose=0 |
| 62 |
bitstream_warning=1 |
| 63 |
|
| 64 |
# Print helper function to output test depending on verbose flag |
| 65 |
function printv() { |
| 66 |
if [ $verbose -gt 0 ]; then |
| 67 |
echo $* |
| 68 |
fi |
| 69 |
} |
| 70 |
|
| 71 |
# Helper function to stop any running workload jobs |
| 72 |
function stop_jobs() { |
| 73 |
JOBS=`jobs -rp` |
| 74 |
printv "Running: "$JOBS |
| 75 |
printv "Expected: ${runpids}" |
| 76 |
printv "Wait while terminating jobs..." |
| 77 |
kill -n 15 $JOBS |
| 78 |
sleep 2 |
| 79 |
wait |
| 80 |
JOBS=`jobs -rp` |
| 81 |
printv "Still running: "$JOBS |
| 82 |
runpids="" |
| 83 |
cleanup |
| 84 |
} |
| 85 |
|
| 86 |
# Cleanup helper function called when CTRL-C is pressed or process is killed |
| 87 |
function cleanup() { |
| 88 |
rm -rf ${DATA_DIR}_* |
| 89 |
rm -f ${ORIG_DATA}/.lock_$$ # remove own lockfile which frees the |
| 90 |
# orig data for own process |
| 91 |
LOCKFILES=`ls ${ORIG_DATA}/.lock* 2>/dev/null` |
| 92 |
if [ "$LOCKFILES" == "" ]; then # all lock files removed? |
| 93 |
printv "Cleaning up source data..." |
| 94 |
rm -rf ${ORIG_DATA} |
| 95 |
unset ZLIB_CARD |
| 96 |
printv "Done" |
| 97 |
fi |
| 98 |
} |
| 99 |
|
| 100 |
trap stop_jobs SIGINT |
| 101 |
trap stop_jobs SIGKILL |
| 102 |
|
| 103 |
# Print usage message helper function |
| 104 |
function usage() { |
| 105 |
echo "Usage of $PROGRAM:" |
| 106 |
echo " [-h] Print this help message." |
| 107 |
echo " [-s] Run on software zlib if ${DRIVER} is not loaded." |
| 108 |
echo " [-S] Run on software zlib even if ${DRIVER} is loaded." |
| 109 |
echo " [-i] <iterations> repeat multiple times for more testing." |
| 110 |
echo " Default: 100" |
| 111 |
echo " [-p] <number of instances> of this test to run in parallel." |
| 112 |
echo " Default: 10" |
| 113 |
echo " [-A] <accelerator> use either GENWQE for the PCIe and CAPI for" |
| 114 |
echo " CAPI based solution available only on System p" |
| 115 |
echo " Use SW to use software compress/decompression" |
| 116 |
echo " [-C] <card> set the compression card to use (0, 1, ... )." |
| 117 |
echo " RED (or -1) drive work to all available cards." |
| 118 |
echo " [-t] <testdata.tar.gz> Define alternate for test-data.tar.gz." |
| 119 |
echo " [-v] Print status and informational output." |
| 120 |
echo " -vv for more verbosity" |
| 121 |
echo " [-V] Print program version (${version})" |
| 122 |
echo |
| 123 |
} |
| 124 |
|
| 125 |
# Check for tools availability |
| 126 |
function check_tools |
| 127 |
{ |
| 128 |
for t in ${GZIPTOOL} ${GUNZIPTOOL} ; do |
| 129 |
echo -n "Checking if ${t} is there ... " |
| 130 |
if [ ! -x `which ${t}` ]; then |
| 131 |
echo "failure" |
| 132 |
exit -3; |
| 133 |
fi |
| 134 |
echo "ok" |
| 135 |
done |
| 136 |
} |
| 137 |
|
| 138 |
# Check for and create directory holding the original data. |
| 139 |
# Pass location of original data to this function. |
| 140 |
function prep_orig_data() |
| 141 |
{ |
| 142 |
local d=$1 |
| 143 |
local data=`basename $d` |
| 144 |
|
| 145 |
printv "Preparing data..." |
| 146 |
|
| 147 |
if [ ! -f ${d} ]; then |
| 148 |
echo "Testdata \"${d}\" is missing. Please install it first."; |
| 149 |
echo |
| 150 |
echo "E.g.:"; |
| 151 |
echo " wget http://corpus.canterbury.ac.nz/resources/cantrbry.tar.gz"; |
| 152 |
echo " sudo mkdir -p ${INSTALL_DIR}/share/testdata/"; |
| 153 |
echo " sudo cp cantrbry.tar.gz ${d}"; |
| 154 |
echo |
| 155 |
exit -1; |
| 156 |
fi |
| 157 |
|
| 158 |
if [ ! -d ${ORIG_DATA} ]; then |
| 159 |
mkdir -p $ORIG_DATA |
| 160 |
fi |
| 161 |
cp ${d} ${ORIG_DATA} |
| 162 |
cd ${ORIG_DATA} |
| 163 |
tar zxf ${data} |
| 164 |
rm -f ${ORIG_DATA}/${data} |
| 165 |
} |
| 166 |
|
| 167 |
function ffdc_msg_and_cleanup() |
| 168 |
{ |
| 169 |
ls -alR ${ORIG_DATA} ${WORK_DIR} >> $ERRLOG; |
| 170 |
echo "---------------- dmesg output -------------" >> $ERRLOG; |
| 171 |
dmesg >> $ERRLOG; |
| 172 |
echo " ========= END OF LOG `date`==========" >> $ERRLOG; |
| 173 |
echo "$ERRLOG has been written." |
| 174 |
echo "Open an IBM-internal defect against $DRIVER development," |
| 175 |
echo "copy all console messages related to the error" |
| 176 |
echo "and attach $ERRLOG. Thanks." |
| 177 |
rm -rf ${WORK_DIR} |
| 178 |
} |
| 179 |
|
| 180 |
# Check for and create working directories. |
| 181 |
# These are deleted upon script termination. |
| 182 |
function prep_work_and_run_load() |
| 183 |
{ |
| 184 |
WORK_DIR="${DATA_DIR}_$1" |
| 185 |
if [ ! -d ${WORK_DIR} ]; then |
| 186 |
mkdir -p $WORK_DIR |
| 187 |
fi |
| 188 |
touch ${ORIG_DATA}/.lock_$$ # mark source data as 'in use' |
| 189 |
cp -r * ${WORK_DIR}/ |
| 190 |
cd ${WORK_DIR} |
| 191 |
# Compress/decompress and compare in each iteration |
| 192 |
for i in `seq 1 $iterations` ; do |
| 193 |
if [ $verbose -gt 1 ]; then |
| 194 |
echo " Run #$i/Instance_$1 : unpacking, packing, comparing... "; |
| 195 |
fi |
| 196 |
for file in `ls`; do |
| 197 |
${GZIPTOOL} $file; |
| 198 |
rc=$? |
| 199 |
if [ $rc -ne 0 ]; then |
| 200 |
echo "$PROGRAM: ERROR - ${GZIPTOOL} returned RC=$rc" \ |
| 201 |
| tee $ERRLOG |
| 202 |
ffdc_msg_and_cleanup |
| 203 |
exit -4 |
| 204 |
fi |
| 205 |
done |
| 206 |
for file in `ls`; do |
| 207 |
${GUNZIPTOOL} $file; |
| 208 |
rc=$? |
| 209 |
if [ $rc -ne 0 ]; then |
| 210 |
echo "$PROGRAM: ERROR - ${GUNZIPTOOL} returned RC=$rc" \ |
| 211 |
|tee $ERRLOG |
| 212 |
ffdc_msg_and_cleanup |
| 213 |
exit -5 |
| 214 |
fi |
| 215 |
done |
| 216 |
for file in `ls`; do |
| 217 |
diff -q $file ${ORIG_DATA}/$file; |
| 218 |
rc=$? |
| 219 |
if [ $rc -ne 0 ]; then |
| 220 |
echo "$PROGRAM: ERROR - miscompare in run # $i/Instance $1:" \ |
| 221 |
"File ${WORK_DIR}/$file after successful compression" \ |
| 222 |
"decompression" | tee $ERRLOG; |
| 223 |
ffdc_msg_and_cleanup |
| 224 |
exit -6 |
| 225 |
fi |
| 226 |
done |
| 227 |
done |
| 228 |
} |
| 229 |
|
| 230 |
# Checks an input bitstream value against a fixed list of bit stream versions |
| 231 |
# in the way that global value bitstream_warning is set as follows |
| 232 |
# 0 if the bit stream is among the versions $DRIVER supports |
| 233 |
# 1 if an unsupported bit stream version is on the PCIe card |
| 234 |
# Parameters: 1. bit stream value of card to verify |
| 235 |
# 2. Application ID (String) of card to verify, 'GZIP' for comp. |
| 236 |
function is_supported() |
| 237 |
{ |
| 238 |
if [ "$2" != "${SUPPORTED_APPID}" ]; then |
| 239 |
# ignore an unsupported appid, prevent bitstream warning |
| 240 |
bitstream_warning=0; |
| 241 |
else |
| 242 |
for i in `seq 0 $((${#BIT_STREAMS[@]}-1))`; do |
| 243 |
if [ "$1" == "${BIT_STREAMS[$i]}" ]; then |
| 244 |
bitstream_warning=0; |
| 245 |
fi |
| 246 |
done |
| 247 |
fi |
| 248 |
} |
| 249 |
|
| 250 |
# GenWQE Prerequisite: The genwqe driver needs to be loaded for this |
| 251 |
# function to be able to check the bit stream version |
| 252 |
# |
| 253 |
function genwqe_check_supported_bitstream_versions() |
| 254 |
{ |
| 255 |
if [ $ZLIB_CARD -ge 0 ]; then |
| 256 |
# check APPID |
| 257 |
appid=`cat ${CLASS_PATH}${DRIVER_PREFIX}${ZLIB_CARD}_card/appid` |
| 258 |
# check bit stream version for a specific virtual or physical Function |
| 259 |
ver=`cat ${CLASS_PATH}${DRIVER_PREFIX}${ZLIB_CARD}_card/version` |
| 260 |
is_supported $ver $appid |
| 261 |
else |
| 262 |
# ZLIB_CARD is set to -1. Thus run against all cards, to |
| 263 |
# check the bit streams. |
| 264 |
# Determine the number of cards via lspci |
| 265 |
NR_CARDS=`lspci -d$DEVICE_ID|wc -l` |
| 266 |
for i in `seq 0 $((NR_CARDS - 1))`; do |
| 267 |
appid=`cat ${CLASS_PATH}${DRIVER_PREFIX}${i}_card/appid` |
| 268 |
ver=`cat ${CLASS_PATH}${DRIVER_PREFIX}${i}_card/version` |
| 269 |
is_supported $ver $appid |
| 270 |
done |
| 271 |
fi |
| 272 |
} |
| 273 |
|
| 274 |
# Parse any options given on the command line |
| 275 |
while getopts "t:A:vVhsSi:C:p:" opt; do |
| 276 |
case ${opt} in |
| 277 |
s) |
| 278 |
driver_check=0; |
| 279 |
;; |
| 280 |
S) |
| 281 |
driver_check=0; |
| 282 |
# use software zlib rather than hardware. |
| 283 |
GZIPTOOL=gzip; |
| 284 |
GUNZIPTOOL=gunzip; |
| 285 |
;; |
| 286 |
i) |
| 287 |
iterations=${OPTARG}; |
| 288 |
;; |
| 289 |
p) |
| 290 |
nr_instances=${OPTARG}; |
| 291 |
;; |
| 292 |
t) |
| 293 |
TEST_DATA=${OPTARG}; |
| 294 |
;; |
| 295 |
A) |
| 296 |
export ZLIB_ACCELERATOR=${OPTARG}; |
| 297 |
;; |
| 298 |
C) |
| 299 |
ZLIB_CARD=${OPTARG}; |
| 300 |
if [ "${OPTARG}" == "-1" -o "${OPTARG}" == "RED" ]; then |
| 301 |
ZLIB_CARD=-1; |
| 302 |
fi |
| 303 |
;; |
| 304 |
v) |
| 305 |
verbose+=1; |
| 306 |
;; |
| 307 |
V) |
| 308 |
echo "${version}" |
| 309 |
exit 0; |
| 310 |
;; |
| 311 |
h) |
| 312 |
usage; |
| 313 |
exit 0; |
| 314 |
;; |
| 315 |
\?) |
| 316 |
echo "ERROR: Invalid option: -$OPTARG" >&2 |
| 317 |
exit 1; |
| 318 |
;; |
| 319 |
esac |
| 320 |
done |
| 321 |
|
| 322 |
# Start of main program |
| 323 |
|
| 324 |
if [ $ZLIB_ACCELERATOR == "GENWQE" ]; then |
| 325 |
# warn user if the hardware acceleration for compression/decompression |
| 326 |
# is not ready |
| 327 |
driver_loaded=`lsmod|grep $DRIVER` |
| 328 |
if [ ${driver_check} -eq 1 ]; then |
| 329 |
if [ "${driver_loaded}" = "" ]; then |
| 330 |
echo "WARNING: ${DRIVER} is not loaded." \ |
| 331 |
"No Hardware compression available!" |
| 332 |
exit -2; |
| 333 |
fi |
| 334 |
fi |
| 335 |
if [ "${driver_loaded}" != "" -a ${driver_check} -eq 1 ]; then |
| 336 |
genwqe_check_supported_bitstream_versions $ZLIB_CARD |
| 337 |
if [ $bitstream_warning -eq 1 ]; then |
| 338 |
2>&1 echo "ERROR: Unsupported FPGA image (bitstream) detected on one" \ |
| 339 |
"or more cards." |
| 340 |
2>&1 echo " Check the bitstream versions on all of your cards and" |
| 341 |
2>&1 echo " update to a supported version for the compression" \ |
| 342 |
"solution." |
| 343 |
exit -3; |
| 344 |
fi |
| 345 |
fi |
| 346 |
fi |
| 347 |
|
| 348 |
|
| 349 |
# Check if tools are available |
| 350 |
check_tools |
| 351 |
|
| 352 |
# provide source data |
| 353 |
prep_orig_data ${TEST_DATA} |
| 354 |
|
| 355 |
TStart=`date +%s` |
| 356 |
|
| 357 |
# Main part of test driving workload to card or software zlib |
| 358 |
for i in `seq 1 $nr_instances`; do |
| 359 |
prep_work_and_run_load $i & |
| 360 |
newpid=$! |
| 361 |
if [ $verbose -ge 2 ]; then echo "NewPID: $newpid"; fi |
| 362 |
runpids=$runpids" "$newpid |
| 363 |
if [ $verbose -ge 2 ]; then printv "RunPIDs: $runpids"; fi |
| 364 |
done |
| 365 |
|
| 366 |
# Workload is kicked off, wait for it to finish |
| 367 |
printv "Waiting for jobs to terminate ..." |
| 368 |
wait |
| 369 |
|
| 370 |
# Calculate duration |
| 371 |
TEnd=`date +%s` |
| 372 |
T=`expr ${TEnd} - ${TStart}` |
| 373 |
printv "Runtime: $((T/3600%24)):$((T/60%60)):$((T%60)) [H:M:S]" |
| 374 |
|
| 375 |
# Cleanup the test data and the copy of original data |
| 376 |
cleanup |
| 377 |
|
| 378 |
exit 0 |