Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts for building/testing gcc torture tests #317

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions scripts/build_gcc_torture_tests/build_and_compress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# stop on failure
set -euo pipefail

function show_usage {

printf "${0}: Build bitcode and binaries for all architectures for clang's gcc
torture test suite"
printf "Usage (default values in [brackets]):\n"
printf "\n"
printf "\t--help: this screen\n"
printf "\t--clang ##: Which clang this bitcode was built with\n"
printf "\t--ld LINKER: Which linker to use for linking the binaries\n"
return 0
}

CLANG=unknown
LD=unknown

while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--help | -h | -?)
show_usage ${0}
exit 0
;;
--clang)
shift
CLANG=clang-${1}
CLANG_VERSION=${1}
shift
;;
--ld)
shift
LD=${1}
shift
;;
*) # unknown option
echo "UNKNOWN OPTION: ${1}"
exit 1
shift # past argument
;;
esac
done

if [[ "${CLANG}" = "unknown" ]]
then
echo "Please specify a clang version via --clang # (e.g. --clang 15)"
exit 1
fi

if [[ "${LD}" = "unknown" ]]
then
echo "Please specify a linker via --ld LINKER (e.g. --ld lld-15)"
exit 1
fi

mkdir -p "${DIR}/build"
pushd "${DIR}/build" &>/dev/null
# download only the part of the llvm test suite that is required, otherwise
# cloning might take several minutes
TEST_SUITE_DIR="llvm-test-suite-${CLANG_VERSION}"
if [ ! -d "${TEST_SUITE_DIR}" ]; then
echo "retrieving llvm-test-suite"
git clone \
--branch "release/${CLANG_VERSION}.x" \
--depth 1 \
--filter=blob:none \
--sparse \
https://github.com/llvm/llvm-test-suite.git \
"${TEST_SUITE_DIR}"

(cd "${TEST_SUITE_DIR}" && git sparse-checkout set "SingleSource/Regression/C/gcc-c-torture")
else
echo "llvm-test-suite already downloaded"
fi

compile_commands=$(mktemp /tmp/compile_commands.XXXXXX)
echo "generating compile commands in tmp file ${compile_commands}"
"${DIR}/generate_compile_commands.py" \
--clang "${CLANG}" \
--ld "${LD}" \
--source "${TEST_SUITE_DIR}/SingleSource/Regression/C/gcc-c-torture/execute" \
--emit-bitcode \
--emit-binaries \
--dest ./compiled \
> "${compile_commands}"

# execute the mkdir commands sequentially first
grep "mkdir -p" "${compile_commands}" | bash

# run the compile commands in parallel since they are >10k for all
# architectures combined
echo "Executing compile commands in parallel"
grep "mkdir -p" "${compile_commands}" --invert-match \
| xargs --delimiter '\n' --max-procs=0 --max-args=1 bash -c

# Executing sequentially is quite slow, prefer using xargs
# echo "Executing compile commands ${compile_commands}"
# bash "${compile_commands}"

# compressing results for upload
"${DIR}/compress_bitcode.sh" --clang "${CLANG_VERSION}"

echo "results can be found in ${DIR}/build"
57 changes: 57 additions & 0 deletions scripts/build_gcc_torture_tests/compress_bitcode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

set -euo pipefail

function show_usage {

printf "${0}: Compress bitcode to a form that can be uploaded"
printf "Usage (default values in [brackets]):\n"
printf "\n"
printf "\t--help: this screen\n"
printf "\t--clang ##: Which clang this bitcode was built with\n"
return 0
}

CLANG=unknown

while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--help | -h | -?)
show_usage ${0}
exit 0
;;
--clang)
shift
CLANG=clang-${1}
shift
;;
*) # unknown option
echo "UNKNOWN OPTION: ${1}"
exit 1
shift # past argument
;;
esac
done

if [[ "${CLANG}" = "unknown" ]]
then
echo "Please specify a clang version via --clang # (e.g. --clang 12)"
exit 1
fi

pushd "${DIR}/build/compiled" &>/dev/null

for otype in bitcode binaries
do
for archdir in ${otype}/*
do
arch=$(basename ${archdir})
echo "Compressing ${otype} ${arch}"
XZ_OPT=-e9 tar -Ipixz -cf ${otype}.${CLANG}.${arch}.tar.xz ${otype}/${arch}
done
done

popd &>/dev/null
Loading