Skip to content

Commit

Permalink
test: also test examples and run cross-compiled executables when poss…
Browse files Browse the repository at this point in the history
…ible
  • Loading branch information
illwieckz committed Jul 7, 2024
1 parent bbc1816 commit ac88f0a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 27 deletions.
51 changes: 31 additions & 20 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,60 +29,71 @@ strategy:
VM_IMAGE: 'ubuntu-20.04'
APT_PACKAGES: ninja-build g++-8
CXX_COMPILER: g++-8
RUN_TESTS: true
Linux i686 GCC:
VM_IMAGE: 'ubuntu-20.04'
APT_PACKAGES: ninja-build g++-i686-linux-gnu
CXX_COMPILER: i686-linux-gnu-g++
RUN_TESTS: true
Linux arm64 GCC:
VM_IMAGE: 'ubuntu-20.04'
APT_PACKAGES: ninja-build g++-aarch64-linux-gnu
APT_PACKAGES: ninja-build g++-aarch64-linux-gnu qemu-user
CXX_COMPILER: aarch64-linux-gnu-g++
CRUNCH_EXE_RUNNER: qemu-aarch64 -L /usr/aarch64-linux-gnu
Linux armhf GCC:
VM_IMAGE: 'ubuntu-20.04'
APT_PACKAGES: ninja-build g++-arm-linux-gnueabihf
APT_PACKAGES: ninja-build g++-arm-linux-gnueabihf qemu-user
CXX_COMPILER: arm-linux-gnueabihf-g++
CRUNCH_EXE_RUNNER: qemu-arm -L /usr/arm-linux-gnueabihf
# There is a qemu-arm IO bug in ubuntu-20.04 and ubuntu-22.04,
# remove when ubuntu-24.04 is available.
CRUNCH_SIMPLE_TEST: true
Linux amd64 Clang:
VM_IMAGE: 'ubuntu-20.04'
APT_PACKAGES: ninja-build
CXX_COMPILER: clang++
RUN_TESTS: true
Windows amd64 MinGW:
VM_IMAGE: 'ubuntu-20.04'
APT_PACKAGES: ninja-build g++-mingw-w64-x86-64 mingw-w64-x86-64-dev
VM_IMAGE: 'ubuntu-22.04'
APT_PACKAGES: ninja-build g++-mingw-w64-x86-64 mingw-w64-x86-64-dev gcc-mingw-w64-x86-64-posix-runtime wine
SETUP_COMMANDS: sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
TOOLCHAIN_FILE: cmake/cross-toolchain-mingw64.cmake
EXE_EXTENSIONS: .exe
CRUNCH_EXE_RUNNER: wine
CRUNCH_EXTENSION: .exe
RUNTIME_FILES: /usr/lib/gcc/x86_64-w64-mingw32/10-posix/libgcc_s_seh-1.dll /usr/lib/gcc/x86_64-w64-mingw32/10-posix/libstdc++-6.dll /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll
Windows i686 MinGW:
VM_IMAGE: 'ubuntu-20.04'
APT_PACKAGES: ninja-build g++-mingw-w64-i686 mingw-w64-i686-dev
VM_IMAGE: 'ubuntu-22.04'
APT_ARCHITECTURE: i386
APT_PACKAGES: ninja-build g++-mingw-w64-i686 mingw-w64-i686-dev gcc-mingw-w64-i686-posix-runtime wine wine32
SETUP_COMMANDS: sudo update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix
TOOLCHAIN_FILE: cmake/cross-toolchain-mingw32.cmake
EXE_EXTENSIONS: .exe
CRUNCH_EXE_RUNNER: wine
CRUNCH_EXTENSION: .exe
RUNTIME_FILES: /usr/lib/gcc/i686-w64-mingw32/10-posix/libgcc_s_dw2-1.dll /usr/lib/gcc/i686-w64-mingw32/10-posix/libstdc++-6.dll /usr/i686-w64-mingw32/lib/libwinpthread-1.dll
macOS amd64 AppleClang:
VM_IMAGE: 'macOS-12'
CMAKE_GENERATOR: Unix Makefiles
NPROC_COMMAND: sysctl -n hw.logicalcpu
RUN_TESTS: true
macOS arm64 AppleClang:
VM_IMAGE: 'macOS-12'
CMAKE_GENERATOR: Unix Makefiles
COMPILER_FLAGS: -target arm64-apple-macos11 -Wno-overriding-t-option
NPROC_COMMAND: sysctl -n hw.logicalcpu
RUN_TESTS: false
Web Asm.js Emscripten:
VM_IMAGE: 'ubuntu-22.04'
APT_PACKAGES: ninja-build emscripten
TOOLCHAIN_FILE: /usr/share/emscripten/cmake/Modules/Platform/Emscripten.cmake
SOURCE_DIR: emscripten
EXE_EXTENSIONS: .js .wasm
EXECUTABLES: crunch.js crunch.wasm
RUN_TESTS: false

pool:
vmImage: $(VM_IMAGE)

steps:
- bash: |
set -xue
if [ -n "${APT_ARCHITECTURE:-}" ]; then
sudo dpkg --add-architecture "${APT_ARCHITECTURE}"
fi
if [ -n "${APT_PACKAGES:-}" ]; then
sudo apt-get update && sudo apt-get -y -q --no-install-recommends install ${APT_PACKAGES}
fi
Expand Down Expand Up @@ -112,14 +123,14 @@ steps:
displayName: 'Build'
- bash: |
set -xue
if [ -z "${EXE_EXTENSIONS:-}" ]; then
file 'build/crunch'
else
for ext in ${EXE_EXTENSIONS}; do
file "build/crunch${ext}"
done
EXECUTABLES="${EXECUTABLES:-crunch example1 example2 example3}"
for exe_file in ${EXECUTABLES}; do
file 'build/${exe_file}${CRUNCH_EXTENSION:-}'
done
if [ -n "${RUNTIME_FILES:-}" ]; then
cp -av ${RUNTIME_FILES} build/
fi
if "${RUN_TESTS:-false}"; then
if "${RUN_TESTS:-true}"; then
test/test.py
fi
displayName: 'Test'
63 changes: 56 additions & 7 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,44 @@
import subprocess
import sys

build_dir = os.getenv("CRUNCH_BUILD_DIR", "build")
executable_extension = os.getenv("CRUNCH_EXE_EXTENSION", "")
executable_runner = os.getenv("CRUNCH_EXE_RUNNER")

def print_command(command_list):
print("running: " + " ".join(command_list), file=sys.stderr)

def convert_path(path):
if path.startswith("build/"):
path = build_dir + path[len("build"):]
return path.replace("/", os.path.sep)

def run(command_list):
if executable_runner:
command_list = executable_runner.split(" ") + command_list
print_command(command_list)
returncode = subprocess.run(command_list).returncode
if returncode:
exit(returncode)

def mkdir(path):
path = convert_path(path)
print_command(["mkdir", path])
os.makedirs(path, exist_ok=True)

def crunch(input_path, output_path, options=[]):
executable_extension = ["", ".exe"][sys.platform == 'win32']
executable_name = "crunch" + executable_extension

build_dir = "build"
def get_build_dir():
windows_build_dir = os.path.join(build_dir, "Release")
if os.path.exists(windows_build_dir):
build_dir = windows_build_dir
return windows_build_dir
return build_dir

executable_path = os.path.join(build_dir, executable_name)
def get_executable_path(executable_name):
executable_name += executable_extension
build_dir = get_build_dir()
return os.path.join(build_dir, executable_name)

def crunch(input_path, output_path, options=[]):
executable_path = get_executable_path("crunch")
command_list = [executable_path] + options

if input_path:
Expand All @@ -39,8 +51,31 @@ def crunch(input_path, output_path, options=[]):

run(command_list)

def example(num, input_path, output_path, options=[]):
executable_path = get_executable_path("example" + str(num))
command_list = [executable_path]

if (num == 1):
command_list += [options[0]]
options = options[1:]

if input_path:
input_path = convert_path(input_path)
command_list += [input_path]

command_list += options

if output_path:
output_path = convert_path(output_path)
command_list += ["-out", output_path]

run(command_list)

crunch(None, None, ["--help"])

if "CRUNCH_SIMPLE_TEST" in os.environ.keys():
exit(0)

mkdir("build/test/0")
crunch("test/unvanquished_64.png", "build/test/0/unvanquished_64.crn")
crunch("test/unvanquished_64.png", "build/test/0/unvanquished_64.dds")
Expand Down Expand Up @@ -99,3 +134,17 @@ def crunch(input_path, output_path, options=[]):

mkdir("build/test/7")
crunch("test/black.jpg", "build/test/7/black.crn")

mkdir("build/test/8")
example(1, "test/unvanquished_64.png", None, ["i"])
example(1, "test/unvanquished_64.png", "build/test/8/unvanquished_64.dds", ["c"])

mkdir("build/test/9")
example(1, "test/unvanquished_64.png", "build/test/9/unvanquished_64.crn", ["c", "-crn"])
example(1, "build/test/9/unvanquished_64.crn", "build/test/9/unvanquished_64.dds", ["d"])

mkdir("build/test/10")
example(2, "build/test/9/unvanquished_64.crn", "build/test/10/unvanquished_64.dds")

mkdir("build/test/11")
example(3, "test/unvanquished_64.png", "build/test/11/unvanquished_64.dds")

0 comments on commit ac88f0a

Please sign in to comment.