Skip to content

Commit 33bb4b9

Browse files
authored
Improve error message output from the fork() utest (#4753)
* Add perror to report the reason for a fork failure * reword the malloc failure message
1 parent f13403b commit 33bb4b9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

utest/test_fork.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333

3434
#include <sys/types.h>
3535
#include <sys/wait.h>
36+
#include <errno.h>
3637
#include <cblas.h>
3738
#include "openblas_utest.h"
3839

@@ -41,7 +42,7 @@ static void* xmalloc(size_t n)
4142
void* tmp;
4243
tmp = malloc(n);
4344
if (tmp == NULL) {
44-
fprintf(stderr, "You are about to die\n");
45+
fprintf(stderr, "Failed to allocate memory for the testcase.\n");
4546
exit(1);
4647
} else {
4748
return tmp;
@@ -103,6 +104,7 @@ exit(0);
103104

104105
fork_pid = fork();
105106
if (fork_pid == -1) {
107+
perror("fork");
106108
CTEST_ERR("Failed to fork process.");
107109
} else if (fork_pid == 0) {
108110
// Compute a DGEMM product in the child process to check that the
@@ -113,7 +115,8 @@ exit(0);
113115
// recursively
114116
fork_pid_nested = fork();
115117
if (fork_pid_nested == -1) {
116-
CTEST_ERR("Failed to fork process.");
118+
perror("fork");
119+
CTEST_ERR("Failed to fork nested process.");
117120
exit(1);
118121
} else if (fork_pid_nested == 0) {
119122
check_dgemm(a, b, d, c, n);

utest/test_post_fork.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333

3434
#include <sys/types.h>
3535
#include <sys/wait.h>
36+
#include <errno.h>
3637
#include <cblas.h>
3738
#ifdef USE_OPENMP
3839
#include <omp.h>
@@ -44,7 +45,7 @@ static void* xmalloc(size_t n)
4445
void* tmp;
4546
tmp = malloc(n);
4647
if (tmp == NULL) {
47-
fprintf(stderr, "You are about to die\n");
48+
fprintf(stderr, "Failed to allocate memory for the test payload.\n");
4849
exit(1);
4950
} else {
5051
return tmp;
@@ -114,7 +115,11 @@ exit(0);
114115

115116
fork_pid = fork();
116117
if (fork_pid == -1) {
117-
CTEST_ERR("Failed to fork process.");
118+
perror("fork");
119+
CTEST_ERR("Failed to fork subprocesses in a loop.");
120+
#ifdef USE_OPENMP
121+
CTEST_ERR("Number of OpenMP threads was %d in this attempt.",i);
122+
#endif
118123
} else if (fork_pid == 0) {
119124
// Just pretend to do something, e.g. call `uname`, then exit
120125
exit(0);

0 commit comments

Comments
 (0)