Skip to content

Commit ac88f0a

Browse files
committed
test: also test examples and run cross-compiled executables when possible
1 parent bbc1816 commit ac88f0a

2 files changed

Lines changed: 87 additions & 27 deletions

File tree

.azure-pipelines.yml

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,60 +29,71 @@ strategy:
2929
VM_IMAGE: 'ubuntu-20.04'
3030
APT_PACKAGES: ninja-build g++-8
3131
CXX_COMPILER: g++-8
32-
RUN_TESTS: true
3332
Linux i686 GCC:
3433
VM_IMAGE: 'ubuntu-20.04'
3534
APT_PACKAGES: ninja-build g++-i686-linux-gnu
3635
CXX_COMPILER: i686-linux-gnu-g++
37-
RUN_TESTS: true
3836
Linux arm64 GCC:
3937
VM_IMAGE: 'ubuntu-20.04'
40-
APT_PACKAGES: ninja-build g++-aarch64-linux-gnu
38+
APT_PACKAGES: ninja-build g++-aarch64-linux-gnu qemu-user
4139
CXX_COMPILER: aarch64-linux-gnu-g++
40+
CRUNCH_EXE_RUNNER: qemu-aarch64 -L /usr/aarch64-linux-gnu
4241
Linux armhf GCC:
4342
VM_IMAGE: 'ubuntu-20.04'
44-
APT_PACKAGES: ninja-build g++-arm-linux-gnueabihf
43+
APT_PACKAGES: ninja-build g++-arm-linux-gnueabihf qemu-user
4544
CXX_COMPILER: arm-linux-gnueabihf-g++
45+
CRUNCH_EXE_RUNNER: qemu-arm -L /usr/arm-linux-gnueabihf
46+
# There is a qemu-arm IO bug in ubuntu-20.04 and ubuntu-22.04,
47+
# remove when ubuntu-24.04 is available.
48+
CRUNCH_SIMPLE_TEST: true
4649
Linux amd64 Clang:
4750
VM_IMAGE: 'ubuntu-20.04'
4851
APT_PACKAGES: ninja-build
4952
CXX_COMPILER: clang++
50-
RUN_TESTS: true
5153
Windows amd64 MinGW:
52-
VM_IMAGE: 'ubuntu-20.04'
53-
APT_PACKAGES: ninja-build g++-mingw-w64-x86-64 mingw-w64-x86-64-dev
54+
VM_IMAGE: 'ubuntu-22.04'
55+
APT_PACKAGES: ninja-build g++-mingw-w64-x86-64 mingw-w64-x86-64-dev gcc-mingw-w64-x86-64-posix-runtime wine
5456
SETUP_COMMANDS: sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
5557
TOOLCHAIN_FILE: cmake/cross-toolchain-mingw64.cmake
56-
EXE_EXTENSIONS: .exe
58+
CRUNCH_EXE_RUNNER: wine
59+
CRUNCH_EXTENSION: .exe
60+
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
5761
Windows i686 MinGW:
58-
VM_IMAGE: 'ubuntu-20.04'
59-
APT_PACKAGES: ninja-build g++-mingw-w64-i686 mingw-w64-i686-dev
62+
VM_IMAGE: 'ubuntu-22.04'
63+
APT_ARCHITECTURE: i386
64+
APT_PACKAGES: ninja-build g++-mingw-w64-i686 mingw-w64-i686-dev gcc-mingw-w64-i686-posix-runtime wine wine32
6065
SETUP_COMMANDS: sudo update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix
6166
TOOLCHAIN_FILE: cmake/cross-toolchain-mingw32.cmake
62-
EXE_EXTENSIONS: .exe
67+
CRUNCH_EXE_RUNNER: wine
68+
CRUNCH_EXTENSION: .exe
69+
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
6370
macOS amd64 AppleClang:
6471
VM_IMAGE: 'macOS-12'
6572
CMAKE_GENERATOR: Unix Makefiles
6673
NPROC_COMMAND: sysctl -n hw.logicalcpu
67-
RUN_TESTS: true
6874
macOS arm64 AppleClang:
6975
VM_IMAGE: 'macOS-12'
7076
CMAKE_GENERATOR: Unix Makefiles
7177
COMPILER_FLAGS: -target arm64-apple-macos11 -Wno-overriding-t-option
7278
NPROC_COMMAND: sysctl -n hw.logicalcpu
79+
RUN_TESTS: false
7380
Web Asm.js Emscripten:
7481
VM_IMAGE: 'ubuntu-22.04'
7582
APT_PACKAGES: ninja-build emscripten
7683
TOOLCHAIN_FILE: /usr/share/emscripten/cmake/Modules/Platform/Emscripten.cmake
7784
SOURCE_DIR: emscripten
78-
EXE_EXTENSIONS: .js .wasm
85+
EXECUTABLES: crunch.js crunch.wasm
86+
RUN_TESTS: false
7987

8088
pool:
8189
vmImage: $(VM_IMAGE)
8290

8391
steps:
8492
- bash: |
8593
set -xue
94+
if [ -n "${APT_ARCHITECTURE:-}" ]; then
95+
sudo dpkg --add-architecture "${APT_ARCHITECTURE}"
96+
fi
8697
if [ -n "${APT_PACKAGES:-}" ]; then
8798
sudo apt-get update && sudo apt-get -y -q --no-install-recommends install ${APT_PACKAGES}
8899
fi
@@ -112,14 +123,14 @@ steps:
112123
displayName: 'Build'
113124
- bash: |
114125
set -xue
115-
if [ -z "${EXE_EXTENSIONS:-}" ]; then
116-
file 'build/crunch'
117-
else
118-
for ext in ${EXE_EXTENSIONS}; do
119-
file "build/crunch${ext}"
120-
done
126+
EXECUTABLES="${EXECUTABLES:-crunch example1 example2 example3}"
127+
for exe_file in ${EXECUTABLES}; do
128+
file 'build/${exe_file}${CRUNCH_EXTENSION:-}'
129+
done
130+
if [ -n "${RUNTIME_FILES:-}" ]; then
131+
cp -av ${RUNTIME_FILES} build/
121132
fi
122-
if "${RUN_TESTS:-false}"; then
133+
if "${RUN_TESTS:-true}"; then
123134
test/test.py
124135
fi
125136
displayName: 'Test'

test/test.py

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,44 @@
44
import subprocess
55
import sys
66

7+
build_dir = os.getenv("CRUNCH_BUILD_DIR", "build")
8+
executable_extension = os.getenv("CRUNCH_EXE_EXTENSION", "")
9+
executable_runner = os.getenv("CRUNCH_EXE_RUNNER")
10+
711
def print_command(command_list):
812
print("running: " + " ".join(command_list), file=sys.stderr)
913

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

1319
def run(command_list):
20+
if executable_runner:
21+
command_list = executable_runner.split(" ") + command_list
1422
print_command(command_list)
1523
returncode = subprocess.run(command_list).returncode
1624
if returncode:
1725
exit(returncode)
1826

1927
def mkdir(path):
28+
path = convert_path(path)
2029
print_command(["mkdir", path])
2130
os.makedirs(path, exist_ok=True)
2231

23-
def crunch(input_path, output_path, options=[]):
24-
executable_extension = ["", ".exe"][sys.platform == 'win32']
25-
executable_name = "crunch" + executable_extension
26-
27-
build_dir = "build"
32+
def get_build_dir():
2833
windows_build_dir = os.path.join(build_dir, "Release")
2934
if os.path.exists(windows_build_dir):
30-
build_dir = windows_build_dir
35+
return windows_build_dir
36+
return build_dir
3137

32-
executable_path = os.path.join(build_dir, executable_name)
38+
def get_executable_path(executable_name):
39+
executable_name += executable_extension
40+
build_dir = get_build_dir()
41+
return os.path.join(build_dir, executable_name)
42+
43+
def crunch(input_path, output_path, options=[]):
44+
executable_path = get_executable_path("crunch")
3345
command_list = [executable_path] + options
3446

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

4052
run(command_list)
4153

54+
def example(num, input_path, output_path, options=[]):
55+
executable_path = get_executable_path("example" + str(num))
56+
command_list = [executable_path]
57+
58+
if (num == 1):
59+
command_list += [options[0]]
60+
options = options[1:]
61+
62+
if input_path:
63+
input_path = convert_path(input_path)
64+
command_list += [input_path]
65+
66+
command_list += options
67+
68+
if output_path:
69+
output_path = convert_path(output_path)
70+
command_list += ["-out", output_path]
71+
72+
run(command_list)
73+
4274
crunch(None, None, ["--help"])
4375

76+
if "CRUNCH_SIMPLE_TEST" in os.environ.keys():
77+
exit(0)
78+
4479
mkdir("build/test/0")
4580
crunch("test/unvanquished_64.png", "build/test/0/unvanquished_64.crn")
4681
crunch("test/unvanquished_64.png", "build/test/0/unvanquished_64.dds")
@@ -99,3 +134,17 @@ def crunch(input_path, output_path, options=[]):
99134

100135
mkdir("build/test/7")
101136
crunch("test/black.jpg", "build/test/7/black.crn")
137+
138+
mkdir("build/test/8")
139+
example(1, "test/unvanquished_64.png", None, ["i"])
140+
example(1, "test/unvanquished_64.png", "build/test/8/unvanquished_64.dds", ["c"])
141+
142+
mkdir("build/test/9")
143+
example(1, "test/unvanquished_64.png", "build/test/9/unvanquished_64.crn", ["c", "-crn"])
144+
example(1, "build/test/9/unvanquished_64.crn", "build/test/9/unvanquished_64.dds", ["d"])
145+
146+
mkdir("build/test/10")
147+
example(2, "build/test/9/unvanquished_64.crn", "build/test/10/unvanquished_64.dds")
148+
149+
mkdir("build/test/11")
150+
example(3, "test/unvanquished_64.png", "build/test/11/unvanquished_64.dds")

0 commit comments

Comments
 (0)