Commit 87cf0cb5 authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Pavel Emelyanov

test: combine remap_dead_pid{,_root} tests

1. Dropped check for (fd < 0) - there is check after open() in the
test, just two lines upper or so.
2. Combined two test to share common code: they differ only by proc
path to open in a dead process.

travis-ci: success for pstree: rename lookup_create_{item <=> pid} (rev2)
Cc: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 8f2b2c7f
...@@ -390,6 +390,7 @@ shm: override CFLAGS += -DNEW_IPC_NS ...@@ -390,6 +390,7 @@ shm: override CFLAGS += -DNEW_IPC_NS
msgque: override CFLAGS += -DNEW_IPC_NS msgque: override CFLAGS += -DNEW_IPC_NS
sem: override CFLAGS += -DNEW_IPC_NS sem: override CFLAGS += -DNEW_IPC_NS
posix_timers: override LDLIBS += -lrt -pthread posix_timers: override LDLIBS += -lrt -pthread
remap_dead_pid_root: override CFLAGS += -DREMAP_PID_ROOT
socket-tcp6: override CFLAGS += -D ZDTM_IPV6 socket-tcp6: override CFLAGS += -D ZDTM_IPV6
socket-tcpbuf6: override CFLAGS += -D ZDTM_IPV6 socket-tcpbuf6: override CFLAGS += -D ZDTM_IPV6
socket-tcpbuf-local: override CFLAGS += -D ZDTM_TCP_LOCAL socket-tcpbuf-local: override CFLAGS += -D ZDTM_TCP_LOCAL
......
...@@ -14,6 +14,12 @@ ...@@ -14,6 +14,12 @@
#define CLONE_NEWNS 0x00020000 #define CLONE_NEWNS 0x00020000
#endif #endif
#ifdef REMAP_PID_ROOT
const char *proc_path = "/proc/%d";
#else
const char *proc_path = "/proc/%d/mountinfo";
#endif
const char *test_doc = "Check that dead pid's /proc entries are remapped correctly"; const char *test_doc = "Check that dead pid's /proc entries are remapped correctly";
const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>";
...@@ -40,7 +46,7 @@ int main(int argc, char **argv) ...@@ -40,7 +46,7 @@ int main(int argc, char **argv)
char path[PATH_MAX]; char path[PATH_MAX];
pid_t result; pid_t result;
sprintf(path, "/proc/%d/mountinfo", pid); sprintf(path, proc_path, pid);
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
if (fd < 0) { if (fd < 0) {
fail("failed to open fd"); fail("failed to open fd");
...@@ -55,11 +61,6 @@ int main(int argc, char **argv) ...@@ -55,11 +61,6 @@ int main(int argc, char **argv)
return -1; return -1;
} }
if (fd < 0) {
fail("failed opening %s", path);
return -1;
}
test_daemon(); test_daemon();
test_waitsig(); test_waitsig();
......
#define _GNU_SOURCE
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "zdtmtst.h"
#ifndef CLONE_NEWNS
#define CLONE_NEWNS 0x00020000
#endif
const char *test_doc = "Check that dead pid's /proc entries are remapped correctly";
const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>";
int main(int argc, char **argv)
{
pid_t pid;
test_init(argc, argv);
pid = fork();
if (pid < 0) {
fail("fork() failed");
return -1;
}
if (pid == 0) {
test_msg("child is %d\n", pid);
/* Child process just sleeps until it is killed. All we need
* here is a process to open the mountinfo of. */
while(1)
sleep(10);
} else {
int fd, ret;
char path[PATH_MAX];
pid_t result;
sprintf(path, "/proc/%d", pid);
fd = open(path, O_RDONLY);
if (fd < 0) {
fail("failed to open fd");
return -1;
}
/* no matter what, we should kill the child */
kill(pid, SIGKILL);
result = waitpid(pid, NULL, 0);
if (result < 0) {
fail("failed waitpid()");
return -1;
}
test_daemon();
test_waitsig();
ret = fcntl(fd, F_GETFD);
close(fd);
if (ret) {
fail("bad fd after restore");
return -1;
}
}
pass();
return 0;
}
remap_dead_pid.c
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment