~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to tests/stress/parser/stress.sh

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
PROFILE_COUNT=1000
 
4
KEEP_FILES=0
 
5
LOAD_PROFILES=0
 
6
STRESS_ARGS=
 
7
APPARMOR_PARSER="/sbin/apparmor_parser"
 
8
 
 
9
usage () {
 
10
        echo 'stress.sh [-klh] [-c count] [-s seed] [-p parser]'
 
11
        echo '  -c count        generate _count_ number of profiles'
 
12
        echo '  -h              usage (this message)'
 
13
        echo '  -k              keep files after completion'
 
14
        echo '  -l              attempt to load profiles into kernel'
 
15
        echo '  -p parser       use _parser_ instead of /sbin/apparmor_parser'
 
16
        echo '  -s seed use _seed_ as random seed value'
 
17
        echo '$Id$'
 
18
        exit 0
 
19
}
 
20
 
 
21
while getopts 'klc:s:p:h' OPTION ; do
 
22
        case $OPTION in
 
23
            k) KEEP_FILES=1
 
24
               ;;
 
25
            l) LOAD_PROFILES=1
 
26
               ;;
 
27
            c) PROFILE_COUNT=$OPTARG
 
28
               ;;
 
29
            s) STRESS_ARGS="${STRESS_ARGS} -s ${OPTARG}"
 
30
               ;;
 
31
            p) APPARMOR_PARSER=$OPTARG
 
32
               ;;
 
33
            h) usage
 
34
               ;;
 
35
        esac
 
36
done
 
37
 
 
38
# stress.rb exports the profile locations it generatees in PROFILEDIR
 
39
# and PROFILESINGLE
 
40
echo "Generating ${PROFILE_COUNT} profiles..."
 
41
eval $(./stress.rb ${STRESS_ARGS} ${PROFILE_COUNT})
 
42
 
 
43
if [ ! -d "${PROFILEDIR}" -o ! -f "${PROFILESINGLE}" ] ; then
 
44
        echo "Generated profiles don't exist! Aborting...."
 
45
        exit 1
 
46
fi
 
47
 
 
48
cleanup () {
 
49
        if [ ${KEEP_FILES} == 0 ] ; then
 
50
                rm -rf "${PROFILEDIR}"
 
51
                rm "${PROFILESINGLE}"
 
52
        else
 
53
                echo "Files kept in ${PROFILEDIR} and ${PROFILESINGLE}"
 
54
        fi
 
55
}
 
56
 
 
57
timedir () {
 
58
        COMMAND=$1
 
59
        DESCRIPTION=$2
 
60
        echo "$DESCRIPTION"
 
61
        time for profile in ${PROFILEDIR}/* ; do
 
62
                ${COMMAND} ${profile} > /dev/null
 
63
        done
 
64
}
 
65
 
 
66
timesingle () {
 
67
        COMMAND=$1
 
68
        DESCRIPTION=$2
 
69
        echo "$DESCRIPTION"
 
70
        time ${COMMAND} ${PROFILESINGLE} > /dev/null
 
71
}
 
72
 
 
73
remove_profiles () {
 
74
        echo "Unloading profiles..."
 
75
        (for profile in $(grep "^/does/not/exist" /sys/kernel/security/apparmor/profiles | cut -d " " -f 1); do
 
76
                echo "${profile} {} "
 
77
        done) | apparmor_parser -K -R > /dev/null
 
78
}
 
79
 
 
80
# load files into buffer cache
 
81
timedir "cat" "Loading directory of profiles into buffer cache"
 
82
timedir "apparmor_parser -dd" "Running preprocess only parser on directory of profiles"
 
83
timedir "apparmor_parser -S" "Running full parser on directory of profiles"
 
84
if [ "${LOAD_PROFILES}" == 1 ] ; then
 
85
        if [ "$(whoami)" == 'root' ] ; then
 
86
                timedir "apparmor_parser" "Parsing/loading directory of profiles"
 
87
                remove_profiles
 
88
        else
 
89
                echo "Not root, skipping load test..."
 
90
        fi
 
91
fi
 
92
 
 
93
timesingle "cat" "Loading equivalent profile into buffer cache"
 
94
timesingle "apparmor_parser -dd" "Running preprocess only parser on single equiv profile"
 
95
timesingle "apparmor_parser -S" "Running full parser on single equivalent profile"
 
96
if [ "${LOAD_PROFILES}" == 1 ] ; then
 
97
        if [ "$(whoami)" == 'root' ] ; then
 
98
                timesingle "apparmor_parser" "Parsing/loading single file of profiles"
 
99
                remove_profiles
 
100
        else
 
101
                echo "Not root, skipping load test..."
 
102
        fi
 
103
fi
 
104
 
 
105
cleanup