#!/bin/bash
builddir=`dirname "$0"`
GCONV_PATH="${builddir}/iconvdata"

usage () {
cat << EOF
Usage: $0 [OPTIONS] <program> [ARGUMENTS...]

  --tool=TOOL  Run with the specified TOOL. It can be strace, rpctrace,
               valgrind or container. The container will run within
               support/test-container.
EOF

  exit 1
}

toolname=default
while test $# -gt 0 ; do
  case "$1" in
    --tool=*)
      toolname="${1:7}"
      shift
      ;;
    --*)
      usage
      ;;
    *)
      break
      ;;
  esac
done

if test $# -eq 0 ; then
  usage
fi

case "$toolname" in
  default)
    exec   env GCONV_PATH="${builddir}"/iconvdata LOCPATH="${builddir}"/localedata LC_ALL=C  "${builddir}"/elf/ld-linux-aarch64.so.1 --library-path "${builddir}":"${builddir}"/math:"${builddir}"/elf:"${builddir}"/dlfcn:"${builddir}"/nss:"${builddir}"/nis:"${builddir}"/rt:"${builddir}"/resolv:"${builddir}"/mathvec:"${builddir}"/support:"${builddir}"/nptl ${1+"$@"}
    ;;
  strace)
    exec strace  -EGCONV_PATH=/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/iconvdata  -ELOCPATH=/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/localedata  -ELC_ALL=C  /home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/elf/ld-linux-aarch64.so.1 --library-path /home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/math:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/elf:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/dlfcn:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nss:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nis:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/rt:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/resolv:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/mathvec:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/support:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nptl ${1+"$@"}
    ;;
  rpctrace)
    exec rpctrace  -EGCONV_PATH=/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/iconvdata  -ELOCPATH=/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/localedata  -ELC_ALL=C  /home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/elf/ld-linux-aarch64.so.1 --library-path /home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/math:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/elf:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/dlfcn:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nss:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nis:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/rt:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/resolv:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/mathvec:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/support:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nptl ${1+"$@"}
    ;;
  valgrind)
    exec env GCONV_PATH=/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/iconvdata LOCPATH=/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/localedata LC_ALL=C valgrind  /home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/elf/ld-linux-aarch64.so.1 --library-path /home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/math:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/elf:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/dlfcn:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nss:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nis:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/rt:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/resolv:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/mathvec:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/support:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nptl ${1+"$@"}
    ;;
  container)
    exec env GCONV_PATH=/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/iconvdata LOCPATH=/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/localedata LC_ALL=C  /home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/elf/ld-linux-aarch64.so.1 --library-path /home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/math:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/elf:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/dlfcn:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nss:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nis:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/rt:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/resolv:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/mathvec:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/support:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nptl /home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/support/test-container env GCONV_PATH=/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/iconvdata LOCPATH=/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/localedata LC_ALL=C  /home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/elf/ld-linux-aarch64.so.1 --library-path /home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/math:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/elf:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/dlfcn:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nss:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nis:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/rt:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/resolv:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/mathvec:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/support:/home/valonso/oe-core/build/tmp/work/cortexa53-tdx-linux/glibc/2.35-r0/build-aarch64-tdx-linux/nptl ${1+"$@"}
    ;;
  *)
    usage
    ;;
esac
