aba7ab1
#!/bin/bash
aba7ab1
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
aba7ab1
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aba7ab1
#
aba7ab1
#   runtest.sh of /CoreOS/libselinux/Sanity/selinux_boolean_sub-function
aba7ab1
#   Description: Test selinux_boolean_sub function
aba7ab1
#   Author: Jan Zarsky <jzarsky@redhat.com>
aba7ab1
#
aba7ab1
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aba7ab1
#
aba7ab1
#   Copyright (c) 2016 Red Hat, Inc.
aba7ab1
#
aba7ab1
#   This program is free software: you can redistribute it and/or
aba7ab1
#   modify it under the terms of the GNU General Public License as
aba7ab1
#   published by the Free Software Foundation, either version 2 of
aba7ab1
#   the License, or (at your option) any later version.
aba7ab1
#
aba7ab1
#   This program is distributed in the hope that it will be
aba7ab1
#   useful, but WITHOUT ANY WARRANTY; without even the implied
aba7ab1
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
aba7ab1
#   PURPOSE.  See the GNU General Public License for more details.
aba7ab1
#
aba7ab1
#   You should have received a copy of the GNU General Public License
aba7ab1
#   along with this program. If not, see http://www.gnu.org/licenses/.
aba7ab1
#
aba7ab1
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aba7ab1
aba7ab1
# Include Beaker environment
aba7ab1
. /usr/share/beakerlib/beakerlib.sh || exit 1
aba7ab1
aba7ab1
PACKAGE="libselinux"
aba7ab1
aba7ab1
rlJournalStart
aba7ab1
    rlPhaseStartSetup
aba7ab1
        rlAssertRpm ${PACKAGE}
aba7ab1
        rlAssertRpm ${PACKAGE}-devel
aba7ab1
        rlAssertRpm "glibc"
aba7ab1
        rlAssertRpm "gcc"
aba7ab1
aba7ab1
        rlRun -l "gcc test.c -o test -lselinux -Wall -Wextra -std=c99"
aba7ab1
    rlPhaseEnd
aba7ab1
aba7ab1
    rlPhaseStartTest
aba7ab1
        rlRun "./test NULL | tee output"
aba7ab1
        rlRun "grep 'selinux_boolean_sub: (null)' output"
aba7ab1
aba7ab1
        rlRun "./test my_nonexisting_record | tee output"
aba7ab1
        rlRun "grep 'selinux_boolean_sub: my_nonexisting_record' output"
aba7ab1
    
aba7ab1
        policy_type="$(grep -E '^SELINUXTYPE=' /etc/selinux/config | cut -c13- | tr '[:upper:]' '[:lower:]' | tr -d ' ')"
aba7ab1
        line1="$(cat /etc/selinux/$policy_type/booleans.subs_dist | head -n 1)"
aba7ab1
        line2="$(cat /etc/selinux/$policy_type/booleans.subs_dist | head -n 7 | tail -n 1)"
aba7ab1
        line3="$(cat /etc/selinux/$policy_type/booleans.subs_dist | tail -n 1)"
aba7ab1
aba7ab1
        input="$(echo $line1 | awk '{ print $1 }')"
aba7ab1
        output="$(echo $line1 | awk '{ print $2 }')"
aba7ab1
aba7ab1
        rlRun "./test $input | tee output"
aba7ab1
        rlRun "grep 'selinux_boolean_sub: $output' output"
aba7ab1
aba7ab1
        input="$(echo $line2 | awk '{ print $1 }')"
aba7ab1
        output="$(echo $line2 | awk '{ print $2 }')"
aba7ab1
aba7ab1
        rlRun "./test $input | tee output"
aba7ab1
        rlRun "grep 'selinux_boolean_sub: $output' output"
aba7ab1
aba7ab1
        input="$(echo $line3 | awk '{ print $1 }')"
aba7ab1
        output="$(echo $line3 | awk '{ print $2 }')"
aba7ab1
aba7ab1
        rlRun "./test $input | tee output"
aba7ab1
        rlRun "grep 'selinux_boolean_sub: $output' output"
aba7ab1
    rlPhaseEnd
aba7ab1
aba7ab1
    rlPhaseStartCleanup
aba7ab1
        rlRun "rm -f test output"
aba7ab1
    rlPhaseEnd
aba7ab1
rlJournalPrintText
aba7ab1
rlJournalEnd