nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

commit 8e931537ff13137f49de58b84898a13ed3cdeeef
parent e261c743dea0184ca32740160b2f101325d366fd
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Fri,  9 May 2025 18:00:00 +0200

Add wasmtest target to build script; minor fixes in tools and tests

Diffstat:
M.gitignore | 2++
Mbuild | 60+++++++++++++++++++++++++++++++++++++++++++-----------------
Mtest/090_tables_readwrite/tables_readwrite_tests.c | 4++--
Mtools/100_checkdata/checkdata.c | 6+++---
4 files changed, 50 insertions(+), 22 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -18,6 +18,8 @@ test/.DS_Store test/run test/run.DSYM runtest +runtest.js +runtest.wasm runtool tools/.DS_Store run.DSYM diff --git a/build b/build @@ -32,6 +32,10 @@ CC=${CC-${NISSY_BUILD_CC}} # The default value is "emcc". EMCC=${EMCC-${NISSY_BUILD_EMCC}} +# Specify the nodejs command for running tests for the WASM target. +# The default value is "node". +NODE=${NODE-${NISSY_BUILD_NODE}} + # The maximum number of threads to use for multi-threaded operations. # This is also used as default value in case an operation allows # specifying how many threads to use. @@ -115,6 +119,7 @@ parsesanitize() { # Set variables to default values if unset CC=${CC:-"cc"} EMCC=${EMCC:-"emcc"} +NODE=${NODE:-"emcc"} THREADS=${THREADS:-"$(detectthreads)"} ARCH=${ARCH:-"$(detectarch)"} OPTIMIZE=${OPTIMIZE:-"-O3"} @@ -145,10 +150,11 @@ build_help() { echo "Build system for nissy" echo "" echo "usage:" - echo "$0 TARGET # build the given TARGET" - echo "$0 # same as '$0 nissy'" - echo "$0 test [PATTERN] # run unit tests (optionally matching PATTERN) - echo "$0 tool PATTERN # run the tool matching PATTERN + echo "$0 TARGET # build the given TARGET" + echo "$0 # same as '$0 nissy'" + echo "$0 test [PATTERN] # run unit tests (matching PATTERN)" + echo "$0 wasmtest [PATTERN] # same as test, but for WASM target" + echo "$0 tool PATTERN # run the tool matching PATTERN" echo "" echo "targets:" echo "" @@ -171,6 +177,7 @@ build_config() { echo "Optimization options: $OFLAGS" echo "Debug flags: $DFLAGS" echo "WASM compiler: $EMCC" + echo "nodejs executable: $NODE" echo "Python bindings: $PYTHON3" } @@ -223,7 +230,7 @@ build_python() { build_wasm() { run $EMCC $WASMCFLAGS $WFLAGS $WASMMFLAGS $(odflags) -c \ - -o wasmnissy.o src/nissy.c + -o nissy.o src/nissy.c } dotest() { @@ -240,13 +247,12 @@ dotest() { return 0 fi - $CC $CFLAGS $WFLAGS $DFLAGS $MFLAGS -o runtest "$t"/*.c nissy.o \ - || exit 1 + $testbuild "$t"/*.c nissy.o || exit 1 for cin in "$t"/*.in; do c="$(echo "$cin" | sed 's/\.in//')" cout="$c.out" printf '%s: ' "$c" - ./runtest < "$cin" > "$testout" 2> "$testerr" + $testrun < "$cin" > "$testout" 2> "$testerr" if diff "$cout" "$testout"; then printf "OK\n" else @@ -257,33 +263,50 @@ dotest() { done } -build_test() { +build_test_generic() { if [ -n "$1" ]; then pattern="$1" shift fi debug="yes" - build_nissy + build_$obj for t in test/*; do dotest || exit 1 done echo "All tests passed!" } +build_test() { + obj="nissy" + testobj="runtest" + testbuild="$CC $CFLAGS $WFLAGS $DFLAGS $MFLAGS -o $testobj" + testrun="./$testobj" + build_test_generic $@ + rm runtest +} + +build_wasmtest() { + obj="wasm" + testobj="runtest.js" + testbuild="$EMCC $WASMCFLAGS $WFLAGS $WASMMFLAGS $DFLAGS -o $testobj" + testrun="$NODE $testobj" + build_test_generic $@ + rm -f runtest.js runtest.wasm +} + tool_usage() { echo "usage: ./build tool PATTERN" } build_tool() { - if [ -z "$1" ]; then + pattern="$1" + + if [ -z "$pattern" ]; then tool_usage exit 1 fi - pattern="$1" shift - build_nissy - # Select a single tool matched by the given pattern for t in tools/*; do if [ -d "$t" ] && (echo "$t" | grep -q "$pattern"); then @@ -292,13 +315,15 @@ build_tool() { fi done if [ -z "$toolname" ]; then - tool_usage + echo "pattern '$pattern' does not match any tool" exit 1 fi + build_nissy + results="tools/results" last="$results/last.out" - date="$(date + '%Y-%m-%d-%H-%M-%S')" + date="$(date +'%Y-%m-%d-%H-%M-%S')" file="$results/$toolname-$date.txt" $CC $CFLAGS $WFLAGS $MFLAGS $(odflags) -o runtool "$t"/*.c nissy.o \ @@ -319,6 +344,7 @@ build_tool() { echo "============ tool output ============" ./runtool $@ ) | tee "$file" "$last" + rm -f runtool } if [ "$1" = "-d" ]; then @@ -335,7 +361,7 @@ fi case "$target" in help|config|clean|\ -nissy|lib|sharedlib|shell|python|wasm|test|tool) +nissy|lib|sharedlib|shell|python|wasm|test|wasmtest|tool) mkdir -p tables tools/results (build_"$target" $@) || exit 1 exit 0 diff --git a/test/090_tables_readwrite/tables_readwrite_tests.c b/test/090_tables_readwrite/tables_readwrite_tests.c @@ -1,7 +1,7 @@ #include "../test.h" -bool readtableinfo(uint64_t, const unsigned char *, tableinfo_t *); -bool writetableinfo(const tableinfo_t *, uint64_t, unsigned char *); +int64_t readtableinfo(size_t, const unsigned char *, tableinfo_t *); +int64_t writetableinfo(const tableinfo_t *, size_t, unsigned char *); uint64_t readn(void) { char str[STRLENMAX]; diff --git a/tools/100_checkdata/checkdata.c b/tools/100_checkdata/checkdata.c @@ -5,7 +5,7 @@ char *solver, *filename; static void run(void) { - long long int size, result; + long long int size, sizeread, result; char dataid[NISSY_SIZE_DATAID]; unsigned char *buf; FILE *f; @@ -23,9 +23,9 @@ run(void) { } buf = malloc(size); - fread(buf, size, 1, f); + sizeread = fread(buf, size, 1, f); fclose(f); - result = nissy_checkdata(size, buf); + result = sizeread == 1 && nissy_checkdata(size, buf); free(buf); printf("checkdata %s\n", result == 0 ? "succeeded" : "failed");