From: Eric Blake <eblake(a)redhat.com>
Original (nbdkit) commit message:
While we support compilation with CFLAGS=-DNDEBUG for the brave user
desiring to avoid assertion overhead, this causes the tests to be less
powerful (the tests "fail open" for anything where we relied on an
assert to validate nbdkit was behaving correctly; and this would be
even worse if we had side effects in a test assert, such as we just
fixed in d5cedf20). Fortunately, a quick test of './configure
CFLAGS=-DNDEBUG' didn't hit any test failures, but it seems better to
just ensure that assertions always work in our tests, even when they
are turned off for the main binary.
Porting notes:
This is a partial port. At this point, the test cases we have under
common/ actually reflect our common/ header file usage (meaning that, if
nbdkit has a test case for a header file we use, then we also have that
test case). However, test case *content* remains different at this point;
one piece is nbdkit commit 0b6d62668584 ("tests: Avoid odd test behavior
under NDEBUG", 2020-07-07). Port those parts of it that modify such test
cases that libnbd does have, at this point. Note that the nbdkit commit
modifies "test-ispowerof2.c" as well, be we have ported that particular
NDEBUG addition earlier (in libnbd commit 6cc512341281, "common/include:
Copy test-ispowerof2.c from nbdkit", 2022-08-25).
Signed-off-by: Eric Blake <eblake(a)redhat.com>
Signed-off-by: Laszlo Ersek <lersek(a)redhat.com>
(cherry picked from nbdkit commit 0b6d626685846d41ea113a394cb37e321c63e8bf)
---
common/include/test-byte-swapping.c | 1 +
common/include/test-isaligned.c | 1 +
common/include/test-iszero.c | 1 +
common/include/test-minmax.c | 1 +
4 files changed, 4 insertions(+)
diff --git a/common/include/test-byte-swapping.c b/common/include/test-byte-swapping.c
index 741b3d11517e..a3b9b68b785f 100644
--- a/common/include/test-byte-swapping.c
+++ b/common/include/test-byte-swapping.c
@@ -36,6 +36,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
+#undef NDEBUG /* Keep test strong even for nbdkit built without assertions */
#include <assert.h>
#include "byte-swapping.h"
diff --git a/common/include/test-isaligned.c b/common/include/test-isaligned.c
index e3709a8f05bd..4240df6f80c4 100644
--- a/common/include/test-isaligned.c
+++ b/common/include/test-isaligned.c
@@ -36,6 +36,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
+#undef NDEBUG /* Keep test strong even for nbdkit built without assertions */
#include <assert.h>
#include "isaligned.h"
diff --git a/common/include/test-iszero.c b/common/include/test-iszero.c
index 6c2836678155..36769d1305c7 100644
--- a/common/include/test-iszero.c
+++ b/common/include/test-iszero.c
@@ -36,6 +36,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
+#undef NDEBUG /* Keep test strong even for nbdkit built without assertions */
#include <assert.h>
#include "iszero.h"
diff --git a/common/include/test-minmax.c b/common/include/test-minmax.c
index e622cfefe1ff..285f8074e503 100644
--- a/common/include/test-minmax.c
+++ b/common/include/test-minmax.c
@@ -36,6 +36,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
+#undef NDEBUG /* Keep test strong even for nbdkit built without assertions */
#include <assert.h>
#include <float.h>