Debian Codegraph @

src/tests/enable

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 --enable and --disable.
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-magic /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-magic" "$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-magic" "$tmpdir/1-proc.exp"
55
56 update_binfmts_proc --install test-extension /bin/sh --extension ext
57 report 'extension: install' "$?"
58 cat >"$tmpdir/2-admin.exp" <<'EOF'
59 :
60 extension
61 0
62 ext
63
64 /bin/sh
65
66
67
68
69 EOF
70 expect_files_equal 'extension: admindir entry OK' \
71 "$tmpdir/var/lib/binfmts/test-extension" "$tmpdir/2-admin.exp"
72 cat >"$tmpdir/2-proc.exp" <<'EOF'
73 enabled
74 interpreter /bin/sh
75 flags:
76 extension .ext
77 EOF
78 expect_files_equal 'extension: procdir entry OK' \
79 "$tmpdir/proc/test-extension" "$tmpdir/2-proc.exp"
80
81 update_binfmts_proc --disable test-magic
82 report 'magic: disable' "$?"
83 ! test -e "$tmpdir/proc/test-magic"
84 report 'magic: procdir entry gone' "$?"
85 expect_files_equal 'extension: still enabled' \
86 "$tmpdir/proc/test-extension" "$tmpdir/2-proc.exp"
87
88 update_binfmts_proc --disable test-extension
89 report 'extension: disable' "$?"
90 ! test -e "$tmpdir/proc/test-extension"
91 report 'extension: procdir entry gone' "$?"
92
93 update_binfmts_proc --enable test-extension
94 report 'extension: enable' "$?"
95 expect_files_equal 'extension: procdir entry OK' \
96 "$tmpdir/proc/test-extension" "$tmpdir/2-proc.exp"
97 ! test -e "$tmpdir/proc/test-magic"
98 report 'magic: still disabled' "$?"
99
100 update_binfmts_proc --enable
101 report 'enable all' "$?"
102 expect_files_equal 'magic: procdir entry OK' \
103 "$tmpdir/proc/test-magic" "$tmpdir/1-proc.exp"
104 expect_files_equal 'extension: procdir entry OK' \
105 "$tmpdir/proc/test-extension" "$tmpdir/2-proc.exp"
106
107 update_binfmts_proc --disable
108 report 'disable all' "$?"
109 ! test -e "$tmpdir/proc/test-magic"
110 report 'magic: procdir entry gone' "$?"
111 ! test -e "$tmpdir/proc/test-extension"
112 report 'extension: procdir entry gone' "$?"
113 ! test -e "$tmpdir/proc/register"
114 report 'procdir unmounted' "$?"
115
116 finish