Home | History | Annotate | Download | only in tests
      1 #!/bin/bash
      2 #
      3 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 #
      7 # Script to run a test under qemu
      8 #
      9 # Usage:
     10 #    test_using_qemu.sh (command line to run)
     11 #
     12 # Required environment variables:
     13 #    BUILD_RUN - path to build directory inside chroot
     14 #    HOME - home directory inside chroot
     15 #    QEMU_RUN - path to QEMU binary inside chroot
     16 #    SYSROOT - path to root for target platform, outside chroot
     17 
     18 set -e
     19 
     20 # Set up mounts
     21 sudo mkdir -p "${SYSROOT}/proc" "${SYSROOT}/dev"
     22 sudo mount --bind /proc "${SYSROOT}/proc"
     23 sudo mount --bind /dev "${SYSROOT}/dev"
     24 
     25 # Don't exit on error, so we can capture the error code
     26 set +e
     27 sudo chroot ${SYSROOT} ${QEMU_RUN} -drop-ld-preload \
     28     -E LD_LIBRARY_PATH=/lib64:/lib:/usr/lib64:/usr/lib \
     29     -E HOME=${HOME} \
     30     -E BUILD=${BUILD_RUN} \
     31     -- $*
     32 exit_code=$?
     33 set -e
     34 
     35 # Clean up mounts
     36 sudo umount -l "${SYSROOT}/proc"
     37 sudo umount -l "${SYSROOT}/dev"
     38 
     39 # Pass through exit code from command
     40 exit $exit_code
     41