From a2a66789988afd67212513f94f43bbdc1db7adc6 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 11 Jul 2024 04:32:50 +0200 Subject: [PATCH 1/8] test: add RLE TGA images The RLE TGA images were converted from raw TGA ones using GIMP and some tweaks as the GIMP exporter only support bottom-left and top-left: - Left ones are unmodified GIMP export. - Right ones are in-GIMP horizontally flipped images exported as left ones then the TGA X flip bit was modified by hand in a hex editor. --- test/rle-bottom-left.tga | Bin 0 -> 536 bytes test/rle-bottom-right.tga | Bin 0 -> 536 bytes test/rle-top-left.tga | Bin 0 -> 536 bytes test/rle-top-right.tga | Bin 0 -> 536 bytes test/test.py | 4 ++++ 5 files changed, 4 insertions(+) create mode 100644 test/rle-bottom-left.tga create mode 100644 test/rle-bottom-right.tga create mode 100644 test/rle-top-left.tga create mode 100644 test/rle-top-right.tga diff --git a/test/rle-bottom-left.tga b/test/rle-bottom-left.tga new file mode 100644 index 0000000000000000000000000000000000000000..7ce5ad96947125fc7aac5e6dbe6b156ca28b534c GIT binary patch literal 536 zcmZQz;9`IQ1qLAGnExLLs7SN{jsMR9GIam`{r~Ih>;K!^+y4g%0?~gU2_%3RNcMxs zevk~9)dE%n5^Dmnnn0{(T(V#jT8Ween*uhk5pD-UFTw=~7D63ZFW9zrxNQhouuH+R z9av-$>N-(nnLvI634uTts$3&TtQ%FV6(okRAK^}-!WkSR;2;K?3I-uTp{`+`!Jhtp Mx)E-kKCXHU04dZzdjJ3c literal 0 HcmV?d00001 diff --git a/test/rle-bottom-right.tga b/test/rle-bottom-right.tga new file mode 100644 index 0000000000000000000000000000000000000000..17a32e574965298b4f00563196fd94737ceb5626 GIT binary patch literal 536 zcmZQz;9`IQ1qL9LnExLLs7UmK%;NxJhW`ve1fhUThX3~V_W$ea>;LcHzaOOLe;Y^; zth^u2Y6h{IK(b9B76XXY0+(%ti%}xm2)6@l8=4CcZfS?x237}l3s^5$M+aOM;TD8! zCtMaRhNia*B+CTy8;Ah{2%X&^p+;0OuuED|#SrcUha*uT4m27JLV`kF!#smM{rz+! K+&q0;^%wwTVn2%j literal 0 HcmV?d00001 diff --git a/test/rle-top-left.tga b/test/rle-top-left.tga new file mode 100644 index 0000000000000000000000000000000000000000..5a84a8ece9273f1a4e02e2663c906e1eeea57147 GIT binary patch literal 536 zcmZQz;9`IP1qLwG;P?*&`}gnvUteGU-`?K-KTsNo|NjS)Kmv$?WE)7ZAH?j3vl>CH zR*+abs#qgPtQ%E~2_yy*0)Z}6Ij|tuG%%|Zi)<4}3@qD$MYb6(i*O0Tod_0KT@%O! z2-{lW=C#00LD)v7EZ7dPZD?Tz4o9Lw9ISCZ$gNZ)fIb9+kf2c4FwbC5e?Q#_H%}i| GJq7?qP(Ql> literal 0 HcmV?d00001 diff --git a/test/rle-top-right.tga b/test/rle-top-right.tga new file mode 100644 index 0000000000000000000000000000000000000000..7473c1faf181639b689a71d7f037f746bc75b5ba GIT binary patch literal 536 zcmZQz;9`IP1qLv*=>HD{Z9uXA96$!ce;@-48Gsxh+uq*(e|>%Z|NZ;-gB1P;EAI!% zfLZMzRx3!N5iZsZVl|?Qb%Df~Kw=;Us$3^X2rLLT1Hl5@&;gfig0m2If$azDXvQLo za3_M*imI*& Date: Thu, 11 Jul 2024 04:42:46 +0200 Subject: [PATCH 2/8] stb_image: support horizontally flipped TGA images The TGA format is a bottom-left format by default: the first byte of the first column is expected to be displayed at the bottom-left of the screen, this behavior is inherited from devices painting the screen from the bottom left to the top right. The TGA format provides two bits in the image descriptor byte to paint the data from other sides. The 4th bit tells the device to paint the screen from right-to left and the 5th bit tells the device to paint the screen from top to bottom. So basically: - 00: from bottom-left to top-right - 01: from top-left to bottom-right - 10: from bottom-right to top-left - 11: from top-right to bottom-left Previously stb_image only read the 5th bit and then only supported the loading of vertically flipped images, stb_image was ignoring the 4th bit coding the horizontal flip. Now both flipping directions are supported for both raw and RLE storage. --- crnlib/stb_image.h | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/crnlib/stb_image.h b/crnlib/stb_image.h index 9eedabed..884a29ca 100644 --- a/crnlib/stb_image.h +++ b/crnlib/stb_image.h @@ -5884,8 +5884,8 @@ static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req int tga_height = stbi__get16le(s); int tga_bits_per_pixel = stbi__get8(s); int tga_comp, tga_rgb16=0; - int tga_inverted = stbi__get8(s); - // int tga_alpha_bits = tga_inverted & 15; // the 4 lowest bits - unused (useless?) + int tga_descriptor = stbi__get8(s); + // int tga_alpha_bits = tga_descriptor & 15; // the 4 lowest bits - unused (useless?) // image data unsigned char *tga_data; unsigned char *tga_palette = NULL; @@ -5907,7 +5907,8 @@ static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req tga_image_type -= 8; tga_is_RLE = 1; } - tga_inverted = 1 - ((tga_inverted >> 5) & 1); + int tga_x_inverted = ((tga_descriptor >> 4) & 1); + int tga_y_inverted = 1 - ((tga_descriptor >> 5) & 1); // If I'm paletted, then I'll use the number of bits from the palette if ( tga_indexed ) tga_comp = stbi__tga_get_comp(tga_palette_bits, 0, &tga_rgb16); @@ -5932,9 +5933,16 @@ static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req if ( !tga_indexed && !tga_is_RLE && !tga_rgb16 ) { for (i=0; i < tga_height; ++i) { - int row = tga_inverted ? tga_height -i - 1 : i; + int row = tga_y_inverted ? tga_height - i - 1 : i; stbi_uc *tga_row = tga_data + row*tga_width*tga_comp; - stbi__getn(s, tga_row, tga_width * tga_comp); + if (tga_x_inverted) { + for (j = 0; j < tga_width; j++) { + int index = (tga_width - j - 1) * tga_comp; + stbi__getn(s, tga_row + index, tga_comp); + } + } else { + stbi__getn(s, tga_row, tga_width * tga_comp); + } } } else { // do I need to load a palette? @@ -6024,7 +6032,22 @@ static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req --RLE_count; } // do I need to invert the image? - if ( tga_inverted ) + if (tga_x_inverted) + { + for (j = 0; j < tga_height; j++) { + stbi_uc *row = tga_data + (j * tga_width * tga_comp); + for (int s = 0, d = tga_width - 1; s * 2 < tga_width; s++, d--) { + stbi_uc *src = row + (s * tga_comp); + stbi_uc *dest = row + (d * tga_comp); + for (i = 0; i < tga_comp; i++) { + stbi_uc temp = src[i]; + src[i] = dest[i]; + dest[i] = temp; + } + } + } + } + if (tga_y_inverted) { for (j = 0; j*2 < tga_height; ++j) { From a26263bc6b9daaa96ea28230f438b2b6500f1c28 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 11 Jul 2024 08:19:24 +0200 Subject: [PATCH 3/8] ci/azure-pipelines: avoid x87 on i686 --- .azure-pipelines.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 58e0d4cb..f0bb42cb 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -33,6 +33,7 @@ strategy: VM_IMAGE: 'ubuntu-20.04' APT_PACKAGES: ninja-build g++-i686-linux-gnu CXX_COMPILER: i686-linux-gnu-g++ + COMPILER_FLAGS: -mfpmath=sse -msse Linux arm64 GCC: VM_IMAGE: 'ubuntu-20.04' APT_PACKAGES: ninja-build g++-aarch64-linux-gnu qemu-user @@ -64,6 +65,7 @@ strategy: 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 + COMPILER_FLAGS: -mfpmath=sse -msse 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 From a4ae6f1adc58eff7ec00e9d292211367c21cbb28 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 11 Jul 2024 08:19:24 +0200 Subject: [PATCH 4/8] ci: disable fast math --- .appveyor.yml | 1 + .azure-pipelines.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index 283e75ff..3c686c07 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -51,6 +51,7 @@ build_script: cmake -Wdev -G"%generator%" -A"%platform%" -S. -Bbuild -DCMAKE_CONFIGURATION_TYPES=Release -DBUILD_CRUNCH=ON -DBUILD_SHARED_LIBCRN=ON -DBUILD_EXAMPLES=ON + -DUSE_FAST_MATH=OFF cmake --build build --config Release diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index f0bb42cb..abfe52f6 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -120,6 +120,7 @@ steps: if [ -z "${SOURCE_DIR:-}" ]; then cmake_args+=(-DBUILD_CRUNCH=ON -DBUILD_SHARED_LIBCRN=ON -DBUILD_EXAMPLES=ON) fi + cmake_args+=(-DUSE_FAST_MATH=OFF) cmake -S"${SOURCE_DIR:-.}" -Bbuild "${cmake_args[@]}" cmake --build build --config Release displayName: 'Build' From 487cb5f88a1f708cea5c38ef6185c2e52d7476b4 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 11 Jul 2024 11:13:33 +0200 Subject: [PATCH 5/8] ci: install pip packages --- .appveyor.yml | 2 ++ .azure-pipelines.yml | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index 3c686c07..c5904aee 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -39,6 +39,8 @@ build_script: # The CMAKE_CONFIGURATION_TYPES CMake option make sure to not uselessly provide # build configurations that will not be used. - cmd: > + pip install colorama + echo %NUMBER_OF_PROCESSORS% set CMAKE_BUILD_PARALLEL_LEVEL=%NUMBER_OF_PROCESSORS% diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index abfe52f6..17a23731 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -71,10 +71,12 @@ strategy: 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' + PIP_PACKAGES: colorama CMAKE_GENERATOR: Unix Makefiles NPROC_COMMAND: sysctl -n hw.logicalcpu macOS arm64 AppleClang: VM_IMAGE: 'macOS-12' + PIP_PACKAGES: colorama CMAKE_GENERATOR: Unix Makefiles COMPILER_FLAGS: -target arm64-apple-macos11 -Wno-overriding-t-option NPROC_COMMAND: sysctl -n hw.logicalcpu @@ -99,6 +101,9 @@ steps: if [ -n "${APT_PACKAGES:-}" ]; then sudo apt-get update && sudo apt-get -y -q --no-install-recommends install ${APT_PACKAGES} fi + if [ -n "${PIP_PACKAGES:-}" ]; then + pip install ${PIP_PACKAGES} + fi if [ -n "${SETUP_COMMANDS:-}" ]; then $(SETUP_COMMANDS) fi From 9fc7aa87968d04192ab77c2298426f7ac14a4773 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 16 Jul 2024 23:15:19 +0200 Subject: [PATCH 6/8] cmake: also disable FP contraction when disabling fast math --- CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24b6e976..2254202a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,10 @@ if (MSVC) # CMake already sets the /O2 flag on Release and RelWithDebInfo build and /O[1-2] already sets the /Oy flag. if (USE_FAST_MATH) + # By default, the MSVC /fp:fast option enables /fp:contract (introduced in VS 2022). + # See https://learn.microsoft.com/en-us/cpp/build/reference/fp-specify-floating-point-behavior + # and https://devblogs.microsoft.com/cppblog/the-fpcontract-flag-and-changes-to-fp-modes-in-vs2022/ + # By default, MSVC doesn't enable the /fp:fast option. set_cxx_flag("/fp:fast") endif() @@ -109,7 +113,13 @@ else() endif() if (USE_FAST_MATH) - set_cxx_flag("-ffast-math -fno-math-errno") + # By default, GCC uses -ffp-contract=fast with -std=gnu* and uses -ffp-contract=off with -std=c*. + # See https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html + # By default, GCC doesn't enable the -ffast-math option. + set_cxx_flag("-ffast-math -fno-math-errno -ffp-contract=fast") + else() + # By default, GCC uses -std=gnu* and then enables -ffp-contract=fast even if -ffast-math is not enabled. + set_cxx_flag("-ffp-contract=off") endif() # It should be done at the very end because it copies all compiler flags From a3e01aea471809ed2b096398a748dd116b14a842 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Wed, 17 Jul 2024 05:25:36 +0200 Subject: [PATCH 7/8] ci: minor changes in ways how things build or link - appveyor: do not build the shared library (it is unusable yet), - azure-pipelines: make all binaries use the same library, - codeql: use the shared library. --- .appveyor.yml | 2 +- .azure-pipelines.yml | 2 +- .github/workflows/codeql.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index c5904aee..d55826f4 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -52,7 +52,7 @@ build_script: set CXXFLAGS=/Wv:19.29.30037 cmake -Wdev -G"%generator%" -A"%platform%" -S. -Bbuild -DCMAKE_CONFIGURATION_TYPES=Release - -DBUILD_CRUNCH=ON -DBUILD_SHARED_LIBCRN=ON -DBUILD_EXAMPLES=ON + -DBUILD_CRUNCH=ON -DBUILD_EXAMPLES=ON -DUSE_FAST_MATH=OFF cmake --build build --config Release diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 17a23731..33314f9c 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -123,7 +123,7 @@ steps: cmake_args+=(-DCMAKE_CXX_FLAGS="${COMPILER_FLAGS}") fi if [ -z "${SOURCE_DIR:-}" ]; then - cmake_args+=(-DBUILD_CRUNCH=ON -DBUILD_SHARED_LIBCRN=ON -DBUILD_EXAMPLES=ON) + cmake_args+=(-DBUILD_CRUNCH=ON -DBUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON) fi cmake_args+=(-DUSE_FAST_MATH=OFF) cmake -S"${SOURCE_DIR:-.}" -Bbuild "${cmake_args[@]}" diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index a691f6ee..5c9e02e9 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -75,7 +75,7 @@ jobs: export CMAKE_BUILD_PARALLEL_LEVEL="$(nproc)" echo "${CMAKE_BUILD_PARALLEL_LEVEL}" cmake -Wdev -S. -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_CRUNCH=ON -DBUILD_SHARED_LIBCRN=ON -DBUILD_EXAMPLES=OFF + -DBUILD_CRUNCH=ON -DBUILD_EXAMPLES=OFF -DBUILD_SHARED_LIBS=ON cmake --build build - name: Perform CodeQL Analysis From 097416217bef15baf32cf274865f200ba217e232 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 11 Jul 2024 05:27:10 +0200 Subject: [PATCH 8/8] test: add more tests, check some output, improve readability --- test/checksums.tsv | 89 +++++++++ test/test.py | 447 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 444 insertions(+), 92 deletions(-) create mode 100644 test/checksums.tsv diff --git a/test/checksums.tsv b/test/checksums.tsv new file mode 100644 index 00000000..bc225bc8 --- /dev/null +++ b/test/checksums.tsv @@ -0,0 +1,89 @@ +build/test/png-to-all/unvanquished_64.tga 34434170b06843b2d4fb5964a4b8751ec3a151a7d03e351e45a5967508f6a21f6e40ffc214bb46640105c4058bc35e196ecb5dd3261528a64acfeff52034fb40 +build/test/png-to-all/unvanquished_64.bmp 1c5f28be8151a8125346e9cf17b1bf6e3f9fe27f6947b164b7eefa8fd3732a2e4dff173c354a0cd4ed599cd604d4b8f916c0575b0a4b4b508acc68dc9b4067ae +build/test/png-to-all/unvanquished_64.png 71bb28da97cd778b99f131acaeb1c28ea37bae295a9e9934bed339508d8428587120c0da8f5bbc7963cdb77741ef789414f9d0d2c1e0da46026336efde147cc5 +build/test/png-to-all/unvanquished_64.crn a3b526e95f44b6a4c919bc8eb79f4debf592f0bccc163c900cd1b6f9add0ce58c3db9fc8dac1828d350bbcd915823d7743a0c114a533fbc08c163fcb4846d2f5 +build/test/png-to-all/unvanquished_64.dds ce98b21c574b4883e4aff4a0b92fd0f533f22e00ab753686f353111fa7503287c2c4dba25f2c2670508630d79b59464578e094461bad81ad803e1d58ed5e69f8 +build/test/png-to-all/unvanquished_64.ktx d82eab591163d802231722ef325571735971b6a9b0703ed8ea59b4a4144189825d96d3455605426453fb3ad8d7cc61f931c52b3e73df2bb6787f7408baeb4ac7 +build/test/png-to-all/unvanquished_64.jpg 6cd22de7e2e5baced5ef16e84f816dde3049f822459d552ced4dcd4e3f9a16be82ee0747ed1479fe8339991176004b4ccc90380b7ef51292c7d9b518503a348d +build/test/tga-to-all/unvanquished_64.tga 34434170b06843b2d4fb5964a4b8751ec3a151a7d03e351e45a5967508f6a21f6e40ffc214bb46640105c4058bc35e196ecb5dd3261528a64acfeff52034fb40 +build/test/tga-to-all/unvanquished_64.bmp 1c5f28be8151a8125346e9cf17b1bf6e3f9fe27f6947b164b7eefa8fd3732a2e4dff173c354a0cd4ed599cd604d4b8f916c0575b0a4b4b508acc68dc9b4067ae +build/test/tga-to-all/unvanquished_64.png 71bb28da97cd778b99f131acaeb1c28ea37bae295a9e9934bed339508d8428587120c0da8f5bbc7963cdb77741ef789414f9d0d2c1e0da46026336efde147cc5 +build/test/tga-to-all/unvanquished_64.crn a3b526e95f44b6a4c919bc8eb79f4debf592f0bccc163c900cd1b6f9add0ce58c3db9fc8dac1828d350bbcd915823d7743a0c114a533fbc08c163fcb4846d2f5 +build/test/tga-to-all/unvanquished_64.dds ce98b21c574b4883e4aff4a0b92fd0f533f22e00ab753686f353111fa7503287c2c4dba25f2c2670508630d79b59464578e094461bad81ad803e1d58ed5e69f8 +build/test/tga-to-all/unvanquished_64.ktx d82eab591163d802231722ef325571735971b6a9b0703ed8ea59b4a4144189825d96d3455605426453fb3ad8d7cc61f931c52b3e73df2bb6787f7408baeb4ac7 +build/test/tga-to-all/unvanquished_64.jpg 6cd22de7e2e5baced5ef16e84f816dde3049f822459d552ced4dcd4e3f9a16be82ee0747ed1479fe8339991176004b4ccc90380b7ef51292c7d9b518503a348d +build/test/bmp-to-all/unvanquished_64.tga 34434170b06843b2d4fb5964a4b8751ec3a151a7d03e351e45a5967508f6a21f6e40ffc214bb46640105c4058bc35e196ecb5dd3261528a64acfeff52034fb40 +build/test/bmp-to-all/unvanquished_64.bmp 1c5f28be8151a8125346e9cf17b1bf6e3f9fe27f6947b164b7eefa8fd3732a2e4dff173c354a0cd4ed599cd604d4b8f916c0575b0a4b4b508acc68dc9b4067ae +build/test/bmp-to-all/unvanquished_64.png 71bb28da97cd778b99f131acaeb1c28ea37bae295a9e9934bed339508d8428587120c0da8f5bbc7963cdb77741ef789414f9d0d2c1e0da46026336efde147cc5 +build/test/bmp-to-all/unvanquished_64.crn a3b526e95f44b6a4c919bc8eb79f4debf592f0bccc163c900cd1b6f9add0ce58c3db9fc8dac1828d350bbcd915823d7743a0c114a533fbc08c163fcb4846d2f5 +build/test/bmp-to-all/unvanquished_64.dds ce98b21c574b4883e4aff4a0b92fd0f533f22e00ab753686f353111fa7503287c2c4dba25f2c2670508630d79b59464578e094461bad81ad803e1d58ed5e69f8 +build/test/bmp-to-all/unvanquished_64.ktx d82eab591163d802231722ef325571735971b6a9b0703ed8ea59b4a4144189825d96d3455605426453fb3ad8d7cc61f931c52b3e73df2bb6787f7408baeb4ac7 +build/test/bmp-to-all/unvanquished_64.jpg 6cd22de7e2e5baced5ef16e84f816dde3049f822459d552ced4dcd4e3f9a16be82ee0747ed1479fe8339991176004b4ccc90380b7ef51292c7d9b518503a348d +build/test/crn-to-all/unvanquished_64.tga 71014682514ec9d2baa19444fd026ceb65aa06e86d32f34b326f336e47cf4ea351aa7c2eee6a1f0fbf290658fae72c24a86c4e167272143012d384dd6d6b1ce9 +build/test/crn-to-all/unvanquished_64.bmp a6d6886879f9aade027ecb4d55f2092c3af98c297aaf2f689d77a11870156099853a41993575a9a313a23e399b3bcb06dcc0eac46b877639f3875972af7933d7 +build/test/crn-to-all/unvanquished_64.png dd9d45459bd5a3ed74d494838a3d61ed4baea9960300cb3f1d54ecc923f742c9036fe13a338da6db2efc98049a2e206cb7c0e1cba6d79ea0e3ad86473af13e83 +build/test/crn-to-all/unvanquished_64.crn 1596d312526073fd8923faefbed879fb1299ee53eeb54787f2b66754768d9a8160d9921b13aa9b7c781eb088be41cec0f3b703713aede43116a2b62f284f39f9 +build/test/crn-to-all/unvanquished_64.dds 2aae5c5bd8c6a82d1cf3fc9d9da12fe3fc5be8651261ff1cb359e754308fd81e93bf304aeb55ada0bad50794d6e97d3e48084e5a4f48fa7caec4ed954152bae9 +build/test/crn-to-all/unvanquished_64.ktx 10a45e43609c49b4929b91293e203557d8f5c1b146aa8162d946248e8fa24709e1645ed1fc40c2c1a541567b3d1287c7885cb0185230b660386825c4d03db22f +build/test/crn-to-all/unvanquished_64.jpg f68e74b3c8a404fc867345411c8778228728897e5d0870e071d6ec67fd1fccb45b3b97993575c3ed66d80cd6a7d60845e8fe68780ac322fe1d46adc57014fa8b +build/test/dds-to-all/unvanquished_64.tga 46e0c1796f7b1a998829919e14f69cb43d83b895585aca69ad17e0f6cd9839d20b383a6eca161320b87bb7161cbedc116466ec27319078a011b59fe16dc6ce26 +build/test/dds-to-all/unvanquished_64.bmp 9d1b7c76f345332fa53e9b517ee47ba142d0c9def2b27b908af67b3c19edec0882f183f83eb9022cc2e726082193d7c82394a92b068137a4698a505d8bab0080 +build/test/dds-to-all/unvanquished_64.png cd5b04f9c081f91a2d3a3fbf4484153feec5f0c027608f48a51209596ff604680ab93de70fbb616dc3fecea3fa6d240ac7a2e294bb0fc8244766375ffae54230 +build/test/dds-to-all/unvanquished_64.crn 0db1f3bcf6240389be389dc2a94fdabf97aab439d12aabc6cca2ccb69559759fc414d2bc7735d0d4812b895ffb4085172f6a48439a104d79e0b5d65124b1f002 +build/test/dds-to-all/unvanquished_64.dds ce98b21c574b4883e4aff4a0b92fd0f533f22e00ab753686f353111fa7503287c2c4dba25f2c2670508630d79b59464578e094461bad81ad803e1d58ed5e69f8 +build/test/dds-to-all/unvanquished_64.ktx dbbea021367254587000704d11b5cf7982d3ac4a42edd9489b7b2ec49da796d4346c68c6ee1a163e6880f0efaeafc0235b739c2a4acbd1ed27750657af36e3df +build/test/dds-to-all/unvanquished_64.jpg 3a2bfcc1f2ecb18371163bb16812096b019fec176731f015a301384d605910702d168f8762076fa5d912760947c8df8d4026fd9b038c0d94360d1bf744f592a2 +build/test/ktx-to-all/unvanquished_64.tga 516bc1db1bfcda9c7f466cbb6f45b7608d9803391ae6d32e8de30d8e8102ef2de623cf6adfc74d471202ab14930dc4babe93a41b6c35b90e250a0de6b690fe7e +build/test/ktx-to-all/unvanquished_64.bmp 0493fc75c26629d3a532e68e3778bb25ed6de4d81f3a39eb34a65a1990aa4072aa6b0948dc1ed3122b7ecf45e6be139d05b008ad7277649fc244d039404503fd +build/test/ktx-to-all/unvanquished_64.png 7b5da6fea08f73d0e06791d000780820574d08e14c00c06ba2ef208296ebcfbc427175d72d6f2797e7240930782c70bf717a1e966fdd9aaada4a8b826ff9a2df +build/test/ktx-to-all/unvanquished_64.crn 7cb43bf1f8fa87735d7643c3590b52bf918b6e202095787f2305c7469db957185871434b101fb2e2fb7d57e55fc0dc635994b8ed2765edb6b453f10931508f6b +build/test/ktx-to-all/unvanquished_64.dds b2cecbf2870835ec04a8ed69012d294402017fa565393f8266a6dcc868f9c5b472b8b568c98250b5beb5b0d43ee9d9dc06d04cca4f35073541ba8331d55a6b46 +build/test/ktx-to-all/unvanquished_64.ktx d82eab591163d802231722ef325571735971b6a9b0703ed8ea59b4a4144189825d96d3455605426453fb3ad8d7cc61f931c52b3e73df2bb6787f7408baeb4ac7 +build/test/ktx-to-all/unvanquished_64.jpg c350e1e0d90b8d519a0cfdbad85c972a6f6c077988b8e96f5daef415f816b3ace2bb87c79772c6d25954caeb598ef3af7700f0bc10914349161fe1a4cc1f2d73 +build/test/jpg-to-all/unvanquished_64.tga 4ea9e7b358a01fe1b09e9c16845a0249daddc87010403f33c525cfca69af85cb561019221adc8beae4172908d48a951df2d8bf65d63ae2ee183ee5c6df424c99 +build/test/jpg-to-all/unvanquished_64.bmp 20636873950cde44336751526644ea6e979b5bdf1f45a166a40b583977a6f6cce6db32ab9b14d66eba1777ab8447fbc926a91b095c27cb4487e04d1f36ed3b0b +build/test/jpg-to-all/unvanquished_64.png 24124a42c01f243ec2864cc70d399b685183acb04216a0b21133b454f4d69d7606b3190119ff8c869c5dd4a28f77fbc352f3717747e32099f507cc7b790c39e2 +build/test/jpg-to-all/unvanquished_64.crn f7bf97cafc570eb16335006623b887de1b05591035a20f9399edc2386c59ab43832d4741a3763210c022cb65ee7a0facb29138bb7daf0b71f6b9059c1852c445 +build/test/jpg-to-all/unvanquished_64.dds c1b3b785d107ba2f18097fb1cf009f598dbda9e797741ed66bd6cf9b1c376447f0990bb3890af12e3c73c4e02410adc0b5be6f386867d8ffc6aded53adb5f309 +build/test/jpg-to-all/unvanquished_64.ktx 233e5d029b08cc45f8b3e9853edc6dc5dd5cab49cb0f95e870b9b6db917b2ddceaa2756d55aec1785c147375bc7a37030e3a8cde77d364f73d86043e99a7969a +build/test/jpg-to-all/unvanquished_64.jpg abe6f8c6820c4d0762a00b6ce0789834601d764b1a9a330eeb3b49d5209ee9ca2968e154d53e74912e05a4b99467df1710c12d62354cdfc8d49c9cd315de2b65 +build/test/tga-to-png/raw-bottom-left.png 6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3 +build/test/tga-to-png/raw-bottom-right.png 6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3 +build/test/tga-to-png/raw-top-left.png 6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3 +build/test/tga-to-png/raw-top-right.png 6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3 +build/test/tga-to-png/rle-bottom-left.png 6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3 +build/test/tga-to-png/rle-bottom-right.png 6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3 +build/test/tga-to-png/rle-top-left.png 6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3 +build/test/tga-to-png/rle-top-right.png 6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3 +build/test/tga-to-crn/raw-bottom-left.crn fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854 +build/test/tga-to-crn/raw-bottom-right.crn fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854 +build/test/tga-to-crn/raw-top-left.crn fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854 +build/test/tga-to-crn/raw-top-right.crn fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854 +build/test/tga-to-crn/rle-bottom-left.crn fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854 +build/test/tga-to-crn/rle-bottom-right.crn fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854 +build/test/tga-to-crn/rle-top-left.crn fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854 +build/test/tga-to-crn/rle-top-right.crn fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854 +build/test/png-to-png/test-colormap1-alpha1.png f596534970da37597230ae60112a4fe4d08d950e03b99754a633d9d285f4683624b1f710727d6b3e556b80b9d44428bfa297dc898beaf6fecad29fe98bbc98cb +build/test/png-to-png/test-colormap2-alpha1.png 2ffd5907e77157dfaac01c786b5150dcf822699254bebdd51ef1797568208ae924a572d90bc3ed3a06cc5e524c4c0d5a3de7aa75ae99febc4638533e41a6dda0 +build/test/png-to-png/test-colormap4-alpha1.png f8cd5a9b1ae040baee41a7f378e18bba426f79532555e22fe2f8c605a8347d79e7b98bb8284130536512b187f9d8435d58665eddb8d36596296f84f05ee904ae +build/test/png-to-png/test-colormap8-alpha1.png 3561be7b7958d37913708664413c149942f302907bf5f928782c7cf6cc4b312082f51fea6d8a3271b93bd37ace03ec22af65c224d6e7617ed8644fbe2f95dc35 +build/test/png-to-png/test-grayscale1-alpha1.png 57876e1d84ada2604c5e2dbbfd08c19286c87c8f1843cf47a9b77b4f6561c3b414a269f924c2be74bba4662503ede0fd9d94cb0a084c35a9f63a3cce07dcb876 +build/test/png-to-png/test-grayscale1-alpha8.png 62ba2ca3669febcb88959224732c295d891f10942dcddf2494c052886c4f502b0e30c1238d05196ce8113c2c150fa4d96fc81436af5ad6a28f7b8a64a77bbe7f +build/test/png-to-png/test-grayscale8-alpha1.png 62ba2ca3669febcb88959224732c295d891f10942dcddf2494c052886c4f502b0e30c1238d05196ce8113c2c150fa4d96fc81436af5ad6a28f7b8a64a77bbe7f +build/test/png-to-png/test-rgb8-alpha8.png 21630317b2ed9957241f4982c4e8207f7a00af23e0dd5df863965dbca9dcefd9a3c4f77b15ea91141c6c35181e44801ff1b5d0a7ed62f0c11eddfdaf7122b1a9 +build/test/png-to-crn/test-colormap1-alpha1.crn f223d84528a0470cedeaf014c85f78ed16e1cc0f8990324fdbc087b190b6f972d1db6d829881c1414c5bd37b04c26794e7aa59b0d5b6eb535dae766a0c1d4ee9 +build/test/png-to-crn/test-colormap2-alpha1.crn 91b8372d3f16a0d198ac557b15cbafff4c3d456108dd4bee66902a20593a3ea2735ca2f052d3f6ca62cc31335e5a24f6f995116802ab46e3ded534168ba4fea3 +build/test/png-to-crn/test-colormap4-alpha1.crn 75c03a7c9181aa74a32040f9bea4e13317b342f1ce8c41e3a52ff8784f6cc28de08b4c002e089470873bbdd555d87a9c09c8a649c5ab4cda6614cf2f0cbf73e9 +build/test/png-to-crn/test-colormap8-alpha1.crn b9ca0def9743aa4790d12de2faa9ce0bc355c916af8c0c4440e9a87a20c482feb563222b364a20ee7f70abff97e7d6312d679700b64704c2783d03b8cd9a757b +build/test/png-to-crn/test-grayscale1-alpha1.crn 3a9175379f9512c74675a6d573bccdb0426d70e0ff9d63dacaa83e2c1f857dda14df93732a5776ef3625bdcf17d3ec51788623bb85e46c70a56bb306fd563b05 +build/test/png-to-crn/test-grayscale1-alpha8.crn 2660ab64afdb6eb70fdb131ef9927fc0b21bca021694bb4b8220451a9e0d5195306ef08d022ec7fb3b6535eed56efbe093e1108a116fdca81c5ce5a0c6e1da01 +build/test/png-to-crn/test-grayscale8-alpha1.crn 0e0dd5cf4f613eae1a5638060e6fbdcc1b8438e1c22ab27785a30efa8f0b20458e9b28b3da09b87d6bb9cab16f101908c64d74ab8247bef032de09449b380a77 +build/test/png-to-crn/test-rgb8-alpha8.crn 70aa2d510a77ef971cbc91c8eea5cc1c0d571722f3cd7eb5cf9e3b825987b87eb7653b0bfceee733f2a54d5fa9ce452df64ab441e64f327b78b492fd57c461a9 +build/test/bmp-to-crn/sample-default.crn 119f0f756811e56ba688c402ea317923d9665017aed19022ad19fc8396e45d3ca3bb7b5383f3edc00e859e31558a0865de88af71110529b16b89ded731070925 +build/test/bmp-to-crn/sample-vertical-flip.crn 119f0f756811e56ba688c402ea317923d9665017aed19022ad19fc8396e45d3ca3bb7b5383f3edc00e859e31558a0865de88af71110529b16b89ded731070925 +build/test/jpg-to-crn/black.crn 19fb840c8dbb7da96400af5af1c45fe48c7c7e19340d03fbe5a2af28ceecfb9efba26fe6c1bf46bd76164ecb0efe91cc9237917e8e431cd8365f80e9ffacc906 +build/test/example1-dds/unvanquished_64.dds ce98b21c574b4883e4aff4a0b92fd0f533f22e00ab753686f353111fa7503287c2c4dba25f2c2670508630d79b59464578e094461bad81ad803e1d58ed5e69f8 +build/test/example1-crn/unvanquished_64.crn a3b526e95f44b6a4c919bc8eb79f4debf592f0bccc163c900cd1b6f9add0ce58c3db9fc8dac1828d350bbcd915823d7743a0c114a533fbc08c163fcb4846d2f5 +build/test/example1-crn/unvanquished_64.dds 2aae5c5bd8c6a82d1cf3fc9d9da12fe3fc5be8651261ff1cb359e754308fd81e93bf304aeb55ada0bad50794d6e97d3e48084e5a4f48fa7caec4ed954152bae9 +build/test/example2-dds/unvanquished_64.dds 2aae5c5bd8c6a82d1cf3fc9d9da12fe3fc5be8651261ff1cb359e754308fd81e93bf304aeb55ada0bad50794d6e97d3e48084e5a4f48fa7caec4ed954152bae9 +build/test/example3-dds/unvanquished_64.dds a719dd943bc4e30be0c124e6bafb1d8ba4002b9233e6208104f93046edd4ddd7aea7815430ae2c0b7efe259943f6a8fe109f56ea457e43cde79295ae7ac85b43 diff --git a/test/test.py b/test/test.py index 6e1b51c3..b038cacb 100755 --- a/test/test.py +++ b/test/test.py @@ -1,154 +1,417 @@ #! /usr/bin/env python3 +import hashlib import os import subprocess import sys +from collections import OrderedDict + +try: + from colorama import Fore, Style +except ModuleNotFoundError: + class Fore: CYAN = MAGENTA = GREEN = YELLOW = RED = "" + class Style: RESET_ALL = "" build_dir = os.getenv("CRUNCH_BUILD_DIR", "build") executable_extension = os.getenv("CRUNCH_EXE_EXTENSION", "") executable_runner = os.getenv("CRUNCH_EXE_RUNNER") +simple_test = os.getenv("CRUNCH_SIMPLE_TEST") +check_list = os.getenv("CRUNCH_CHECK_LIST", "files clones").split(" ") + +database_path = "test/checksums.tsv" + +file_knowledge = OrderedDict() +clone_knowledge = OrderedDict() + +def print_status(message): + print("{}{}{}".format(Fore.CYAN, message, Style.RESET_ALL), file=sys.stderr) + +def print_notice(message): + print("{}{}{}".format(Fore.MAGENTA, message, Style.RESET_ALL), file=sys.stderr) -def print_command(command_list): - print("running: " + " ".join(command_list), file=sys.stderr) +def print_success(message): + print("{}{}{}".format(Fore.GREEN, message, Style.RESET_ALL), file=sys.stderr) + +def print_warning(message): + print("{}Warning: {}{}".format(Fore.YELLOW, message, Style.RESET_ALL), file=sys.stderr) + +def print_error(message): + print("{}Error: {}{}".format(Fore.RED, message, Style.RESET_ALL), file=sys.stderr) + exit(1) + +def print_command_run(command_list): + print_status("Running command: {}".format(" ".join(command_list))) + +def print_command_success(command_list): + print_success("Command succeeded: {}".format(" ".join(command_list))) def convert_path(path): if path.startswith("build/"): path = build_dir + path[len("build"):] + return path.replace("/", os.path.sep) +def get_file_sum(file_path): + return hashlib.blake2b(open(file_path, "rb").read()).hexdigest() + def run(command_list): if executable_runner: command_list = executable_runner.split(" ") + command_list - print_command(command_list) + + print_command_run(command_list) returncode = subprocess.run(command_list).returncode + if returncode: + print_error("Command failed: {}".format(" ".join(command_list))) exit(returncode) + print_command_success(command_list) + def mkdir(path): path = convert_path(path) - print_command(["mkdir", path]) + command_list = ["mkdir", path] + print_command_run(command_list) os.makedirs(path, exist_ok=True) + print_command_success(command_list) def get_build_dir(): windows_build_dir = os.path.join(build_dir, "Release") + if os.path.exists(windows_build_dir): return windows_build_dir + return build_dir 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=[]): +def add_clone(clone, file_path): + if not clone: + return + + if clone not in clone_knowledge.keys(): + clone_knowledge[clone] = {} + clone_knowledge[clone]["files"] = OrderedDict() + + + clone_knowledge[clone]["files"][file_path] = False + +def crunch(input_path, output_path, clone=None, options=[]): executable_path = get_executable_path("crunch") command_list = [executable_path] + options if input_path: - input_path = convert_path(input_path) - output_path = convert_path(output_path) - command_list += ["-noTitle", "-file", input_path, "-out", output_path] + converted_input_path = convert_path(input_path) + command_list += ["-noTitle", "-helperThreads", "3", "-nostats", "-noprogress", "-file", converted_input_path] + + if output_path: + converted_output_path = convert_path(output_path) + command_list += ["-out", converted_output_path] + file_knowledge[output_path] = {"converted_path": converted_output_path} + add_clone(clone, output_path) run(command_list) -def example(num, input_path, output_path, options=[]): +def example(num, input_path, output_path, clone=None, options=[]): executable_path = get_executable_path("example" + str(num)) - command_list = [executable_path] + 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] + converted_input_path = convert_path(input_path) + command_list += [converted_input_path] command_list += options if output_path: - output_path = convert_path(output_path) - command_list += ["-out", output_path] + converted_output_path = convert_path(output_path) + command_list += ["-out", converted_output_path] + file_knowledge[output_path] = {"converted_path": converted_output_path} + add_clone(clone, output_path) run(command_list) -crunch(None, None, ["--help"]) +def sum_files(): + for file_path in file_knowledge.keys(): + print_status("Summing file {}".format(file_path)) + file_sum = get_file_sum(file_knowledge[file_path]["converted_path"]) + file_knowledge[file_path]["file_sum"] = file_sum + print_notice("File {} has checksum {}".format(file_path, file_sum)) + +def record_sums(): + database_content = "" + + for file_path in file_knowledge.keys(): + database_content += "{}\t{}\n".format(file_path, file_knowledge[file_path]["file_sum"]) + + database_file = open(database_path, "w") + database_file.write(database_content) + database_file.close() + + print_success("All test results recorded") + +def verify_clones(verification): + all_verified = True + + if verification: + for file_clone in clone_knowledge.keys(): + for file_path in clone_knowledge[file_clone]["files"].keys(): + file_sum = file_knowledge[file_path]["file_sum"] + + if "known_sum" in clone_knowledge[file_clone].keys(): + known_sum = clone_knowledge[file_clone]["known_sum"] + verified = file_sum == known_sum + clone_knowledge[file_clone]["files"][file_path] = verified + + if verified: + print_success("Clone {}'s checksum {} matches known one".format(file_path, known_sum)) + else: + print_warning("Clone {}'s checksum {} doesn't match known one {}".format(file_path, file_sum, known_sum)) + all_verified = False + + else: + clone_knowledge[file_clone]["known_sum"] = file_sum + + return all_verified + +def verify_files(verification): + all_verified = True + + if verification: + database_file = open(database_path, "r") + + for line in database_file.readlines(): + file_path, known_sum = line.split("\t") + file_knowledge[file_path]["known_sum"] = known_sum.split("\n")[0] + + database_file.close() + + for file_path in file_knowledge.keys(): + print_status("Checking file {}".format(file_path)) + file_sum = file_knowledge[file_path]["file_sum"] + known_sum = file_knowledge[file_path]["known_sum"] + verified = file_sum == known_sum + file_knowledge[file_path]["verified"] = verified -if "CRUNCH_SIMPLE_TEST" in os.environ.keys(): + if verified: + print_success("File {}'s checksum {} matches known one".format(file_path, known_sum)) + else: + print_warning("File {}'s checksum {} doesn't match known one {}".format(file_path, file_sum, known_sum)) + all_verified = False + + return all_verified + +def print_clones_results(verification): + if verification: + print("Clones verification results:") + else: + print("Clones generation results:") + + for file_clone in clone_knowledge.keys(): + first = True + for file_path in clone_knowledge[file_clone]["files"].keys(): + if first: + verified_string = "---" + first = False + elif verification: + verified = clone_knowledge[file_clone]["files"][file_path] + verified_string = ["No", "Yes"][verified] + else: + verified_string = "???" + + short_sum = file_knowledge[file_path]["file_sum"][0:10] + print("{:<3} {} {} {}".format(verified_string, short_sum, file_clone, file_path)) + +def print_files_results(verification): + if verification: + print("Files verification results:") + else: + print("Files generation results:") + + for file_path in file_knowledge.keys(): + if verification: + verified = file_knowledge[file_path]["verified"] + verified_string = ["No", "Yes"][verified] + else: + verified_string = "???" + + short_sum = file_knowledge[file_path]["file_sum"][0:10] + print("{:<3} {} {}".format(verified_string, short_sum, file_path)) + +def print_end_results(clones_verification, clones_verified, files_verification, files_verified): + if clones_verification: + if clones_verified: + print_success("All clones verified") + else: + print_warning("Some clones were not verified") + + if files_verification: + if files_verified: + print_success("All files verified") + else: + print_warning("Some files were not verified") + + if clones_verified and files_verified: + print_success("All tests passed") + else: + print_error("Some tests failed") + +crunch(None, None, options=["--help"]) + +if simple_test == "true": 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") -crunch("test/unvanquished_64.png", "build/test/0/unvanquished_64.ktx") -crunch("test/unvanquished_64.png", "build/test/0/unvanquished_64.tga") -crunch("test/unvanquished_64.png", "build/test/0/unvanquished_64.bmp") -crunch("test/unvanquished_64.png", "build/test/0/unvanquished_64.png") -crunch("test/unvanquished_64.png", "build/test/0/unvanquished_64.jpg") - -mkdir("build/test/1") -crunch("build/test/0/unvanquished_64.crn", "build/test/1/unvanquished_64.crn") -crunch("build/test/0/unvanquished_64.crn", "build/test/1/unvanquished_64.dds") -crunch("build/test/0/unvanquished_64.crn", "build/test/1/unvanquished_64.ktx") -crunch("build/test/0/unvanquished_64.crn", "build/test/1/unvanquished_64.tga") -crunch("build/test/0/unvanquished_64.crn", "build/test/1/unvanquished_64.bmp") -crunch("build/test/0/unvanquished_64.crn", "build/test/1/unvanquished_64.png") -crunch("build/test/0/unvanquished_64.crn", "build/test/1/unvanquished_64.jpg") - -mkdir("build/test/2") -crunch("build/test/0/unvanquished_64.dds", "build/test/2/unvanquished_64.crn") -crunch("build/test/0/unvanquished_64.dds", "build/test/2/unvanquished_64.dds") -crunch("build/test/0/unvanquished_64.dds", "build/test/2/unvanquished_64.ktx") -crunch("build/test/0/unvanquished_64.dds", "build/test/2/unvanquished_64.tga") -crunch("build/test/0/unvanquished_64.dds", "build/test/2/unvanquished_64.bmp") -crunch("build/test/0/unvanquished_64.dds", "build/test/2/unvanquished_64.png") -crunch("build/test/0/unvanquished_64.dds", "build/test/2/unvanquished_64.jpg") - -mkdir("build/test/3") -crunch("build/test/0/unvanquished_64.ktx", "build/test/3/unvanquished_64.crn") -crunch("build/test/0/unvanquished_64.ktx", "build/test/3/unvanquished_64.dds") -crunch("build/test/0/unvanquished_64.ktx", "build/test/3/unvanquished_64.ktx") -crunch("build/test/0/unvanquished_64.ktx", "build/test/3/unvanquished_64.tga") -crunch("build/test/0/unvanquished_64.ktx", "build/test/3/unvanquished_64.bmp") -crunch("build/test/0/unvanquished_64.ktx", "build/test/3/unvanquished_64.png") -crunch("build/test/0/unvanquished_64.ktx", "build/test/3/unvanquished_64.jpg") - -mkdir("build/test/4") -crunch("test/raw-bottom-left.tga", "build/test/4/raw-bottom-left.crn") -crunch("test/raw-bottom-right.tga", "build/test/4/raw-bottom-right.crn") -crunch("test/raw-top-left.tga", "build/test/4/raw-top-left.crn") -crunch("test/raw-top-right.tga", "build/test/4/raw-top-right.crn") -crunch("test/rle-bottom-left.tga", "build/test/4/rle-bottom-left.crn") -crunch("test/rle-bottom-right.tga", "build/test/4/rle-bottom-right.crn") -crunch("test/rle-top-left.tga", "build/test/4/rle-top-left.crn") -crunch("test/rle-top-right.tga", "build/test/4/rle-top-right.crn") - -mkdir("build/test/5") -crunch("test/test-colormap1-alpha1.png", "build/test/5/test-colormap1-alpha1.crn") -crunch("test/test-colormap2-alpha1.png", "build/test/5/test-colormap2-alpha1.crn") -crunch("test/test-colormap4-alpha1.png", "build/test/5/test-colormap4-alpha1.crn") -crunch("test/test-colormap8-alpha1.png", "build/test/5/test-colormap8-alpha1.crn") -crunch("test/test-grayscale1-alpha1.png", "build/test/5/test-grayscale1-alpha1.crn") -crunch("test/test-grayscale1-alpha8.png", "build/test/5/test-grayscale1-alpha8.crn") -crunch("test/test-grayscale8-alpha1.png", "build/test/5/test-grayscale8-alpha1.crn") -crunch("test/test-rgb8-alpha8.png", "build/test/5/test-rgb8-alpha8.crn") - -mkdir("build/test/6") -crunch("test/sample-default.bmp", "build/test/6/sample-default.crn") -crunch("test/sample-vertical-flip.bmp", "build/test/6/sample-vertical-flip.crn") - -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") +mkdir("build/test/png-to-all") +crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.tga", clone="tga") +crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.bmp", clone="bmp") +crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.png", clone="png") +crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.crn", clone="crn") +crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.dds", clone="dds") +crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.ktx", clone="ktx") +crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.jpg", clone="jpg") + +mkdir("build/test/tga-to-all") +crunch("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.tga", clone="tga") +crunch("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.bmp", clone="bmp") +crunch("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.png", clone="png") +crunch("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.crn", clone="crn") +crunch("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.dds", clone="dds") +crunch("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.ktx", clone="ktx") +crunch("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.jpg", clone="jpg") + +mkdir("build/test/bmp-to-all") +crunch("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.tga", clone="tga") +crunch("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.bmp", clone="bmp") +crunch("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.png", clone="png") +crunch("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.crn", clone="crn") +crunch("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.dds", clone="dds") +crunch("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.ktx", clone="ktx") +crunch("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.jpg", clone="jpg") + +mkdir("build/test/crn-to-all") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.tga") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.bmp") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.dds", clone="crn_dds") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.ktx") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.jpg") + +mkdir("build/test/dds-to-all") +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.tga") +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.bmp") +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.dds", clone="dds") +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.ktx") +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.jpg") + +mkdir("build/test/ktx-to-all") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.tga") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.bmp") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.dds") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.ktx") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.jpg") + +mkdir("build/test/jpg-to-all") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.tga") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.bmp") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.dds") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.ktx") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.jpg") + +mkdir("build/test/tga-to-png") +crunch("test/raw-bottom-left.tga", "build/test/tga-to-png/raw-bottom-left.png", clone="tga_png") +crunch("test/raw-bottom-right.tga", "build/test/tga-to-png/raw-bottom-right.png", clone="tga_png") +crunch("test/raw-top-left.tga", "build/test/tga-to-png/raw-top-left.png", clone="tga_png") +crunch("test/raw-top-right.tga", "build/test/tga-to-png/raw-top-right.png", clone="tga_png") +crunch("test/rle-bottom-left.tga", "build/test/tga-to-png/rle-bottom-left.png", clone="tga_png") +crunch("test/rle-bottom-right.tga", "build/test/tga-to-png/rle-bottom-right.png", clone="tga_png") +crunch("test/rle-top-left.tga", "build/test/tga-to-png/rle-top-left.png", clone="tga_png") +crunch("test/rle-top-right.tga", "build/test/tga-to-png/rle-top-right.png", clone="tga_png") + +mkdir("build/test/tga-to-crn") +crunch("test/raw-bottom-left.tga", "build/test/tga-to-crn/raw-bottom-left.crn", clone="tga_crn") +crunch("test/raw-bottom-right.tga", "build/test/tga-to-crn/raw-bottom-right.crn", clone="tga_crn") +crunch("test/raw-top-left.tga", "build/test/tga-to-crn/raw-top-left.crn", clone="tga_crn") +crunch("test/raw-top-right.tga", "build/test/tga-to-crn/raw-top-right.crn", clone="tga_crn") +crunch("test/rle-bottom-left.tga", "build/test/tga-to-crn/rle-bottom-left.crn", clone="tga_crn") +crunch("test/rle-bottom-right.tga", "build/test/tga-to-crn/rle-bottom-right.crn", clone="tga_crn") +crunch("test/rle-top-left.tga", "build/test/tga-to-crn/rle-top-left.crn", clone="tga_crn") +crunch("test/rle-top-right.tga", "build/test/tga-to-crn/rle-top-right.crn", clone="tga_crn") + +mkdir("build/test/png-to-png") +crunch("test/test-colormap1-alpha1.png", "build/test/png-to-png/test-colormap1-alpha1.png") +crunch("test/test-colormap2-alpha1.png", "build/test/png-to-png/test-colormap2-alpha1.png") +crunch("test/test-colormap4-alpha1.png", "build/test/png-to-png/test-colormap4-alpha1.png") +crunch("test/test-colormap8-alpha1.png", "build/test/png-to-png/test-colormap8-alpha1.png") +crunch("test/test-grayscale1-alpha1.png", "build/test/png-to-png/test-grayscale1-alpha1.png") +crunch("test/test-grayscale1-alpha8.png", "build/test/png-to-png/test-grayscale1-alpha8.png") +crunch("test/test-grayscale8-alpha1.png", "build/test/png-to-png/test-grayscale8-alpha1.png") +crunch("test/test-rgb8-alpha8.png", "build/test/png-to-png/test-rgb8-alpha8.png") + +mkdir("build/test/png-to-crn") +crunch("test/test-colormap1-alpha1.png", "build/test/png-to-crn/test-colormap1-alpha1.crn") +crunch("test/test-colormap2-alpha1.png", "build/test/png-to-crn/test-colormap2-alpha1.crn") +crunch("test/test-colormap4-alpha1.png", "build/test/png-to-crn/test-colormap4-alpha1.crn") +crunch("test/test-colormap8-alpha1.png", "build/test/png-to-crn/test-colormap8-alpha1.crn") +crunch("test/test-grayscale1-alpha1.png", "build/test/png-to-crn/test-grayscale1-alpha1.crn") +crunch("test/test-grayscale1-alpha8.png", "build/test/png-to-crn/test-grayscale1-alpha8.crn") +crunch("test/test-grayscale8-alpha1.png", "build/test/png-to-crn/test-grayscale8-alpha1.crn") +crunch("test/test-rgb8-alpha8.png", "build/test/png-to-crn/test-rgb8-alpha8.crn") + +mkdir("build/test/bmp-to-crn") +crunch("test/sample-default.bmp", "build/test/bmp-to-crn/sample-default.crn", "bmp_crn") +crunch("test/sample-vertical-flip.bmp", "build/test/bmp-to-crn/sample-vertical-flip.crn", "bmp_crn") + +mkdir("build/test/jpg-to-crn") +crunch("test/black.jpg", "build/test/jpg-to-crn/black.crn") + +mkdir("build/test/example1-dds") +example(1, "test/unvanquished_64.png", None, options=["i"]) +example(1, "test/unvanquished_64.png", "build/test/example1-dds/unvanquished_64.dds", clone="dds", options=["c"]) + +mkdir("build/test/example1-crn") +example(1, "test/unvanquished_64.png", "build/test/example1-crn/unvanquished_64.crn", clone="crn", options=["c", "-crn"]) +example(1, "build/test/example1-crn/unvanquished_64.crn", "build/test/example1-crn/unvanquished_64.dds", clone="crn_dds", options=["d"]) + +mkdir("build/test/example2-dds") +example(2, "build/test/example1-crn/unvanquished_64.crn", "build/test/example2-dds/unvanquished_64.dds", clone="crn_dds") + +mkdir("build/test/example3-dds") +example(3, "test/unvanquished_64.png", "build/test/example3-dds/unvanquished_64.dds") + +print_success("All tests executed") + +sum_files() + +all_verified = True +clones_verification = "clones" in check_list +files_verification = "files" in check_list + +recording = sys.argv[1:] == ["--record"] + +if recording: + clones_verification = False + files_verification = False + record_sums() + +clones_verified = verify_clones(clones_verification) + +files_verified = verify_files(files_verification) + +print_clones_results(clones_verification) + +print_files_results(files_verification) + +print_end_results(clones_verification, clones_verified, files_verification, files_verified)