From c210ec3098e1bb138b041d64e1d392ccc728ffaa Mon Sep 17 00:00:00 2001 From: Kai Bao Date: Mon, 23 Nov 2026 10:09:51 +0100 Subject: [PATCH 1/2] Check the child's exit in test_tasklets_failure without assert() The parent checked the child's exit status with assert(), so a build with -DWITH_NDEBUG=ON passed the test whatever the child did. It also read the status without checking that waitpid() had reported the child. --- tests/models/test_tasklets_failure.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/models/test_tasklets_failure.cpp b/tests/models/test_tasklets_failure.cpp index 2ce0c31befe..b33bb435246 100644 --- a/tests/models/test_tasklets_failure.cpp +++ b/tests/models/test_tasklets_failure.cpp @@ -29,7 +29,10 @@ // Note: we do not use boost.test as it does not cleanly combine with fork() usage +#include #include +#include +#include #include #include #include @@ -131,7 +134,8 @@ int main() { pid_t pid = fork(); // Create a new process, such that this child process can call exit(EXIT_FAILURE) if (pid == -1) { - assert(0 && "Fork failed"); + std::perror("fork"); + return EXIT_FAILURE; } else if (pid == 0) { // Child process execute(); @@ -139,9 +143,20 @@ int main() } else { // Parent process std::cout << "Checking failure of child process with parent process, process id " << pid << std::endl; - int status; - waitpid(pid, &status, 0); - assert(WIFEXITED(status)); // Check if the child process exited - assert(WEXITSTATUS(status) == EXIT_FAILURE); // Check if the exit status is EXIT_FAILURE + // Checked without assert(), which NDEBUG compiles out. + int status = 0; + pid_t waited; + do { + waited = waitpid(pid, &status, 0); + } while (waited == -1 && errno == EINTR); + if (waited != pid) { + std::perror("waitpid"); + return EXIT_FAILURE; + } + if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_FAILURE) { + std::cerr << "The child process did not exit with EXIT_FAILURE" << std::endl; + return EXIT_FAILURE; + } } + return EXIT_SUCCESS; } From fc7173d122d39afe466392358d9f270d51f4a0c1 Mon Sep 17 00:00:00 2001 From: Kai Bao Date: Mon, 23 Nov 2026 12:07:48 +0100 Subject: [PATCH 2/2] Check the identity mapping in test_quadrature without assert() With -DWITH_NDEBUG=ON the assert() was compiled out and the test checked nothing. A failed check now throws, which main() reports as a failure. --- tests/models/test_quadrature.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/models/test_quadrature.cpp b/tests/models/test_quadrature.cpp index 113ef186ccc..1f9647957cd 100644 --- a/tests/models/test_quadrature.cpp +++ b/tests/models/test_quadrature.cpp @@ -49,6 +49,7 @@ using AluGrid = Dune::ALUGrid #include +#include const unsigned dim = 3; using Scalar = double; @@ -106,7 +107,10 @@ void testIdenityMapping() GlobalPosition diff(localPos); diff -= globalPos; - assert(diff.two_norm() < 1e-10); + // Checked without assert(), which NDEBUG compiles out. + if (!(diff.two_norm() < 1e-10)) { + throw std::runtime_error("The identity mapping moves a point"); + } } } }