File: genwqe_test_gz

package info (click to toggle)
genwqe-user 4.0.18-3
  • links: PTS
  • area: main
  • in suites: buster
  • size: 1,440 kB
  • ctags: 2,978
  • sloc: ansic: 17,497; sh: 2,157; makefile: 406
file content (378 lines) | stat: -rwxr-xr-x 11,399 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#!/bin/bash

#
# Copyright 2015, 2016 International Business Machines
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# Purpose: Test hardware-accelerated compression/decompression for 
#          identical results after 1 or more compression/decompression
#          iteration(s) of a given set of test files.

#
# Environment variables for the hardware compression zlib by default
# distribute workload over all plugged cards.
#

export ZLIB_ACCELERATOR=GENWQE
export ZLIB_CARD=-1

# Directories used
INSTALL_DIR="/usr"                           # Tool RPM install directory
TEST_DATA=${INSTALL_DIR}/share/testdata/testdata.tar.gz
TMP_DIR="/tmp"                               # Temporary directory to use
DATA_DIR="${TMP_DIR}/$$_testdata"            # directory for testdata
ORIG_DATA="${TMP_DIR}/orig"                  # directory for original data
GZIPTOOL="genwqe_gzip"
GUNZIPTOOL="genwqe_gunzip"

# GenWQE Global values
DEVICE_ID=":044b"
SUPPORTED_APPID="GZIP"
DRIVER_PREFIX=genwqe
DRIVER=${DRIVER_PREFIX}_card
PROGRAM=`basename $0`
CWD=`pwd`
ERRLOG=${TMP_DIR}/${PROGRAM}_$$_err.log
CLASS_PATH="/sys/class/${DRIVER_PREFIX}/"

# GenWQE add supported bit stream for version strings to this array:
BIT_STREAMS=( 00000b0330342260.00000002475a4950 \
              0000000330353090.00000002475a4950 )

# Helper variables
driver_check=1                               # flag for GenWQE card driver
iterations=100                               # holds the number of repeats
nr_instances=10                              # number of parallel tests
version="https://github.com/ibm-genwqe/genwqe-user"
runpids=
verbose=0
bitstream_warning=1

# Print helper function to output test depending on verbose flag
function printv() {
    if [ $verbose -gt 0 ]; then
        echo $*
    fi    
}

# Helper function to stop any running workload jobs
function stop_jobs() {
    JOBS=`jobs -rp`
    printv "Running: "$JOBS
    printv "Expected: ${runpids}"
    printv "Wait while terminating jobs..."
    kill -n 15 $JOBS
    sleep 2 
    wait
    JOBS=`jobs -rp`
    printv "Still running: "$JOBS
    runpids=""
    cleanup
}

# Cleanup helper function called when CTRL-C is pressed or process is killed
function cleanup() {
  rm -rf ${DATA_DIR}_*
  rm -f ${ORIG_DATA}/.lock_$$         # remove own lockfile which frees the
                                      # orig data for own process
  LOCKFILES=`ls ${ORIG_DATA}/.lock* 2>/dev/null`
  if [ "$LOCKFILES" == "" ]; then     # all lock files removed?
      printv "Cleaning up source data..."
      rm -rf ${ORIG_DATA}
      unset ZLIB_CARD
      printv "Done"
  fi
}
  
trap stop_jobs SIGINT
trap stop_jobs SIGKILL

# Print usage message helper function
function usage() {
    echo "Usage of $PROGRAM:"
    echo "    [-h] Print this help message."
    echo "    [-s] Run on software zlib if ${DRIVER} is not loaded."
    echo "    [-S] Run on software zlib even if ${DRIVER} is loaded."
    echo "    [-i] <iterations>  repeat multiple times for more testing."
    echo "         Default: 100"
    echo "    [-p] <number of instances> of this test to run in parallel."
    echo "         Default: 10"
    echo "    [-A] <accelerator> use either GENWQE for the PCIe and CAPI for"
    echo "         CAPI based solution available only on System p"
    echo "         Use SW to use software compress/decompression"
    echo "    [-C] <card> set the compression card to use (0, 1, ... )."
    echo "         RED (or -1) drive work to all available cards."
    echo "    [-t] <testdata.tar.gz> Define alternate for test-data.tar.gz."
    echo "    [-v] Print status and informational output."
    echo "         -vv for more verbosity"
    echo "    [-V] Print program version (${version})"
    echo
}

# Check for tools availability
function check_tools
{
    for t in ${GZIPTOOL} ${GUNZIPTOOL} ; do
	echo -n "Checking if ${t} is there ... "
	if [ ! -x `which ${t}` ]; then
	    echo "failure"
	    exit -3;
	fi
	echo "ok"
    done
}

# Check for and create directory holding the original data.
# Pass location of original data to this function.
function prep_orig_data()
{
    local d=$1
    local data=`basename $d`

    printv "Preparing data..."

    if [ ! -f ${d} ]; then
	echo "Testdata \"${d}\" is missing. Please install it first.";
	echo
	echo "E.g.:";
	echo "  wget http://corpus.canterbury.ac.nz/resources/cantrbry.tar.gz";
	echo "  sudo mkdir -p ${INSTALL_DIR}/share/testdata/";
	echo "  sudo cp cantrbry.tar.gz ${d}";
	echo
	exit -1;
    fi

    if [ ! -d ${ORIG_DATA} ]; then
        mkdir -p $ORIG_DATA
    fi
    cp ${d} ${ORIG_DATA}
    cd ${ORIG_DATA}
    tar zxf ${data}
    rm -f ${ORIG_DATA}/${data}
}

function ffdc_msg_and_cleanup()
{
        ls -alR ${ORIG_DATA} ${WORK_DIR} >> $ERRLOG;
        echo "---------------- dmesg output -------------" >> $ERRLOG;
        #dmesg >> $ERRLOG;
        echo " ========= END OF LOG     `date`==========" >> $ERRLOG;
        echo "$ERRLOG has been written."
        echo "Open an IBM-internal defect against $DRIVER development,"
        echo "copy all console messages related to the error"
        echo "and attach $ERRLOG. Thanks."
	rm -rf ${WORK_DIR}
}

# Check for and create working directories.
# These are deleted upon script termination.
function prep_work_and_run_load()
{
    WORK_DIR="${DATA_DIR}_$1"
    if [ ! -d ${WORK_DIR} ]; then
        mkdir -p $WORK_DIR
    fi
    touch ${ORIG_DATA}/.lock_$$     # mark source data as 'in use'
    cp -r * ${WORK_DIR}/
    cd ${WORK_DIR}
    # Compress/decompress and compare in each iteration
    for i in `seq 1 $iterations` ; do
        if [ $verbose -gt 1 ]; then
	    echo  "  Run #$i/Instance_$1 : unpacking, packing, comparing... ";
	fi
        for file in `ls`; do
	    ${GZIPTOOL} $file;
	    rc=$?
	    if [ $rc -ne 0 ]; then
	        echo "$PROGRAM: ERROR - ${GZIPTOOL} returned RC=$rc"     \
                 | tee $ERRLOG
		ffdc_msg_and_cleanup
		exit -4
            fi
        done
        for file in `ls`; do
            ${GUNZIPTOOL} $file;
            rc=$?
            if [ $rc -ne 0 ]; then
	        echo "$PROGRAM: ERROR - ${GUNZIPTOOL} returned RC=$rc"   \
                |tee $ERRLOG
		ffdc_msg_and_cleanup
		exit -5
            fi
	done
        for file in `ls`; do
            diff -q $file ${ORIG_DATA}/$file;
	    rc=$?
            if [ $rc -ne 0 ]; then
                echo "$PROGRAM: ERROR - miscompare in run # $i/Instance $1:"   \
                     "File ${WORK_DIR}/$file after successful compression"     \
                     "decompression" | tee $ERRLOG;
                ffdc_msg_and_cleanup
                exit -6
            fi
        done
    done
}

# Checks an input bitstream value against a fixed list of bit stream versions
# in the way that global value bitstream_warning is set as follows
#    0    if the bit stream is among the versions $DRIVER supports
#    1    if an unsupported bit stream version is on the PCIe card
# Parameters:    1. bit stream value of card to verify
#                2. Application ID (String) of card to verify, 'GZIP' for comp.
function is_supported()
{
    if [ "$2" != "${SUPPORTED_APPID}" ]; then
        # ignore an unsupported appid, prevent bitstream warning
        bitstream_warning=0;
    else
        for i in `seq 0 $((${#BIT_STREAMS[@]}-1))`; do
            if [ "$1" == "${BIT_STREAMS[$i]}" ]; then
                bitstream_warning=0;
	    fi
        done
    fi
}

# GenWQE Prerequisite: The genwqe driver needs to be loaded for this
#                      function to be able to check the bit stream version
#
function genwqe_check_supported_bitstream_versions()
{
    if [ $ZLIB_CARD -ge 0 ]; then
        # check APPID
	appid=`cat ${CLASS_PATH}${DRIVER_PREFIX}${ZLIB_CARD}_card/appid`
        # check bit stream version for a specific virtual or physical Function
	ver=`cat ${CLASS_PATH}${DRIVER_PREFIX}${ZLIB_CARD}_card/version`
	is_supported $ver $appid
    else
        # ZLIB_CARD is set to -1. Thus run against all cards, to
	# check the bit streams.
        # Determine the number of cards via lspci
        NR_CARDS=`lspci -d$DEVICE_ID|wc -l`
        for i in `seq 0 $((NR_CARDS - 1))`; do
            appid=`cat ${CLASS_PATH}${DRIVER_PREFIX}${i}_card/appid`
            ver=`cat ${CLASS_PATH}${DRIVER_PREFIX}${i}_card/version`
	    is_supported $ver $appid
        done
    fi
}

# Parse any options given on the command line
while getopts "t:A:vVhsSi:C:p:" opt; do
    case ${opt} in
        s)
	    driver_check=0;
	    ;;
        S)
	    driver_check=0;
	    # use software zlib rather than hardware.
            GZIPTOOL=gzip;
            GUNZIPTOOL=gunzip;
	    ;;
        i)
            iterations=${OPTARG};
            ;;
        p)
            nr_instances=${OPTARG};
            ;;
        t)
            TEST_DATA=${OPTARG};
            ;;
        A)
            export ZLIB_ACCELERATOR=${OPTARG};
	    ;;
	C)
	    ZLIB_CARD=${OPTARG};
            if [ "${OPTARG}" == "-1" -o  "${OPTARG}" == "RED" ]; then
                ZLIB_CARD=-1;
            fi
	    ;;
        v)
            verbose+=1;
            ;;
        V)
            echo "${version}"
            exit 0;
            ;;
        h)
            usage;
            exit 0;
            ;;
        \?)
            echo "ERROR: Invalid option: -$OPTARG" >&2
            exit 1;
            ;;
    esac
done

# Start of main program

if [ $ZLIB_ACCELERATOR == "GENWQE" ]; then
# warn user if the hardware acceleration for compression/decompression
# is not ready
    driver_loaded=`lsmod|grep $DRIVER`
    if [ ${driver_check} -eq 1 ]; then
	if [ "${driver_loaded}" = "" ]; then
	    echo "WARNING: ${DRIVER} is not loaded." \
		"No Hardware compression available!"
	    exit -2;
	fi
    fi
    if [ "${driver_loaded}" != "" -a ${driver_check} -eq 1 ]; then
	genwqe_check_supported_bitstream_versions $ZLIB_CARD
	if [ $bitstream_warning -eq 1 ]; then
	    2>&1 echo "ERROR: Unsupported FPGA image (bitstream) detected on one"  \
		"or more cards."
	    2>&1 echo "       Check the bitstream versions on all of your cards and"
	    2>&1 echo "       update to a supported version for the compression"   \
		"solution."
	    exit -3;
	fi
    fi
fi


# Check if tools are available
check_tools

# provide source data
prep_orig_data ${TEST_DATA}

TStart=`date +%s`

# Main part of test driving workload to card or software zlib
for i in `seq 1 $nr_instances`; do
    prep_work_and_run_load $i &
    newpid=$!
    if [ $verbose -ge 2 ]; then echo "NewPID:    $newpid"; fi
    runpids=$runpids" "$newpid
    if [ $verbose -ge 2 ]; then printv "RunPIDs:   $runpids"; fi
done

# Workload is kicked off, wait for it to finish
printv "Waiting for jobs to terminate ..."
wait

# Calculate duration
TEnd=`date +%s`
T=`expr ${TEnd} - ${TStart}`
printv  "Runtime: $((T/3600%24)):$((T/60%60)):$((T%60)) [H:M:S]"

# Cleanup the test data and the copy of original data
cleanup

exit 0