Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tests/models/test_quadrature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ using AluGrid = Dune::ALUGrid<dim, dim, elType, Dune::nonconforming, Dune::ALUGr
#include <opm/models/discretization/vcfv/vcfvstencil.hh>

#include <array>
#include <stdexcept>

const unsigned dim = 3;
using Scalar = double;
Expand Down Expand Up @@ -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");
}
}
}
}
Expand Down
25 changes: 20 additions & 5 deletions tests/models/test_tasklets_failure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@

// Note: we do not use boost.test as it does not cleanly combine with fork() usage

#include <cerrno>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <mutex>
#include <thread>
Expand Down Expand Up @@ -131,17 +134,29 @@ 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();
_exit(0); // Should never reach here
} 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;
}