Skip to content

Commit feb8fc9

Browse files
committed
test: also test examples, support some environment variables for configuration
1 parent ed6c813 commit feb8fc9

2 files changed

Lines changed: 105 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_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_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_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_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: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,62 @@
44
import subprocess
55
import sys
66

7+
if "CRUNCH_BUILD_DIR" in os.environ.keys():
8+
build_dir = os.environ["CRUNCH_BUILD_DIR"]
9+
else:
10+
build_dir = "build"
11+
12+
if "CRUNCH_RUNNER" in os.environ.keys():
13+
crunch_runner = os.environ["CRUNCH_RUNNER"]
14+
else:
15+
crunch_runner = None
16+
17+
if "CRUNCH_EXTENSION" in os.environ.keys():
18+
crunch_extension = os.environ["CRUNCH_EXTENSION"]
19+
else:
20+
crunch_extension = None
21+
722
def print_command(command_list):
823
print("running: " + " ".join(command_list), file=sys.stderr)
924

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

1330
def run(command_list):
31+
if crunch_runner:
32+
command_list = crunch_runner.split(" ") + command_list
1433
print_command(command_list)
1534
returncode = subprocess.run(command_list).returncode
1635
if returncode:
1736
exit(returncode)
1837

1938
def mkdir(path):
39+
path = convert_path(path)
2040
print_command(["mkdir", path])
2141
os.makedirs(path, exist_ok=True)
2242

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"
43+
def get_build_dir():
2844
windows_build_dir = os.path.join(build_dir, "Release")
2945
if os.path.exists(windows_build_dir):
30-
build_dir = windows_build_dir
46+
return windows_build_dir
47+
return build_dir
3148

32-
executable_path = os.path.join(build_dir, executable_name)
49+
def get_executable_path(executable_name):
50+
if crunch_extension:
51+
executable_extension = crunch_extension
52+
elif sys.platform == "win32":
53+
executable_extension = ".exe"
54+
else:
55+
executable_extension = ""
56+
57+
executable_name += executable_extension
58+
build_dir = get_build_dir()
59+
return os.path.join(build_dir, executable_name)
60+
61+
def crunch(input_path, output_path, options=[]):
62+
executable_path = get_executable_path("crunch")
3363
command_list = [executable_path] + options
3464

3565
if input_path:
@@ -39,8 +69,31 @@ def crunch(input_path, output_path, options=[]):
3969

4070
run(command_list)
4171

72+
def example(num, input_path, output_path, options=[]):
73+
executable_path = get_executable_path("example" + str(num))
74+
command_list = [executable_path]
75+
76+
if (num == 1):
77+
command_list += [options[0]]
78+
options = options[1:]
79+
80+
if input_path:
81+
input_path = convert_path(input_path)
82+
command_list += [input_path]
83+
84+
command_list += options
85+
86+
if output_path:
87+
output_path = convert_path(output_path)
88+
command_list += ["-out", output_path]
89+
90+
run(command_list)
91+
4292
crunch(None, None, ["--help"])
4393

94+
if "CRUNCH_SIMPLE_TEST" in os.environ.keys():
95+
exit(0)
96+
4497
mkdir("build/test/0")
4598
crunch("test/unvanquished_64.png", "build/test/0/unvanquished_64.crn")
4699
crunch("test/unvanquished_64.png", "build/test/0/unvanquished_64.dds")
@@ -99,3 +152,17 @@ def crunch(input_path, output_path, options=[]):
99152

100153
mkdir("build/test/7")
101154
crunch("test/black.jpg", "build/test/7/black.crn")
155+
156+
mkdir("build/test/8")
157+
example(1, "test/unvanquished_64.png", None, ["i"])
158+
example(1, "test/unvanquished_64.png", "build/test/8/unvanquished_64.dds", ["c"])
159+
160+
mkdir("build/test/9")
161+
example(1, "test/unvanquished_64.png", "build/test/9/unvanquished_64.crn", ["c", "-crn"])
162+
example(1, "build/test/9/unvanquished_64.crn", "build/test/9/unvanquished_64.dds", ["d"])
163+
164+
mkdir("build/test/10")
165+
example(2, "build/test/9/unvanquished_64.crn", "build/test/10/unvanquished_64.dds")
166+
167+
mkdir("build/test/11")
168+
example(3, "test/unvanquished_64.png", "build/test/11/unvanquished_64.dds")

0 commit comments

Comments
 (0)