[CRIU] [PATCH 5/5] zdtm: introduce and use pr_err()
Kir Kolyshkin
kir at openvz.org
Wed Oct 21 16:06:16 PDT 2015
Sometimes pr_perror() is used in places that don't have errno set.
In such places, pr_perror() should not be used as it will print
some nonsense.
Introduce and use pr_err() for such cases.
Now, I see sometimes fail() is used in such cases but I think
it is reserved for places where test fails (rather than there is
something that prevents the test from working).
Also, sometimes test_msg() is used but it doesn't print source
file name and line number.
If there will be a need, we can unify pr_err() with say fail(),
it will be easier to do after this patch.
Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
test/zdtm/lib/test.c | 8 ++++----
test/zdtm/lib/zdtmtst.h | 3 +++
test/zdtm/live/static/socket-closed-tcp.c | 4 ++--
test/zdtm/live/static/socket-tcp.c | 4 ++--
test/zdtm/live/static/socket-tcpbuf.c | 6 +++---
test/zdtm/live/static/socket_aio.c | 8 ++++----
test/zdtm/live/static/socket_listen.c | 6 +++---
test/zdtm/live/streaming/fifo_loop.c | 4 ++--
test/zdtm/live/streaming/file_aio.c | 2 +-
test/zdtm/live/streaming/netlink00.c | 2 +-
test/zdtm/live/streaming/pipe_loop00.c | 4 ++--
test/zdtm/live/streaming/pipe_shared00.c | 4 ++--
test/zdtm/live/streaming/socket_loop00.c | 4 ++--
test/zdtm/live/streaming/unix_sock.c | 8 ++++----
test/zdtm/live/transition/epoll.c | 2 +-
test/zdtm/live/transition/file_read.c | 2 +-
16 files changed, 37 insertions(+), 34 deletions(-)
diff --git a/test/zdtm/lib/test.c b/test/zdtm/lib/test.c
index 27d2b6e..40aee21 100644
--- a/test/zdtm/lib/test.c
+++ b/test/zdtm/lib/test.c
@@ -192,11 +192,11 @@ void test_init(int argc, char **argv)
waitpid(pid, &ret, 0);
if (WIFEXITED(ret)) {
- pr_perror("Test exited unexpectedly with code %d", WEXITSTATUS(ret));
+ pr_err("Test exited unexpectedly with code %d\n", WEXITSTATUS(ret));
exit(0);
}
if (WIFSIGNALED(ret)) {
- pr_perror("Test exited on unexpected signal %d", WTERMSIG(ret));
+ pr_err("Test exited on unexpected signal %d\n", WTERMSIG(ret));
exit(0);
}
}
@@ -324,11 +324,11 @@ void test_init_ns(int argc, char **argv, unsigned long clone_flags,
waitpid(pid, &ret, 0);
if (WIFEXITED(ret)) {
- pr_perror("Test exited unexpectedly with code %d", WEXITSTATUS(ret));
+ pr_err("Test exited unexpectedly with code %d\n", WEXITSTATUS(ret));
exit(0);
}
if (WIFSIGNALED(ret)) {
- pr_perror("Test exited on unexpected signal %d", WTERMSIG(ret));
+ pr_err("Test exited on unexpected signal %d\n", WTERMSIG(ret));
exit(0);
}
}
diff --git a/test/zdtm/lib/zdtmtst.h b/test/zdtm/lib/zdtmtst.h
index 0b91065..4871eff 100644
--- a/test/zdtm/lib/zdtmtst.h
+++ b/test/zdtm/lib/zdtmtst.h
@@ -102,6 +102,9 @@ extern int parse_opt_string(char *param, void *arg);
extern void setup_outfile(void);
extern int test_log_init(const char *outfile, const char *suffix);
extern int zdtm_seccomp;
+#define pr_err(format, arg...) \
+ test_msg("ERR: %s:%d: " format, \
+ __FILE__, __LINE__, ## arg)
#define pr_perror(format, arg...) \
test_msg("ERR: %s:%d: " format " (errno = %d (%s))\n", \
__FILE__, __LINE__, ## arg, errno, strerror(errno))
diff --git a/test/zdtm/live/static/socket-closed-tcp.c b/test/zdtm/live/static/socket-closed-tcp.c
index bda14ad..58fc7d7 100644
--- a/test/zdtm/live/static/socket-closed-tcp.c
+++ b/test/zdtm/live/static/socket-closed-tcp.c
@@ -27,7 +27,7 @@ int main(int argc, char **argv)
test_init(argc, argv);
if ((fd_s = tcp_init_server(ZDTM_FAMILY, &port)) < 0) {
- pr_perror("initializing server failed");
+ pr_err("initializing server failed\n");
return 1;
}
@@ -40,7 +40,7 @@ int main(int argc, char **argv)
*/
fd = tcp_accept_server(fd_s);
if (fd < 0) {
- pr_perror("can't accept client connection %m");
+ pr_err("can't accept client connection\n");
return 1;
}
close(fd_s);
diff --git a/test/zdtm/live/static/socket-tcp.c b/test/zdtm/live/static/socket-tcp.c
index b179a9b..fd2f61e 100644
--- a/test/zdtm/live/static/socket-tcp.c
+++ b/test/zdtm/live/static/socket-tcp.c
@@ -118,7 +118,7 @@ int main(int argc, char **argv)
test_init(argc, argv);
if ((fd_s = tcp_init_server(ZDTM_FAMILY, &port)) < 0) {
- pr_perror("initializing server failed");
+ pr_err("initializing server failed\n");
return 1;
}
@@ -134,7 +134,7 @@ int main(int argc, char **argv)
*/
fd = tcp_accept_server(fd_s);
if (fd < 0) {
- pr_perror("can't accept client connection %m");
+ pr_err("can't accept client connection\n");
return 1;
}
diff --git a/test/zdtm/live/static/socket-tcpbuf.c b/test/zdtm/live/static/socket-tcpbuf.c
index 535d379..f61f6a5 100644
--- a/test/zdtm/live/static/socket-tcpbuf.c
+++ b/test/zdtm/live/static/socket-tcpbuf.c
@@ -212,7 +212,7 @@ int main(int argc, char **argv)
#endif
if ((fd_s = tcp_init_server(ZDTM_FAMILY, &port)) < 0) {
- pr_perror("initializing server failed");
+ pr_err("initializing server failed\n");
return 1;
}
@@ -225,13 +225,13 @@ int main(int argc, char **argv)
*/
fd = tcp_accept_server(fd_s);
if (fd < 0) {
- pr_perror("can't accept client connection %m");
+ pr_err("can't accept client connection\n");
return 1;
}
ctl_fd = tcp_accept_server(fd_s);
if (ctl_fd < 0) {
- pr_perror("can't accept client connection %m");
+ pr_err("can't accept client connection\n");
return 1;
}
diff --git a/test/zdtm/live/static/socket_aio.c b/test/zdtm/live/static/socket_aio.c
index bbad397..6ca5079 100644
--- a/test/zdtm/live/static/socket_aio.c
+++ b/test/zdtm/live/static/socket_aio.c
@@ -36,7 +36,7 @@ int main(int argc, char **argv)
test_init(argc, argv);
if ((fd_s = tcp_init_server(AF_INET, &port)) < 0) {
- pr_perror("initializing server failed");
+ pr_err("initializing server failed\n");
return 1;
}
@@ -86,7 +86,7 @@ again:
goto again;
}
if (ret != 0) {
- pr_perror("Error at aio_error() %s", strerror(ret));
+ pr_err("Error at aio_error(): %s\n", strerror(ret));
res = 1;
}
@@ -105,7 +105,7 @@ again:
fd = tcp_accept_server(fd_s);
close(fd_s);
if (fd < 0) {
- pr_perror("can't accept client connection %m");
+ pr_err("can't accept client connection\n");
goto error;
}
@@ -125,7 +125,7 @@ again:
}
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
- pr_perror("chiled failed. Return %d", WEXITSTATUS(status));
+ pr_err("child failed with exit code %d\n", WEXITSTATUS(status));
return 1;
}
diff --git a/test/zdtm/live/static/socket_listen.c b/test/zdtm/live/static/socket_listen.c
index c96c9d0..f11d379 100644
--- a/test/zdtm/live/static/socket_listen.c
+++ b/test/zdtm/live/static/socket_listen.c
@@ -44,7 +44,7 @@ int main(int argc, char **argv)
test_init(argc, argv);
if ((fd_s = tcp_init_server(ZDTM_FAMILY, &port)) < 0) {
- pr_perror("initializing server failed");
+ pr_err("initializing server failed\n");
return 1;
}
@@ -87,7 +87,7 @@ int main(int argc, char **argv)
fd = tcp_accept_server(fd_s);
close(fd_s);
if (fd < 0) {
- pr_perror("can't accept client connection %m");
+ pr_err("can't accept client connection\n");
goto error;
}
@@ -105,7 +105,7 @@ int main(int argc, char **argv)
}
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
- pr_perror("chiled failed. Return %d", WEXITSTATUS(status));
+ pr_err("child failed with exit code %d\n", WEXITSTATUS(status));
return 1;
}
diff --git a/test/zdtm/live/streaming/fifo_loop.c b/test/zdtm/live/streaming/fifo_loop.c
index 5b6c113..2e28320 100644
--- a/test/zdtm/live/streaming/fifo_loop.c
+++ b/test/zdtm/live/streaming/fifo_loop.c
@@ -45,7 +45,7 @@ int main(int argc, char **argv)
for (i = 0; i < PROCS_DEF; i++) {
file_path = path[i];
if (snprintf(file_path, BUF_SIZE, "%s-%02d", filename, i) >= BUF_SIZE) {
- pr_perror("filename %s is too long\n", filename);
+ pr_err("filename %s is too long\n", filename);
exit(1);
}
if (mkfifo(file_path, mode)) {
@@ -113,7 +113,7 @@ int main(int argc, char **argv)
}
if (num_exited) {
- pr_perror("Some children died unexpectedly\n");
+ pr_err("Some children died unexpectedly\n");
kill(0, SIGKILL);
exit(1);
}
diff --git a/test/zdtm/live/streaming/file_aio.c b/test/zdtm/live/streaming/file_aio.c
index 9eae8b8..a160101 100644
--- a/test/zdtm/live/streaming/file_aio.c
+++ b/test/zdtm/live/streaming/file_aio.c
@@ -80,7 +80,7 @@ again:
goto again;
}
if (ret != 0) {
- pr_perror("Error at aio_error() %s", strerror(ret));
+ pr_err("Error at aio_error(): %s\n", strerror(ret));
return 1;
}
diff --git a/test/zdtm/live/streaming/netlink00.c b/test/zdtm/live/streaming/netlink00.c
index 34e627e..9a2ed16 100644
--- a/test/zdtm/live/streaming/netlink00.c
+++ b/test/zdtm/live/streaming/netlink00.c
@@ -163,7 +163,7 @@ int recv_reply()
}
if (rtn == 0) {
- pr_perror("EOF on netlink\n");
+ pr_err("EOF on netlink\n");
return -1;
}
diff --git a/test/zdtm/live/streaming/pipe_loop00.c b/test/zdtm/live/streaming/pipe_loop00.c
index 0f9bd2a..cce6027 100644
--- a/test/zdtm/live/streaming/pipe_loop00.c
+++ b/test/zdtm/live/streaming/pipe_loop00.c
@@ -38,7 +38,7 @@ int main(int argc, char **argv)
test_init(argc, argv);
if (num_procs > PROCS_MAX) {
- pr_perror("%d processes is too many: max = %d\n", num_procs, PROCS_MAX);
+ pr_err("%d processes is too many: max = %d\n", num_procs, PROCS_MAX);
exit(1);
}
@@ -96,7 +96,7 @@ int main(int argc, char **argv)
}
if (num_exited) {
- pr_perror("Some children died unexpectedly\n");
+ pr_err("Some children died unexpectedly\n");
kill(0, SIGKILL);
exit(1);
}
diff --git a/test/zdtm/live/streaming/pipe_shared00.c b/test/zdtm/live/streaming/pipe_shared00.c
index 44856ea..64708d9 100644
--- a/test/zdtm/live/streaming/pipe_shared00.c
+++ b/test/zdtm/live/streaming/pipe_shared00.c
@@ -39,7 +39,7 @@ int main(int argc, char **argv)
test_init(argc, argv);
if (num_procs > PROCS_MAX) {
- pr_perror("%d processes is too many: max = %d\n", num_procs, PROCS_MAX);
+ pr_err("%d processes is too many: max = %d\n", num_procs, PROCS_MAX);
exit(1);
}
@@ -91,7 +91,7 @@ int main(int argc, char **argv)
close(pipes[0]);
if (num_exited) {
- pr_perror("Some children died unexpectedly\n");
+ pr_err("Some children died unexpectedly\n");
kill(0, SIGKILL);
exit(1);
}
diff --git a/test/zdtm/live/streaming/socket_loop00.c b/test/zdtm/live/streaming/socket_loop00.c
index 2a6a6a8..9bc3d6e 100644
--- a/test/zdtm/live/streaming/socket_loop00.c
+++ b/test/zdtm/live/streaming/socket_loop00.c
@@ -39,7 +39,7 @@ int main(int argc, char **argv)
test_init(argc, argv);
if (num_procs > PROCS_MAX) {
- pr_perror("%d processes is too many: max = %d\n", num_procs, PROCS_MAX);
+ pr_err("%d processes is too many: max = %d\n", num_procs, PROCS_MAX);
exit(1);
}
@@ -98,7 +98,7 @@ int main(int argc, char **argv)
}
if (num_exited) {
- pr_perror("Some children died unexpectedly\n");
+ pr_err("Some children died unexpectedly\n");
kill(0, SIGKILL);
exit(1);
}
diff --git a/test/zdtm/live/streaming/unix_sock.c b/test/zdtm/live/streaming/unix_sock.c
index f8b00fc..64a4919 100644
--- a/test/zdtm/live/streaming/unix_sock.c
+++ b/test/zdtm/live/streaming/unix_sock.c
@@ -44,7 +44,7 @@ static int setup_srv_sock(void)
int sock;
if (fill_sock_name(&name, filename) < 0) {
- pr_perror("filename \"%s\" is too long", filename);
+ pr_err("filename \"%s\" is too long\n", filename);
return -1;
}
@@ -90,7 +90,7 @@ static int accept_one_conn(int sock)
case 1:
break;
case 0:
- pr_perror("timeout accepting a connection");
+ pr_err("timeout accepting a connection\n");
return -1;
default:
pr_perror("error while waiting for a connection");
@@ -110,7 +110,7 @@ static int setup_clnt_sock(void)
int ret = 0;
if (fill_sock_name(&name, filename) < 0) {
- pr_perror("filename \"%s\" is too long", filename);
+ pr_err("filename \"%s\" is too long\n", filename);
return -1;
}
@@ -181,7 +181,7 @@ int main(int argc, char **argv)
test_init(argc, argv);
if (num_procs > PROCS_MAX) {
- pr_perror("%d processes is too many: max = %d\n", num_procs, PROCS_MAX);
+ pr_err("%d processes is too many: max = %d\n", num_procs, PROCS_MAX);
exit(1);
}
diff --git a/test/zdtm/live/transition/epoll.c b/test/zdtm/live/transition/epoll.c
index b4c02b9..f89d96d 100644
--- a/test/zdtm/live/transition/epoll.c
+++ b/test/zdtm/live/transition/epoll.c
@@ -106,7 +106,7 @@ int main(int argc, char **argv)
test_init(argc, argv);
if (scale > MAX_SCALE) {
- pr_perror("Too many children specified\n");
+ pr_err("Too many children specified\n");
exit(1);
}
diff --git a/test/zdtm/live/transition/file_read.c b/test/zdtm/live/transition/file_read.c
index 3f9d1e1..63926c0 100644
--- a/test/zdtm/live/transition/file_read.c
+++ b/test/zdtm/live/transition/file_read.c
@@ -187,7 +187,7 @@ int main(int argc, char **argv)
test_init(argc, argv);
if (scale > MAX_SCALE) {
- pr_perror("Too many children specified\n");
+ pr_err("Too many children specified\n");
exit(-1);
}
--
2.4.3
More information about the CRIU
mailing list