| 1 | #!/bin/bash |
| 2 | |
| 3 | # Description: Test for openscap excessive memory consumption. |
| 4 | # Author: Matus Marhefka <[email protected]>, Jan Černý <[email protected]> |
| 5 | |
| 6 | set -e -o pipefail |
| 7 | |
| 8 | build_dir="../../build" |
| 9 | |
| 10 | profile="xccdf_org.ssgproject.content_profile_oom" |
| 11 | os_name=$(sed -nr "s/^NAME=\"?([^\"]*)\"?/\1/p" /etc/os-release) |
| 12 | os_version=$(sed -nr "s/^VERSION=\"?([^\"]*)\"?/\1/p" /etc/os-release) |
| 13 | |
| 14 | if [[ $os_name == "Red Hat Enterprise Linux"* ]] ; then |
| 15 | if [[ $os_version =~ ^7.* ]] ; then |
| 16 | tailoring="ssg-rhel7-oom-tailoring.xml" |
| 17 | ds="ssg-rhel7-ds.xml" |
| 18 | elif [[ $os_version =~ ^8.* ]] ; then |
| 19 | tailoring="ssg-rhel8-oom-tailoring.xml" |
| 20 | ds="ssg-rhel8-ds.xml" |
| 21 | else |
| 22 | echo "This test doesn't support $os_name $os_version" >&2 |
| 23 | exit 1 |
| 24 | fi |
| 25 | else |
| 26 | echo "This test doesn't support $os_name $os_version" >&2 |
| 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | # Extracting source datastream |
| 31 | rm -f "$ds" |
| 32 | bunzip2 -k "$ds.bz2" |
| 33 | |
| 34 | stderr="$(mktemp)" |
| 35 | |
| 36 | # Run oscap in "oscap_cgroup" on single CPU core and with limited memory |
| 37 | $build_dir/run cgexec -g "memory,cpuset:oscap_cgroup" $build_dir/utils/oscap xccdf eval --tailoring-file $tailoring --profile $profile --results $results --report $report $ds 2>$stderr || ret="$?" |
| 38 | |
| 39 | grep -qiE "(^E:|killed)" "$stderr" && exit 1 |
| 40 | rm -f "$stderr" |
| 41 | |
| 42 | dmesg_out="$(mktemp)" |
| 43 | dmesg -H | grep oscap &> "$dmesg_out" || ret="$?" |
| 44 | grep -qiE "(killed|out of memory|oom)" "$dmesg_out" && exit 1 |
| 45 | rm -f "$dmesg_out" |
| 46 | |
| 47 | rm -f "$ds" |