aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--README.md14
-rwxr-xr-xbuild70
-rw-r--r--tools/solvetest.h9
3 files changed, 64 insertions, 29 deletions
diff --git a/README.md b/README.md
index fa5b4a3..34d5f72 100644
--- a/README.md
+++ b/README.md
@@ -73,6 +73,8 @@ output, the results compared with the .out files) and test/last.err
73Tests are always run in debug mode: this means that optimizations are 73Tests are always run in debug mode: this means that optimizations are
74disabled and some extra logging is enabled. 74disabled and some extra logging is enabled.
75 75
76More comprehensive tests (integration tests) can be performed with *tools*.
77
76## Running "tools" 78## Running "tools"
77 79
78In the tools folder there are some small programs that test various 80In the tools folder there are some small programs that test various
@@ -104,6 +106,18 @@ file in the tools/results folder.
104 106
105To build and run a tool in debug mode, use `./build -d tool`. 107To build and run a tool in debug mode, use `./build -d tool`.
106 108
109### The `solvetest` tools
110
111The tools denoted with `solvetest` can be used to test that the various
112solvers produce the correct solutions. They can be run individually as
113all other tools, or all together with
114
115```
116$ ./build solvetest # Use -d for debug mode (very slow for some solvers)
117```
118
119If one of the solvetests fails, subsequent tests are going to be skipped.
120
107## Command-line interface 121## Command-line interface
108 122
109The `shell` folder contains the code for a rudimentary shell that can 123The `shell` folder contains the code for a rudimentary shell that can
diff --git a/build b/build
index 8c9e72f..9700d4a 100755
--- a/build
+++ b/build
@@ -177,6 +177,7 @@ build_help() {
177 echo "shell Build a basic nissy shell (./run)" 177 echo "shell Build a basic nissy shell (./run)"
178 echo "web Build the WebAssembly / JavaScript module for nissy" 178 echo "web Build the WebAssembly / JavaScript module for nissy"
179 echo "cpp FILES Build and run the given FILES including cpp/nissy.h" 179 echo "cpp FILES Build and run the given FILES including cpp/nissy.h"
180 echo "solvetest Build nissy and run the tests for solvers (tools)"
180 echo "" 181 echo ""
181 echo "help Show this help message" 182 echo "help Show this help message"
182 echo "config Show build configuration and exit" 183 echo "config Show build configuration and exit"
@@ -371,6 +372,39 @@ build_webtest() {
371 rm -f runtest.js runtest.wasm 372 rm -f runtest.js runtest.wasm
372} 373}
373 374
375run_single_tool() {
376 results="tools/results"
377 last="$results/last.out"
378 date="$(date +'%Y-%m-%d-%H-%M-%S')"
379 file="$results/$toolname-$date.txt"
380 failed="tools/failed"
381
382 $CC $CFLAGS $WFLAGS $MFLAGS $(odflags) -o runtool "$t"/*.c nissy.o \
383 || exit 1
384
385 (
386 date +'%Y-%m-%d %H:%M'
387 echo ""
388 echo "=========== Running tool ==========="
389 echo "tool name: $toolname"
390 echo ""
391 echo "======== nissy build command ========"
392 echo "$CC $CFLAGS $WFLAGS $MFLAGS $(odflags)"
393 echo ""
394 echo "======== tool build command ========"
395 echo "$CC $CFLAGS $WFLAGS $MFLAGS $(odflags)"
396 echo ""
397 echo "============ tool output ============"
398 ./runtool $@ || touch "$failed"
399 ) | tee "$file" "$last"
400
401 rm -f runtool
402 if [ -f "$failed" ]; then
403 rm "$failed"
404 exit 1
405 fi
406}
407
374build_tool() { 408build_tool() {
375 pattern="$1" 409 pattern="$1"
376 410
@@ -394,31 +428,17 @@ build_tool() {
394 fi 428 fi
395 429
396 build_nissy || exit 1 430 build_nissy || exit 1
431 run_single_tool
432}
397 433
398 results="tools/results" 434build_solvetest() {
399 last="$results/last.out" 435 build_nissy || exit 1
400 date="$(date +'%Y-%m-%d-%H-%M-%S')" 436 for t in tools/*; do
401 file="$results/$toolname-$date.txt" 437 if [ -d "$t" ] && (echo "$t" | grep -q "solvetest"); then
402 438 toolname="$(basename "$t" .c)"
403 $CC $CFLAGS $WFLAGS $MFLAGS $(odflags) -o runtool "$t"/*.c nissy.o \ 439 run_single_tool || exit 1
404 || exit 1 440 fi
405 441 done
406 (
407 date +'%Y-%m-%d %H:%M'
408 echo ""
409 echo "=========== Running tool ==========="
410 echo "tool name: $toolname"
411 echo ""
412 echo "======== nissy build command ========"
413 echo "$CC $CFLAGS $WFLAGS $MFLAGS $(odflags)"
414 echo ""
415 echo "======== tool build command ========"
416 echo "$CC $CFLAGS $WFLAGS $MFLAGS $(odflags)"
417 echo ""
418 echo "============ tool output ============"
419 ./runtool $@
420 ) | tee "$file" "$last"
421 rm -f runtool
422} 442}
423 443
424if [ "$1" = "-d" ]; then 444if [ "$1" = "-d" ]; then
@@ -435,7 +455,7 @@ fi
435 455
436case "$target" in 456case "$target" in
437help|config|clean|\ 457help|config|clean|\
438nissy|lib|sharedlib|shell|python|cpp|web|test|webtest|tool) 458nissy|lib|sharedlib|shell|python|cpp|web|test|webtest|tool|solvetest)
439 mkdir -p tables tools/results 459 mkdir -p tables tools/results
440 (build_"$target" $@) || exit 1 460 (build_"$target" $@) || exit 1
441 exit 0 461 exit 0
diff --git a/tools/solvetest.h b/tools/solvetest.h
index 4c72ca5..75f7aab 100644
--- a/tools/solvetest.h
+++ b/tools/solvetest.h
@@ -95,23 +95,24 @@ void run(void) {
95 for (i = 0; s[i].scramble[0]; i++) { 95 for (i = 0; s[i].scramble[0]; i++) {
96 printf("\n%d. %s\n", i, s[i].scramble); 96 printf("\n%d. %s\n", i, s[i].scramble);
97 97
98 /* Multiple solutions */
99 if (nissy_applymoves(NISSY_SOLVED_CUBE, s[i].scramble, cube) 98 if (nissy_applymoves(NISSY_SOLVED_CUBE, s[i].scramble, cube)
100 == -1) { 99 == NISSY_ERROR_INVALID_MOVES) {
101 printf("Invalid scramble\n"); 100 printf("Invalid scramble\n");
102 continue; 101 exit(1);
103 } 102 }
103
104 nissy_solve(cube, solver, 104 nissy_solve(cube, solver,
105 NISSFLAG, MINMOVES, MAXMOVES, MAXSOLUTIONS, OPTIMAL, 105 NISSFLAG, MINMOVES, MAXMOVES, MAXSOLUTIONS, OPTIMAL,
106 0, size, buf, SOL_BUFFER_LEN, sol, stats, 106 0, size, buf, SOL_BUFFER_LEN, sol, stats,
107 NULL, NULL); 107 NULL, NULL);
108
108 if (check_all(sol, s[i].solutions)) { 109 if (check_all(sol, s[i].solutions)) {
109 printf("All solutions are correct\n"); 110 printf("All solutions are correct\n");
110 } else { 111 } else {
111 printf("Error!\n"); 112 printf("Error!\n");
112 printf("Found solution(s):\n%s", sol); 113 printf("Found solution(s):\n%s", sol);
113 printf("Valid solution(s):\n%s", s[i].solutions); 114 printf("Valid solution(s):\n%s", s[i].solutions);
114 return; 115 exit(1);
115 } 116 }
116 } 117 }
117 118

Generated with cgit - Back to sebastiano.tronto.net