]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/lxc-test-exit-code
oss-fuzz: adapt options to oss-fuzz build
[mirror_lxc.git] / src / tests / lxc-test-exit-code
1 #!/bin/sh
2
3 # lxc: linux Container library
4
5 # Authors:
6 # Florian Margaine <florian@platform.sh>
7 #
8 # This is a test script for the lxc-attach and lxc-execute
9 # programs. It tests whether the exit code is not 0 when a script
10 # fails to execute.
11
12 # This library is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU Lesser General Public
14 # License as published by the Free Software Foundation; either
15 # version 2.1 of the License, or (at your option) any later version.
16
17 # This library is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # Lesser General Public License for more details.
21
22 # You should have received a copy of the GNU Lesser General Public
23 # License along with this library; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25
26 set -e
27
28 FAIL() {
29 echo -n "Failed " >&2
30 echo "$*" >&2
31 lxc-destroy -n busy -f
32 exit 1
33 }
34
35 # Create a container
36 lxc-create -t busybox -n busy || FAIL "creating busybox container"
37
38 # Run lxc-execute to make sure it fails when the command fails, and
39 # succeed when the command succeeds.
40 lxc-execute -n busy -- sh -c 'exit 1' && FAIL "should be failing" || true
41 lxc-execute -n busy -- sh -c 'exit 0' || FAIL "should be succeeding"
42
43 # Now, start the container and wait for it to be in running state.
44 lxc-start -n busy -d || FAIL "starting busybox container"
45 lxc-wait -n busy -s RUNNING || FAIL "waiting for busybox container to run"
46
47 # And run the same tests on lxc-attach.
48 lxc-attach -n busy -- sh -c 'exit 1' && FAIL "should be failing" || true
49 lxc-attach -n busy -- sh -c 'exit 0' || FAIL "should be succeeding"
50
51 lxc-destroy -n busy -f
52
53 exit 0