summaryrefslogtreecommitdiff
path: root/automated/linux/toolchain-smoke/toolchain-smoke.sh
blob: 2dc76ed2958ed90465defec65e0e5d7a39ba5a14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh -e

# shellcheck disable=SC1091
. ../../lib/sh-test-lib
OUTPUT="$(pwd)/output"
RESULT_FILE="${OUTPUT}/result.txt"
export RESULT_FILE
STATIC=false

usage() {
    echo "Usage: $0 [-s <true|flase>] [-t <true|flase>]" 1>&2
    exit 1
}

while getopts "s:t:h" o; do
    case "$o" in
        t) STATIC=${OPTARG} ;;
        s) SKIP_INSTALL="${OPTARG}" ;;
        h|*) usage ;;
    esac
done

install() {
    dist_name
    # shellcheck disable=SC2154
    case "${dist}" in
      Debian|Ubuntu) install_deps "build-essential" "${SKIP_INSTALL}" ;;
      Fedora|CentOS) install_deps "gcc glibc-static" "${SKIP_INSTALL}" ;;
      Unknown) warn_msg "Unsupported distro: package install skipped" ;;
    esac
}

! check_root && error_msg "You need to be root to run this script."
[ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}_$(date +%Y%m%d%H%M%S)"
mkdir -p "${OUTPUT}"
cd "${OUTPUT}"

install

FLAGS=""
if [ "${STATIC}" = "true" ] || [ "${STATIC}" = "True" ]; then
    FLAGS="-static"
fi

skip_list="execute_binary"
command="gcc ${FLAGS} -o hello ../hello.c"
run_test_case "${command}" "gcc${FLAGS}" "${skip_list}"

command="./hello | grep -x 'Hello world'"
# skip_list is used as test case name to avoid typing mistakes
run_test_case "${command}" "${skip_list}"