Files
KTX-Software/tests/toktx-tests
2018-04-27 20:12:10 +09:00

176 lines
4.7 KiB
Bash
Executable File

#! /bin/bash
# -*- tab-width: 4; -*-
# vi: set sw=2 ts=4:
# Regression tests for toktx
# -------------------------------------------------------------------------
#
# ©2010 The Khronos Group, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -------------------------------------------------------------------------
# Depth of this script relative to the project root
depth=..
# Change dir to the testimages folder, a child of the script location...
cd $(dirname $0)/testimages
# ...and adjust depth
depth=$depth/..
# Make paths relative to the testimages directory.
ktx_root=$depth
toktx_vs2013=$ktx_root/build/msvs/win/vs2013/x64/Release/toktx.exe
toktx_vs2015=$ktx_root/build/msvs/win/vs2015/x64/Release/toktx.exe
toktx_cmake=$ktx_root/build/cmake/linux/Release/toktx
toktx_cmake_d=$ktx_root/build/cmake/linux/Debug/toktx
toktx_make=$ktx_root/build/make/linux/out/Release/toktx
toktx_make_d=$ktx_root/build/make/linux/out/Debug/toktx
declare -i numtests=0
declare -i passed=0
declare -i failed=0
# Ensure test is not polluted by user environment
unset TOKTX_OPTIONS
if [ -n "$1" -a -x "$1" ]; then
toktx="$1"
elif [ -x "$toktx_vs2013" ]; then
toktx=$toktx_vs2013
elif [ -x "$toktx_vs2015" ]; then
toktx=$toktx_vs2015
elif [ -x "$toktx_cmake" ]; then
toktx=$toktx_cmake
elif [ -x "$toktx_cmake_d" ]; then
toktx=$toktx_cmake_d
elif [ -x "$toktx_make" ]; then
toktx=$toktx_gmake
elif [ -x "$toktx_make_d" ]; then
toktx=$toktx_gmake
else
echo $0: None of $toktx_vs2013, $toktx_vs2015, $toktx_gmake or $toktx_cmake found.
echo $0: Aborting test
exit 1
fi
numtests=$numtests+1
if $toktx --help 2> /dev/null; then
passed=$passed+1
else
echo "--help not recognized"
failed=$failed+1
fi
numtests=$numtests+1
if $toktx --version 2> /dev/null; then
passed=$passed+1
else
echo "--version not recognized"
failed=$failed+1
fi
numtests=$numtests+1
if ! $toktx --foobar 2> /dev/null; then
passed=$passed+1
else
echo "invalid option --foobar accepted"
failed=$failed+1
fi
numtests=$numtests+1
if ! $toktx --automipmap --mipmaps a b 2> /dev/null; then
passed=$passed+1
else
echo "Simultaneous --automipmap & --mipmaps allowed"
failed=$failed+1
fi
numtests=$numtests+1
if ! $toktx --alpha --luminance a b 2> /dev/null; then
passed=$passed+1
else
echo "Simultaneous --alpha & --luminance allowed"
failed=$failed+1
fi
function cmpktx () {
if diff $1 $2; then
passed=$passed+1
else
failed=$failed+1
echo "created ktx file differs from target $2"
fi
}
# Generate ktx file and compare with reference
# gencmpktx <reference> <toktx args> <toktx infile> ...
function gencmpktx() {
numtests=$numtests+1
local args
local reference=$1; shift
for i in $*; do
if [ ${i:0:2} == "--" ]; then
args="$args $i"
shift
fi
done
#echo $toktx $args $tempfile $*
$toktx $args $tempfile $*
cmpktx $tempfile $reference
rm $tempfile
}
#---------------- Tests start here -----------------------
# Git Bash does not include mktemp.
if which mktemp > /dev/null; then
tempfile=$(mktemp toktxXXXX.ktx)
else
tempfile=/tmp/toktxXXXX.ktx
fi
gencmpktx rgb-reference.ktx --lower_left_maps_to_s0t0 --nometadata rgb.ppm
gencmpktx rgb-amg-reference.ktx --automipmap --lower_left_maps_to_s0t0 --nometadata rgb.ppm
TOKTX_OPTIONS="--lower_left_maps_to_s0t0 --nometadata" gencmpktx orient-up.ktx up.ppm
gencmpktx orient-up-metadata.ktx --lower_left_maps_to_s0t0 up.ppm
gencmpktx orient-down-metadata.ktx up.ppm
gencmpktx rgb-mipmap-reference.ktx --lower_left_maps_to_s0t0 --mipmap --nometadata level0.ppm level1.ppm level2.ppm level3.ppm level4.ppm level5.ppm level6.ppm
gencmpktx rgba-reference.ktx --lower_left_maps_to_s0t0 --nometadata rgba.pam
gencmpktx luminance-reference-metadata.ktx --luminance luminance.pgm
numtests=$numtests+1
TOKTX_OPTIONS=--lower_left_maps_to_s0t0 $toktx --nometadata - rgb.ppm > $tempfile
cmpktx $tempfile rgb-reference.ktx
rm $tempfile
numtests=$numtests+1
cat rgb.ppm | $toktx --lower_left_maps_to_s0t0 --nometadata - > $tempfile
cmpktx $tempfile rgb-reference.ktx
rm $tempfile
numtests=$numtests+1
cat rgb.ppm | $toktx --lower_left_maps_to_s0t0 --nometadata $tempfile
cmpktx $tempfile rgb-reference.ktx
rm $tempfile
echo "Tests run: $numtests; passed: $passed; failed: $failed"
if [ $failed -gt 0 ]; then
exit 1;
else
exit 0;
fi