| 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 userspace detectors. |
| 22 |
|
| 23 |
: "${srcdir=.}" |
| 24 |
# shellcheck source-path=SCRIPTDIR |
| 25 |
. "$srcdir/testlib.sh" |
| 26 |
|
| 27 |
init |
| 28 |
fake_proc |
| 29 |
|
| 30 |
for i in 1 2 3; do |
| 31 |
cat >"$tmpdir/program-$i" <<EOF |
| 32 |
#! /bin/sh |
| 33 |
echo program-$i "\$@" |
| 34 |
EOF |
| 35 |
chmod +x "$tmpdir/program-$i" |
| 36 |
done |
| 37 |
|
| 38 |
for i in 1 2; do |
| 39 |
cat >"$tmpdir/detector-$i" <<EOF |
| 40 |
#! /bin/sh |
| 41 |
grep -q ^$i "\$1" |
| 42 |
EOF |
| 43 |
chmod +x "$tmpdir/detector-$i" |
| 44 |
done |
| 45 |
|
| 46 |
for i in 1 2 3; do |
| 47 |
cat >"$tmpdir/input-$i.ext" <<EOF |
| 48 |
$i input file |
| 49 |
EOF |
| 50 |
done |
| 51 |
|
| 52 |
update_binfmts_proc \ |
| 53 |
--install test-1 "$tmpdir/program-1" --extension ext \ |
| 54 |
--detector "$tmpdir/detector-1" |
| 55 |
report 'detector 1: install' "$?" |
| 56 |
cat >"$tmpdir/1-admin.exp" <<EOF |
| 57 |
: |
| 58 |
extension |
| 59 |
0 |
| 60 |
ext |
| 61 |
|
| 62 |
$tmpdir/program-1 |
| 63 |
$tmpdir/detector-1 |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
EOF |
| 68 |
expect_files_equal 'detector 1: admindir entry OK' \ |
| 69 |
"$tmpdir/var/lib/binfmts/test-1" "$tmpdir/1-admin.exp" |
| 70 |
# shellcheck disable=SC2154 |
| 71 |
cat >"$tmpdir/1-proc.exp" <<EOF |
| 72 |
enabled |
| 73 |
interpreter $pkglibexecdir/run-detectors |
| 74 |
flags: |
| 75 |
extension .ext |
| 76 |
EOF |
| 77 |
expect_files_equal 'detector 1: procdir entry OK' \ |
| 78 |
"$tmpdir/proc/test-1" "$tmpdir/1-proc.exp" |
| 79 |
|
| 80 |
update_binfmts_proc \ |
| 81 |
--install test-2 "$tmpdir/program-2" --extension ext \ |
| 82 |
--detector "$tmpdir/detector-2" |
| 83 |
report 'detector 2: install' "$?" |
| 84 |
cat >"$tmpdir/2-admin.exp" <<EOF |
| 85 |
: |
| 86 |
extension |
| 87 |
0 |
| 88 |
ext |
| 89 |
|
| 90 |
$tmpdir/program-2 |
| 91 |
$tmpdir/detector-2 |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
EOF |
| 96 |
expect_files_equal 'detector 2: admindir entry OK' \ |
| 97 |
"$tmpdir/var/lib/binfmts/test-2" "$tmpdir/2-admin.exp" |
| 98 |
cat >"$tmpdir/2-proc.exp" <<EOF |
| 99 |
enabled |
| 100 |
interpreter $pkglibexecdir/run-detectors |
| 101 |
flags: |
| 102 |
extension .ext |
| 103 |
EOF |
| 104 |
expect_files_equal 'detector 2: procdir entry OK' \ |
| 105 |
"$tmpdir/proc/test-2" "$tmpdir/2-proc.exp" |
| 106 |
|
| 107 |
update_binfmts_proc --install test-3 "$tmpdir/program-3" --extension ext |
| 108 |
report 'no detector: install' "$?" |
| 109 |
cat >"$tmpdir/3-admin.exp" <<EOF |
| 110 |
: |
| 111 |
extension |
| 112 |
0 |
| 113 |
ext |
| 114 |
|
| 115 |
$tmpdir/program-3 |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
EOF |
| 121 |
expect_files_equal 'no detector: admindir entry OK' \ |
| 122 |
"$tmpdir/var/lib/binfmts/test-3" "$tmpdir/3-admin.exp" |
| 123 |
cat >"$tmpdir/3-proc.exp" <<EOF |
| 124 |
enabled |
| 125 |
interpreter $pkglibexecdir/run-detectors |
| 126 |
flags: |
| 127 |
extension .ext |
| 128 |
EOF |
| 129 |
expect_files_equal 'no detector: procdir entry OK' \ |
| 130 |
"$tmpdir/proc/test-3" "$tmpdir/3-proc.exp" |
| 131 |
|
| 132 |
echo "program-1 $tmpdir/input-1.ext --foo=bar file --admindir=baz -v" >"$tmpdir/4.exp" |
| 133 |
run_detectors "$tmpdir/input-1.ext" --foo=bar file --admindir=baz -v >"$tmpdir/4.out" |
| 134 |
report 'detector 1: run' "$?" |
| 135 |
expect_files_equal 'detector 1: output' \ |
| 136 |
"$tmpdir/4.out" "$tmpdir/4.exp" |
| 137 |
|
| 138 |
echo "program-2 $tmpdir/input-2.ext" >"$tmpdir/5.exp" |
| 139 |
run_detectors "$tmpdir/input-2.ext" >"$tmpdir/5.out" |
| 140 |
report 'detector 2, without arguments: run' "$?" |
| 141 |
expect_files_equal 'detector 2, without arguments: output' \ |
| 142 |
"$tmpdir/5.out" "$tmpdir/5.exp" |
| 143 |
|
| 144 |
echo "program-3 $tmpdir/input-3.ext foo --arg" >"$tmpdir/6.exp" |
| 145 |
run_detectors "$tmpdir/input-3.ext" foo --arg >"$tmpdir/6.out" |
| 146 |
report 'no detector: run' "$?" |
| 147 |
expect_files_equal 'no detector: output' \ |
| 148 |
"$tmpdir/6.out" "$tmpdir/6.exp" |
| 149 |
|
| 150 |
echo "program-3 $tmpdir/input-3.ext" >"$tmpdir/7.exp" |
| 151 |
run_detectors "$tmpdir/input-3.ext" >"$tmpdir/7.out" |
| 152 |
report 'no detector, without arguments: run' "$?" |
| 153 |
expect_files_equal 'no detector, without arguments: output' \ |
| 154 |
"$tmpdir/7.out" "$tmpdir/7.exp" |
| 155 |
|
| 156 |
finish |