diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-08-13 15:10:37 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-08-13 15:10:37 +0100 |
| commit | c368c0f4aa0a810f5102cb8958e57410e572afa8 (patch) | |
| tree | fb78228de7ee0b7883c19848e522fec58f673043 | |
| parent | 1562c2e8ef10e25973317c790c2779e9d595e5f1 (diff) | |
| download | nissy-core-c368c0f4aa0a810f5102cb8958e57410e572afa8.tar.gz nissy-core-c368c0f4aa0a810f5102cb8958e57410e572afa8.zip | |
Improvements to build.bat (unit tests on Windows)
| -rw-r--r-- | .gitignore | 6 | ||||
| -rw-r--r-- | README.md | 24 | ||||
| -rw-r--r-- | build.bat | 149 | ||||
| -rw-r--r-- | test/test.h | 1 |
4 files changed, 160 insertions, 20 deletions
| @@ -11,8 +11,6 @@ perf.data.old | |||
| 11 | run | 11 | run |
| 12 | run.exe | 12 | run.exe |
| 13 | debugrun | 13 | debugrun |
| 14 | shell/lasttest.out | ||
| 15 | shell/lasttest.err | ||
| 16 | tables/* | 14 | tables/* |
| 17 | test/*/runtest | 15 | test/*/runtest |
| 18 | test/.DS_Store | 16 | test/.DS_Store |
| @@ -43,3 +41,7 @@ tools/results | |||
| 43 | *.exp | 41 | *.exp |
| 44 | *.lib | 42 | *.lib |
| 45 | *.pdb | 43 | *.pdb |
| 44 | *.ilk | ||
| 45 | python/*.pyd | ||
| 46 | python/*.exp | ||
| 47 | python/*.lib | ||
| @@ -48,15 +48,25 @@ the "C++ development" pack, as well as the "clang" and "Windows SDK 11" | |||
| 48 | components. It is advised to use "x64 Native Tools Command Prompt for | 48 | components. It is advised to use "x64 Native Tools Command Prompt for |
| 49 | VS 2022" instead of a regular command prompt to run the build script. | 49 | VS 2022" instead of a regular command prompt to run the build script. |
| 50 | 50 | ||
| 51 | The `build.bat` script is going to build: | 51 | The `build.bat` script has the same syntax as the `build.sh` script, |
| 52 | but not all options are available. For example | ||
| 52 | 53 | ||
| 53 | * The core nissy library | 54 | ``` |
| 54 | * The shell `run.exe` (see below) | 55 | > build.bat shell |
| 55 | * The Python module (see below) | 56 | ``` |
| 57 | |||
| 58 | can be used to build the basic shell, while | ||
| 59 | |||
| 60 | ``` | ||
| 61 | > build.bat test | ||
| 62 | ``` | ||
| 63 | |||
| 64 | Builds and runs the unit tests. See `build.bat help` for a list of | ||
| 65 | all available options. | ||
| 56 | 66 | ||
| 57 | All other options are unavailable. Moreover, Windows build will not | 67 | Not: At the moment certain optimizations, such as multithreading and |
| 58 | enable certain optimizations, such as multithreading and advanced CPU | 68 | advanced CPU instructions, are not supported on Windows. |
| 59 | instructions. Work is ongoing to improve Windows support. | 69 | Work is ongoing to improve Windows support. |
| 60 | 70 | ||
| 61 | ## Running tests | 71 | ## Running tests |
| 62 | 72 | ||
| @@ -1,21 +1,150 @@ | |||
| 1 | SET COMPILER=clang | 1 | @echo off |
| 2 | |||
| 3 | if [%1]==[/d] ( | ||
| 4 | SET DEBUG=1 | ||
| 5 | shift | ||
| 6 | ) else ( | ||
| 7 | SET DEBUG=0 | ||
| 8 | ) | ||
| 9 | |||
| 10 | SET CC=clang | ||
| 11 | SET ARCH=PORTABLE | ||
| 12 | SET THREADS=1 | ||
| 13 | SET SANITIZE= | ||
| 14 | |||
| 15 | :: TODO depends on ARCH variable | ||
| 16 | SET ARCHOPTS= | ||
| 17 | :: TODO depends on SANITIZE variable | ||
| 18 | SET DFLAGS=-g3 -DDEBUG | ||
| 2 | 19 | ||
| 3 | SET ARCH= | ||
| 4 | SET WARNINGS=-Wno-deprecated-declarations | 20 | SET WARNINGS=-Wno-deprecated-declarations |
| 5 | SET VARIABLES=-DTHREADS=1 -DPORTABLE | 21 | SET VARIABLES=-DTHREADS=%THREADS% -D%ARCH% |
| 6 | SET OFLAGS=-O3 | 22 | SET OFLAGS=-O3 |
| 7 | SET DFLAGS=-g -fsanitize=address | 23 | |
| 8 | SET CFLAGS=-std=c11 %OFLAGS% %ARCH% %WARNINGS% %VARIABLES% | 24 | SET CFLAGS=-std=c11 %ARCHOPTS% %WARNINGS% %VARIABLES% |
| 9 | 25 | ||
| 10 | SET STACKSIZE=-Wl,-stack:16777216 | 26 | SET STACKSIZE=-Wl,-stack:16777216 |
| 11 | SET LFLAGS=%STACKSIZE% | 27 | SET LFLAGS=%STACKSIZE% |
| 12 | 28 | ||
| 13 | %COMPILER% %CFLAGS% -c src\nissy.c || exit /b | 29 | :: Python libraries - change to match your local installation |
| 14 | %COMPILER% %CFLAGS% %LFLAGS% nissy.o shell\shell.c -o run.exe || exit /b | ||
| 15 | |||
| 16 | :: Python libraries - change to mathc your local installation | ||
| 17 | SET PYPATH=%userprofile%\AppData\Local\Programs\Python\Python313 | 30 | SET PYPATH=%userprofile%\AppData\Local\Programs\Python\Python313 |
| 18 | SET PYINCLUDE=%PYPATH%\include | 31 | SET PYINCLUDE=%PYPATH%\include |
| 19 | SET PYLIBS=%PYPATH%\libs | 32 | SET PYLIBS=%PYPATH%\libs |
| 20 | 33 | ||
| 21 | %COMPILER% %CFLAGS% -I%PYINCLUDE% -L%PYLIBS% -shared -lpython3 python/nissy_module.c nissy.o -o nissy.pyd \ No newline at end of file | 34 | SET TARGET=%1 |
| 35 | if not defined TARGET SET TARGET=nissy | ||
| 36 | SET EXPR=%2 | ||
| 37 | for %%a in (nissy python shell test config help) do ( | ||
| 38 | if %TARGET%==%%a ( | ||
| 39 | call:build_%TARGET% | ||
| 40 | exit /b | ||
| 41 | ) | ||
| 42 | ) | ||
| 43 | |||
| 44 | echo Target '%TARGET%' unavailable, run 'build help' for info | ||
| 45 | exit /b 1 | ||
| 46 | |||
| 47 | :build_help | ||
| 48 | echo *** Warning: support for building nissy on Windows is incomplete *** | ||
| 49 | echo. | ||
| 50 | echo Build system for nissy. Usage: | ||
| 51 | echo. | ||
| 52 | echo build [/d] [TARGET] | ||
| 53 | echo. | ||
| 54 | echo Possible values for TARGET (defaults to 'nissy' if unspecified): | ||
| 55 | echo. | ||
| 56 | echo nissy Build the nissy.o object file. | ||
| 57 | echo python Build the Python module for nissy. | ||
| 58 | echo shell Build the basic nissy shell (./run). | ||
| 59 | echo help Show this help message. | ||
| 60 | echo config Show build configuration and exit. | ||
| 61 | echo test [EXPR] Build and run unit tests. If EXPR is provided, only the | ||
| 62 | echo tests whose name contains EXPR are run. The /d option is | ||
| 63 | echo is always implied. | ||
| 64 | echo. | ||
| 65 | echo The /d option activates debug mode (slower, used for testing). | ||
| 66 | echo Tests are automatically built in debug mode even without /d. | ||
| 67 | echo For more on build configurations, see the comments in build.bat. | ||
| 68 | exit /b | ||
| 69 | |||
| 70 | :build_config | ||
| 71 | echo Compiler: %CC% | ||
| 72 | echo Architecture: %ARCH% | ||
| 73 | echo Max threads: %THREADS% | ||
| 74 | echo Optimization flags: %OFLAGS% | ||
| 75 | echo Debug flags: %DFLAGS% | ||
| 76 | exit /b | ||
| 77 | |||
| 78 | :build_nissy | ||
| 79 | call:odflags | ||
| 80 | @echo on | ||
| 81 | %CC% %CFLAGS% %ODFLAGS% -c src\nissy.c || exit /b 1 | ||
| 82 | @echo off | ||
| 83 | exit /b | ||
| 84 | |||
| 85 | :build_shell | ||
| 86 | call:build_nissy || exit /b 1 | ||
| 87 | call:odflags | ||
| 88 | @echo on | ||
| 89 | %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o shell\shell.c -o run.exe ^ | ||
| 90 | || exit /b 1 | ||
| 91 | @echo off | ||
| 92 | exit /b | ||
| 93 | |||
| 94 | :build_python | ||
| 95 | call:build_nissy || exit /b 1 | ||
| 96 | call:odflags | ||
| 97 | @echo on | ||
| 98 | %CC% %CFLAGS% %LFLAGS% -I%PYINCLUDE% -L%PYLIBS% -shared -lpython3 ^ | ||
| 99 | python\nissy_module.c nissy.o -o python\nissy.pyd || exit /b 1 | ||
| 100 | @echo off | ||
| 101 | exit /b | ||
| 102 | |||
| 103 | :build_test | ||
| 104 | SET DEBUG=1 | ||
| 105 | call:build_nissy || exit /b 1 | ||
| 106 | if not defined EXPR ( | ||
| 107 | SET WILDCARD=* | ||
| 108 | ) else ( | ||
| 109 | SET WILDCARD=*%EXPR%* | ||
| 110 | ) | ||
| 111 | for /d %%d in ( test\%WILDCARD% ) do ( | ||
| 112 | if exist %%d\* ( | ||
| 113 | call:build_single_test %%d || exit /b 1 | ||
| 114 | ) | ||
| 115 | ) | ||
| 116 | exit /b | ||
| 117 | |||
| 118 | :build_single_test | ||
| 119 | call:odflags | ||
| 120 | %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o %1\*.c -o runtest.exe || exit /b 1 | ||
| 121 | set error=0 | ||
| 122 | for %%c in ( %1\*.in ) do ( | ||
| 123 | if %error%==1 exit /b 1 | ||
| 124 | @echo | set /p v="%1\%%~nc: " | ||
| 125 | runtest < %%c > test\last.out 2> test\last.err | ||
| 126 | FC /a %1\%%~nc.out test\last.out > test\last.fc.out | ||
| 127 | if ERRORLEVEL 1 ( | ||
| 128 | @echo Test failed! Different output: | ||
| 129 | type test\last.fc.out | ||
| 130 | @echo stderr: | ||
| 131 | type test\last.err | ||
| 132 | goto :error | ||
| 133 | ) else ( | ||
| 134 | @echo ok | ||
| 135 | ) | ||
| 136 | ) | ||
| 137 | if %error%==1 exit /b 1 | ||
| 138 | del runtest.* | ||
| 139 | exit /b | ||
| 140 | |||
| 141 | :odflags | ||
| 142 | if %DEBUG%==1 ( | ||
| 143 | SET ODFLAGS=%DFLAGS% | ||
| 144 | ) else ( | ||
| 145 | SET ODFLAGS=%OFLAGS% | ||
| 146 | ) | ||
| 147 | exit /b | ||
| 148 | |||
| 149 | :error | ||
| 150 | exit /b 1 \ No newline at end of file | ||
diff --git a/test/test.h b/test/test.h index 703447b..60e340f 100644 --- a/test/test.h +++ b/test/test.h | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | #define TEST_H | 1 | #define TEST_H |
| 2 | 2 | ||
| 3 | #include <inttypes.h> | 3 | #include <inttypes.h> |
| 4 | #include <pthread.h> | ||
| 5 | #include <stdarg.h> | 4 | #include <stdarg.h> |
| 6 | #include <stdbool.h> | 5 | #include <stdbool.h> |
| 7 | #include <stdio.h> | 6 | #include <stdio.h> |
