diff --git a/.gitignore b/.gitignore index 66eceb0..b464a60 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ plugins tools/assimp-vc*-mt.lib tools/assimp/ v4k.code-workspace +tests/out +tests/diff diff --git a/MAKE.bat b/MAKE.bat index ea95692..c7a1156 100644 --- a/MAKE.bat +++ b/MAKE.bat @@ -587,6 +587,8 @@ rem del ??-*.* > nul 2> nul rd /q /s _fwk > nul 2> nul rd /q /s _cache > 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 del tcc.bat > nul 2> nul del sh.bat > nul 2> nul diff --git a/TEST.bat b/TEST.bat index 966200d..3a4eaa8 100644 --- a/TEST.bat +++ b/TEST.bat @@ -1,5 +1,31 @@ @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 ( 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 + ) + ) ) diff --git a/demos/99-crashrpt.c b/demos/99-crashrpt.c deleted file mode 100644 index 6e802cf..0000000 --- a/demos/99-crashrpt.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "v4k.h" - -int main() { - trap_install(); - app_crash(); - return 0; -} \ No newline at end of file diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index d251c68..d9d64db 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -392583,6 +392583,8 @@ void glNewFrame() { 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) { // abort run if any test suite failed in unit-test mode 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); + cook_done = true; v4k_post_init(mode->refreshRate); return true; @@ -392978,6 +392981,17 @@ int window_swap() { window_shutdown(); 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; } diff --git a/engine/split/v4k_window.c b/engine/split/v4k_window.c index b1dd44d..1ced7b3 100644 --- a/engine/split/v4k_window.c +++ b/engine/split/v4k_window.c @@ -260,6 +260,8 @@ void glNewFrame() { 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) { // abort run if any test suite failed in unit-test mode 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); + cook_done = true; v4k_post_init(mode->refreshRate); return true; @@ -655,6 +658,17 @@ int window_swap() { window_shutdown(); 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; } diff --git a/engine/v4k.c b/engine/v4k.c index 5e752d6..78d1601 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -27123,6 +27123,8 @@ void glNewFrame() { 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) { // abort run if any test suite failed in unit-test mode 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); + cook_done = true; v4k_post_init(mode->refreshRate); return true; @@ -27518,6 +27521,17 @@ int window_swap() { window_shutdown(); 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; } diff --git a/tests/ref/00-loop.exe.png b/tests/ref/00-loop.exe.png new file mode 100644 index 0000000..a59cb1d Binary files /dev/null and b/tests/ref/00-loop.exe.png differ diff --git a/tests/ref/00-script.exe.png b/tests/ref/00-script.exe.png new file mode 100644 index 0000000..e049950 Binary files /dev/null and b/tests/ref/00-script.exe.png differ diff --git a/tests/ref/01-demo2d.exe.png b/tests/ref/01-demo2d.exe.png new file mode 100644 index 0000000..80f5804 Binary files /dev/null and b/tests/ref/01-demo2d.exe.png differ diff --git a/tests/ref/01-easing.exe.png b/tests/ref/01-easing.exe.png new file mode 100644 index 0000000..d383fbe Binary files /dev/null and b/tests/ref/01-easing.exe.png differ diff --git a/tests/ref/01-font.exe.png b/tests/ref/01-font.exe.png new file mode 100644 index 0000000..1d9c409 Binary files /dev/null and b/tests/ref/01-font.exe.png differ diff --git a/tests/ref/01-ui.exe.png b/tests/ref/01-ui.exe.png new file mode 100644 index 0000000..aa1f384 Binary files /dev/null and b/tests/ref/01-ui.exe.png differ diff --git a/tests/ref/02-ddraw.exe.png b/tests/ref/02-ddraw.exe.png new file mode 100644 index 0000000..5dad4c8 Binary files /dev/null and b/tests/ref/02-ddraw.exe.png differ diff --git a/tests/ref/02-frustum.exe.png b/tests/ref/02-frustum.exe.png new file mode 100644 index 0000000..e4dc34c Binary files /dev/null and b/tests/ref/02-frustum.exe.png differ diff --git a/tests/ref/03-anims.exe.png b/tests/ref/03-anims.exe.png new file mode 100644 index 0000000..2b2ae20 Binary files /dev/null and b/tests/ref/03-anims.exe.png differ diff --git a/tests/ref/04-actor.exe.png b/tests/ref/04-actor.exe.png new file mode 100644 index 0000000..325390e Binary files /dev/null and b/tests/ref/04-actor.exe.png differ diff --git a/tests/ref/06-material.exe.png b/tests/ref/06-material.exe.png new file mode 100644 index 0000000..6cb0ffe Binary files /dev/null and b/tests/ref/06-material.exe.png differ diff --git a/tests/ref/06-scene.exe.png b/tests/ref/06-scene.exe.png new file mode 100644 index 0000000..19e3d31 Binary files /dev/null and b/tests/ref/06-scene.exe.png differ diff --git a/tests/ref/07-netsync.exe.png b/tests/ref/07-netsync.exe.png new file mode 100644 index 0000000..d8c2a40 Binary files /dev/null and b/tests/ref/07-netsync.exe.png differ diff --git a/tests/ref/07-network.exe.png b/tests/ref/07-network.exe.png new file mode 100644 index 0000000..1293525 Binary files /dev/null and b/tests/ref/07-network.exe.png differ diff --git a/tests/ref/08-audio.exe.png b/tests/ref/08-audio.exe.png new file mode 100644 index 0000000..35bdce7 Binary files /dev/null and b/tests/ref/08-audio.exe.png differ diff --git a/tests/ref/08-video.exe.png b/tests/ref/08-video.exe.png new file mode 100644 index 0000000..91ce30d Binary files /dev/null and b/tests/ref/08-video.exe.png differ diff --git a/tests/ref/09-cubemap.exe.png b/tests/ref/09-cubemap.exe.png new file mode 100644 index 0000000..8120a97 Binary files /dev/null and b/tests/ref/09-cubemap.exe.png differ diff --git a/tests/ref/09-shadertoy.exe.png b/tests/ref/09-shadertoy.exe.png new file mode 100644 index 0000000..8b8a2c6 Binary files /dev/null and b/tests/ref/09-shadertoy.exe.png differ diff --git a/tests/ref/99-billboard.exe.png b/tests/ref/99-billboard.exe.png new file mode 100644 index 0000000..22e75c9 Binary files /dev/null and b/tests/ref/99-billboard.exe.png differ diff --git a/tests/ref/99-bt.exe.png b/tests/ref/99-bt.exe.png new file mode 100644 index 0000000..0475b7f Binary files /dev/null and b/tests/ref/99-bt.exe.png differ diff --git a/tests/ref/99-cart.exe.png b/tests/ref/99-cart.exe.png new file mode 100644 index 0000000..9b20e2f Binary files /dev/null and b/tests/ref/99-cart.exe.png differ diff --git a/tests/ref/99-compute.exe.png b/tests/ref/99-compute.exe.png new file mode 100644 index 0000000..04e530d Binary files /dev/null and b/tests/ref/99-compute.exe.png differ diff --git a/tests/ref/99-controller.exe.png b/tests/ref/99-controller.exe.png new file mode 100644 index 0000000..c194227 Binary files /dev/null and b/tests/ref/99-controller.exe.png differ diff --git a/tests/ref/99-dblclick.exe.png b/tests/ref/99-dblclick.exe.png new file mode 100644 index 0000000..a562146 Binary files /dev/null and b/tests/ref/99-dblclick.exe.png differ diff --git a/tests/ref/99-demo.exe.png b/tests/ref/99-demo.exe.png new file mode 100644 index 0000000..5af8601 Binary files /dev/null and b/tests/ref/99-demo.exe.png differ diff --git a/tests/ref/99-fpstest.exe.png b/tests/ref/99-fpstest.exe.png new file mode 100644 index 0000000..7e3e68a Binary files /dev/null and b/tests/ref/99-fpstest.exe.png differ diff --git a/tests/ref/99-geom.exe.png b/tests/ref/99-geom.exe.png new file mode 100644 index 0000000..e757d45 Binary files /dev/null and b/tests/ref/99-geom.exe.png differ diff --git a/tests/ref/99-gizmo.exe.png b/tests/ref/99-gizmo.exe.png new file mode 100644 index 0000000..258b36b Binary files /dev/null and b/tests/ref/99-gizmo.exe.png differ diff --git a/tests/ref/99-gui.exe.png b/tests/ref/99-gui.exe.png new file mode 100644 index 0000000..9d2012f Binary files /dev/null and b/tests/ref/99-gui.exe.png differ diff --git a/tests/ref/99-lmap.exe.png b/tests/ref/99-lmap.exe.png new file mode 100644 index 0000000..0b1a6eb Binary files /dev/null and b/tests/ref/99-lmap.exe.png differ diff --git a/tests/ref/99-lod.exe.png b/tests/ref/99-lod.exe.png new file mode 100644 index 0000000..a1e81e1 Binary files /dev/null and b/tests/ref/99-lod.exe.png differ diff --git a/tests/ref/99-occlusion.exe.png b/tests/ref/99-occlusion.exe.png new file mode 100644 index 0000000..eff7650 Binary files /dev/null and b/tests/ref/99-occlusion.exe.png differ diff --git a/tests/ref/99-pathfind.exe.png b/tests/ref/99-pathfind.exe.png new file mode 100644 index 0000000..e22edce Binary files /dev/null and b/tests/ref/99-pathfind.exe.png differ diff --git a/tests/ref/99-pbr.exe.png b/tests/ref/99-pbr.exe.png new file mode 100644 index 0000000..e5660cd Binary files /dev/null and b/tests/ref/99-pbr.exe.png differ diff --git a/tests/ref/99-renderstate.exe.png b/tests/ref/99-renderstate.exe.png new file mode 100644 index 0000000..be3c197 Binary files /dev/null and b/tests/ref/99-renderstate.exe.png differ diff --git a/tests/ref/99-spine.exe.png b/tests/ref/99-spine.exe.png new file mode 100644 index 0000000..54010bb Binary files /dev/null and b/tests/ref/99-spine.exe.png differ diff --git a/tests/ref/99-splines.exe.png b/tests/ref/99-splines.exe.png new file mode 100644 index 0000000..9133378 Binary files /dev/null and b/tests/ref/99-splines.exe.png differ diff --git a/tests/ref/99-sponza.exe.png b/tests/ref/99-sponza.exe.png new file mode 100644 index 0000000..3890270 Binary files /dev/null and b/tests/ref/99-sponza.exe.png differ diff --git a/tests/ref/99-sprite.exe.png b/tests/ref/99-sprite.exe.png new file mode 100644 index 0000000..1a57436 Binary files /dev/null and b/tests/ref/99-sprite.exe.png differ diff --git a/tests/ref/99-sprite3d.exe.png b/tests/ref/99-sprite3d.exe.png new file mode 100644 index 0000000..83f35e4 Binary files /dev/null and b/tests/ref/99-sprite3d.exe.png differ diff --git a/tests/ref/99-steam.exe.png b/tests/ref/99-steam.exe.png new file mode 100644 index 0000000..1b1956b Binary files /dev/null and b/tests/ref/99-steam.exe.png differ diff --git a/tests/ref/99-temperature.exe.png b/tests/ref/99-temperature.exe.png new file mode 100644 index 0000000..7f0e9ad Binary files /dev/null and b/tests/ref/99-temperature.exe.png differ diff --git a/tests/ref/editor.exe.png b/tests/ref/editor.exe.png new file mode 100644 index 0000000..d88988a Binary files /dev/null and b/tests/ref/editor.exe.png differ diff --git a/tests/ref/hello.exe.png b/tests/ref/hello.exe.png new file mode 100644 index 0000000..a57586b Binary files /dev/null and b/tests/ref/hello.exe.png differ