Skip to content

Commit

Permalink
testsuite: abrt core dump file size limits
Browse files Browse the repository at this point in the history
Related: #1333068
  • Loading branch information
Jakub Filak committed Nov 2, 2016
1 parent c34837f commit 218ee2d
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/runtests/aux/test_order
Expand Up @@ -13,6 +13,7 @@ abrt-auto-reporting-sanity-authenticated
dumpdir_completedness
ccpp-plugin
ccpp-plugin-config
ccpp-plugin-core-size
# Remove me and revert to common python-addon test
# when rhel6's python hook stops sending "basename=pyhook" item:
python-addon
Expand Down
3 changes: 3 additions & 0 deletions tests/runtests/ccpp-plugin-core-size/PURPOSE
@@ -0,0 +1,3 @@
PURPOSE of ccpp-plugin-core-size
Description: Test ABRT's ability to limit core file size.
Author: Jakub Filak <jfilak@redhat.com>
40 changes: 40 additions & 0 deletions tests/runtests/ccpp-plugin-core-size/bigcore.c
@@ -0,0 +1,40 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <err.h>

int main(int argc, char *argv[])
{
long bufsize = 1024*1024;
long loops = 0;
int opt;

while ((opt = getopt(argc, argv, "M:")) != -1) {
switch (opt) {
case 'M':
loops = atoi(optarg);
break;
default:
errx(EXIT_FAILURE, "Usage: %s [-M MEGA]", argv[0]);

}
}

if (loops == 0) {
errx(EXIT_FAILURE, "Usage: %s [-M MEGA]", argv[0]);
}

for (int i = 0; i < loops; ++i) {
uint8_t *buf = (uint8_t *)malloc(bufsize * sizeof(uint8_t));

if (buf == NULL) {
err(EXIT_FAILURE, "malloc");
}
}

abort();

/* Dead code! */
exit(EXIT_FAILURE);
}
215 changes: 215 additions & 0 deletions tests/runtests/ccpp-plugin-core-size/runtest.sh
@@ -0,0 +1,215 @@
#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of ccpp-plugin-core-size
# Description: Test ABRT's ability to limit core file size.
# Author: Jakub Filak <jfilak@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2016 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.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

. /usr/share/beakerlib/beakerlib.sh
. ../aux/lib.sh

TEST="ccpp-plugin-core-size"
PACKAGE="abrt"
CRASHER="bigcore"
ABRT_CONF=/etc/abrt/abrt.conf
CCPP_CONF=/etc/abrt/plugins/CCpp.conf
AASPD_CONF=/etc/abrt/abrt-action-save-package-data.conf

function assert_file_size_min
{
rlAssertGreaterOrEqual "Minimal size of $1" $(stat -c "%s" $1) $2
}

function assert_file_size_max
{
rlAssertGreaterOrEqual "Maximal size of $1" $2 $(stat -c "%s" $1)
}

function run_test
{
rlRun "sed 's/#\? *\(MaxCrashReportsSize\).*$/\1 = '${ABRTD_LIMIT_MiB}'/' -i ${ABRT_CONF}"
rlRun "sed 's/#\? *\(MaxCoreFileSize\).*$/\1 = '${CCPP_LIMIT_MiB}'/' -i ${CCPP_CONF}"
rlRun "sed 's/#\? *\(MakeCompatCore\).*$/\1 = yes/' -i ${CCPP_CONF}"
rlRun "ulimit -c ${USER_LIMIT_kiB}"

prepare
rlRun "rm -f core*"

rlRun "./$CRASHER -M ${ALLOC_SIZE_MiB}" 134
wait_for_hooks
get_crash_path

rlAssertExists ${crash_PATH}/coredump
if [ $ABRT_REAL_LIMIT_MiB -eq 0 ]; then
assert_file_size_min ${crash_PATH}/coredump $((ABRT_REAL_LIMIT_MiB * 1024 * 1024))
else
assert_file_size_max ${crash_PATH}/coredump $((ABRT_REAL_LIMIT_MiB * 1024 * 1024))
fi

rlAssertExists ${crash_PATH}/pid
pid=$(cat ${crash_PATH}/pid)

if [ "0" == "${USER_LIMIT_kiB}" ]; then
rlAssertEquals "" "$(ls core*)" "No user core-files"
else
rlAssertExists core.${pid}
if [ "unlimited" == "${USER_LIMIT_kiB}" ]; then
assert_file_size_min core.${pid} $((ALLOC_SIZE_MiB * 1024 * 1024))
else
assert_file_size_max core.${pid} $((USER_LIMIT_kiB * 1024))
fi
fi

rlRun "abrt-cli rm $crash_PATH"
}

rlJournalStart
rlPhaseStartSetup
check_prior_crashes
load_abrt_conf

TmpDir=$(mktemp -d)
rlRun "gcc -Wall -std=gnu99 -pedantic -o $TmpDir/$CRASHER $CRASHER.c"
pushd $TmpDir

rlFileBackup $ABRT_CONF $CCPP_CONF $AASPD_CONF
rlRun "sed 's/#\? *\(ProcessUnpackaged\).*$/\1 = yes/' -i ${AASPD_CONF}"
rlPhaseEnd

rlPhaseStartTest "All unlimited"
ALLOC_SIZE_MiB=256

ABRTD_LIMIT_MiB=0
CCPP_LIMIT_MiB=0
ABRT_REAL_LIMIT_MiB=0

USER_LIMIT_kiB="unlimited"

run_test
rlPhaseEnd

rlPhaseStartTest "ABRTD limit - CCpp unlimited - User unlimited"
ALLOC_SIZE_MiB=256

ABRTD_LIMIT_MiB=128
CCPP_LIMIT_MiB=0
ABRT_REAL_LIMIT_MiB=128

USER_LIMIT_kiB="unlimited"

run_test
rlPhaseEnd

rlPhaseStartTest "ABRTD unlimited - CCpp limit - User unlimited"
ALLOC_SIZE_MiB=256

ABRTD_LIMIT_MiB=0
CCPP_LIMIT_MiB=128
ABRT_REAL_LIMIT_MiB=128

USER_LIMIT_kiB="unlimited"

run_test
rlPhaseEnd

rlPhaseStartTest "ABRTD greater than CCpp - User unlimited"
ALLOC_SIZE_MiB=256

ABRTD_LIMIT_MiB=256
CCPP_LIMIT_MiB=128
ABRT_REAL_LIMIT_MiB=128

USER_LIMIT_kiB="unlimited"

run_test
rlPhaseEnd

rlPhaseStartTest "ABRTD lower than CCpp - User unlimited"
ALLOC_SIZE_MiB=256

ABRTD_LIMIT_MiB=128
CCPP_LIMIT_MiB=256
ABRT_REAL_LIMIT_MiB=128

USER_LIMIT_kiB="unlimited"

run_test
rlPhaseEnd

rlPhaseStartTest "ABRTD equal to CCpp - User unlimited"
ALLOC_SIZE_MiB=256

ABRTD_LIMIT_MiB=128
CCPP_LIMIT_MiB=128
ABRT_REAL_LIMIT_MiB=128

USER_LIMIT_kiB="unlimited"

run_test
rlPhaseEnd

rlPhaseStartTest "ABRT greater than allocated - User unlimited"
ALLOC_SIZE_MiB=256

ABRTD_LIMIT_MiB=1024
CCPP_LIMIT_MiB=1024
ABRT_REAL_LIMIT_MiB=0

USER_LIMIT_kiB="unlimited"

run_test
rlPhaseEnd

rlPhaseStartTest "ABRT greater than User"
ALLOC_SIZE_MiB=256

ABRTD_LIMIT_MiB=0
CCPP_LIMIT_MiB=0
ABRT_REAL_LIMIT_MiB=0

USER_LIMIT_kiB="$((128 * 1024))"

run_test
rlPhaseEnd

rlPhaseStartTest "ABRT equal User"
ALLOC_SIZE_MiB=256

ABRTD_LIMIT_MiB=128
CCPP_LIMIT_MiB=128
ABRT_REAL_LIMIT_MiB=128

USER_LIMIT_kiB="$((128 * 1024))"

run_test
rlPhaseEnd

rlPhaseStartCleanup
rlFileRestore
rlBundleLogs abrt $(ls *.log)
popd # TmpDir
rm -rf $TmpDir
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

0 comments on commit 218ee2d

Please sign in to comment.