new: automated tests

main
Dominik Madarász 2024-04-15 19:55:47 +02:00
parent 8fd7a45533
commit c1673be3fe
51 changed files with 73 additions and 8 deletions

2
.gitignore vendored
View File

@ -25,3 +25,5 @@ plugins
tools/assimp-vc*-mt.lib tools/assimp-vc*-mt.lib
tools/assimp/ tools/assimp/
v4k.code-workspace v4k.code-workspace
tests/out
tests/diff

View File

@ -587,6 +587,8 @@ rem del ??-*.* > nul 2> nul
rd /q /s _fwk > nul 2> nul rd /q /s _fwk > nul 2> nul
rd /q /s _cache > nul 2> nul rd /q /s _cache > nul 2> nul
rd /q /s _deploy > nul 2> nul rd /q /s _deploy > nul 2> nul
rd /q /s tests\out > nul 2> nul
rd /q /s tests\diff > nul 2> nul
rem rd /q /s _project > nul 2> nul rem rd /q /s _project > nul 2> nul
del tcc.bat > nul 2> nul del tcc.bat > nul 2> nul
del sh.bat > nul 2> nul del sh.bat > nul 2> nul

View File

@ -1,5 +1,31 @@
@echo off @echo off
set WORKDIR=%~dp0
call make cook
mkdir %WORKDIR%\tests > nul 2> nul
mkdir %WORKDIR%\tests\out > nul 2> nul
mkdir %WORKDIR%\tests\ref > nul 2> nul
mkdir %WORKDIR%\tests\diff > nul 2> nul
where gm > nul 2> nul
if errorlevel 1 (
echo "gm" not found. Please install GraphicsMagick and add it to the PATH.
pause
exit /b 1
)
for %%x in (*.exe) do ( for %%x in (*.exe) do (
echo Running %%x... echo Running %%x...
start /wait "" "%%x" start /wait "" "%%x" --nocook --capture=50
if not exist %WORKDIR%\tests\ref\%%~nx.exe.png (
echo Reference image not found. Copying %%~nx.exe.png ...
copy %WORKDIR%\tests\out\%%~nx.exe.png %WORKDIR%\tests\ref\%%~nx.exe.png
) else (
call gm compare -metric MSE -maximum-error 0.02 %WORKDIR%\tests\ref\%%~nx.exe.png %WORKDIR%\tests\out\%%~nx.exe.png -file %WORKDIR%\tests\diff\%%~nx.exe.png > nul 2> nul
if errorlevel 1 (
echo Images differ too much. Check %WORKDIR%\tests\diff\%%~nx.exe.png
)
)
) )

View File

@ -1,7 +0,0 @@
#include "v4k.h"
int main() {
trap_install();
app_crash();
return 0;
}

View File

@ -392583,6 +392583,8 @@ void glNewFrame() {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
} }
static bool cook_done = false;
bool window_create_from_handle(void *handle, float scale, unsigned flags) { bool window_create_from_handle(void *handle, float scale, unsigned flags) {
// abort run if any test suite failed in unit-test mode // abort run if any test suite failed in unit-test mode
ifdef(debug, if( flag("--test") ) exit( test_errors ? -test_errors : 0 )); ifdef(debug, if( flag("--test") ) exit( test_errors ? -test_errors : 0 ));
@ -392771,6 +392773,7 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) {
} }
if(cook_cancelling) cook_stop(), exit(-1); if(cook_cancelling) cook_stop(), exit(-1);
cook_done = true;
v4k_post_init(mode->refreshRate); v4k_post_init(mode->refreshRate);
return true; return true;
@ -392978,6 +392981,17 @@ int window_swap() {
window_shutdown(); window_shutdown();
return 0; return 0;
} }
static uint64_t capture_frame = 0;
if (cook_done && optioni("--capture", 0) && capture_frame++ == optioni("--capture", 0)) {
void *rgb = screenshot(3);
stbi_flip_vertically_on_write(true);
if(!stbi_write_png(va("tests/out/%s.png", argv(0)), w, h, 3, rgb, 3 * w) ) {
PANIC("!could not write screenshot file `%s`\n", screenshot_file);
}
exit(0);
}
return 1; return 1;
} }

View File

@ -260,6 +260,8 @@ void glNewFrame() {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
} }
static bool cook_done = false;
bool window_create_from_handle(void *handle, float scale, unsigned flags) { bool window_create_from_handle(void *handle, float scale, unsigned flags) {
// abort run if any test suite failed in unit-test mode // abort run if any test suite failed in unit-test mode
ifdef(debug, if( flag("--test") ) exit( test_errors ? -test_errors : 0 )); ifdef(debug, if( flag("--test") ) exit( test_errors ? -test_errors : 0 ));
@ -448,6 +450,7 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) {
} }
if(cook_cancelling) cook_stop(), exit(-1); if(cook_cancelling) cook_stop(), exit(-1);
cook_done = true;
v4k_post_init(mode->refreshRate); v4k_post_init(mode->refreshRate);
return true; return true;
@ -655,6 +658,17 @@ int window_swap() {
window_shutdown(); window_shutdown();
return 0; return 0;
} }
static uint64_t capture_frame = 0;
if (cook_done && optioni("--capture", 0) && capture_frame++ == optioni("--capture", 0)) {
void *rgb = screenshot(3);
stbi_flip_vertically_on_write(true);
if(!stbi_write_png(va("tests/out/%s.png", argv(0)), w, h, 3, rgb, 3 * w) ) {
PANIC("!could not write screenshot file `%s`\n", screenshot_file);
}
exit(0);
}
return 1; return 1;
} }

View File

@ -27123,6 +27123,8 @@ void glNewFrame() {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
} }
static bool cook_done = false;
bool window_create_from_handle(void *handle, float scale, unsigned flags) { bool window_create_from_handle(void *handle, float scale, unsigned flags) {
// abort run if any test suite failed in unit-test mode // abort run if any test suite failed in unit-test mode
ifdef(debug, if( flag("--test") ) exit( test_errors ? -test_errors : 0 )); ifdef(debug, if( flag("--test") ) exit( test_errors ? -test_errors : 0 ));
@ -27311,6 +27313,7 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) {
} }
if(cook_cancelling) cook_stop(), exit(-1); if(cook_cancelling) cook_stop(), exit(-1);
cook_done = true;
v4k_post_init(mode->refreshRate); v4k_post_init(mode->refreshRate);
return true; return true;
@ -27518,6 +27521,17 @@ int window_swap() {
window_shutdown(); window_shutdown();
return 0; return 0;
} }
static uint64_t capture_frame = 0;
if (cook_done && optioni("--capture", 0) && capture_frame++ == optioni("--capture", 0)) {
void *rgb = screenshot(3);
stbi_flip_vertically_on_write(true);
if(!stbi_write_png(va("tests/out/%s.png", argv(0)), w, h, 3, rgb, 3 * w) ) {
PANIC("!could not write screenshot file `%s`\n", screenshot_file);
}
exit(0);
}
return 1; return 1;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 969 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1017 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 KiB