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

Run C/C++ application testing on Windows and Mac #164

Open
wants to merge 15 commits into
base: main
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
162 changes: 102 additions & 60 deletions .github/workflows/c_apps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set -x
set -e
set -u

# Old bash versions can't expand empty arrays, so we always include at least this option.
CMAKE_OPTIONS=("-DCMAKE_OSX_ARCHITECTURES=x86_64")

help | head

Expand All @@ -38,8 +40,20 @@ case "$(uname)" in
df -h
;;

"Darwin")
NINJA_OS="mac"
SDKROOT=$(xcrun --show-sdk-path)
export SDKROOT
;;

"MINGW"*|"MSYS_NT"*)
NINJA_OS="win"
CMAKE_OPTIONS+=("-DCMAKE_C_COMPILER=cl.exe" "-DCMAKE_CXX_COMPILER=cl.exe")
choco install zip
;;

*)
echo "Unknown OS: only Linux is supported for the dev_build workflow"
echo "Unknown OS"
exit 1
;;
esac
Expand All @@ -58,80 +72,108 @@ popd

DREDD_ROOT=$(pwd)

export PATH="${DREDD_ROOT}/third_party/clang+llvm/bin:$PATH"
case "$(uname)" in
"Linux")
# On Linux, build Dredd using the prebuilt version of Clang that has been downloaded
export PATH="${DREDD_ROOT}/third_party/clang+llvm/bin:$PATH"
export CC=clang
export CXX=clang++
which ${CC}
which ${CXX}
;;

export CC=clang
export CXX=clang++
"Darwin")
;;

which ${CC}
which ${CXX}
"MINGW"*|"MSYS_NT"*)
;;

*)
echo "Unknown OS"
exit 1
;;
esac

mkdir -p build
pushd build
cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Debug
cmake --build . --config Debug
cmake -DCMAKE_INSTALL_PREFIX=./install -DBUILD_TYPE=Debug -P cmake_install.cmake
cmake -G Ninja .. -DCMAKE_BUILD_TYPE="${CONFIG}" "${CMAKE_OPTIONS[@]}"
cmake --build . --config "${CONFIG}"
cmake -DCMAKE_INSTALL_PREFIX=./install -DBUILD_TYPE="${CONFIG}" -P cmake_install.cmake
popd

# Check that dredd works on some projects
DREDD_EXECUTABLE="${DREDD_ROOT}/third_party/clang+llvm/bin/dredd"
cp "${DREDD_ROOT}/build/src/dredd/dredd" "${DREDD_EXECUTABLE}"

echo "Curl"
date

git clone https://github.com/curl/curl.git
pushd curl
git reset --hard curl-7_84_0
mkdir build
pushd build
cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
popd
FILES=()
for f in $(find src -name "*.c")
do
FILES+=("${f}")
done

"${DREDD_EXECUTABLE}" --mutation-info-file temp.json -p "build/compile_commands.json" "${FILES[@]}"
pushd build
ninja
# TODO: run some tests
case "$(uname)" in
"Linux"|"MINGW"*|"MSYS_NT"*)
echo "Curl"
date

git clone https://github.com/curl/curl.git
pushd curl
git reset --hard curl-7_84_0
mkdir build
pushd build
cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
popd
FILES=()
for f in $(find src -name "*.c")
do
FILES+=("${f}")
done

"${DREDD_EXECUTABLE}" --mutation-info-file temp.json -p "build/compile_commands.json" "${FILES[@]}"
pushd build
ninja
# TODO: run some tests
popd
popd
popd
;;

echo "zstd"
date
*)
;;
esac

git clone https://github.com/facebook/zstd.git
pushd zstd
git reset --hard v1.4.10
mkdir temp
pushd temp
# Generate a compilation database
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ../build/cmake
case "$(uname)" in
"Linux"|"Darwin")
echo "zstd"
date

git clone https://github.com/facebook/zstd.git
pushd zstd
git reset --hard v1.4.10
mkdir temp
pushd temp
# Generate a compilation database
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ../build/cmake
popd
# Build non-mutated zstd
CFLAGS=-O0 make zstd-release
# Use the compiled zstd binary as a target for compression, and compress it.
cp ./programs/zstd tocompress
./zstd tocompress -o normal
# Mutate all the source files in the lib directory of zstd
FILES=()
for f in $(find lib -name "*.c")
do
FILES+=("${f}")
done
"${DREDD_EXECUTABLE}" --mutation-info-file temp.json -p "temp/compile_commands.json" "${FILES[@]}"
# Build mutated zstd
make clean
CFLAGS=-O0 make zstd-release
# Use it to compress the original (non-mutated) zstd binary
./zstd tocompress -o mutated
# The results obtained using the original and mutated versions of zstd should
# be identical, since no mutations were enabled.
diff normal mutated
popd
# Build non-mutated zstd
CFLAGS=-O0 make zstd-release
# Use the compiled zstd binary as a target for compression, and compress it.
cp ./programs/zstd tocompress
./zstd tocompress -o normal
# Mutate all the source files in the lib directory of zstd
FILES=()
for f in $(find lib -name "*.c")
do
FILES+=("${f}")
done
"${DREDD_EXECUTABLE}" --mutation-info-file temp.json -p "temp/compile_commands.json" "${FILES[@]}"
# Build mutated zstd
make clean
CFLAGS=-O0 make zstd-release
# Use it to compress the original (non-mutated) zstd binary
./zstd tocompress -o mutated
# The results obtained using the original and mutated versions of zstd should
# be identical, since no mutations were enabled.
diff normal mutated
popd
;;

*)
;;
esac

echo "Finished"
date
15 changes: 14 additions & 1 deletion .github/workflows/c_apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ jobs:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- macOS-latest
- windows-latest
config:
- Release
include:
- os: ubuntu-22.04
config: Debug

runs-on: ${{ matrix.os }}
env:
Expand Down Expand Up @@ -69,3 +73,12 @@ jobs:
run: |
.github/workflows/c_apps.sh
shell: bash
if: |
!startsWith(matrix.os, 'windows')
- name: build_step_windows
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
"C:\Program Files\Git\bin\bash.EXE" --noprofile --norc -e -o pipefail .github/workflows/c_apps.sh
shell: cmd
if: |
startsWith(matrix.os, 'windows')
89 changes: 75 additions & 14 deletions .github/workflows/cxx_apps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set -x
set -e
set -u

# Old bash versions can't expand empty arrays, so we always include at least this option.
CMAKE_OPTIONS=("-DCMAKE_OSX_ARCHITECTURES=x86_64")

help | head

Expand All @@ -38,8 +40,20 @@ case "$(uname)" in
df -h
;;

"Darwin")
NINJA_OS="mac"
SDKROOT=$(xcrun --show-sdk-path)
export SDKROOT
;;

"MINGW"*|"MSYS_NT"*)
NINJA_OS="win"
CMAKE_OPTIONS+=("-DCMAKE_C_COMPILER=cl.exe" "-DCMAKE_CXX_COMPILER=cl.exe")
choco install zip
;;

*)
echo "Unknown OS: only Linux is supported for the dev_build workflow"
echo "Unknown OS"
exit 1
;;
esac
Expand All @@ -58,39 +72,86 @@ popd

DREDD_ROOT=$(pwd)

export PATH="${DREDD_ROOT}/third_party/clang+llvm/bin:$PATH"
case "$(uname)" in
"Linux")
# On Linux, build Dredd using the prebuilt version of Clang that has been downloaded
export PATH="${DREDD_ROOT}/third_party/clang+llvm/bin:$PATH"
export CC=clang
export CXX=clang++
which ${CC}
which ${CXX}
;;

"Darwin")
;;

export CC=clang
export CXX=clang++
"MINGW"*|"MSYS_NT"*)
;;

which ${CC}
which ${CXX}
*)
echo "Unknown OS"
exit 1
;;
esac

mkdir -p build
pushd build
cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Debug
cmake --build . --config Debug
cmake -DCMAKE_INSTALL_PREFIX=./install -DBUILD_TYPE=Debug -P cmake_install.cmake
cmake -G Ninja .. -DCMAKE_BUILD_TYPE="${CONFIG}" "${CMAKE_OPTIONS[@]}"
cmake --build . --config "${CONFIG}"
cmake -DCMAKE_INSTALL_PREFIX=./install -DBUILD_TYPE="${CONFIG}" -P cmake_install.cmake
popd

# Check that dredd works on some projects
DREDD_EXECUTABLE="${DREDD_ROOT}/third_party/clang+llvm/bin/dredd"
cp "${DREDD_ROOT}/build/src/dredd/dredd" "${DREDD_EXECUTABLE}"

case "$(uname)" in
"Linux")
CMAKE_OPTIONS_FOR_COMPILING_MUTATED_CODE=("-DCMAKE_CXX_FLAGS=-w")
;;

"MINGW"*|"MSYS_NT"*)
# Dredd can lead to object files with many sections, which can be too much for MSVC's default settings.
# The /bigobj switch enables a larger number of sections.
CMAKE_OPTIONS_FOR_COMPILING_MUTATED_CODE=("-DCMAKE_CXX_FLAGS=\"/w /bigobj /EHsc\"")
;;

"Darwin")
# The Apple compiler does not use C++11 by default; Dredd requires at least this language version.
CMAKE_OPTIONS_FOR_COMPILING_MUTATED_CODE=("-DCMAKE_CXX_FLAGS=\"-w -std=c++11\"")
;;

*)
;;
esac

echo "examples/simple/pi.cc: check that we can build the simple example"
date

${DREDD_EXECUTABLE} --mutation-info-file temp.json examples/simple/pi.cc
clang++ examples/simple/pi.cc -o examples/simple/pi
diff <(./examples/simple/pi) <(echo "3.14159")
case "$(uname)" in
"Linux"|"Darwin")
clang++ -std=c++11 examples/simple/pi.cc -o examples/simple/pi
;;

"MINGW"*|"MSYS_NT"*)
cl examples/simple/pi.cc
mv pi.exe examples/simple/
;;

*)
;;
esac

diff --strip-trailing-cr <(./examples/simple/pi) <(echo "3.14159")

echo "examples/math: check that the tests pass after mutating the library"
date

pushd examples/math
mkdir build
pushd build
cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON "${CMAKE_OPTIONS_FOR_COMPILING_MUTATED_CODE[@]}" ..
../mutate.sh
cmake --build .
./mathtest/mathtest
Expand All @@ -106,7 +167,7 @@ pushd SPIRV-Tools
python3 utils/git-sync-deps
mkdir build
pushd build
cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DSPIRV_WERROR=OFF -DCMAKE_CXX_FLAGS="-w" ..
cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DSPIRV_WERROR=OFF "${CMAKE_OPTIONS_FOR_COMPILING_MUTATED_CODE[@]}" ..
# Build something minimal to ensure all header files get generated.
ninja SPIRV-Tools-static
popd
Expand All @@ -133,7 +194,7 @@ git clone --branch llvmorg-14.0.6 --depth 1 https://github.com/llvm/llvm-project
pushd llvm-project
mkdir build
pushd build
cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_FLAGS="-w" ../llvm
cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON "${CMAKE_OPTIONS_FOR_COMPILING_MUTATED_CODE[@]}" ../llvm
# Build something minimal to ensure all header files get generated.
ninja LLVMCore
popd
Expand Down
Loading