Debian Codegraph @

src/tests/install

raw
1 #! /bin/sh
2
3 # Copyright (C) 2010 Colin Watson.
4 #
5 # This file is part of binfmt-support.
6 #
7 # binfmt-support is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 3 of the License, or (at your
10 # option) any later version.
11 #
12 # binfmt-support is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15 # Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with binfmt-support; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
21 # Test update-binfmts --install and --remove.
22
23 : "${srcdir=.}"
24 # shellcheck source-path=SCRIPTDIR
25 . "$srcdir/testlib.sh"
26
27 init
28 fake_proc
29
30 update_binfmts_proc --install test /bin/sh --magic ABCD
31 report 'magic: install' "$?"
32 cat >"$tmpdir/1-admin.exp" <<'EOF'
33 :
34 magic
35 0
36 ABCD
37
38 /bin/sh
39
40
41
42
43 EOF
44 expect_files_equal 'magic: admindir entry OK' \
45 "$tmpdir/var/lib/binfmts/test" "$tmpdir/1-admin.exp"
46 cat >"$tmpdir/1-proc.exp" <<'EOF'
47 enabled
48 interpreter /bin/sh
49 flags:
50 offset 0
51 magic 41424344
52 EOF
53 expect_files_equal 'magic: procdir entry OK' \
54 "$tmpdir/proc/test" "$tmpdir/1-proc.exp"
55 update_binfmts_proc --remove test /bin/sh
56 report 'magic: remove' "$?"
57 ! test -e "$tmpdir/var/lib/binfmts/test"
58 report 'magic: admindir entry gone' "$?"
59 ! test -e "$tmpdir/proc/test"
60 report 'magic: procdir entry gone' "$?"
61
62 update_binfmts_proc \
63 --install test /bin/sh --magic ABCD --offset 10 \
64 --mask "\\x7f\\x7f\\x7f\\x7f"
65 report 'magic with offset and mask: install' "$?"
66 cat >"$tmpdir/2-admin.exp" <<'EOF'
67 :
68 magic
69 10
70 ABCD
71 \x7f\x7f\x7f\x7f
72 /bin/sh
73
74
75
76
77 EOF
78 expect_files_equal 'magic with offset and mask: admindir entry OK' \
79 "$tmpdir/var/lib/binfmts/test" "$tmpdir/2-admin.exp"
80 cat >"$tmpdir/2-proc.exp" <<'EOF'
81 enabled
82 interpreter /bin/sh
83 flags:
84 offset 10
85 magic 41424344
86 mask 7f7f7f7f
87 EOF
88 expect_files_equal 'magic with offset and mask: procdir entry OK' \
89 "$tmpdir/proc/test" "$tmpdir/2-proc.exp"
90 update_binfmts_proc --remove test /bin/sh
91 report 'magic with offset and mask: remove' "$?"
92 ! test -e "$tmpdir/var/lib/binfmts/test"
93 report 'magic with offset and mask: admindir entry gone' "$?"
94 ! test -e "$tmpdir/proc/test"
95 report 'magic with offset and mask: procdir entry gone' "$?"
96
97 update_binfmts_proc --install test /bin/sh --extension ext
98 report 'extension: install' "$?"
99 cat >"$tmpdir/3-admin.exp" <<'EOF'
100 :
101 extension
102 0
103 ext
104
105 /bin/sh
106
107
108
109
110 EOF
111 expect_files_equal 'extension: admindir entry OK' \
112 "$tmpdir/var/lib/binfmts/test" "$tmpdir/3-admin.exp"
113 cat >"$tmpdir/3-proc.exp" <<'EOF'
114 enabled
115 interpreter /bin/sh
116 flags:
117 extension .ext
118 EOF
119 expect_files_equal 'extension: procdir entry OK' \
120 "$tmpdir/proc/test" "$tmpdir/3-proc.exp"
121 update_binfmts_proc --package testpkg --remove test /bin/sh 2>/dev/null
122 report 'extension: remove with package' "$?"
123 test -e "$tmpdir/var/lib/binfmts/test"
124 report 'extension: admindir entry still here' "$?"
125 test -e "$tmpdir/proc/test"
126 report 'extension: procdir entry still here' "$?"
127 update_binfmts_proc --remove test /bin/sh
128 report 'extension: remove without package' "$?"
129 ! test -e "$tmpdir/var/lib/binfmts/test"
130 report 'extension: admindir entry gone' "$?"
131 ! test -e "$tmpdir/proc/test"
132 report 'extension: procdir entry gone' "$?"
133
134 update_binfmts_proc --package testpkg --install test /bin/sh --extension ext
135 report 'extension with package: install' "$?"
136 cat >"$tmpdir/4-admin.exp" <<'EOF'
137 testpkg
138 extension
139 0
140 ext
141
142 /bin/sh
143
144
145
146
147 EOF
148 expect_files_equal 'extension with package: admindir entry OK' \
149 "$tmpdir/var/lib/binfmts/test" "$tmpdir/4-admin.exp"
150 cat >"$tmpdir/4-proc.exp" <<'EOF'
151 enabled
152 interpreter /bin/sh
153 flags:
154 extension .ext
155 EOF
156 expect_files_equal 'extension with package: procdir entry OK' \
157 "$tmpdir/proc/test" "$tmpdir/4-proc.exp"
158 update_binfmts_proc --remove test /bin/sh 2>/dev/null
159 report 'extension with package: remove without package' "$?"
160 test -e "$tmpdir/var/lib/binfmts/test"
161 report 'extension with package: admindir entry still here' "$?"
162 test -e "$tmpdir/proc/test"
163 report 'extension with package: procdir entry still here' "$?"
164 update_binfmts_proc --package testpkg --remove test /bin/sh
165 report 'extension with package: remove with package' "$?"
166 ! test -e "$tmpdir/var/lib/binfmts/test"
167 report 'extension with package: admindir entry gone' "$?"
168 ! test -e "$tmpdir/proc/test"
169 report 'extension with package: procdir entry gone' "$?"
170
171 finish