~ubuntu-branches/ubuntu/trusty/apparmor/trusty

« back to all changes in this revision

Viewing changes to .pc/update-tests-for-new-semantics.patch/tests/regression/apparmor/dbus.inc

  • Committer: Package Import Robot
  • Author(s): Jamie Strandboge
  • Date: 2014-04-04 01:07:24 UTC
  • Revision ID: package-import@ubuntu.com-20140404010724-n7pyk2cd5er3gi6m
Tags: 2.8.95~2430-0ubuntu5
debian/control: add versioned Breaks to apparmor for lxc, libvirt-bin,
lightdm and apparmor-easyprof-ubuntu

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim:syntax=sh
 
2
#
 
3
#       Copyright (C) 2013 Canonical, Ltd.
 
4
#
 
5
#       This program is free software; you can redistribute it and/or
 
6
#       modify it under the terms of the GNU General Public License as
 
7
#       published by the Free Software Foundation, version 2 of the
 
8
#       License.
 
9
 
 
10
gendbusprofile()
 
11
{
 
12
        genprofile --stdin <<EOF
 
13
${__dbus_var_decl}
 
14
$test {
 
15
  @{gen $test}
 
16
  $@
 
17
}
 
18
EOF
 
19
        unset __dbus_var_decl
 
20
}
 
21
 
 
22
# the arguments passed are emitted in the profile's prologue, for
 
23
# setting profile variables, e.g.
 
24
#       set_dbus_var "@{MY_DBUS_VAR}=stuff"
 
25
# the saved variable declaration gets unset after each test run
 
26
set_dbus_var()
 
27
{
 
28
  __dbus_var_decl=$@
 
29
}
 
30
 
 
31
start_bus()
 
32
{
 
33
        out=$(dbus-daemon --fork --print-pid --print-address --config-file=dbus.conf)
 
34
        if [ $? -ne 0 ]
 
35
        then
 
36
                fatalerror "Failed to start DBus daemon"
 
37
        fi
 
38
 
 
39
        bus_addr=$(echo $out | cut -d\  -f 1)
 
40
        bus_pid=$(echo $out | cut -d\  -f 2)
 
41
 
 
42
        # The daemon may error out during initialization. Unfortunately,
 
43
        # there's no good way to detect that, but this will work under normal
 
44
        # conditions.
 
45
        sleep 1
 
46
        kill -0 $bus_pid 2>/dev/null
 
47
        if [ $? -ne 0 ]
 
48
        then
 
49
                fatalerror "DBus daemon unexpectedly stopped"
 
50
        fi
 
51
 
 
52
        do_onexit="kill $bus_pid"
 
53
        export DBUS_SESSION_BUS_ADDRESS=$bus_addr
 
54
}
 
55
 
 
56
bus="session"
 
57
dest=com.apparmor.Test
 
58
path=/com/apparmor/Test
 
59
iface=com.apparmor.Test
 
60
 
 
61
# parameters: bus message_type destination path interface.member
 
62
#
 
63
# destination must be a connection name or "broadcast" for a broadcast signal
 
64
send()
 
65
{
 
66
  d=""
 
67
 
 
68
  if [ "$3" == "broadcast" ]
 
69
  then
 
70
    if [ "$2" != "signal" ]
 
71
    then
 
72
      fatalerror "Cannot send broadcast for message type \"$2\""
 
73
    fi
 
74
  else
 
75
    d="--name=$3"
 
76
  fi
 
77
 
 
78
  out=$(./dbus_message --$1 --type=$2 $d $4 $5 2>&1)
 
79
  if [ $? -ne 0 ]
 
80
  then
 
81
    fatalerror "$out"
 
82
  fi
 
83
}
 
84
 
 
85
sendsignal()
 
86
{
 
87
  send "$bus" "signal" "$dest" "$path" "${iface}.Signal"
 
88
}
 
89
 
 
90
sendbroadcastsignal()
 
91
{
 
92
  send "$bus" "signal" "broadcast" "$path" "${iface}.Signal"
 
93
}
 
94
 
 
95
sendmethod()
 
96
{
 
97
  send "$bus" "method_call" "$dest" "$path" "${iface}.Method"
 
98
}
 
99
 
 
100
compare_logs()
 
101
{
 
102
        local msg
 
103
        local rc=0
 
104
 
 
105
        cmp -s "$1" "$3" || rc=$?
 
106
        if [ $rc -ne 0 ] && [ "$2" == "eq" ]
 
107
        then
 
108
                msg="Log files \"$1\" and \"$3\" are different, but should be equal."
 
109
        elif [ $rc -eq 0 ] && [ "$2" == "ne" ]
 
110
        then
 
111
                msg="Log files \"$1\" and \"$3\" are the same, but should be different."
 
112
        else
 
113
                return
 
114
        fi
 
115
 
 
116
        echo "Error: ${testname} failed. Test '${_testdesc}' produced unexpected log contents. ${msg}"
 
117
        testfailed
 
118
}