#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/openCryptoki/Regression/bz612274-Opencryptoki-session-object-performance-degradation
# Description: Tests if overall performance of cryptographic operations degrades exponentially with the number of objects per token or open sessions per process
# Author: Miroslav Vadkerti <mvadkert@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2010 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include rhts environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="opencryptoki"
PACKAGES="gcc automake libtool openssl-devel expect"
TMPDIR=`mktemp -d`
TMP=`mktemp`
SRC="src.tbz"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
for PKG in $PACKAGES; do
rlAssertRpm $PKG
done
PKGVER=`rpm -q --qf '%{VERSION}' opencryptoki`
rlServiceStart "pkcsslotd"
# use always software slot
# SLOT=$(($(pkcsconf -s | grep -B1 Soft | grep -o '#[0-9]' | tr -d '#')-1))
SLOT=$(pkcsconf -s | egrep -B1 '(Soft|Linux)' | grep -o '#[0-9]' | tr -d '#')
rlLog "Using slot $SLOT"
rlRun "pushd ."
rlRun "cd $TMPDIR"
rlFetchSrcForInstalled opencryptoki
rlRun "yum-builddep -y opencryptoki*src.rpm"
rlRun "rpm -i opencryptoki*src.rpm"
# opencryptoki version >= 3.11.0 needs to enable building test cases during the pkg build
rlRun "sed -i 's/^%configure /%configure --enable-testcases /' ~/rpmbuild/SPECS/opencryptoki.spec"
rlRun "rpmbuild -bp ~/rpmbuild/SPECS/opencryptoki.spec" 0 "Preparing builddir"
TESTDIR=`ls -d ~/rpmbuild/BUILD/opencryptoki*/testcases`
rlRun "pushd . && cd $TESTDIR"
rlRun "sed -i 's/50000/10000/g' pkcs11/sess_perf.c" 0 "Adjusting testcase"
rlRun "rpmbuild -bc --short-circuit ~/rpmbuild/SPECS/opencryptoki.spec" 0 "Building opencryptoki files"
popd
rlPhaseEnd
rlPhaseStartTest
cd $TESTDIR
if [ -d driver ]; then
rlRun "cd driver"
rlRun "./sess_perf_tests -slot $SLOT | tee $TMP"
else
rlRun "cd pkcs11"
rlRun "./sess_bench -slot $SLOT | tee $TMP"
fi
rlRun "cat $TMP | grep CKR" 1 "Checking for errors"
# Count the number occurrences when performance test time exceeds >10ms
# In buggy version this will happen a lot and the performance will degrade.
# The count (3) currently tested may need more adjustment.
COUNT=$(cat $TMP | grep Time | egrep -c '[0-9][0-9]+')
rlAssertGreater "Checking performance" 3 $COUNT
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -rf $TMPDIR $TMP"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd