commit 7f24b27652ee6fa84e38f181cea57f319af0c204
parent 9b248f3b46d5dc0e9522ed264ef71e422a5bc5a5
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Mon, 28 Jul 2025 13:52:00 +0200
Make failed assert exit immediately
Diffstat:
11 files changed, 15 insertions(+), 61 deletions(-)
diff --git a/src/arch/coordinates_unoptimized.h b/src/arch/coordinates_unoptimized.h
@@ -34,8 +34,6 @@ coord_epud(cube_t cube)
uint8_t c[8], e[12];
pieces(&cube, c, e);
- DBG_ASSERT(isperm(8, e), -1,
- "Cannot compute epud coordinate: edges not separated");
for (i = 0; i < 8; i++)
e[i] &= PBITS;
diff --git a/src/core/cube.h b/src/core/cube.h
@@ -87,8 +87,7 @@ issolvable(oriented_cube_t cube)
{
uint8_t i, eo, co, piece, edge[12], corner[8], ep[12], cp[8];
- DBG_ASSERT(isconsistent(cube), false,
- "issolvable: cube is inconsistent\n");
+ DBG_ASSERT(isconsistent(cube), "issolvable: cube is inconsistent\n");
pieces(&cube.cube, corner, edge);
for (i = 0; i < 12; i++)
@@ -175,16 +174,16 @@ getcube(int64_t ep, int64_t eo, int64_t cp, int64_t co)
uint8_t i, earr[12], carr[8], eoarr[12], coarr[8];
sumzerotodigits(eo, 12, 2, eoarr);
- DBG_ASSERT(eoarr[0] != UINT8_ERROR, ZERO_CUBE, "Error making EO");
+ DBG_ASSERT(eoarr[0] != UINT8_ERROR, "Error making EO");
indextoperm(ep, 12, earr);
- DBG_ASSERT(earr[0] != UINT8_ERROR, ZERO_CUBE, "Error making EP");
+ DBG_ASSERT(earr[0] != UINT8_ERROR, "Error making EP");
for (i = 0; i < 12; i++)
earr[i] |= eoarr[i] << EOSHIFT;
sumzerotodigits(co, 8, 3, coarr);
- DBG_ASSERT(coarr[0] != UINT8_ERROR, ZERO_CUBE, "Error making CO");
+ DBG_ASSERT(coarr[0] != UINT8_ERROR, "Error making CO");
indextoperm(cp, 8, carr);
- DBG_ASSERT(carr[0] != UINT8_ERROR, ZERO_CUBE, "Error making CP");
+ DBG_ASSERT(carr[0] != UINT8_ERROR, "Error making CP");
for (i = 0; i < 8; i++)
carr[i] |= coarr[i] << COSHIFT;
diff --git a/src/core/oriented_cube.h b/src/core/oriented_cube.h
@@ -56,8 +56,7 @@ applymoves(oriented_cube_t cube, const char *buf)
uint8_t m;
oriented_cube_t c, cinv;
- DBG_ASSERT(isconsistent(cube), ZERO_ORIENTED_CUBE,
- "move error: inconsistent cube\n");
+ DBG_ASSERT(isconsistent(cube), "move error: inconsistent cube\n");
c = cube;
cinv = SOLVED_ORIENTED_CUBE;
diff --git a/src/core/transform.h b/src/core/transform.h
@@ -371,7 +371,7 @@ applytrans(oriented_cube_t cube, const char *buf)
{
uint8_t t;
- DBG_ASSERT(isconsistent(cube), ZERO_ORIENTED_CUBE,
+ DBG_ASSERT(isconsistent(cube),
"transformation error: inconsistent cube\n");
t = readtrans(buf);
diff --git a/src/solvers/coord/common.h b/src/solvers/coord/common.h
@@ -133,7 +133,7 @@ coord_gendata_generic(
writetableinfo(&info, coord_datasize, data);
- DBG_ASSERT(n == coord->sym.classes, SIZE_MAX,
+ DBG_ASSERT(n == coord->sym.classes,
"%s coordinate data: computed %" PRIu64 " classes, "
"expected %" PRIu64 "\n", coord->name, n, coord->sym.classes);
diff --git a/src/solvers/h48/coordinate.h b/src/solvers/h48/coordinate.h
@@ -15,7 +15,7 @@ coord_h48(
uint32_t data;
uint8_t ttrep;
- DBG_ASSERT(h <= 11, -1, "coord_h48: h must be between 0 and 11\n");
+ DBG_ASSERT(h <= 11, "coord_h48: h must be between 0 and 11\n");
cocsep = coord_cocsep(c);
data = cocsepdata[cocsep];
@@ -54,8 +54,7 @@ invcoord_h48(
cube_t ret;
int64_t hh, coclass, ee, esep, eo;
- DBG_ASSERT(h <= 11, ZERO_CUBE,
- "invcoord_h48: h must be between 0 and 11\n");
+ DBG_ASSERT(h <= 11, "invcoord_h48: h must be between 0 and 11\n");
hh = (int64_t)h;
coclass = i / H48_ESIZE(h);
diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h
@@ -61,9 +61,8 @@ gendata_cocsep(
writetableinfo(&info, COCSEP_FULLSIZE, buf);
- DBG_ASSERT(n == COCSEP_CLASSES, 0,
- "cocsep: computed %" PRIu16 " symmetry classes, "
- "expected %zu\n", n, COCSEP_CLASSES);
+ DBG_ASSERT(n == COCSEP_CLASSES, "cocsep: computed %" PRIu16
+ " symmetry classes, expected %zu\n", n, COCSEP_CLASSES);
LOG("[H48 gendata] cocsep data computed\n");
diff --git a/src/utils/dbg_log.h b/src/utils/dbg_log.h
@@ -24,11 +24,11 @@ write_wrapper(void (*write)(const char *, void *), const char *str, ...)
#define STATIC
#define STATIC_INLINE
#define DBG_WARN(condition, ...) if (!(condition)) LOG(__VA_ARGS__);
-#define DBG_ASSERT(condition, retval, ...) \
- if (!(condition)) { LOG(__VA_ARGS__); return retval; }
+#define DBG_ASSERT(condition, ...) \
+ if (!(condition)) { LOG(__VA_ARGS__); exit(1); }
#else
#define STATIC static
#define STATIC_INLINE static inline
#define DBG_WARN(condition, ...)
-#define DBG_ASSERT(condition, retval, ...)
+#define DBG_ASSERT(condition, ...)
#endif
diff --git a/test/000_basic/all.in b/test/000_basic/all.in
diff --git a/test/000_basic/all.out b/test/000_basic/all.out
@@ -1,7 +0,0 @@
-Solved is solvable
-Solved is solved
-Zero is NOT solvable
-Zero is NOT solved
-Solved and Solved are equal
-Solved and Zero are NOT equal
-Zero and Solved are NOT equal
diff --git a/test/000_basic/basic_tests.c b/test/000_basic/basic_tests.c
@@ -1,33 +0,0 @@
-#include "../test.h"
-
-bool issolved(oriented_cube_t);
-bool equal(cube_t, cube_t);
-
-void
-check(oriented_cube_t cube, char *name)
-{
- printf("%s is%s solvable\n", name, issolvable(cube) ? "" : " NOT");
- printf("%s is%s solved\n", name, issolved(cube) ? "" : " NOT");
-}
-
-void
-check2(oriented_cube_t cube1, char *name1, oriented_cube_t cube2, char *name2)
-{
- bool eq = equal(cube1.cube, cube2.cube) &&
- cube1.orientation == cube2.orientation;
- printf("%s and %s are%s equal\n", name1, name2, eq ? "" : " NOT");
-}
-
-void run(void) {
- oriented_cube_t zero, solved;
-
- memset(&zero, 0, sizeof(oriented_cube_t));
- solved = solvedcube();
-
- check(solved, "Solved");
- check(zero, "Zero");
-
- check2(solved, "Solved", solved, "Solved");
- check2(solved, "Solved", zero, "Zero");
- check2(zero, "Zero", solved, "Solved");
-}